Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 54122d3d95 |
10 changed files with 2055 additions and 699 deletions
|
|
@ -852,3 +852,31 @@ input:checked + .noindex-seo-slider:before {
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ===========================
|
||||||
|
Robots.txt management (3.7.0)
|
||||||
|
=========================== */
|
||||||
|
|
||||||
|
.noindex-seo-robotstxt-table {
|
||||||
|
margin-top: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.noindex-seo-robotstxt-table input[type="text"] {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 320px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.noindex-seo-robotstxt-preview {
|
||||||
|
max-width: 480px;
|
||||||
|
padding: 12px;
|
||||||
|
background: #fff;
|
||||||
|
border: 1px solid #c3c4c7;
|
||||||
|
border-radius: 3px;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.noindex-seo-robotstxt-preview code {
|
||||||
|
font-family: Consolas, Monaco, monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
white-space: pre;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,22 +21,24 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the conditional-rules table (add / remove rows)
|
* Initialize the rule tables (conditional rules + robots.txt):
|
||||||
|
* add / remove rows, and the robots.txt preset buttons.
|
||||||
*/
|
*/
|
||||||
function initRules() {
|
function initRules() {
|
||||||
// Add rule: clone the last row and clear its inputs.
|
// Add rule: clone the last row of the target container and clear it.
|
||||||
$( '.noindex-seo-rule-add' ).on(
|
$( '.noindex-seo-rule-add' ).on(
|
||||||
'click',
|
'click',
|
||||||
function () {
|
function () {
|
||||||
const $rows = $( '.noindex-seo-rule-rows' );
|
const target = $( this ).data( 'target' ) || '.noindex-seo-rule-rows';
|
||||||
const max = parseInt( $rows.data( 'max-rules' ) || 20, 10 );
|
const $rows = $( target ).first();
|
||||||
|
const max = parseInt( $rows.data( 'max-rules' ) || 20, 10 );
|
||||||
|
|
||||||
if ( $rows.find( '.noindex-seo-rule-row' ).length >= max ) {
|
if ( $rows.find( '.noindex-seo-rule-row' ).length >= max ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const $clone = $rows.find( '.noindex-seo-rule-row' ).last().clone();
|
const $clone = $rows.find( '.noindex-seo-rule-row' ).last().clone();
|
||||||
$clone.find( 'input' ).val( '' );
|
$clone.find( 'input[type="text"], input[type="number"], input[type="datetime-local"]' ).val( '' );
|
||||||
$rows.append( $clone );
|
$rows.append( $clone );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
@ -52,10 +54,45 @@
|
||||||
if ( $rows.find( '.noindex-seo-rule-row' ).length > 1 ) {
|
if ( $rows.find( '.noindex-seo-rule-row' ).length > 1 ) {
|
||||||
$row.remove();
|
$row.remove();
|
||||||
} else {
|
} else {
|
||||||
$row.find( 'input' ).val( '' );
|
$row.find( 'input[type="text"]' ).val( '' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Robots.txt presets: append one blocked row per bot of the preset
|
||||||
|
// (skipping agents that already have a rule).
|
||||||
|
$( '.noindex-seo-robotstxt-preset' ).on(
|
||||||
|
'click',
|
||||||
|
function () {
|
||||||
|
const preset = $( this ).data( 'preset' );
|
||||||
|
const bots = ( 'search' === preset ) ? ( window.noindexSeoAdmin.searchBots || [] ) : ( window.noindexSeoAdmin.aiBots || [] );
|
||||||
|
const $rows = $( '.noindex-seo-robotstxt-rows' ).first();
|
||||||
|
const max = parseInt( $rows.data( 'max-rules' ) || 30, 10 );
|
||||||
|
|
||||||
|
const existing = {};
|
||||||
|
$rows.find( 'input[name="noindex_seo_robotstxt_agent[]"]' ).each(
|
||||||
|
function () {
|
||||||
|
existing[ $( this ).val().toLowerCase() ] = true;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
bots.forEach(
|
||||||
|
function ( bot ) {
|
||||||
|
if ( existing[ bot.toLowerCase() ] ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( $rows.find( '.noindex-seo-rule-row' ).length >= max ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const $clone = $rows.find( '.noindex-seo-rule-row' ).last().clone();
|
||||||
|
$clone.find( 'input[name="noindex_seo_robotstxt_agent[]"]' ).val( bot );
|
||||||
|
$clone.find( 'select' ).val( 'block' );
|
||||||
|
$rows.append( $clone );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,44 @@
|
||||||
== Changelog ==
|
== Changelog ==
|
||||||
|
|
||||||
|
= 3.7.0 =
|
||||||
|
|
||||||
|
_Release date: 2026-11-03_
|
||||||
|
|
||||||
|
**Highlights**
|
||||||
|
|
||||||
|
* Import from other SEO plugins (spec section 5): on-demand migration of the noindex / nofollow flags stored by Yoast SEO, Rank Math, SEOPress and All in One SEO into noindex SEO per-post and per-term overrides — detected from data presence (the source plugin does not need to be installed), user-confirmed, and never overwriting content that already has its own override.
|
||||||
|
* Virtual robots.txt management (spec section 7): block (`Disallow: /`) or allow (`Allow: /`) individual crawlers, appended to the robots.txt WordPress generates virtually — never replacing it — with one-click presets for the well-known AI and search-engine crawlers. Inactive by default.
|
||||||
|
|
||||||
|
**Added**
|
||||||
|
|
||||||
|
* **Import from other plugins.** A new section on the Import / Export tab lists every supported source plugin together with how many posts and terms carry its robots flags, and imports the checked ones on explicit confirmation. The runner converts source flags into granular overrides (`_noindex_seo_override=1` plus noindex / nofollow), skips and reports content that already carries a noindex SEO override row (an explicit "off" counts as data), re-verifies LIKE-based matches (Rank Math's serialized arrays) per post so false positives are dropped, and whitelists source slugs server-side. Sources are data-driven and filterable (`noindex_seo_import_sources`) so third parties can register or correct one.
|
||||||
|
* **Robots.txt tab.** A fourth settings tab manages up to 30 bot rules (User-agent token + block/allow policy; `*` wildcard supported, duplicates collapse, agents stripped to the robots.txt-legal charset). The rules are appended through core's `robots_txt` filter only while the feature is enabled, a live preview shows the exact block appended, and preset buttons add the well-known AI crawlers (GPTBot, ClaudeBot, Google-Extended, CCBot, Bytespider… — filterable via `noindex_seo_ai_bots`) or the main search engine crawlers (`noindex_seo_search_bots`) as blocked rules. The core output — and a physical robots.txt or "Discourage search engines" — always takes precedence.
|
||||||
|
* The robots.txt settings ride the consolidated option and the JSON export/import.
|
||||||
|
|
||||||
|
**Changed**
|
||||||
|
|
||||||
|
* The settings page gained a fourth tab (General / SEO Settings / Import-Export / Robots.txt); the rule-table JavaScript is now shared between the conditional rules and the robots.txt tables, scoped per container.
|
||||||
|
|
||||||
|
**Fixed**
|
||||||
|
|
||||||
|
* Block editor granular overrides now save on custom post types registered without `custom-fields` support (a very common CPT registration). Without that support the REST API exposes no `meta` field for the post type, so the editor sidebar's saves were silently dropped with an HTTP 200 — the override checkbox appeared to do nothing. The plugin now adds `custom-fields` support for exactly the post types it registers meta on (while per-post granular control is enabled).
|
||||||
|
|
||||||
|
**Security**
|
||||||
|
|
||||||
|
* No new attack surface: the import handler is `manage_options` + nonce gated with whitelisted sources, writes only through the meta API after re-reading each source flag, and skips content with existing override data; robots.txt agents are charset-stripped (no newline or comment injection into the file) and policies are whitelisted; the tab form rides the existing nonce + capability path. PHPCS/PHPStan/composer audit clean.
|
||||||
|
|
||||||
|
**Compatibility**
|
||||||
|
|
||||||
|
* WordPress: 7.0 - 7.2
|
||||||
|
* PHP: 8.3 - 8.6
|
||||||
|
|
||||||
|
**Tests**
|
||||||
|
|
||||||
|
* PHPUnit: 9.6.38 (230 tests, 1152 assertions, all passing) on the WordPress 7.2-beta3 test library, run under PHP 8.3, 8.4, 8.5 and 8.6.0RC3 — including the new robots.txt sanitization/output/filter/form suites and the import detection/conversion/never-overwrite/false-positive/handler suites.
|
||||||
|
* PHPCompatibility: 0 errors on the declared range 8.3-8.6 and on the full review range 5.6-8.6.
|
||||||
|
* PHPCS (WordPress-Core, -Docs, -Extra) and PHPStan level 9: 0 errors.
|
||||||
|
* Translations: Catalan and Spanish catalogs regenerated and 100% complete (209 strings each).
|
||||||
|
|
||||||
= 3.6.0 =
|
= 3.6.0 =
|
||||||
|
|
||||||
_Release date: 2026-11-03_
|
_Release date: 2026-11-03_
|
||||||
|
|
|
||||||
Binary file not shown.
File diff suppressed because it is too large
Load diff
Binary file not shown.
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
886
noindex-seo.php
886
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.6.0
|
* Version: 3.7.0
|
||||||
* Requires at least: 7.0
|
* Requires at least: 7.0
|
||||||
* Requires PHP: 8.3
|
* Requires PHP: 8.3
|
||||||
* Author: ROBOTSTXT
|
* Author: ROBOTSTXT
|
||||||
|
|
@ -77,8 +77,12 @@ defined( 'ABSPATH' ) || die( 'Bye bye!' );
|
||||||
* every surface (global grid, per-post, per-term, Quick Edit,
|
* every surface (global grid, per-post, per-term, Quick Edit,
|
||||||
* block editor, REST, WP-CLI) and conditional auto-noindex
|
* block editor, REST, WP-CLI) and conditional auto-noindex
|
||||||
* rules driven by custom-field (ACF) matches.
|
* rules driven by custom-field (ACF) matches.
|
||||||
|
* @since 3.7.0 Bridge release: on-demand import of robots overrides from
|
||||||
|
* other SEO plugins (Yoast, Rank Math, SEOPress, AIOSEO) and
|
||||||
|
* virtual robots.txt management (bot rules appended to the
|
||||||
|
* WordPress-generated robots.txt, inactive by default).
|
||||||
*/
|
*/
|
||||||
define( 'NOINDEX_SEO_VERSION', '3.6.0' );
|
define( 'NOINDEX_SEO_VERSION', '3.7.0' );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Option key holding the consolidated plugin settings array.
|
* Option key holding the consolidated plugin settings array.
|
||||||
|
|
@ -261,6 +265,10 @@ function noindex_seo_format_directives( array $directives ) {
|
||||||
* version: int,
|
* version: int,
|
||||||
* contexts: array<string, array<string, int|string>>,
|
* contexts: array<string, array<string, int|string>>,
|
||||||
* rules: array<int, array{field: string, value: 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{
|
* config: array{
|
||||||
* method: string,
|
* method: string,
|
||||||
* granular: int,
|
* granular: int,
|
||||||
|
|
@ -278,10 +286,14 @@ function noindex_seo_get_settings( $force_refresh = false ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$defaults = array(
|
$defaults = array(
|
||||||
'version' => 3,
|
'version' => 3,
|
||||||
'contexts' => array(),
|
'contexts' => array(),
|
||||||
'rules' => array(),
|
'rules' => array(),
|
||||||
'config' => array(
|
'robots_txt' => array(
|
||||||
|
'enabled' => 0,
|
||||||
|
'rules' => array(),
|
||||||
|
),
|
||||||
|
'config' => array(
|
||||||
'method' => 'meta',
|
'method' => 'meta',
|
||||||
'granular' => 0,
|
'granular' => 0,
|
||||||
'taxonomies_granular' => 0,
|
'taxonomies_granular' => 0,
|
||||||
|
|
@ -325,6 +337,14 @@ function noindex_seo_get_settings( $force_refresh = false ) {
|
||||||
$defaults['rules'] = noindex_seo_sanitize_rules( $saved['rules'] );
|
$defaults['rules'] = noindex_seo_sanitize_rules( $saved['rules'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Virtual robots.txt management (3.7.0).
|
||||||
|
if ( isset( $saved['robots_txt'] ) && is_array( $saved['robots_txt'] ) ) {
|
||||||
|
$defaults['robots_txt']['enabled'] = empty( $saved['robots_txt']['enabled'] ) ? 0 : 1;
|
||||||
|
if ( isset( $saved['robots_txt']['rules'] ) ) {
|
||||||
|
$defaults['robots_txt']['rules'] = noindex_seo_sanitize_robots_txt_rules( $saved['robots_txt']['rules'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( isset( $saved['config'] ) && is_array( $saved['config'] ) ) {
|
if ( isset( $saved['config'] ) && is_array( $saved['config'] ) ) {
|
||||||
foreach ( $defaults['config'] as $key => $default_value ) {
|
foreach ( $defaults['config'] as $key => $default_value ) {
|
||||||
if ( ! isset( $saved['config'][ $key ] ) ) {
|
if ( ! isset( $saved['config'][ $key ] ) ) {
|
||||||
|
|
@ -448,6 +468,551 @@ function noindex_seo_matching_rule_for_post( $post_id ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitizes the virtual robots.txt bot rules (3.7.0).
|
||||||
|
*
|
||||||
|
* Each rule is a `user_agent` string (letters, digits, `-`, `_`, `.`, `/`,
|
||||||
|
* `*` — the characters valid in a robots.txt User-agent token) plus a policy
|
||||||
|
* of `block` (Disallow: /) or `allow` (Allow: /). Empty agents are dropped,
|
||||||
|
* duplicates collapse (first policy wins) and at most 30 rules are kept.
|
||||||
|
*
|
||||||
|
* @since 3.7.0
|
||||||
|
*
|
||||||
|
* @param mixed $raw Untrusted rules array.
|
||||||
|
* @return array<int, array{user_agent: string, policy: string}> Sanitized rules.
|
||||||
|
*/
|
||||||
|
function noindex_seo_sanitize_robots_txt_rules( $raw ) {
|
||||||
|
if ( ! is_array( $raw ) ) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$rules = array();
|
||||||
|
$seen = array();
|
||||||
|
foreach ( $raw as $rule ) {
|
||||||
|
if ( ! is_array( $rule ) || ! isset( $rule['user_agent'], $rule['policy'] ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$agent = is_scalar( $rule['user_agent'] ) ? preg_replace( '/[^A-Za-z0-9_*.\-\/]/', '', (string) $rule['user_agent'] ) : '';
|
||||||
|
$agent = trim( substr( (string) $agent, 0, 100 ), " \t\0\x0B-_." ); // Length-capped; a lone '*' (all crawlers) stays valid.
|
||||||
|
if ( '' === $agent || isset( $seen[ strtolower( $agent ) ] ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$policy = ( 'allow' === $rule['policy'] ) ? 'allow' : 'block';
|
||||||
|
|
||||||
|
$seen[ strtolower( $agent ) ] = true;
|
||||||
|
$rules[] = array(
|
||||||
|
'user_agent' => $agent,
|
||||||
|
'policy' => $policy,
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( count( $rules ) >= 30 ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rules;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the well-known AI crawler User-agent tokens for the preset button.
|
||||||
|
*
|
||||||
|
* Source: public crawler documentation of the main AI vendors (OpenAI,
|
||||||
|
* Anthropic, Google, Perplexity, Amazon, Meta, Apple, Common Crawl, Cohere,
|
||||||
|
* ByteDance). Filterable so the list can track new crawlers without a release.
|
||||||
|
*
|
||||||
|
* @since 3.7.0
|
||||||
|
*
|
||||||
|
* @return array<int, string> User-agent tokens.
|
||||||
|
*/
|
||||||
|
function noindex_seo_get_ai_bots() {
|
||||||
|
/**
|
||||||
|
* Filter the AI crawler User-agent tokens offered by the preset button.
|
||||||
|
*
|
||||||
|
* @since 3.7.0
|
||||||
|
*
|
||||||
|
* @param array<int, string> $bots User-agent tokens.
|
||||||
|
*/
|
||||||
|
return apply_filters(
|
||||||
|
'noindex_seo_ai_bots',
|
||||||
|
array(
|
||||||
|
'GPTBot',
|
||||||
|
'ChatGPT-User',
|
||||||
|
'OAI-SearchBot',
|
||||||
|
'ClaudeBot',
|
||||||
|
'Claude-User',
|
||||||
|
'anthropic-ai',
|
||||||
|
'Google-Extended',
|
||||||
|
'PerplexityBot',
|
||||||
|
'Amazonbot',
|
||||||
|
'meta-externalagent',
|
||||||
|
'Applebot-Extended',
|
||||||
|
'CCBot',
|
||||||
|
'cohere-ai',
|
||||||
|
'Bytespider',
|
||||||
|
'YouBot',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the well-known search engine crawler User-agent tokens.
|
||||||
|
*
|
||||||
|
* @since 3.7.0
|
||||||
|
*
|
||||||
|
* @return array<int, string> User-agent tokens.
|
||||||
|
*/
|
||||||
|
function noindex_seo_get_search_bots() {
|
||||||
|
/**
|
||||||
|
* Filter the search engine crawler User-agent tokens offered by the preset button.
|
||||||
|
*
|
||||||
|
* @since 3.7.0
|
||||||
|
*
|
||||||
|
* @param array<int, string> $bots User-agent tokens.
|
||||||
|
*/
|
||||||
|
return apply_filters(
|
||||||
|
'noindex_seo_search_bots',
|
||||||
|
array(
|
||||||
|
'Googlebot',
|
||||||
|
'Bingbot',
|
||||||
|
'DuckDuckBot',
|
||||||
|
'Slurp',
|
||||||
|
'Baiduspider',
|
||||||
|
'YandexBot',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the robots.txt block the plugin appends, or '' when inactive.
|
||||||
|
*
|
||||||
|
* Each rule renders as its own `User-agent: <token>` group:
|
||||||
|
*
|
||||||
|
* User-agent: GPTBot
|
||||||
|
* Disallow: /
|
||||||
|
*
|
||||||
|
* `allow` rules render `Allow: /` so they can override a broader block
|
||||||
|
* (the last matching group wins in most crawlers' implementations).
|
||||||
|
*
|
||||||
|
* @since 3.7.0
|
||||||
|
*
|
||||||
|
* @return string Robots.txt snippet (no trailing newline), '' when disabled or empty.
|
||||||
|
*/
|
||||||
|
function noindex_seo_get_robots_txt_block() {
|
||||||
|
$settings = noindex_seo_get_settings();
|
||||||
|
|
||||||
|
if ( empty( $settings['robots_txt']['enabled'] ) ) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$lines = array();
|
||||||
|
foreach ( $settings['robots_txt']['rules'] as $rule ) {
|
||||||
|
$lines[] = 'User-agent: ' . $rule['user_agent'];
|
||||||
|
$lines[] = ( 'allow' === $rule['policy'] ) ? 'Allow: /' : 'Disallow: /';
|
||||||
|
$lines[] = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return trim( implode( "\n", $lines ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extends the virtual robots.txt generated by WordPress with the configured
|
||||||
|
* bot rules (3.7.0).
|
||||||
|
*
|
||||||
|
* Inactive by default; only appends when the feature is enabled and rules
|
||||||
|
* exist. This extends — never replaces — the core output, and only applies
|
||||||
|
* when WordPress serves robots.txt virtually (no physical robots.txt file
|
||||||
|
* in the site root and "Search engines visibility" allowed).
|
||||||
|
*
|
||||||
|
* Hooked to the {@see 'robots_txt'} filter.
|
||||||
|
*
|
||||||
|
* @since 3.7.0
|
||||||
|
*
|
||||||
|
* @param string $output Robots.txt output so far.
|
||||||
|
* @return string Filtered output.
|
||||||
|
*/
|
||||||
|
function noindex_seo_filter_robots_txt( $output ) {
|
||||||
|
$block = noindex_seo_get_robots_txt_block();
|
||||||
|
|
||||||
|
if ( '' === $block ) {
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output . "\n\n" . $block;
|
||||||
|
}
|
||||||
|
add_filter( 'robots_txt', 'noindex_seo_filter_robots_txt' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the supported import sources: other SEO plugins whose robots
|
||||||
|
* directive data noindex SEO can import (3.7.0, spec section 5).
|
||||||
|
*
|
||||||
|
* Each source declares how to read its per-post (and, where stored, per-term)
|
||||||
|
* noindex / nofollow flags:
|
||||||
|
*
|
||||||
|
* - `is` => exact meta value match (e.g. Yoast stores '1').
|
||||||
|
* - `has` => the value contains the token (Rank Math stores a serialized
|
||||||
|
* array of directive names).
|
||||||
|
*
|
||||||
|
* Sources are data-driven so third parties can register or correct one via
|
||||||
|
* the filter. Only the two directives every source shares (noindex,
|
||||||
|
* nofollow) are imported; anything richer stays for the importing plugin's
|
||||||
|
* own UI.
|
||||||
|
*
|
||||||
|
* @since 3.7.0
|
||||||
|
*
|
||||||
|
* @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}}
|
||||||
|
* }> Source registry.
|
||||||
|
*/
|
||||||
|
function noindex_seo_get_import_sources() {
|
||||||
|
$sources = array(
|
||||||
|
'yoast' => array(
|
||||||
|
'label' => 'Yoast SEO',
|
||||||
|
'posts' => array(
|
||||||
|
'noindex' => array(
|
||||||
|
'key' => '_yoast_wpseo_meta-robots-noindex',
|
||||||
|
'is' => '1',
|
||||||
|
),
|
||||||
|
'nofollow' => array(
|
||||||
|
'key' => '_yoast_wpseo_meta-robots-nofollow',
|
||||||
|
'is' => '1',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'terms' => array(
|
||||||
|
'noindex' => array(
|
||||||
|
'key' => '_yoast_wpseo_meta-robots-noindex',
|
||||||
|
'is' => '1',
|
||||||
|
),
|
||||||
|
'nofollow' => array(
|
||||||
|
'key' => '_yoast_wpseo_meta-robots-nofollow',
|
||||||
|
'is' => '1',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'rankmath' => array(
|
||||||
|
'label' => 'Rank Math SEO',
|
||||||
|
'posts' => array(
|
||||||
|
'noindex' => array(
|
||||||
|
'key' => 'rank_math_robots',
|
||||||
|
'has' => 'noindex',
|
||||||
|
),
|
||||||
|
'nofollow' => array(
|
||||||
|
'key' => 'rank_math_robots',
|
||||||
|
'has' => 'nofollow',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'terms' => array(
|
||||||
|
'noindex' => array(
|
||||||
|
'key' => 'rank_math_robots',
|
||||||
|
'has' => 'noindex',
|
||||||
|
),
|
||||||
|
'nofollow' => array(
|
||||||
|
'key' => 'rank_math_robots',
|
||||||
|
'has' => 'nofollow',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'seopress' => array(
|
||||||
|
'label' => 'SEOPress',
|
||||||
|
'posts' => array(
|
||||||
|
'noindex' => array(
|
||||||
|
'key' => '_seopress_robots_index',
|
||||||
|
'is' => 'no',
|
||||||
|
),
|
||||||
|
'nofollow' => array(
|
||||||
|
'key' => '_seopress_robots_follow',
|
||||||
|
'is' => 'no',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'aioseo' => array(
|
||||||
|
'label' => 'All in One SEO',
|
||||||
|
'posts' => array(
|
||||||
|
'noindex' => array(
|
||||||
|
'key' => '_aioseop_noindex',
|
||||||
|
'is' => 'on',
|
||||||
|
),
|
||||||
|
'nofollow' => array(
|
||||||
|
'key' => '_aioseop_nofollow',
|
||||||
|
'is' => 'on',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter the importable SEO plugin sources.
|
||||||
|
*
|
||||||
|
* @since 3.7.0
|
||||||
|
*
|
||||||
|
* @param array $sources Source registry (see noindex_seo_get_import_sources()).
|
||||||
|
*/
|
||||||
|
return apply_filters( 'noindex_seo_import_sources', $sources );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the meta_query clause that finds content flagged by a source.
|
||||||
|
*
|
||||||
|
* @since 3.7.0
|
||||||
|
*
|
||||||
|
* @param array<string, array<string, mixed>> $flags noindex / nofollow flag specs of one source.
|
||||||
|
* @return array<int, array<string, mixed>> meta_query clauses (unkeyed; caller wraps with OR).
|
||||||
|
*/
|
||||||
|
function noindex_seo_import_flags_meta_query( array $flags ) {
|
||||||
|
$clauses = array();
|
||||||
|
foreach ( $flags as $spec ) {
|
||||||
|
if ( isset( $spec['is'] ) ) {
|
||||||
|
$clauses[] = array(
|
||||||
|
'key' => $spec['key'],
|
||||||
|
'value' => $spec['is'],
|
||||||
|
'compare' => '=',
|
||||||
|
);
|
||||||
|
} elseif ( isset( $spec['has'] ) ) {
|
||||||
|
$clauses[] = array(
|
||||||
|
'key' => $spec['key'],
|
||||||
|
'value' => $spec['has'],
|
||||||
|
'compare' => 'LIKE',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $clauses;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the shared post-type and status coverage for finding posts flagged
|
||||||
|
* by a source.
|
||||||
|
*
|
||||||
|
* Attachments (status `inherit`) and CPTs that hide from search must be
|
||||||
|
* included: 'post_type' => 'any' would silently exclude both, and SEO
|
||||||
|
* plugins do store flags on media.
|
||||||
|
*
|
||||||
|
* @since 3.7.0
|
||||||
|
*
|
||||||
|
* @return array{post_types: array<int, string>, post_statuses: array<int, string>} Coverage lists.
|
||||||
|
*/
|
||||||
|
function noindex_seo_import_posts_coverage() {
|
||||||
|
return array(
|
||||||
|
'post_types' => array_values( get_post_types( array( 'show_ui' => true ), 'names' ) ),
|
||||||
|
'post_statuses' => array( 'publish', 'draft', 'pending', 'private', 'future', 'inherit' ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Counts the importable posts and terms per source.
|
||||||
|
*
|
||||||
|
* Detection is data-driven, not activation-driven: leftover meta from an
|
||||||
|
* uninstalled SEO plugin still counts (that is exactly the migration case).
|
||||||
|
* The counts are cached in a 15-minute transient because the LIKE-based
|
||||||
|
* meta scans are not free on large sites; noindex_seo_run_import()
|
||||||
|
* invalidates the cache after an import.
|
||||||
|
*
|
||||||
|
* @since 3.7.0
|
||||||
|
*
|
||||||
|
* @return array<string, array{label: string, posts: int, terms: int}> Counts per source slug.
|
||||||
|
*/
|
||||||
|
function noindex_seo_count_import_sources() {
|
||||||
|
$cached = get_transient( 'noindex_seo_import_counts' );
|
||||||
|
if ( is_array( $cached ) ) {
|
||||||
|
// Transients can hold stale or foreign shapes: validate per row.
|
||||||
|
$valid = array();
|
||||||
|
foreach ( $cached as $slug => $row ) {
|
||||||
|
if ( is_string( $slug ) && is_array( $row ) && isset( $row['label'], $row['posts'], $row['terms'] ) ) {
|
||||||
|
$valid[ $slug ] = array(
|
||||||
|
'label' => (string) $row['label'],
|
||||||
|
'posts' => (int) $row['posts'],
|
||||||
|
'terms' => (int) $row['terms'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( array() !== $valid ) {
|
||||||
|
return $valid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$counts = array();
|
||||||
|
$coverage = noindex_seo_import_posts_coverage();
|
||||||
|
|
||||||
|
foreach ( noindex_seo_get_import_sources() as $slug => $source ) {
|
||||||
|
$found = get_posts(
|
||||||
|
array(
|
||||||
|
'post_type' => $coverage['post_types'],
|
||||||
|
'post_status' => $coverage['post_statuses'],
|
||||||
|
'fields' => 'ids',
|
||||||
|
'posts_per_page' => -1,
|
||||||
|
'no_found_rows' => true,
|
||||||
|
'suppress_filters' => true,
|
||||||
|
'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'] ) ),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$term_count = 0;
|
||||||
|
if ( isset( $source['terms'] ) ) {
|
||||||
|
$terms = get_terms(
|
||||||
|
array(
|
||||||
|
'taxonomy' => get_taxonomies( array( 'public' => true ), 'names' ),
|
||||||
|
'hide_empty' => false,
|
||||||
|
'fields' => 'ids',
|
||||||
|
'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['terms'] ) ),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$term_count = is_array( $terms ) ? count( $terms ) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$counts[ $slug ] = array(
|
||||||
|
'label' => $source['label'],
|
||||||
|
'posts' => count( $found ),
|
||||||
|
'terms' => $term_count,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
set_transient( 'noindex_seo_import_counts', $counts, 15 * MINUTE_IN_SECONDS );
|
||||||
|
|
||||||
|
return $counts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads one flag of a source from a raw meta value.
|
||||||
|
*
|
||||||
|
* @since 3.7.0
|
||||||
|
*
|
||||||
|
* @param mixed $meta_value Raw meta value.
|
||||||
|
* @param array<string,mixed> $spec Flag spec (key + is|has).
|
||||||
|
* @return bool True when the source flag is on.
|
||||||
|
*/
|
||||||
|
function noindex_seo_source_flag_is_on( $meta_value, array $spec ) {
|
||||||
|
if ( isset( $spec['is'] ) ) {
|
||||||
|
return is_scalar( $meta_value ) && (string) $meta_value === $spec['is'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( isset( $spec['has'] ) && is_scalar( $spec['has'] ) ) {
|
||||||
|
$token = (string) $spec['has'];
|
||||||
|
if ( is_string( $meta_value ) ) {
|
||||||
|
return false !== strpos( $meta_value, $token );
|
||||||
|
}
|
||||||
|
if ( is_array( $meta_value ) ) {
|
||||||
|
return in_array( $token, $meta_value, true );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports the robots overrides of the given sources (3.7.0, spec section 5).
|
||||||
|
*
|
||||||
|
* Rules, per the specification:
|
||||||
|
*
|
||||||
|
* - On-demand: only runs when the user asked for it.
|
||||||
|
* - Never overwrites: content that already carries a `_noindex_seo_override`
|
||||||
|
* meta row (even an "off" one) is skipped and counted.
|
||||||
|
* - Only the shared noindex / nofollow booleans are imported; they become
|
||||||
|
* granular per-post / per-term overrides with the override flag set.
|
||||||
|
*
|
||||||
|
* @since 3.7.0
|
||||||
|
*
|
||||||
|
* @param array<int, string> $slugs Source slugs to import.
|
||||||
|
* @return array{posts: int, terms: int, skipped_posts: int, skipped_terms: int} Totals across sources.
|
||||||
|
*/
|
||||||
|
function noindex_seo_run_import( array $slugs ) {
|
||||||
|
$totals = array(
|
||||||
|
'posts' => 0,
|
||||||
|
'terms' => 0,
|
||||||
|
'skipped_posts' => 0,
|
||||||
|
'skipped_terms' => 0,
|
||||||
|
);
|
||||||
|
|
||||||
|
$sources = noindex_seo_get_import_sources();
|
||||||
|
|
||||||
|
foreach ( $slugs as $slug ) {
|
||||||
|
if ( ! isset( $sources[ $slug ] ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$source = $sources[ $slug ];
|
||||||
|
|
||||||
|
// Posts.
|
||||||
|
$coverage = noindex_seo_import_posts_coverage();
|
||||||
|
$post_ids = get_posts(
|
||||||
|
array(
|
||||||
|
'post_type' => $coverage['post_types'],
|
||||||
|
'post_status' => $coverage['post_statuses'],
|
||||||
|
'fields' => 'ids',
|
||||||
|
'posts_per_page' => -1,
|
||||||
|
'no_found_rows' => true,
|
||||||
|
'suppress_filters' => true,
|
||||||
|
'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'] ) ),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ( (array) $post_ids as $post_id ) {
|
||||||
|
$post_id = (int) $post_id;
|
||||||
|
// Never overwrite existing data (an explicit "off" row counts as data too).
|
||||||
|
if ( metadata_exists( 'post', $post_id, '_noindex_seo_override' ) ) {
|
||||||
|
++$totals['skipped_posts'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$noindex = noindex_seo_source_flag_is_on( get_post_meta( $post_id, $source['posts']['noindex']['key'], true ), $source['posts']['noindex'] );
|
||||||
|
$nofollow = noindex_seo_source_flag_is_on( get_post_meta( $post_id, $source['posts']['nofollow']['key'], true ), $source['posts']['nofollow'] );
|
||||||
|
|
||||||
|
if ( ! $noindex && ! $nofollow ) {
|
||||||
|
continue; // False positive of the LIKE query: nothing to import.
|
||||||
|
}
|
||||||
|
|
||||||
|
update_post_meta( $post_id, '_noindex_seo_override', 1 );
|
||||||
|
update_post_meta( $post_id, '_noindex_seo_noindex', $noindex ? 1 : 0 );
|
||||||
|
update_post_meta( $post_id, '_noindex_seo_nofollow', $nofollow ? 1 : 0 );
|
||||||
|
++$totals['posts'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Terms (only sources that store term meta).
|
||||||
|
if ( isset( $source['terms'] ) ) {
|
||||||
|
$term_ids = get_terms(
|
||||||
|
array(
|
||||||
|
'taxonomy' => get_taxonomies( array( 'public' => true ), 'names' ),
|
||||||
|
'hide_empty' => false,
|
||||||
|
'fields' => 'ids',
|
||||||
|
'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['terms'] ) ),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ( is_array( $term_ids ) ? $term_ids : array() as $term_id ) {
|
||||||
|
if ( metadata_exists( 'term', $term_id, '_noindex_seo_override' ) ) {
|
||||||
|
++$totals['skipped_terms'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$noindex = noindex_seo_source_flag_is_on( get_term_meta( $term_id, $source['terms']['noindex']['key'], true ), $source['terms']['noindex'] );
|
||||||
|
$nofollow = noindex_seo_source_flag_is_on( get_term_meta( $term_id, $source['terms']['nofollow']['key'], true ), $source['terms']['nofollow'] );
|
||||||
|
|
||||||
|
if ( ! $noindex && ! $nofollow ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
update_term_meta( $term_id, '_noindex_seo_override', 1 );
|
||||||
|
update_term_meta( $term_id, '_noindex_seo_noindex', $noindex ? 1 : 0 );
|
||||||
|
update_term_meta( $term_id, '_noindex_seo_nofollow', $nofollow ? 1 : 0 );
|
||||||
|
++$totals['terms'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The counts shown on the Tools tab describe pre-import state: drop them.
|
||||||
|
delete_transient( 'noindex_seo_import_counts' );
|
||||||
|
|
||||||
|
return $totals;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects the active directive map stored in a post's granular meta.
|
* Collects the active directive map stored in a post's granular meta.
|
||||||
*
|
*
|
||||||
|
|
@ -1533,9 +2098,9 @@ function noindex_seo_rest_effective_permission_check( WP_REST_Request $request )
|
||||||
* REST callback: returns the consolidated settings array.
|
* REST callback: returns the consolidated settings array.
|
||||||
*
|
*
|
||||||
* Strips the internal `version` key — that is an implementation detail that
|
* Strips the internal `version` key — that is an implementation detail that
|
||||||
* callers should not depend on. Everything else (contexts, config) is exposed
|
* callers should not depend on. Everything else (contexts, rules,
|
||||||
* verbatim so headless consumers can replicate the directive logic on their
|
* robots_txt, config) is exposed verbatim so headless consumers can
|
||||||
* own front-end.
|
* replicate the directive logic on their own front-end.
|
||||||
*
|
*
|
||||||
* @since 3.1.0
|
* @since 3.1.0
|
||||||
*
|
*
|
||||||
|
|
@ -1885,7 +2450,7 @@ function noindex_seo_enqueue_admin_assets( $hook ) {
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
// Localize script with translations..
|
// Localize script with translations and the robots.txt preset bot lists..
|
||||||
wp_localize_script(
|
wp_localize_script(
|
||||||
'noindex-seo-admin',
|
'noindex-seo-admin',
|
||||||
'noindexSeoAdmin',
|
'noindexSeoAdmin',
|
||||||
|
|
@ -1893,6 +2458,8 @@ function noindex_seo_enqueue_admin_assets( $hook ) {
|
||||||
'successMessage' => __( 'Settings saved successfully!', 'noindex-seo' ),
|
'successMessage' => __( 'Settings saved successfully!', 'noindex-seo' ),
|
||||||
'expandAll' => __( 'Expand All', 'noindex-seo' ),
|
'expandAll' => __( 'Expand All', 'noindex-seo' ),
|
||||||
'collapseAll' => __( 'Collapse All', 'noindex-seo' ),
|
'collapseAll' => __( 'Collapse All', 'noindex-seo' ),
|
||||||
|
'aiBots' => array_values( noindex_seo_get_ai_bots() ),
|
||||||
|
'searchBots' => array_values( noindex_seo_get_search_bots() ),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -2413,7 +2980,7 @@ function noindex_seo_process_form() {
|
||||||
$scope = ( isset( $_POST['noindex_seo_form_scope'] ) && is_string( $_POST['noindex_seo_form_scope'] ) )
|
$scope = ( isset( $_POST['noindex_seo_form_scope'] ) && is_string( $_POST['noindex_seo_form_scope'] ) )
|
||||||
? sanitize_key( wp_unslash( $_POST['noindex_seo_form_scope'] ) )
|
? sanitize_key( wp_unslash( $_POST['noindex_seo_form_scope'] ) )
|
||||||
: 'settings';
|
: 'settings';
|
||||||
if ( ! in_array( $scope, array( 'general', 'settings' ), true ) ) {
|
if ( ! in_array( $scope, array( 'general', 'settings', 'robotstxt' ), true ) ) {
|
||||||
$scope = 'settings';
|
$scope = 'settings';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2475,6 +3042,28 @@ function noindex_seo_process_form() {
|
||||||
}
|
}
|
||||||
$settings['rules'] = noindex_seo_sanitize_rules( $raw_rules );
|
$settings['rules'] = noindex_seo_sanitize_rules( $raw_rules );
|
||||||
// phpcs:enable WordPress.Security.NonceVerification.Missing
|
// phpcs:enable WordPress.Security.NonceVerification.Missing
|
||||||
|
} elseif ( 'robotstxt' === $scope ) {
|
||||||
|
// Virtual robots.txt management (3.7.0): feature toggle + bot rules
|
||||||
|
// from the parallel agent/policy arrays of the Robots.txt tab.
|
||||||
|
// phpcs:disable WordPress.Security.NonceVerification.Missing -- nonce verified above.
|
||||||
|
$settings['robots_txt']['enabled'] = isset( $_POST['noindex_seo_robotstxt_enabled'] ) ? 1 : 0;
|
||||||
|
|
||||||
|
$raw_rules = array();
|
||||||
|
if ( isset( $_POST['noindex_seo_robotstxt_agent'], $_POST['noindex_seo_robotstxt_policy'] )
|
||||||
|
&& is_array( $_POST['noindex_seo_robotstxt_agent'] ) && is_array( $_POST['noindex_seo_robotstxt_policy'] ) ) {
|
||||||
|
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- array input; every element is sanitized in the loop below.
|
||||||
|
$agents = (array) wp_unslash( $_POST['noindex_seo_robotstxt_agent'] );
|
||||||
|
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- array input; every element is sanitized in the loop below.
|
||||||
|
$policies = (array) wp_unslash( $_POST['noindex_seo_robotstxt_policy'] );
|
||||||
|
foreach ( $policies as $index => $policy ) {
|
||||||
|
$raw_rules[] = array(
|
||||||
|
'user_agent' => isset( $agents[ $index ] ) && is_scalar( $agents[ $index ] ) ? sanitize_text_field( wp_unslash( (string) $agents[ $index ] ) ) : '',
|
||||||
|
'policy' => is_scalar( $policy ) ? sanitize_key( wp_unslash( (string) $policy ) ) : '',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$settings['robots_txt']['rules'] = noindex_seo_sanitize_robots_txt_rules( $raw_rules );
|
||||||
|
// phpcs:enable WordPress.Security.NonceVerification.Missing
|
||||||
} else {
|
} else {
|
||||||
// phpcs:disable WordPress.Security.NonceVerification.Missing -- nonce verified above.
|
// phpcs:disable WordPress.Security.NonceVerification.Missing -- nonce verified above.
|
||||||
// Get the implementation method to validate field compatibility.
|
// Get the implementation method to validate field compatibility.
|
||||||
|
|
@ -2671,6 +3260,14 @@ function noindex_seo_sanitize_imported_settings( $raw ) {
|
||||||
$settings['rules'] = noindex_seo_sanitize_rules( $raw['rules'] );
|
$settings['rules'] = noindex_seo_sanitize_rules( $raw['rules'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Virtual robots.txt rules (3.7.0) ride the JSON backup as well.
|
||||||
|
if ( isset( $raw['robots_txt'] ) && is_array( $raw['robots_txt'] ) ) {
|
||||||
|
$settings['robots_txt']['enabled'] = empty( $raw['robots_txt']['enabled'] ) ? 0 : 1;
|
||||||
|
if ( isset( $raw['robots_txt']['rules'] ) ) {
|
||||||
|
$settings['robots_txt']['rules'] = noindex_seo_sanitize_robots_txt_rules( $raw['robots_txt']['rules'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$raw_config = $raw['config'];
|
$raw_config = $raw['config'];
|
||||||
|
|
||||||
$method = isset( $raw_config['method'] ) && is_string( $raw_config['method'] )
|
$method = isset( $raw_config['method'] ) && is_string( $raw_config['method'] )
|
||||||
|
|
@ -2748,6 +3345,63 @@ function noindex_seo_handle_import() {
|
||||||
}
|
}
|
||||||
add_action( 'admin_post_noindex_seo_import', 'noindex_seo_handle_import' );
|
add_action( 'admin_post_noindex_seo_import', 'noindex_seo_handle_import' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the "Import from other plugins" action (3.7.0, spec section 5).
|
||||||
|
*
|
||||||
|
* On-demand and confirmed by the user: only the sources checked in the form
|
||||||
|
* are imported, and noindex SEO never overwrites content that already
|
||||||
|
* carries its own override data (skipped and counted instead). Redirects
|
||||||
|
* back to the tools tab with the totals for the result notices.
|
||||||
|
*
|
||||||
|
* Hooked to the {@see 'admin_post_noindex_seo_plugin_import'} action.
|
||||||
|
*
|
||||||
|
* @since 3.7.0
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function noindex_seo_handle_plugin_import() {
|
||||||
|
if ( ! current_user_can( 'manage_options' ) ) {
|
||||||
|
wp_die( esc_html__( 'Permission denied.', 'noindex-seo' ) );
|
||||||
|
}
|
||||||
|
check_admin_referer( 'noindex_seo_plugin_import' );
|
||||||
|
|
||||||
|
$known = array_keys( noindex_seo_get_import_sources() );
|
||||||
|
$slugs = array();
|
||||||
|
$raw_selection = isset( $_POST['noindex_seo_import_sources'] ) && is_array( $_POST['noindex_seo_import_sources'] )
|
||||||
|
? wp_unslash( $_POST['noindex_seo_import_sources'] ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- array of slugs, whitelisted against the known sources below.
|
||||||
|
: array();
|
||||||
|
foreach ( $raw_selection as $slug ) {
|
||||||
|
if ( is_string( $slug ) && in_array( sanitize_key( $slug ), $known, true ) ) {
|
||||||
|
$slugs[] = sanitize_key( $slug );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$redirect = admin_url( 'options-general.php?page=noindex_seo&tab=tools' );
|
||||||
|
|
||||||
|
if ( array() === $slugs ) {
|
||||||
|
wp_safe_redirect( add_query_arg( 'plugin_import_empty', '1', $redirect ) );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$totals = noindex_seo_run_import( $slugs );
|
||||||
|
|
||||||
|
wp_safe_redirect(
|
||||||
|
add_query_arg(
|
||||||
|
array(
|
||||||
|
'plugin_import_posts' => $totals['posts'],
|
||||||
|
'plugin_import_terms' => $totals['terms'],
|
||||||
|
'plugin_import_skipped_posts' => $totals['skipped_posts'],
|
||||||
|
'plugin_import_skipped_terms' => $totals['skipped_terms'],
|
||||||
|
),
|
||||||
|
( $totals['posts'] || $totals['terms'] || $totals['skipped_posts'] || $totals['skipped_terms'] )
|
||||||
|
? $redirect
|
||||||
|
: add_query_arg( 'plugin_import_done', '1', $redirect )
|
||||||
|
)
|
||||||
|
);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
add_action( 'admin_post_noindex_seo_plugin_import', 'noindex_seo_handle_plugin_import' );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies a directive change to a context in the consolidated settings.
|
* Applies a directive change to a context in the consolidated settings.
|
||||||
*
|
*
|
||||||
|
|
@ -3281,6 +3935,10 @@ function noindex_seo_get_suggested_contexts() {
|
||||||
* @since 3.1.3 Skipped on WordPress versions without register_post_meta()
|
* @since 3.1.3 Skipped on WordPress versions without register_post_meta()
|
||||||
* (pre-4.9.6): granular control still works there through the
|
* (pre-4.9.6): granular control still works there through the
|
||||||
* classic meta box, Quick Edit and bulk actions.
|
* classic meta box, Quick Edit and bulk actions.
|
||||||
|
* @since 3.7.1 Adds 'custom-fields' post type support for the registered
|
||||||
|
* types: without it the REST API exposes no `meta` field and
|
||||||
|
* the block editor sidebar silently drops every save on
|
||||||
|
* custom post types registered without that support.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
|
@ -3298,6 +3956,17 @@ function noindex_seo_register_post_meta() {
|
||||||
// Get all public post types.
|
// Get all public post types.
|
||||||
$post_types = get_post_types( array( 'public' => true ), 'names' );
|
$post_types = get_post_types( array( 'public' => true ), 'names' );
|
||||||
|
|
||||||
|
// The REST API (and with it the block editor sidebar) only exposes the
|
||||||
|
// `meta` field for post types that support 'custom-fields'. Custom post
|
||||||
|
// types registered without it (a very common registration) would
|
||||||
|
// silently drop every sidebar save with an HTTP 200, so the support is
|
||||||
|
// added for exactly the post types the plugin registers meta on.
|
||||||
|
foreach ( $post_types as $post_type ) {
|
||||||
|
if ( ! post_type_supports( $post_type, 'custom-fields' ) ) {
|
||||||
|
add_post_type_support( $post_type, 'custom-fields' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Meta fields to register. Boolean directives (and the override flag) are
|
// Meta fields to register. Boolean directives (and the override flag) are
|
||||||
// integers; value directives (3.6.0) are strings normalized on write.
|
// integers; value directives (3.6.0) are strings normalized on write.
|
||||||
$boolean_meta_fields = array(
|
$boolean_meta_fields = array(
|
||||||
|
|
@ -4614,14 +5283,15 @@ function noindex_seo_admin() {
|
||||||
|
|
||||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only navigation state, not form data.
|
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only navigation state, not form data.
|
||||||
$current_tab = isset( $_GET['tab'] ) && is_string( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'general';
|
$current_tab = isset( $_GET['tab'] ) && is_string( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'general';
|
||||||
if ( ! in_array( $current_tab, array( 'general', 'settings', 'tools' ), true ) ) {
|
if ( ! in_array( $current_tab, array( 'general', 'settings', 'tools', 'robotstxt' ), true ) ) {
|
||||||
$current_tab = 'general';
|
$current_tab = 'general';
|
||||||
}
|
}
|
||||||
|
|
||||||
$tabs = array(
|
$tabs = array(
|
||||||
'general' => __( 'General', 'noindex-seo' ),
|
'general' => __( 'General', 'noindex-seo' ),
|
||||||
'settings' => __( 'SEO Settings', 'noindex-seo' ),
|
'settings' => __( 'SEO Settings', 'noindex-seo' ),
|
||||||
'tools' => __( 'Import / Export', 'noindex-seo' ),
|
'tools' => __( 'Import / Export', 'noindex-seo' ),
|
||||||
|
'robotstxt' => __( 'Robots.txt', 'noindex-seo' ),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Define section icons (using Dashicons)..
|
// Define section icons (using Dashicons)..
|
||||||
|
|
@ -5384,6 +6054,112 @@ function noindex_seo_admin() {
|
||||||
|
|
||||||
<?php if ( 'tools' === $current_tab ) : ?>
|
<?php if ( 'tools' === $current_tab ) : ?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// Result notices for the plugin import (set by our own admin-post
|
||||||
|
// handler after a nonce check; display-only query flags).
|
||||||
|
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- read-only result flags set by our own handler.
|
||||||
|
$imported_posts = isset( $_GET['plugin_import_posts'] ) && is_numeric( $_GET['plugin_import_posts'] ) ? absint( $_GET['plugin_import_posts'] ) : 0;
|
||||||
|
$imported_terms = isset( $_GET['plugin_import_terms'] ) && is_numeric( $_GET['plugin_import_terms'] ) ? absint( $_GET['plugin_import_terms'] ) : 0;
|
||||||
|
$skipped_posts = isset( $_GET['plugin_import_skipped_posts'] ) && is_numeric( $_GET['plugin_import_skipped_posts'] ) ? absint( $_GET['plugin_import_skipped_posts'] ) : 0;
|
||||||
|
$skipped_terms = isset( $_GET['plugin_import_skipped_terms'] ) && is_numeric( $_GET['plugin_import_skipped_terms'] ) ? absint( $_GET['plugin_import_skipped_terms'] ) : 0;
|
||||||
|
$import_selection_empty = isset( $_GET['plugin_import_empty'] );
|
||||||
|
// phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||||
|
if ( $imported_posts || $imported_terms ) {
|
||||||
|
$imported_posts_text = sprintf(
|
||||||
|
/* translators: %d: number of posts. */
|
||||||
|
_n( 'Imported robots overrides for %d post', 'Imported robots overrides for %d posts', $imported_posts, 'noindex-seo' ),
|
||||||
|
$imported_posts
|
||||||
|
);
|
||||||
|
$imported_terms_text = sprintf(
|
||||||
|
/* translators: %d: number of terms. */
|
||||||
|
_n( '%d term', '%d terms', $imported_terms, 'noindex-seo' ),
|
||||||
|
$imported_terms
|
||||||
|
);
|
||||||
|
|
||||||
|
echo '<div class="notice notice-success is-dismissible"><p>';
|
||||||
|
echo esc_html( $imported_posts_text . ', ' . $imported_terms_text );
|
||||||
|
|
||||||
|
if ( $skipped_posts || $skipped_terms ) {
|
||||||
|
echo ' — ' . esc_html(
|
||||||
|
sprintf(
|
||||||
|
/* translators: 1: number of skipped posts, 2: number of skipped terms. */
|
||||||
|
__( '%1$d posts and %2$d terms skipped (already configured)', 'noindex-seo' ),
|
||||||
|
$skipped_posts,
|
||||||
|
$skipped_terms
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
echo '</p></div>';
|
||||||
|
}
|
||||||
|
if ( $import_selection_empty ) {
|
||||||
|
echo '<div class="notice notice-warning is-dismissible"><p>';
|
||||||
|
esc_html_e( 'No plugins were selected to import from.', 'noindex-seo' );
|
||||||
|
echo '</p></div>';
|
||||||
|
}
|
||||||
|
if ( isset( $_GET['plugin_import_done'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only result flag set by our own handler after a nonce check.
|
||||||
|
echo '<div class="notice notice-warning is-dismissible"><p>';
|
||||||
|
esc_html_e( 'The selected plugins had no importable robots data left.', 'noindex-seo' );
|
||||||
|
echo '</p></div>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<!-- Import from other plugins: on-demand migration of robots overrides. -->
|
||||||
|
<h2 class="noindex-seo-section-title"><?php esc_html_e( 'Import from other plugins', 'noindex-seo' ); ?></h2>
|
||||||
|
<p class="description">
|
||||||
|
<?php esc_html_e( 'Imports the noindex and nofollow flags stored by other SEO plugins (Yoast SEO, Rank Math, SEOPress, All in One SEO) as per-post and per-term overrides. Nothing is imported automatically: you pick the plugins below and confirm. Content that already has its own override is never touched.', 'noindex-seo' ); ?>
|
||||||
|
</p>
|
||||||
|
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" class="noindex-seo-apply-form">
|
||||||
|
<input type="hidden" name="action" value="noindex_seo_plugin_import">
|
||||||
|
<?php wp_nonce_field( 'noindex_seo_plugin_import' ); ?>
|
||||||
|
<?php $import_counts = noindex_seo_count_import_sources(); ?>
|
||||||
|
<?php $any_importable = false; ?>
|
||||||
|
<?php foreach ( $import_counts as $import_slug => $import_count ) : ?>
|
||||||
|
<?php if ( $import_count['posts'] || $import_count['terms'] ) : ?>
|
||||||
|
<?php $any_importable = true; ?>
|
||||||
|
<p>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="noindex_seo_import_sources[]" value="<?php echo esc_attr( $import_slug ); ?>" checked>
|
||||||
|
<strong><?php echo esc_html( $import_count['label'] ); ?></strong>
|
||||||
|
—
|
||||||
|
<?php
|
||||||
|
echo esc_html(
|
||||||
|
sprintf(
|
||||||
|
/* translators: %d: number of posts found. */
|
||||||
|
_n( '%d post', '%d posts', $import_count['posts'], 'noindex-seo' ),
|
||||||
|
$import_count['posts']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
?>
|
||||||
|
<?php if ( $import_count['terms'] ) : ?>
|
||||||
|
,
|
||||||
|
<?php
|
||||||
|
echo esc_html(
|
||||||
|
sprintf(
|
||||||
|
/* translators: %d: number of terms found. */
|
||||||
|
_n( '%d term', '%d terms', $import_count['terms'], 'noindex-seo' ),
|
||||||
|
$import_count['terms']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</label>
|
||||||
|
</p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php if ( ! $any_importable ) : ?>
|
||||||
|
<p><em><?php esc_html_e( 'No importable robots data from other SEO plugins was found on this site.', 'noindex-seo' ); ?></em></p>
|
||||||
|
<?php else : ?>
|
||||||
|
<?php
|
||||||
|
submit_button(
|
||||||
|
__( 'Import selected plugins', 'noindex-seo' ),
|
||||||
|
'secondary',
|
||||||
|
'noindex-seo-plugin-import',
|
||||||
|
false
|
||||||
|
);
|
||||||
|
?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</form>
|
||||||
|
|
||||||
<!-- Export: download the current settings as a JSON file. -->
|
<!-- Export: download the current settings as a JSON file. -->
|
||||||
<h2 class="noindex-seo-section-title"><?php esc_html_e( 'Export settings', 'noindex-seo' ); ?></h2>
|
<h2 class="noindex-seo-section-title"><?php esc_html_e( 'Export settings', 'noindex-seo' ); ?></h2>
|
||||||
<p class="description">
|
<p class="description">
|
||||||
|
|
@ -5430,6 +6206,86 @@ function noindex_seo_admin() {
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ( 'robotstxt' === $current_tab ) : ?>
|
||||||
|
|
||||||
|
<!-- Virtual robots.txt management (3.7.0): extends, never replaces,
|
||||||
|
the robots.txt WordPress generates virtually. Inactive by default. -->
|
||||||
|
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
|
||||||
|
<input type="hidden" name="action" value="update_noindex_seo">
|
||||||
|
<input type="hidden" name="noindex_seo_form_scope" value="robotstxt">
|
||||||
|
<?php wp_nonce_field( 'update_noindex_seo_nonce' ); ?>
|
||||||
|
|
||||||
|
<div class="noindex-seo-config-option">
|
||||||
|
<label class="noindex-seo-switch">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id="noindex_seo_robotstxt_enabled"
|
||||||
|
name="noindex_seo_robotstxt_enabled"
|
||||||
|
value="1"
|
||||||
|
<?php checked( 1, noindex_seo_get_settings()['robots_txt']['enabled'] ); ?>
|
||||||
|
>
|
||||||
|
<span class="noindex-seo-slider"></span>
|
||||||
|
</label>
|
||||||
|
<div class="noindex-seo-config-body">
|
||||||
|
<label for="noindex_seo_robotstxt_enabled" class="noindex-seo-config-label">
|
||||||
|
<?php esc_html_e( 'Extend the virtual robots.txt with bot rules', 'noindex-seo' ); ?>
|
||||||
|
</label>
|
||||||
|
<p class="description">
|
||||||
|
<?php esc_html_e( 'Inactive by default. When enabled, the rules below are appended to the robots.txt that WordPress generates virtually — they never replace it. This only applies when WordPress serves robots.txt itself: a physical robots.txt file in the site root, or "Discourage search engines" in Reading settings, takes precedence.', 'noindex-seo' ); ?>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="noindex-seo-rules-table noindex-seo-robotstxt-table">
|
||||||
|
<div class="noindex-seo-rule-row noindex-seo-rule-head">
|
||||||
|
<span><?php esc_html_e( 'User-agent', 'noindex-seo' ); ?></span>
|
||||||
|
<span><?php esc_html_e( 'Policy', 'noindex-seo' ); ?></span>
|
||||||
|
<span class="screen-reader-text"><?php esc_html_e( 'Actions', 'noindex-seo' ); ?></span>
|
||||||
|
</div>
|
||||||
|
<div class="noindex-seo-rule-rows noindex-seo-robotstxt-rows" data-max-rules="30">
|
||||||
|
<?php $robotstxt_rules = noindex_seo_get_settings()['robots_txt']['rules']; ?>
|
||||||
|
<?php if ( empty( $robotstxt_rules ) ) : ?>
|
||||||
|
<?php
|
||||||
|
$robotstxt_rules = array(
|
||||||
|
array(
|
||||||
|
'user_agent' => '',
|
||||||
|
'policy' => 'block',
|
||||||
|
),
|
||||||
|
); // One empty row to start from.
|
||||||
|
?>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php foreach ( $robotstxt_rules as $robotstxt_rule ) : ?>
|
||||||
|
<div class="noindex-seo-rule-row">
|
||||||
|
<input type="text" maxlength="100" name="noindex_seo_robotstxt_agent[]" value="<?php echo esc_attr( $robotstxt_rule['user_agent'] ); ?>" placeholder="<?php esc_attr_e( 'User-agent token, e.g. GPTBot or *', 'noindex-seo' ); ?>">
|
||||||
|
<select name="noindex_seo_robotstxt_policy[]">
|
||||||
|
<option value="block" <?php selected( 'block', $robotstxt_rule['policy'] ); ?>><?php esc_html_e( 'Block (Disallow: /)', 'noindex-seo' ); ?></option>
|
||||||
|
<option value="allow" <?php selected( 'allow', $robotstxt_rule['policy'] ); ?>><?php esc_html_e( 'Allow (Allow: /)', 'noindex-seo' ); ?></option>
|
||||||
|
</select>
|
||||||
|
<button type="button" class="button noindex-seo-rule-remove" aria-label="<?php esc_attr_e( 'Remove rule', 'noindex-seo' ); ?>"><span class="dashicons dashicons-no-alt"></span></button>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<p>
|
||||||
|
<button type="button" class="button noindex-seo-rule-add" data-target=".noindex-seo-robotstxt-rows"><?php esc_html_e( 'Add rule', 'noindex-seo' ); ?></button>
|
||||||
|
<button type="button" class="button noindex-seo-robotstxt-preset" data-preset="ai"><?php esc_html_e( 'Add common AI bots', 'noindex-seo' ); ?></button>
|
||||||
|
<button type="button" class="button noindex-seo-robotstxt-preset" data-preset="search"><?php esc_html_e( 'Add common search engine bots', 'noindex-seo' ); ?></button>
|
||||||
|
</p>
|
||||||
|
<p class="description">
|
||||||
|
<?php esc_html_e( 'Up to 30 rules. Blocked bots receive "Disallow: /" for the whole site; allowed bots receive "Allow: /" (useful to allow one crawler inside a broader block set with a * rule). Duplicate user-agents are ignored.', 'noindex-seo' ); ?>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php $robotstxt_block = noindex_seo_get_robots_txt_block(); ?>
|
||||||
|
<?php if ( '' !== $robotstxt_block ) : ?>
|
||||||
|
<h2 class="noindex-seo-section-title"><?php esc_html_e( 'Preview of the appended block', 'noindex-seo' ); ?></h2>
|
||||||
|
<pre class="noindex-seo-robotstxt-preview"><code><?php echo esc_html( $robotstxt_block ); ?></code></pre>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php submit_button(); ?>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
|
||||||
26
readme.txt
26
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.6.0
|
Stable tag: 3.7.0
|
||||||
Requires PHP: 8.3
|
Requires PHP: 8.3
|
||||||
Version: 3.6.0
|
Version: 3.7.0
|
||||||
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
|
||||||
|
|
||||||
|
|
@ -132,6 +132,18 @@ The commands enforce the same rules as the settings page (unknown contexts and d
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
|
= Robots.txt =
|
||||||
|
|
||||||
|
A dedicated "Robots.txt" tab extends the robots.txt that WordPress generates virtually with bot rules — it never replaces the core output and is inactive until you enable it:
|
||||||
|
|
||||||
|
* Block (`Disallow: /`) or allow (`Allow: /`) individual crawlers, with `*` wildcard rules supported.
|
||||||
|
* One-click presets add the well-known AI crawlers (GPTBot, ClaudeBot, Google-Extended, CCBot, Bytespider…) or the main search engine crawlers (Googlebot, Bingbot, DuckDuckBot…) as blocked rules — edit them freely afterwards. Both lists are filterable.
|
||||||
|
* Rules only apply when WordPress serves robots.txt itself: a physical robots.txt file in the site root, or "Discourage search engines" in Reading settings, takes precedence.
|
||||||
|
|
||||||
|
= Import from other plugins =
|
||||||
|
|
||||||
|
The "Import / Export" tab detects robots data left by other SEO plugins — Yoast SEO, Rank Math, SEOPress and All in One SEO (installed or not) — and imports their noindex / nofollow flags as per-post and per-term overrides. Nothing imports automatically: you pick the detected plugins and confirm. Content that already has its own override — even a disabled one — is never touched and is reported as skipped.
|
||||||
|
|
||||||
= REST API =
|
= REST API =
|
||||||
|
|
||||||
The plugin exposes two read-only endpoints under `/wp-json/noindex-seo/v1/` so headless consumers can read the configuration:
|
The plugin exposes two read-only endpoints under `/wp-json/noindex-seo/v1/` so headless consumers can read the configuration:
|
||||||
|
|
@ -180,6 +192,10 @@ No. By default all plugin data is preserved on uninstall. If you want a complete
|
||||||
|
|
||||||
== Changelog ==
|
== Changelog ==
|
||||||
|
|
||||||
|
= 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.
|
||||||
|
|
||||||
= 3.6.0 =
|
= 3.6.0 =
|
||||||
|
|
||||||
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).
|
||||||
|
|
@ -188,10 +204,6 @@ Feature release: 5 modern robots directives (notranslate, max-snippet, max-image
|
||||||
|
|
||||||
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).
|
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).
|
||||||
|
|
||||||
= 3.4.0 =
|
|
||||||
|
|
||||||
WP-CLI support: a `wp noindex-seo` command namespace with `list`, `set`, `unset`, `export`, `import` and bulk per-post `override` — automation-friendly and scaling past the ~200-post ceiling of the bulk UI.
|
|
||||||
|
|
||||||
= 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/).
|
||||||
|
|
@ -212,6 +224,6 @@ This plugin adheres to the following security measures and review protocols for
|
||||||
|
|
||||||
== Vulnerabilities ==
|
== Vulnerabilities ==
|
||||||
|
|
||||||
* No vulnerabilities have been published up to version 3.6.0.
|
* No vulnerabilities have been published up to version 3.7.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).
|
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).
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue