v3.7.1
This commit is contained in:
parent
54122d3d95
commit
ba2c697d36
4 changed files with 374 additions and 139 deletions
|
|
@ -1,5 +1,60 @@
|
||||||
== Changelog ==
|
== Changelog ==
|
||||||
|
|
||||||
|
= 3.7.1 =
|
||||||
|
|
||||||
|
_Release date: 2026-11-26_
|
||||||
|
|
||||||
|
**Highlights**
|
||||||
|
|
||||||
|
* WordPress 7.2 certified: verified on 7.2-RC3 (build 65782, treated as GA), `Tested up to: 7.2`. PHP 8.6 support verified on PHP 8.6.0 GA.
|
||||||
|
* Static analysis raised to PHPStan level 10 (the maximum) with no baseline and no ignore comments: every finding was fixed in code.
|
||||||
|
* Two front-end/admin bugs fixed (contradictory `follow, nofollow` on search results; missing notranslate icon on WordPress 7.0 - 7.1) and a round of input-validation and database-API hardening.
|
||||||
|
|
||||||
|
**Added**
|
||||||
|
|
||||||
|
* Nothing.
|
||||||
|
|
||||||
|
**Changed**
|
||||||
|
|
||||||
|
* The 2.x → 3.x migration now flips the legacy options to non-autoloaded with the core `wp_set_option_autoload_values()` API (which also keeps the options cache consistent) instead of a hand-written `UPDATE` query; the main plugin file no longer contains direct SQL.
|
||||||
|
* `uninstall.php` builds every query with the `%i` identifier placeholder (wildcard option/transient prefixes, and one `DELETE … WHERE meta_key = %s` per post/term meta key — kept as single statements so large sites never load every meta ID into PHP), and also deletes the import-count transient through the Transients API so persistent object caches are cleared.
|
||||||
|
* The import queries drop the redundant `suppress_filters => true` (already the `get_posts()` default; flagged by Plugin Check). Behavior is unchanged.
|
||||||
|
* The test suite is version-aware: SVG-only icon assertions are skipped below WordPress 7.2 and the emoji fallback is asserted instead, so the suite passes on every supported WordPress version. `phpunit.xml` uses the PHPUnit 9.6 schema attribute (`processUncoveredFiles`).
|
||||||
|
* Development dependencies refreshed via `composer update`: PHPStan 2.3.7, PHPUnit 9.6.39, doctrine/instantiator 2.2.0 (no CVEs).
|
||||||
|
|
||||||
|
**Fixed**
|
||||||
|
|
||||||
|
* Search results (and any page where another source adds the positive counterpart) printed contradictory robots directives — `noindex, follow, …, nofollow` — when the plugin enabled `nofollow`: core's `wp_robots_noindex_search()` adds `follow` on search results and the plugin added `nofollow` next to it. A plugin `nofollow` now replaces `follow`, and a plugin `noindex` replaces `index`. This also applies to the HTTP-header-only output method: the plugin still adds nothing to the meta tag, but a header `nofollow` / `noindex` now removes the `follow` / `index` that the tag other sources print would otherwise contradict it with (nothing else in that tag is changed).
|
||||||
|
* The `notranslate` directive (added in 3.6.0) rendered no icon on WordPress 7.0 - 7.1: its legacy emoji fallback glyph was missing, so the settings grid, meta box, Quick Edit and Robots columns showed an empty slot. It now falls back to 🌐 like the other directives.
|
||||||
|
* Entries returned by the `noindex_seo_import_sources` filter are validated (slug, label, and noindex/nofollow flag specs); malformed ones — or a non-array filter result — are dropped instead of raising PHP warnings in the import counter and runner. A non-array or non-string `noindex_seo_conflicting_plugins` filter result is ignored the same way.
|
||||||
|
* Cached import counts with stale or foreign value types are recounted instead of being cast.
|
||||||
|
* `unavailable_after` (added in 3.6.0) printed the raw site-time value without a UTC offset in the robots meta tag (`unavailable_after:2030-01-01 09:00`), so crawlers could read a time shifted by the site's offset, and the RFC 1123 form used in the `X-Robots-Tag` header contained a comma (`Tue, 01 Jan …`) that collided with the directive separator. Both outputs now use ISO 8601 with the offset (`2030-01-01T09:00:00+01:00`), a format search engines document as supported. Stored values are unchanged.
|
||||||
|
|
||||||
|
**Security**
|
||||||
|
|
||||||
|
* The legacy 2.x options are registered with a `sanitize_callback` (`absint` for the 0/1 flags; the method is whitelisted to `meta`, `header` or `both`, falling back to `meta`): a direct `options.php` write — `manage_options` only — can no longer store unsanitized values. Resolves the five Plugin Check `register_setting()` errors. Registration is limited to the five directives that had 2.x options (the 3.6.0 directives were registered as phantom legacy options before).
|
||||||
|
* The uninstall wildcard cleanup escapes its prefixes with `$wpdb->esc_like()`: the `_` in `noindex_seo_%` is a LIKE wildcard, so the old pattern could also delete look-alike options of other plugins (`noindexXseoX…`).
|
||||||
|
* No new attack surface. PHPCS, PHPStan level 10, Plugin Check (0 errors) and `composer audit` clean.
|
||||||
|
|
||||||
|
**Compatibility**
|
||||||
|
|
||||||
|
* WordPress: 7.0 - 7.2
|
||||||
|
* PHP: 8.3 - 8.6
|
||||||
|
* WP-CLI: 2.12.0
|
||||||
|
* PHP 8.6 needs WordPress 7.1 or newer: WordPress 7.0.9 core itself raises PHP 8.6 deprecations (`spl_object_hash()`, constructor return values); the plugin's own code is clean on 8.6.
|
||||||
|
|
||||||
|
**Tests**
|
||||||
|
|
||||||
|
* PHP Coding Standards: 3.13.6
|
||||||
|
* WordPress Coding Standards: 3.4.1
|
||||||
|
* Plugin Check (PCP): 2.2.0 — 0 errors; 4 justified warnings (`load_plugin_textdomain()` for the bundled translations, `post__not_in` / `exclude` in the sitemap exclusions).
|
||||||
|
* PHPUnit: 9.6.39 — 238 tests, 1196 assertions, all passing on WordPress 7.2-RC3 under PHP 7.4, 8.0, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6.0, single site and Multisite; also passing on WordPress 7.1.5 (PHP 8.3 - 8.6), 7.0.9 (PHP 8.3 - 8.5), 6.9.12 and 6.4.15 (PHP 8.3).
|
||||||
|
* PHPStan: 2.3.7, level 10, no baseline, 0 errors.
|
||||||
|
* Pre-deploy AI audit (clean context): CONDITIONAL PASS, no critical findings; every finding was fixed before release (non-array import-sources filter result, uninstall meta deletion at scale, header-only `follow`, legacy method whitelist, `unavailable_after` offset); a second clean-context audit of those fixes found no critical issue. No known issues remain open.
|
||||||
|
* PHPCompatibility: 9.3.5 — 0 errors on the declared range 8.3-8.6 and on the full review ranges 7.4-8.6 and 5.6-8.6; PHP 8.6 deprecation scan (`spl_object_hash`, `is_integer`, `is_double`, `strcoll`, `mb_ereg*`, `is_a()`, constructor/destructor returns, `class Is`, `const namespace`) and `opcache_reset()` / `opcache_invalidate()` usage: none.
|
||||||
|
* Real compatibility (measured, beyond the declared window): WordPress 6.4+ (static API floor via wp-compat; was 5.3 in 3.7.0) and PHP 7.4+ (runtime-verified).
|
||||||
|
* Database: MariaDB 11.8.10.
|
||||||
|
|
||||||
= 3.7.0 =
|
= 3.7.0 =
|
||||||
|
|
||||||
_Release date: 2026-11-03_
|
_Release date: 2026-11-03_
|
||||||
|
|
|
||||||
322
noindex-seo.php
322
noindex-seo.php
|
|
@ -3,7 +3,7 @@
|
||||||
* Plugin Name: noindex SEO
|
* Plugin Name: noindex SEO
|
||||||
* Plugin URI: https://www.robotstxt.software/plugins/noindex-seo/
|
* Plugin URI: https://www.robotstxt.software/plugins/noindex-seo/
|
||||||
* Description: Control search engine indexing with robots directives (noindex, nofollow, noarchive, nosnippet, noimageindex) for specific parts of your WordPress site.
|
* Description: Control search engine indexing with robots directives (noindex, nofollow, noarchive, nosnippet, noimageindex) for specific parts of your WordPress site.
|
||||||
* Version: 3.7.0
|
* Version: 3.7.1
|
||||||
* Requires at least: 7.0
|
* Requires at least: 7.0
|
||||||
* Requires PHP: 8.3
|
* Requires PHP: 8.3
|
||||||
* Author: ROBOTSTXT
|
* Author: ROBOTSTXT
|
||||||
|
|
@ -81,8 +81,13 @@ defined( 'ABSPATH' ) || die( 'Bye bye!' );
|
||||||
* other SEO plugins (Yoast, Rank Math, SEOPress, AIOSEO) and
|
* other SEO plugins (Yoast, Rank Math, SEOPress, AIOSEO) and
|
||||||
* virtual robots.txt management (bot rules appended to the
|
* virtual robots.txt management (bot rules appended to the
|
||||||
* WordPress-generated robots.txt, inactive by default).
|
* WordPress-generated robots.txt, inactive by default).
|
||||||
|
* @since 3.7.1 Maintenance release: certified on WordPress 7.2 and PHP 8.6,
|
||||||
|
* PHPStan level 10 (no baseline), search-results follow/nofollow
|
||||||
|
* conflict and the missing notranslate fallback icon fixed,
|
||||||
|
* legacy settings sanitized, direct SQL reduced to the uninstall
|
||||||
|
* wildcard cleanup.
|
||||||
*/
|
*/
|
||||||
define( 'NOINDEX_SEO_VERSION', '3.7.0' );
|
define( 'NOINDEX_SEO_VERSION', '3.7.1' );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Option key holding the consolidated plugin settings array.
|
* Option key holding the consolidated plugin settings array.
|
||||||
|
|
@ -183,14 +188,35 @@ function noindex_seo_normalize_directive_value( $directive, $raw ) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a stored `unavailable_after` value to an ISO 8601 datetime.
|
||||||
|
*
|
||||||
|
* The stored value is 'Y-m-d H:i' in the site timezone; the output carries
|
||||||
|
* the numeric UTC offset (e.g. `2025-06-25T15:00:00+02:00`), so crawlers read
|
||||||
|
* the right instant whatever the site timezone, and it contains no comma
|
||||||
|
* (the robots directive separator).
|
||||||
|
*
|
||||||
|
* @since 3.7.1
|
||||||
|
*
|
||||||
|
* @param string $value Normalized stored value.
|
||||||
|
* @return string ISO 8601 datetime, or '' when the value is not a valid datetime.
|
||||||
|
*/
|
||||||
|
function noindex_seo_format_unavailable_after( $value ) {
|
||||||
|
$dt = date_create_from_format( 'Y-m-d H:i', $value, wp_timezone() );
|
||||||
|
return ( false !== $dt ) ? $dt->format( 'c' ) : '';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats a stored value directive for robots output.
|
* Formats a stored value directive for robots output.
|
||||||
*
|
*
|
||||||
* Value directives render as `name:value`; `unavailable_after` additionally
|
* Value directives render as `name:value`; `unavailable_after` additionally
|
||||||
* converts its stored 'Y-m-d H:i' site-time value to the RFC-style datetime
|
* converts its stored 'Y-m-d H:i' site-time value to an ISO 8601 datetime
|
||||||
* search engines expect (e.g. `unavailable_after: Wed, 25 Jun 2025 15:00:00 +0200`).
|
* with a UTC offset (e.g. `unavailable_after: 2025-06-25T15:00:00+02:00`).
|
||||||
*
|
*
|
||||||
* @since 3.6.0
|
* @since 3.6.0
|
||||||
|
* @since 3.7.1 `unavailable_after` renders as ISO 8601 instead of the RFC
|
||||||
|
* 1123 form, whose comma ("Wed, 25 Jun …") collided with the
|
||||||
|
* directive separator.
|
||||||
*
|
*
|
||||||
* @param string $directive Directive slug.
|
* @param string $directive Directive slug.
|
||||||
* @param string $value Normalized stored value (non-empty).
|
* @param string $value Normalized stored value (non-empty).
|
||||||
|
|
@ -198,13 +224,8 @@ function noindex_seo_normalize_directive_value( $directive, $raw ) {
|
||||||
*/
|
*/
|
||||||
function noindex_seo_format_value_directive( $directive, $value ) {
|
function noindex_seo_format_value_directive( $directive, $value ) {
|
||||||
if ( 'unavailable_after' === $directive ) {
|
if ( 'unavailable_after' === $directive ) {
|
||||||
$dt = date_create_from_format( 'Y-m-d H:i', $value, wp_timezone() );
|
$datetime = noindex_seo_format_unavailable_after( $value );
|
||||||
if ( false !== $dt ) {
|
return ( '' !== $datetime ) ? $directive . ': ' . $datetime : '';
|
||||||
// RFC 1123-style with a numeric UTC offset ('O'): stable across
|
|
||||||
// PHP versions, unlike the 'T' abbreviation.
|
|
||||||
return $directive . ': ' . $dt->format( 'D, d M Y H:i:s O' );
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $directive . ':' . $value;
|
return $directive . ':' . $value;
|
||||||
|
|
@ -279,6 +300,17 @@ function noindex_seo_format_directives( array $directives ) {
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
function noindex_seo_get_settings( $force_refresh = false ) {
|
function noindex_seo_get_settings( $force_refresh = false ) {
|
||||||
|
/**
|
||||||
|
* Per-request cache of the merged settings (same shape as the return value).
|
||||||
|
*
|
||||||
|
* @var array{
|
||||||
|
* version: int,
|
||||||
|
* contexts: array<string, array<string, int|string>>,
|
||||||
|
* rules: array<int, array{field: string, value: string}>,
|
||||||
|
* robots_txt: array{enabled: int, rules: array<int, array{user_agent: string, policy: string}>},
|
||||||
|
* config: array{method: string, granular: int, taxonomies_granular: int, seoplugins: int, delete_on_uninstall: int}
|
||||||
|
* }|null $cached
|
||||||
|
*/
|
||||||
static $cached = null;
|
static $cached = null;
|
||||||
|
|
||||||
if ( null !== $cached && ! $force_refresh ) {
|
if ( null !== $cached && ! $force_refresh ) {
|
||||||
|
|
@ -748,9 +780,100 @@ function noindex_seo_get_import_sources() {
|
||||||
*
|
*
|
||||||
* @since 3.7.0
|
* @since 3.7.0
|
||||||
*
|
*
|
||||||
|
* @since 3.7.1 Malformed entries returned by the filter are dropped
|
||||||
|
* (they used to raise PHP warnings in the counter and runner).
|
||||||
|
*
|
||||||
* @param array $sources Source registry (see noindex_seo_get_import_sources()).
|
* @param array $sources Source registry (see noindex_seo_get_import_sources()).
|
||||||
*/
|
*/
|
||||||
return apply_filters( 'noindex_seo_import_sources', $sources );
|
return noindex_seo_validate_import_sources( apply_filters( 'noindex_seo_import_sources', $sources ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the filtered import source registry.
|
||||||
|
*
|
||||||
|
* Drops every entry that does not match the shape documented on
|
||||||
|
* noindex_seo_get_import_sources(); a non-array filter result yields no
|
||||||
|
* sources.
|
||||||
|
*
|
||||||
|
* @since 3.7.1
|
||||||
|
*
|
||||||
|
* @param mixed $filtered Untrusted result of the noindex_seo_import_sources filter.
|
||||||
|
* @return array<string, array{
|
||||||
|
* label: string,
|
||||||
|
* posts: array{noindex: array{key: string, is?: string, has?: string}, nofollow: array{key: string, is?: string, has?: string}},
|
||||||
|
* terms?: array{noindex: array{key: string, is?: string, has?: string}, nofollow: array{key: string, is?: string, has?: string}}
|
||||||
|
* }> Valid sources.
|
||||||
|
*/
|
||||||
|
function noindex_seo_validate_import_sources( $filtered ) {
|
||||||
|
if ( ! is_array( $filtered ) ) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$valid = array();
|
||||||
|
foreach ( $filtered as $slug => $source ) {
|
||||||
|
if ( ! is_string( $slug ) || sanitize_key( $slug ) !== $slug || ! is_array( $source ) || ! isset( $source['label'] ) || ! is_string( $source['label'] ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$posts = noindex_seo_validate_import_flags( isset( $source['posts'] ) ? $source['posts'] : null );
|
||||||
|
if ( null === $posts ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$entry = array(
|
||||||
|
'label' => $source['label'],
|
||||||
|
'posts' => $posts,
|
||||||
|
);
|
||||||
|
$terms = noindex_seo_validate_import_flags( isset( $source['terms'] ) ? $source['terms'] : null );
|
||||||
|
if ( null !== $terms ) {
|
||||||
|
$entry['terms'] = $terms;
|
||||||
|
}
|
||||||
|
$valid[ $slug ] = $entry;
|
||||||
|
}
|
||||||
|
return $valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the noindex / nofollow flag specs of one import source.
|
||||||
|
*
|
||||||
|
* Both flags are required; each needs a non-empty meta `key` plus either an
|
||||||
|
* exact `is` value or a non-empty `has` substring (see
|
||||||
|
* noindex_seo_get_import_sources()).
|
||||||
|
*
|
||||||
|
* @since 3.7.1
|
||||||
|
*
|
||||||
|
* @param mixed $flags Untrusted flag specs (from the noindex_seo_import_sources filter).
|
||||||
|
* @return array{noindex: array{key: string, is?: string, has?: string}, nofollow: array{key: string, is?: string, has?: string}}|null
|
||||||
|
* The validated specs, or null when the set is malformed.
|
||||||
|
*/
|
||||||
|
function noindex_seo_validate_import_flags( $flags ) {
|
||||||
|
if ( ! is_array( $flags ) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$valid = array();
|
||||||
|
foreach ( array( 'noindex', 'nofollow' ) as $directive ) {
|
||||||
|
$spec = isset( $flags[ $directive ] ) ? $flags[ $directive ] : null;
|
||||||
|
if ( ! is_array( $spec ) || ! isset( $spec['key'] ) || ! is_string( $spec['key'] ) || '' === $spec['key'] ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if ( isset( $spec['is'] ) && is_string( $spec['is'] ) ) {
|
||||||
|
$valid[ $directive ] = array(
|
||||||
|
'key' => $spec['key'],
|
||||||
|
'is' => $spec['is'],
|
||||||
|
);
|
||||||
|
} elseif ( isset( $spec['has'] ) && is_string( $spec['has'] ) && '' !== $spec['has'] ) {
|
||||||
|
$valid[ $directive ] = array(
|
||||||
|
'key' => $spec['key'],
|
||||||
|
'has' => $spec['has'],
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'noindex' => $valid['noindex'],
|
||||||
|
'nofollow' => $valid['nofollow'],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -819,11 +942,11 @@ function noindex_seo_count_import_sources() {
|
||||||
// Transients can hold stale or foreign shapes: validate per row.
|
// Transients can hold stale or foreign shapes: validate per row.
|
||||||
$valid = array();
|
$valid = array();
|
||||||
foreach ( $cached as $slug => $row ) {
|
foreach ( $cached as $slug => $row ) {
|
||||||
if ( is_string( $slug ) && is_array( $row ) && isset( $row['label'], $row['posts'], $row['terms'] ) ) {
|
if ( is_string( $slug ) && is_array( $row ) && isset( $row['label'], $row['posts'], $row['terms'] ) && is_string( $row['label'] ) && is_int( $row['posts'] ) && is_int( $row['terms'] ) ) {
|
||||||
$valid[ $slug ] = array(
|
$valid[ $slug ] = array(
|
||||||
'label' => (string) $row['label'],
|
'label' => $row['label'],
|
||||||
'posts' => (int) $row['posts'],
|
'posts' => $row['posts'],
|
||||||
'terms' => (int) $row['terms'],
|
'terms' => $row['terms'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -843,7 +966,6 @@ function noindex_seo_count_import_sources() {
|
||||||
'fields' => 'ids',
|
'fields' => 'ids',
|
||||||
'posts_per_page' => -1,
|
'posts_per_page' => -1,
|
||||||
'no_found_rows' => true,
|
'no_found_rows' => true,
|
||||||
'suppress_filters' => true,
|
|
||||||
'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
||||||
array_merge( array( 'relation' => 'OR' ), noindex_seo_import_flags_meta_query( $source['posts'] ) ),
|
array_merge( array( 'relation' => 'OR' ), noindex_seo_import_flags_meta_query( $source['posts'] ) ),
|
||||||
),
|
),
|
||||||
|
|
@ -945,7 +1067,6 @@ function noindex_seo_run_import( array $slugs ) {
|
||||||
'fields' => 'ids',
|
'fields' => 'ids',
|
||||||
'posts_per_page' => -1,
|
'posts_per_page' => -1,
|
||||||
'no_found_rows' => true,
|
'no_found_rows' => true,
|
||||||
'suppress_filters' => true,
|
|
||||||
'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
||||||
array_merge( array( 'relation' => 'OR' ), noindex_seo_import_flags_meta_query( $source['posts'] ) ),
|
array_merge( array( 'relation' => 'OR' ), noindex_seo_import_flags_meta_query( $source['posts'] ) ),
|
||||||
),
|
),
|
||||||
|
|
@ -1134,6 +1255,13 @@ function noindex_seo_update_settings( array $settings ) {
|
||||||
* (value directive), so value-carrying directives such as
|
* (value directive), so value-carrying directives such as
|
||||||
* `max-snippet` render as `max-snippet:-1`. Flat lists of
|
* `max-snippet` render as `max-snippet:-1`. Flat lists of
|
||||||
* boolean names passed by third-party code still work.
|
* boolean names passed by third-party code still work.
|
||||||
|
* @since 3.7.1 `nofollow` / `noindex` remove a `follow` / `index` already in
|
||||||
|
* the wp_robots array (core's search-results `follow` produced
|
||||||
|
* contradictory "follow, nofollow" output). The header-only
|
||||||
|
* method applies the same clean-up to the meta tag other
|
||||||
|
* sources print, without adding the plugin's own directives.
|
||||||
|
* `unavailable_after` reaches wp_robots as ISO 8601 with the
|
||||||
|
* UTC offset instead of the raw site-time value.
|
||||||
*
|
*
|
||||||
* @see https://developer.wordpress.org/reference/hooks/wp_robots/
|
* @see https://developer.wordpress.org/reference/hooks/wp_robots/
|
||||||
* @see https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag
|
* @see https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag
|
||||||
|
|
@ -1196,21 +1324,18 @@ function noindex_seo_metarobots( $method = 'meta', array $directives = array( 'n
|
||||||
// Add HTML meta tag if requested, or as fallback if headers already sent.
|
// Add HTML meta tag if requested, or as fallback if headers already sent.
|
||||||
$use_meta = in_array( $method, array( 'meta', 'both' ), true );
|
$use_meta = in_array( $method, array( 'meta', 'both' ), true );
|
||||||
$fallback_needed = in_array( $method, array( 'header', 'both' ), true ) && ! $header_sent;
|
$fallback_needed = in_array( $method, array( 'header', 'both' ), true ) && ! $header_sent;
|
||||||
|
$add_own = $use_meta || $fallback_needed;
|
||||||
if ( ! ( $use_meta || $fallback_needed ) ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( function_exists( 'wp_robots' ) ) {
|
if ( function_exists( 'wp_robots' ) ) {
|
||||||
// WordPress 5.7+: inject the directives into the core robots API.
|
// WordPress 5.7+: inject the directives into the core robots API.
|
||||||
// On WordPress older than 5.7 the wp_robots filter does not exist and the classic wp_head output below is used instead.
|
// On WordPress older than 5.7 the wp_robots filter does not exist and the classic wp_head output below is used instead.
|
||||||
|
// With the header-only method the plugin adds nothing to the meta
|
||||||
|
// tag, but still keeps other sources' tag from contradicting the
|
||||||
|
// header (core's search-results 'follow' next to a header 'nofollow').
|
||||||
add_filter(
|
add_filter(
|
||||||
'wp_robots',
|
'wp_robots',
|
||||||
function ( array $robots ) use ( $directives ) {
|
function ( array $robots ) use ( $directives, $add_own ) {
|
||||||
foreach ( $directives as $name => $value ) {
|
return noindex_seo_merge_robots( $robots, $directives, $add_own );
|
||||||
$robots[ $name ] = ( true === $value ) ? true : $value;
|
|
||||||
}
|
|
||||||
return $robots;
|
|
||||||
},
|
},
|
||||||
99 // High priority to ensure our directives take precedence over other plugins.
|
99 // High priority to ensure our directives take precedence over other plugins.
|
||||||
);
|
);
|
||||||
|
|
@ -1218,6 +1343,10 @@ function noindex_seo_metarobots( $method = 'meta', array $directives = array( 'n
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! $add_own ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// WordPress 4.0 - 5.6: classic <meta name="robots"> tag on wp_head.
|
// WordPress 4.0 - 5.6: classic <meta name="robots"> tag on wp_head.
|
||||||
add_action(
|
add_action(
|
||||||
'wp_head',
|
'wp_head',
|
||||||
|
|
@ -1228,6 +1357,44 @@ function noindex_seo_metarobots( $method = 'meta', array $directives = array( 'n
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge the plugin's directives into a wp_robots array without contradictions.
|
||||||
|
*
|
||||||
|
* A plugin `nofollow` / `noindex` removes a `follow` / `index` set by core
|
||||||
|
* (search results), the theme or another plugin. With `$add_own` false
|
||||||
|
* (header-only method) nothing is added or changed; only those positive
|
||||||
|
* counterparts are removed, so the meta tag other sources print does not
|
||||||
|
* contradict the X-Robots-Tag header. `unavailable_after` is converted to
|
||||||
|
* ISO 8601 with the UTC offset (core prints the value as given).
|
||||||
|
*
|
||||||
|
* @since 3.7.1
|
||||||
|
*
|
||||||
|
* @param array<mixed> $robots The wp_robots array (filter input, untyped).
|
||||||
|
* @param array<string, int|string|true> $directives Normalized directive map (name => true or value).
|
||||||
|
* @param bool $add_own Whether to add the plugin's directives to the array.
|
||||||
|
* @return array<mixed> The merged array.
|
||||||
|
*/
|
||||||
|
function noindex_seo_merge_robots( array $robots, array $directives, $add_own ) {
|
||||||
|
if ( $add_own ) {
|
||||||
|
foreach ( $directives as $name => $value ) {
|
||||||
|
if ( 'unavailable_after' === $name ) {
|
||||||
|
$value = noindex_seo_format_unavailable_after( (string) $value );
|
||||||
|
if ( '' === $value ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$robots[ $name ] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( isset( $directives['nofollow'] ) ) {
|
||||||
|
unset( $robots['follow'] );
|
||||||
|
}
|
||||||
|
if ( isset( $directives['noindex'] ) ) {
|
||||||
|
unset( $robots['index'] );
|
||||||
|
}
|
||||||
|
return $robots;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear all robots directive meta values for a post.
|
* Clear all robots directive meta values for a post.
|
||||||
*
|
*
|
||||||
|
|
@ -1668,38 +1835,20 @@ function noindex_seo_migrate_to_v3() {
|
||||||
update_option( NOINDEX_SEO_SETTINGS_KEY, $consolidated );
|
update_option( NOINDEX_SEO_SETTINGS_KEY, $consolidated );
|
||||||
|
|
||||||
// Mark each legacy option as non-autoloaded. update_option() short-circuits
|
// Mark each legacy option as non-autoloaded. update_option() short-circuits
|
||||||
// when the value is unchanged (which is the case here — we are only flipping
|
// when the value is unchanged (we are only flipping the autoload flag), so
|
||||||
// the autoload flag), so we use a direct SQL UPDATE on the options table.
|
// the dedicated core API is used instead (WP 6.4+; it also keeps the
|
||||||
// The options themselves remain readable for a safe rollback to 2.x; they
|
// alloptions cache consistent). The options themselves remain readable for
|
||||||
// will be deleted entirely in 4.0.
|
// a safe rollback to 2.x; they will be deleted entirely in 4.0.
|
||||||
global $wpdb;
|
$legacy_keys = array();
|
||||||
|
|
||||||
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
|
||||||
// Migration is a one-shot operation. Direct update is necessary because
|
|
||||||
// update_option() does not change autoload when the value is unchanged.
|
|
||||||
// This is a UPDATE (no result set), so caching is not applicable.
|
|
||||||
foreach ( $contexts as $context ) {
|
foreach ( $contexts as $context ) {
|
||||||
foreach ( $directives as $directive ) {
|
foreach ( $directives as $directive ) {
|
||||||
$option_key = $directive . '_seo_' . $context;
|
$legacy_keys[ $directive . '_seo_' . $context ] = false;
|
||||||
$wpdb->query(
|
|
||||||
$wpdb->prepare(
|
|
||||||
"UPDATE {$wpdb->options} SET autoload = 'no' WHERE option_name = %s",
|
|
||||||
$option_key
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( array( 'method', 'granular', 'seoplugins', 'delete_on_uninstall' ) as $config_key ) {
|
foreach ( array( 'method', 'granular', 'seoplugins', 'delete_on_uninstall' ) as $config_key ) {
|
||||||
$option_key = 'noindex_seo_config_' . $config_key;
|
$legacy_keys[ 'noindex_seo_config_' . $config_key ] = false;
|
||||||
$wpdb->query(
|
|
||||||
$wpdb->prepare(
|
|
||||||
"UPDATE {$wpdb->options} SET autoload = 'no' WHERE option_name = %s",
|
|
||||||
$option_key
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
// phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
wp_set_option_autoload_values( $legacy_keys );
|
||||||
|
|
||||||
// Mark migration complete and clear cache.
|
// Mark migration complete and clear cache.
|
||||||
update_option( 'noindex_seo_config_version', 3 );
|
update_option( 'noindex_seo_config_version', 3 );
|
||||||
|
|
@ -2355,8 +2504,10 @@ add_action( 'init', 'noindex_seo_register_icons' );
|
||||||
* the legacy emoji glyph, escaped and hidden from assistive technology.
|
* the legacy emoji glyph, escaped and hidden from assistive technology.
|
||||||
*
|
*
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
|
* @since 3.7.1 Added the missing notranslate fallback glyph (WP 7.0 - 7.1
|
||||||
|
* rendered no icon for it since 3.6.0).
|
||||||
*
|
*
|
||||||
* @param string $directive Directive slug (noindex|nofollow|noarchive|nosnippet|noimageindex).
|
* @param string $directive Directive slug (noindex|nofollow|noarchive|nosnippet|noimageindex|notranslate).
|
||||||
* @return string Safe-to-embed icon markup (SVG from the plugin's own registry, or the escaped emoji fallback).
|
* @return string Safe-to-embed icon markup (SVG from the plugin's own registry, or the escaped emoji fallback).
|
||||||
*/
|
*/
|
||||||
function noindex_seo_get_directive_icon_html( $directive ) {
|
function noindex_seo_get_directive_icon_html( $directive ) {
|
||||||
|
|
@ -2380,6 +2531,7 @@ function noindex_seo_get_directive_icon_html( $directive ) {
|
||||||
'noarchive' => '💾',
|
'noarchive' => '💾',
|
||||||
'nosnippet' => '📄',
|
'nosnippet' => '📄',
|
||||||
'noimageindex' => '🖼️',
|
'noimageindex' => '🖼️',
|
||||||
|
'notranslate' => '🌐',
|
||||||
);
|
);
|
||||||
|
|
||||||
// The emoji is decorative (the directive name is always rendered next to
|
// The emoji is decorative (the directive name is always rendered next to
|
||||||
|
|
@ -2696,12 +2848,13 @@ function noindex_seo_get_contexts() {
|
||||||
* @return string The label to display.
|
* @return string The label to display.
|
||||||
*/
|
*/
|
||||||
function noindex_seo_get_cpt_label( $cpt ) {
|
function noindex_seo_get_cpt_label( $cpt ) {
|
||||||
if ( isset( $cpt->labels->name ) && '' !== (string) $cpt->labels->name ) {
|
$labels = isset( $cpt->labels ) && is_object( $cpt->labels ) ? $cpt->labels : null;
|
||||||
return (string) $cpt->labels->name;
|
if ( null !== $labels && isset( $labels->name ) && is_string( $labels->name ) && '' !== $labels->name ) {
|
||||||
|
return $labels->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset( $cpt->name ) ) {
|
if ( isset( $cpt->name ) && is_string( $cpt->name ) ) {
|
||||||
return (string) $cpt->name;
|
return $cpt->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
|
|
@ -2729,6 +2882,9 @@ function noindex_seo_get_cpt_label( $cpt ) {
|
||||||
* @since 3.1.3 Uses the two-argument register_setting() form: the third
|
* @since 3.1.3 Uses the two-argument register_setting() form: the third
|
||||||
* $args array is only supported since WordPress 4.7, and all
|
* $args array is only supported since WordPress 4.7, and all
|
||||||
* sanitization already happens in the admin-post form handler.
|
* sanitization already happens in the admin-post form handler.
|
||||||
|
* @since 3.7.1 Back to the $args form (the WordPress floor is 7.0) with a
|
||||||
|
* sanitize_callback on every legacy option, so a direct
|
||||||
|
* options.php write can no longer store unsanitized values.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
|
@ -2737,23 +2893,54 @@ function noindex_seo_register() {
|
||||||
|
|
||||||
$directives = noindex_seo_get_directives();
|
$directives = noindex_seo_get_directives();
|
||||||
|
|
||||||
// Register each directive for each context.
|
// Legacy 2.x flags are 0|1 integers; the method is a short slug.
|
||||||
|
$int_args = array(
|
||||||
|
'type' => 'integer',
|
||||||
|
'sanitize_callback' => 'absint',
|
||||||
|
);
|
||||||
|
|
||||||
|
// Register each legacy directive for each context. Only the five 2.x
|
||||||
|
// directives ever had individual options (the 3.6.0 directives live in
|
||||||
|
// the consolidated option only).
|
||||||
foreach ( $contexts as $context ) {
|
foreach ( $contexts as $context ) {
|
||||||
foreach ( $directives as $directive ) {
|
foreach ( array_intersect( $directives, array( 'noindex', 'nofollow', 'noarchive', 'nosnippet', 'noimageindex' ) ) as $directive ) {
|
||||||
register_setting( 'noindexseo', $directive . '_seo_' . $context );
|
register_setting( 'noindexseo', $directive . '_seo_' . $context, $int_args );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
register_setting( 'noindexseo', 'noindex_seo_config_seoplugins' );
|
register_setting( 'noindexseo', 'noindex_seo_config_seoplugins', $int_args );
|
||||||
register_setting( 'noindexseo', 'noindex_seo_config_method' );
|
register_setting(
|
||||||
register_setting( 'noindexseo', 'noindex_seo_config_granular' );
|
'noindexseo',
|
||||||
register_setting( 'noindexseo', 'noindex_seo_config_delete_on_uninstall' );
|
'noindex_seo_config_method',
|
||||||
|
array(
|
||||||
|
'type' => 'string',
|
||||||
|
'sanitize_callback' => 'noindex_seo_sanitize_legacy_method',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
register_setting( 'noindexseo', 'noindex_seo_config_granular', $int_args );
|
||||||
|
register_setting( 'noindexseo', 'noindex_seo_config_delete_on_uninstall', $int_args );
|
||||||
|
|
||||||
// NOTE: 'noindexseo' is the Settings API *group* name, not an option name.
|
// NOTE: 'noindexseo' is the Settings API *group* name, not an option name.
|
||||||
// update_option_noindexseo would never fire; the transient is cleared explicitly
|
// update_option_noindexseo would never fire; the transient is cleared explicitly
|
||||||
// inside noindex_seo_process_form() after every successful form save.
|
// inside noindex_seo_process_form() after every successful form save.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitize the legacy 2.x `noindex_seo_config_method` option.
|
||||||
|
*
|
||||||
|
* Whitelists the three output methods; anything else becomes 'meta', the
|
||||||
|
* same fallback noindex_seo_metarobots() applies.
|
||||||
|
*
|
||||||
|
* @since 3.7.1
|
||||||
|
*
|
||||||
|
* @param mixed $value Raw option value.
|
||||||
|
* @return string 'meta', 'header' or 'both'.
|
||||||
|
*/
|
||||||
|
function noindex_seo_sanitize_legacy_method( $value ) {
|
||||||
|
$value = is_string( $value ) ? sanitize_key( $value ) : '';
|
||||||
|
return in_array( $value, array( 'meta', 'header', 'both' ), true ) ? $value : 'meta';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deprecated: clears the cached plugin settings stored in the transient.
|
* Deprecated: clears the cached plugin settings stored in the transient.
|
||||||
*
|
*
|
||||||
|
|
@ -2824,7 +3011,10 @@ function noindex_seo_detect_conflicts() {
|
||||||
|
|
||||||
// Iterate through the conflicting plugins to check if any are active.
|
// Iterate through the conflicting plugins to check if any are active.
|
||||||
$found_conflict = false;
|
$found_conflict = false;
|
||||||
foreach ( $conflicting_plugins as $plugin_path => $plugin_name ) {
|
foreach ( is_array( $conflicting_plugins ) ? $conflicting_plugins : array() as $plugin_path => $plugin_name ) {
|
||||||
|
if ( ! is_string( $plugin_path ) || ! is_string( $plugin_name ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if ( is_plugin_active( $plugin_path ) ) {
|
if ( is_plugin_active( $plugin_path ) ) {
|
||||||
// Add an admin notice if a conflicting plugin is active..
|
// Add an admin notice if a conflicting plugin is active..
|
||||||
add_action(
|
add_action(
|
||||||
|
|
|
||||||
24
readme.txt
24
readme.txt
|
|
@ -3,9 +3,9 @@ Contributors: robotstxt, javiercasares
|
||||||
Tags: seo, noindex, nofollow, noarchive, robots
|
Tags: seo, noindex, nofollow, noarchive, robots
|
||||||
Requires at least: 7.0
|
Requires at least: 7.0
|
||||||
Tested up to: 7.2
|
Tested up to: 7.2
|
||||||
Stable tag: 3.7.0
|
Stable tag: 3.7.1
|
||||||
Requires PHP: 8.3
|
Requires PHP: 8.3
|
||||||
Version: 3.7.0
|
Version: 3.7.1
|
||||||
License: GPL-3.0-or-later
|
License: GPL-3.0-or-later
|
||||||
License URI: https://www.gnu.org/licenses/gpl-3.0.txt
|
License URI: https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
|
|
||||||
|
|
@ -15,17 +15,17 @@ Control search engine indexing with robots directives using HTML meta tags or HT
|
||||||
|
|
||||||
Fine-grained control over how search engines index and display your WordPress content. Apply 10 robots directives to 25 different page contexts with flexible implementation methods.
|
Fine-grained control over how search engines index and display your WordPress content. Apply 10 robots directives to 25 different page contexts with flexible implementation methods.
|
||||||
|
|
||||||
**5 Boolean Robots Directives:**
|
**6 Boolean Robots Directives:**
|
||||||
|
|
||||||
* **noindex**: Prevent search engines from indexing the page
|
* **noindex**: Prevent search engines from indexing the page
|
||||||
* **nofollow**: Prevent search engines from following links on the page
|
* **nofollow**: Prevent search engines from following links on the page
|
||||||
* **noarchive**: Prevent search engines from showing cached versions
|
* **noarchive**: Prevent search engines from showing cached versions
|
||||||
* **nosnippet**: Prevent search engines from showing text snippets in results
|
* **nosnippet**: Prevent search engines from showing text snippets in results
|
||||||
* **noimageindex**: Prevent search engines from indexing images on the page
|
* **noimageindex**: Prevent search engines from indexing images on the page
|
||||||
|
* **notranslate** (3.6.0): Ask search engines not to translate the page
|
||||||
|
|
||||||
**5 Value Robots Directives (3.6.0):**
|
**4 Value Robots Directives (3.6.0):**
|
||||||
|
|
||||||
* **notranslate**: Ask search engines not to translate the page
|
|
||||||
* **max-snippet**: Limit the text snippet length in characters (-1 = no limit)
|
* **max-snippet**: Limit the text snippet length in characters (-1 = no limit)
|
||||||
* **max-image-preview**: Limit the image preview size (none / standard / large)
|
* **max-image-preview**: Limit the image preview size (none / standard / large)
|
||||||
* **max-video-preview**: Limit the video preview length in seconds (-1 = no limit)
|
* **max-video-preview**: Limit the video preview length in seconds (-1 = no limit)
|
||||||
|
|
@ -185,6 +185,10 @@ Both send the same robots directives to search engines. The meta tag method outp
|
||||||
|
|
||||||
No. By default all plugin data is preserved on uninstall. If you want a complete cleanup, enable the "Delete all plugin data on uninstall" option in the settings page before removing the plugin.
|
No. By default all plugin data is preserved on uninstall. If you want a complete cleanup, enable the "Delete all plugin data on uninstall" option in the settings page before removing the plugin.
|
||||||
|
|
||||||
|
= Does it support PHP 8.6? =
|
||||||
|
|
||||||
|
Yes. The plugin's code is verified on PHP 8.3 through 8.6. PHP 8.6 itself needs WordPress 7.1 or newer: WordPress 7.0 core raises PHP 8.6 deprecation notices of its own.
|
||||||
|
|
||||||
== Compatibility ==
|
== Compatibility ==
|
||||||
|
|
||||||
* WordPress: 7.0 - 7.2
|
* WordPress: 7.0 - 7.2
|
||||||
|
|
@ -192,6 +196,10 @@ No. By default all plugin data is preserved on uninstall. If you want a complete
|
||||||
|
|
||||||
== Changelog ==
|
== Changelog ==
|
||||||
|
|
||||||
|
= 3.7.1 =
|
||||||
|
|
||||||
|
Maintenance release certified on WordPress 7.2 (tested on 7.2-RC3) and PHP 8.6.0. Fixes contradictory `follow, nofollow` output on search results when nofollow is enabled (core adds `follow` there; with every output method, including header-only), the missing notranslate icon on WordPress 7.0 - 7.1, and `unavailable_after` dates without a timezone offset (now ISO 8601). Legacy settings now carry sanitize callbacks, malformed third-party filter data is validated instead of raising PHP warnings, and the uninstall cleanup escapes its wildcard patterns. Static analysis raised to PHPStan level 10 (maximum) without a baseline.
|
||||||
|
|
||||||
= 3.7.0 =
|
= 3.7.0 =
|
||||||
|
|
||||||
Feature release: on-demand import of robots overrides from other SEO plugins (Yoast SEO, Rank Math, SEOPress, All in One SEO — detected with or without them installed, never overwriting existing data) and virtual robots.txt management: block or allow individual crawlers (AI and search-engine presets included) appended to the robots.txt WordPress generates, inactive by default.
|
Feature release: on-demand import of robots overrides from other SEO plugins (Yoast SEO, Rank Math, SEOPress, All in One SEO — detected with or without them installed, never overwriting existing data) and virtual robots.txt management: block or allow individual crawlers (AI and search-engine presets included) appended to the robots.txt WordPress generates, inactive by default.
|
||||||
|
|
@ -200,10 +208,6 @@ Feature release: on-demand import of robots overrides from other SEO plugins (Yo
|
||||||
|
|
||||||
Feature release: 5 modern robots directives (notranslate, max-snippet, max-image-preview, max-video-preview, unavailable_after) available on every surface — global contexts, per-post and per-term overrides, Quick Edit, the block editor sidebar, REST and WP-CLI (name=value tokens); conditional auto-noindex rules that apply noindex when a custom field (e.g. an ACF field) exactly matches a value (matched posts also drop out of the XML sitemap); Multisite behavior documented (per-site by design, with export/import-based rollout).
|
Feature release: 5 modern robots directives (notranslate, max-snippet, max-image-preview, max-video-preview, unavailable_after) available on every surface — global contexts, per-post and per-term overrides, Quick Edit, the block editor sidebar, REST and WP-CLI (name=value tokens); conditional auto-noindex rules that apply noindex when a custom field (e.g. an ACF field) exactly matches a value (matched posts also drop out of the XML sitemap); Multisite behavior documented (per-site by design, with export/import-based rollout).
|
||||||
|
|
||||||
= 3.5.0 =
|
|
||||||
|
|
||||||
WooCommerce special-page contexts: dedicated robots directives for the Cart, Checkout and My Account pages (detected through the page-ID options, no WooCommerce code needed), recommended by default and mirrored across the front-end, the REST /effective endpoint and the core XML sitemaps. Compatibility window updated to WordPress 7.0 - 7.2 and PHP 8.3 - 8.6 (tested on WordPress 7.2-beta3 and PHP 8.6.0RC3). The five directive icons now render as SVG through the WordPress Icons API on WP 7.2+ (legacy emoji fallback on WP 7.0 - 7.1), matching the SVG direction of the WordPress 7.2 admin. Fixed the `wp noindex-seo list` command, which fatalled on real WP-CLI installs (its `--context` filter collided with WP-CLI 2.11+'s reserved global flag, now `--only`, and the output call used a nonexistent API).
|
|
||||||
|
|
||||||
= Previous versions =
|
= Previous versions =
|
||||||
|
|
||||||
If you want to see the full changelog, visit the [noindex SEO plugin page](https://www.robotstxt.software/plugins/noindex-seo/).
|
If you want to see the full changelog, visit the [noindex SEO plugin page](https://www.robotstxt.software/plugins/noindex-seo/).
|
||||||
|
|
@ -224,6 +228,6 @@ This plugin adheres to the following security measures and review protocols for
|
||||||
|
|
||||||
== Vulnerabilities ==
|
== Vulnerabilities ==
|
||||||
|
|
||||||
* No vulnerabilities have been published up to version 3.7.0.
|
* No vulnerabilities have been published up to version 3.7.1.
|
||||||
|
|
||||||
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).
|
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).
|
||||||
|
|
|
||||||
|
|
@ -98,44 +98,40 @@ delete_option( 'noindex_seo_config_granular' );
|
||||||
delete_option( 'noindex_seo_config_version' );
|
delete_option( 'noindex_seo_config_version' );
|
||||||
delete_option( 'noindex_seo_config_delete_on_uninstall' );
|
delete_option( 'noindex_seo_config_delete_on_uninstall' );
|
||||||
|
|
||||||
// Delete transient cache.
|
// Delete transient caches (through the API so persistent object caches are
|
||||||
|
// cleared too; the SQL wildcard below only reaches database-stored rows).
|
||||||
delete_transient( 'noindex_seo_options' );
|
delete_transient( 'noindex_seo_options' );
|
||||||
|
delete_transient( 'noindex_seo_import_counts' );
|
||||||
|
|
||||||
// Clean up any leftover options (in case of partial uninstall or pre-3.0 installs).
|
// Clean up any leftover options (in case of partial uninstall or pre-3.0 installs).
|
||||||
|
/**
|
||||||
|
* WordPress database abstraction object.
|
||||||
|
*
|
||||||
|
* @var wpdb $wpdb
|
||||||
|
*/
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||||
// Direct database queries are necessary here for complete cleanup during uninstall.
|
// Direct database queries are necessary here for complete cleanup during uninstall:
|
||||||
// This is a DELETE operation (not SELECT), so caching is not applicable.
|
// delete_option() has no wildcard form. These are DELETE operations (not SELECT),
|
||||||
// Using wildcards with delete_option() is not possible, requiring direct SQL.
|
// so caching is not applicable. Prefixes are LIKE-escaped (the "_" in them is a
|
||||||
// Clean up all directive-related options (noindex, nofollow, noarchive, nosnippet, noimageindex).
|
// LIKE wildcard otherwise) and the table name goes through the %i placeholder.
|
||||||
|
//
|
||||||
|
// Prefixes: every directive's legacy options (noindex_seo_*, nofollow_seo_*, ...),
|
||||||
|
// the consolidated option plus any stray noindex_seo_config_* rows (belt-and-
|
||||||
|
// suspenders in case delete_option() above failed on a corrupted cache), and
|
||||||
|
// the plugin's transients.
|
||||||
|
$noindex_seo_option_prefixes = array( 'noindex_seo_', '_transient_noindex_seo_', '_transient_timeout_noindex_seo_' );
|
||||||
foreach ( $noindex_seo_directives as $noindex_seo_directive ) {
|
foreach ( $noindex_seo_directives as $noindex_seo_directive ) {
|
||||||
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s", $noindex_seo_directive . '_seo_%' ) );
|
$noindex_seo_option_prefixes[] = $noindex_seo_directive . '_seo_';
|
||||||
}
|
}
|
||||||
|
foreach ( array_unique( $noindex_seo_option_prefixes ) as $noindex_seo_option_prefix ) {
|
||||||
// Belt-and-suspenders: clean up the consolidated option one more time in case
|
$noindex_seo_sql = $wpdb->prepare( 'DELETE FROM %i WHERE option_name LIKE %s', $wpdb->options, $wpdb->esc_like( $noindex_seo_option_prefix ) . '%' );
|
||||||
// delete_option() above failed due to a corrupted cache. The wildcard LIKE
|
if ( null !== $noindex_seo_sql ) {
|
||||||
// matches both noindex_seo_settings and any stray noindex_seo_config_* rows.
|
$wpdb->query( $noindex_seo_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- prepared on the previous line.
|
||||||
$wpdb->query(
|
}
|
||||||
$wpdb->prepare(
|
}
|
||||||
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
|
// phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||||
'noindex_seo_%'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Clean up transients.
|
|
||||||
$wpdb->query(
|
|
||||||
$wpdb->prepare(
|
|
||||||
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
|
|
||||||
'_transient_noindex_seo_%'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$wpdb->query(
|
|
||||||
$wpdb->prepare(
|
|
||||||
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
|
|
||||||
'_transient_timeout_noindex_seo_%'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Clean up post meta (granular control). The 3.6.0 value directives store
|
// Clean up post meta (granular control). The 3.6.0 value directives store
|
||||||
// their per-post values under the same prefix.
|
// their per-post values under the same prefix.
|
||||||
|
|
@ -153,28 +149,18 @@ $noindex_seo_meta_keys = array(
|
||||||
'_noindex_seo_unavailable_after',
|
'_noindex_seo_unavailable_after',
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ( $noindex_seo_meta_keys as $noindex_seo_meta_key ) {
|
// Clean up post meta and term meta (per-term granular control, added in 3.0.2).
|
||||||
$wpdb->query(
|
// One prepared DELETE per key and table instead of delete_metadata( ..., true ):
|
||||||
$wpdb->prepare(
|
// the metadata API loads every matching meta ID into PHP and fires the delete
|
||||||
"DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s",
|
// actions with the full arrays, which does not scale for _noindex_seo_override
|
||||||
$noindex_seo_meta_key
|
// (written on every meta box / Quick Edit save) on large sites.
|
||||||
)
|
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||||
);
|
foreach ( array( $wpdb->postmeta, $wpdb->termmeta ) as $noindex_seo_meta_table ) {
|
||||||
}
|
|
||||||
|
|
||||||
// Clean up term meta (per-term granular control, added in 3.0.2).
|
|
||||||
// delete_term_meta() cannot be used here because term IDs are not known at
|
|
||||||
// uninstall time and there is no built-in "delete all term meta by key".
|
|
||||||
// $wpdb->termmeta is set by WP when the table exists; older WP versions
|
|
||||||
// (pre-4.4) did not have it, hence the property_exists() check.
|
|
||||||
if ( property_exists( $wpdb, 'termmeta' ) && $wpdb->termmeta ) {
|
|
||||||
foreach ( $noindex_seo_meta_keys as $noindex_seo_meta_key ) {
|
foreach ( $noindex_seo_meta_keys as $noindex_seo_meta_key ) {
|
||||||
$wpdb->query(
|
$noindex_seo_sql = $wpdb->prepare( 'DELETE FROM %i WHERE meta_key = %s', $noindex_seo_meta_table, $noindex_seo_meta_key );
|
||||||
$wpdb->prepare(
|
if ( null !== $noindex_seo_sql ) {
|
||||||
"DELETE FROM {$wpdb->termmeta} WHERE meta_key = %s",
|
$wpdb->query( $noindex_seo_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- prepared on the previous line.
|
||||||
$noindex_seo_meta_key
|
}
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
// phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue