|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Integrations\WPBakery; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Hooks\AbstractHooks; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Modules\Notice; |
|
7
|
|
|
|
|
8
|
|
|
class Hooks extends AbstractHooks |
|
9
|
|
|
{ |
|
10
|
|
|
public function run(): void |
|
11
|
|
|
{ |
|
12
|
|
|
if (!$this->isInstalled()) { |
|
13
|
|
|
return; |
|
14
|
|
|
} |
|
15
|
|
|
if (!$this->isVersionSupported()) { |
|
16
|
|
|
$this->unsupportedVersionNotice(); |
|
17
|
|
|
return; |
|
18
|
|
|
} |
|
19
|
|
|
$this->hook(Controller::class, [ |
|
20
|
|
|
['enqueueInlineScripts', 'vc_frontend_editor_enqueue_js_css'], |
|
21
|
|
|
['enqueueInlineStyles', 'vc_backend_editor_enqueue_js_css'], |
|
22
|
|
|
['enqueueInlineStyles', 'vc_frontend_editor_enqueue_js_css'], |
|
23
|
|
|
['filterAutocompleteAssignedPosts', 'vc_autocomplete_site_reviews_assigned_posts_callback'], |
|
24
|
|
|
['filterAutocompleteAssignedPosts', 'vc_autocomplete_site_reviews_form_assigned_posts_callback'], |
|
25
|
|
|
['filterAutocompleteAssignedPosts', 'vc_autocomplete_site_reviews_summary_assigned_posts_callback'], |
|
26
|
|
|
['filterAutocompleteAssignedTerms', 'vc_autocomplete_site_reviews_assigned_terms_callback'], |
|
27
|
|
|
['filterAutocompleteAssignedTerms', 'vc_autocomplete_site_reviews_form_assigned_terms_callback'], |
|
28
|
|
|
['filterAutocompleteAssignedTerms', 'vc_autocomplete_site_reviews_summary_assigned_terms_callback'], |
|
29
|
|
|
['filterAutocompleteAssignedUsers', 'vc_autocomplete_site_reviews_assigned_users_callback'], |
|
30
|
|
|
['filterAutocompleteAssignedUsers', 'vc_autocomplete_site_reviews_form_assigned_users_callback'], |
|
31
|
|
|
['filterAutocompleteAssignedUsers', 'vc_autocomplete_site_reviews_summary_assigned_users_callback'], |
|
32
|
|
|
['filterAutocompletePostId', 'vc_autocomplete_site_review_post_id_callback'], |
|
33
|
|
|
['filterSettingOutput', 'vc_single_param_edit_holder_output', 10, 4], |
|
34
|
|
|
['registerParameters', 'vc_load_default_params'], |
|
35
|
|
|
['registerShortcodes', 'vc_before_init', 5], |
|
36
|
|
|
]); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
protected function isInstalled(): bool |
|
40
|
|
|
{ |
|
41
|
|
|
return class_exists('WPBakeryShortCode') |
|
42
|
|
|
&& function_exists('vc_add_shortcode_param') |
|
43
|
|
|
&& function_exists('vc_map') |
|
44
|
|
|
&& defined('WPB_VC_VERSION'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
protected function isVersionSupported(): bool |
|
48
|
|
|
{ |
|
49
|
|
|
return defined('WPB_VC_VERSION') && version_compare(\WPB_VC_VERSION, '7.9', '>='); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
protected function unsupportedVersionNotice(): void |
|
53
|
|
|
{ |
|
54
|
|
|
add_action('admin_notices', function () { |
|
55
|
|
|
if (!str_starts_with(glsr_current_screen()->post_type, glsr()->post_type)) { |
|
56
|
|
|
return; |
|
57
|
|
|
} |
|
58
|
|
|
glsr(Notice::class)->addWarning( |
|
59
|
|
|
_x('Update WPBakery Page Builder to v7.9 or higher to enable integration with Site Reviews.', 'admin-text', 'site-reviews') |
|
60
|
|
|
); |
|
61
|
|
|
}); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|