WordPress 7.1.3

This commit is contained in:
2026-10-06 18:59:45 -06:00
parent e2c26b7f21
commit 5c09d6fa68
51 changed files with 1111 additions and 825 deletions
@@ -13,8 +13,6 @@ namespace RankMath\CLI;
use WP_CLI;
use WP_CLI_Command;
use RankMath\Helper;
use RankMath\Sitemap\Cache;
use RankMath\Sitemap\Sitemap_XML;
defined( 'ABSPATH' ) || exit;
@@ -35,10 +33,6 @@ class Commands extends WP_CLI_Command {
return;
}
Cache::invalidate_storage();
$generator = new Sitemap_XML( '1' );
$generator->get_output();
WP_CLI::success( 'Sitemap generated.' );
( new Sitemap_WPCLI() )->cache_sitemaps();
}
}
@@ -0,0 +1,225 @@
<?php
/**
* Rank Math sitemap CLI commands.
*
* @since 1.0.280
* @package RankMath
* @subpackage RankMath\WP_CLI
* @author Rank Math <support@rankmath.com>
*/
namespace RankMath\CLI;
use WP_CLI;
use RankMath\Traits\Hooker;
use RankMath\Sitemap\Cache;
defined( 'ABSPATH' ) || exit;
/**
* Class Sitemap_WPCLI.
* Generate sitemap cache files via CLI.
*
* Better used with the filter add_filter( 'rank_math/sitemap/invalidate_storage', '__return_false' );
* so cache files are only deleted and regenerated via WP CLI
*/
class Sitemap_WPCLI extends \RankMath\Sitemap\Generator {
use Hooker;
/**
* Sitemap cache instance.
*
* @var Cache
*/
private $cache;
/**
* Number of sitemaps that could not be generated.
*
* @var int
*/
private $failed = 0;
/**
* Holds index pages discovered through the sitemap/index/entry filter.
* In the form of type (eg post) -> object type (eg product) -> index count.
*
* @var array
*/
public $index_counts = [];
/**
* Disable sitemap redirection.
*
* Sitemap providers call Sitemap::maybe_redirect() while building links, which
* redirects and die()s on the front-end. That must never happen under WP-CLI.
*
* @return false
*/
public function disable_redirect() {
return false;
}
/**
* Force cache invalidation.
*
* Sites are advised to disable automatic invalidation via
* `rank_math/sitemap/invalidate_storage` so caches are only rebuilt from here.
* This runs at PHP_INT_MAX so it reliably wins over such a filter regardless of
* the priority it was registered at.
*
* @param bool $invalidate Whether to invalidate storage.
* @param null|string $type Type of storage to invalidate.
*
* @return true
*/
public function invalidate_storage( $invalidate, $type ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
return true;
}
/**
* Cache sitemaps.
*
* @return void
*/
public function cache_sitemaps() {
$this->filter( 'rank_math/sitemap/invalidate_storage', 'invalidate_storage', PHP_INT_MAX, 2 );
try {
Cache::invalidate_storage();
} finally {
$this->remove_filter( 'rank_math/sitemap/invalidate_storage', 'invalidate_storage', PHP_INT_MAX );
}
$this->filter( 'rank_math/sitemap/maybe_redirect', 'disable_redirect' );
$this->filter( 'rank_math/sitemap/index/entry', 'get_indexes_listener', 100, 3 );
try {
$this->generate_sitemaps();
} finally {
$this->remove_filter( 'rank_math/sitemap/maybe_redirect', 'disable_redirect' );
$this->remove_filter( 'rank_math/sitemap/index/entry', 'get_indexes_listener', 100 );
}
}
/**
* Checks whether a sitemap can be built for the given object type.
*
* A type is buildable when a provider claims it through handles_type() - the
* canonical check used everywhere else in the sitemap code, which already accounts
* for filtered slugs and per-type settings - or when it is contributed purely
* through the `sitemap/{$type}/content` filter, as the Local SEO KML sitemap is.
*
* @param string $object_type The object type to check, eg product or local.
*
* @return bool
*/
protected function is_buildable_type( $object_type ) {
foreach ( $this->providers as $provider ) {
if ( $provider->handles_type( $object_type ) ) {
return true;
}
}
return has_filter( "rank_math/sitemap/{$object_type}/content" );
}
/**
* Listens to the sitemap/index/entry hook and records how many index pages each
* object type has, so the matching sitemaps can be generated afterwards.
*
* Providers do not pass a uniform third argument: post and taxonomy pass the object
* type as a string, author passes a WP_User, video passes an array, while news and
* the Local SEO KML file pass nothing at all. Anything that is not a usable string
* falls back to the provider type, which is also the sitemap slug for those cases.
*
* @param array $item The index URL entry.
* @param string $type The provider type, eg post or term.
* @param mixed $object_type The object type, eg product or category. Not always a string.
*
* @return array
*/
public function get_indexes_listener( $item, $type = '', $object_type = null ) {
$type = 'term' === $type ? 'taxonomy' : $type;
if ( ! is_string( $object_type ) || '' === $object_type ) {
$object_type = $type;
}
if ( '' === $object_type ) {
return $item;
}
if ( ! isset( $this->index_counts[ $type ][ $object_type ] ) ) {
$this->index_counts[ $type ][ $object_type ] = 1;
} else {
++$this->index_counts[ $type ][ $object_type ];
}
return $item;
}
/**
* Generates sitemaps and adds related cache files.
*
* @return void
*/
public function generate_sitemaps() {
$this->cache = new Cache();
$this->failed = 0;
$total_files = 0;
try {
// Saves the rootmap i.e sitemap_index.xml.
$total_files += $this->store( '1', 1, 'index' );
foreach ( $this->index_counts as $items ) {
foreach ( $items as $object_type => $count ) {
if ( ! $this->is_buildable_type( $object_type ) ) {
WP_CLI::warning( sprintf( 'Nothing can build a sitemap for "%s", skipping.', $object_type ) );
continue;
}
$pages = max( 1, $count );
for ( $page = 1; $page <= $pages; $page++ ) {
$total_files += $this->store( $object_type, $page, $object_type );
}
}
}
} catch ( \Throwable $ex ) {
WP_CLI::error( $ex->getMessage() );
}
if ( $this->failed > 0 ) {
WP_CLI::error( sprintf( 'Generated %d sitemap cache file(s), %d failed.', $total_files, $this->failed ) );
}
WP_CLI::success( sprintf( 'Generated %d sitemap cache file(s).', $total_files ) );
}
/**
* Builds a single sitemap and writes it to the cache.
*
* @param string $type Sitemap type, or '1' for the index sitemap.
* @param int $page Page number to generate.
* @param string $label Human readable name used in the CLI output.
*
* @return int 1 when the sitemap was stored, 0 otherwise.
*/
private function store( $type, $page, $label ) {
$sitemap = $this->get_output( $type, $page );
if ( '' === $sitemap ) {
WP_CLI::warning( sprintf( 'Empty output for "%s" page %d, nothing cached.', $label, $page ) );
++$this->failed;
return 0;
}
if ( false === $this->cache->store_sitemap( $type, $page, $sitemap ) ) {
WP_CLI::warning( sprintf( 'Could not cache "%s" page %d.', $label, $page ) );
++$this->failed;
return 0;
}
WP_CLI::log( sprintf( 'Generated sitemap for %s, page %d.', $label, $page ) );
return 1;
}
}
@@ -830,10 +830,12 @@ trait WordPress {
* @return array
*/
public static function filetype_and_ext( $types, $file, $filename ) {
if ( false !== strpos( $filename, '.json' ) ) {
// Validate the real trailing extension so names like `file.json.php` are rejected.
$extension = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) );
if ( 'json' === $extension ) {
$types['ext'] = 'json';
$types['type'] = 'application/json';
} elseif ( false !== strpos( $filename, '.txt' ) ) {
} elseif ( 'txt' === $extension ) {
$types['ext'] = 'txt';
$types['type'] = 'text/plain';
}
@@ -439,6 +439,9 @@ class DB {
return '';
}
$host = Helper::get_home_url();
$url = str_replace( $host, '', $url );
$url = urldecode( preg_replace( '/#.*$/', '', $url ) );
$url = self::remove_hash( $url );
@@ -446,22 +449,18 @@ class DB {
// Parse the URL to get the path component.
$parsed_url = wp_parse_url( $url );
if ( isset( $parsed_url['path'] ) ) {
return $parsed_url['path'];
$page = $parsed_url['path'];
} else {
// Remove ASCII domain. idn_to_ascii() needs ext-intl, which isn't
// guaranteed to be installed on every host — fall back to the
// unconverted host rather than fatal-erroring when it's missing.
$host_ascii = function_exists( 'idn_to_ascii' ) ? idn_to_ascii( $host ) : $host;
$url = str_replace( $host_ascii, '', $url );
$page = preg_replace( '#^https?://(www\.)?#i', '', $url );
}
// Fallback: try to extract path by removing domain.
$host = Helper::get_home_url();
$url = str_replace( $host, '', $url );
// Remove ASCII domain. idn_to_ascii() needs ext-intl, which isn't
// guaranteed to be installed on every host — fall back to the
// unconverted host rather than fatal-erroring when it's missing.
$host_ascii = function_exists( 'idn_to_ascii' ) ? idn_to_ascii( $host ) : $host;
$url = str_replace( $host_ascii, '', $url );
$url = preg_replace( '#^https?://(www\.)?#i', '', $url );
return apply_filters( 'rank_math/analytics/get_page', $url );
return apply_filters( 'rank_math/analytics/get_page', $page );
}
/**
@@ -61,8 +61,9 @@ class Objects extends Summary {
'noData' => $request->get_param( 'noData' ),
];
$field_name = 'seo_score';
$per_page = $request->get_param( 'per_page' ) ? sanitize_text_field( $request->get_param( 'per_page' ) ) : 25;
$offset = ( sanitize_text_field( $request->get_param( 'page' ) ) - 1 ) * $per_page;
$per_page = absint( $request->get_param( 'per_page' ) );
$per_page = $per_page ? min( $per_page, 100 ) : 25;
$offset = ( max( 1, absint( $request->get_param( 'page' ) ) ) - 1 ) * $per_page;
// Construct SQL condition based on filter parameters.
$conditions = [];
@@ -48,6 +48,20 @@ class Rest extends WP_REST_Controller {
],
'postsRowsByObjects' => [
'callback' => [ Stats::get(), 'get_posts_rows_by_objects' ],
'args' => [
'page' => [
'description' => esc_html__( 'Page number.', 'seo-by-rank-math' ),
'type' => 'integer',
'required' => false,
'sanitize_callback' => 'absint',
],
'per_page' => [
'description' => esc_html__( 'Results per page.', 'seo-by-rank-math' ),
'type' => 'integer',
'required' => false,
'sanitize_callback' => 'absint',
],
],
],
'post/(?P<id>\d+)' => [
'callback' => [ $this, 'get_post' ],
@@ -250,7 +250,7 @@ class Table extends List_Table {
'deactivate' => '<a href="' . $url . '" data-action="deactivate" class="rank-math-redirection-action">' . esc_html__( 'Deactivate', 'seo-by-rank-math' ) . '</a>',
'activate' => '<a href="' . $url . '" data-action="activate" class="rank-math-redirection-action">' . esc_html__( 'Activate', 'seo-by-rank-math' ) . '</a>',
'trash' => '<a href="' . $url . '" data-action="trash" class="rank-math-redirection-action">' . esc_html__( 'Trash', 'seo-by-rank-math' ) . '</a>',
'view' => '<a href="' . $view_url . '" rel="bookmark">' . esc_html__( 'View', 'seo-by-rank-math' ) . '</a>',
'view' => '<a href="' . esc_url( $view_url ) . '" rel="bookmark">' . esc_html__( 'View', 'seo-by-rank-math' ) . '</a>',
]
);
}
@@ -58,8 +58,11 @@ class DB {
'usermeta' => 'user_id',
];
$key = isset( $keys_by_table[ $table ] ) ? $keys_by_table[ $table ] : 'post_id';
$data = self::table( $table )
->select( 'meta_id' )
// The wp_usermeta table's primary key column is umeta_id, unlike post/term/comment meta tables which use meta_id.
$id_column = 'usermeta' === $table ? 'umeta_id' : 'meta_id';
$data = self::table( $table )
->select( [ $id_column => 'meta_id' ] )
->select( 'meta_value' )
->where( $key, $object_id )
->whereLike( 'meta_key', 'rank_math_schema', '' )
@@ -89,7 +89,7 @@ class SEO_Analyzer {
$this->analyse_url = home_url();
$this->action( 'init', 'set_url' );
$this->maybe_clear_storage();
$this->action( 'admin_init', 'maybe_clear_storage' );
$this->ajax( 'analyze', 'analyze_me' );
$this->ajax( 'enable_auto_update', 'enable_auto_update' );
@@ -235,13 +235,22 @@ class SEO_Analyzer {
/**
* Clear stored results if needed.
*/
private function maybe_clear_storage() {
if ( '1' === Param::request( 'clear_results' ) ) {
delete_option( 'rank_math_seo_analysis_results' );
delete_option( 'rank_math_seo_analysis_date' );
Helper::redirect( Security::remove_query_arg_raw( 'clear_results' ) );
exit;
public function maybe_clear_storage() {
if ( '1' !== Param::request( 'clear_results' ) ) {
return;
}
if (
! Helper::has_cap( 'site_analysis' ) ||
! wp_verify_nonce( Param::request( 'security' ), 'rank-math-ajax-nonce' )
) {
return;
}
delete_option( 'rank_math_seo_analysis_results' );
delete_option( 'rank_math_seo_analysis_date' );
Helper::redirect( Security::remove_query_arg_raw( [ 'clear_results', 'security' ] ) );
exit;
}
/**
@@ -307,6 +307,9 @@ class Sitemap {
* @param int $max_entries Entries per sitemap.
*/
public static function maybe_redirect( $count, $max_entries ) {
if ( ! apply_filters( 'rank_math/sitemap/maybe_redirect', true ) ) {
return;
}
$current_page = (int) get_query_var( 'sitemap_n' );
if ( ! $current_page && $count > $max_entries ) {
Helper::redirect( preg_replace( '/\.xml$/', '1.xml', Helper::get_current_page_url() ) );
@@ -50,6 +50,7 @@ class Import_Export_Settings {
// Parse Options.
$wp_filesystem = Helper::get_filesystem();
if ( is_null( $wp_filesystem ) || ! Helper::is_filesystem_direct() ) {
\wp_delete_file( $file['file'] );
return [
'error' => esc_html__( 'Uploaded file could not be read.', 'seo-by-rank-math' ),
];
@@ -2,14 +2,14 @@
# This file is distributed under the GPL-3.0+.
msgid ""
msgstr ""
"Project-Id-Version: Rank Math SEO 1.0.279\n"
"Project-Id-Version: Rank Math SEO 1.0.280\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/seo-by-rank-math\n"
"Last-Translator: Rank Math <support@rankmath.com>\n"
"Language-Team: Rank Math <support@rankmath.com>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2026-09-22T04:13:08+00:00\n"
"POT-Creation-Date: 2026-10-06T05:13:11+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.12.0\n"
"X-Domain: seo-by-rank-math\n"
@@ -3152,18 +3152,18 @@ msgstr ""
msgid "Unknown error, call get_response() to find out what happened."
msgstr ""
msgid "Post ID."
msgstr ""
msgid "Post Type."
msgstr ""
msgid "Page number."
msgstr ""
msgid "Results per page."
msgstr ""
msgid "Post ID."
msgstr ""
msgid "Post Type."
msgstr ""
msgid "Order by."
msgstr ""
@@ -9,7 +9,7 @@
*
* @wordpress-plugin
* Plugin Name: Rank Math SEO
* Version: 1.0.279
* Version: 1.0.280
* Plugin URI: https://rankmath.com/
* Description: Rank Math SEO is the Best WordPress SEO plugin with the features of many SEO and AI SEO tools in a single package to help multiply your SEO traffic.
* Author: Rank Math SEO
@@ -34,7 +34,7 @@ final class RankMath {
*
* @var string
*/
public $version = '1.0.279';
public $version = '1.0.280';
/**
* Rank Math database version.
@@ -422,8 +422,8 @@ final class RankMath {
new \RankMath\ThirdParty\WPML();
}
// Hook into `pll_init` when Polylang is active, unless the manual KB integration is already enabled.
if ( is_plugin_active( 'polylang/polylang.php' ) && ! class_exists( 'PLL_RankMath' ) ) {
// Hook into `pll_init` when Polylang (Free or Pro) is active, unless the manual KB integration is already enabled.
if ( ( is_plugin_active( 'polylang/polylang.php' ) || is_plugin_active( 'polylang-pro/polylang.php' ) ) && ! class_exists( 'PLL_RankMath' ) ) {
new \RankMath\ThirdParty\Polylang\Polylang();
}
@@ -5,7 +5,7 @@ Tags: seo, google search console, schema, redirection, xml sitemap
Tested up to: 7.1
Requires at least: 6.7
Requires PHP: 7.4
Stable tag: 1.0.279
Stable tag: 1.0.280
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.txt
@@ -428,14 +428,12 @@ Terms of service: https://developers.facebook.com/terms/
== Changelog ==
= 1.0.279 [Sep 22, 2026] =
- [HUGE!] Added Gemini Tracking, Multi-Language Support, and Daily/Weekly/Monthly refresh options to [AI Visibility] (https://rankmath.com/ai-visibility/?play-video=gS5-DFQrSxs).
- Added `rank-math/get-404-logs` and `rank-math/get-sitemap-status` MCP tools to expose [404 Monitor](https://rankmath.com/kb/monitor-404-errors/) log data and sitemap status/sub-type data to AI assistants.
- Improved [llms.txt](https://rankmath.com/kb/llms-txt/) output to conform to the latest llms.txt specification.
- Fixed AI Visibility Brand detail page was missing data shown on the dashboard, and the "Analyses in last 24h" label was misleading.
- Fixed `rank-math/get-post-links` MCP tool to correctly enforce per-post capability checks.
- Fixed Link Suggestions was building link HTML by unescaped string concatenation, allowing unsafe URL and link text values into block content.
- Fixed Analytics Objects table `page` column was not showing accurate values for WPML translated pages.
= 1.0.280 [Oct 06, 2026] =
- Improved [Sitemaps](https://rankmath.com/kb/configure-sitemaps/) can now be fully pre-generated with the `wp rankmath sitemap generate` WP-CLI command, so large sites serve cached sitemap files instead of building them on every visit.
- Improved plugin security with additional input validation and output escaping hardening.
- Fixed [Analytics](https://rankmath.com/kb/analytics/) dashboard sections showing `N/A` after data fetching was completed.
- Fixed [Polylang](https://rankmath.com/kb/polylang-compatibility/) meta translations that were not showing for secondary languages when Polylang PRO was active.
- Fixed a database error being logged when saving user profiles with SEO Controls enabled for [Author Archives](https://rankmath.com/kb/titles-and-meta/#author-archives).
Full changelog can be found here - **[Rank Math changelog](https://rankmath.com/changelog/?utm_source=Plugin&utm_medium=Changelog&utm_campaign=WP)**
+1 -1
View File
@@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitda5118e07739bcc2a9ee8b03eeea8972::getLoader();
return ComposerAutoloaderInit1a6db0eae96225599b2819e07037bb60::getLoader();
@@ -1,167 +0,0 @@
# CMB2 Conventions & Blast-Radius Notes
CMB2 is an opinionated, 10+-year-old library bundled inside hundreds of themes
and plugins. This file is the compounding knowledge base of its conventions,
architectural seams, and back-compat blast radii — written for both human
contributors and AI agents.
**Reading rule:** consult this file before changing anything under `includes/`,
`bootstrap.php`, or `init.php`.
**Capture rule:** when a code review catches a convention violation or a
back-compat near-miss, the fix must land alongside a new or updated entry here,
on the same branch. Each entry cites the canonical in-code example — the code
is the spec; this file is the index to it.
**Delegation rule (AI agents):** subagents don't inherit this context. Work
orders delegating changes must quote the relevant entries verbatim.
---
## C1 — Per-box features hook up via `cmb2_init_hookup_{$cmb_id}`
**Rule:** A feature that attaches to boxes (hookup, REST, notices, anything
box-aware) registers a `maybe_init_and_hookup( CMB2 $cmb )` static on the
box-specific `cmb2_init_hookup_{$cmb_id}` action, added in the `CMB2`
constructor. The feature class *self-guards*: it receives every box and decides
for itself whether it applies (e.g. `CMB2_REST` checks `show_in_rest`).
**Canonical example:** `includes/CMB2.php` constructor (the
`CMB2_Hookup`/`CMB2_REST` `add_action` pair); fired from `bootstrap.php`'s
`cmb2_init_hookup_{$cmb->cmb_id}` loop; contract in
`CMB2_Hookup_Base::maybe_init_and_hookup()`.
**Anti-pattern:** registering a global hook elsewhere and scanning
`CMB2_Boxes::get_all()` to find relevant boxes. Two sources of truth for
"which boxes does this apply to", misses late-registered boxes, and bypasses
the per-box action seam developers use to unhook features from a single box.
**Blast radius:** extenders unhook/re-order `cmb2_init_hookup_*` callbacks per
box; a feature wired outside that seam won't respect their customizations.
## C2 — `bootstrap.php` is generic lifecycle only
**Rule:** `bootstrap.php` contains only the init ceremony: `do_action` /
`apply_filters` lifecycle events and the box-instantiation loops. No
feature-specific class references, ever. Feature wiring belongs in the `CMB2`
constructor (per-box features, see C1) or in the feature's own file.
**Canonical example:** `bootstrap.php` — note it ends "End. That's it, folks!"
and has barely changed since 2.2.0.
## C3 — The self-electing loader makes every behavior change site-wide
**Rule:** `init.php` version-elects: when multiple copies of CMB2 are bundled
(themes + plugins commonly each ship one), the *newest* copy wins and serves
ALL registered boxes on the site. Any default-behavior change therefore
propagates to every bundling product the moment one of them updates.
**Consequence:** behavior flips ship staged — opt-in first (default-off filter
+ notice + docs), default-on only in a later release. Never flip a default in
the same release that introduces the switch.
**Canonical example:** `init.php` (the `CMB2_Bootstrap_*` priority dance);
staged-rollout example: the `cmb2_rest_enforce_options_page_read_permissions`
filter (default false).
## C4 — REST reads are public by design; permission filters are the escape hatch
**Rule:** Boxes with `show_in_rest` readable expose reads publicly — this
mirrors WP core's `show_in_rest` semantics for object meta and is intentional,
not an oversight. Per-request overrides go through the existing
`cmb2_api_get_box_permissions_check` / `cmb2_api_get_field_permissions_check`
filters, which always run last and have final say. New permission logic must
run *before* them and must not remove them.
**Canonical example:** `CMB2_REST_Controller_Boxes::get_item_permissions_check_filter()`;
pinned by tests in `tests/test-cmb-rest-controllers.php`.
**Blast radius:** headless/decoupled front-ends read box data anonymously for
public display. Tightening reads by default breaks them — hence the staged
approach in C3, scoped only to options-page boxes (matching core's
settings-vs-meta distinction).
## C5 — The `capability` box prop means "who sees the admin screen"
**Rule:** `capability` (default `manage_options` for options pages) governs the
admin page. Reusing it for other gates (REST, front-end) conflates concerns —
acceptable only where the semantic genuinely matches (e.g. options-page REST
reads mirror the settings screen), and even then behind its own switch.
**Canonical example:** `includes/CMB2.php` `$mb_defaults['capability']` usage in
`CMB2_Options_Hookup`.
**Where the semantic does match:** an options-page target's *object id is the
option name* the data lands in, so "may write this option" and "may use this
settings screen" are the same question — see
`CMB2_Ajax::can_cache_for_options_page()`. Note the shape: the box that
declared the option key is also the only place a capability for it exists, so
looking the box up both supplies the check and bounds the accepted option keys
to ones a box declared. An id no box claims has no capability to consult, and
is therefore not a target.
## C6 — Autoloader paths are case-sensitive by prefix
**Rule:** `cmb2_autoload_classes()` maps `CMB2_REST`/`CMB2_REST_*` (exact case)
to `includes/rest-api/`, `CMB2_Type*` to `includes/types/`, everything else to
`includes/`. A class named `CMB2_Rest_Foo` (lowercase "est") deliberately lands
in `includes/` — name classes with full awareness of which directory the prefix
routes to, and match filename to class name exactly.
**Canonical example:** `includes/helper-functions.php` `cmb2_autoload_classes()`.
## C7 — PHP floor is 7.4; local tests don't prove it
**Rule:** All code must run on PHP 7.4. Local `npm run phptests` runs PHP 8.3
only; the 7.4 floor is guarded exclusively by the CI matrix (`phpunit.yml`).
"Passes locally" is necessary, never sufficient. (Tooling details: CLAUDE.md
"Testing Strategy".)
## C8 — Configuration over code: box props are the primary interface
**Rule:** A new per-box behavior must be reachable as a **box registration
property**. The registration array is the interface CMB2 developers actually
use — and the one a bundling theme/plugin can ship per box — so it is the
primary layer; filters are the secondary, site-wide layer for cross-cutting
policy. When a behavior has both, the box prop wins outright and the filter
governs only the boxes that left the prop unset. That way a box declares its
intent once, in the array where it was registered, and keeps it across a later
default flip (C3).
**Canonical examples:** `includes/CMB2.php` `$mb_defaults` — `show_in_rest`,
`capability`, and `rest_read_capability`. The last one is the shape to copy,
reading exactly as plain English: `false` = "no" (REST reads disabled for
everyone, via core's `do_not_allow`); `true` = "yes, everyone" (alias of
`'exist'`, the capability WP grants every visitor); `'box-capability'` = the
box's own `capability` prop (the only non-duplicating spelling — naming the cap
copies a value that lives elsewhere and can drift); any other capability string
= only its holders; unset = the default policy (and the staged flip, C3). It
cascades field → box → default like `show_in_rest`. Precedence is resolved in one
place, `CMB2_REST::get_rest_read_capability()`, and consumed by
`CMB2_REST_Controller::maybe_gate_read_by_capability()`.
**Value semantics — a prop value must read correctly in plain English.** A
config value is documentation; if its plain-English reading is ambiguous or
contradicts its behavior, it's the wrong value. `rest_read_capability` went
through this exact wringer: `false` originally meant "reads are public (no
capability required)" — but it *reads* as "REST read capability? no", i.e.
reads disabled. The fix wasn't banning the boolean; it was making the meaning
match the reading (`false` now disables reads; `true` now means everyone).
Corollaries: booleans are fine only when yes/no is the honest answer to the
prop's name read as a question; when the answer is a *which* (which
capability?), every value is a real answer; and prefer WP-canonical vocabulary
over invented sentinels — `'exist'` (granted to everyone) and `do_not_allow`
(denied to everyone) bound the range, so neither "public" nor "disabled" needs
special-casing.
**Anti-pattern:** shipping a filter-only interface for per-box behavior. It
forces every developer to write a callback that re-derives "which box is this?"
from the filter args, cannot be expressed in the registration array a theme or
plugin already ships, and leaves no way to declare per-box intent — the filter
answers site-wide, so a site with a single box needing the old behavior has to
special-case every box by hand.
**Blast radius:** props are public API forever — name them for the behavior,
not the implementation. Adding one to `$mb_defaults` also changes the array
pinned by `Test_CMB2_Core::test_defaults_set()`; update that fixture in the same
commit.
@@ -1,5 +1,5 @@
/*!
* CMB2 - v2.13.0 - 2026-09-20
* CMB2 - v2.13.3 - 2026-10-03
* https://cmb2.io
* Copyright (c) 2026
* Licensed GPLv2+
@@ -1,6 +1,6 @@
/*! CMB2 - v2.13.0 - 2026-09-20 | https://cmb2.io | Copyright (c) 2026 CMB2 team | Licensed GPLv2 */
/*! CMB2 - v2.13.3 - 2026-10-03 | https://cmb2.io | Copyright (c) 2026 CMB2 team | Licensed GPLv2 */
/*!
* CMB2 - v2.13.0 - 2026-09-20
* CMB2 - v2.13.3 - 2026-10-03
* https://cmb2.io
* Copyright (c) 2026
* Licensed GPLv2+
@@ -1,5 +1,5 @@
/*!
* CMB2 - v2.13.0 - 2026-09-20
* CMB2 - v2.13.3 - 2026-10-03
* https://cmb2.io
* Copyright (c) 2026
* Licensed GPLv2+
@@ -1,6 +1,6 @@
/*! CMB2 - v2.13.0 - 2026-09-20 | https://cmb2.io | Copyright (c) 2026 CMB2 team | Licensed GPLv2 */
/*! CMB2 - v2.13.3 - 2026-10-03 | https://cmb2.io | Copyright (c) 2026 CMB2 team | Licensed GPLv2 */
/*!
* CMB2 - v2.13.0 - 2026-09-20
* CMB2 - v2.13.3 - 2026-10-03
* https://cmb2.io
* Copyright (c) 2026
* Licensed GPLv2+
@@ -169,7 +169,7 @@ class CMB2_Field_Display {
* @since 2.2.2
*/
protected function _display() {
print_r( $this->value );
echo esc_html( print_r( $this->value, true ) );
}
}
@@ -192,7 +192,7 @@ class CMB2_Display_Text_Money extends CMB2_Field_Display {
*/
protected function _display() {
$this->value = $this->value ? $this->value : '0';
echo ( ! $this->field->get_param_callback_result( 'before_field' ) ? '$' : ' ' ), $this->value;
echo ( ! $this->field->get_param_callback_result( 'before_field' ) ? '$' : ' ' ), esc_html( print_r( $this->value, true ) );
}
}
@@ -285,7 +285,8 @@ class CMB2_Display_Textarea_Code extends CMB2_Field_Display {
* @since 2.2.2
*/
protected function _display() {
echo '<xmp class="cmb2-code">' . print_r( $this->value, true ) . '</xmp>';
// Double-encode entities so the browser displays the stored source literally inside <pre>.
echo '<pre class="cmb2-code">', htmlspecialchars( print_r( $this->value, true ), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8' ), '</pre>';
}
}
@@ -476,6 +477,10 @@ class CMB2_Display_File_List extends CMB2_Display_File {
echo '<ul class="cmb2-display-file-list">';
foreach ( $this->value as $id => $fullurl ) {
if ( ! is_scalar( $fullurl ) ) {
continue;
}
echo '<li>', $this->file_output( esc_url_raw( $fullurl ), $id, $type ), '</li>';
}
echo '</ul>';
@@ -59,7 +59,10 @@ class CMB2_Options_Hookup extends CMB2_Hookup {
}
// Register setting to cmb2 group.
register_setting( 'cmb2', $this->option_key );
register_setting( 'cmb2', $this->option_key, array(
'type' => 'array',
'sanitize_callback' => 'cmb2_sanitize_option_passthrough',
) );
// Handle saving the data.
add_action( 'admin_post_' . $this->option_key, array( $this, 'save_options' ) );
@@ -97,11 +97,24 @@ class CMB2_Sanitize {
break;
case 'multicheck':
case 'multicheck_inline':
case 'file_list':
case 'group':
// no filtering
$sanitized_value = $this->value;
break;
case 'file_list':
$sanitized_value = array();
$protocols = $this->field->args( 'protocols' );
foreach ( (array) $this->value as $attachment_id => $url ) {
if ( ! is_int( $attachment_id ) || $attachment_id < 1 || ! is_scalar( $url ) ) {
continue;
}
$url = self::sanitize_and_secure_url( $url, $protocols, '' );
if ( '' !== $url ) {
$sanitized_value[ $attachment_id ] = $url;
}
}
break;
default:
// Handle repeatable fields array
// We'll fallback to 'sanitize_text_field'
@@ -448,7 +461,11 @@ class CMB2_Sanitize {
return $repeat_value;
}
return htmlspecialchars_decode( stripslashes( $this->value ), ENT_COMPAT );
if ( ! is_scalar( $this->value ) ) {
return '';
}
return htmlspecialchars_decode( stripslashes( (string) $this->value ), ENT_COMPAT );
}
/**
@@ -425,3 +425,22 @@ if ( ! function_exists( 'date_timestamp_get' ) ) {
return $date->format( 'U' );
}
}// End if.
/**
* Passthrough sanitize_callback for the option CMB2_Options_Hookup registers.
*
* Deliberately a passthrough. Each value is sanitized by CMB2_Sanitize on the
* way in, per field type, before the option array is assembled — re-sanitizing
* the assembled array here would apply one field type's rule to all of them.
* The callback exists so register_setting() has one, which wp.org's Plugin
* Check requires of every registered setting.
*
* @since 2.13.1
*
* @param mixed $value The option value, already sanitized per-field.
*
* @return mixed The unmodified value.
*/
function cmb2_sanitize_option_passthrough( $value ) {
return $value;
}
@@ -340,16 +340,100 @@ abstract class CMB2_REST_Controller extends WP_REST_Controller {
} else {
if ( isset( $this->request['object_id'] ) ) {
$this->rest_box->cmb->object_id( sanitize_text_field( $this->request['object_id'] ) );
$object_id = isset( $this->request['object_id'] ) ? sanitize_text_field( $this->request['object_id'] ) : null;
$object_type = isset( $this->request['object_type'] ) ? sanitize_text_field( $this->request['object_type'] ) : null;
$error = $this->validate_request_object( $object_type, $object_id );
if ( is_wp_error( $error ) ) {
$this->rest_box = $error;
return;
}
if ( isset( $this->request['object_type'] ) ) {
$this->rest_box->cmb->object_type( sanitize_text_field( $this->request['object_type'] ) );
if ( null !== $object_id ) {
$this->rest_box->cmb->object_id( $object_id );
}
if ( null !== $object_type ) {
$this->rest_box->cmb->object_type( $object_type );
}
}
}
/**
* Validates the requested object_type/object_id against the box's registration.
*
* The requested object_type selects the storage the box reads from and writes
* to, so it has to be a storage type the box was registered for. For the
* options-page type, the object_id is the option name, so it has to be one of
* the box's own option keys. This is request validation, so it is applied
* regardless of the permissions filters.
*
* @since 2.13.3
*
* @param string|null $object_type The requested object type, if any.
* @param string|null $object_id The requested object id, if any.
*
* @return true|WP_Error True if valid, or a WP_Error.
*/
protected function validate_request_object( $object_type, $object_id ) {
if ( null === $object_type || '' === $object_type ) {
return true;
}
$cmb = $this->rest_box->cmb;
if ( ! in_array( $object_type, $this->get_box_storage_types( $cmb ), true ) ) {
return new WP_Error( 'cmb2_rest_invalid_object_type', __( 'The object_type parameter does not match an object type this box is registered for.', 'cmb2' ), array(
'status' => 400,
) );
}
if (
'options-page' === $object_type
&& null !== $object_id
&& '' !== $object_id
&& ! in_array( $object_id, array_map( 'strval', (array) $cmb->options_page_keys() ), true )
) {
return new WP_Error( 'cmb2_rest_invalid_object_id', __( 'The object_id parameter does not match an option key this box is registered for.', 'cmb2' ), array(
'status' => 400,
) );
}
return true;
}
/**
* Gets the storage object types for a box's registered object types.
*
* Registered types that are not core object types (post types) store as 'post',
* matching CMB2::mb_object_type().
*
* @since 2.13.3
*
* @param CMB2 $cmb The box.
*
* @return array The storage object types.
*/
protected function get_box_storage_types( CMB2 $cmb ) {
$types = array();
if ( $cmb->is_options_page_mb() ) {
$types[] = 'options-page';
}
foreach ( $cmb->box_types( array( 'post' ) ) as $type ) {
$types[] = $cmb->is_supported_core_object_type( $type ) ? $type : 'post';
}
// A non-core type from the `cmb2_set_box_object_type` filter is the box's own declaration.
$mb_object_type = $cmb->mb_object_type();
if ( ! $cmb->is_supported_core_object_type( $mb_object_type ) ) {
$types[] = $mb_object_type;
}
return array_unique( $types );
}
/**
* Initiates the request property and sets up the initial static properties.
*
@@ -329,9 +329,9 @@ class CMB2_REST_Controller_Fields extends CMB2_REST_Controller_Boxes {
? $this->field->remove_data()
: $this->field->save_field( $this->request['value'] );
// If options page, save the $activity options
if ( 'options-page' == $this->request['object_type'] ) {
$this->field->args[ "value_{$activity}" ] = cmb2_options( $this->request['object_id'] )->set();
// If options page, save the $activity options to the validated option key.
if ( 'options-page' === $this->rest_box->cmb->object_type() ) {
$this->field->args[ "value_{$activity}" ] = cmb2_options( $this->rest_box->cmb->object_id() )->set();
}
return $this->prepare_read_field( $this->field );
@@ -17,6 +17,7 @@ class CMB2_Type_File_List extends CMB2_Type_File_Base {
$meta_value = $field->escaped_value();
$name = $this->_name();
$img_size = $field->args( 'preview_size' );
$protocols = $field->args( 'protocols' );
$query_args = $field->args( 'query_args' );
$output = '';
@@ -48,9 +49,18 @@ class CMB2_Type_File_List extends CMB2_Type_File_Base {
if ( $meta_value && is_array( $meta_value ) ) {
foreach ( $meta_value as $id => $fullurl ) {
if ( ! is_int( $id ) || $id < 1 || ! is_scalar( $fullurl ) ) {
continue;
}
$fullurl = CMB2_Sanitize::sanitize_and_secure_url( (string) $fullurl, $protocols, '' );
if ( '' === $fullurl ) {
continue;
}
$id_input = parent::render( array(
'type' => 'hidden',
'value' => $fullurl,
'value' => esc_attr( $fullurl ),
'name' => $name . '[' . $id . ']',
'id' => 'filelist-' . $id,
'data-id' => $id,
+10 -10
View File
@@ -20,7 +20,7 @@
* Bill Erickson (@billerickson / billerickson.net)
* Andrew Norcross (@norcross / andrewnorcross.com)
*
* Version: 2.13.0
* Version: 2.13.3
*
* Text Domain: cmb2
* Domain Path: languages
@@ -53,7 +53,7 @@
* ***********************************************************************
*/
if ( ! class_exists( 'CMB2_Bootstrap_2130', false ) ) {
if ( ! class_exists( 'CMB2_Bootstrap_2133', false ) ) {
/**
* Handles checking for and loading the newest version of CMB2
@@ -66,7 +66,7 @@ if ( ! class_exists( 'CMB2_Bootstrap_2130', false ) ) {
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Bootstrap_2130 {
class CMB2_Bootstrap_2133 {
/**
* Current version number
@@ -74,7 +74,7 @@ if ( ! class_exists( 'CMB2_Bootstrap_2130', false ) ) {
* @var string
* @since 1.0.0
*/
const VERSION = '2.13.0';
const VERSION = '2.13.3';
/**
* Current version hook priority.
@@ -83,20 +83,20 @@ if ( ! class_exists( 'CMB2_Bootstrap_2130', false ) ) {
* @var int
* @since 2.0.0
*/
const PRIORITY = 9955;
const PRIORITY = 9952;
/**
* Single instance of the CMB2_Bootstrap_2130 object
* Single instance of the CMB2_Bootstrap_2133 object
*
* @var CMB2_Bootstrap_2130
* @var CMB2_Bootstrap_2133
*/
public static $single_instance = null;
/**
* Creates/returns the single instance CMB2_Bootstrap_2130 object
* Creates/returns the single instance CMB2_Bootstrap_2133 object
*
* @since 2.0.0
* @return CMB2_Bootstrap_2130 Single instance object
* @return CMB2_Bootstrap_2133 Single instance object
*/
public static function initiate() {
if ( null === self::$single_instance ) {
@@ -192,6 +192,6 @@ if ( ! class_exists( 'CMB2_Bootstrap_2130', false ) ) {
}
// Make it so...
CMB2_Bootstrap_2130::initiate();
CMB2_Bootstrap_2133::initiate();
}// End if().
@@ -152,6 +152,7 @@ return array(
'RankMath\\BuddyPress\\Admin' => $baseDir . '/includes/modules/buddypress/class-admin.php',
'RankMath\\BuddyPress\\BuddyPress' => $baseDir . '/includes/modules/buddypress/class-buddypress.php',
'RankMath\\CLI\\Commands' => $baseDir . '/includes/cli/class-commands.php',
'RankMath\\CLI\\Sitemap_WPCLI' => $baseDir . '/includes/cli/class-sitemap-wpcli.php',
'RankMath\\CMB2' => $baseDir . '/includes/class-cmb2.php',
'RankMath\\Common' => $baseDir . '/includes/class-common.php',
'RankMath\\Compatibility' => $baseDir . '/includes/class-compatibility.php',
@@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitda5118e07739bcc2a9ee8b03eeea8972
class ComposerAutoloaderInit1a6db0eae96225599b2819e07037bb60
{
private static $loader;
@@ -24,18 +24,18 @@ class ComposerAutoloaderInitda5118e07739bcc2a9ee8b03eeea8972
require __DIR__ . '/platform_check.php';
spl_autoload_register(array('ComposerAutoloaderInitda5118e07739bcc2a9ee8b03eeea8972', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit1a6db0eae96225599b2819e07037bb60', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitda5118e07739bcc2a9ee8b03eeea8972', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit1a6db0eae96225599b2819e07037bb60', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitda5118e07739bcc2a9ee8b03eeea8972::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit1a6db0eae96225599b2819e07037bb60::getInitializer($loader));
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInitda5118e07739bcc2a9ee8b03eeea8972::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInit1a6db0eae96225599b2819e07037bb60::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequireda5118e07739bcc2a9ee8b03eeea8972($fileIdentifier, $file);
composerRequire1a6db0eae96225599b2819e07037bb60($fileIdentifier, $file);
}
return $loader;
@@ -47,7 +47,7 @@ class ComposerAutoloaderInitda5118e07739bcc2a9ee8b03eeea8972
* @param string $file
* @return void
*/
function composerRequireda5118e07739bcc2a9ee8b03eeea8972($fileIdentifier, $file)
function composerRequire1a6db0eae96225599b2819e07037bb60($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
@@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInitda5118e07739bcc2a9ee8b03eeea8972
class ComposerStaticInit1a6db0eae96225599b2819e07037bb60
{
public static $files = array (
'6c592737b91137905268e9a0eb968869' => __DIR__ . '/..' . '/wp-media/apply-filters-typed/functions.php',
@@ -198,6 +198,7 @@ class ComposerStaticInitda5118e07739bcc2a9ee8b03eeea8972
'RankMath\\BuddyPress\\Admin' => __DIR__ . '/../..' . '/includes/modules/buddypress/class-admin.php',
'RankMath\\BuddyPress\\BuddyPress' => __DIR__ . '/../..' . '/includes/modules/buddypress/class-buddypress.php',
'RankMath\\CLI\\Commands' => __DIR__ . '/../..' . '/includes/cli/class-commands.php',
'RankMath\\CLI\\Sitemap_WPCLI' => __DIR__ . '/../..' . '/includes/cli/class-sitemap-wpcli.php',
'RankMath\\CMB2' => __DIR__ . '/../..' . '/includes/class-cmb2.php',
'RankMath\\Common' => __DIR__ . '/../..' . '/includes/class-common.php',
'RankMath\\Compatibility' => __DIR__ . '/../..' . '/includes/class-compatibility.php',
@@ -748,9 +749,9 @@ class ComposerStaticInitda5118e07739bcc2a9ee8b03eeea8972
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitda5118e07739bcc2a9ee8b03eeea8972::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitda5118e07739bcc2a9ee8b03eeea8972::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitda5118e07739bcc2a9ee8b03eeea8972::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit1a6db0eae96225599b2819e07037bb60::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit1a6db0eae96225599b2819e07037bb60::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit1a6db0eae96225599b2819e07037bb60::$classMap;
}, null, ClassLoader::class);
}
@@ -55,17 +55,17 @@
},
{
"name": "cmb2/cmb2",
"version": "v2.13.0",
"version_normalized": "2.13.0.0",
"version": "v2.13.3",
"version_normalized": "2.13.3.0",
"source": {
"type": "git",
"url": "https://github.com/CMB2/CMB2.git",
"reference": "06783dbfdde0f23e89e088652451525d07bcd03a"
"reference": "0f2498434d97876f6f141fa1de99c8ec87840a4a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/CMB2/CMB2/zipball/06783dbfdde0f23e89e088652451525d07bcd03a",
"reference": "06783dbfdde0f23e89e088652451525d07bcd03a",
"url": "https://api.github.com/repos/CMB2/CMB2/zipball/0f2498434d97876f6f141fa1de99c8ec87840a4a",
"reference": "0f2498434d97876f6f141fa1de99c8ec87840a4a",
"shasum": ""
},
"require": {
@@ -78,7 +78,7 @@
"suggest": {
"composer/installers": "~1.0"
},
"time": "2026-09-21T01:10:54+00:00",
"time": "2026-10-03T19:02:06+00:00",
"type": "wordpress-plugin",
"installation-source": "dist",
"notification-url": "https://packagist.org/downloads/",
@@ -1,9 +1,9 @@
<?php return array(
'root' => array(
'name' => 'rankmath/seo-by-rank-math',
'pretty_version' => 'v1.0.279',
'version' => '1.0.279.0',
'reference' => 'f9c63fe7ff6c3cf2d90470a6a60b2fbcfbd48f99',
'pretty_version' => 'v1.0.280',
'version' => '1.0.280.0',
'reference' => '5f39f15d5bba2cc2e2134ec52bb55272fff3042b',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@@ -20,9 +20,9 @@
'dev_requirement' => false,
),
'cmb2/cmb2' => array(
'pretty_version' => 'v2.13.0',
'version' => '2.13.0.0',
'reference' => '06783dbfdde0f23e89e088652451525d07bcd03a',
'pretty_version' => 'v2.13.3',
'version' => '2.13.3.0',
'reference' => '0f2498434d97876f6f141fa1de99c8ec87840a4a',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../cmb2/cmb2',
'aliases' => array(),
@@ -38,9 +38,9 @@
'dev_requirement' => false,
),
'rankmath/seo-by-rank-math' => array(
'pretty_version' => 'v1.0.279',
'version' => '1.0.279.0',
'reference' => 'f9c63fe7ff6c3cf2d90470a6a60b2fbcfbd48f99',
'pretty_version' => 'v1.0.280',
'version' => '1.0.280.0',
'reference' => '5f39f15d5bba2cc2e2134ec52bb55272fff3042b',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),