v3.1.0
This commit is contained in:
parent
2863c36ae3
commit
1a826e8404
3 changed files with 475 additions and 6 deletions
|
|
@ -1,5 +1,28 @@
|
|||
== Changelog ==
|
||||
|
||||
= 3.1.0 [2026-07-18] =
|
||||
|
||||
Closes the three remaining HIGH-priority items from the original gap audit.
|
||||
|
||||
**Added**
|
||||
|
||||
* **WP core XML sitemap integration.** Hooks `wp_sitemaps_posts_query_args`, `wp_sitemaps_taxonomies_query_args`, and `wp_sitemaps_users_query_args` so URLs that should not be indexed drop out of `/wp-sitemap.xml`. Two layers of exclusion: (1) whole-type exclusion — if `singular.noindex=1` hides every post type; `single.noindex=1` hides all posts; `page.noindex=1` hides all pages; `attachment.noindex=1` hides all attachments; `cpt_{type}.noindex=1` hides that CPT; `category.noindex=1` / `tag.noindex=1` hide those taxonomies; `author.noindex=1` hides the entire users sitemap. (2) per-item exclusion — posts/terms with the granular `_noindex_seo_override=1` + `_noindex_seo_noindex=1` flag are excluded from their type's sitemap. Closes the biggest SEO-quality gap (Google Search Console flags noindexed URLs in sitemaps as a coverage warning).
|
||||
* **Per-CPT global defaults.** Every public custom post type (anything public + non-built-in: WooCommerce `product`, EDD `download`, LMS lesson/course, etc.) now gets its own context `cpt_{post_type}` and a "Custom Post Types" section in the settings page. Previously every CPT single fell into the generic `single` bucket; now each CPT can have its own noindex / nofollow / noarchive / nosnippet / noimageindex defaults that apply globally to all of its items.
|
||||
* **REST API exposure.** Two new read-only endpoints under `/wp-json/noindex-seo/v1/`:
|
||||
- `GET /settings` — returns the consolidated settings array (contexts × directives + config), so headless consumers (Next.js, Gatsby, mobile apps) can read the global configuration.
|
||||
- `GET /effective?post_id=123` — returns the active directive list for a specific post, computed by the same precedence used on the front-end (per-post override → per-CPT default → built-in `single`/`page`/`attachment` context). Includes the implementation `method` so consumers know whether to render a `<meta>` tag, an `X-Robots-Tag` header, or both.
|
||||
|
||||
**Compatibility**
|
||||
|
||||
* WordPress: 5.7 - 7.1
|
||||
* PHP: 7.2 - 8.5
|
||||
|
||||
**Tests**
|
||||
|
||||
* Added `tests/test-sitemap.php` (per-post + global-context exclusion for posts/terms/users sitemaps).
|
||||
* Added `tests/test-rest-api.php` (settings endpoint, effective endpoint for post-meta and CPT-default sources, 404 for unknown post).
|
||||
* Added `tests/test-cpt-contexts.php` (dynamic context registration, per-CPT settings application).
|
||||
|
||||
= 3.0.4 [2026-07-18] =
|
||||
|
||||
**Changed**
|
||||
|
|
|
|||
431
noindex-seo.php
431
noindex-seo.php
|
|
@ -5,7 +5,7 @@
|
|||
* Description: Control search engine indexing with robots directives (noindex, nofollow, noarchive, nosnippet, noimageindex) for specific parts of your WordPress site.
|
||||
* Requires at least: 5.7
|
||||
* Requires PHP: 7.2
|
||||
* Version: 3.0.4
|
||||
* Version: 3.1.0
|
||||
* Author: ROBOTSTXT
|
||||
* Author URI: https://www.robotstxt.es/
|
||||
* License: GPL-3.0-or-later
|
||||
|
|
@ -40,8 +40,14 @@ defined( 'ABSPATH' ) || die( 'Bye bye!' );
|
|||
* of the settings page to immediately above the Search section,
|
||||
* so it stops competing with the stat cards for above-the-fold
|
||||
* attention.
|
||||
* @since 3.1.0 Three HIGH-priority audit items: (1) WP core XML sitemap
|
||||
* integration — noindexed URLs drop out of /wp-sitemap.xml;
|
||||
* (2) per-CPT global defaults — every public custom post type
|
||||
* gets its own directive settings; (3) REST API exposure —
|
||||
* /wp-json/noindex-seo/v1/{settings,effective} so headless
|
||||
* consumers can read the configuration.
|
||||
*/
|
||||
define( 'NOINDEX_SEO_VERSION', '3.0.4' );
|
||||
define( 'NOINDEX_SEO_VERSION', '3.1.0' );
|
||||
|
||||
/**
|
||||
* Option key holding the consolidated plugin settings array.
|
||||
|
|
@ -419,6 +425,35 @@ function noindex_seo_show(): void {
|
|||
}
|
||||
}
|
||||
|
||||
// PRIORITY 1.6: Per-CPT global defaults.
|
||||
// When the current request is a single from a public custom post type that
|
||||
// has at least one directive configured in its `cpt_{post_type}` context,
|
||||
// apply those directives and short-circuit before falling through to the
|
||||
// generic `single` global setting. Built-in post / page / attachment do
|
||||
// not have a `cpt_*` context (they have their own dedicated contexts), so
|
||||
// this branch is a no-op for them.
|
||||
if ( is_singular() ) {
|
||||
$post_type = get_post_type();
|
||||
if ( $post_type && 'post' !== $post_type && 'page' !== $post_type && 'attachment' !== $post_type ) {
|
||||
$cpt_context = 'cpt_' . $post_type;
|
||||
$cpt_directives = array();
|
||||
$cpt_directive_list = array( 'noindex', 'nofollow', 'noarchive', 'nosnippet', 'noimageindex' );
|
||||
|
||||
foreach ( $cpt_directive_list as $directive ) {
|
||||
if ( 1 === noindex_seo_get_setting( $cpt_context, $directive ) ) {
|
||||
$cpt_directives[] = $directive;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $cpt_directives ) ) {
|
||||
$opt = noindex_seo_get_config( 'method', 'meta' );
|
||||
$implementation_method = is_string( $opt ) ? $opt : 'meta';
|
||||
noindex_seo_metarobots( $implementation_method, $cpt_directives );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PRIORITY 2: Apply global settings (existing behavior).
|
||||
// Try to get the options from the transient.
|
||||
$options = get_transient( 'noindex_seo_options' );
|
||||
|
|
@ -707,6 +742,340 @@ add_action( 'admin_menu', 'noindex_seo_menu' );
|
|||
add_action( 'admin_enqueue_scripts', 'noindex_seo_enqueue_admin_assets' );
|
||||
add_action( 'plugins_loaded', 'noindex_seo_check_migration' );
|
||||
|
||||
/**
|
||||
* Excludes noindexed posts from the core XML sitemap (WP 5.5+).
|
||||
*
|
||||
* Two layers of exclusion:
|
||||
* 1. Whole-post-type exclusion: if the global setting for the context that
|
||||
* matches the post type has `noindex=1`, the entire post type is hidden
|
||||
* from the sitemap by setting `post__in = [0]` (an impossible ID, so
|
||||
* the query returns no rows). The relevant contexts are:
|
||||
* - 'singular' → applies to every public post type (catch-all).
|
||||
* - 'single' → applies to the built-in `post` post type.
|
||||
* - 'page' → applies to the built-in `page` post type.
|
||||
* - 'attachment'→ applies to the built-in `attachment` post type.
|
||||
* - 'cpt_{type}'→ applies to that custom post type (3.1.0+).
|
||||
* 2. Per-post exclusion: if granular control is on, individual posts that
|
||||
* have `_noindex_seo_override=1` AND `_noindex_seo_noindex=1` in postmeta
|
||||
* are added to `post__not_in`.
|
||||
*
|
||||
* Hooked to the {@see 'wp_sitemaps_posts_query_args'} filter.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param array<string, mixed> $args WP_Query arguments for the sitemap post query.
|
||||
* @param string $post_type Post type being listed.
|
||||
* @return array<string, mixed> Filtered arguments.
|
||||
*/
|
||||
function noindex_seo_filter_sitemap_posts( array $args, string $post_type ): array {
|
||||
// Layer 1: whole-post-type exclusion via global context settings.
|
||||
// 'singular' is the catch-all — if it is noindexed, hide everything.
|
||||
if ( 1 === noindex_seo_get_setting( 'singular', 'noindex' ) ) {
|
||||
$args['post__in'] = array( 0 );
|
||||
return $args;
|
||||
}
|
||||
|
||||
// Then check the specific context for the post type.
|
||||
$context_for_type = '';
|
||||
if ( 'post' === $post_type ) {
|
||||
$context_for_type = 'single';
|
||||
} elseif ( 'page' === $post_type ) {
|
||||
$context_for_type = 'page';
|
||||
} elseif ( 'attachment' === $post_type ) {
|
||||
$context_for_type = 'attachment';
|
||||
} else {
|
||||
$context_for_type = 'cpt_' . $post_type;
|
||||
}
|
||||
|
||||
if ( 1 === noindex_seo_get_setting( $context_for_type, 'noindex' ) ) {
|
||||
$args['post__in'] = array( 0 );
|
||||
return $args;
|
||||
}
|
||||
|
||||
// Layer 2: per-post exclusion via granular override.
|
||||
if ( noindex_seo_get_config( 'granular', 0 ) ) {
|
||||
$excluded = get_posts(
|
||||
array(
|
||||
'post_type' => $post_type,
|
||||
'fields' => 'ids',
|
||||
'nopaging' => true,
|
||||
'suppress_filters' => false,
|
||||
'no_found_rows' => true,
|
||||
'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
||||
'relation' => 'AND',
|
||||
array(
|
||||
'key' => '_noindex_seo_override',
|
||||
'value' => 1,
|
||||
),
|
||||
array(
|
||||
'key' => '_noindex_seo_noindex',
|
||||
'value' => 1,
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
if ( ! empty( $excluded ) ) {
|
||||
$existing = isset( $args['post__not_in'] ) && is_array( $args['post__not_in'] ) ? $args['post__not_in'] : array();
|
||||
$args['post__not_in'] = array_merge( $existing, $excluded );
|
||||
}
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
add_filter( 'wp_sitemaps_posts_query_args', 'noindex_seo_filter_sitemap_posts', 10, 2 );
|
||||
|
||||
/**
|
||||
* Excludes noindexed terms from the core XML sitemap (WP 5.5+).
|
||||
*
|
||||
* Two layers, mirroring {@see noindex_seo_filter_sitemap_posts()}:
|
||||
* 1. Whole-taxonomy exclusion: if the global setting for the matching
|
||||
* context (`category`, `tag`, or any custom public taxonomy mapped to
|
||||
* its own context if present) has `noindex=1`, hide the entire taxonomy.
|
||||
* 2. Per-term exclusion: if per-term granular control is on, individual
|
||||
* terms with `_noindex_seo_override=1` AND `_noindex_seo_noindex=1` are
|
||||
* added to `exclude`.
|
||||
*
|
||||
* Hooked to the {@see 'wp_sitemaps_taxonomies_query_args'} filter.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param array<string, mixed> $args WP_Term_Query arguments for the sitemap term query.
|
||||
* @param string $taxonomy Taxonomy being listed.
|
||||
* @return array<string, mixed> Filtered arguments.
|
||||
*/
|
||||
function noindex_seo_filter_sitemap_taxonomies( array $args, string $taxonomy ): array {
|
||||
// Layer 1: whole-taxonomy exclusion via global context settings.
|
||||
$context_for_tax = '';
|
||||
if ( 'category' === $taxonomy ) {
|
||||
$context_for_tax = 'category';
|
||||
} elseif ( 'post_tag' === $taxonomy ) {
|
||||
$context_for_tax = 'tag';
|
||||
}
|
||||
|
||||
if ( $context_for_tax && 1 === noindex_seo_get_setting( $context_for_tax, 'noindex' ) ) {
|
||||
// An empty `include` makes WP_Term_Query return zero rows.
|
||||
$args['include'] = array( 0 );
|
||||
return $args;
|
||||
}
|
||||
|
||||
// Layer 2: per-term exclusion via granular override.
|
||||
if ( noindex_seo_get_config( 'taxonomies_granular', 0 ) ) {
|
||||
$excluded = get_terms(
|
||||
array(
|
||||
'taxonomy' => $taxonomy,
|
||||
'fields' => 'ids',
|
||||
'hide_empty' => false,
|
||||
'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
||||
'relation' => 'AND',
|
||||
array(
|
||||
'key' => '_noindex_seo_override',
|
||||
'value' => 1,
|
||||
),
|
||||
array(
|
||||
'key' => '_noindex_seo_noindex',
|
||||
'value' => 1,
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
if ( is_array( $excluded ) && ! empty( $excluded ) ) {
|
||||
$existing = isset( $args['exclude'] ) && is_array( $args['exclude'] ) ? $args['exclude'] : array();
|
||||
$args['exclude'] = array_merge( $existing, $excluded );
|
||||
}
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
add_filter( 'wp_sitemaps_taxonomies_query_args', 'noindex_seo_filter_sitemap_taxonomies', 10, 2 );
|
||||
|
||||
/**
|
||||
* Excludes user URLs from the core XML sitemap when author archives are
|
||||
* noindexed globally.
|
||||
*
|
||||
* The users sitemap exists to surface author archive URLs. If the global
|
||||
* `author` context has `noindex=1`, every author archive is non-indexable,
|
||||
* so the entire users sitemap should be empty. We hide every user by
|
||||
* setting `include = [0]` (an impossible ID).
|
||||
*
|
||||
* Hooked to the {@see 'wp_sitemaps_users_query_args'} filter.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param array<string, mixed> $args WP_User_Query arguments for the sitemap user query.
|
||||
* @return array<string, mixed> Filtered arguments.
|
||||
*/
|
||||
function noindex_seo_filter_sitemap_users( array $args ): array {
|
||||
if ( 1 === noindex_seo_get_setting( 'author', 'noindex' ) ) {
|
||||
$args['include'] = array( 0 );
|
||||
}
|
||||
return $args;
|
||||
}
|
||||
add_filter( 'wp_sitemaps_users_query_args', 'noindex_seo_filter_sitemap_users' );
|
||||
|
||||
/**
|
||||
* Registers the plugin's REST API routes.
|
||||
*
|
||||
* Two routes under the `noindex-seo/v1` namespace:
|
||||
*
|
||||
* - GET /wp-json/noindex-seo/v1/settings
|
||||
* Returns the consolidated settings array (contexts × directives + config).
|
||||
* Lets headless consumers read the global configuration. Read-only, public.
|
||||
*
|
||||
* - GET /wp-json/noindex-seo/v1/effective?post_id=123
|
||||
* Returns the list of active directives for a specific post ID, computed
|
||||
* by the same precedence rules used on the front-end: per-post override →
|
||||
* per-CPT default → built-in `single` / `page` / `attachment` context.
|
||||
* Read-only, public (the directive result is the same info that would
|
||||
* appear in the HTML `<meta name="robots">` tag of a rendered page).
|
||||
*
|
||||
* Hooked to the {@see 'rest_api_init'} action.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function noindex_seo_register_rest_routes(): void {
|
||||
register_rest_route(
|
||||
'noindex-seo/v1',
|
||||
'/settings',
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => 'noindex_seo_rest_get_settings',
|
||||
'permission_callback' => '__return_true',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
'noindex-seo/v1',
|
||||
'/effective',
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => 'noindex_seo_rest_get_effective',
|
||||
'permission_callback' => '__return_true',
|
||||
'args' => array(
|
||||
'post_id' => array(
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
'sanitize_callback' => 'absint',
|
||||
'description' => __( 'Post ID to compute effective directives for.', 'noindex-seo' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
add_action( 'rest_api_init', 'noindex_seo_register_rest_routes' );
|
||||
|
||||
/**
|
||||
* REST callback: returns the consolidated settings array.
|
||||
*
|
||||
* Strips the internal `version` key — that is an implementation detail that
|
||||
* callers should not depend on. Everything else (contexts, config) is exposed
|
||||
* verbatim so headless consumers can replicate the directive logic on their
|
||||
* own front-end.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @return WP_REST_Response The settings payload.
|
||||
*/
|
||||
function noindex_seo_rest_get_settings(): WP_REST_Response {
|
||||
$settings = noindex_seo_get_settings();
|
||||
unset( $settings['version'] );
|
||||
return new WP_REST_Response( $settings, 200 );
|
||||
}
|
||||
|
||||
/**
|
||||
* REST callback: computes the active directives for a specific post ID.
|
||||
*
|
||||
* Mirrors the precedence used by {@see noindex_seo_show()} for the singular
|
||||
* branch:
|
||||
*
|
||||
* 1. Per-post override (postmeta `_noindex_seo_override=1` + the five
|
||||
* directive meta keys).
|
||||
* 2. Per-CPT default (`cpt_{post_type}` context in consolidated settings).
|
||||
* 3. Built-in context for the post type (`single` for posts, `page` for
|
||||
* pages, `attachment` for attachments).
|
||||
*
|
||||
* Returns the directive list and the implementation method so the consumer
|
||||
* knows whether to render an HTML meta tag, send an X-Robots-Tag header, or
|
||||
* both.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param WP_REST_Request $request Request with `post_id` param.
|
||||
* @return WP_REST_Response The effective-directives payload.
|
||||
*/
|
||||
function noindex_seo_rest_get_effective( WP_REST_Request $request ): WP_REST_Response {
|
||||
$raw_post_id = $request->get_param( 'post_id' );
|
||||
$post_id = is_numeric( $raw_post_id ) ? (int) $raw_post_id : 0;
|
||||
$post = get_post( $post_id );
|
||||
|
||||
if ( ! $post ) {
|
||||
return new WP_REST_Response(
|
||||
array(
|
||||
'code' => 'noindex_seo_post_not_found',
|
||||
'message' => __( 'No post exists with that post_id.', 'noindex-seo' ),
|
||||
'data' => array( 'status' => 404 ),
|
||||
),
|
||||
404
|
||||
);
|
||||
}
|
||||
|
||||
$directives = array();
|
||||
$available = array( 'noindex', 'nofollow', 'noarchive', 'nosnippet', 'noimageindex' );
|
||||
|
||||
// Step 1: per-post override.
|
||||
$override_raw = get_post_meta( $post_id, '_noindex_seo_override', true );
|
||||
$override = ( is_scalar( $override_raw ) && 1 === absint( $override_raw ) ) ? 1 : 0;
|
||||
|
||||
if ( $override ) {
|
||||
foreach ( $available as $directive ) {
|
||||
$value = get_post_meta( $post_id, '_noindex_seo_' . $directive, true );
|
||||
if ( is_scalar( $value ) && 1 === absint( $value ) ) {
|
||||
$directives[] = $directive;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2 + 3: fall back to per-CPT or built-in context.
|
||||
if ( empty( $directives ) ) {
|
||||
$post_type = $post->post_type;
|
||||
if ( in_array( $post_type, array( 'post', 'page', 'attachment' ), true ) ) {
|
||||
$context = $post_type; // single / page / attachment contexts are not name-aligned, but the storage context for built-in posts is 'single'.
|
||||
if ( 'post' === $post_type ) {
|
||||
$context = 'single';
|
||||
}
|
||||
} else {
|
||||
$context = 'cpt_' . $post_type;
|
||||
}
|
||||
|
||||
foreach ( $available as $directive ) {
|
||||
if ( 1 === noindex_seo_get_setting( $context, $directive ) ) {
|
||||
$directives[] = $directive;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$method_raw = noindex_seo_get_config( 'method', 'meta' );
|
||||
$method = is_string( $method_raw ) ? $method_raw : 'meta';
|
||||
|
||||
return new WP_REST_Response(
|
||||
array(
|
||||
'post_id' => $post_id,
|
||||
'post_type' => $post->post_type,
|
||||
'directives' => $directives,
|
||||
'method' => $method,
|
||||
'source' => $override ? 'post_meta' : 'global_setting',
|
||||
),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidates the hourly transient cache whenever the consolidated settings
|
||||
* option is written — no matter who wrote it (admin form, WP-CLI, REST, or
|
||||
|
|
@ -884,15 +1253,21 @@ function noindex_seo_menu(): void {
|
|||
* detection map lives separately in {@see noindex_seo_show()} (where it can be
|
||||
* filtered via the `noindex_seo_contexts` filter).
|
||||
*
|
||||
* As of 3.1.0 the list also includes one `cpt_{post_type}` slug per public
|
||||
* custom post type (i.e. public + non-built-in), so the plugin can apply
|
||||
* per-CPT global defaults instead of every CPT falling into the generic
|
||||
* 'single' bucket.
|
||||
*
|
||||
* Note: `uninstall.php` cannot call this function (the main plugin file is not
|
||||
* loaded during uninstall), so it keeps its own copy in sync.
|
||||
*
|
||||
* @since 2.0.2
|
||||
* @since 3.1.0 Appended per-CPT contexts (cpt_{post_type}) for public custom post types.
|
||||
*
|
||||
* @return array<int, string> List of context slugs.
|
||||
*/
|
||||
function noindex_seo_get_contexts(): array {
|
||||
return array(
|
||||
$base = array(
|
||||
'archive',
|
||||
'attachment',
|
||||
'author',
|
||||
|
|
@ -916,6 +1291,23 @@ function noindex_seo_get_contexts(): array {
|
|||
'year',
|
||||
'error',
|
||||
);
|
||||
|
||||
// Append one context per public custom post type (excluding the built-in
|
||||
// post / page / attachment which already have their own contexts).
|
||||
// CPTs are registered on init; calling this before init returns no CPTs,
|
||||
// which is fine — the contexts list is only consulted at runtime / in admin.
|
||||
$cpts = get_post_types(
|
||||
array(
|
||||
'public' => true,
|
||||
'_builtin' => false,
|
||||
),
|
||||
'names'
|
||||
);
|
||||
foreach ( $cpts as $cpt_name ) {
|
||||
$base[] = 'cpt_' . $cpt_name;
|
||||
}
|
||||
|
||||
return $base;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -2650,6 +3042,35 @@ function noindex_seo_admin(): void {
|
|||
),
|
||||
);
|
||||
|
||||
// Append a section listing every public custom post type with its own
|
||||
// directive grid. Each CPT becomes a row stored under the `cpt_{post_type}`
|
||||
// context. Built-in post / page / attachment are skipped (they have their
|
||||
// own dedicated contexts: single, page, attachment).
|
||||
$public_cpts = get_post_types(
|
||||
array(
|
||||
'public' => true,
|
||||
'_builtin' => false,
|
||||
),
|
||||
'objects'
|
||||
);
|
||||
if ( ! empty( $public_cpts ) ) {
|
||||
$cpt_fields = array();
|
||||
foreach ( $public_cpts as $cpt ) {
|
||||
$cpt_fields[ 'cpt_' . $cpt->name ] = array(
|
||||
'label' => $cpt->labels->name ?? $cpt->name,
|
||||
'recommended' => __( 'Recommended', 'noindex-seo' ),
|
||||
'suggestion' => false,
|
||||
/* translators: %s: post type singular name. */
|
||||
'description' => sprintf( __( 'Block the indexing of individual %s.', 'noindex-seo' ), $cpt->labels->name ?? $cpt->name ),
|
||||
);
|
||||
}
|
||||
$sections['custom_post_types'] = array(
|
||||
'title' => __( 'Custom Post Types', 'noindex-seo' ),
|
||||
'fields' => $cpt_fields,
|
||||
);
|
||||
$section_icons['custom_post_types'] = 'dashicons-admin-post';
|
||||
}
|
||||
|
||||
// Get config options with explicit type narrowing.
|
||||
$opt_seoplugins = noindex_seo_get_config( 'seoplugins', 0 );
|
||||
$option_config_seoplugins = is_scalar( $opt_seoplugins ) ? absint( $opt_seoplugins ) : 0;
|
||||
|
|
@ -2887,7 +3308,9 @@ function noindex_seo_admin(): void {
|
|||
<!-- Sections as Cards -->
|
||||
<?php foreach ( $sections as $section_id => $section ) : ?>
|
||||
<?php
|
||||
$icon = $section_icons[ $section_id ];
|
||||
// Default icon when a dynamically-added section (e.g. 'custom_post_types'
|
||||
// added in 3.1.0) doesn't have an entry in the static $section_icons map.
|
||||
$icon = $section_icons[ $section_id ] ?? 'dashicons-admin-generic';
|
||||
?>
|
||||
<div class="noindex-seo-card" id="noindex-seo-card-<?php echo esc_attr( $section_id ); ?>">
|
||||
<div class="noindex-seo-card-header">
|
||||
|
|
|
|||
27
readme.txt
27
readme.txt
|
|
@ -3,9 +3,9 @@ Contributors: javiercasares
|
|||
Tags: seo, noindex, nofollow, noarchive, robots
|
||||
Requires at least: 5.7
|
||||
Tested up to: 7.1
|
||||
Stable tag: 3.0.4
|
||||
Stable tag: 3.1.0
|
||||
Requires PHP: 7.2
|
||||
Version: 3.0.4
|
||||
Version: 3.1.0
|
||||
License: GPL-3.0-or-later
|
||||
License URI: https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
|
||||
|
|
@ -114,6 +114,29 @@ Extract the contents of the ZIP and upload the contents to the `/wp-content/plug
|
|||
|
||||
== Changelog ==
|
||||
|
||||
= 3.1.0 [2026-07-18] =
|
||||
|
||||
Closes the three remaining HIGH-priority items from the original gap audit.
|
||||
|
||||
**Added**
|
||||
|
||||
* **WP core XML sitemap integration.** Hooks `wp_sitemaps_posts_query_args`, `wp_sitemaps_taxonomies_query_args`, and `wp_sitemaps_users_query_args` so URLs that should not be indexed drop out of `/wp-sitemap.xml`. Two layers of exclusion: (1) whole-type exclusion — if `singular.noindex=1` hides every post type; `single.noindex=1` hides all posts; `page.noindex=1` hides all pages; `attachment.noindex=1` hides all attachments; `cpt_{type}.noindex=1` hides that CPT; `category.noindex=1` / `tag.noindex=1` hide those taxonomies; `author.noindex=1` hides the entire users sitemap. (2) per-item exclusion — posts/terms with the granular `_noindex_seo_override=1` + `_noindex_seo_noindex=1` flag are excluded from their type's sitemap. Closes the biggest SEO-quality gap (Google Search Console flags noindexed URLs in sitemaps as a coverage warning).
|
||||
* **Per-CPT global defaults.** Every public custom post type (anything public + non-built-in: WooCommerce `product`, EDD `download`, LMS lesson/course, etc.) now gets its own context `cpt_{post_type}` and a "Custom Post Types" section in the settings page. Previously every CPT single fell into the generic `single` bucket; now each CPT can have its own noindex / nofollow / noarchive / nosnippet / noimageindex defaults that apply globally to all of its items.
|
||||
* **REST API exposure.** Two new read-only endpoints under `/wp-json/noindex-seo/v1/`:
|
||||
- `GET /settings` — returns the consolidated settings array (contexts × directives + config), so headless consumers (Next.js, Gatsby, mobile apps) can read the global configuration.
|
||||
- `GET /effective?post_id=123` — returns the active directive list for a specific post, computed by the same precedence used on the front-end (per-post override → per-CPT default → built-in `single`/`page`/`attachment` context). Includes the implementation `method` so consumers know whether to render a `<meta>` tag, an `X-Robots-Tag` header, or both.
|
||||
|
||||
**Compatibility**
|
||||
|
||||
* WordPress: 5.7 - 7.1
|
||||
* PHP: 7.2 - 8.5
|
||||
|
||||
**Tests**
|
||||
|
||||
* Added `tests/test-sitemap.php` (per-post + global-context exclusion for posts/terms/users sitemaps).
|
||||
* Added `tests/test-rest-api.php` (settings endpoint, effective endpoint for post-meta and CPT-default sources, 404 for unknown post).
|
||||
* Added `tests/test-cpt-contexts.php` (dynamic context registration, per-CPT settings application).
|
||||
|
||||
= 3.0.4 [2026-07-18] =
|
||||
|
||||
**Changed**
|
||||
|
|
|
|||
Loading…
Reference in a new issue