PluginProbe
Search Atlas SEO – OTTO AI SEO Automation for WordPress / trunk
Search Atlas SEO – OTTO AI SEO Automation for WordPress vtrunk
2.6.26 2.6.25 2.6.24 2.6.23 2.6.22 2.6.21 2.6.20 2.6.19 2.6.18 2.6.17 2.6.16 2.6.15 2.6.14 2.6.13 2.6.12 2.6.11 2.6.10 2.6.9 2.6.8 2.6.7 2.6.6 2.6.5 2.6.4 2.6.3 2.5.23 All 138 releases
← All changes | metasync.php +282 -336 2.6.3trunk View file →
@@ -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.3
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.3';
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,17 +118,86 @@
107 118 return $sanitized;
108 119 }
109 120 }
110 121
122 +// Skip heavy MetaSync init on admin-ajax requests that don't target our own actions (Sentry issue 7441226449).
123 +if (!function_exists('metasync_is_non_metasync_admin_ajax')) {
124 + function metasync_is_non_metasync_admin_ajax() {
125 + static $result = null;
126 + if ($result !== null) {
127 + return $result;
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 + }
135 + if (!defined('DOING_AJAX') || !DOING_AJAX) {
136 + return ($result = false);
137 + }
138 + $action = isset($_POST['action']) ? sanitize_text_field(wp_unslash($_POST['action']))
139 + : (isset($_GET['action']) ? sanitize_text_field(wp_unslash($_GET['action'])) : '');
140 + if ($action === '') {
141 + return ($result = true);
142 + }
143 + if (strpos($action, 'metasync_') === 0 || strpos($action, 'meta_sync_') === 0 || $action === 'sample-permalink') {
144 + return ($result = false);
145 + }
146 + return ($result = true);
147 + }
148 +}
149 +
150 +// Lazy-load guard: only initialise the MCP server when the request is actually targeting
151 +// the MCP REST route (or its sibling SEO-inventory route, which depends on $metasync_mcp_server
152 +// for its permission callback). Saves ~2-5 MB / 10-50 ms on the 99.9% of requests that never
153 +// touch MCP.
154 +if (!function_exists('metasync_is_mcp_rest_request')) {
155 + function metasync_is_mcp_rest_request(): bool {
156 + $uri = isset($_SERVER['REQUEST_URI']) ? (string) $_SERVER['REQUEST_URI'] : '';
157 + if ($uri === '') {
158 + return false;
159 + }
160 + $prefix = function_exists('rest_get_url_prefix') ? rest_get_url_prefix() : 'wp-json';
161 + $needles = [
162 + '/' . $prefix . '/metasync/v1/mcp',
163 + '/' . $prefix . '/metasync/v1/seo-inventory',
164 + 'rest_route=/metasync/v1/mcp',
165 + 'rest_route=/metasync/v1/seo-inventory',
166 + 'rest_route=%2Fmetasync%2Fv1%2Fmcp',
167 + 'rest_route=%2Fmetasync%2Fv1%2Fseo-inventory',
168 + ];
169 + foreach ($needles as $needle) {
170 + if (stripos($uri, $needle) !== false) {
171 + return true;
172 + }
173 + }
174 + return false;
175 + }
176 +}
177 +
111 178 // Phase 2 — these files have file-level side effects (add_action outside class body)
112 179 // and must remain as explicit require_once until refactored.
113 180 require_once plugin_dir_path( __FILE__ ) . 'includes/class-metasync-api-backoff-rest.php';
114 181 require_once plugin_dir_path( __FILE__ ) . 'includes/class-metasync-error-logger.php';
115 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 +
116 192 /**
117 193 * Include the Otto Pixel Php Code
118 194 */
119 -require_once plugin_dir_path( __FILE__ ) . '/otto/otto_pixel.php';
195 +if (!metasync_is_non_metasync_admin_ajax()) {
196 + require_once plugin_dir_path( __FILE__ ) . '/otto/otto_pixel.php';
197 + require_once plugin_dir_path( __FILE__ ) . '/otto/class-metasync-otto-clone-meta-cleaner.php';
198 + Metasync_Otto_Clone_Meta_Cleaner::register();
199 +}
120 200
121 201
122 202 /**
123 203 * Initialize OTTO Persistence Settings (registers REST API endpoints)
@@ -122,8 +202,11 @@
122 202 /**
123 203 * Initialize OTTO Persistence Settings (registers REST API endpoints)
124 204 */
125 205 add_action('init', function() {
206 + if (metasync_is_non_metasync_admin_ajax()) {
207 + return;
208 + }
126 209 Metasync_Otto_Persistence_Settings::init();
127 210 }, 5);
128 211
129 212 /**
@@ -198,11 +281,18 @@
198 281 MetaSync_DBMigration::activation();
199 282
200 283 // Set initial version
201 284 update_option('metasync_version', METASYNC_VERSION);
202 -
285 +
286 + // Record activation timestamp so Divi CSS fix transients
287 + // auto-invalidate after plugin deactivate/reactivate cycles.
288 + update_option('metasync_activated_at', (string) time());
289 +
203 290 // Clear all cache plugins to ensure fresh start
204 291 Metasync_Cache_Purge::purge_all('plugin_activation');
292 +
293 + // Migrate physical sitemap files on activation.
294 + metasync_migrate_physical_sitemaps();
205 295 }
206 296
207 297 // Log-sync removed - error monitoring now handled by Sentry
208 298 // require_once plugin_dir_path(__FILE__) . 'log-sync/log-sync.php';
@@ -209,9 +299,11 @@
209 299
210 300 /**
211 301 * Initialize telemetry system for error monitoring and Sentry integration
212 302 */
213 -require_once plugin_dir_path(__FILE__) . 'telemetry/telemetry-init.php';
303 +if (!metasync_is_non_metasync_admin_ajax()) {
304 + require_once plugin_dir_path(__FILE__) . 'telemetry/telemetry-init.php';
305 +}
214 306
215 307 /**
216 308 * The code that runs during plugin deactivation.
217 309 * This action is documented in includes/class-metasync-deactivator.php
@@ -221,18 +313,15 @@
221 313 Metasync_Deactivator::deactivate();
222 314 // class name is changed at class-db-migrations.php
223 315 MetaSync_DBMigration::deactivation();
224 316
225 - // Unschedule the sync log cleanup cron to avoid orphaned events.
226 - $timestamp = wp_next_scheduled('metasync_sync_log_daily_cleanup');
227 - if ($timestamp) {
228 - wp_unschedule_event($timestamp, 'metasync_sync_log_daily_cleanup');
229 - }
230 -
231 317 // Clear news/video sitemap caches
232 318 delete_transient('metasync_vsm_' . md5('news-sitemap.xml'));
233 319 delete_transient('metasync_vsm_' . md5('video-sitemap.xml'));
234 320 delete_option('metasync_sitemap_virtual_index');
321 +
322 + // Clear OTTO JS detection cache so re-activation gets a fresh check
323 + delete_transient('metasync_otto_js_detected');
235 324 }
236 325
237 326 register_activation_hook(__FILE__, 'activate_metasync');
238 327 register_deactivation_hook(__FILE__, 'deactivate_metasync');
@@ -237,8 +326,77 @@
237 326 register_activation_hook(__FILE__, 'activate_metasync');
238 327 register_deactivation_hook(__FILE__, 'deactivate_metasync');
239 328
240 329 /**
330 + * Migrate physical sitemap .xml files into transients and delete them.
331 + *
332 + * Physical files in ABSPATH cause nginx/Plesk to 403 before WordPress can
333 + * serve them. Called from both the activation hook and the version-gate
334 + * migration so it covers fresh activations and auto-updates.
335 + */
336 +function metasync_migrate_physical_sitemaps()
337 +{
338 + update_option('metasync_sitemap_virtual_mode', true, false);
339 +
340 + $candidates = [];
341 + $globbed = glob(ABSPATH . 'sitemap*.xml');
342 + if (is_array($globbed)) {
343 + foreach ($globbed as $file) {
344 + $basename = basename($file);
345 + if ($basename === 'sitemap_index.xml' || preg_match('/^sitemap\d*\.xml$/', $basename)) {
346 + $candidates[] = $file;
347 + }
348 + }
349 + }
350 + foreach (['news-sitemap.xml', 'video-sitemap.xml'] as $extra) {
351 + $path = ABSPATH . $extra;
352 + if (file_exists($path)) {
353 + $candidates[] = $path;
354 + }
355 + }
356 +
357 + if (empty($candidates)) {
358 + return;
359 + }
360 +
361 + $virtual_index = get_option('metasync_sitemap_virtual_index', []);
362 + $migrated_files = [];
363 +
364 + foreach ($candidates as $file) {
365 + $bn = basename($file);
366 + $content = @file_get_contents($file);
367 + if (false !== $content) {
368 + $tkey = 'metasync_vsm_' . md5($bn);
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);
376 + if (false !== get_transient($tkey)) {
377 + @unlink($file);
378 + $virtual_index[$bn] = $tkey;
379 + if ($bn !== 'sitemap_index.xml' && $bn !== 'news-sitemap.xml' && $bn !== 'video-sitemap.xml') {
380 + $migrated_files[] = [
381 + 'filename' => $bn,
382 + 'url' => home_url('/' . $bn),
383 + 'lastmod' => current_time('mysql', true),
384 + ];
385 + }
386 + }
387 + }
388 + }
389 +
390 + update_option('metasync_sitemap_virtual_index', $virtual_index, false);
391 +
392 + if (!empty($migrated_files)) {
393 + update_option('metasync_sitemap_files', $migrated_files);
394 + update_option('metasync_sitemap_last_generated', current_time('mysql'));
395 + }
396 +}
397 +
398 +/**
241 399 * Check for plugin updates and run migrations if needed
242 400 */
243 401 function check_metasync_updates()
244 402 {
@@ -278,8 +436,52 @@
278 436 update_option('metasync_options', $options);
279 437 }
280 438 }
281 439
440 + // One-time purge of stale OTTO SEO cron backlog.
441 + // Prior versions could accumulate thousands of metasync_process_seo_job and
442 + // metasync_process_otto_crawl_url_job events due to unbounded rescheduling.
443 + // Clear the backlog once on update; the new code prevents re-accumulation.
444 + if (!get_option('metasync_wp299_cron_cleanup_done')) {
445 + wp_unschedule_hook('metasync_process_seo_job');
446 + wp_unschedule_hook('metasync_process_otto_crawl_url_job');
447 + wp_unschedule_hook('metasync_process_otto_batch_cache_job');
448 + update_option('metasync_wp299_cron_cleanup_done', true, false);
449 + }
450 +
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.
482 + metasync_migrate_physical_sitemaps();
483 +
282 484 // Run full migration to ensure all tables are up to date
283 485 MetaSync_DBMigration::run_migrations();
284 486
285 487 // Update stored version
@@ -309,8 +511,23 @@
309 511 if (!isset($hook_extra['type']) || $hook_extra['type'] !== 'plugin') {
310 512 return;
311 513 }
312 514
515 + // By the time upgrader_process_complete fires, the upgrader may have
516 + // deleted the directory this (old, still-in-memory) copy of the plugin was
517 + // loaded from — e.g. when the installed dir name differs from the package's
518 + // root dir ('metasync-develop' vs 'metasync'). The Composer classmap then
519 + // points at files that no longer exist, so autoloading Metasync_Activator
520 + // below would fatal. Bail instead; the whitelabel re-import runs on the next
521 + // request via check_metasync_updates() once the new copy is active.
522 + if (!class_exists('Metasync_Activator', false)) {
523 + $activator = __DIR__ . '/includes/class-metasync-activator.php';
524 + if (!is_file($activator)) {
525 + return;
526 + }
527 + require_once $activator;
528 + }
529 +
313 530 // Only process install and update actions
314 531 if (!isset($hook_extra['action']) || !in_array($hook_extra['action'], ['install', 'update'], true)) {
315 532 return;
316 533 }
@@ -362,9 +579,9 @@
362 579 }
363 580 }
364 581
365 582 if ($should_import) {
366 - Metasync_Activator::check_whitelabel_settings_update();
583 + Metasync_Activator::check_whitelabel_settings_update(true);
367 584 }
368 585 }
369 586
370 587 // Hook into WordPress upgrader to detect plugin updates
@@ -373,34 +590,41 @@
373 590 /**
374 591 * Fallback: Check for whitelabel file changes on admin pages
375 592 * This handles edge cases where upgrader_process_complete doesn't fire
376 593 * (e.g., FTP uploads, manual file replacements)
377 - * Only checks once per admin session to minimize performance impact
594 + * Only checks once per admin request to minimize performance impact
378 595 */
379 -// function metasync_check_whitelabel_on_admin()
380 -// {
381 -// // Only check once per admin session to avoid overhead
382 -// static $checked = false;
383 -// if ($checked) {
384 -// return;
385 -// }
386 -// $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;
387 603
388 -// require_once plugin_dir_path(__FILE__) . 'includes/class-metasync-activator.php';
389 -// Metasync_Activator::check_whitelabel_settings_update();
390 -// }
604 + require_once plugin_dir_path(__FILE__) . 'includes/class-metasync-activator.php';
391 605
392 -// Check for whitelabel changes on admin pages (fallback for edge cases)
393 -// 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'));
394 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 +
395 617 // Include Media Optimization Module
396 -require_once plugin_dir_path(__FILE__) . 'media-optimization/media-optimization-loader.php';
618 +if (!metasync_is_non_metasync_admin_ajax()) {
619 + require_once plugin_dir_path(__FILE__) . 'media-optimization/media-optimization-loader.php';
620 +}
397 621
398 622 // Include Code Minification & Delivery Module
399 -require_once plugin_dir_path(__FILE__) . 'code-minification/code-minification-loader.php';
623 +if (!metasync_is_non_metasync_admin_ajax()) {
624 + require_once plugin_dir_path(__FILE__) . 'code-minification/code-minification-loader.php';
625 +}
400 626
401 -// Include Zapier Connector
402 -require_once plugin_dir_path(__FILE__) . 'zapier/zapier-loader.php';
403 627
404 628 function run_metasync()
405 629 {
406 630 $plugin = new Metasync();
@@ -407,255 +631,11 @@
407 631 $plugin->run();
408 632 }
409 633 run_metasync();
410 634
411 -/**
412 - * Initialize WordPress MCP Server
413 - *
414 - * Creates and configures the MCP server instance,
415 - * registers all available MCP tools for WordPress operations.
416 - * Hooked to 'init' for proper WordPress lifecycle integration.
417 - */
418 -function metasync_init_mcp_server() {
419 - // Initialize MCP server
420 - global $metasync_mcp_server;
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';
421 637
422 - try {
423 - $metasync_mcp_server = new Metasync_MCP_Server();
424 -
425 - // Attach MCP sync logger so all write tool calls are recorded in Sync History.
426 - new Metasync_MCP_Sync_Logger();
427 -
428 - // SEO Inventory: shared builder + standalone REST endpoint (WP-135)
429 - new Metasync_REST_SEO_Inventory();
430 - } catch (Exception $e) {
431 - error_log('MCP Server Initialization Error: ' . $e->getMessage());
432 - return;
433 - }
434 -
435 - // Helper: register a single tool, logging failures without aborting subsequent registrations
436 - $safe_register = function($tool) use ($metasync_mcp_server) {
437 - try {
438 - $metasync_mcp_server->register_tool($tool);
439 - } catch (Exception $e) {
440 - error_log('MetaSync MCP: Failed to register tool ' . get_class($tool) . ': ' . $e->getMessage());
441 - }
442 - };
443 -
444 - // Register MCP Tools (Total: 92 existing + 8 new = 100 tools total!)
445 - // NEW in v2.8.0: +4 Taxonomy Meta tools, +4 Bulk Alt Text tools
446 -
447 - // Post Meta Operations (4 tools)
448 - $safe_register(new MCP_Tool_Update_Post_Meta());
449 - $safe_register(new MCP_Tool_Get_Post_Meta());
450 - $safe_register(new MCP_Tool_Get_SEO_Meta());
451 - $safe_register(new MCP_Tool_Get_Hreflang_Links());
452 -
453 - // Post Operations (4 tools)
454 - $safe_register(new MCP_Tool_Get_Post());
455 - $safe_register(new MCP_Tool_Get_Post_By_URL());
456 - $safe_register(new MCP_Tool_List_Posts());
457 - $safe_register(new MCP_Tool_Update_Post());
458 - $safe_register(new MCP_Tool_Get_Post_Types());
459 -
460 - // SEO Analysis (3 tools)
461 - $safe_register(new MCP_Tool_Analyze_SEO());
462 - $safe_register(new MCP_Tool_Check_Indexability());
463 - $safe_register(new MCP_Tool_SEO_Health_Report());
464 -
465 - // Search Operations (3 tools)
466 - $safe_register(new MCP_Tool_Search_Posts());
467 - $safe_register(new MCP_Tool_Search_By_Keyword());
468 - $safe_register(new MCP_Tool_Find_Missing_Meta());
469 -
470 - // Redirect Management (4 tools)
471 - $safe_register(new MCP_Tool_Create_Redirect());
472 - $safe_register(new MCP_Tool_List_Redirects());
473 - $safe_register(new MCP_Tool_Delete_Redirect());
474 - $safe_register(new MCP_Tool_Update_Redirect());
475 -
476 - // 404 Error Monitoring (5 tools)
477 - $safe_register(new MCP_Tool_List_404_Errors());
478 - $safe_register(new MCP_Tool_Get_404_Stats());
479 - $safe_register(new MCP_Tool_Delete_404_Error());
480 - $safe_register(new MCP_Tool_Clear_404_Errors());
481 - $safe_register(new MCP_Tool_Create_Redirect_From_404());
482 -
483 - // Robots.txt & Sitemap Management (11 tools - 7 existing + 4 new)
484 - $safe_register(new MCP_Tool_Get_Robots_Txt());
485 - $safe_register(new MCP_Tool_Update_Robots_Txt());
486 - $safe_register(new MCP_Tool_Get_Sitemap_Status());
487 - $safe_register(new MCP_Tool_Regenerate_Sitemap());
488 - $safe_register(new MCP_Tool_Exclude_From_Sitemap());
489 - $safe_register(new MCP_Tool_Add_Robots_Rule());
490 - $safe_register(new MCP_Tool_Remove_Robots_Rule());
491 - $safe_register(new MCP_Tool_Parse_Robots_Txt());
492 - $safe_register(new MCP_Tool_Validate_Robots_Txt());
493 - $safe_register(new MCP_Tool_Get_News_Sitemap());
494 - $safe_register(new MCP_Tool_Get_Video_Sitemap());
495 -
496 - // Plugin Settings Management (4 tools)
497 - $safe_register(new MCP_Tool_Get_Plugin_Settings());
498 - $safe_register(new MCP_Tool_Update_Plugin_Settings());
499 - $safe_register(new MCP_Tool_List_Plugin_Settings_Schema());
500 - $safe_register(new MCP_Tool_Get_MCP_Settings());
501 -
502 - // Schema Markup Management (5 tools)
503 - $safe_register(new MCP_Tool_Get_Schema_Markup());
504 - $safe_register(new MCP_Tool_Update_Schema_Markup());
505 - $safe_register(new MCP_Tool_Add_Schema_Type());
506 - $safe_register(new MCP_Tool_Remove_Schema_Type());
507 - $safe_register(new MCP_Tool_Validate_Schema());
508 -
509 - // Google Instant Index (6 tools)
510 - $safe_register(new MCP_Tool_Instant_Index_Update());
511 - $safe_register(new MCP_Tool_Instant_Index_Delete());
512 - $safe_register(new MCP_Tool_Instant_Index_Status());
513 - $safe_register(new MCP_Tool_Instant_Index_Bulk_Update());
514 - $safe_register(new MCP_Tool_Get_Instant_Index_Settings());
515 - $safe_register(new MCP_Tool_Update_Instant_Index_Settings());
516 -
517 - // Custom HTML Pages (5 tools)
518 - $safe_register(new MCP_Tool_Create_Custom_Page());
519 - $safe_register(new MCP_Tool_Get_Custom_Page());
520 - $safe_register(new MCP_Tool_List_Custom_Pages());
521 - $safe_register(new MCP_Tool_Update_Custom_Page());
522 - $safe_register(new MCP_Tool_Delete_Custom_Page());
523 -
524 - // HTML to Builder Converter (3 tools)
525 - $safe_register(new MCP_Tool_Convert_HTML_To_Builder());
526 - $safe_register(new MCP_Tool_Create_Builder_Page_From_HTML());
527 - $safe_register(new MCP_Tool_Convert_Custom_Page_To_Builder());
528 -
529 - // Code Snippets (6 tools)
530 - $safe_register(new MCP_Tool_Get_Header_Snippet());
531 - $safe_register(new MCP_Tool_Update_Header_Snippet());
532 - $safe_register(new MCP_Tool_Get_Footer_Snippet());
533 - $safe_register(new MCP_Tool_Update_Footer_Snippet());
534 - $safe_register(new MCP_Tool_Get_Post_Snippets());
535 - $safe_register(new MCP_Tool_Update_Post_Snippets());
536 -
537 - // Categories & Taxonomies (15 tools)
538 - $safe_register(new MCP_Tool_List_Categories());
539 - $safe_register(new MCP_Tool_Get_Category());
540 - $safe_register(new MCP_Tool_Create_Category());
541 - $safe_register(new MCP_Tool_Update_Category());
542 - $safe_register(new MCP_Tool_Delete_Category());
543 - $safe_register(new MCP_Tool_Get_Post_Categories());
544 - $safe_register(new MCP_Tool_Set_Post_Categories());
545 -
546 - // Tags (8 tools)
547 - $safe_register(new MCP_Tool_List_Tags());
548 - $safe_register(new MCP_Tool_Get_Tag());
549 - $safe_register(new MCP_Tool_Create_Tag());
550 - $safe_register(new MCP_Tool_Update_Tag());
551 - $safe_register(new MCP_Tool_Delete_Tag());
552 - $safe_register(new MCP_Tool_Get_Post_Tags());
553 - $safe_register(new MCP_Tool_Set_Post_Tags());
554 -
555 - // Featured Images & Media (6 tools)
556 - $safe_register(new MCP_Tool_Get_Featured_Image());
557 - $safe_register(new MCP_Tool_Set_Featured_Image());
558 - $safe_register(new MCP_Tool_Upload_Featured_Image());
559 - $safe_register(new MCP_Tool_Remove_Featured_Image());
560 - $safe_register(new MCP_Tool_List_Media());
561 - $safe_register(new MCP_Tool_Get_Media_Details());
562 -
563 - // Post CRUD Operations (1 tool - delete/restore disabled for safety)
564 - $safe_register(new MCP_Tool_Create_Post());
565 - // $safe_register(new MCP_Tool_Delete_Post()); // DISABLED - safety
566 - // $safe_register(new MCP_Tool_Restore_Post()); // DISABLED - safety
567 -
568 - // Bulk Operations (3 tools - bulk delete disabled for safety)
569 - $safe_register(new MCP_Tool_Bulk_Update_Meta());
570 - $safe_register(new MCP_Tool_Bulk_Set_Categories());
571 - $safe_register(new MCP_Tool_Bulk_Change_Status());
572 - // $safe_register(new MCP_Tool_Bulk_Delete_Posts()); // DISABLED - safety
573 -
574 - // WordPress Core SEO Settings (10 tools)
575 - $safe_register(new MCP_Tool_Get_Site_Info());
576 - $safe_register(new MCP_Tool_Update_Site_Info());
577 - $safe_register(new MCP_Tool_Get_Permalink_Structure());
578 - $safe_register(new MCP_Tool_Update_Permalink_Structure());
579 - $safe_register(new MCP_Tool_Get_Reading_Settings());
580 - $safe_register(new MCP_Tool_Update_Reading_Settings());
581 - $safe_register(new MCP_Tool_Get_Search_Visibility());
582 - $safe_register(new MCP_Tool_Update_Search_Visibility());
583 - $safe_register(new MCP_Tool_Get_Date_Format());
584 - $safe_register(new MCP_Tool_Get_Discussion_Settings());
585 -
586 - // Taxonomy Meta Operations (4 tools - NEW in v2.8.0)
587 - $safe_register(new MCP_Tool_Get_Term_Meta());
588 - $safe_register(new MCP_Tool_Update_Term_Meta());
589 - $safe_register(new MCP_Tool_Bulk_Update_Term_Meta());
590 - $safe_register(new MCP_Tool_List_Terms_With_Meta());
591 -
592 - // Bulk Alt Text Operations (4 tools - NEW in v2.8.0)
593 - $safe_register(new MCP_Tool_Audit_Alt_Text());
594 - $safe_register(new MCP_Tool_Bulk_Update_Alt_Text());
595 - $safe_register(new MCP_Tool_Generate_Alt_Text());
596 - $safe_register(new MCP_Tool_Validate_Alt_Text());
597 -
598 - // OTTO Persistence Settings (2 tools)
599 - if (class_exists('MCP_Tool_Get_Otto_Persistence_Settings')) {
600 - $safe_register(new MCP_Tool_Get_Otto_Persistence_Settings());
601 - }
602 - if (class_exists('MCP_Tool_Update_Otto_Persistence_Settings')) {
603 - $safe_register(new MCP_Tool_Update_Otto_Persistence_Settings());
604 - }
605 -
606 - // OTTO Pipeline Tools (3 tools)
607 - if (class_exists('MCP_Tool_Trigger_Otto_Optimization')) {
608 - $safe_register(new MCP_Tool_Trigger_Otto_Optimization());
609 - }
610 - if (class_exists('MCP_Tool_Get_Otto_Status')) {
611 - $safe_register(new MCP_Tool_Get_Otto_Status());
612 - }
613 - if (class_exists('MCP_Tool_Verify_SEO_Output')) {
614 - $safe_register(new MCP_Tool_Verify_SEO_Output());
615 - }
616 -
617 - // System Diagnostics & Plugin Info (4 tools)
618 - $safe_register(new MCP_Tool_System_Diagnostics());
619 - $safe_register(new MCP_Tool_List_All_Plugins());
620 - $safe_register(new MCP_Tool_Get_Cron_Jobs());
621 - $safe_register(new MCP_Tool_Get_WP_Option());
622 -
623 - // SEO Inventory (1 tool — WP-135)
624 - $safe_register(new MCP_Tool_List_Posts_SEO_Inventory());
625 -
626 - // Read-Only Database Access (3 tools)
627 - $safe_register(new MCP_Tool_DB_Tables());
628 - $safe_register(new MCP_Tool_DB_Describe());
629 - $safe_register(new MCP_Tool_DB_Select());
630 -
631 - // Breadcrumb Tools (1 tool)
632 - $safe_register(new MCP_Tool_Get_Breadcrumb_Path());
633 -
634 - // Cache Purge (2 tools)
635 - $safe_register(new MCP_Tool_Cache_Purge_All());
636 - $safe_register(new MCP_Tool_Cache_Purge_URL());
637 -
638 - // LLMs.txt Tools (5 tools)
639 - $safe_register(new MCP_Tool_Get_LLMs_Txt());
640 - $safe_register(new MCP_Tool_Regenerate_LLMs_Txt());
641 - $safe_register(new MCP_Tool_Get_LLMs_Txt_Settings());
642 - $safe_register(new MCP_Tool_Update_LLMs_Txt_Settings());
643 - $safe_register(new MCP_Tool_Get_Post_Markdown());
644 -
645 - // SEO Plugin Audit (4 tools — WP-202)
646 - $safe_register(new MCP_Tool_Read_SEO_Plugin_Data());
647 - $safe_register(new MCP_Tool_SEO_Plugin_Diff());
648 - if (class_exists('Metasync_Plugin_Sync')) {
649 - $safe_register(new MCP_Tool_Sync_To_Active_Plugins());
650 - }
651 - $safe_register(new MCP_Tool_Detect_SEO_Conflicts());
652 -
653 - // Allow other plugins/themes to register tools
654 - do_action('metasync_mcp_register_tools', $metasync_mcp_server);
655 -}
656 -add_action('init', 'metasync_init_mcp_server', 5);
657 -
658 638 /**
659 639 * Schedule a daily cron event to auto-purge Sync History records older than 90 days.
660 640 */
661 641 function metasync_schedule_sync_log_cleanup() {
@@ -683,76 +663,41 @@
683 663 echo '<script>window.__SA_DYO_INITIALIZED__=true;</script>' . "\n";
684 664 }
685 665 add_action('wp_head', 'metasync_output_dyo_init_flag', 1);
686 666
687 -/**
688 - * Initialize GA4 Analytics for Admin Area
689 - * Hooked to admin_init for proper WordPress lifecycle integration
690 - * Only loads after WordPress, plugins, and themes are fully loaded
691 - */
692 -function metasync_init_analytics() {
693 - // Only initialize in admin area (excludes AJAX and REST API requests)
694 - if (is_admin() && !wp_doing_ajax() && !defined('REST_REQUEST')) {
695 - Metasync_GA4::get_instance();
696 - }
697 -}
698 -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';
699 669
700 670 /**
701 - * Initialize API Backoff System
702 - * Hooked to init for proper WordPress lifecycle integration
703 - * Monitors API responses and manages exponential backoff for rate limiting
704 - * @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.
705 683 */
706 -function metasync_init_api_backoff() {
707 - // Initialize backoff manager (registers HTTP response filters)
708 - Metasync_API_Backoff_Manager::get_instance();
709 -
710 - // Initialize admin notices (only in admin area)
711 - if (is_admin()) {
712 - Metasync_API_Backoff_Notices::get_instance();
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;
713 690 }
714 -}
715 -add_action('init', 'metasync_init_api_backoff', 5);
716 -
717 -/**
718 - * Initialize Review Notice
719 - * Shows a dismissible notice asking users to rate the plugin after a usage period
720 - * @since 2.8.0
721 - */
722 -function metasync_init_review_notice() {
723 - if (is_admin()) {
724 - Metasync_Review_Notice::get_instance();
691 + if (!metasync_is_custom_or_lps_page($post->ID)) {
692 + return $post_states;
725 693 }
694 + $post_states['metasync_website_studio'] = __('Website Studio', 'metasync');
695 + return $post_states;
726 696 }
727 -add_action('init', 'metasync_init_review_notice');
728 697
729 -/**
730 - * Global convenience function to get active JWT token
731 - * Can be called from anywhere in WordPress (themes, other plugins, etc.)
732 - *
733 - * @param bool $force_refresh Force generation of new token even if cached one exists
734 - * @return string|false JWT token on success, false on failure
735 - */
736 -if (!function_exists('metasync_get_jwt_token')) {
737 - function metasync_get_jwt_token($force_refresh = false)
738 - {
739 - return Metasync::get_jwt_token($force_refresh);
740 - }
741 -}
742 698
743 -
744 699 /**
745 - * Initialize Debug Mode Manager
746 - * Hooked to 'init' for proper WordPress lifecycle integration
747 - */
748 -function metasync_init_debug_mode_manager() {
749 - // Initialize the Debug Mode Manager singleton
750 - Metasync_Debug_Mode_Manager::get_instance();
751 -}
752 -add_action('init', 'metasync_init_debug_mode_manager', 10);
753 -
754 -/**
755 700 * Oxygen Builder Compatibility
756 701 * Auto re-signs [oxygen] dynamic-data shortcodes when their HMAC signatures
757 702 * are invalid (e.g. after design-set import or site migration).
758 703 * Runs once on admin_init; skips entirely when Oxygen is inactive.
@@ -758,5 +703,6 @@
758 703 * Runs once on admin_init; skips entirely when Oxygen is inactive.
759 704 */
760 705 if (is_admin()) {
761 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);
762 708 }