features-performance.php
Performance features
Emoji, self pingbacks, asset versions, post embeds, comment-reply, dashicons, block library CSS, global styles, heartbeat, revisions and the autosave interval.
Hooks are only added for features whose value is active. Role-scoped features decide inside their callbacks, where the current user is known; global features act for everyone. Every hook name and priority below was checked against the WordPress 7.1.3 source.
Tags
Table of Contents
Constants
- AUTOSAVE_INTERVAL : mixed = $settings['autosave_interval']
Functions
- jpkcom_harden_trim_register_performance_features() : void
- Register the hooks of the active performance features.
- jpkcom_harden_trim_remove_emoji() : void
- Remove the emoji detection script and styles for the current request.
- jpkcom_harden_trim_filter_tinymce_plugins() : mixed
- Drop the TinyMCE `wpemoji` plugin (classic editor and Classic block).
- jpkcom_harden_trim_normalized_host() : string
- Lowercase ASCII host of a URL without a leading `www.`.
- jpkcom_harden_trim_url_path() : string
- Lowercase path of a URL without trailing slashes ('' for the root).
- jpkcom_harden_trim_sibling_site_paths() : array<int, string>
- Paths of the other sites of a multisite installation on a host.
- jpkcom_harden_trim_path_of_sibling() : bool
- Whether a path below this site's base belongs to another site of the network.
- jpkcom_harden_trim_is_self_link() : bool
- Whether a URL points to this site (home or WordPress address).
- jpkcom_harden_trim_filter_self_pings() : void
- Remove links to this site from the pingback list (`pre_ping`, by reference).
- jpkcom_harden_trim_rewrite_asset_src() : string
- Hash or remove the `ver` query argument of an asset URL.
- jpkcom_harden_trim_filter_asset_src() : mixed
- `script_loader_src` / `style_loader_src` / `script_module_loader_src` callback.
- jpkcom_harden_trim_strip_wp_embed_iframe() : string
- Turn WordPress post-embed markup into its plain blockquote fallback.
- jpkcom_harden_trim_filter_embed_html() : mixed
- `embed_oembed_html` callback: strip WordPress embed iframes (cached and fresh).
- jpkcom_harden_trim_embed_404() : void
- Answer `/embed/` requests with the theme's 404.
- jpkcom_harden_trim_oembed_proxy_no_discover() : mixed
- Switch off oEmbed discovery for the editor's oEmbed proxy route.
- jpkcom_harden_trim_dequeue_comment_reply() : void
- Dequeue `comment-reply`; replies fall back to the `?replytocom=` reload.
- jpkcom_harden_trim_dequeue_dashicons() : void
- Dequeue `dashicons` for logged-out visitors.
- jpkcom_harden_trim_dequeue_block_library_css() : void
- Dequeue the block library CSS and the core per-block styles (classic themes only).
- jpkcom_harden_trim_dequeue_global_styles() : void
- Dequeue the global styles and the core block-supports / duotone CSS (classic themes only).
- jpkcom_harden_trim_heartbeat_settings() : array<string, mixed>
- Heartbeat settings for `optimized`: 120 s interval and minimal interval.
- jpkcom_harden_trim_filter_heartbeat_settings() : mixed
- `heartbeat_settings` callback.
- jpkcom_harden_trim_heartbeat_disabled_handles() : array<int, string>
- Script handles that print nothing while heartbeat is disabled.
- jpkcom_harden_trim_filter_heartbeat_src() : mixed
- `script_loader_src` callback for `heartbeat = disabled`.
- jpkcom_harden_trim_filter_auth_check_load() : mixed
- `wp_auth_check_load` callback for `heartbeat = disabled`.
- jpkcom_harden_trim_revision_exempt_post_types() : array<int, string>
- Post types whose revision count this plugin never changes.
- jpkcom_harden_trim_revisions_to_keep() : int
- Number of revisions to keep for a post.
- jpkcom_harden_trim_filter_revisions_to_keep() : mixed
- `wp_revisions_to_keep` callback.
Constants
AUTOSAVE_INTERVAL
public
mixed
AUTOSAVE_INTERVAL
= $settings['autosave_interval']
Functions
jpkcom_harden_trim_register_performance_features()
Register the hooks of the active performance features.
jpkcom_harden_trim_register_performance_features(array<string, mixed> $settings) : void
Parameters
- $settings : array<string, mixed>
-
Effective settings.
Tags
jpkcom_harden_trim_remove_emoji()
Remove the emoji detection script and styles for the current request.
jpkcom_harden_trim_remove_emoji() : void
The deprecated print_emoji_styles() fallback is removed together with wp_enqueue_emoji_styles(): the latter normally unhooks the former, and left alone it would raise a deprecation notice. Idempotent.
Tags
jpkcom_harden_trim_filter_tinymce_plugins()
Drop the TinyMCE `wpemoji` plugin (classic editor and Classic block).
jpkcom_harden_trim_filter_tinymce_plugins(mixed $plugins) : mixed
Parameters
- $plugins : mixed
-
TinyMCE plugin names.
Tags
Return values
mixed —The list without wpemoji; anything else unchanged.
jpkcom_harden_trim_normalized_host()
Lowercase ASCII host of a URL without a leading `www.`.
jpkcom_harden_trim_normalized_host(string $url) : string
An internationalised host is converted to its punycode form when the
intl extension is available, so bücher.example and
xn--bcher-kva.example compare equal.
Parameters
- $url : string
-
Absolute or protocol-relative URL.
Tags
Return values
string —Host, or '' when the URL has none.
jpkcom_harden_trim_url_path()
Lowercase path of a URL without trailing slashes ('' for the root).
jpkcom_harden_trim_url_path(string $url) : string
Parameters
- $url : string
-
URL.
Tags
Return values
string —Path such as /site2, or ''.
jpkcom_harden_trim_sibling_site_paths()
Paths of the other sites of a multisite installation on a host.
jpkcom_harden_trim_sibling_site_paths(string $host) : array<int, string>
On the main site of a subdirectory network home_url() has no path, so
host and path prefix alone would count every sibling site as "self".
Every site with the same domain (with or without www.) except the
current one is listed, in any network and any status: a path that
belongs to another site is never the current site's. Cached per
request, current site and host; empty on a single site.
Parameters
- $host : string
-
Normalised host (see jpkcom_harden_trim_normalized_host()).
Tags
Return values
array<int, string> —Lowercase paths without trailing slash, such as /site2.
jpkcom_harden_trim_path_of_sibling()
Whether a path below this site's base belongs to another site of the network.
jpkcom_harden_trim_path_of_sibling(string $host, string $path, string $base) : bool
Parameters
- $host : string
-
Normalised host of the link.
- $path : string
-
Lowercase link path without trailing slash.
- $base : string
-
Lowercase path of this site's matching URL ('' for the host root).
Tags
Return values
bool —True when a sibling site's path, deeper than $base, contains $path.
jpkcom_harden_trim_is_self_link()
Whether a URL points to this site (home or WordPress address).
jpkcom_harden_trim_is_self_link(string $url) : bool
Host and path prefix: the host is compared without scheme, www. and
letter case, and the link's path must start with the path of
home_url() or site_url() at a segment boundary. On a subdirectory
multisite (or a second WordPress under a path) a link to a sibling site
on the same host is therefore not a self ping. On the main site of such
a network (home without a path) a link into the path of another site
of the network is not a self ping either (see
jpkcom_harden_trim_sibling_site_paths()); a single site is unaffected.
Parameters
- $url : string
-
URL to check.
Tags
Return values
bool —True for a link to this site.
jpkcom_harden_trim_filter_self_pings()
Remove links to this site from the pingback list (`pre_ping`, by reference).
jpkcom_harden_trim_filter_self_pings(array<int, mixed> &$links) : void
Parameters
- $links : array<int, mixed>
-
Links about to be pinged.
Tags
jpkcom_harden_trim_rewrite_asset_src()
Hash or remove the `ver` query argument of an asset URL.
jpkcom_harden_trim_rewrite_asset_src(string $src, string $mode) : string
Only an argument named exactly ver is touched; every other argument
and the fragment are kept byte for byte.
Parameters
- $src : string
-
Asset URL.
- $mode : string
-
hash,remove; anything else returns$src.
Tags
Return values
string —Rewritten URL.
jpkcom_harden_trim_filter_asset_src()
`script_loader_src` / `style_loader_src` / `script_module_loader_src` callback.
jpkcom_harden_trim_filter_asset_src(mixed $src) : mixed
Front end only; non-string values (core may pass false) are returned as is.
Parameters
- $src : mixed
-
Asset URL.
Tags
Return values
mixed —Rewritten URL, or the value unchanged.
jpkcom_harden_trim_strip_wp_embed_iframe()
Turn WordPress post-embed markup into its plain blockquote fallback.
jpkcom_harden_trim_strip_wp_embed_iframe(string $html) : string
Removes every <iframe> carrying the wp-embedded-content class (also
self-closing ones), so the hidden iframe no longer loads the remote page,
and drops an inline style that hides the blockquote. Other iframes
(YouTube and the like) are untouched.
Parameters
- $html : string
-
Embed HTML.
Tags
Return values
string —HTML without WordPress embed iframes.
jpkcom_harden_trim_filter_embed_html()
`embed_oembed_html` callback: strip WordPress embed iframes (cached and fresh).
jpkcom_harden_trim_filter_embed_html(mixed $html) : mixed
Parameters
- $html : mixed
-
Embed HTML.
Tags
Return values
mixed —Stripped HTML, or the value unchanged.
jpkcom_harden_trim_embed_404()
Answer `/embed/` requests with the theme's 404.
jpkcom_harden_trim_embed_404() : void
Runs at template_redirect priority 1. jpkcom_harden_trim_force_404() also clears is_embed and the post, so the template loader picks the 404 template instead of the embed card (theme-compat/embed.php renders while have_posts()). redirect_canonical() is told not to turn the 404 into a guessed redirect to the post.
Tags
jpkcom_harden_trim_oembed_proxy_no_discover()
Switch off oEmbed discovery for the editor's oEmbed proxy route.
jpkcom_harden_trim_oembed_proxy_no_discover(mixed $result[, mixed $server = null ][, mixed $request = null ]) : mixed
Keeps the editor preview consistent with the front end, where
embed_oembed_discover is false. Whitelisted providers still work.
Parameters
- $result : mixed
-
Dispatch short-circuit value, passed through.
- $server : mixed = null
-
REST server.
- $request : mixed = null
-
REST request.
Tags
Return values
mixed —$result unchanged.
jpkcom_harden_trim_dequeue_comment_reply()
Dequeue `comment-reply`; replies fall back to the `?replytocom=` reload.
jpkcom_harden_trim_dequeue_comment_reply() : void
Tags
jpkcom_harden_trim_dequeue_dashicons()
Dequeue `dashicons` for logged-out visitors.
jpkcom_harden_trim_dequeue_dashicons() : void
Never deregistered: styles that depend on dashicons still pull it in.
Tags
jpkcom_harden_trim_dequeue_block_library_css()
Dequeue the block library CSS and the core per-block styles (classic themes only).
jpkcom_harden_trim_dequeue_block_library_css() : void
Core per-block style handles are wp-block-<name>. The block-theme check
happens here, at print time, so a theme switch needs no re-registration.
Tags
jpkcom_harden_trim_dequeue_global_styles()
Dequeue the global styles and the core block-supports / duotone CSS (classic themes only).
jpkcom_harden_trim_dequeue_global_styles() : void
Covers the head output and the classic-theme on-demand path, where global styles are enqueued at wp_footer@1 and a placeholder in the head.
Tags
jpkcom_harden_trim_heartbeat_settings()
Heartbeat settings for `optimized`: 120 s interval and minimal interval.
jpkcom_harden_trim_heartbeat_settings(array<string, mixed> $settings) : array<string, mixed>
minimalInterval is the only value the block editor's forced
interval( 10 ) respects; 120 s is the maximum core documents as safe
for post locks. Higher values set by someone else are kept (heartbeat.js
ignores a minimal interval above 600 s, so that is the cap).
Parameters
- $settings : array<string, mixed>
-
Heartbeat settings.
Tags
Return values
array<string, mixed> —Adjusted settings, unchanged unless optimized and not exempt.
jpkcom_harden_trim_filter_heartbeat_settings()
`heartbeat_settings` callback.
jpkcom_harden_trim_filter_heartbeat_settings(mixed $settings) : mixed
Parameters
- $settings : mixed
-
Heartbeat settings.
Tags
Return values
mixed —Adjusted settings, or the value unchanged when it is no array.
jpkcom_harden_trim_heartbeat_disabled_handles()
Script handles that print nothing while heartbeat is disabled.
jpkcom_harden_trim_heartbeat_disabled_handles() : array<int, string>
Mechanism (read from 7.1.3 script-loader.php, class-wp-dependencies.php, class-wp-scripts.php, edit-form-blocks.php and js/dist/editor.js):
- Deregistering
heartbeatis not an option:autosaveandwp-auth-checkdepend on it, and WP_Dependencies::all_deps() then raises_doing_it_wrongfor the missing dependency (since 6.9.1). - Instead the handles stay registered and resolvable, and
script_loader_srcreturns '' for them. WP_Scripts::do_item() then returns before building the tag, so neither the file nor its inline before/after scripts are printed. That drops edit-form-blocks.php's inlinewp.heartbeat.interval( 10 ), which would throw without heartbeat.js. Only the localizedheartbeatSettingsvariable remains. autosavegoes too: its triggerSave() calls wp.heartbeat.connectNow() unguarded (Ctrl+S, slug blur in the classic editor). Every caller of wp.autosave in core checkswp.autosavefirst, and every core caller of wp.heartbeat outside autosave.js checkswp.heartbeatfirst.- The block editor (js/dist/editor.js) only uses
heartbeat.send/heartbeat.tickhook actions and its own REST autosave, so it runs without heartbeat;wp-auth-checkis also switched off viawp_auth_check_load, which removes its CSS and markup as well.
Tags
Return values
array<int, string> —Script handles.
jpkcom_harden_trim_filter_heartbeat_src()
`script_loader_src` callback for `heartbeat = disabled`.
jpkcom_harden_trim_filter_heartbeat_src(mixed $src[, mixed $handle = '' ]) : mixed
Parameters
- $src : mixed
-
Script URL.
- $handle : mixed = ''
-
Script handle.
Tags
Return values
mixed —'' for the heartbeat handles, otherwise $src unchanged.
jpkcom_harden_trim_filter_auth_check_load()
`wp_auth_check_load` callback for `heartbeat = disabled`.
jpkcom_harden_trim_filter_auth_check_load(mixed $show) : mixed
Parameters
- $show : mixed
-
Whether to load the authentication check.
Tags
Return values
mixed —False while heartbeat is disabled for this user, otherwise $show.
jpkcom_harden_trim_revision_exempt_post_types()
Post types whose revision count this plugin never changes.
jpkcom_harden_trim_revision_exempt_post_types() : array<int, string>
The Site Editor types, so Site Editor history survives.
Tags
Return values
array<int, string> —Post type slugs.
jpkcom_harden_trim_revisions_to_keep()
Number of revisions to keep for a post.
jpkcom_harden_trim_revisions_to_keep(int $num, WP_Post $post) : int
Exempt post types and post types without revision support keep the value core computed.
Parameters
- $num : int
-
Value computed so far.
- $post : WP_Post
-
Post.
Tags
Return values
int —The setting, or $num.
jpkcom_harden_trim_filter_revisions_to_keep()
`wp_revisions_to_keep` callback.
jpkcom_harden_trim_filter_revisions_to_keep(mixed $num[, mixed $post = null ]) : mixed
Parameters
- $num : mixed
-
Value computed so far.
- $post : mixed = null
-
Post.
Tags
Return values
mixed —The setting, or $num unchanged.