| @@ -14,9 +14,10 @@ | ||
| 14 | 14 | * @wordpress-plugin |
| 15 | 15 | * Plugin Name: Search Atlas: The Premier AI SEO Plugin for Instant Optimization |
| 16 | 16 | * Plugin URI: https://searchatlas.com/ |
| 17 | 17 | * Description: Search Atlas SEO is an intuitive WordPress Plugin that transforms the most complicated, most labor-intensive SEO tasks into streamlined, straightforward processes. With a few clicks, the meta-bulk update feature automates the re-optimization of meta tags using AI to increase clicks. Stay up-to-date with the freshest Google Search data for your entire site or targeted URLs within the Meta Sync plug-in page. |
| 18 | - * Version: 2.6.14 | |
| 18 | + * Version: 2.6.26 | |
| 19 | + * Requires PHP: 8.1 | |
| 19 | 20 | * Author: Search Atlas |
| 20 | 21 | * Author URI: https://searchatlas.com |
| 21 | 22 | * License: GPL v3 |
| 22 | 23 | * License URI: https://www.gnu.org/licenses/gpl-3.0.txt |
| @@ -30,20 +31,30 @@ | ||
| 30 | 31 | |
| 31 | 32 | // Composer classmap autoloader — loads all plugin classes on demand. |
| 32 | 33 | require_once __DIR__ . '/vendor/autoload.php'; |
| 33 | 34 | |
| 35 | +// Canonical sanitizer — required explicitly (not via the committed classmap) | |
| 36 | +// so it is guaranteed loadable everywhere canonicals are read or written. | |
| 37 | +require_once __DIR__ . '/includes/class-metasync-canonical-sanitizer.php'; | |
| 38 | + | |
| 39 | +// Editor-settings feature flags — required explicitly for the same reason: they | |
| 40 | +// gate output in the OTTO buffer and in third-party filter callbacks, both of | |
| 41 | +// which can run before the classmap has resolved anything else. | |
| 42 | +require_once __DIR__ . '/includes/class-metasync-feature-flags.php'; | |
| 43 | +Metasync_Feature_Flags::register_invalidation(); | |
| 44 | + | |
| 34 | 45 | /** |
| 35 | 46 | * Currently plugin version. |
| 36 | 47 | * Start at version 1.0.0 and use SemVer - https://semver.org |
| 37 | 48 | * Rename this for your plugin and update it as you release new versions. |
| 38 | 49 | */ |
| 39 | -$metasync_version = '2.6.14'; | |
| 50 | +$metasync_version = '2.6.26'; | |
| 40 | 51 | define('METASYNC_VERSION', preg_match('/^\d+\.\d+/', $metasync_version) ? $metasync_version : '9.9.9'); |
| 41 | 52 | /** |
| 42 | 53 | * Define the current required php version |
| 43 | 54 | * This will be used to validate whether the user can install the plugin or not |
| 44 | 55 | */ |
| 45 | -define('METASYNC_MIN_PHP', '8.2'); | |
| 56 | +define('METASYNC_MIN_PHP', '8.1'); | |
| 46 | 57 | |
| 47 | 58 | /** |
| 48 | 59 | * Define the current required php version |
| 49 | 60 | * This will be used to validate whether the user can install the plugin or not |
| @@ -107,9 +118,9 @@ | ||
| 107 | 118 | return $sanitized; |
| 108 | 119 | } |
| 109 | 120 | } |
| 110 | 121 | |
| 111 | -// Skip heavy MetaSync init on admin-ajax requests that don't target our own actions (Sentry issue 7441226449 / WP-227). | |
| 122 | +// Skip heavy MetaSync init on admin-ajax requests that don't target our own actions (Sentry issue 7441226449). | |
| 112 | 123 | if (!function_exists('metasync_is_non_metasync_admin_ajax')) { |
| 113 | 124 | function metasync_is_non_metasync_admin_ajax() { |
| 114 | 125 | static $result = null; |
| 115 | 126 | if ($result !== null) { |
| @@ -114,8 +125,14 @@ | ||
| 114 | 125 | static $result = null; |
| 115 | 126 | if ($result !== null) { |
| 116 | 127 | return $result; |
| 117 | 128 | } |
| 129 | + // The MCP bridge intentionally boots WordPress with DOING_AJAX set, but it | |
| 130 | + // is a MetaSync entry point rather than an unrelated admin AJAX request. | |
| 131 | + // The constant is only ever defined as true by the bridge bootstraps. | |
| 132 | + if (defined('METASYNC_MCP_BRIDGE')) { | |
| 133 | + return ($result = false); | |
| 134 | + } | |
| 118 | 135 | if (!defined('DOING_AJAX') || !DOING_AJAX) { |
| 119 | 136 | return ($result = false); |
| 120 | 137 | } |
| 121 | 138 | $action = isset($_POST['action']) ? sanitize_text_field(wp_unslash($_POST['action'])) |
| @@ -132,9 +149,9 @@ | ||
| 132 | 149 | |
| 133 | 150 | // Lazy-load guard: only initialise the MCP server when the request is actually targeting |
| 134 | 151 | // the MCP REST route (or its sibling SEO-inventory route, which depends on $metasync_mcp_server |
| 135 | 152 | // for its permission callback). Saves ~2-5 MB / 10-50 ms on the 99.9% of requests that never |
| 136 | -// touch MCP. See WP-255. | |
| 153 | +// touch MCP. | |
| 137 | 154 | if (!function_exists('metasync_is_mcp_rest_request')) { |
| 138 | 155 | function metasync_is_mcp_rest_request(): bool { |
| 139 | 156 | $uri = isset($_SERVER['REQUEST_URI']) ? (string) $_SERVER['REQUEST_URI'] : ''; |
| 140 | 157 | if ($uri === '') { |
| @@ -162,8 +179,17 @@ | ||
| 162 | 179 | // and must remain as explicit require_once until refactored. |
| 163 | 180 | require_once plugin_dir_path( __FILE__ ) . 'includes/class-metasync-api-backoff-rest.php'; |
| 164 | 181 | require_once plugin_dir_path( __FILE__ ) . 'includes/class-metasync-error-logger.php'; |
| 165 | 182 | |
| 183 | +// Shared helpers (custom/LPS page detection + query exclusion) — loaded in all | |
| 184 | +// request contexts (admin, REST, MCP, AJAX) so every SEO surface uses one rule. | |
| 185 | +require_once plugin_dir_path( __FILE__ ) . 'includes/metasync-helpers.php'; | |
| 186 | + | |
| 187 | +// Shared "results per page" selector helper used by the Redirections, 404 | |
| 188 | +// Monitor, Changes Log and Media Library admin list tables. Loaded early so | |
| 189 | +// the helper class is available before any list table instantiates. | |
| 190 | +require_once plugin_dir_path( __FILE__ ) . 'includes/class-metasync-per-page-helper.php'; | |
| 191 | + | |
| 166 | 192 | /** |
| 167 | 193 | * Include the Otto Pixel Php Code |
| 168 | 194 | */ |
| 169 | 195 | if (!metasync_is_non_metasync_admin_ajax()) { |
| @@ -256,9 +282,9 @@ | ||
| 256 | 282 | |
| 257 | 283 | // Set initial version |
| 258 | 284 | update_option('metasync_version', METASYNC_VERSION); |
| 259 | 285 | |
| 260 | - // WP-315: Record activation timestamp so Divi CSS fix transients | |
| 286 | + // Record activation timestamp so Divi CSS fix transients | |
| 261 | 287 | // auto-invalidate after plugin deactivate/reactivate cycles. |
| 262 | 288 | update_option('metasync_activated_at', (string) time()); |
| 263 | 289 | |
| 264 | 290 | // Clear all cache plugins to ensure fresh start |
| @@ -263,9 +289,9 @@ | ||
| 263 | 289 | |
| 264 | 290 | // Clear all cache plugins to ensure fresh start |
| 265 | 291 | Metasync_Cache_Purge::purge_all('plugin_activation'); |
| 266 | 292 | |
| 267 | - // WP-332: Migrate physical sitemap files on activation. | |
| 293 | + // Migrate physical sitemap files on activation. | |
| 268 | 294 | metasync_migrate_physical_sitemaps(); |
| 269 | 295 | } |
| 270 | 296 | |
| 271 | 297 | // Log-sync removed - error monitoring now handled by Sentry |
| @@ -300,9 +326,9 @@ | ||
| 300 | 326 | register_activation_hook(__FILE__, 'activate_metasync'); |
| 301 | 327 | register_deactivation_hook(__FILE__, 'deactivate_metasync'); |
| 302 | 328 | |
| 303 | 329 | /** |
| 304 | - * WP-332: Migrate physical sitemap .xml files into transients and delete them. | |
| 330 | + * Migrate physical sitemap .xml files into transients and delete them. | |
| 305 | 331 | * |
| 306 | 332 | * Physical files in ABSPATH cause nginx/Plesk to 403 before WordPress can |
| 307 | 333 | * serve them. Called from both the activation hook and the version-gate |
| 308 | 334 | * migration so it covers fresh activations and auto-updates. |
| @@ -339,9 +365,15 @@ | ||
| 339 | 365 | $bn = basename($file); |
| 340 | 366 | $content = @file_get_contents($file); |
| 341 | 367 | if (false !== $content) { |
| 342 | 368 | $tkey = 'metasync_vsm_' . md5($bn); |
| 343 | - set_transient($tkey, $content, 30 * DAY_IN_SECONDS); | |
| 369 | + // The news sitemap's entries are only valid inside Google News' | |
| 370 | + // 48-hour window, so it must not be migrated in under a 30-day | |
| 371 | + // TTL — that would re-introduce the staleness the generator's | |
| 372 | + // own bounded TTL exists to prevent. Regenerate-on-miss rebuilds | |
| 373 | + // it with a fresh date_query when this expires. | |
| 374 | + $ttl = ('news-sitemap.xml' === $bn) ? (int) (DAY_IN_SECONDS / 4) : 30 * DAY_IN_SECONDS; | |
| 375 | + set_transient($tkey, $content, $ttl); | |
| 344 | 376 | if (false !== get_transient($tkey)) { |
| 345 | 377 | @unlink($file); |
| 346 | 378 | $virtual_index[$bn] = $tkey; |
| 347 | 379 | if ($bn !== 'sitemap_index.xml' && $bn !== 'news-sitemap.xml' && $bn !== 'video-sitemap.xml') { |
| @@ -404,9 +436,9 @@ | ||
| 404 | 436 | update_option('metasync_options', $options); |
| 405 | 437 | } |
| 406 | 438 | } |
| 407 | 439 | |
| 408 | - // WP-299: One-time purge of stale OTTO SEO cron backlog. | |
| 440 | + // One-time purge of stale OTTO SEO cron backlog. | |
| 409 | 441 | // Prior versions could accumulate thousands of metasync_process_seo_job and |
| 410 | 442 | // metasync_process_otto_crawl_url_job events due to unbounded rescheduling. |
| 411 | 443 | // Clear the backlog once on update; the new code prevents re-accumulation. |
| 412 | 444 | if (!get_option('metasync_wp299_cron_cleanup_done')) { |
| @@ -415,9 +447,39 @@ | ||
| 415 | 447 | wp_unschedule_hook('metasync_process_otto_batch_cache_job'); |
| 416 | 448 | update_option('metasync_wp299_cron_cleanup_done', true, false); |
| 417 | 449 | } |
| 418 | 450 | |
| 419 | - // WP-332: Migrate physical sitemap files on version update. | |
| 451 | + // One-time cleanup of canonical values corrupted to the literal | |
| 452 | + // "Array" (emitted as http://Array once the 2.6.16 canonical filters | |
| 453 | + // started reading them). The sanitizer prevents new corruption; this | |
| 454 | + // repairs the rows already in the database. Cache purge below pushes | |
| 455 | + // the clean pages live. Claimed via add_option() — it fails if the row | |
| 456 | + // already exists, so concurrent requests can't run the cleanup twice, | |
| 457 | + // and the claim lands BEFORE the work: everything inside is idempotent | |
| 458 | + // and the read-side sanitizer already protects output if a run is | |
| 459 | + // interrupted. | |
| 460 | + if (false === get_option('metasync_canonical_cleanup_done') | |
| 461 | + && add_option('metasync_canonical_cleanup_done', 'running', '', false)) { | |
| 462 | + MetaSync_DBMigration::cleanup_corrupted_canonicals(); | |
| 463 | + update_option('metasync_canonical_cleanup_done', 'done', false); | |
| 464 | + } | |
| 465 | + | |
| 466 | + // One-time repair of Local Business logos corrupted to "http://<id>". | |
| 467 | + // The sanitizer fix stopped new corruption; this restores the | |
| 468 | + // attachment ID on sites that saved a logo before it. The corrupted | |
| 469 | + // value encodes the original ID exactly, so the rewrite is lossless. | |
| 470 | + // Claimed via add_option() — it fails when the row already exists, so | |
| 471 | + // concurrent requests can't run the repair twice, and the claim lands | |
| 472 | + // BEFORE the work: the repair itself is idempotent, and the read-side | |
| 473 | + // normalisation in the schema output and admin preview already | |
| 474 | + // protects output if a run is interrupted. | |
| 475 | + if (false === get_option('metasync_local_seo_logo_repair_done') | |
| 476 | + && add_option('metasync_local_seo_logo_repair_done', 'running', '', false)) { | |
| 477 | + MetaSync_DBMigration::repair_corrupted_local_seo_logo(); | |
| 478 | + update_option('metasync_local_seo_logo_repair_done', 'done', false); | |
| 479 | + } | |
| 480 | + | |
| 481 | + // Migrate physical sitemap files on version update. | |
| 420 | 482 | metasync_migrate_physical_sitemaps(); |
| 421 | 483 | |
| 422 | 484 | // Run full migration to ensure all tables are up to date |
| 423 | 485 | MetaSync_DBMigration::run_migrations(); |
| @@ -449,9 +511,9 @@ | ||
| 449 | 511 | if (!isset($hook_extra['type']) || $hook_extra['type'] !== 'plugin') { |
| 450 | 512 | return; |
| 451 | 513 | } |
| 452 | 514 | |
| 453 | - // WP-427: By the time upgrader_process_complete fires, the upgrader may have | |
| 515 | + // By the time upgrader_process_complete fires, the upgrader may have | |
| 454 | 516 | // deleted the directory this (old, still-in-memory) copy of the plugin was |
| 455 | 517 | // loaded from — e.g. when the installed dir name differs from the package's |
| 456 | 518 | // root dir ('metasync-develop' vs 'metasync'). The Composer classmap then |
| 457 | 519 | // points at files that no longer exist, so autoloading Metasync_Activator |
| @@ -517,9 +579,9 @@ | ||
| 517 | 579 | } |
| 518 | 580 | } |
| 519 | 581 | |
| 520 | 582 | if ($should_import) { |
| 521 | - Metasync_Activator::check_whitelabel_settings_update(); | |
| 583 | + Metasync_Activator::check_whitelabel_settings_update(true); | |
| 522 | 584 | } |
| 523 | 585 | } |
| 524 | 586 | |
| 525 | 587 | // Hook into WordPress upgrader to detect plugin updates |
| @@ -528,26 +590,31 @@ | ||
| 528 | 590 | /** |
| 529 | 591 | * Fallback: Check for whitelabel file changes on admin pages |
| 530 | 592 | * This handles edge cases where upgrader_process_complete doesn't fire |
| 531 | 593 | * (e.g., FTP uploads, manual file replacements) |
| 532 | - * Only checks once per admin session to minimize performance impact | |
| 594 | + * Only checks once per admin request to minimize performance impact | |
| 533 | 595 | */ |
| 534 | -// function metasync_check_whitelabel_on_admin() | |
| 535 | -// { | |
| 536 | -// // Only check once per admin session to avoid overhead | |
| 537 | -// static $checked = false; | |
| 538 | -// if ($checked) { | |
| 539 | -// return; | |
| 540 | -// } | |
| 541 | -// $checked = true; | |
| 596 | +function metasync_check_whitelabel_on_admin() | |
| 597 | +{ | |
| 598 | + static $checked = false; | |
| 599 | + if ($checked || !current_user_can('manage_options')) { | |
| 600 | + return; | |
| 601 | + } | |
| 602 | + $checked = true; | |
| 542 | 603 | |
| 543 | -// require_once plugin_dir_path(__FILE__) . 'includes/class-metasync-activator.php'; | |
| 544 | -// Metasync_Activator::check_whitelabel_settings_update(); | |
| 545 | -// } | |
| 604 | + require_once plugin_dir_path(__FILE__) . 'includes/class-metasync-activator.php'; | |
| 546 | 605 | |
| 547 | -// Check for whitelabel changes on admin pages (fallback for edge cases) | |
| 548 | -// add_action('admin_init', 'metasync_check_whitelabel_on_admin', 1); | |
| 606 | + // Surface a persistently failing White Label import instead of | |
| 607 | + // retrying it silently on every admin request. | |
| 608 | + add_action('admin_notices', array('Metasync_Activator', 'render_whitelabel_import_failure_notice')); | |
| 549 | 609 | |
| 610 | + Metasync_Activator::check_whitelabel_settings_update(); | |
| 611 | +} | |
| 612 | + | |
| 613 | +// Retry package imports on an authorized admin request when an update completed | |
| 614 | +// through the public version-check or stale-classmap fallback path. | |
| 615 | +add_action('admin_init', 'metasync_check_whitelabel_on_admin', 1); | |
| 616 | + | |
| 550 | 617 | // Include Media Optimization Module |
| 551 | 618 | if (!metasync_is_non_metasync_admin_ajax()) { |
| 552 | 619 | require_once plugin_dir_path(__FILE__) . 'media-optimization/media-optimization-loader.php'; |
| 553 | 620 | } |
| @@ -564,277 +631,12 @@ | ||
| 564 | 631 | $plugin->run(); |
| 565 | 632 | } |
| 566 | 633 | run_metasync(); |
| 567 | 634 | |
| 568 | -/** | |
| 569 | - * Initialize WordPress MCP Server | |
| 570 | - * | |
| 571 | - * Safely register a single MCP tool class, logging failures without aborting | |
| 572 | - * subsequent registrations. Extracted as a named function so both production | |
| 573 | - * code and unit tests exercise the same logic (WP-265). | |
| 574 | - * | |
| 575 | - * @param object $server The MCP server instance (must have register_tool()). | |
| 576 | - * @param string $class_name Fully-qualified tool class name. | |
| 577 | - */ | |
| 578 | -function metasync_safe_register_mcp_tool($server, $class_name) { | |
| 579 | - static $logged_missing = []; | |
| 580 | - if (!class_exists($class_name)) { | |
| 581 | - if (empty($logged_missing[$class_name])) { | |
| 582 | - error_log('MetaSync MCP: ' . $class_name . ' class not found — skipping registration. Run composer dump-autoload to regenerate the classmap.'); | |
| 583 | - $logged_missing[$class_name] = true; | |
| 584 | - } | |
| 585 | - return; | |
| 586 | - } | |
| 587 | - try { | |
| 588 | - $server->register_tool(new $class_name()); | |
| 589 | - } catch (\Throwable $e) { | |
| 590 | - error_log('MetaSync MCP: Failed to register tool ' . $class_name . ': ' . $e->getMessage()); | |
| 591 | - } | |
| 592 | -} | |
| 635 | +// MCP server bootstrap (server + tool registration) extracted to keep this entry file lean. | |
| 636 | +require_once plugin_dir_path( __FILE__ ) . 'includes/mcp-server-bootstrap.php'; | |
| 593 | 637 | |
| 594 | 638 | /** |
| 595 | - * Creates and configures the MCP server instance, | |
| 596 | - * registers all available MCP tools for WordPress operations. | |
| 597 | - * Hooked to 'init' for proper WordPress lifecycle integration. | |
| 598 | - */ | |
| 599 | -function metasync_init_mcp_server() { | |
| 600 | - if (metasync_is_non_metasync_admin_ajax()) { | |
| 601 | - return; | |
| 602 | - } | |
| 603 | - // Skip the heavy MCP boot (server + sync logger + REST inventory + 100+ tool objects) | |
| 604 | - // unless this request is actually targeting the MCP REST route or was loaded via | |
| 605 | - // the stdio/HTTP bridge. WP-255. | |
| 606 | - if (!metasync_is_mcp_rest_request() && !defined('METASYNC_MCP_BRIDGE')) { | |
| 607 | - return; | |
| 608 | - } | |
| 609 | - // Initialize MCP server | |
| 610 | - global $metasync_mcp_server; | |
| 611 | - | |
| 612 | - try { | |
| 613 | - $metasync_mcp_server = new Metasync_MCP_Server(); | |
| 614 | - | |
| 615 | - // Attach MCP sync logger so all write tool calls are recorded in Sync History. | |
| 616 | - new Metasync_MCP_Sync_Logger(); | |
| 617 | - | |
| 618 | - // SEO Inventory: shared builder + standalone REST endpoint (WP-135) | |
| 619 | - new Metasync_REST_SEO_Inventory(); | |
| 620 | - } catch (\Throwable $e) { | |
| 621 | - error_log('MCP Server Initialization Error: ' . $e->getMessage()); | |
| 622 | - return; | |
| 623 | - } | |
| 624 | - | |
| 625 | - // Helper: register a single tool, logging failures without aborting subsequent registrations | |
| 626 | - $safe_register = function($class_name) use ($metasync_mcp_server) { | |
| 627 | - metasync_safe_register_mcp_tool($metasync_mcp_server, $class_name); | |
| 628 | - }; | |
| 629 | - | |
| 630 | - // Register MCP Tools (Total: 92 existing + 8 new = 100 tools total!) | |
| 631 | - // NEW in v2.8.0: +4 Taxonomy Meta tools, +4 Bulk Alt Text tools | |
| 632 | - | |
| 633 | - // Post Meta Operations (4 tools) | |
| 634 | - $safe_register('MCP_Tool_Update_Post_Meta'); | |
| 635 | - $safe_register('MCP_Tool_Get_Post_Meta'); | |
| 636 | - $safe_register('MCP_Tool_Get_SEO_Meta'); | |
| 637 | - $safe_register('MCP_Tool_Get_Hreflang_Links'); | |
| 638 | - | |
| 639 | - // Post Operations (4 tools) | |
| 640 | - $safe_register('MCP_Tool_Get_Post'); | |
| 641 | - $safe_register('MCP_Tool_Get_Post_By_URL'); | |
| 642 | - $safe_register('MCP_Tool_List_Posts'); | |
| 643 | - $safe_register('MCP_Tool_Update_Post'); | |
| 644 | - $safe_register('MCP_Tool_Get_Post_Types'); | |
| 645 | - | |
| 646 | - // SEO Analysis (3 tools) | |
| 647 | - $safe_register('MCP_Tool_Analyze_SEO'); | |
| 648 | - $safe_register('MCP_Tool_Check_Indexability'); | |
| 649 | - $safe_register('MCP_Tool_SEO_Health_Report'); | |
| 650 | - | |
| 651 | - // Search Operations (3 tools) | |
| 652 | - $safe_register('MCP_Tool_Search_Posts'); | |
| 653 | - $safe_register('MCP_Tool_Search_By_Keyword'); | |
| 654 | - $safe_register('MCP_Tool_Find_Missing_Meta'); | |
| 655 | - | |
| 656 | - // Redirect Management (5 tools) | |
| 657 | - $safe_register('MCP_Tool_Create_Redirect'); | |
| 658 | - $safe_register('MCP_Tool_List_Redirects'); | |
| 659 | - $safe_register('MCP_Tool_Delete_Redirect'); | |
| 660 | - $safe_register('MCP_Tool_Update_Redirect'); | |
| 661 | - $safe_register('MCP_Tool_Check_Redirects_Health'); | |
| 662 | - | |
| 663 | - // 404 Error Monitoring (5 tools) | |
| 664 | - $safe_register('MCP_Tool_List_404_Errors'); | |
| 665 | - $safe_register('MCP_Tool_Get_404_Stats'); | |
| 666 | - $safe_register('MCP_Tool_Delete_404_Error'); | |
| 667 | - $safe_register('MCP_Tool_Clear_404_Errors'); | |
| 668 | - $safe_register('MCP_Tool_Create_Redirect_From_404'); | |
| 669 | - | |
| 670 | - // Robots.txt & Sitemap Management (11 tools - 7 existing + 4 new) | |
| 671 | - $safe_register('MCP_Tool_Get_Robots_Txt'); | |
| 672 | - $safe_register('MCP_Tool_Update_Robots_Txt'); | |
| 673 | - $safe_register('MCP_Tool_Get_Sitemap_Status'); | |
| 674 | - $safe_register('MCP_Tool_Regenerate_Sitemap'); | |
| 675 | - $safe_register('MCP_Tool_Exclude_From_Sitemap'); | |
| 676 | - $safe_register('MCP_Tool_Add_Robots_Rule'); | |
| 677 | - $safe_register('MCP_Tool_Remove_Robots_Rule'); | |
| 678 | - $safe_register('MCP_Tool_Parse_Robots_Txt'); | |
| 679 | - $safe_register('MCP_Tool_Validate_Robots_Txt'); | |
| 680 | - $safe_register('MCP_Tool_Get_News_Sitemap'); | |
| 681 | - $safe_register('MCP_Tool_Get_Video_Sitemap'); | |
| 682 | - | |
| 683 | - // Plugin Settings Management (4 tools) | |
| 684 | - $safe_register('MCP_Tool_Get_Plugin_Settings'); | |
| 685 | - $safe_register('MCP_Tool_Update_Plugin_Settings'); | |
| 686 | - $safe_register('MCP_Tool_List_Plugin_Settings_Schema'); | |
| 687 | - $safe_register('MCP_Tool_Get_MCP_Settings'); | |
| 688 | - | |
| 689 | - // Schema Markup Management (7 tools) | |
| 690 | - $safe_register('MCP_Tool_Get_Schema_Markup'); | |
| 691 | - $safe_register('MCP_Tool_Update_Schema_Markup'); | |
| 692 | - $safe_register('MCP_Tool_Add_Schema_Type'); | |
| 693 | - $safe_register('MCP_Tool_Remove_Schema_Type'); | |
| 694 | - $safe_register('MCP_Tool_Validate_Schema'); | |
| 695 | - $safe_register('MCP_Tool_Get_Schema_Content'); | |
| 696 | - $safe_register('MCP_Tool_Set_Schema_Content'); | |
| 697 | - | |
| 698 | - // Google Instant Index (6 tools) | |
| 699 | - $safe_register('MCP_Tool_Instant_Index_Update'); | |
| 700 | - $safe_register('MCP_Tool_Instant_Index_Delete'); | |
| 701 | - $safe_register('MCP_Tool_Instant_Index_Status'); | |
| 702 | - $safe_register('MCP_Tool_Instant_Index_Bulk_Update'); | |
| 703 | - $safe_register('MCP_Tool_Get_Instant_Index_Settings'); | |
| 704 | - $safe_register('MCP_Tool_Update_Instant_Index_Settings'); | |
| 705 | - | |
| 706 | - // Custom HTML Pages (6 tools) | |
| 707 | - $safe_register('MCP_Tool_Create_Custom_Page'); | |
| 708 | - $safe_register('MCP_Tool_Get_Custom_Page'); | |
| 709 | - $safe_register('MCP_Tool_List_Custom_Pages'); | |
| 710 | - $safe_register('MCP_Tool_Update_Custom_Page'); | |
| 711 | - $safe_register('MCP_Tool_Delete_Custom_Page'); | |
| 712 | - $safe_register('MCP_Tool_Import_LPS_Page'); | |
| 713 | - | |
| 714 | - // HTML to Builder Converter (3 tools) | |
| 715 | - $safe_register('MCP_Tool_Convert_HTML_To_Builder'); | |
| 716 | - $safe_register('MCP_Tool_Create_Builder_Page_From_HTML'); | |
| 717 | - $safe_register('MCP_Tool_Convert_Custom_Page_To_Builder'); | |
| 718 | - | |
| 719 | - // Code Snippets (6 tools) | |
| 720 | - $safe_register('MCP_Tool_Get_Header_Snippet'); | |
| 721 | - $safe_register('MCP_Tool_Update_Header_Snippet'); | |
| 722 | - $safe_register('MCP_Tool_Get_Footer_Snippet'); | |
| 723 | - $safe_register('MCP_Tool_Update_Footer_Snippet'); | |
| 724 | - $safe_register('MCP_Tool_Get_Post_Snippets'); | |
| 725 | - $safe_register('MCP_Tool_Update_Post_Snippets'); | |
| 726 | - | |
| 727 | - // Categories & Taxonomies (15 tools) | |
| 728 | - $safe_register('MCP_Tool_List_Categories'); | |
| 729 | - $safe_register('MCP_Tool_Get_Category'); | |
| 730 | - $safe_register('MCP_Tool_Create_Category'); | |
| 731 | - $safe_register('MCP_Tool_Update_Category'); | |
| 732 | - $safe_register('MCP_Tool_Delete_Category'); | |
| 733 | - $safe_register('MCP_Tool_Get_Post_Categories'); | |
| 734 | - $safe_register('MCP_Tool_Set_Post_Categories'); | |
| 735 | - | |
| 736 | - // Tags (8 tools) | |
| 737 | - $safe_register('MCP_Tool_List_Tags'); | |
| 738 | - $safe_register('MCP_Tool_Get_Tag'); | |
| 739 | - $safe_register('MCP_Tool_Create_Tag'); | |
| 740 | - $safe_register('MCP_Tool_Update_Tag'); | |
| 741 | - $safe_register('MCP_Tool_Delete_Tag'); | |
| 742 | - $safe_register('MCP_Tool_Get_Post_Tags'); | |
| 743 | - $safe_register('MCP_Tool_Set_Post_Tags'); | |
| 744 | - | |
| 745 | - // Featured Images & Media (6 tools) | |
| 746 | - $safe_register('MCP_Tool_Get_Featured_Image'); | |
| 747 | - $safe_register('MCP_Tool_Set_Featured_Image'); | |
| 748 | - $safe_register('MCP_Tool_Upload_Featured_Image'); | |
| 749 | - $safe_register('MCP_Tool_Remove_Featured_Image'); | |
| 750 | - $safe_register('MCP_Tool_List_Media'); | |
| 751 | - $safe_register('MCP_Tool_Get_Media_Details'); | |
| 752 | - | |
| 753 | - // Post CRUD Operations (1 tool - delete/restore disabled for safety) | |
| 754 | - $safe_register('MCP_Tool_Create_Post'); | |
| 755 | - // $safe_register('MCP_Tool_Delete_Post'); // DISABLED - safety | |
| 756 | - // $safe_register('MCP_Tool_Restore_Post'); // DISABLED - safety | |
| 757 | - | |
| 758 | - // Bulk Operations (3 tools - bulk delete disabled for safety) | |
| 759 | - $safe_register('MCP_Tool_Bulk_Update_Meta'); | |
| 760 | - $safe_register('MCP_Tool_Bulk_Set_Categories'); | |
| 761 | - $safe_register('MCP_Tool_Bulk_Change_Status'); | |
| 762 | - // $safe_register('MCP_Tool_Bulk_Delete_Posts'); // DISABLED - safety | |
| 763 | - | |
| 764 | - // WordPress Core SEO Settings (10 tools) | |
| 765 | - $safe_register('MCP_Tool_Get_Site_Info'); | |
| 766 | - $safe_register('MCP_Tool_Update_Site_Info'); | |
| 767 | - $safe_register('MCP_Tool_Get_Permalink_Structure'); | |
| 768 | - $safe_register('MCP_Tool_Update_Permalink_Structure'); | |
| 769 | - $safe_register('MCP_Tool_Get_Reading_Settings'); | |
| 770 | - $safe_register('MCP_Tool_Update_Reading_Settings'); | |
| 771 | - $safe_register('MCP_Tool_Get_Search_Visibility'); | |
| 772 | - $safe_register('MCP_Tool_Update_Search_Visibility'); | |
| 773 | - $safe_register('MCP_Tool_Get_Date_Format'); | |
| 774 | - $safe_register('MCP_Tool_Get_Discussion_Settings'); | |
| 775 | - | |
| 776 | - // Taxonomy Meta Operations (4 tools - NEW in v2.8.0) | |
| 777 | - $safe_register('MCP_Tool_Get_Term_Meta'); | |
| 778 | - $safe_register('MCP_Tool_Update_Term_Meta'); | |
| 779 | - $safe_register('MCP_Tool_Bulk_Update_Term_Meta'); | |
| 780 | - $safe_register('MCP_Tool_List_Terms_With_Meta'); | |
| 781 | - | |
| 782 | - // Bulk Alt Text Operations (4 tools - NEW in v2.8.0) | |
| 783 | - $safe_register('MCP_Tool_Audit_Alt_Text'); | |
| 784 | - $safe_register('MCP_Tool_Bulk_Update_Alt_Text'); | |
| 785 | - $safe_register('MCP_Tool_Generate_Alt_Text'); | |
| 786 | - $safe_register('MCP_Tool_Validate_Alt_Text'); | |
| 787 | - | |
| 788 | - // OTTO Persistence Settings (2 tools) | |
| 789 | - $safe_register('MCP_Tool_Get_Otto_Persistence_Settings'); | |
| 790 | - $safe_register('MCP_Tool_Update_Otto_Persistence_Settings'); | |
| 791 | - | |
| 792 | - // OTTO Pipeline Tools (3 tools) | |
| 793 | - $safe_register('MCP_Tool_Trigger_Otto_Optimization'); | |
| 794 | - $safe_register('MCP_Tool_Get_Otto_Status'); | |
| 795 | - $safe_register('MCP_Tool_Verify_SEO_Output'); | |
| 796 | - | |
| 797 | - // System Diagnostics & Plugin Info (4 tools) | |
| 798 | - $safe_register('MCP_Tool_System_Diagnostics'); | |
| 799 | - $safe_register('MCP_Tool_List_All_Plugins'); | |
| 800 | - $safe_register('MCP_Tool_Get_Cron_Jobs'); | |
| 801 | - $safe_register('MCP_Tool_Get_WP_Option'); | |
| 802 | - | |
| 803 | - // SEO Inventory (1 tool — WP-135) | |
| 804 | - $safe_register('MCP_Tool_List_Posts_SEO_Inventory'); | |
| 805 | - | |
| 806 | - // Read-Only Database Access (3 tools) | |
| 807 | - $safe_register('MCP_Tool_DB_Tables'); | |
| 808 | - $safe_register('MCP_Tool_DB_Describe'); | |
| 809 | - $safe_register('MCP_Tool_DB_Select'); | |
| 810 | - | |
| 811 | - // Breadcrumb Tools (1 tool) | |
| 812 | - $safe_register('MCP_Tool_Get_Breadcrumb_Path'); | |
| 813 | - | |
| 814 | - // Cache Purge (2 tools) | |
| 815 | - $safe_register('MCP_Tool_Cache_Purge_All'); | |
| 816 | - $safe_register('MCP_Tool_Cache_Purge_URL'); | |
| 817 | - | |
| 818 | - // LLMs.txt Tools (5 tools) | |
| 819 | - $safe_register('MCP_Tool_Get_LLMs_Txt'); | |
| 820 | - $safe_register('MCP_Tool_Regenerate_LLMs_Txt'); | |
| 821 | - $safe_register('MCP_Tool_Get_LLMs_Txt_Settings'); | |
| 822 | - $safe_register('MCP_Tool_Update_LLMs_Txt_Settings'); | |
| 823 | - $safe_register('MCP_Tool_Get_Post_Markdown'); | |
| 824 | - | |
| 825 | - // SEO Plugin Audit (4 tools — WP-202) | |
| 826 | - $safe_register('MCP_Tool_Read_SEO_Plugin_Data'); | |
| 827 | - $safe_register('MCP_Tool_SEO_Plugin_Diff'); | |
| 828 | - $safe_register('MCP_Tool_Sync_To_Active_Plugins'); | |
| 829 | - $safe_register('MCP_Tool_Detect_SEO_Conflicts'); | |
| 830 | - | |
| 831 | - // Allow other plugins/themes to register tools | |
| 832 | - do_action('metasync_mcp_register_tools', $metasync_mcp_server); | |
| 833 | -} | |
| 834 | -add_action('init', 'metasync_init_mcp_server', 5); | |
| 835 | - | |
| 836 | -/** | |
| 837 | 639 | * Schedule a daily cron event to auto-purge Sync History records older than 90 days. |
| 838 | 640 | */ |
| 839 | 641 | function metasync_schedule_sync_log_cleanup() { |
| 840 | 642 | if (!wp_next_scheduled('metasync_sync_log_daily_cleanup')) { |
| @@ -861,85 +663,41 @@ | ||
| 861 | 663 | echo '<script>window.__SA_DYO_INITIALIZED__=true;</script>' . "\n"; |
| 862 | 664 | } |
| 863 | 665 | add_action('wp_head', 'metasync_output_dyo_init_flag', 1); |
| 864 | 666 | |
| 865 | -/** | |
| 866 | - * Initialize GA4 Analytics for Admin Area | |
| 867 | - * Hooked to admin_init for proper WordPress lifecycle integration | |
| 868 | - * Only loads after WordPress, plugins, and themes are fully loaded | |
| 869 | - */ | |
| 870 | -function metasync_init_analytics() { | |
| 871 | - // Only initialize in admin area (excludes AJAX and REST API requests) | |
| 872 | - if (is_admin() && !wp_doing_ajax() && !defined('REST_REQUEST')) { | |
| 873 | - Metasync_GA4::get_instance(); | |
| 874 | - } | |
| 875 | -} | |
| 876 | -add_action('admin_init', 'metasync_init_analytics', 10); | |
| 667 | +// Runtime feature initialisers (GA4, API backoff, review notice, JWT accessor, debug mode) extracted to keep this entry file lean. | |
| 668 | +require_once plugin_dir_path( __FILE__ ) . 'includes/metasync-runtime-init.php'; | |
| 877 | 669 | |
| 878 | 670 | /** |
| 879 | - * Initialize API Backoff System | |
| 880 | - * Hooked to init for proper WordPress lifecycle integration | |
| 881 | - * Monitors API responses and manages exponential backoff for rate limiting | |
| 882 | - * @since 2.7.1 | |
| 671 | + * Append a "Website Studio" post state to LPS-synced / MetaSync custom pages in | |
| 672 | + * the admin Pages list, so site owners can tell at a glance which pages are | |
| 673 | + * managed by Website Studio and shouldn't be hand-edited. | |
| 674 | + * | |
| 675 | + * Hooks WordPress core's display_post_states filter — the same mechanism that | |
| 676 | + * renders the grey inline tags like "— Front Page" / "— Draft" — so the label | |
| 677 | + * is native-styled and only appears next to relevant page titles, with no | |
| 678 | + * custom admin column. | |
| 679 | + * | |
| 680 | + * @param string[] $post_states Existing post-state labels keyed by slug. | |
| 681 | + * @param WP_Post $post The post being listed. | |
| 682 | + * @return string[] Possibly-augmented post states. | |
| 883 | 683 | */ |
| 884 | -function metasync_init_api_backoff() { | |
| 885 | - if (metasync_is_non_metasync_admin_ajax()) { | |
| 886 | - return; | |
| 684 | +function metasync_add_lps_post_state($post_states, $post) { | |
| 685 | + // metasync_is_custom_or_lps_page() lives in otto/otto_pixel.php, which is NOT | |
| 686 | + // loaded on non-MetaSync admin-ajax requests (e.g. Quick Edit's inline-save, | |
| 687 | + // where this filter still fires), so guard against the undefined function. | |
| 688 | + if (!function_exists('metasync_is_custom_or_lps_page')) { | |
| 689 | + return $post_states; | |
| 887 | 690 | } |
| 888 | - // Initialize backoff manager (registers HTTP response filters) | |
| 889 | - Metasync_API_Backoff_Manager::get_instance(); | |
| 890 | - | |
| 891 | - // Initialize admin notices (only in admin area) | |
| 892 | - if (is_admin()) { | |
| 893 | - Metasync_API_Backoff_Notices::get_instance(); | |
| 691 | + if (!metasync_is_custom_or_lps_page($post->ID)) { | |
| 692 | + return $post_states; | |
| 894 | 693 | } |
| 694 | + $post_states['metasync_website_studio'] = __('Website Studio', 'metasync'); | |
| 695 | + return $post_states; | |
| 895 | 696 | } |
| 896 | -add_action('init', 'metasync_init_api_backoff', 5); | |
| 897 | 697 | |
| 898 | -/** | |
| 899 | - * Initialize Review Notice | |
| 900 | - * Shows a dismissible notice asking users to rate the plugin after a usage period | |
| 901 | - * @since 2.8.0 | |
| 902 | - */ | |
| 903 | -function metasync_init_review_notice() { | |
| 904 | - if (metasync_is_non_metasync_admin_ajax()) { | |
| 905 | - return; | |
| 906 | - } | |
| 907 | - if (is_admin()) { | |
| 908 | - Metasync_Review_Notice::get_instance(); | |
| 909 | - } | |
| 910 | -} | |
| 911 | -add_action('init', 'metasync_init_review_notice'); | |
| 912 | 698 | |
| 913 | 699 | /** |
| 914 | - * Global convenience function to get active JWT token | |
| 915 | - * Can be called from anywhere in WordPress (themes, other plugins, etc.) | |
| 916 | - * | |
| 917 | - * @param bool $force_refresh Force generation of new token even if cached one exists | |
| 918 | - * @return string|false JWT token on success, false on failure | |
| 919 | - */ | |
| 920 | -if (!function_exists('metasync_get_jwt_token')) { | |
| 921 | - function metasync_get_jwt_token($force_refresh = false) | |
| 922 | - { | |
| 923 | - return Metasync::get_jwt_token($force_refresh); | |
| 924 | - } | |
| 925 | -} | |
| 926 | - | |
| 927 | - | |
| 928 | -/** | |
| 929 | - * Initialize Debug Mode Manager | |
| 930 | - * Hooked to 'init' for proper WordPress lifecycle integration | |
| 931 | - */ | |
| 932 | -function metasync_init_debug_mode_manager() { | |
| 933 | - if (metasync_is_non_metasync_admin_ajax()) { | |
| 934 | - return; | |
| 935 | - } | |
| 936 | - // Initialize the Debug Mode Manager singleton | |
| 937 | - Metasync_Debug_Mode_Manager::get_instance(); | |
| 938 | -} | |
| 939 | -add_action('init', 'metasync_init_debug_mode_manager', 10); | |
| 940 | - | |
| 941 | -/** | |
| 942 | 700 | * Oxygen Builder Compatibility |
| 943 | 701 | * Auto re-signs [oxygen] dynamic-data shortcodes when their HMAC signatures |
| 944 | 702 | * are invalid (e.g. after design-set import or site migration). |
| 945 | 703 | * Runs once on admin_init; skips entirely when Oxygen is inactive. |
| @@ -945,5 +703,6 @@ | ||
| 945 | 703 | * Runs once on admin_init; skips entirely when Oxygen is inactive. |
| 946 | 704 | */ |
| 947 | 705 | if (is_admin()) { |
| 948 | 706 | add_action('admin_init', ['Metasync_Oxygen_Compat', 'maybe_resign_shortcodes'], 20); |
| 707 | + add_filter('display_post_states', 'metasync_add_lps_post_state', 10, 2); | |
| 949 | 708 | } |