Actualizacion 7.1.2

This commit is contained in:
2026-09-25 12:02:42 -06:00
parent fa60d1f364
commit 32351c9497
221 changed files with 19735 additions and 6951 deletions
@@ -12,6 +12,7 @@ namespace RankMath\Abilities\AI_Visibility;
use WP_REST_Request;
use RankMath\Abilities\Ability_Interface;
use RankMath\AI_Visibility\Platforms;
use RankMath\AI_Visibility\Api\Brands_Controller;
defined( 'ABSPATH' ) || exit;
@@ -66,14 +67,18 @@ class Create_AI_Visibility_Brand implements Ability_Interface {
[
'category' => $this->category,
'label' => esc_html__( 'Create AI Visibility brand', 'seo-by-rank-math' ),
'description' => esc_html__(
'Creates a new brand for AI Visibility monitoring, triggering an initial analysis automatically.',
'seo-by-rank-math'
'description' => sprintf(
/* translators: %s: supported platform IDs. */
esc_html__(
'Creates a new brand for AI Visibility monitoring, triggering an initial analysis automatically. Ask which AI platforms to track. Supported platforms: %s. Selecting more than one requires the Expert plan; other plans may choose only one.',
'seo-by-rank-math'
),
Platforms::supported_as_string()
),
'input_schema' => [
'type' => 'object',
'default' => [],
'required' => [ 'name', 'url' ],
'required' => [ 'name', 'url', 'language', 'platforms' ],
'properties' => [
'name' => [
'type' => 'string',
@@ -94,6 +99,30 @@ class Create_AI_Visibility_Brand implements Ability_Interface {
'description' => esc_html__( 'ISO 3166-1 alpha-2 country code (e.g. "US", "HU"). Defaults to no country filter.', 'seo-by-rank-math' ),
'default' => '',
],
'language' => [
'type' => 'string',
'description' => esc_html__( 'Language the brand should be analyzed in (e.g. "US English", "French"). Required; immutable after creation — ask the user which language to use.', 'seo-by-rank-math' ),
'enum' => Brands_Controller::get_language_choices( false ),
],
'interval' => [
'type' => 'string',
'description' => esc_html__( 'Analysis refresh cadence. Defaults to the account plan\'s default when omitted.', 'seo-by-rank-math' ),
'enum' => array_merge( [ '' ], Brands_Controller::get_interval_choices() ),
'default' => '',
],
'platforms' => [
'type' => 'array',
'minItems' => 1,
'description' => sprintf(
/* translators: %s: supported platform IDs. */
esc_html__( 'AI platforms to track. Supported: %s. Selecting more than one requires the Expert plan; otherwise choose exactly one. Do not assume a default — ask the user which platform(s) to use.', 'seo-by-rank-math' ),
Platforms::supported_as_string()
),
'items' => [
'type' => 'string',
'enum' => Platforms::supported(),
],
],
],
'additionalProperties' => false,
],
@@ -130,11 +159,19 @@ class Create_AI_Visibility_Brand implements Ability_Interface {
* @return array
*/
public function execute( array $input = [] ): array {
$platforms = $this->validate_platforms( $input['platforms'] ?? null );
if ( isset( $platforms['error'] ) ) {
return $platforms;
}
$request = new WP_REST_Request( 'POST' );
$request->set_param( 'name', sanitize_text_field( (string) ( $input['name'] ?? '' ) ) );
$request->set_param( 'url', esc_url_raw( (string) ( $input['url'] ?? '' ) ) );
$request->set_param( 'description', sanitize_textarea_field( (string) ( $input['description'] ?? '' ) ) );
$request->set_param( 'locale', sanitize_text_field( (string) ( $input['locale'] ?? '' ) ) );
$request->set_param( 'language', sanitize_text_field( (string) ( $input['language'] ?? '' ) ) );
$request->set_param( 'interval', sanitize_text_field( (string) ( $input['interval'] ?? '' ) ) );
$request->set_param( 'platforms', $platforms );
$response = $this->controller->create_brand( $request );
@@ -149,11 +186,28 @@ class Create_AI_Visibility_Brand implements Ability_Interface {
'id' => $brand['id'] ?? '',
'name' => $brand['name'] ?? '',
'url' => $brand['url'] ?? '',
'interval' => $brand['interval'] ?? null,
'platforms' => $brand['platforms'] ?? [],
'analysis_status' => 'pending',
'created_at' => $brand['created_at'] ?? null,
];
}
/**
* Sanitize and validate platforms. No silent defaults.
*
* @param mixed $platforms Raw platforms value.
* @return string[]|array{error: string}
*/
private function validate_platforms( $platforms ) {
$valid = Platforms::validate( $platforms );
if ( is_wp_error( $valid ) ) {
return [ 'error' => $valid->get_error_message() ];
}
return Platforms::sanitize( $platforms );
}
/**
* JSON schema for the ability output.
*
@@ -176,6 +230,19 @@ class Create_AI_Visibility_Brand implements Ability_Interface {
'format' => 'uri',
'description' => 'Brand website URL.',
],
'interval' => [
'type' => [ 'string', 'null' ],
'enum' => array_merge( [ null ], Brands_Controller::get_interval_choices() ),
'description' => 'Resolved analysis cadence for this brand.',
],
'platforms' => [
'type' => 'array',
'description' => 'AI platforms selected for this brand.',
'items' => [
'type' => 'string',
'enum' => Platforms::supported(),
],
],
'analysis_status' => [
'type' => 'string',
'enum' => [ 'pending' ],
@@ -188,7 +255,7 @@ class Create_AI_Visibility_Brand implements Ability_Interface {
],
'error' => [
'type' => 'string',
'description' => 'Present only on failure — human-readable error from the upstream API.',
'description' => 'Present only on failure — human-readable error from validation or the upstream API.',
],
],
];
@@ -109,7 +109,6 @@ class Get_AI_Visibility_Brand_Insights implements Ability_Interface {
$cached = Cache::get_analysis( $brand_id );
// Cache miss or stale — signal the caller to trigger a fetch via the REST endpoint.
if ( false === $cached || Cache::is_brand_stale( $brand_id ) ) {
rank_math()->tracking->track_ability_executed(
'AI Visibility Brand Insights Fetched',
@@ -175,31 +174,38 @@ class Get_AI_Visibility_Brand_Insights implements Ability_Interface {
'type' => [ 'number', 'null' ],
'description' => 'Total number of AI citations.',
],
'analysis' => [
'type' => [ 'object', 'null' ],
'description' => 'Metadata about the latest analysis run.',
'properties' => [
'id' => [
'type' => [ 'string', 'null' ],
'description' => 'Analysis UUID.',
],
'status' => [
'type' => [ 'string', 'null' ],
'description' => 'Analysis status (e.g. done, processing, error).',
],
'started_at' => [
'type' => [ 'string', 'null' ],
'format' => 'date-time',
'description' => 'ISO 8601 datetime when the analysis started.',
],
'finished_at' => [
'type' => [ 'string', 'null' ],
'format' => 'date-time',
'description' => 'ISO 8601 datetime when the analysis completed.',
],
'duration_seconds' => [
'type' => [ 'number', 'null' ],
'description' => 'How long the analysis took in seconds.',
'analyses' => [
'type' => 'array',
'description' => 'The latest completed analysis for each tracked AI platform (one entry per platform).',
'items' => [
'type' => 'object',
'properties' => [
'id' => [
'type' => [ 'string', 'null' ],
'description' => 'Analysis UUID.',
],
'platform' => [
'type' => [ 'string', 'null' ],
'description' => 'AI platform this analysis ran on (e.g. chatgpt, gemini).',
],
'status' => [
'type' => [ 'string', 'null' ],
'description' => 'Analysis status (e.g. done, processing, error).',
],
'started_at' => [
'type' => [ 'string', 'null' ],
'format' => 'date-time',
'description' => 'ISO 8601 datetime when the analysis started.',
],
'finished_at' => [
'type' => [ 'string', 'null' ],
'format' => 'date-time',
'description' => 'ISO 8601 datetime when the analysis completed.',
],
'duration_seconds' => [
'type' => [ 'number', 'null' ],
'description' => 'How long the analysis took in seconds.',
],
],
],
],
@@ -243,6 +249,10 @@ class Get_AI_Visibility_Brand_Insights implements Ability_Interface {
'type' => 'string',
'description' => 'The query that was submitted to the AI model.',
],
'platform' => [
'type' => [ 'string', 'null' ],
'description' => 'AI platform that produced this result (e.g. chatgpt, gemini).',
],
'found' => [
'type' => 'boolean',
'description' => 'Whether the brand was mentioned in the AI response.',
@@ -18,6 +18,8 @@ use RankMath\Abilities\Analytics\Subscriber as Analytics_Subscriber;
use RankMath\Abilities\AI_Visibility\Subscriber as AI_Visibility_Subscriber;
use RankMath\Abilities\Settings\Subscriber as Settings_Subscriber;
use RankMath\Abilities\Content_Analysis\Subscriber as Content_Analysis_Subscriber;
use RankMath\Abilities\Sitemap\Subscriber as Sitemap_Subscriber;
use RankMath\Abilities\Monitor_404\Subscriber as Monitor_404_Subscriber;
use RankMath\Abilities\Redirections\Subscriber as Redirections_Subscriber;
defined( 'ABSPATH' ) || exit;
@@ -74,6 +76,8 @@ class Abilities {
new AI_Visibility_Subscriber( $shared_meta ),
new Settings_Subscriber( $shared_meta ),
new Content_Analysis_Subscriber( $shared_meta ),
new Sitemap_Subscriber( $shared_meta ),
new Monitor_404_Subscriber( $shared_meta ),
new Redirections_Subscriber( $shared_meta ),
];
@@ -11,6 +11,7 @@
namespace RankMath\Abilities\Link_Genius;
use RankMath\Abilities\Ability_Interface;
use RankMath\Rest\Rest_Helper;
defined( 'ABSPATH' ) || exit;
@@ -117,6 +118,15 @@ class Get_Post_Links implements Ability_Interface {
*/
public function execute( array $input = [] ): array {
$post_id = absint( $input['post_id'] ?? 0 );
$post = $post_id ? get_post( $post_id ) : null;
if ( ! $post ) {
return [ 'error' => esc_html__( 'Invalid post ID.', 'seo-by-rank-math' ) ];
}
if ( ! Rest_Helper::can_edit_post( $post ) ) {
return [ 'error' => esc_html__( 'Sorry, you are not allowed to edit this post.', 'seo-by-rank-math' ) ];
}
$result = $this->runner->run(
[
@@ -226,6 +236,9 @@ class Get_Post_Links implements Ability_Interface {
],
],
],
'error' => [
'type' => 'string',
],
],
];
}
@@ -0,0 +1,219 @@
<?php
/**
* Ability: rank-math/get-404-logs
*
* @since 1.0.279
* @package RankMath
* @subpackage RankMath\Abilities\Monitor_404
* @author Rank Math <support@rankmath.com>
*/
namespace RankMath\Abilities\Monitor_404;
use RankMath\Abilities\Ability_Interface;
use RankMath\Monitor\DB;
defined( 'ABSPATH' ) || exit;
/**
* Registers and executes the rank-math/get-404-logs ability.
*/
class Get_404_Logs implements Ability_Interface {
/**
* Ability category slug.
*
* @var string
*/
private $category;
/**
* Shared meta args.
*
* @var array
*/
private $shared_meta;
/**
* Constructor.
*
* @param string $category Ability category slug.
* @param array $shared_meta Shared meta args.
*/
public function __construct( string $category, array $shared_meta ) {
$this->category = $category;
$this->shared_meta = $shared_meta;
}
/**
* Register the ability with the WordPress Abilities API.
*
* @return void
*/
public function register(): void {
\wp_register_ability(
'rank-math/get-404-logs',
[
'category' => $this->category,
'label' => esc_html__( 'Get 404 logs', 'seo-by-rank-math' ),
'description' => esc_html__(
'Returns the 404 error monitor log entries, with hit counts and referer/user-agent data.',
'seo-by-rank-math'
),
'input_schema' => [
'type' => 'object',
'default' => [],
'properties' => [
'per_page' => [
'type' => 'integer',
'description' => esc_html__( 'The number of log entries to return per page.', 'seo-by-rank-math' ),
'default' => 100,
'minimum' => 1,
'maximum' => 1000,
],
'page' => [
'type' => 'integer',
'description' => esc_html__( 'The page number to return.', 'seo-by-rank-math' ),
'default' => 1,
],
'orderby' => [
'type' => 'string',
'enum' => [ 'hits', 'accessed' ],
'default' => 'hits',
'description' => esc_html__( 'Field to order results by.', 'seo-by-rank-math' ),
],
'order' => [
'type' => 'string',
'enum' => [ 'asc', 'desc' ],
'default' => 'desc',
'description' => esc_html__( 'Sort direction.', 'seo-by-rank-math' ),
],
],
'additionalProperties' => false,
],
'output_schema' => $this->output_schema(),
'permission_callback' => [ $this, 'check_permissions' ],
'execute_callback' => [ $this, 'execute' ],
'meta' => array_merge(
$this->shared_meta,
[
'annotations' => [
'readonly' => true,
'destructive' => false,
'idempotent' => true,
],
]
),
]
);
}
/**
* Check if the current user has permission to execute this ability.
*
* @return bool
*/
public function check_permissions(): bool {
return current_user_can( 'rank_math_404_monitor' );
}
/**
* Execute the ability.
*
* @param array $input Ability input arguments.
* @return array
*/
public function execute( array $input = [] ): array {
$per_page = isset( $input['per_page'] ) ? absint( $input['per_page'] ) : 100;
$page = max( 1, isset( $input['page'] ) ? (int) $input['page'] : 1 );
$orderby = isset( $input['orderby'] ) ? sanitize_text_field( $input['orderby'] ) : 'hits';
$order = isset( $input['order'] ) && in_array( $input['order'], [ 'asc', 'desc' ], true ) ? $input['order'] : 'desc';
$order_map = [
'hits' => 'times_accessed',
'accessed' => 'accessed',
];
$logs = DB::get_logs(
[
'orderby' => $order_map[ $orderby ] ?? 'times_accessed',
'order' => strtoupper( $order ),
'limit' => $per_page,
'paged' => $page,
]
);
$items = array_map(
function ( $log ) {
return [
'id' => (int) $log['id'],
'uri' => $log['uri'],
'hits' => (int) $log['times_accessed'],
'referer' => $log['referer'],
'user_agent' => $log['user_agent'],
'accessed' => $log['accessed'],
];
},
$logs['logs']
);
$stats = DB::get_stats();
$result = [
'stats' => [
'total_urls' => (int) ( $stats->total ?? 0 ),
'total_hits' => (int) ( $stats->hits ?? 0 ),
],
'total' => (int) $logs['count'],
'items' => $items,
];
rank_math()->tracking->track_ability_executed(
'404 Logs Fetched',
[ 'count' => (int) $logs['count'] ],
'rank_math_404_monitor'
);
return $result;
}
/**
* JSON schema for the ability output.
*
* @return array
*/
private function output_schema(): array {
return [
'type' => 'object',
'properties' => [
'stats' => [
'type' => 'object',
'description' => esc_html__( 'Log counts across the entire table, independent of pagination.', 'seo-by-rank-math' ),
'properties' => [
'total_urls' => [ 'type' => 'integer' ],
'total_hits' => [ 'type' => 'integer' ],
],
],
'total' => [
'type' => 'integer',
'description' => esc_html__( 'Number of log entries included in this response (the size of items).', 'seo-by-rank-math' ),
],
'items' => [
'type' => 'array',
'description' => esc_html__( 'The 404 log entries for the requested page.', 'seo-by-rank-math' ),
'items' => [
'type' => 'object',
'properties' => [
'id' => [ 'type' => 'integer' ],
'uri' => [ 'type' => 'string' ],
'hits' => [ 'type' => 'integer' ],
'referer' => [ 'type' => 'string' ],
'user_agent' => [ 'type' => 'string' ],
'accessed' => [ 'type' => 'string' ],
],
],
],
],
];
}
}
@@ -0,0 +1,79 @@
<?php
/**
* Subscriber for 404 Monitor abilities.
*
* @since 1.0.279
* @package RankMath
* @subpackage RankMath\Abilities\Monitor_404
* @author Rank Math <support@rankmath.com>
*/
namespace RankMath\Abilities\Monitor_404;
use RankMath\Traits\Hooker;
use RankMath\Abilities\Subscriber_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Registers the 404 Monitor ability category and its abilities.
*/
class Subscriber implements Subscriber_Interface {
use Hooker;
/**
* Ability category slug for 404 Monitor abilities.
*/
const CATEGORY_SLUG = 'rank-math-404-monitor';
/**
* Shared meta args.
*
* @var array
*/
private $shared_meta;
/**
* Constructor.
*
* @param array $shared_meta Shared meta args from the top-level Abilities class.
*/
public function __construct( array $shared_meta ) {
$this->shared_meta = $shared_meta;
}
/**
* Wire hooks.
*
* @return void
*/
public function register(): void {
$this->action( 'wp_abilities_api_categories_init', 'register_category' );
$this->action( 'wp_abilities_api_init', 'register_get_404_logs' );
}
/**
* Register the 404 Monitor ability category.
*
* @return void
*/
public function register_category(): void {
\wp_register_ability_category(
self::CATEGORY_SLUG,
[
'label' => esc_html__( '404 Monitor', 'seo-by-rank-math' ),
'description' => esc_html__( 'Abilities to inspect the 404 error monitor log.', 'seo-by-rank-math' ),
]
);
}
/**
* Register the rank-math/get-404-logs ability.
*
* @return void
*/
public function register_get_404_logs(): void {
( new Get_404_Logs( self::CATEGORY_SLUG, $this->shared_meta ) )->register();
}
}
@@ -0,0 +1 @@
<?php // Silence is golden.
@@ -0,0 +1,335 @@
<?php
/**
* Ability: rank-math/get-sitemap-status
*
* @since 1.0.277
* @package RankMath
* @subpackage RankMath\Abilities\Sitemap
* @author Rank Math <support@rankmath.com>
*/
namespace RankMath\Abilities\Sitemap;
use RankMath\Abilities\Ability_Interface;
use RankMath\Helper;
use RankMath\Sitemap\Generator;
use RankMath\Sitemap\Router;
use RankMath\Sitemap\Sitemap;
use RankMath\Sitemap\Providers\Post_Type as Post_Type_Provider;
use RankMath\Sitemap\Providers\Taxonomy as Taxonomy_Provider;
use RankMath\Sitemap\Providers\Author as Author_Provider;
defined( 'ABSPATH' ) || exit;
/**
* Registers and executes the rank-math/get-sitemap-status ability.
*/
class Get_Sitemap_Status implements Ability_Interface {
/**
* Ability category slug.
*
* @var string
*/
private $category;
/**
* Shared meta args.
*
* @var array
*/
private $shared_meta;
/**
* Constructor.
*
* @param string $category Ability category slug.
* @param array $shared_meta Shared meta args.
*/
public function __construct( string $category, array $shared_meta ) {
$this->category = $category;
$this->shared_meta = $shared_meta;
}
/**
* Register the ability with the WordPress Abilities API.
*
* @return void
*/
public function register(): void {
\wp_register_ability(
'rank-math/get-sitemap-status',
[
'category' => $this->category,
'label' => esc_html__( 'Get sitemap status', 'seo-by-rank-math' ),
'description' => esc_html__(
'Returns whether the XML sitemap is enabled, the sitemap index URL, and the active sitemap types (post types, taxonomies, and the Local SEO sitemap, when active) with their URLs and estimated entry counts.',
'seo-by-rank-math'
),
'input_schema' => [
'type' => 'object',
'default' => [],
'properties' => [],
'additionalProperties' => false,
],
'output_schema' => $this->output_schema(),
'permission_callback' => [ $this, 'check_permissions' ],
'execute_callback' => [ $this, 'execute' ],
'meta' => array_merge(
$this->shared_meta,
[
'annotations' => [
'readonly' => true,
'destructive' => false,
'idempotent' => true,
],
]
),
]
);
}
/**
* Check if the current user has permission to execute this ability.
*
* @return bool
*/
public function check_permissions(): bool {
return current_user_can( 'rank_math_sitemap' );
}
/**
* Execute the ability.
*
* @param array $input Ability input arguments.
* @return array
*/
public function execute( array $input = [] ): array {
$enabled = Helper::is_module_active( 'sitemap' );
$result = [
'enabled' => $enabled,
'index_url' => Router::get_base_url( Sitemap::get_sitemap_index_slug() . '.xml' ),
'sitemaps' => $this->get_sitemaps(),
];
rank_math()->tracking->track_ability_executed(
'Sitemap Status Fetched',
[
'enabled' => $enabled,
'sitemaps_count' => count( $result['sitemaps'] ),
],
'rank_math_sitemap'
);
return $result;
}
/**
* Build the list of active sitemap types with their URL and estimated entry count.
*
* Reuses the real Generator's provider list, so PRO types (e.g. news/video)
* show up automatically. Local SEO's `local-sitemap.xml` isn't a Provider
* though, so it's captured separately via get_non_provider_entries().
*
* @return array
*/
private function get_sitemaps(): array {
$max_entries = absint( Helper::get_settings( 'sitemap.items_per_page', 100 ) );
$providers = ( new Generator() )->providers;
$sitemaps = [];
foreach ( $providers as $provider ) {
$sitemaps = array_merge( $sitemaps, $this->build_sitemap_entries( $provider, $max_entries ) );
}
$local_sitemap = $this->get_local_sitemap();
if ( null !== $local_sitemap ) {
$sitemaps[] = $local_sitemap;
}
return array_merge( $sitemaps, $this->get_non_provider_entries() );
}
/**
* Capture sitemap entries added outside the Provider system, via the
* `rank_math/sitemap/index` filter (currently only Local SEO's KML_File).
*
* The 'local' type is excluded here because get_local_sitemap() already
* builds that entry with an accurate location count; KML_File::add_local_sitemap()
* fires this same filter internally, so without the exclusion the local
* sitemap would be added twice.
*
* @return array
*/
private function get_non_provider_entries(): array {
$entries = [];
$capture = function ( $item, $label, $type_slug = null ) use ( &$entries ) {
$type = ( is_string( $type_slug ) && '' !== $type_slug ) ? $type_slug : $label;
if ( ! empty( $item['loc'] ) && 'local' !== $type ) {
$entries[] = [
'type' => $type,
'url' => $item['loc'],
'estimated_count' => 1,
];
}
return $item;
};
add_filter( 'rank_math/sitemap/index/entry', $capture, 10, 3 );
apply_filters( 'rank_math/sitemap/index', '' );
remove_filter( 'rank_math/sitemap/index/entry', $capture, 10 );
return $entries;
}
/**
* Build sitemap entries for a single provider.
*
* Get_index_links() only returns {loc, lastmod}, so type and page number
* are captured via the `sitemap/index/entry` filter it fires internally.
* Per-page counts use each provider's own safe public method instead of
* get_sitemap_links(), which can die() via Sitemap::maybe_redirect() when
* called outside an actual sitemap page request.
*
* @param object $provider Sitemap provider instance.
* @param int $max_entries Entries per sitemap page.
* @return array
*/
private function build_sitemap_entries( $provider, int $max_entries ): array {
$entries = [];
$capture = function ( $item, $label, $type_slug = null ) use ( &$entries ) {
if ( ! empty( $item['loc'] ) ) {
$entries[] = [
'type' => ( is_string( $type_slug ) && '' !== $type_slug ) ? $type_slug : $label,
'url' => $item['loc'],
];
}
return $item;
};
add_filter( 'rank_math/sitemap/index/entry', $capture, 10, 3 );
$provider->get_index_links( $max_entries );
remove_filter( 'rank_math/sitemap/index/entry', $capture, 10 );
$post_type_totals = [];
$page_numbers = [];
$sitemaps = [];
foreach ( $entries as $entry ) {
$type = $entry['type'];
$page_numbers[ $type ] = ( $page_numbers[ $type ] ?? 0 ) + 1;
$page = $page_numbers[ $type ];
if ( $provider instanceof Post_Type_Provider ) {
if ( ! isset( $post_type_totals[ $type ] ) ) {
$post_type_totals[ $type ] = (int) $provider->get_post_type_count( $type );
}
$offset = ( $page - 1 ) * $max_entries;
$estimated_count = max( 0, min( $max_entries, $post_type_totals[ $type ] - $offset ) );
} elseif ( $provider instanceof Taxonomy_Provider ) {
$estimated_count = $this->count_taxonomy_page( $provider, $type, $max_entries, $page );
} elseif ( $provider instanceof Author_Provider ) {
$estimated_count = count(
(array) $provider->get_users(
[
'offset' => ( $page - 1 ) * $max_entries,
'number' => $max_entries,
]
)
);
} else {
$estimated_count = $max_entries;
}
$sitemaps[] = [
'type' => $type,
'url' => $entry['url'],
'estimated_count' => $estimated_count,
];
}
return $sitemaps;
}
/**
* Build the Local SEO sitemap entry, if the Local Sitemap is active.
*
* Mirrors the conditions in RankMath\Local_Seo\Local_Seo::location_sitemap(),
* which is what actually decides whether local-sitemap.xml gets served.
*
* @return array|null
*/
private function get_local_sitemap(): ?array {
if (
! Helper::is_module_active( 'sitemap' ) ||
! Helper::is_module_active( 'local-seo' ) ||
'company' !== Helper::get_settings( 'titles.knowledgegraph_type' ) ||
! apply_filters( 'rank_math/sitemap/locations', false ) // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
) {
return null;
}
$locations = apply_filters( // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
'rank_math/sitemap/locations/data',
[ [ 'name' => Helper::get_settings( 'titles.knowledgegraph_name' ) ] ]
);
return [
'type' => 'local',
'url' => Router::get_base_url( 'local-sitemap.xml' ),
'estimated_count' => is_array( $locations ) ? count( $locations ) : 0,
];
}
/**
* Real per-page term count for a taxonomy, via Taxonomy_Provider::get_terms().
*
* @param Taxonomy_Provider $provider Taxonomy provider instance.
* @param string $taxonomy Taxonomy slug.
* @param int $max_entries Entries per sitemap page.
* @param int $current_page Page number (1-indexed).
* @return int
*/
private function count_taxonomy_page( Taxonomy_Provider $provider, string $taxonomy, int $max_entries, int $current_page ): int {
$taxonomy_object = get_taxonomy( $taxonomy );
if ( ! $taxonomy_object ) {
return 0;
}
return count( (array) $provider->get_terms( $taxonomy_object, $max_entries, $current_page ) );
}
/**
* JSON schema for the ability output.
*
* @return array
*/
private function output_schema(): array {
return [
'type' => 'object',
'properties' => [
'enabled' => [
'type' => 'boolean',
'description' => esc_html__( 'Whether the XML sitemap module is active.', 'seo-by-rank-math' ),
],
'index_url' => [
'type' => 'string',
'description' => esc_html__( 'The URL of the sitemap index file.', 'seo-by-rank-math' ),
],
'sitemaps' => [
'type' => 'array',
'description' => esc_html__( 'The active sitemap types, e.g. post types, taxonomies, and the Local SEO sitemap (PRO adds news/video when active).', 'seo-by-rank-math' ),
'items' => [
'type' => 'object',
'properties' => [
'type' => [ 'type' => 'string' ],
'url' => [ 'type' => 'string' ],
'estimated_count' => [ 'type' => 'integer' ],
],
],
],
],
];
}
}
@@ -0,0 +1,79 @@
<?php
/**
* Subscriber for Sitemap abilities.
*
* @since 1.0.277
* @package RankMath
* @subpackage RankMath\Abilities\Sitemap
* @author Rank Math <support@rankmath.com>
*/
namespace RankMath\Abilities\Sitemap;
use RankMath\Traits\Hooker;
use RankMath\Abilities\Subscriber_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Registers the Sitemap ability category and its abilities.
*/
class Subscriber implements Subscriber_Interface {
use Hooker;
/**
* Ability category slug for Sitemap abilities.
*/
const CATEGORY_SLUG = 'rank-math-sitemap';
/**
* Shared meta args.
*
* @var array
*/
private $shared_meta;
/**
* Constructor.
*
* @param array $shared_meta Shared meta args from the top-level Abilities class.
*/
public function __construct( array $shared_meta ) {
$this->shared_meta = $shared_meta;
}
/**
* Wire hooks.
*
* @return void
*/
public function register(): void {
$this->action( 'wp_abilities_api_categories_init', 'register_category' );
$this->action( 'wp_abilities_api_init', 'register_get_sitemap_status' );
}
/**
* Register the Sitemap ability category.
*
* @return void
*/
public function register_category(): void {
\wp_register_ability_category(
self::CATEGORY_SLUG,
[
'label' => esc_html__( 'Sitemap', 'seo-by-rank-math' ),
'description' => esc_html__( 'Abilities to inspect the XML sitemap status.', 'seo-by-rank-math' ),
]
);
}
/**
* Register the rank-math/get-sitemap-status ability.
*
* @return void
*/
public function register_get_sitemap_status(): void {
( new Get_Sitemap_Status( self::CATEGORY_SLUG, $this->shared_meta ) )->register();
}
}
@@ -0,0 +1 @@
<?php // Silence is golden.