From 7b3c00cacc8d1c1d08d599e1199d18cd628cc412 Mon Sep 17 00:00:00 2001 From: Javier Casares Date: Tue, 3 Nov 2026 17:02:51 +0000 Subject: [PATCH] v3.2.0 --- changelog.txt | 33 ++++ languages/noindex-seo-ca.mo | Bin 16104 -> 17317 bytes languages/noindex-seo-ca.po | 29 +++ languages/noindex-seo-es_ES.mo | Bin 16083 -> 17264 bytes languages/noindex-seo-es_ES.po | 29 +++ languages/noindex-seo.pot | 29 +++ noindex-seo.php | 325 ++++++++++++++++++++++++++++++++- readme.txt | 18 +- 8 files changed, 454 insertions(+), 9 deletions(-) diff --git a/changelog.txt b/changelog.txt index 6efd308..8757699 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,38 @@ == Changelog == += 3.2.0 = + +_Release date: 2026-09-18_ +**Highlights** + +* Two roadmap features: JSON export/import of the settings (#6) and runtime conflict verification against the `wp_robots` API (#10). + +**Added** + +* **Export / Import of settings (JSON).** Two new controls on the settings page: "Export settings" downloads the consolidated settings as a JSON file (`noindex-seo-settings-{date}.json`), and "Import settings" restores the global settings from a previously exported file. Imports are strictly validated and sanitized: plugin marker check, 1 MB size limit, `is_uploaded_file()` verification, the upload is never persisted to the uploads directory, every directive is normalized to 0/1, config values go through the same safelists as the settings form, and contexts that do not exist on the importing site (e.g. custom post types from another install) are dropped. Per-post and per-term granular overrides are content data and are never touched by an import. Both actions require `manage_options` and a nonce; success and error notices survive the redirect. +* **Runtime conflict verification (TODO #10).** When no known SEO plugin conflicts, `noindex_seo_detect_conflicts()` now also inspects the callbacks actually registered on the `wp_robots` filter (WordPress 5.7+): anything that is not a core callback or one of ours — a foreign function, a class method, or a closure from a theme or unknown plugin — produces a dismissible admin notice naming the detected callback. The core callback safelist is filterable via `noindex_seo_core_robots_callbacks`. The notice honours the existing "disable compatibility warnings" opt-out. + +**Changed** + +* Nothing. + +**Fixed** + +* Nothing. + +**Security** + +* No security changes; the new endpoints follow the canonical checklist (capability + nonce on both actions, strict input validation, safelisted config values, no persistence of uploads) and PHPCS/PHPStan/composer audit stay clean. + +**Compatibility** + +* WordPress: 4.7 - 7.2 +* PHP: 5.6 - 8.5 + +**Tests** + +* PHPUnit: 9.6.36 (165 tests, all passing): export payload shape and JSON round-trip, import sanitizer (happy path, normalization, unknown-context dropping, malformed-payload rejection), handler guards, foreign-callback detection (functions, class methods, closures, own-prefix skipping, filterable safelist) and the runtime notice. + = 3.1.6 = _Release date: 2026-09-18_ diff --git a/languages/noindex-seo-ca.mo b/languages/noindex-seo-ca.mo index 4a9cbac24af377a7744d6b3a64d611438e0b3550..15b212d62a5fa26461623a29765ba7a8c58175d5 100644 GIT binary patch delta 4313 zcmZYAd5{$48OQN=xfWP1S#B`Au&&Fpu;9uqH;V*Vj&KB(vzh7L8JL+KdwP~d#1T*k zk%+Q_qEe6;gH%OgWr`$}7Q_%MAsGCFN=(cFl_DuMCRIr+5mF}k{$_fGBwalFdAq0k z?e~43=WX8K{_>uZ-0ypLIA}PI5JQL#9gVq!A9djm$E5DY^v20pjtw{nH()7l!_K%1 zd*MDT!z0)UPvD*S8rI>vI0d`*FlLM~IWw2Wd@f|M2G8PX{4sdFYw=Um{Z))&7%syR7@&SXf_m<4)O)Vu7~XFxZ!2C{iPQLD2kL>ds1^AuYKCPj z!%Nr)yWtOT4ZelX;c%9RTg~gCKgSN7Uq&Wvu3~%qJ67N)*q`^CL4AxFk9DY-$FMIR z!hZN|oQ3DG5&@U#R=q_b+xZ5Fg>Z8rAVDNZFV?YUxkoVEhg0h1Wt$2Nd7aAC-a;16Y6B zW(9v#BuUf@pFur%IP?VSMW<0q{9|O*%`Z_o{Q#AcegliYS70^g<5B&rN9JHW)I@iO z=g$sg{WX%4T$qIKp^B}X64&)fs9K2PIBdnc@TaJbZlH>?jOnUI?#3QC6_tX8s1&Tk zo#>!e@+xk|8#x-Z)Ife1{{A+q7<0d%p{4ybx_A|*H3`RB=}R_dFfc~n0?!tUDt@6b>OzeCfG{fTT%^A9SL?3hv# ztR<{KR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xj494!t+|hO zjx3__+lRVcBZ?%ENhF+TyhYUYuWExafuxexNEPuX4@N$dOiyg^qySHI_!%GfqR1nj z^r&;bp7NLkANPUS5uW^>EquH^ JcVW(q{{dcZOK1Q9 diff --git a/languages/noindex-seo-ca.po b/languages/noindex-seo-ca.po index d4e1122..674d751 100644 --- a/languages/noindex-seo-ca.po +++ b/languages/noindex-seo-ca.po @@ -715,3 +715,32 @@ msgstr "Evita fragments de text als resultats de cerca" #: assets/js/editor-sidebar.js:237 msgid "Active Directives:" msgstr "Directrius actives:" + +#: noindex-seo.php +msgid "Export settings" +msgstr "Exporta els ajustaments" + +#: noindex-seo.php +msgid "Download the current settings as a JSON file." +msgstr "Baixa els ajustaments actuals en un fitxer JSON." + +#: noindex-seo.php +msgid "Import settings" +msgstr "Importa els ajustaments" + +#: noindex-seo.php +msgid "Restore the global settings from a previously exported JSON file. Per-post and per-term overrides are kept." +msgstr "Restaura els ajustaments globals des d'un fitxer JSON exportat anteriorment. Les sobreescriptures per entrada i per terme es conserven." + +#: noindex-seo.php +msgid "Settings imported successfully." +msgstr "S'han importat els ajustaments correctament." + +#: noindex-seo.php +msgid "The settings file could not be imported: it is missing, too large, or not a valid noindex SEO export." +msgstr "No s'ha pogut importar el fitxer d'ajustaments: no existeix, és massa gran o no és una exportació vàlida de noindex SEO." + +#, php-format +#: noindex-seo.php +msgid "noindex SEO has detected that another plugin or theme is adding robots directives through the wp_robots API (%s). This may cause conflicts. Please configure the options accordingly." +msgstr "noindex SEO ha detectat que un altre complement o tema està afegint directrius de robots a través de l'API wp_robots (%s). Això pot causar conflictes. Configureu les opcions en conseqüència." diff --git a/languages/noindex-seo-es_ES.mo b/languages/noindex-seo-es_ES.mo index 23164c5499d1c430c7bbc86598af233f9dc47b69..91253a34cf8241694ca693322ef3fa0da6cb4880 100644 GIT binary patch delta 4339 zcmZA33vd+m9l-H_c*PLjkAxVMKTsYa%Zz2HH;zz7=$JaCqn+AesBN7VYneW#PRF)0(mI3o`@7u>On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HJL3Ggmze!`a$ zT^s1ji|H8PJsjKLml; $plugin_name ) { if ( is_plugin_active( $plugin_path ) ) { // Add an admin notice if a conflicting plugin is active.. @@ -1655,13 +1656,113 @@ function noindex_seo_detect_conflicts() { echo '

'; } ); + $found_conflict = true; break; // Stop checking after finding the first conflict. } } + + // Runtime verification (3.2.0): when no known plugin conflicts, check + // whether anything else is actually emitting robots directives through + // the wp_robots API — this also catches themes and unknown plugins. + // Only possible on WordPress 5.7+ (the filter does not exist earlier). + if ( ! $found_conflict && function_exists( 'has_filter' ) && has_filter( 'wp_robots' ) ) { + $foreign_callbacks = noindex_seo_get_foreign_robots_callbacks(); + if ( ! empty( $foreign_callbacks ) ) { + add_action( + 'admin_notices', + function () use ( $foreign_callbacks ) { + echo '

'; + // translators: %s: comma-separated list of wp_robots callbacks. + printf( esc_html__( 'noindex SEO has detected that another plugin or theme is adding robots directives through the wp_robots API (%s). This may cause conflicts. Please configure the options accordingly.', 'noindex-seo' ), esc_html( implode( ', ', $foreign_callbacks ) ) ); + echo '

'; + } + ); + } + } } } add_action( 'admin_init', 'noindex_seo_detect_conflicts' ); +/** + * Returns the wp_robots filter callbacks that do not belong to WordPress + * core or to this plugin. + * + * Runtime conflict verification for {@see noindex_seo_detect_conflicts()}: + * instead of trusting plugin slugs, this inspects the callbacks actually + * registered on the `wp_robots` filter. Core registers plain functions + * (wp_robots_noindex, wp_robots_noindex_embeds, wp_robots_noindex_search, + * wp_robots_max_image_preview_large and, conditionally, wp_robots_no_robots); + * anything else — named functions from other code, class methods, or + * closures — is a third-party robots emitter. + * + * Only meaningful on WordPress 5.7+; on older versions the filter does not + * exist and an empty array is returned. + * + * @since 3.2.0 + * + * @return string[] Unique readable callback identifiers ('function', + * 'Class::method' or 'Closure'). + */ +function noindex_seo_get_foreign_robots_callbacks() { + $foreign = array(); + + $wp_filter = isset( $GLOBALS['wp_filter'] ) && is_array( $GLOBALS['wp_filter'] ) ? $GLOBALS['wp_filter'] : array(); + $robots_hook = isset( $wp_filter['wp_robots'] ) ? $wp_filter['wp_robots'] : null; + if ( ! $robots_hook instanceof WP_Hook ) { + return $foreign; + } + + /** + * Filter the wp_robots callbacks considered native to WordPress core. + * + * Third-party code can extend this list if it needs to mark its own + * callback as expected (e.g. a site-specific mu-plugin). + * + * @since 3.2.0 + * + * @param string[] $core_callbacks Function names registered by core on wp_robots. + */ + $core_callbacks = apply_filters( + 'noindex_seo_core_robots_callbacks', + array( + 'wp_robots_noindex', + 'wp_robots_noindex_embeds', + 'wp_robots_noindex_search', + 'wp_robots_max_image_preview_large', + 'wp_robots_no_robots', + ) + ); + + foreach ( $robots_hook->callbacks as $callbacks ) { + foreach ( $callbacks as $callback ) { + $function = $callback['function']; + + if ( $function instanceof Closure ) { + $identifier = 'Closure'; + } elseif ( is_string( $function ) ) { + if ( in_array( $function, $core_callbacks, true ) || 0 === strpos( $function, 'noindex_seo_' ) ) { + continue; + } + $identifier = $function; + } elseif ( is_array( $function ) ) { + $class = is_object( $function[0] ) ? get_class( $function[0] ) : (string) $function[0]; + if ( 0 === strpos( $class, 'noindex_seo_' ) || 0 === strpos( $class, 'Noindex_Seo_' ) ) { + continue; + } + $identifier = $class . '::' . (string) $function[1]; + } else { + continue; + } + + if ( ! in_array( $identifier, $foreign, true ) ) { + $foreign[] = $identifier; + } + } + } + + return $foreign; +} + /** * Processes the form submission for the 'noindex SEO' plugin settings. * @@ -1805,6 +1906,169 @@ function noindex_seo_process_apply_suggestions() { } add_action( 'admin_post_noindex_seo_apply_suggestions', 'noindex_seo_process_apply_suggestions' ); +/** + * Builds the JSON export payload for the current settings. + * + * The payload carries a plugin marker, an export timestamp and the full + * consolidated settings array, so a backup can be identified and validated + * on import. + * + * @since 3.2.0 + * + * @return array Export payload. + */ +function noindex_seo_build_export_payload() { + return array( + 'plugin' => 'noindex-seo', + 'exported' => gmdate( 'c' ), + 'settings' => noindex_seo_get_settings(), + ); +} + +/** + * Handles the "Export settings" form action: streams the current settings + * as a downloadable JSON file. + * + * Hooked to the {@see 'admin_post_noindex_seo_export'} action. + * + * @since 3.2.0 + * + * @return void + */ +function noindex_seo_handle_export() { + if ( ! current_user_can( 'manage_options' ) ) { + wp_die( esc_html__( 'Permission denied.', 'noindex-seo' ) ); + } + check_admin_referer( 'noindex_seo_export' ); + + nocache_headers(); + header( 'Content-Type: application/json; charset=utf-8' ); + header( 'Content-Disposition: attachment; filename=noindex-seo-settings-' . gmdate( 'Ymd-His' ) . '.json' ); + echo wp_json_encode( noindex_seo_build_export_payload() ); + exit; +} +add_action( 'admin_post_noindex_seo_export', 'noindex_seo_handle_export' ); + +/** + * Validates and sanitizes a settings array that came from an imported + * JSON file. + * + * Only contexts and directives currently known to the plugin are imported + * (contexts for custom post types that do not exist on this site are + * silently dropped); every directive value is normalized to 0/1 and every + * config value to its safelisted form. The returned array always has the + * full default shape of noindex_seo_get_settings(). + * + * @since 3.2.0 + * + * @param mixed $raw Decoded JSON 'settings' value. + * @return array{ + * version: int, + * contexts: array>, + * config: array{ + * method: string, + * granular: int, + * taxonomies_granular: int, + * seoplugins: int, + * delete_on_uninstall: int + * } + * }|null Sanitized settings array, or null when the payload is not importable. + */ +function noindex_seo_sanitize_imported_settings( $raw ) { + if ( ! is_array( $raw ) || ! isset( $raw['contexts'], $raw['config'] ) || ! is_array( $raw['contexts'] ) || ! is_array( $raw['config'] ) ) { + return null; + } + + $settings = noindex_seo_get_settings(); + $directives = array( 'noindex', 'nofollow', 'noarchive', 'nosnippet', 'noimageindex' ); + + foreach ( noindex_seo_get_contexts() as $context ) { + if ( ! isset( $raw['contexts'][ $context ] ) || ! is_array( $raw['contexts'][ $context ] ) ) { + continue; + } + foreach ( $directives as $directive ) { + if ( isset( $raw['contexts'][ $context ][ $directive ] ) && is_numeric( $raw['contexts'][ $context ][ $directive ] ) ) { + $settings['contexts'][ $context ][ $directive ] = ( 1 === (int) $raw['contexts'][ $context ][ $directive ] ) ? 1 : 0; + } + } + } + + $raw_config = $raw['config']; + + $method = isset( $raw_config['method'] ) && is_string( $raw_config['method'] ) + ? $raw_config['method'] + : 'meta'; + $settings['config']['method'] = in_array( $method, array( 'meta', 'header', 'both' ), true ) ? $method : 'meta'; + + foreach ( array( 'granular', 'taxonomies_granular', 'seoplugins', 'delete_on_uninstall' ) as $key ) { + $value = isset( $raw_config[ $key ] ) && is_numeric( $raw_config[ $key ] ) ? (int) $raw_config[ $key ] : 0; + $settings['config'][ $key ] = ( 1 === $value ) ? 1 : 0; + } + + return $settings; +} + +/** + * Handles the "Import settings" form action: reads an uploaded JSON backup + * and restores the global settings from it. + * + * The upload is validated (error code, size limit, is_uploaded_file) and + * never persisted to the uploads directory. Per-post and per-term granular + * overrides are content data and are never touched by an import. + * + * Hooked to the {@see 'admin_post_noindex_seo_import'} action. + * + * @since 3.2.0 + * + * @return void + */ +function noindex_seo_handle_import() { + if ( ! current_user_can( 'manage_options' ) ) { + wp_die( esc_html__( 'Permission denied.', 'noindex-seo' ) ); + } + check_admin_referer( 'noindex_seo_import' ); + + $redirect_error = admin_url( 'options-general.php?page=noindex_seo&import_error=1' ); + + // The upload is validated immediately below (error code, size, is_uploaded_file) and its + // contents go through strict JSON shape validation before anything is persisted. + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + $upload = isset( $_FILES['noindex_seo_import_file'] ) && is_array( $_FILES['noindex_seo_import_file'] ) + ? $_FILES['noindex_seo_import_file'] // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + : array(); + + $error = isset( $upload['error'] ) && is_numeric( $upload['error'] ) ? (int) $upload['error'] : -1; + $size = isset( $upload['size'] ) && is_numeric( $upload['size'] ) ? (int) $upload['size'] : 0; + $tmp = isset( $upload['tmp_name'] ) && is_string( $upload['tmp_name'] ) ? $upload['tmp_name'] : ''; + + if ( UPLOAD_ERR_OK !== $error || '' === $tmp || $size > 1048576 || ! is_uploaded_file( $tmp ) ) { + wp_safe_redirect( $redirect_error ); + exit; + } + + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- reading the just-validated upload before it is discarded; is_uploaded_file() was checked above. + $raw = file_get_contents( $tmp ); + $data = is_string( $raw ) ? json_decode( $raw, true ) : null; + + if ( ! is_array( $data ) || 'noindex-seo' !== ( isset( $data['plugin'] ) ? $data['plugin'] : '' ) ) { + wp_safe_redirect( $redirect_error ); + exit; + } + + $settings = noindex_seo_sanitize_imported_settings( isset( $data['settings'] ) ? $data['settings'] : null ); + + if ( null === $settings ) { + wp_safe_redirect( $redirect_error ); + exit; + } + + noindex_seo_update_settings( $settings ); + + wp_safe_redirect( admin_url( 'options-general.php?page=noindex_seo&imported=1' ) ); + exit; +} +add_action( 'admin_post_noindex_seo_import', 'noindex_seo_handle_import' ); + /** * Returns the list of contexts flagged as suggested defaults on the settings page. * @@ -3347,6 +3611,20 @@ function noindex_seo_admin() { echo '

'; } } + + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display-only flag set by our own admin-post handler after a nonce check. + if ( '1' === ( isset( $_GET['imported'] ) && is_string( $_GET['imported'] ) ? sanitize_key( wp_unslash( $_GET['imported'] ) ) : '' ) ) { + echo '

'; + esc_html_e( 'Settings imported successfully.', 'noindex-seo' ); + echo '

'; + } + + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display-only flag set by our own admin-post handler after a nonce check. + if ( '1' === ( isset( $_GET['import_error'] ) && is_string( $_GET['import_error'] ) ? sanitize_key( wp_unslash( $_GET['import_error'] ) ) : '' ) ) { + echo '

'; + esc_html_e( 'The settings file could not be imported: it is missing, too large, or not a valid noindex SEO export.', 'noindex-seo' ); + echo '

'; + } ?> +
+ + + + + + +
+ +
+ + + + + + + + +
+
diff --git a/readme.txt b/readme.txt index 55b9f96..3e60883 100644 --- a/readme.txt +++ b/readme.txt @@ -3,9 +3,9 @@ Contributors: robotstxt, javiercasares Tags: seo, noindex, nofollow, noarchive, robots Requires at least: 4.7 Tested up to: 7.2 -Stable tag: 3.1.6 +Stable tag: 3.2.0 Requires PHP: 5.6 -Version: 3.1.6 +Version: 3.2.0 License: GPL-3.0-or-later License URI: https://www.gnu.org/licenses/gpl-3.0.txt @@ -99,6 +99,10 @@ Important note: if you have any doubt about any of the following items it is bes == Using the plugin == += Export / Import = + +The settings page includes an "Export settings" button that downloads the current global settings as a JSON file, and an "Import settings" form that restores them on the same or another site (useful for migrations and staging-to-production copies). Imports are strictly validated, and per-post / per-term overrides are never touched. + = REST API = The plugin exposes two read-only endpoints under `/wp-json/noindex-seo/v1/` so headless consumers can read the configuration: @@ -139,6 +143,10 @@ No. By default all plugin data is preserved on uninstall. If you want a complete == Changelog == += 3.2.0 = + +Feature release: JSON export/import of the settings (validated, sanitized, per-post and per-term overrides untouched) and runtime conflict verification against the `wp_robots` API (foreign callbacks named in a dismissible notice). + = 3.1.6 = Admin UI modernization: all inline styles removed in favour of WordPress admin color-scheme-aware, RTL-ready classes (follows the admin color schemes instead of hardcoded colors); stale form-handler message corrected; unreachable REST fallbacks removed; Catalan and Spanish translations updated. @@ -147,10 +155,6 @@ Admin UI modernization: all inline styles removed in favour of WordPress admin c Maintenance review: WordPress floor corrected to 4.7 (oldest tested version, first with the complete REST API) and tested up to 7.2; nonce verification in the form handlers split into a capability check plus a standalone `check_admin_referer()`; dev dependencies updated; test suite expanded to 147 tests with 94.78% coverage. -= 3.1.3 = - -Compatibility release: WordPress 4.0+ and PHP 5.6+ supported again (the classic `` output covers WordPress versions without the `wp_robots` API, and every newer-API integration degrades gracefully). Branding moved to robotstxt.software. - = Previous versions = If you want to see the full changelog, visit the [noindex SEO plugin page](https://www.robotstxt.software/plugins/noindex-seo/). @@ -171,6 +175,6 @@ This plugin adheres to the following security measures and review protocols for == Vulnerabilities == -* No vulnerabilities have been published up to version 3.1.6. +* No vulnerabilities have been published up to version 3.2.0. Found a security vulnerability? Please report it to us privately at the [noindex SEO GitHub repository](https://github.com/javiercasares/noindex-seo/security/advisories/new).