1 | <?php |
||
2 | |||
3 | use GeminiLabs\SiteReviews\Application; |
||
4 | use GeminiLabs\SiteReviews\Compatibility; |
||
5 | use GeminiLabs\SiteReviews\Contracts\BuilderContract; |
||
6 | use GeminiLabs\SiteReviews\Database\ReviewManager; |
||
7 | use GeminiLabs\SiteReviews\Modules\Paginate; |
||
8 | use GeminiLabs\SiteReviews\Review; |
||
9 | |||
10 | defined('ABSPATH') || exit; |
||
11 | |||
12 | /** |
||
13 | * This fixes the Site Reviews settings when the User Activity Log plugin is enabled. |
||
14 | * |
||
15 | * @see https://wordpress.org/support/topic/this-breaks-the-wordpress-color-picker/ |
||
16 | */ |
||
17 | add_action('admin_enqueue_scripts', function () { |
||
18 | $screen = get_current_screen(); |
||
1 ignored issue
–
show
|
|||
19 | if (str_starts_with($screen->post_type, glsr()->post_type)) { |
||
20 | wp_dequeue_script('chats-js'); |
||
21 | } |
||
22 | }, 20); |
||
23 | |||
24 | /** |
||
25 | * This fixes the button classes in themes using the Avia framework. |
||
26 | * |
||
27 | * @see https://kriesi.at/themes/enfold-overview/ |
||
28 | */ |
||
29 | function glsr_filter_avia_button_classes(array $defaults): array |
||
30 | { |
||
31 | $defaults['button'] = 'glsr-button avia-button avia-color-theme-color'; |
||
32 | return $defaults; |
||
33 | } |
||
34 | add_action('avia_action_before_framework_init', function () { |
||
35 | add_filter('site-reviews/defaults/style-classes/defaults', 'glsr_filter_avia_button_classes'); |
||
36 | }); |
||
37 | |||
38 | /** |
||
39 | * This fixes the Duplicate option provided by the Enfold theme. |
||
40 | * |
||
41 | * @see https://kriesi.at/themes/enfold-overview/ |
||
42 | */ |
||
43 | add_action('avf_duplicate_post_added', function ($newPostId, $post) { |
||
44 | if (!Review::isReview($post)) { |
||
45 | return; |
||
46 | } |
||
47 | $review = glsr_get_review($post->ID); |
||
48 | if ($review->isValid()) { |
||
49 | glsr(ReviewManager::class)->createFromPost((int) $newPostId, $review->toArray()); |
||
50 | } |
||
51 | }, 10, 2); |
||
52 | |||
53 | /** |
||
54 | * Classic Editor. |
||
55 | * |
||
56 | * @return array |
||
57 | * |
||
58 | * @see https://wordpress.org/plugins/classic-editor/ |
||
59 | */ |
||
60 | add_action('edit_form_top', function ($post) { |
||
61 | if (class_exists('Classic_Editor') && glsr()->post_type === get_post_type($post)) { |
||
62 | remove_action('edit_form_top', ['Classic_Editor', 'remember_classic_editor']); |
||
63 | } |
||
64 | }, 0); |
||
65 | |||
66 | /** |
||
67 | * Bootstrap pagination. |
||
68 | * |
||
69 | * @filter site-reviews/paginate_link |
||
70 | */ |
||
71 | function glsr_filter_bootstrap_pagination_link(array $link, array $args, BuilderContract $builder): array |
||
72 | { |
||
73 | $args['class'] = 'page-link'; |
||
74 | if ('current' === $link['type']) { |
||
75 | $class = 'page-item active'; |
||
76 | $text = $builder->span($args); |
||
77 | } |
||
78 | if ('dots' === $link['type']) { |
||
79 | $text = $builder->span($args); |
||
80 | } |
||
81 | $link['link'] = $builder->li([ |
||
82 | 'text' => $text ?? $builder->a($args), |
||
83 | 'class' => $class ?? 'page-item', |
||
84 | ]); |
||
85 | return $link; |
||
86 | } |
||
87 | add_filter('site-reviews/paginate_links', function (string $links, array $args): string { |
||
88 | if ('bootstrap' !== glsr_get_option('general.style')) { |
||
89 | return $links; |
||
90 | } |
||
91 | $args = wp_parse_args(['mid_size' => 1], $args); |
||
92 | add_filter('site-reviews/paginate_link', 'glsr_filter_bootstrap_pagination_link', 10, 3); |
||
93 | $links = (new Paginate($args))->links(); |
||
94 | remove_filter('site-reviews/paginate_link', 'glsr_filter_bootstrap_pagination_link'); |
||
95 | $links = wp_list_pluck($links, 'link'); |
||
96 | return implode("\n", $links); |
||
97 | }, 10, 2); |
||
98 | |||
99 | /** |
||
100 | * @param array $editors |
||
101 | * @param string $postType |
||
102 | * |
||
103 | * @return array |
||
104 | * |
||
105 | * @see https://wordpress.org/plugins/classic-editor/ |
||
106 | */ |
||
107 | add_filter('classic_editor_enabled_editors_for_post_type', function ($editors, $postType) { |
||
108 | return glsr()->post_type === $postType |
||
109 | ? ['block_editor' => false, 'classic_editor' => false] |
||
110 | : $editors; |
||
111 | }, 10, 2); |
||
112 | |||
113 | /** |
||
114 | * Add human-readable capability names. |
||
115 | * |
||
116 | * @return void |
||
117 | * |
||
118 | * @see https://wordpress.org/plugins/members/ |
||
119 | */ |
||
120 | add_action('members_register_caps', function () { |
||
121 | $labels = [ |
||
122 | 'create_site-reviews' => _x('Create Reviews', 'admin-text', 'site-reviews'), |
||
123 | 'delete_others_site-reviews' => _x("Delete Others' Reviews", 'admin-text', 'site-reviews'), |
||
124 | 'delete_site-reviews' => _x('Delete Reviews', 'admin-text', 'site-reviews'), |
||
125 | 'delete_private_site-reviews' => _x('Delete Private Reviews', 'admin-text', 'site-reviews'), |
||
126 | 'delete_published_site-reviews' => _x('Delete Approved Reviews', 'admin-text', 'site-reviews'), |
||
127 | 'edit_others_site-reviews' => _x("Edit Others' Reviews", 'admin-text', 'site-reviews'), |
||
128 | 'edit_site-reviews' => _x('Edit Reviews', 'admin-text', 'site-reviews'), |
||
129 | 'edit_private_site-reviews' => _x('Edit Private Reviews', 'admin-text', 'site-reviews'), |
||
130 | 'edit_published_site-reviews' => _x('Edit Approved Reviews', 'admin-text', 'site-reviews'), |
||
131 | 'publish_site-reviews' => _x('Approve Reviews', 'admin-text', 'site-reviews'), |
||
132 | 'read_private_site-reviews' => _x('Read Private Reviews', 'admin-text', 'site-reviews'), |
||
133 | 'respond_to_site-reviews' => _x('Respond To Reviews', 'admin-text', 'site-reviews'), |
||
134 | 'respond_to_others_site-reviews' => _x("Respond To Others' Reviews", 'admin-text', 'site-reviews'), |
||
135 | 'assign_site-review_terms' => _x('Assign Review Categories', 'admin-text', 'site-reviews'), |
||
136 | 'delete_site-review_terms' => _x('Delete Review Categories', 'admin-text', 'site-reviews'), |
||
137 | 'edit_site-review_terms' => _x('Edit Review Categories', 'admin-text', 'site-reviews'), |
||
138 | 'manage_site-review_terms' => _x('Manage Review Categories', 'admin-text', 'site-reviews'), |
||
139 | ]; |
||
140 | array_walk($labels, function ($label, $capability) { |
||
141 | members_register_cap($capability, ['label' => $label]); |
||
142 | }); |
||
143 | }); |
||
144 | |||
145 | /** |
||
146 | * Remove Oxygen Builder metabox from reviews. |
||
147 | * |
||
148 | * @see https://oxygenbuilder.com |
||
149 | */ |
||
150 | add_action('plugins_loaded', function () { |
||
151 | global $ct_ignore_post_types; |
||
152 | if (!empty($ct_ignore_post_types) && is_array($ct_ignore_post_types)) { |
||
153 | $ct_ignore_post_types[] = Application::POST_TYPE; |
||
154 | add_filter('pre_option_oxygen_vsb_ignore_post_type_'.Application::POST_TYPE, '__return_true'); |
||
155 | } |
||
156 | }); |
||
157 | |||
158 | /** |
||
159 | * Fix to display all reviews when sorting by rank. |
||
160 | * |
||
161 | * @param array $query |
||
162 | * |
||
163 | * @return array |
||
164 | * |
||
165 | * @see https://searchandfilter.com/ |
||
166 | */ |
||
167 | add_filter('sf_edit_query_args', function ($query) { |
||
168 | if (!empty($query['meta_key']) && '_glsr_ranking' === $query['meta_key']) { |
||
169 | unset($query['meta_key']); |
||
170 | $query['meta_query'] = [ |
||
171 | 'relation' => 'OR', |
||
172 | ['key' => '_glsr_ranking', 'compare' => 'NOT EXISTS'], // this comes first! |
||
173 | ['key' => '_glsr_ranking', 'compare' => 'EXISTS'], |
||
174 | ]; |
||
175 | } |
||
176 | return $query; |
||
177 | }, 20); |
||
178 | |||
179 | /** |
||
180 | * Prevent SG Optimizer from breaking the Site Reviews javascript file. |
||
181 | * |
||
182 | * @param array $excluded |
||
183 | * |
||
184 | * @return array |
||
185 | * |
||
186 | * @see https://wordpress.org/plugins/sg-cachepress/ |
||
187 | */ |
||
188 | add_filter('sgo_js_minify_exclude', function ($excluded) { |
||
189 | if (is_array($excluded) && !in_array(glsr()->id, $excluded)) { |
||
190 | $excluded[] = glsr()->id; |
||
191 | } |
||
192 | return $excluded; |
||
193 | }); |
||
194 | |||
195 | /** |
||
196 | * Load the Ninja Forms (v3) CSS if the plugin style is selected. |
||
197 | * |
||
198 | * @see https://ninjaforms.com/ |
||
199 | */ |
||
200 | function glsr_is_ninja_forms_compatible(): bool |
||
201 | { |
||
202 | return class_exists('Ninja_Forms') |
||
203 | && class_exists('NF_Display_Render') |
||
204 | && method_exists('Ninja_Forms', 'get_setting') |
||
205 | && method_exists('NF_Display_Render', 'enqueue_styles_display'); |
||
206 | } |
||
207 | function glsr_load_ninja_forms_css(): void |
||
208 | { |
||
209 | if ('ninja_forms' === glsr_get_option('general.style') && glsr_is_ninja_forms_compatible()) { |
||
210 | NF_Display_Render::enqueue_styles_display(Ninja_Forms::$url.'assets/css/'); |
||
211 | } |
||
212 | } |
||
213 | add_action('enqueue_block_editor_assets', 'glsr_load_ninja_forms_css'); |
||
214 | add_action('wp_enqueue_scripts', 'glsr_load_ninja_forms_css'); |
||
215 | add_filter('site-reviews/config/styles/ninja_forms', function (array $config): array { |
||
216 | if (glsr_is_ninja_forms_compatible()) { |
||
217 | $formClass = 'nf-style-'.Ninja_Forms()->get_setting('opinionated_styles'); |
||
218 | $config = glsr_set($config, 'classes.form', $formClass); |
||
219 | } |
||
220 | return $config; |
||
221 | }); |
||
222 | |||
223 | /** |
||
224 | * Load the WPForms stylesheet when using the WPForms plugin style. |
||
225 | * |
||
226 | * @see https://wordpress.org/plugins/wpforms-lite/ |
||
227 | */ |
||
228 | add_filter('site-reviews/build/template/reviews-form', function (string $template): string { |
||
229 | if ('wpforms' === glsr_get_option('general.style')) { |
||
230 | add_filter('wpforms_frontend_missing_assets_error_js_disable', '__return_true', PHP_INT_MAX); |
||
231 | add_filter('wpforms_global_assets', '__return_true'); |
||
232 | } |
||
233 | return $template; |
||
234 | }); |
||
235 | |||
236 | /** |
||
237 | * Remove the "Launch Thrive Architect" button from reviews. |
||
238 | * |
||
239 | * @return array |
||
240 | * |
||
241 | * @see https://thrivethemes.com/architect/ |
||
242 | */ |
||
243 | add_filter('tcb_post_types', function ($blacklist) { |
||
244 | $blacklist[] = glsr()->post_type; |
||
245 | return $blacklist; |
||
246 | }); |
||
247 | |||
248 | /** |
||
249 | * This disables OptimizePress v2 assets an notices on Site Reviews admin pages. |
||
250 | */ |
||
251 | function glsr_remove_optimizepress() |
||
252 | { |
||
253 | if (!defined('OP_VERSION')) { |
||
254 | return; |
||
255 | } |
||
256 | if (!str_starts_with(glsr_current_screen()->post_type, glsr()->post_type)) { |
||
257 | return; |
||
258 | } |
||
259 | glsr(Compatibility::class)->removeHook('admin_enqueue_scripts', 'print_scripts', '\OptimizePress_Admin_Init'); |
||
260 | remove_action('admin_notices', 'checkApiKeyValidity'); |
||
261 | remove_action('admin_notices', 'checkEligibility'); |
||
262 | remove_action('admin_notices', 'compatibilityCheck'); |
||
263 | remove_action('admin_notices', 'goToWebinarNewAPI'); |
||
264 | remove_action('admin_notices', 'pluginAndThemeAreRunning'); |
||
265 | remove_action('admin_notices', 'update_nag_screen'); |
||
266 | remove_filter('use_block_editor_for_post_type', 'op2_disable_gutenberg', 100); |
||
267 | remove_filter('gutenberg_can_edit_post', 'op2_disable_gutenberg'); |
||
268 | } |
||
269 | |||
270 | add_action('load-post.php', 'glsr_remove_optimizepress'); |
||
271 | add_action('load-post-new.php', 'glsr_remove_optimizepress'); |
||
272 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.