Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 72 additions & 2 deletions .github/workflows/wp-compatibility-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1901,8 +1901,8 @@ jobs:
$this->assertSame(get_plugin_data(ES_SITE_OPTIMIZER_FILE, false, false)['Version'], ES_SITE_OPTIMIZER_VERSION);
$this->assertSame(10, has_filter('wp_resource_hints', 'es_optimizer_add_preconnect_resource_hints'));
$this->assertSame(10, has_filter('tiny_mce_plugins', 'es_optimizer_disable_emojis_tinymce'));
$this->assertCount(13, es_optimizer_get_settings_fields());
$this->assertCount(11, es_optimizer_get_boolean_option_keys());
$this->assertCount(19, es_optimizer_get_settings_fields());
$this->assertCount(17, es_optimizer_get_boolean_option_keys());
}

/**
Expand Down Expand Up @@ -2724,6 +2724,76 @@ jobs:
wp_dequeue_style('wp-emoji-styles');
}

/**
* The REST API, oEmbed discovery, and feed link options remove core's own registrations.
*
* @since 2.4.0
* @return void
*/
public function test_link_removals_match_core_registrations(): void {
$core = array(
array('wp_head', 'rest_output_link_wp_head', 10),
array('template_redirect', 'rest_output_link_header', 11),
array('wp_head', 'wp_oembed_add_discovery_links', 4),
array('wp_head', 'feed_links', 2),
array('wp_head', 'feed_links_extra', 3),
);
foreach ($core as $row) {
$this->assertSame($row[2], has_action($row[0], $row[1]), 'Control: core registers ' . $row[1] . '.');
}
update_option('es_optimizer_options', array('remove_rest_api_link' => 0, 'remove_oembed_links' => 0, 'remove_feed_links' => 0));
es_optimizer_remove_header_items();
$this->assertSame(10, has_action('wp_head', 'rest_output_link_wp_head'), 'Options off: nothing is removed.');
update_option('es_optimizer_options', array('remove_rest_api_link' => 1, 'remove_oembed_links' => 1, 'remove_feed_links' => 1));
es_optimizer_remove_header_items();
foreach ($core as $row) {
$this->assertFalse(has_action($row[0], $row[1]), $row[1] . ' is removed.');
}
$this->assertNotFalse(has_action('rest_api_init', 'create_initial_rest_routes'), 'The REST API itself stays.');
}

/**
* The pattern-directory, AI, and Heartbeat options act through core's own APIs.
*
* @since 2.4.0
* @return void
*/
public function test_patterns_ai_and_heartbeat_with_core(): void {
$ai_by_constant = !defined('WP_AI_SUPPORT') || WP_AI_SUPPORT;
update_option('es_optimizer_options', array('disable_remote_patterns' => 0, 'disable_ai_features' => 0, 'heartbeat_control' => 0));
$this->assertTrue(apply_filters('should_load_remote_block_patterns', true));
$this->assertSame($ai_by_constant, wp_supports_ai());
update_option('es_optimizer_options', array('disable_remote_patterns' => 1, 'disable_ai_features' => 1, 'heartbeat_control' => 1));
$this->assertFalse(apply_filters('should_load_remote_block_patterns', true));
$this->assertFalse(wp_supports_ai());

$this->assertTrue(wp_script_is('heartbeat', 'registered'), 'Control: core registers Heartbeat.');
es_optimizer_disable_frontend_heartbeat();
$this->assertFalse(wp_script_is('heartbeat', 'registered'), 'Deregistered on the front end.');
unset($GLOBALS['wp_scripts']);

// is_admin() asks the current screen; a minimal admin screen avoids loading admin files.
$previous_page = $GLOBALS['pagenow'] ?? null;
$GLOBALS['current_screen'] = new class() {
public function in_admin($admin = null): bool {
return true;
}
};
try {
$this->assertTrue(is_admin());
$GLOBALS['pagenow'] = 'index.php';
$this->assertSame(120, apply_filters('heartbeat_settings', array())['interval']);
$this->assertSame(300, apply_filters('heartbeat_settings', array('interval' => 300))['interval'], 'A slower interval is kept.');
$GLOBALS['pagenow'] = 'post.php';
$this->assertArrayNotHasKey('interval', apply_filters('heartbeat_settings', array()), 'The post editor keeps core timing.');
} finally {
$GLOBALS['pagenow'] = $previous_page;
unset($GLOBALS['current_screen']);
}
$this->assertFalse(is_admin());
$this->assertArrayNotHasKey('interval', apply_filters('heartbeat_settings', array()), 'Not in the admin area.');
}

/**
* Create sites and give each site, the current one first, a stored option.
*
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- "Remove REST API Link": remove the REST API address from the page head and the Link response header. The REST API keeps working.
- "Remove oEmbed Discovery Links": remove the links other sites read to embed your posts, at both priorities WordPress adds them.
- "Remove Feed Links": remove the RSS feed links from the page head. The feeds keep working.
- "Limit Heartbeat": stop the Heartbeat script on the front end, and send it every 120 seconds instead of 60 on admin screens other than the post editor, the site editor, and the Customizer. A slower interval set by another plugin is kept.
- "Disable Pattern Directory Patterns": stop the block editor from loading patterns from the WordPress.org Pattern Directory.
- "Disable WordPress AI Support": answer `false` to WordPress 7's `wp_supports_ai` filter.

### Fixed

- On the settings page, only the checkbox now turns a setting on or off. A click on the setting's title or its description, or a drag across it to select the text, no longer changes the setting.
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ A WordPress plugin for disabling selected features and configuring resource hint

## Features

- **Header Cleanup:** Remove generator output from the page head and feeds, RSD links from the page head, and shortlinks from the page head and the HTTP response header
- **Script Optimization:** Disable WordPress emojis and remove jQuery Migrate
- **Header Cleanup:** Remove generator output from the page head and feeds, RSD links from the page head, shortlinks and the REST API link from the page head and the HTTP response header, and oEmbed discovery and feed links from the page head
- **Script Optimization:** Disable WordPress emojis, remove jQuery Migrate, and limit the Heartbeat (off on the front end, every 120 seconds on admin screens outside the editors)
- **Style Optimization:** Remove inline styles from recent comments widget and disable classic theme styles
- **Editor and Admin:** Stop loading patterns from the WordPress.org Pattern Directory, and turn off WordPress's AI support
- **Resource Hints:** Configure DNS prefetch and preconnect for HTTPS domains used by your site
- **Jetpack Promotions:** Disable Jetpack promotional messages and Blaze promotions
- **Explained Settings:** Every setting says what it does, its effect on the site, and its performance gain or cost

## Installation

Expand Down
36 changes: 36 additions & 0 deletions includes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ function es_optimizer_get_performance_settings_fields(): array {
es_optimizer_get_checkbox_field_definition( $section, 'disable_emojis', __( 'Disable WordPress Emojis', 'enginescript-site-optimizer' ) ),
es_optimizer_get_checkbox_field_definition( $section, 'remove_jquery_migrate', __( 'Remove jQuery Migrate', 'enginescript-site-optimizer' ) ),
es_optimizer_get_checkbox_field_definition( $section, 'disable_classic_theme_styles', __( 'Disable Classic Theme Styles', 'enginescript-site-optimizer' ) ),
es_optimizer_get_checkbox_field_definition( $section, 'heartbeat_control', __( 'Limit Heartbeat', 'enginescript-site-optimizer' ) ),
es_optimizer_get_checkbox_field_definition( $section, 'disable_remote_patterns', __( 'Disable Pattern Directory Patterns', 'enginescript-site-optimizer' ) ),
];
}

Expand All @@ -114,6 +116,9 @@ function es_optimizer_get_header_cleanup_settings_fields(): array {
es_optimizer_get_checkbox_field_definition( $section, 'remove_rsd_link', __( 'Remove RSD Link', 'enginescript-site-optimizer' ) ),
es_optimizer_get_checkbox_field_definition( $section, 'remove_shortlink', __( 'Remove Shortlink', 'enginescript-site-optimizer' ) ),
es_optimizer_get_checkbox_field_definition( $section, 'remove_recent_comments_style', __( 'Remove Recent Comments Style', 'enginescript-site-optimizer' ) ),
es_optimizer_get_checkbox_field_definition( $section, 'remove_rest_api_link', __( 'Remove REST API Link', 'enginescript-site-optimizer' ) ),
es_optimizer_get_checkbox_field_definition( $section, 'remove_oembed_links', __( 'Remove oEmbed Discovery Links', 'enginescript-site-optimizer' ) ),
es_optimizer_get_checkbox_field_definition( $section, 'remove_feed_links', __( 'Remove Feed Links', 'enginescript-site-optimizer' ) ),
];
}

Expand All @@ -129,6 +134,7 @@ function es_optimizer_get_additional_settings_fields(): array {
return [
es_optimizer_get_checkbox_field_definition( $section, 'disable_jetpack_ads', __( 'Disable Jetpack Promotions', 'enginescript-site-optimizer' ) ),
es_optimizer_get_checkbox_field_definition( $section, 'disable_post_via_email', __( 'Disable Post via Email', 'enginescript-site-optimizer' ) ),
es_optimizer_get_checkbox_field_definition( $section, 'disable_ai_features', __( 'Disable WordPress AI Support', 'enginescript-site-optimizer' ) ),
es_optimizer_get_checkbox_field_definition( $section, 'enable_preconnect', __( 'Enable Preconnect', 'enginescript-site-optimizer' ) ),
es_optimizer_get_textarea_field_definition(
$section,
Expand Down Expand Up @@ -227,6 +233,16 @@ function es_optimizer_get_option_help(): array {
'effect' => __( 'Buttons and File blocks in your content may lose their default spacing and colors if the theme does not style them itself. A stylesheet that another plugin loads on top of this one will not load either.', 'enginescript-site-optimizer' ),
'performance' => __( 'Removes a few lines of CSS, usually printed inline in the page head, on classic themes: a very small gain for visitors. No change on the server.', 'enginescript-site-optimizer' ),
],
'heartbeat_control' => [
'what' => __( 'Limits the Heartbeat, a script that keeps a page in touch with the server through regular background requests. On the front end it stops the script from loading; WordPress loads it there only when a theme or plugin asks for it. On admin screens it sends a request every 120 seconds instead of every 60. The post editor, the site editor, and the Customizer keep the usual timing.', 'enginescript-site-optimizer' ),
'effect' => __( 'Front-end features that rely on the Heartbeat, such as live chat, live notifications, or front-end editing in some plugins, stop updating, and their scripts may not load. In the admin area, dashboard widgets that refresh through the Heartbeat update half as often, and the notice that your login has expired can appear up to two minutes later. Post locking and autosave in the editors are not changed.', 'enginescript-site-optimizer' ),
'performance' => __( 'Each Heartbeat request loads WordPress in full on the server and is never served from a page cache. Halving them on admin screens, and removing them from the front end, saves server work, which adds up when several people keep the admin area open. Visitors see no difference in page speed.', 'enginescript-site-optimizer' ),
],
'disable_remote_patterns' => [
'what' => __( 'Stops the block editor from loading patterns from the WordPress.org Pattern Directory: the general and featured patterns, and the directory patterns a theme asks for. Patterns that come with your theme, your plugins, or WordPress itself, and the patterns you create, stay available.', 'enginescript-site-optimizer' ),
'effect' => __( 'The pattern inserter shows far fewer ready-made patterns, because most of the patterns it offers come from the directory. Patterns already used in your content are not changed.', 'enginescript-site-optimizer' ),
'performance' => __( 'Saves the requests the server makes to WordPress.org when the editor loads patterns, and the stored copies of their results, which are refreshed about every hour. The editor\'s pattern list can open faster. No change on the front end.', 'enginescript-site-optimizer' ),
],
'remove_wp_version' => [
'what' => __( 'Removes the generator tag that names your WordPress version from the page head and from your RSS, Atom, and other feeds. Version numbers on script and stylesheet addresses, and export files, are left as they are.', 'enginescript-site-optimizer' ),
'effect' => __( 'Hides the version from casual inspection and from scanners that read the tag. It is not real protection, because the version can be worked out in other ways; keeping WordPress up to date matters far more. Nothing on the site looks different.', 'enginescript-site-optimizer' ),
Expand All @@ -247,6 +263,26 @@ function es_optimizer_get_option_help(): array {
'effect' => __( 'The widget\'s links may look slightly different if your theme relied on that style. Block themes and the Latest Comments block are not affected.', 'enginescript-site-optimizer' ),
'performance' => __( 'Removes a few bytes of CSS from pages that show the widget. No measurable speed change.', 'enginescript-site-optimizer' ),
],
'remove_rest_api_link' => [
'what' => __( 'Removes the link to the site\'s REST API address from the page head and from the Link header that WordPress sends with each page.', 'enginescript-site-optimizer' ),
'effect' => __( 'The REST API keeps working: the block editor, mobile apps, and plugins that use it are not affected. Only the advertised address is removed, which a few tools and services use to find the API on their own.', 'enginescript-site-optimizer' ),
'performance' => __( 'Removes one line from each page and one response header. No measurable speed change.', 'enginescript-site-optimizer' ),
],
'remove_oembed_links' => [
'what' => __( 'Removes the oEmbed discovery links from the page head of posts and pages. Other sites read them to show one of your posts as an embedded card when someone pastes its link.', 'enginescript-site-optimizer' ),
'effect' => __( 'A link to one of your posts pasted into another WordPress site, or into some apps and services, shows as a plain link instead of a card. Embedding videos, posts, and other content from other sites in your own posts keeps working.', 'enginescript-site-optimizer' ),
'performance' => __( 'Removes two lines from each post and page. No measurable speed change.', 'enginescript-site-optimizer' ),
],
'remove_feed_links' => [
'what' => __( 'Removes the links to the site\'s RSS feeds, for posts, comments, and categories, tags, or authors, from the page head.', 'enginescript-site-optimizer' ),
'effect' => __( 'The feeds keep working at their usual addresses, but browsers and feed readers can no longer find them from a page, so someone who subscribes by entering the site\'s address may need the feed\'s address instead. Leave this off if people follow the site in a feed reader.', 'enginescript-site-optimizer' ),
'performance' => __( 'Removes a few lines from each page. No measurable speed change.', 'enginescript-site-optimizer' ),
],
'disable_ai_features' => [
'what' => __( 'Tells WordPress that AI features are not supported on this site. WordPress then does not register its built-in AI provider connectors, and refuses AI provider connectors from plugins.', 'enginescript-site-optimizer' ),
'effect' => __( 'AI features that rely on WordPress\'s AI support are unavailable, including those in plugins that check for it. Connectors that are not AI providers, such as Akismet, are not affected. Setting the WP_AI_SUPPORT constant to false in wp-config.php has the same effect.', 'enginescript-site-optimizer' ),
'performance' => __( 'No measurable speed change. WordPress only skips registering its AI provider connectors on each request.', 'enginescript-site-optimizer' ),
],
'disable_jetpack_ads' => [
'what' => __( 'Turns off Jetpack\'s promotional notices, its Just-in-Time upgrade messages, and its Blaze prompts to advertise your posts. It does nothing unless Jetpack is installed.', 'enginescript-site-optimizer' ),
'effect' => __( 'Jetpack keeps working; you no longer see its upgrade and advertising prompts in the admin area. Visitors see no difference.', 'enginescript-site-optimizer' ),
Expand Down
4 changes: 4 additions & 0 deletions includes/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ function es_optimizer_init_frontend_optimizations(): void {
add_filter( 'wp_resource_hints', 'es_optimizer_add_dns_prefetch_resource_hints', 10, 2 );
add_filter( 'tiny_mce_plugins', 'es_optimizer_disable_emojis_tinymce' );
add_action( 'init', 'es_optimizer_disable_post_via_email' );
add_filter( 'should_load_remote_block_patterns', 'es_optimizer_filter_remote_patterns', PHP_INT_MAX );
add_filter( 'wp_supports_ai', 'es_optimizer_filter_ai_support', PHP_INT_MAX );
add_action( 'wp_enqueue_scripts', 'es_optimizer_disable_frontend_heartbeat', 100 );
add_filter( 'heartbeat_settings', 'es_optimizer_filter_heartbeat_settings', PHP_INT_MAX );
}

/**
Expand Down
Loading
Loading