PluginProbe ʕ •ᴥ•ʔ
Admin and Site Enhancements (ASE) / 6.9.1
Admin and Site Enhancements (ASE) v6.9.1
9.1.0 9.0.2 9.0.1 9.0.0 8.9.2 8.9.1 8.9.0 8.8.8 8.8.7 8.8.6 8.8.5 8.8.4 8.8.3 8.8.2 8.8.1 8.8.0 8.7.3 8.7.2 8.7.1 8.2.1 8.2.2 8.2.3 8.3.0 8.3.1 8.3.2 8.4.0 8.4.1 8.4.2 8.5.0 8.5.1 8.5.2 8.6.0 8.6.1 8.6.2 8.7.0 5.0.1 5.0.2 5.0.2.1 5.0.2.2 5.0.2.3 5.0.2.4 5.1.0 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1 5.5.0 5.5.1 5.5.2 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.8.0 5.8.1 6.0.0 6.0.3 6.0.4 6.0.5 6.0.5.1 6.0.6 6.0.7 6.0.8.1 6.1.0 6.1.3 6.2.0 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.2.6 6.2.7 6.3.0 6.3.1 6.3.2 6.4.0 6.5.0 6.5.1 6.6.0 6.7.0 6.8.0 6.8.2 6.8.3 6.9.0 6.9.1 6.9.10 6.9.11 6.9.12 6.9.13.1 6.9.13.2 6.9.2 6.9.3 6.9.4 6.9.5 6.9.6 6.9.7 6.9.8 6.9.9 7.0.0 7.0.2 7.0.2.1 7.0.2.2 7.0.2.3 7.0.3 7.1.0 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2.0 7.2.1 7.3.0 7.3.1 7.3.2 7.3.3 7.4.0 7.4.2 7.4.4 7.4.5 7.4.6 7.4.7 7.4.8 7.5.0 7.5.1 7.5.2 7.5.3 7.5.4 7.6.0 7.6.1 7.6.1.1 7.6.10 7.6.11 7.6.2 7.6.3 7.6.4 7.6.5 7.6.6 7.6.7 7.6.7.1 7.6.8 7.6.9 7.7.0 7.8.0 7.8.1 7.8.10 7.8.11 7.8.12 7.8.13 7.8.14 7.8.15 7.8.16 7.8.17 7.8.18 7.8.2 7.8.3 7.8.4 7.8.5 7.8.5.1 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1 7.9.10 7.9.11 7.9.2 7.9.3 7.9.4 7.9.5 7.9.6 7.9.7 7.9.8 7.9.9 8.0.0 8.0.1 8.0.2 8.0.3 8.0.4 8.0.5 8.0.6 8.0.7 8.0.8 8.1.0 8.1.1 8.1.2 8.1.3 8.1.4 8.2.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.2.0 3.3.0 3.4.0 3.5.0 3.6.1 3.7.0 3.8.0 3.9.0 3.9.1 3.9.2 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.9.0 4.9.1 4.9.2 4.9.3 5.0.0
admin-site-enhancements / classes / class-disable-components.php
admin-site-enhancements / classes Last commit date
class-activation.php 2 years ago class-admin-interface.php 2 years ago class-common-methods.php 2 years ago class-content-management.php 2 years ago class-custom-code.php 2 years ago class-deactivation.php 2 years ago class-disable-components.php 2 years ago class-login-logout.php 2 years ago class-optimizations.php 2 years ago class-security.php 2 years ago class-settings-fields-render.php 2 years ago class-settings-sanitization.php 2 years ago class-settings-sections-fields.php 2 years ago class-utilities.php 2 years ago
class-disable-components.php
637 lines
1 <?php
2
3 namespace ASENHA\Classes;
4 use WP_Error;
5
6 /**
7 * Class related to the Disable Components feature
8 *
9 * @since 2.2.0
10 */
11 class Disable_Components {
12
13 /**
14 * Disable comments for post types
15 *
16 * @since 2.7.0
17 */
18 public function disable_comments_for_post_types_edit() {
19
20 $options = get_option( ASENHA_SLUG_U );
21 $disable_comments_for = $options['disable_comments_for'];
22
23 foreach ( $disable_comments_for as $post_type_slug => $is_commenting_disabled ) {
24 if ( $is_commenting_disabled ) {
25 remove_post_type_support( $post_type_slug, 'comments' );
26 remove_post_type_support( $post_type_slug, 'trackbacks' );
27 remove_meta_box( 'commentstatusdiv', $post_type_slug, 'normal' );
28 remove_meta_box( 'commentstatusdiv', $post_type_slug, 'side' );
29 remove_meta_box( 'commentsdiv', $post_type_slug, 'normal' );
30 remove_meta_box( 'commentsdiv', $post_type_slug, 'side' );
31 remove_meta_box( 'trackbacksdiv', $post_type_slug, 'normal' );
32 remove_meta_box( 'trackbacksdiv', $post_type_slug, 'side' );
33 // edit-comments.js
34 wp_dequeue_script( 'admin-comments' );
35 }
36 }
37
38 }
39
40 /**
41 * Hide existing comments from the frontend post
42 *
43 * @since 6.2.1
44 */
45 public function hide_existing_comments_on_frontend() {
46 $options = get_option( ASENHA_SLUG_U );
47 $disable_comments_for = $options['disable_comments_for'];
48 $current_post_type = get_post_type();
49
50 foreach ( $disable_comments_for as $post_type_slug => $is_commenting_disabled ) {
51 if ( ( $current_post_type === $post_type_slug ) && $is_commenting_disabled ) {
52 add_filter( 'comments_array', '__return_empty_array', 10, 2 );
53 }
54 }
55 }
56
57 /**
58 * Return empty comments array for comment templates
59 *
60 * @since 6.3.1
61 */
62 public function maybe_return_empty_comments( $comments, $post_id ) {
63 $options = get_option( ASENHA_SLUG_U );
64 $disable_comments_for = $options['disable_comments_for'];
65 $post = get_post( $post_id );
66 $current_post_type = $post->post_type;
67
68 foreach ( $disable_comments_for as $post_type_slug => $is_commenting_disabled ) {
69 if ( ( $current_post_type === $post_type_slug ) && $is_commenting_disabled ) {
70 return array();
71 } else {
72 return $comments;
73 }
74 }
75 }
76
77 /**
78 * Close commenting on the frontend
79 *
80 * @since 2.7.0
81 */
82 public function close_comments_pings_on_frontend( $comments_pings_open, $post_id ) {
83 // If commenting or pinging is not open, let's keep it that way
84 if ( ! $comments_pings_open ) {
85 return $comments_pings_open;
86 }
87
88 // Commenting or pinging is open for the post ID, let's decide if we should close it
89 $options = get_option( ASENHA_SLUG_U );
90 $disable_comments_for = $options['disable_comments_for'];
91 $post = get_post( $post_id );
92 $current_post_type = $post->post_type;
93
94 foreach ( $disable_comments_for as $post_type_slug => $is_commenting_disabled ) {
95 if ( ( $current_post_type === $post_type_slug ) && $is_commenting_disabled ) {
96 return false;
97 }
98 }
99
100 return $comments_pings_open;
101 }
102
103 /**
104 * Always return zero for comments count on a post where the post type has commenting disabled
105 *
106 * @since 6.2.7
107 */
108 public function return_zero_comments_count( $comments_number, $post_id ) {
109
110 $options = get_option( ASENHA_SLUG_U );
111 $disable_comments_for = $options['disable_comments_for'];
112 $post = get_post( $post_id );
113
114 if ( is_object( $post ) && property_exists( $post, 'post_type' ) ) {
115 $current_post_type = $post->post_type;
116
117 foreach ( $disable_comments_for as $post_type_slug => $is_commenting_disabled ) {
118 if ( ( $current_post_type === $post_type_slug ) && $is_commenting_disabled ) {
119 return 0;
120 }
121 }
122 }
123
124 return $comments_number;
125 }
126
127 /**
128 * Disable commenting via XML-RPC
129 *
130 * @link https://plugins.trac.wordpress.org/browser/disable-comments/tags/2.4.5/disable-comments.php
131 * @since 6.3.1
132 */
133 public function disable_xmlrpc_comments( $methods ) {
134 unset( $methods['wp.newComment'] );
135 return $methods;
136 }
137
138 /**
139 * Disables comments endpoint in REST API
140 *
141 * @link https://plugins.trac.wordpress.org/browser/disable-comments/tags/2.4.5/disable-comments.php
142 * @since 6.3.1
143 */
144 public function disable_rest_api_comments_endpoints( $endpoints ) {
145 if ( isset( $endpoints['comments'] ) ) {
146 unset( $endpoints['comments'] );
147 }
148
149 if ( isset( $endpoints['/wp/v2/comments'] ) ) {
150 unset( $endpoints['/wp/v2/comments'] );
151 }
152
153 if ( isset( $endpoints['/wp/v2/comments/(?P<id>[\d]+)'] ) ) {
154 unset( $endpoints['/wp/v2/comments/(?P<id>[\d]+)'] );
155 }
156
157 return $endpoints;
158 }
159
160 /**
161 * Return blank comment before inserting to DB
162 *
163 * @link https://plugins.trac.wordpress.org/browser/disable-comments/tags/2.4.5/disable-comments.php
164 * @since 6.3.1
165 */
166 public function return_blank_comment( $prepared_comment, $request ) {
167 return;
168 }
169
170 /**
171 * Show blank template on singular views when comment is disabled
172 *
173 * @since 4.9.2
174 */
175 public function show_blank_comment_template() {
176
177 $options = get_option( ASENHA_SLUG_U );
178 $disable_comments_for = $options['disable_comments_for'];
179 $current_post_type = get_post_type();
180
181 foreach ( $disable_comments_for as $post_type_slug => $is_commenting_disabled ) {
182 if ( ( $current_post_type === $post_type_slug ) && $is_commenting_disabled ) {
183
184 if ( is_singular() ) {
185 add_filter( 'comments_template', [ $this, 'load_blank_comment_template' ], 20 );
186 }
187
188 }
189 }
190
191 }
192
193 /**
194 * Load the actual blank comment template
195 *
196 * @since 4.9.2
197 */
198 public function load_blank_comment_template() {
199 return ASENHA_PATH . 'includes/blank-comment-template.php';
200 }
201
202 /**
203 * Disable Gutenberg in wp-admin for some or all post types
204 *
205 * @since 2.8.0
206 */
207 public function disable_gutenberg_for_post_types_admin() {
208
209 // Get current page's post type from WP core globals and query parameters
210
211 global $pagenow, $typenow;
212
213 $post_type = null;
214
215 if ( 'edit.php' === $pagenow ) { // on the list table screen, $typenow returns correct post type
216
217 $post_type = $typenow;
218
219 } elseif ( 'post.php' === $pagenow ) { // on the edit screen, $typenow is empty, so we detect it
220
221 $post_type = isset( $_GET['post'] ) ? get_post_type( $_GET['post'] ) : 'post';
222
223 } elseif ( 'post-new.php' === $pagenow ) { // on the add new screen, best to get post type from GET parameter
224
225 $post_type = isset( $_GET['post_type'] ) ? $_GET['post_type'] : 'post';
226
227 } else {}
228
229 // Check if Gutenberg feature is enabled for the site
230
231 // Before/after WP v5.0.0 via feature plugin
232 $gutenberg = function_exists( 'gutenberg_register_scripts_and_styles' );
233
234 // Since WP v5.0.0, gutenberg is in core
235 $block_editor = has_action( 'enqueue_block_assets' );
236
237 // Gutenberg feature is not enabled for the site
238 if ( ! $gutenberg && ( false === $block_editor ) ) {
239 return; // do nothing
240 }
241
242 // Assemble single-dimensional array of post types for which Gutenberg should be disabled
243 $options = get_option( ASENHA_SLUG_U );
244 $disable_gutenberg_for = $options['disable_gutenberg_for'];
245 $post_types_for_disable_gutenberg = array();
246
247 foreach( $disable_gutenberg_for as $post_type_slug => $is_gutenberg_disabled ) {
248 if ( $is_gutenberg_disabled ) {
249 $post_types_for_disable_gutenberg[] = $post_type_slug;
250 }
251 }
252
253 // Selectively disable Gutenberg
254 if ( in_array( $post_type, $post_types_for_disable_gutenberg ) ) {
255
256 // For WP v5.0.0 upwards
257 add_filter( 'use_block_editor_for_post_type', '__return_false', 100 );
258
259 // If Gutenberg feature plugin is activated
260 if ( $gutenberg ) {
261 add_filter( 'gutenberg_can_edit_post_type', '__return_false', 100 );
262 $this->remove_all_gutenberg_hook();
263 }
264
265 }
266
267 }
268
269 /**
270 * Remove Gutenberg hooks added via feature plugin.
271 *
272 * @link https://plugins.trac.wordpress.org/browser/classic-editor/tags/1.6.2/classic-editor.php#L138
273 * @since 2.8.0
274 */
275 public function remove_all_gutenberg_hooks() {
276
277 remove_action( 'admin_menu', 'gutenberg_menu' );
278 remove_action( 'admin_init', 'gutenberg_redirect_demo' );
279
280 // Gutenberg 5.3+
281 remove_action( 'wp_enqueue_scripts', 'gutenberg_register_scripts_and_styles' );
282 remove_action( 'admin_enqueue_scripts', 'gutenberg_register_scripts_and_styles' );
283 remove_action( 'admin_notices', 'gutenberg_wordpress_version_notice' );
284 remove_action( 'rest_api_init', 'gutenberg_register_rest_widget_updater_routes' );
285 remove_action( 'admin_print_styles', 'gutenberg_block_editor_admin_print_styles' );
286 remove_action( 'admin_print_scripts', 'gutenberg_block_editor_admin_print_scripts' );
287 remove_action( 'admin_print_footer_scripts', 'gutenberg_block_editor_admin_print_footer_scripts' );
288 remove_action( 'admin_footer', 'gutenberg_block_editor_admin_footer' );
289 remove_action( 'admin_enqueue_scripts', 'gutenberg_widgets_init' );
290 remove_action( 'admin_notices', 'gutenberg_build_files_notice' );
291
292 remove_filter( 'load_script_translation_file', 'gutenberg_override_translation_file' );
293 remove_filter( 'block_editor_settings', 'gutenberg_extend_block_editor_styles' );
294 remove_filter( 'default_content', 'gutenberg_default_demo_content' );
295 remove_filter( 'default_title', 'gutenberg_default_demo_title' );
296 remove_filter( 'block_editor_settings', 'gutenberg_legacy_widget_settings' );
297 remove_filter( 'rest_request_after_callbacks', 'gutenberg_filter_oembed_result' );
298
299 // Previously used, compat for older Gutenberg versions.
300 remove_filter( 'wp_refresh_nonces', 'gutenberg_add_rest_nonce_to_heartbeat_response_headers' );
301 remove_filter( 'get_edit_post_link', 'gutenberg_revisions_link_to_editor' );
302 remove_filter( 'wp_prepare_revision_for_js', 'gutenberg_revisions_restore' );
303
304 remove_action( 'rest_api_init', 'gutenberg_register_rest_routes' );
305 remove_action( 'rest_api_init', 'gutenberg_add_taxonomy_visibility_field' );
306 remove_filter( 'registered_post_type', 'gutenberg_register_post_prepare_functions' );
307
308 remove_action( 'do_meta_boxes', 'gutenberg_meta_box_save' );
309 remove_action( 'submitpost_box', 'gutenberg_intercept_meta_box_render' );
310 remove_action( 'submitpage_box', 'gutenberg_intercept_meta_box_render' );
311 remove_action( 'edit_page_form', 'gutenberg_intercept_meta_box_render' );
312 remove_action( 'edit_form_advanced', 'gutenberg_intercept_meta_box_render' );
313 remove_filter( 'redirect_post_location', 'gutenberg_meta_box_save_redirect' );
314 remove_filter( 'filter_gutenberg_meta_boxes', 'gutenberg_filter_meta_boxes' );
315
316 remove_filter( 'body_class', 'gutenberg_add_responsive_body_class' );
317 remove_filter( 'admin_url', 'gutenberg_modify_add_new_button_url' ); // old
318 remove_action( 'admin_enqueue_scripts', 'gutenberg_check_if_classic_needs_warning_about_blocks' );
319 remove_filter( 'register_post_type_args', 'gutenberg_filter_post_type_labels' );
320 }
321
322 /**
323 * Disable Gutenberg styles and scripts on the front end for all or some post types
324 *
325 * @since 2.8.0
326 */
327 public function disable_gutenberg_for_post_types_frontend() {
328
329 $post = get_queried_object();
330
331 if ( ! is_null( $post ) ) {
332 if ( property_exists( $post, 'post_type' ) ) {
333
334 $post_type = $post->post_type;
335
336 // Assemble single-dimensional array of post types for which Gutenberg should be disabled
337 $options = get_option( ASENHA_SLUG_U );
338 $disable_gutenberg_for = $options['disable_gutenberg_for'];
339 $post_types_for_disable_gutenberg = array();
340
341 foreach( $disable_gutenberg_for as $post_type_slug => $is_gutenberg_disabled ) {
342 if ( $is_gutenberg_disabled ) {
343 $post_types_for_disable_gutenberg[] = $post_type_slug;
344 }
345 }
346
347 // Selectively disable for the selected post types
348 if ( in_array( $post_type, $post_types_for_disable_gutenberg ) ) {
349
350 global $wp_styles;
351
352 // As needed, exclude some block styles from dequeuing
353 $keep_enqueued = array(); // e.g. array( 'wp-block-navigation' );
354
355 foreach ( $wp_styles->queue as $handle ) {
356
357 // For all stye handles that starts with 'wp-block'
358 if ( false !== strpos( $handle, 'wp-block' ) ) {
359
360 if ( ! in_array( $handle, $keep_enqueued ) ) {
361 wp_dequeue_style( $handle );
362 }
363
364 }
365
366 }
367
368 // Additional dequeuing
369 wp_dequeue_style( 'core-block-supports' );
370 wp_dequeue_style( 'global-styles' ); // theme.json
371 wp_dequeue_style( 'classic-theme-styles' ); // classic theme
372
373 }
374
375 }
376 }
377
378 }
379
380 /**
381 * Disable REST API for non-authenticated users. This is for WP v4.7 or later.
382 *
383 * @since 2.9.0
384 */
385 public function disable_rest_api() {
386
387 if ( ! is_user_logged_in() ) {
388
389 return new WP_Error(
390 'rest_api_authentication_required',
391 'The REST API has been restricted to authenticated users.',
392 array(
393 'status' => rest_authorization_required_code()
394 )
395 );
396
397 }
398
399 }
400
401 /**
402 * Ensure /feed/ page outputs a 403 Forbidden header and message
403 *
404 * @since 5.5.2
405 */
406 public function redirect_feed_to_403() {
407 if ( is_feed() ) {
408 status_header( 403 ); // Send an HTTP 403 Forbidden status header
409 die( '403 Forbidden' ); // End execution and display a 403 Forbidden message
410 }
411 }
412
413 /**
414 * Disable updates and related functionalities
415 *
416 * @since 4.0.0
417 */
418 public function disable_update_notices_version_checks() {
419
420 // Remove nags
421 remove_action( 'admin_notices', 'update_nag', 3 );
422 remove_action( 'admin_notices', 'maintenance_nag' );
423
424 // Disable WP version check
425 remove_action( 'wp_version_check', 'wp_version_check' );
426 remove_action( 'admin_init', 'wp_version_check' );
427 wp_clear_scheduled_hook( 'wp_version_check' );
428
429 add_filter( 'pre_option_update_core', '__return_null' );
430
431 // Disable theme version checks
432 remove_action( 'wp_update_themes', 'wp_update_themes' );
433 remove_action( 'admin_init', '_maybe_update_themes' );
434 wp_clear_scheduled_hook( 'wp_update_themes' );
435
436 remove_action( 'load-themes.php', 'wp_update_themes' );
437 remove_action( 'load-update.php', 'wp_update_themes' );
438 remove_action( 'load-update-core.php', 'wp_update_themes' );
439
440 // Disable plugin version checks
441 remove_action( 'wp_update_plugins', 'wp_update_plugins' );
442 remove_action( 'admin_init', '_maybe_update_plugins' );
443 wp_clear_scheduled_hook( 'wp_update_plugins' );
444
445 remove_action( 'load-plugins.php', 'wp_update_plugins' );
446 remove_action( 'load-update.php', 'wp_update_plugins' );
447 remove_action( 'load-update-core.php', 'wp_update_plugins' );
448
449 // Disable auto updates
450 wp_clear_scheduled_hook( 'wp_maybe_auto_update' );
451
452 remove_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' );
453 remove_action( 'admin_init', 'wp_maybe_auto_update' );
454 remove_action( 'admin_init', 'wp_auto_update_core' );
455
456 // Disable Site Health checks
457 add_filter( 'site_status_tests', [ $this, 'disable_update_checks_in_site_health' ] );
458
459 }
460
461 /**
462 * Override version check info stored in transients named update_core, update_plugins, update_themes.
463 *
464 * @since 4.0.0
465 */
466 public function override_version_check_info() {
467
468 include( ABSPATH . WPINC . '/version.php' ); // get $wp_version from here
469
470 $current = (object)array(); // create empty object
471 $current->updates = array();
472 $current->response = array();
473 $current->version_checked = $wp_version;
474 $current->last_checked = time();
475
476 return $current;
477
478 }
479
480 /**
481 * Disable Background Updates and Auto-Updates tests in Site Health tests
482 *
483 * @since 4.0.0
484 */
485 public function disable_update_checks_in_site_health( $tests ) {
486
487 unset( $tests['async']['background_updates'] );
488 unset( $tests['direct']['plugin_theme_auto_updates'] );
489
490 return $tests;
491
492 }
493
494 /**
495 * Remove Dashboard >> Updates menu item
496 *
497 * @since 4.0.0
498 */
499 public function remove_updates_menu() {
500 global $submenu;
501 remove_submenu_page( 'index.php', 'update-core.php' );
502 }
503
504 /**
505 * Remove version number from URLs of static resources (CSS, JS)
506 *
507 * @since 5.8.0
508 */
509 public function remove_resource_version_number( $src ) {
510 if ( ! is_user_logged_in() ) {
511 if ( strpos( $src, '?ver=' ) ) {
512 $src = remove_query_arg( 'ver', $src );
513 }
514 }
515 return $src;
516 }
517
518 /**
519 * Disable loading of frontend public assets of dashicons
520 *
521 * @since 4.5.0
522 */
523 public function disable_dashicons_public_assets() {
524 global $pagenow;
525 if ( ! is_user_logged_in() ) {
526
527 // This will get /path/file.php?param=val portion of the full URL
528 $current_request_uri = sanitize_text_field( $_SERVER['REQUEST_URI'] );
529
530 if ( empty( $current_request_uri ) ) {
531 // On the homepage
532 wp_dequeue_style( 'dashicons' );
533 wp_deregister_style( 'dashicons' );
534 } else {
535 // Exclude the login page, where dashicon assets are requred to properly style the page
536 if ( false !== strpos( $current_request_uri, 'wp-login.php' ) || 'wp-login.php' === $pagenow ) {
537 // On wp-login.php, so, do nothing
538 }
539 // Exclude password protection form
540 elseif ( false !== strpos( $current_request_uri, 'protected-page=view' ) ) {
541 // On protected-page=view, so, do nothing
542 }
543 else {
544 // NOT on wp-login.php, e.g. www.example.com/an-article/, so, dequeue dashicons
545 wp_dequeue_style( 'dashicons' );
546 wp_deregister_style( 'dashicons' );
547 }
548 }
549 }
550 }
551
552 /**
553 * Disable emoji support
554 *
555 * @since 4.5.0
556 */
557 public function disable_emoji_support() {
558
559 remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
560 remove_action( 'embed_head', 'print_emoji_detection_script' );
561 remove_action( 'wp_print_styles', 'print_emoji_styles' );
562 remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
563 remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
564 remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
565 add_action( 'admin_init', [ $this, 'disable_admin_emojis' ] );
566 add_filter( 'emoji_svg_url', '__return_false' );
567 add_filter( 'tiny_mce_plugins', [ $this, 'disable_emoji_for_tinymce' ] );
568 add_filter( 'wp_resource_hints', [ $this, 'disable_emoji_remove_dns_prefetch' ], 10, 2 );
569
570 }
571
572 /**
573 * Disable jQuery Migrate
574 *
575 * @since 5.8.0
576 * @link https://plugins.trac.wordpress.org/browser/remove-jquery-migrate/trunk/remove-jquery-migrate.php
577 * @param WP_Scripts $scripts WP_Scripts object.
578 */
579 public function disable_jquery_migrate( $scripts ) {
580 if ( ! is_admin() && isset( $scripts->registered['jquery'] ) ) {
581 $script = $scripts->registered['jquery'];
582
583 if ( ! empty( $script->deps ) ) { // Check whether the script has any dependencies
584 $script->deps = array_diff( $script->deps, array( 'jquery-migrate' ) );
585 }
586 }
587 }
588
589 /**
590 * Remove the tinymce emoji plugin
591 *
592 * @since 4.5.0
593 */
594 public function disable_emoji_for_tinymce( $plugins ) {
595
596 if ( is_array( $plugins ) ) {
597 return array_diff( $plugins, array( 'wpemoji' ) );
598 }
599
600 return array();
601
602 }
603
604 /**
605 * Remove emoji CDN hostname from DNS prefetching hints.
606 *
607 * @since 4.5.0
608 */
609 public function disable_emoji_remove_dns_prefetch( $urls, $relation_type ) {
610
611 if ( 'dns-prefetch' == $relation_type ) {
612
613 // Strip out any URLs referencing the WordPress.org emoji location
614 $emoji_svg_url_base = 'https://s.w.org/images/core/emoji/';
615 foreach ( $urls as $key => $url ) {
616 if ( is_string( $url ) && false !== strpos( $url, $emoji_svg_url_base ) ) {
617 unset( $urls[$key] );
618 }
619 }
620
621 }
622
623 return $urls;
624
625 }
626
627 /**
628 * Disable emojis in wp-admin
629 *
630 * @since 4.7.2
631 */
632 public function disable_admin_emojis() {
633 remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
634 remove_action( 'admin_print_styles', 'print_emoji_styles' );
635 }
636
637 }