From 49b2193dd9a7eb8e28e61a6e35b36164b7c88ac5 Mon Sep 17 00:00:00 2001 From: Peter Downey Date: Fri, 27 Nov 2026 21:37:32 -0500 Subject: [PATCH] Toggle settings only with the checkbox; explain each setting A click on a setting's title or description, or a drag across it to select the text, turned the setting on or off: WordPress printed the title as a label for the checkbox, and the description sat inside a second label. Checkboxes now register without label_for, so the title is plain text, and carry a label for screen readers only. Each setting now shows three short paragraphs below its control: what it does, its effect on the site, and its performance gain or cost. They replace the one-line descriptions and follow what each option does on WordPress 7.0 and 7.1. The two domain lists show the same three parts, then their format rules. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 11 + includes/admin.php | 257 ++++++++++++++-------- languages/enginescript-site-optimizer.pot | 256 +++++++++++++++------ readme.txt | 5 + tests/unit/SettingsPageTest.php | 83 ++++++- 5 files changed, 454 insertions(+), 158 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fa5009..591d697 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### 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. + +### Changed + +- Explain every setting below its control: what it does, its effect on the site, and its performance gain or cost. The explanations replace the one-line descriptions. +- Name each checkbox for screen readers by its title alone, with the explanation read as its description. + ## [2.3.0] - 2026-11-26 ### Fixed diff --git a/includes/admin.php b/includes/admin.php index 8505f9f..95508eb 100644 --- a/includes/admin.php +++ b/includes/admin.php @@ -52,7 +52,7 @@ function es_optimizer_register_settings_sections(): void { continue; } - es_optimizer_register_checkbox_field( $page, $field['section'], $field['option'], $field['title'], $field['description'] ); + es_optimizer_register_checkbox_field( $page, $field['section'], $field['option'], $field['title'] ); } } @@ -94,24 +94,9 @@ function es_optimizer_get_performance_settings_fields(): array { $section = 'es_optimizer_performance'; return [ - es_optimizer_get_checkbox_field_definition( - $section, - 'disable_emojis', - __( 'Disable WordPress Emojis', 'enginescript-site-optimizer' ), - __( 'Remove WordPress emoji scripts and styles.', 'enginescript-site-optimizer' ) - ), - es_optimizer_get_checkbox_field_definition( - $section, - 'remove_jquery_migrate', - __( 'Remove jQuery Migrate', 'enginescript-site-optimizer' ), - __( 'Remove the jQuery Migrate script. This may affect plugins or themes that depend on it.', 'enginescript-site-optimizer' ) - ), - es_optimizer_get_checkbox_field_definition( - $section, - 'disable_classic_theme_styles', - __( 'Disable Classic Theme Styles', 'enginescript-site-optimizer' ), - __( 'Remove the classic theme stylesheet added by WordPress.', 'enginescript-site-optimizer' ) - ), + 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' ) ), ]; } @@ -125,30 +110,10 @@ function es_optimizer_get_header_cleanup_settings_fields(): array { $section = 'es_optimizer_header_cleanup'; return [ - es_optimizer_get_checkbox_field_definition( - $section, - 'remove_wp_version', - __( 'Remove WordPress Version', 'enginescript-site-optimizer' ), - __( 'Remove the WordPress version from the document head and from feeds.', 'enginescript-site-optimizer' ) - ), - es_optimizer_get_checkbox_field_definition( - $section, - 'remove_rsd_link', - __( 'Remove RSD Link', 'enginescript-site-optimizer' ), - __( 'Remove the Really Simple Discovery (RSD) link from the document head.', 'enginescript-site-optimizer' ) - ), - es_optimizer_get_checkbox_field_definition( - $section, - 'remove_shortlink', - __( 'Remove Shortlink', 'enginescript-site-optimizer' ), - __( 'Remove WordPress shortlink URLs from the document head and the HTTP response header.', 'enginescript-site-optimizer' ) - ), - es_optimizer_get_checkbox_field_definition( - $section, - 'remove_recent_comments_style', - __( 'Remove Recent Comments Style', 'enginescript-site-optimizer' ), - __( 'Remove inline CSS from the recent comments widget.', 'enginescript-site-optimizer' ) - ), + es_optimizer_get_checkbox_field_definition( $section, 'remove_wp_version', __( 'Remove WordPress Version', 'enginescript-site-optimizer' ) ), + 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' ) ), ]; } @@ -162,36 +127,16 @@ function es_optimizer_get_additional_settings_fields(): array { $section = 'es_optimizer_additional_features'; return [ - es_optimizer_get_checkbox_field_definition( - $section, - 'disable_jetpack_ads', - __( 'Disable Jetpack Promotions', 'enginescript-site-optimizer' ), - __( 'Disable Jetpack promotional messages and Blaze promotions.', 'enginescript-site-optimizer' ) - ), - es_optimizer_get_checkbox_field_definition( - $section, - 'disable_post_via_email', - __( 'Disable Post via Email', 'enginescript-site-optimizer' ), - __( 'Disable WordPress post via email.', 'enginescript-site-optimizer' ) - ), - es_optimizer_get_checkbox_field_definition( - $section, - 'enable_preconnect', - __( 'Enable Preconnect', 'enginescript-site-optimizer' ), - __( 'Preconnect to external domains for faster resource loading.', 'enginescript-site-optimizer' ) - ), + 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, 'enable_preconnect', __( 'Enable Preconnect', 'enginescript-site-optimizer' ) ), es_optimizer_get_textarea_field_definition( $section, 'preconnect_domains', __( 'Preconnect Domains', 'enginescript-site-optimizer' ), __( 'Use preconnect for domains that host critical resources. Enter one HTTPS domain per line, with no port or port 443 only. Do not include file paths, query parameters, fragments, or credentials. Invalid lines are removed on save; an all-invalid list is cleared. Domain checks do not verify DNS destinations.', 'enginescript-site-optimizer' ) . ' ' . es_optimizer_get_domain_list_limits_description() ), - es_optimizer_get_checkbox_field_definition( - $section, - 'enable_dns_prefetch', - __( 'Enable DNS Prefetch', 'enginescript-site-optimizer' ), - __( 'Resolve less critical external domains in DNS ahead of time.', 'enginescript-site-optimizer' ) - ), + es_optimizer_get_checkbox_field_definition( $section, 'enable_dns_prefetch', __( 'Enable DNS Prefetch', 'enginescript-site-optimizer' ) ), es_optimizer_get_textarea_field_definition( $section, 'dns_prefetch_domains', @@ -239,18 +184,141 @@ function es_optimizer_get_domain_suggestions( string $option_name ): array { }; } +/** + * Get the title of a settings field. + * + * @since 2.4.0 + * @param string $option_name Option name. + * @return string Field title, or an empty string for an unknown option. + */ +function es_optimizer_get_field_title( string $option_name ): string { + foreach ( es_optimizer_get_settings_fields() as $field ) { + if ( $field['option'] === $option_name ) { + return $field['title']; + } + } + + return ''; +} + +/** + * Get the help text shown under each setting. + * + * Every setting explains what it does, its effect on the site, and its + * performance gain or cost, so that the person changing it can decide well. + * + * @since 2.4.0 + * @return array Help text keyed by option name. + */ +function es_optimizer_get_option_help(): array { + return [ + 'disable_emojis' => [ + 'what' => __( 'Stops WordPress from adding its emoji detection script and emoji styles to every page, the admin area, and embedded posts, and from replacing emoji in feeds and emails with images from WordPress.org.', 'enginescript-site-optimizer' ), + 'effect' => __( 'Emoji still appear, drawn by the visitor\'s own device, which every current browser and operating system supports. On very old systems without emoji fonts, some emoji may show as empty boxes. Emoji in feeds and emails stay as characters instead of images.', 'enginescript-site-optimizer' ), + 'performance' => __( 'Removes a small inline script and its styles from every page, and the check that script runs in the browser: a small gain for visitors. No change on the server.', 'enginescript-site-optimizer' ), + ], + 'remove_jquery_migrate' => [ + 'what' => __( 'Stops loading jQuery Migrate on the front end when a theme or plugin loads jQuery. jQuery Migrate restores functions that newer jQuery versions removed. The admin area is not changed.', 'enginescript-site-optimizer' ), + 'effect' => __( 'Front-end code written for old jQuery versions can stop working, which shows as broken sliders, menus, or forms and as errors in the browser console. Check the interactive parts of the site after turning this on. Pages that do not load jQuery are not affected.', 'enginescript-site-optimizer' ), + 'performance' => __( 'One script file fewer to download and run on every page that loads jQuery: a small gain for visitors. No change on the server.', 'enginescript-site-optimizer' ), + ], + 'disable_classic_theme_styles' => [ + 'what' => __( 'Removes the small classic-theme stylesheet that WordPress adds on the front end for themes without a theme.json file. It gives the Button and File blocks their default look. Block themes never load it, so on them this setting changes nothing. The editor is not changed.', 'enginescript-site-optimizer' ), + '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' ), + ], + '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' ), + 'performance' => __( 'Removes one line from each page and feed. No measurable speed change.', 'enginescript-site-optimizer' ), + ], + 'remove_rsd_link' => [ + 'what' => __( 'Removes the Really Simple Discovery (RSD) link from the page head. Old desktop blogging programs used it to find the site\'s XML-RPC address.', 'enginescript-site-optimizer' ), + 'effect' => __( 'A blogging program that relies on this link may need the XML-RPC address entered by hand. XML-RPC itself keeps working; only the link is removed. Most sites notice no difference.', 'enginescript-site-optimizer' ), + 'performance' => __( 'Removes one line from each page. No measurable speed change.', 'enginescript-site-optimizer' ), + ], + 'remove_shortlink' => [ + 'what' => __( 'Removes the shortlink, the short ?p=123 address of a post, from the page head and from the Link header that WordPress sends with each page.', 'enginescript-site-optimizer' ), + 'effect' => __( 'Shortlinks still work when someone uses them; they are only no longer advertised. A tool that reads the shortlink from the page uses the full address instead.', 'enginescript-site-optimizer' ), + 'performance' => __( 'Removes one line from each page and one response header. No measurable speed change.', 'enginescript-site-optimizer' ), + ], + 'remove_recent_comments_style' => [ + 'what' => __( 'Stops WordPress from printing a small inline style for the classic Recent Comments widget. WordPress prints it only on classic themes that support widgets.', 'enginescript-site-optimizer' ), + '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' ), + ], + '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' ), + 'performance' => __( 'Jetpack skips loading and showing these messages, which saves a little work and some requests in the admin area. No change on the front end.', 'enginescript-site-optimizer' ), + ], + 'disable_post_via_email' => [ + 'what' => __( 'Turns off publishing by email: the mail server settings disappear from Settings > Writing and can no longer be saved, and the wp-mail.php address that collects the mail refuses requests.', 'enginescript-site-optimizer' ), + 'effect' => __( 'Nobody can publish posts by sending email to the configured mailbox. Existing posts are not affected. Leave this off if you post by email.', 'enginescript-site-optimizer' ), + 'performance' => __( 'No speed change. It closes a rarely used way into the site.', 'enginescript-site-optimizer' ), + ], + 'enable_preconnect' => [ + 'what' => __( 'Adds a preconnect hint to the page head for each domain in the Preconnect Domains list, so the browser opens a connection to those servers before it needs them. Front-end pages only; the admin area and the login page are skipped.', 'enginescript-site-optimizer' ), + 'effect' => __( 'Files from those domains, such as web fonts, can start downloading sooner. A listed domain that the page does not use wastes a connection.', 'enginescript-site-optimizer' ), + 'performance' => __( 'Can save one or more network round trips the first time each listed domain is used, which helps most on slow or distant connections. Each hint costs the browser a connection, so list only the few domains that serve files a page needs early. No measurable cost on the server.', 'enginescript-site-optimizer' ), + ], + 'preconnect_domains' => [ + 'what' => __( 'The domains that get a preconnect hint while Enable Preconnect is on.', 'enginescript-site-optimizer' ), + 'effect' => __( 'Only the domains entered here get hints. The suggestions below are examples and are never added on their own.', 'enginescript-site-optimizer' ), + 'performance' => __( 'Two or three domains are usually enough. More hints compete for the browser\'s connections and can slow down the files that matter most.', 'enginescript-site-optimizer' ), + ], + 'enable_dns_prefetch' => [ + 'what' => __( 'Adds a DNS prefetch hint to the page head for each domain in the DNS Prefetch Domains list, so the browser looks up those domain names before it needs them. Front-end pages only; the admin area and the login page are skipped.', 'enginescript-site-optimizer' ), + 'effect' => __( 'Requests to those domains start slightly sooner. Unlike preconnect, no connection is opened, so it suits domains that are used later or only on some pages.', 'enginescript-site-optimizer' ), + 'performance' => __( 'Saves the name lookup, often a few tens of milliseconds, the first time each listed domain is used. It costs the browser very little, even for a domain that ends up unused. No measurable cost on the server.', 'enginescript-site-optimizer' ), + ], + 'dns_prefetch_domains' => [ + 'what' => __( 'The domains that get a DNS prefetch hint while Enable DNS Prefetch is on.', 'enginescript-site-optimizer' ), + 'effect' => __( 'Only the domains entered here get hints. The suggestion below is an example and is never added on its own.', 'enginescript-site-optimizer' ), + 'performance' => __( 'Lookups are cheap, so a longer list does little harm, but each entry only helps if pages request files from that domain.', 'enginescript-site-optimizer' ), + ], + ]; +} + +/** + * Print the three-part help text of a setting. + * + * @since 2.4.0 + * @param string $option_name Option name. + */ +function es_optimizer_render_option_help( string $option_name ): void { + $help = es_optimizer_get_option_help()[ $option_name ] ?? null; + + if ( null === $help ) { + return; + } + + $labels = [ + 'what' => __( 'What it does:', 'enginescript-site-optimizer' ), + 'effect' => __( 'Effect on your site:', 'enginescript-site-optimizer' ), + 'performance' => __( 'Performance:', 'enginescript-site-optimizer' ), + ]; + + foreach ( $labels as $part => $label ) { + printf( '

%1$s %2$s

', esc_html( $label ), esc_html( $help[ $part ] ) ); + } +} + /** * Build a checkbox settings field definition. * + * A checkbox has no one-line description: its help text comes from + * es_optimizer_get_option_help(). + * * @since 2.0.0 + * @since 2.4.0 The description parameter was removed. * @param string $section Settings section ID. * @param string $option_name Option name. * @param string $title Field title. - * @param string $description Field description. * @return array{type: string, section: string, option: string, title: string, description: string} */ -function es_optimizer_get_checkbox_field_definition( string $section, string $option_name, string $title, string $description ): array { - return es_optimizer_get_field_definition( 'checkbox', $section, $option_name, $title, $description ); +function es_optimizer_get_checkbox_field_definition( string $section, string $option_name, string $title ): array { + return es_optimizer_get_field_definition( 'checkbox', $section, $option_name, $title, '' ); } /** @@ -340,11 +408,19 @@ function es_optimizer_get_field_id( string $option_name ): string { /** * Get an option name from Settings API field arguments. * + * Checkbox fields name their option directly; text areas carry it in the + * field ID that WordPress uses for their label. + * * @since 2.0.0 - * @param array{label_for?: string, class?: string} $args Field arguments. + * @since 2.4.0 Reads the `option` argument first. + * @param array{option?: mixed, label_for?: string, class?: string} $args Field arguments. * @return string Option name. */ function es_optimizer_get_option_name_from_field_args( array $args ): string { + if ( isset( $args['option'] ) && is_string( $args['option'] ) ) { + return $args['option']; + } + $field_id = $args['label_for'] ?? ''; $prefix = 'es_optimizer_field_'; @@ -358,16 +434,18 @@ function es_optimizer_get_option_name_from_field_args( array $args ): string { /** * Register a checkbox settings field. * + * The field is registered without `label_for`, so WordPress prints its title + * as plain text rather than as a label. A click on the title or the help text + * then cannot toggle the setting; only the checkbox itself does. + * * @since 2.0.0 + * @since 2.4.0 The description parameter was removed; the title is no longer a label. * @param string $page Settings page slug. * @param string $section Settings section ID. * @param string $option_name Option name. * @param string $title Field title. - * @param string $description Field description. */ -function es_optimizer_register_checkbox_field( string $page, string $section, string $option_name, string $title, string $description ): void { - es_optimizer_register_field_description( $option_name, $description ); - +function es_optimizer_register_checkbox_field( string $page, string $section, string $option_name, string $title ): void { add_settings_field( $option_name, esc_html( $title ), @@ -375,8 +453,8 @@ function es_optimizer_register_checkbox_field( string $page, string $section, st $page, $section, [ - 'label_for' => es_optimizer_get_field_id( $option_name ), - 'class' => 'es-optimizer-field', + 'option' => $option_name, + 'class' => 'es-optimizer-field', ] ); } @@ -464,24 +542,30 @@ function es_optimizer_settings_page(): void { /** * Render a checkbox option field. * + * Only the checkbox toggles the setting. Its label is for screen readers only + * and takes no space on screen; the help text below is plain text, tied to the + * checkbox as its description. + * * @since 1.0.0 - * @param array{label_for?: string, class?: string} $args Field arguments. + * @since 2.4.0 Prints the three-part help text, and no visible label. + * @param array{option?: mixed, label_for?: string, class?: string} $args Field arguments. */ function es_optimizer_render_checkbox_field( array $args ): void { $options = es_optimizer_get_options(); $option_name = es_optimizer_get_option_name_from_field_args( $args ); - if ( ! array_key_exists( $option_name, es_optimizer_get_default_options() ) ) { + if ( ! in_array( $option_name, es_optimizer_get_boolean_option_keys(), true ) ) { return; } - $field_id = es_optimizer_get_field_id( $option_name ); - $description = es_optimizer_get_field_description( $option_name ); + $field_id = es_optimizer_get_field_id( $option_name ); + $description_id = $field_id . '_description'; ?> - + + " value="1" aria-describedby="" /> +
+ +
-

+ +

diff --git a/languages/enginescript-site-optimizer.pot b/languages/enginescript-site-optimizer.pot index 733a567..622ffa6 100644 --- a/languages/enginescript-site-optimizer.pot +++ b/languages/enginescript-site-optimizer.pot @@ -9,7 +9,7 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2026-11-27T00:02:38+00:00\n" +"POT-Creation-Date: 2026-11-28T02:27:37+00:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "X-Generator: WP-CLI 2.12.0\n" "X-Domain: enginescript-site-optimizer\n" @@ -46,163 +46,291 @@ msgstr "" msgid "Additional Features" msgstr "" -#: includes/admin.php:100 +#: includes/admin.php:97 msgid "Disable WordPress Emojis" msgstr "" -#: includes/admin.php:101 -msgid "Remove WordPress emoji scripts and styles." +#: includes/admin.php:98 +msgid "Remove jQuery Migrate" msgstr "" -#: includes/admin.php:106 -msgid "Remove jQuery Migrate" +#: includes/admin.php:99 +msgid "Disable Classic Theme Styles" msgstr "" -#: includes/admin.php:107 -msgid "Remove the jQuery Migrate script. This may affect plugins or themes that depend on it." +#: includes/admin.php:113 +msgid "Remove WordPress Version" msgstr "" -#: includes/admin.php:112 -msgid "Disable Classic Theme Styles" +#: includes/admin.php:114 +msgid "Remove RSD Link" msgstr "" -#: includes/admin.php:113 -msgid "Remove the classic theme stylesheet added by WordPress." +#: includes/admin.php:115 +msgid "Remove Shortlink" +msgstr "" + +#: includes/admin.php:116 +msgid "Remove Recent Comments Style" +msgstr "" + +#: includes/admin.php:130 +msgid "Disable Jetpack Promotions" msgstr "" #: includes/admin.php:131 -msgid "Remove WordPress Version" +msgid "Disable Post via Email" msgstr "" #: includes/admin.php:132 -msgid "Remove the WordPress version from the document head and from feeds." +msgid "Enable Preconnect" +msgstr "" + +#: includes/admin.php:136 +msgid "Preconnect Domains" msgstr "" #: includes/admin.php:137 -msgid "Remove RSD Link" +msgid "Use preconnect for domains that host critical resources. Enter one HTTPS domain per line, with no port or port 443 only. Do not include file paths, query parameters, fragments, or credentials. Invalid lines are removed on save; an all-invalid list is cleared. Domain checks do not verify DNS destinations." msgstr "" -#: includes/admin.php:138 -msgid "Remove the Really Simple Discovery (RSD) link from the document head." +#: includes/admin.php:139 +msgid "Enable DNS Prefetch" msgstr "" #: includes/admin.php:143 -msgid "Remove Shortlink" +msgid "DNS Prefetch Domains" msgstr "" #: includes/admin.php:144 -msgid "Remove WordPress shortlink URLs from the document head and the HTTP response header." +msgid "DNS prefetch performs only a DNS lookup of the domain name; ports do not affect the hint. Enter one HTTPS domain per line without file paths, query parameters, fragments, or credentials. Invalid lines are removed on save; an all-invalid list is cleared. Domain checks do not verify DNS destinations." msgstr "" -#: includes/admin.php:149 -msgid "Remove Recent Comments Style" +#. translators: 1: Maximum bytes per domain list, 2: Maximum nonblank lines, 3: Maximum bytes per nonblank line. +#: includes/admin.php:158 +#, php-format +msgid "Limits: %1$d bytes per list, %2$d nonblank lines, and %3$d bytes per nonblank line. Duplicate and invalid lines count toward the limit. Oversize submissions keep your previous list." msgstr "" -#: includes/admin.php:150 -msgid "Remove inline CSS from the recent comments widget." +#: includes/admin.php:216 +msgid "Stops WordPress from adding its emoji detection script and emoji styles to every page, the admin area, and embedded posts, and from replacing emoji in feeds and emails with images from WordPress.org." msgstr "" -#: includes/admin.php:168 -msgid "Disable Jetpack Promotions" +#: includes/admin.php:217 +msgid "Emoji still appear, drawn by the visitor's own device, which every current browser and operating system supports. On very old systems without emoji fonts, some emoji may show as empty boxes. Emoji in feeds and emails stay as characters instead of images." msgstr "" -#: includes/admin.php:169 -msgid "Disable Jetpack promotional messages and Blaze promotions." +#: includes/admin.php:218 +msgid "Removes a small inline script and its styles from every page, and the check that script runs in the browser: a small gain for visitors. No change on the server." msgstr "" -#: includes/admin.php:174 -msgid "Disable Post via Email" +#: includes/admin.php:221 +msgid "Stops loading jQuery Migrate on the front end when a theme or plugin loads jQuery. jQuery Migrate restores functions that newer jQuery versions removed. The admin area is not changed." msgstr "" -#: includes/admin.php:175 -msgid "Disable WordPress post via email." +#: includes/admin.php:222 +msgid "Front-end code written for old jQuery versions can stop working, which shows as broken sliders, menus, or forms and as errors in the browser console. Check the interactive parts of the site after turning this on. Pages that do not load jQuery are not affected." msgstr "" -#: includes/admin.php:180 -msgid "Enable Preconnect" +#: includes/admin.php:223 +msgid "One script file fewer to download and run on every page that loads jQuery: a small gain for visitors. No change on the server." msgstr "" -#: includes/admin.php:181 -msgid "Preconnect to external domains for faster resource loading." +#: includes/admin.php:226 +msgid "Removes the small classic-theme stylesheet that WordPress adds on the front end for themes without a theme.json file. It gives the Button and File blocks their default look. Block themes never load it, so on them this setting changes nothing. The editor is not changed." msgstr "" -#: includes/admin.php:186 -msgid "Preconnect Domains" +#: includes/admin.php:227 +msgid "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." msgstr "" -#: includes/admin.php:187 -msgid "Use preconnect for domains that host critical resources. Enter one HTTPS domain per line, with no port or port 443 only. Do not include file paths, query parameters, fragments, or credentials. Invalid lines are removed on save; an all-invalid list is cleared. Domain checks do not verify DNS destinations." +#: includes/admin.php:228 +msgid "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." msgstr "" -#: includes/admin.php:192 -msgid "Enable DNS Prefetch" +#: includes/admin.php:231 +msgid "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." msgstr "" -#: includes/admin.php:193 -msgid "Resolve less critical external domains in DNS ahead of time." +#: includes/admin.php:232 +msgid "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." msgstr "" -#: includes/admin.php:198 -msgid "DNS Prefetch Domains" +#: includes/admin.php:233 +msgid "Removes one line from each page and feed. No measurable speed change." msgstr "" -#: includes/admin.php:199 -msgid "DNS prefetch performs only a DNS lookup of the domain name; ports do not affect the hint. Enter one HTTPS domain per line without file paths, query parameters, fragments, or credentials. Invalid lines are removed on save; an all-invalid list is cleared. Domain checks do not verify DNS destinations." +#: includes/admin.php:236 +msgid "Removes the Really Simple Discovery (RSD) link from the page head. Old desktop blogging programs used it to find the site's XML-RPC address." msgstr "" -#. translators: 1: Maximum bytes per domain list, 2: Maximum nonblank lines, 3: Maximum bytes per nonblank line. -#: includes/admin.php:213 -#, php-format -msgid "Limits: %1$d bytes per list, %2$d nonblank lines, and %3$d bytes per nonblank line. Duplicate and invalid lines count toward the limit. Oversize submissions keep your previous list." +#: includes/admin.php:237 +msgid "A blogging program that relies on this link may need the XML-RPC address entered by hand. XML-RPC itself keeps working; only the link is removed. Most sites notice no difference." +msgstr "" + +#: includes/admin.php:238 +msgid "Removes one line from each page. No measurable speed change." +msgstr "" + +#: includes/admin.php:241 +msgid "Removes the shortlink, the short ?p=123 address of a post, from the page head and from the Link header that WordPress sends with each page." +msgstr "" + +#: includes/admin.php:242 +msgid "Shortlinks still work when someone uses them; they are only no longer advertised. A tool that reads the shortlink from the page uses the full address instead." +msgstr "" + +#: includes/admin.php:243 +msgid "Removes one line from each page and one response header. No measurable speed change." +msgstr "" + +#: includes/admin.php:246 +msgid "Stops WordPress from printing a small inline style for the classic Recent Comments widget. WordPress prints it only on classic themes that support widgets." +msgstr "" + +#: includes/admin.php:247 +msgid "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." +msgstr "" + +#: includes/admin.php:248 +msgid "Removes a few bytes of CSS from pages that show the widget. No measurable speed change." +msgstr "" + +#: includes/admin.php:251 +msgid "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." +msgstr "" + +#: includes/admin.php:252 +msgid "Jetpack keeps working; you no longer see its upgrade and advertising prompts in the admin area. Visitors see no difference." +msgstr "" + +#: includes/admin.php:253 +msgid "Jetpack skips loading and showing these messages, which saves a little work and some requests in the admin area. No change on the front end." +msgstr "" + +#: includes/admin.php:256 +msgid "Turns off publishing by email: the mail server settings disappear from Settings > Writing and can no longer be saved, and the wp-mail.php address that collects the mail refuses requests." msgstr "" -#: includes/admin.php:417 -#: includes/admin.php:436 +#: includes/admin.php:257 +msgid "Nobody can publish posts by sending email to the configured mailbox. Existing posts are not affected. Leave this off if you post by email." +msgstr "" + +#: includes/admin.php:258 +msgid "No speed change. It closes a rarely used way into the site." +msgstr "" + +#: includes/admin.php:261 +msgid "Adds a preconnect hint to the page head for each domain in the Preconnect Domains list, so the browser opens a connection to those servers before it needs them. Front-end pages only; the admin area and the login page are skipped." +msgstr "" + +#: includes/admin.php:262 +msgid "Files from those domains, such as web fonts, can start downloading sooner. A listed domain that the page does not use wastes a connection." +msgstr "" + +#: includes/admin.php:263 +msgid "Can save one or more network round trips the first time each listed domain is used, which helps most on slow or distant connections. Each hint costs the browser a connection, so list only the few domains that serve files a page needs early. No measurable cost on the server." +msgstr "" + +#: includes/admin.php:266 +msgid "The domains that get a preconnect hint while Enable Preconnect is on." +msgstr "" + +#: includes/admin.php:267 +msgid "Only the domains entered here get hints. The suggestions below are examples and are never added on their own." +msgstr "" + +#: includes/admin.php:268 +msgid "Two or three domains are usually enough. More hints compete for the browser's connections and can slow down the files that matter most." +msgstr "" + +#: includes/admin.php:271 +msgid "Adds a DNS prefetch hint to the page head for each domain in the DNS Prefetch Domains list, so the browser looks up those domain names before it needs them. Front-end pages only; the admin area and the login page are skipped." +msgstr "" + +#: includes/admin.php:272 +msgid "Requests to those domains start slightly sooner. Unlike preconnect, no connection is opened, so it suits domains that are used later or only on some pages." +msgstr "" + +#: includes/admin.php:273 +msgid "Saves the name lookup, often a few tens of milliseconds, the first time each listed domain is used. It costs the browser very little, even for a domain that ends up unused. No measurable cost on the server." +msgstr "" + +#: includes/admin.php:276 +msgid "The domains that get a DNS prefetch hint while Enable DNS Prefetch is on." +msgstr "" + +#: includes/admin.php:277 +msgid "Only the domains entered here get hints. The suggestion below is an example and is never added on its own." +msgstr "" + +#: includes/admin.php:278 +msgid "Lookups are cheap, so a longer list does little harm, but each entry only helps if pages request files from that domain." +msgstr "" + +#: includes/admin.php:297 +msgid "What it does:" +msgstr "" + +#: includes/admin.php:298 +msgid "Effect on your site:" +msgstr "" + +#: includes/admin.php:299 +msgid "Performance:" +msgstr "" + +#: includes/admin.php:495 +#: includes/admin.php:514 msgid "Site Optimizer Settings" msgstr "" -#: includes/admin.php:418 +#: includes/admin.php:496 msgid "Site Optimizer" msgstr "" -#: includes/admin.php:432 +#: includes/admin.php:510 msgid "You do not have sufficient permissions to access this page." msgstr "" -#: includes/admin.php:437 +#: includes/admin.php:515 msgid "Select which optimizations you want to enable and customize the resource hint domains." msgstr "" -#: includes/admin.php:443 +#: includes/admin.php:521 msgid "Save Changes" msgstr "" -#: includes/admin.php:449 +#: includes/admin.php:527 msgid "This plugin is part of the EngineScript project." msgstr "" -#: includes/admin.php:451 +#: includes/admin.php:529 msgid "Visit the EngineScript GitHub page" msgstr "" #. translators: Hidden accessibility text. -#: includes/admin.php:455 +#: includes/admin.php:533 msgid "(opens in a new tab)" msgstr "" -#: includes/admin.php:510 +#: includes/admin.php:594 msgid "This saved list exceeds a size limit. It remains displayed here but adds no resource hints until you shorten and save it." msgstr "" -#: includes/admin.php:512 +#: includes/admin.php:596 msgid "Some saved preconnect entries use unsupported ports. They remain displayed here but are skipped in page hints. Saving removes invalid entries; if none are valid, the list is cleared." msgstr "" -#: includes/admin.php:519 +#: includes/admin.php:602 +msgid "Format:" +msgstr "" + +#: includes/admin.php:604 msgid "Optional suggestions: copy only the domains your site uses into the field above, one per line. This list starts empty; suggestions are not enabled automatically. Enable the setting and save your list to add hints." msgstr "" -#: includes/admin.php:538 +#: includes/admin.php:623 msgid "Settings" msgstr "" diff --git a/readme.txt b/readme.txt index b57c551..d4ee854 100644 --- a/readme.txt +++ b/readme.txt @@ -67,6 +67,11 @@ No. The option removes WordPress's generator output from the page head and from == Changelog == += Unreleased = +* 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. +* Explain every setting below its control: what it does, its effect on the site, and its performance gain or cost. The explanations replace the one-line descriptions. +* Name each checkbox for screen readers by its title alone, with the explanation read as its description. + = 2.3.0 - 2026-11-26 = * Deprecate `es_optimizer_clear_options_cache()`, which has done nothing since WordPress took over option caching; calling it triggers WordPress's deprecation notice. * Write the plugin's PHP in PHP 8 forms (short arrays, an arrow function, first-class callables); behavior is unchanged. diff --git a/tests/unit/SettingsPageTest.php b/tests/unit/SettingsPageTest.php index aebfb59..4e07534 100644 --- a/tests/unit/SettingsPageTest.php +++ b/tests/unit/SettingsPageTest.php @@ -85,10 +85,15 @@ public function test_sections_and_fields_cover_every_option(): void { $by_section = array(); foreach ( $fields as $field ) { $by_section[ $field['section'] ][] = $field['id']; - $this->assertSame( 'es_optimizer_field_' . $field['id'], $field['args']['label_for'] ); - $this->assertSame( 'es-optimizer-field', $field['args']['class'] ); - $expected_callback = str_ends_with( $field['id'], '_domains' ) ? 'es_optimizer_render_textarea_field' : 'es_optimizer_render_checkbox_field'; - $this->assertSame( $expected_callback, $field['callback'], $field['id'] ); + if ( str_ends_with( $field['id'], '_domains' ) ) { + // A text area's title is its label: a click on it only puts the cursor in the box. + $this->assertSame( array( 'label_for' => 'es_optimizer_field_' . $field['id'], 'class' => 'es-optimizer-field' ), $field['args'] ); + $this->assertSame( 'es_optimizer_render_textarea_field', $field['callback'] ); + continue; + } + // A checkbox's title is plain text, so a click on it cannot toggle the setting. + $this->assertSame( array( 'option' => $field['id'], 'class' => 'es-optimizer-field' ), $field['args'], $field['id'] ); + $this->assertSame( 'es_optimizer_render_checkbox_field', $field['callback'], $field['id'] ); } $this->assertSame( array( 'disable_emojis', 'remove_jquery_migrate', 'disable_classic_theme_styles' ), $by_section['es_optimizer_performance'] ); $this->assertSame( array( 'remove_wp_version', 'remove_rsd_link', 'remove_shortlink', 'remove_recent_comments_style' ), $by_section['es_optimizer_header_cleanup'] ); @@ -160,7 +165,7 @@ public function test_page_prints_the_form_and_the_footer_link(): void { public function test_page_escapes_every_translated_string(): void { $payload = ''; $GLOBALS['es_optimizer_test']['translations'] = array_fill_keys( - array( 'Site Optimizer Settings', 'Select which optimizations you want to enable and customize the resource hint domains.', 'Save Changes', 'This plugin is part of the EngineScript project.', 'Visit the EngineScript GitHub page', '(opens in a new tab)', 'Remove WordPress emoji scripts and styles.', 'Optional suggestions: copy only the domains your site uses into the field above, one per line. This list starts empty; suggestions are not enabled automatically. Enable the setting and save your list to add hints.' ), + array( 'Site Optimizer Settings', 'Select which optimizations you want to enable and customize the resource hint domains.', 'Save Changes', 'This plugin is part of the EngineScript project.', 'Visit the EngineScript GitHub page', '(opens in a new tab)', 'What it does:', 'Format:', 'Removes one line from each page. No measurable speed change.', 'Disable WordPress Emojis', 'Optional suggestions: copy only the domains your site uses into the field above, one per line. This list starts empty; suggestions are not enabled automatically. Enable the setting and save your list to add hints.' ), $payload ); es_optimizer_init_settings(); @@ -177,12 +182,11 @@ public function test_page_escapes_every_translated_string(): void { */ public function test_checkbox_reflects_the_stored_flag(): void { es_optimizer_init_settings(); - $args = array( 'label_for' => 'es_optimizer_field_remove_rsd_link' ); + $args = array( 'option' => 'remove_rsd_link' ); $off = $this->capture( static fn () => es_optimizer_render_checkbox_field( $args ) ); $this->assertStringContainsString( 'id="es_optimizer_field_remove_rsd_link" type="checkbox" name="es_optimizer_options[remove_rsd_link]" value="1"', $off ); $this->assertStringNotContainsString( 'checked', $off ); - $this->assertStringContainsString( 'Remove the Really Simple Discovery (RSD) link from the document head.', $off ); $this->store_options( array( 'remove_rsd_link' => 1 ) ); $this->assertStringContainsString( "checked='checked'", $this->capture( static fn () => es_optimizer_render_checkbox_field( $args ) ) ); @@ -197,14 +201,77 @@ public function test_checkbox_reflects_the_stored_flag(): void { * @return void */ public function test_fields_ignore_unknown_arguments(): void { - foreach ( array( array(), array( 'label_for' => 'other_field' ), array( 'label_for' => 'es_optimizer_field_unknown' ) ) as $args ) { + foreach ( array( array(), array( 'label_for' => 'other_field' ), array( 'label_for' => 'es_optimizer_field_unknown' ), array( 'option' => 'unknown' ), array( 'option' => array( 'remove_rsd_link' ) ) ) as $args ) { $this->assertSame( '', $this->capture( static fn () => es_optimizer_render_checkbox_field( $args ) ) ); $this->assertSame( '', $this->capture( static fn () => es_optimizer_render_textarea_field( $args ) ) ); } + $this->assertSame( '', $this->capture( static fn () => es_optimizer_render_checkbox_field( array( 'option' => 'preconnect_domains' ) ) ), 'A text-area option is not a checkbox.' ); + $this->assertSame( 'remove_rsd_link', es_optimizer_get_option_name_from_field_args( array( 'option' => 'remove_rsd_link' ) ) ); $this->assertSame( 'remove_rsd_link', es_optimizer_get_option_name_from_field_args( array( 'label_for' => 'es_optimizer_field_remove_rsd_link' ) ) ); $this->assertSame( '', es_optimizer_get_option_name_from_field_args( array( 'label_for' => 'field_remove_rsd_link' ) ) ); } + /** + * Only the checkbox toggles a setting: its one label is for screen readers, and the help is plain text tied to it. + * + * @return void + */ + public function test_only_the_checkbox_toggles_a_setting(): void { + es_optimizer_init_settings(); + + // The title row is WordPress's own markup: test_sections_and_fields_cover_every_option checks + // that checkboxes register no label_for, which is what makes WordPress print the title as text. + foreach ( es_optimizer_get_boolean_option_keys() as $option ) { + $id = 'es_optimizer_field_' . $option; + $output = $this->capture( static fn () => es_optimizer_render_checkbox_field( array( 'option' => $option ) ) ); + + $this->assertSame( 1, substr_count( $output, 'assertStringContainsString( '', $output ); + $this->assertStringContainsString( 'aria-describedby="' . $id . '_description"', $output ); + $this->assertMatchesRegularExpression( '#/>\s*
\s*

What it does: #', $output, 'The help follows the checkbox, outside any label.' ); + } + } + + /** + * Every setting explains what it does, its effect, and its performance, in that order. + * + * @return void + */ + public function test_every_setting_has_three_part_help(): void { + $help = es_optimizer_get_option_help(); + + $expected = array_keys( es_optimizer_get_default_options() ); + $actual = array_keys( $help ); + sort( $expected ); + sort( $actual ); + $this->assertSame( $expected, $actual, 'One entry per option.' ); + foreach ( $help as $option => $parts ) { + $this->assertSame( array( 'what', 'effect', 'performance' ), array_keys( $parts ), $option ); + foreach ( $parts as $part => $text ) { + $this->assertNotSame( '', trim( $text ), "{$option} {$part}" ); + } + } + + $output = $this->capture( static fn () => es_optimizer_render_option_help( 'disable_emojis' ) ); + $this->assertSame( 3, substr_count( $output, '

' ) ); + $this->assertStringContainsString( '

Effect on your site: ', $output ); + $this->assertStringContainsString( '

Performance: ', $output ); + $this->assertSame( '', $this->capture( static fn () => es_optimizer_render_option_help( 'unknown' ) ) ); + $this->assertSame( '', es_optimizer_get_field_title( 'unknown' ) ); + } + + /** + * A text area shows the three-part help, then its format rules. + * + * @return void + */ + public function test_textarea_shows_help_then_format(): void { + es_optimizer_init_settings(); + $output = $this->capture( static fn () => es_optimizer_render_textarea_field( array( 'label_for' => 'es_optimizer_field_dns_prefetch_domains' ) ) ); + + $this->assertMatchesRegularExpression( '#

What it does: .*

Effect on your site: .*

Performance: .*

Format: DNS prefetch performs only a DNS lookup#s', $output ); + } + /** * A stored list is printed as text in the text area, and the description is tied to it. *