| @@ -21,8 +21,22 @@ | ||
| 21 | 21 | add_action( 'init', [ $self, 'apply' ] ); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function apply() { |
| 25 | + // Heartbeat is the one optimization aimed at wp-admin — the API polls | |
| 26 | + // hardest in the editor — so it is wired up before the frontend guard. | |
| 27 | + if ( $this->enabled( 'perf_control_heartbeat' ) ) { | |
| 28 | + add_filter( 'heartbeat_settings', [ $this, 'heartbeat_frequency' ] ); | |
| 29 | + } | |
| 30 | + | |
| 31 | + // Everything below only shaves weight off what a visitor downloads. No | |
| 32 | + // page-speed tool measures wp-admin, so there is nothing to win there | |
| 33 | + // and plenty to break — stripping core assets from the admin costs the | |
| 34 | + // editor its emoji, icons and scripts for zero benefit. Frontend only. | |
| 35 | + if ( is_admin() ) { | |
| 36 | + return; | |
| 37 | + } | |
| 38 | + | |
| 25 | 39 | if ( $this->enabled( 'perf_disable_emojis' ) ) { |
| 26 | 40 | $this->disable_emojis(); |
| 27 | 41 | } |
| 28 | 42 | if ( $this->enabled( 'perf_disable_embeds' ) ) { |
| @@ -36,11 +50,8 @@ | ||
| 36 | 50 | // scripts print) — hooking wp_default_scripts from init is unreliable |
| 37 | 51 | // because it can fire before this callback is registered. |
| 38 | 52 | add_action( 'wp_enqueue_scripts', [ $this, 'remove_jquery_migrate' ], 100 ); |
| 39 | 53 | } |
| 40 | - if ( $this->enabled( 'perf_control_heartbeat' ) ) { | |
| 41 | - add_filter( 'heartbeat_settings', [ $this, 'heartbeat_frequency' ] ); | |
| 42 | - } | |
| 43 | 54 | } |
| 44 | 55 | |
| 45 | 56 | private function enabled( $key ) { |
| 46 | 57 | $value = (bool) Helper::get_settings( $key, false ); |
| @@ -48,24 +59,21 @@ | ||
| 48 | 59 | } |
| 49 | 60 | |
| 50 | 61 | /** |
| 51 | 62 | * Remove the WordPress emoji detection script + styles. |
| 63 | + * | |
| 64 | + * Frontend only — see the guard in apply(). wp-admin keeps core's emoji | |
| 65 | + * support: the detection script is what draws the emoji the viewer's | |
| 66 | + * platform has no glyph for, so unhooking it there just leaves blanks in | |
| 67 | + * the editor, menus and list tables. | |
| 52 | 68 | */ |
| 53 | 69 | public function disable_emojis() { |
| 54 | 70 | remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); |
| 55 | - remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); | |
| 71 | + // Unhooking the back-compat action is also how wp_enqueue_emoji_styles() | |
| 72 | + // (WP 6.4+) decides to skip the inline stylesheet. | |
| 56 | 73 | remove_action( 'wp_print_styles', 'print_emoji_styles' ); |
| 57 | - remove_action( 'admin_print_styles', 'print_emoji_styles' ); | |
| 58 | 74 | remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); |
| 59 | 75 | remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); |
| 60 | - remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); | |
| 61 | - add_filter( 'emoji_svg_url', '__return_false' ); | |
| 62 | - add_filter( | |
| 63 | - 'tiny_mce_plugins', | |
| 64 | - function ( $plugins ) { | |
| 65 | - return is_array( $plugins ) ? array_diff( $plugins, [ 'wpemoji' ] ) : []; | |
| 66 | - } | |
| 67 | - ); | |
| 68 | 76 | } |
| 69 | 77 | |
| 70 | 78 | /** |
| 71 | 79 | * Remove the wp-embed script and oEmbed discovery/host output on the frontend. |