JPKCom Harden & Trim

features.php

Feature registration

Single entry point the main file calls on plugins_loaded: hands the effective settings to the registrar of each feature group. A group whose module is missing is skipped, so the plugin stays loadable. Also holds the helpers more than one feature module calls; the main file loads this file before every features-*.php.

Tags
since
1.0.0

Table of Contents

Functions

jpkcom_harden_trim_register_features()  : void
Register the hooks of every feature group.
jpkcom_harden_trim_is_front_end()  : bool
Whether the request renders the public site.
jpkcom_harden_trim_force_404()  : void
Turn the main query into a plain 404 that the theme's 404 template renders.

Functions

jpkcom_harden_trim_register_features()

Register the hooks of every feature group.

jpkcom_harden_trim_register_features(array<string, mixed> $settings) : void

Registrars only add hooks for features whose value is active; role decisions happen later, inside the callbacks, where the user is known.

Parameters
$settings : array<string, mixed>

Effective settings.

Tags
since
1.0.0

jpkcom_harden_trim_is_front_end()

Whether the request renders the public site.

jpkcom_harden_trim_is_front_end() : bool

Excludes the admin and REST requests: the block-editor settings REST route builds the editor canvas assets through _wp_get_iframed_editor_assets(), which fires wp_print_styles and wp_print_footer_scripts with is_admin() false.

Tags
since
1.0.0
Return values
bool —

True on the front end.

jpkcom_harden_trim_force_404()

Turn the main query into a plain 404 that the theme's 404 template renders.

jpkcom_harden_trim_force_404(WP_Query $query) : void

WP_Query::set_404() (7.1.3 class-wp-query.php:1843) resets the conditional flags but keeps is_feed, keeps is_embed (unknown to init_query_flags(), :502) and never touches the queried posts or the queried object. template-loader.php runs do_feed() while is_feed() is true and checks is_embed before is_404, and a theme without a 404 template falls back to its index, whose loop would still list the posts. So feed, embed, posts and queried object are cleared as well, together with the globals WP::register_globals() derived from them.

On a feed request WP::send_headers() (7.1.3 class-wp.php:471-476) has already set the feed Content-Type (application/rss+xml and the like) before template_redirect, so the HTML 404 page would go out under it. The Content-Type is then set back to what core sends for HTML pages (html_type; charset blog_charset, class-wp.php:468), unless the headers are already sent.

Parameters
$query : WP_Query

The main query, at template_redirect.

Tags
since
1.0.0
On this page

Search results