Passed
Push — master ( 5e727b...fa3796 )
by Paul
07:53
created

compatibility.php (5 issues)

Labels
Severity
1
<?php
2
3
defined('ABSPATH') || die;
4
5
/**
6
 * Add human-readable capability names
7
 * @return void
8
 * @see https://wordpress.org/plugins/members/
9
 */
10
add_action('members_register_caps', function () {
0 ignored issues
show
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

10
/** @scrutinizer ignore-call */ 
11
add_action('members_register_caps', function () {
Loading history...
11
    members_register_cap('delete_others_site-reviews', [
12
        'label' => _x("Delete Others' Reviews", 'admin-text', 'site-reviews'),
0 ignored issues
show
The function _x was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

12
        'label' => /** @scrutinizer ignore-call */ _x("Delete Others' Reviews", 'admin-text', 'site-reviews'),
Loading history...
13
    ]);
14
    members_register_cap('delete_site-reviews', [
15
        'label' => _x('Delete Reviews', 'admin-text', 'site-reviews'),
16
    ]);
17
    members_register_cap('delete_private_site-reviews', [
18
        'label' => _x('Delete Private Reviews', 'admin-text', 'site-reviews'),
19
    ]);
20
    members_register_cap('delete_published_site-reviews', [
21
        'label' => _x('Delete Approved Reviews', 'admin-text', 'site-reviews'),
22
    ]);
23
    members_register_cap('edit_others_site-reviews', [
24
        'label' => _x("Edit Others' Reviews", 'admin-text', 'site-reviews'),
25
    ]);
26
    members_register_cap('edit_site-reviews', [
27
        'label' => _x('Edit Reviews', 'admin-text', 'site-reviews'),
28
    ]);
29
    members_register_cap('edit_private_site-reviews', [
30
        'label' => _x('Edit Private Reviews', 'admin-text', 'site-reviews'),
31
    ]);
32
    members_register_cap('edit_published_site-reviews', [
33
        'label' => _x('Edit Approved Reviews', 'admin-text', 'site-reviews'),
34
    ]);
35
    members_register_cap('publish_site-reviews', [
36
        'label' => _x('Approve Reviews', 'admin-text', 'site-reviews'),
37
    ]);
38
    members_register_cap('read_private_site-reviews', [
39
        'label' => _x('Read Private Reviews', 'admin-text', 'site-reviews'),
40
    ]);
41
    members_register_cap('create_site-review', [
42
        'label' => _x('Create Review (inactive)', 'admin-text', 'site-reviews'),
43
    ]);
44
});
45
46
/**
47
 * Exclude the reCAPTCHA script from being defered
48
 * @param array $scriptHandles
49
 * @return array
50
 * @see https://wordpress.org/plugins/speed-booster-pack/
51
 */
52
add_filter('sbp_exclude_defer_scripts', function ($scriptHandles) {
0 ignored issues
show
The function add_filter was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
/** @scrutinizer ignore-call */ 
53
add_filter('sbp_exclude_defer_scripts', function ($scriptHandles) {
Loading history...
53
    $scriptHandles[] = 'site-reviews/google-recaptcha';
54
    return array_keys(array_flip($scriptHandles));
55
});
56
57
/**
58
 * Fix to display all reviews when sorting by rank
59
 * @param array $query
60
 * @return array
61
 * @see https://searchandfilter.com/
62
 */
63
add_filter('sf_edit_query_args', function ($query) {
64
    if (!empty($query['meta_key']) && '_glsr_ranking' == $query['meta_key']) {
65
        unset($query['meta_key']);
66
        $query['meta_query'] = [
67
            'relation' => 'OR',
68
            ['key' => '_glsr_ranking', 'compare' => 'NOT EXISTS'], // this comes first!
69
            ['key' => '_glsr_ranking', 'compare' => 'EXISTS'],
70
        ];
71
    }
72
    return $query;
73
}, 20);
74
75
/**
76
 * Fix checkboxes for the Divi plugin style
77
 * @param \GeminiLabs\SiteReviews\Modules\Html\Builder $instance
78
 * @return void
79
 * @see https://www.elegantthemes.com/gallery/divi/
80
 */
81
add_action('site-reviews/customize/divi', function ($instance) {
82
    if ('label' == $instance->tag && 'checkbox' == $instance->args['type']) {
83
        $instance->args['text'] = '<i></i>'.$instance->args['text'];
84
        return;
85
    }
86
});
87
88
/**
89
 * Load the Ninja Forms (v3) CSS if the plugin style is selected.
90
 * @see https://ninjaforms.com/
91
 */
92
function glsr_is_ninja_forms_compatible() {
93
    return class_exists('Ninja_Forms')
94
        && class_exists('NF_Display_Render')
95
        && method_exists('Ninja_Forms', 'get_setting')
96
        && method_exists('NF_Display_Render', 'enqueue_styles_display');
97
}
98
add_action('enqueue_block_editor_assets', function () {
99
    if ('ninja_forms' === glsr_get_option('general.style') && glsr_is_ninja_forms_compatible()) {
100
        NF_Display_Render::enqueue_styles_display(Ninja_Forms::$url.'assets/css/');
101
    }
102
});
103
add_filter('site-reviews/config/styles/ninja_forms', function ($config) {
104
    if (glsr_is_ninja_forms_compatible()) {
105
        $formClass = 'nf-style-'.Ninja_Forms()->get_setting('opinionated_styles');
106
        $config = glsr_set($config, 'classes.form', $formClass);
107
    }
108
    return $config;
109
});
110
add_action('site-reviews/customize/ninja_forms', function () {
111
    if (glsr_is_ninja_forms_compatible()) {
112
        NF_Display_Render::enqueue_styles_display(Ninja_Forms::$url.'assets/css/');
113
    }
114
});
115
116
/**
117
 * Purge the W3 Total Cache database and object caches after plugin migrations.
118
 * @return void
119
 * @see https://wordpress.org/plugins/w3-total-cache/
120
 */
121
add_action('site-reviews/migration/end', function () {
122
    if (function_exists('w3tc_dbcache_flush')) {
123
        w3tc_dbcache_flush();
124
    }
125
    if (function_exists('w3tc_objectcache_flush')) {
126
        w3tc_objectcache_flush();
127
    }
128
});
129
130
/**
131
 * Purge the WP-Super-Cache plugin cache after a review has been created.
132
 * @param \GeminiLabs\SiteReviews\Review $review
133
 * @param \GeminiLabs\SiteReviews\Commands\CreateReview $command
134
 * @return void
135
 * @see https://wordpress.org/plugins/wp-super-cache/
136
 */
137
add_action('site-reviews/review/created', function ($review, $command) {
138
    if (!function_exists('wp_cache_post_change')) {
139
        return;
140
    }
141
    wp_cache_post_change($command->post_id);
142
    foreach ($review->assigned_posts as $postId) {
143
        if ($postId != $command->post_id) {
144
            wp_cache_post_change($postId);
145
        }
146
    }
147
}, 10, 2);
148
149
/**
150
 * Purge the Hummingbird page cache after a review has been created.
151
 * @param \GeminiLabs\SiteReviews\Review $review
152
 * @param \GeminiLabs\SiteReviews\Commands\CreateReview $command
153
 * @return void
154
 * @see https://premium.wpmudev.org/docs/api-plugin-development/hummingbird-api-docs/#action-wphb_clear_page_cache
155
 */
156
add_action('site-reviews/review/created', function ($review, $command) {
157
    do_action('wphb_clear_page_cache', $command->post_id);
0 ignored issues
show
The function do_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

157
    /** @scrutinizer ignore-call */ 
158
    do_action('wphb_clear_page_cache', $command->post_id);
Loading history...
158
}, 10, 2);
159
160
/**
161
 * Purge the WP-Optimize page cache after a review has been created.
162
 * @param \GeminiLabs\SiteReviews\Review $review
163
 * @param \GeminiLabs\SiteReviews\Commands\CreateReview $command
164
 * @return void
165
 * @see https://getwpo.com/documentation/#Purging-the-cache-from-an-other-plugin-or-theme
166
 */
167
add_action('site-reviews/review/created', function ($review, $command) {
168
    if (class_exists('WPO_Page_Cache')) {
169
        WPO_Page_Cache::delete_single_post_cache($command->post_id);
170
    }
171
}, 10, 2);
172
173
174
/**
175
 * Fix Star Rating control when review form is used inside an Elementor Pro Popup
176
 * @return void
177
 * @see https://elementor.com/
178
 */
179
add_action('wp_enqueue_scripts', function () {
180
    if (defined('ELEMENTOR_PRO_VERSION') && 0 > version_compare('2.7.0', ELEMENTOR_PRO_VERSION)) {
181
        wp_add_inline_script(glsr()->id,
0 ignored issues
show
The function wp_add_inline_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

181
        /** @scrutinizer ignore-call */ 
182
        wp_add_inline_script(glsr()->id,
Loading history...
182
            '"undefined"!==typeof jQuery&&jQuery(document).on("elementor/popup/show",function(){new GLSR.Forms()})'
183
        );
184
    }
185
}, 1000);
186