. * * Context, Variables and Resolver are pure — they register no hooks and are * constructed nowhere, because the output classes and the editor UI both call * them statically. Only the four printers below wire themselves to wp_head. */ class Meta { public function __construct() { // Runs before the printers: a disabled archive 404s, and there is no // point resolving a title for a page that will not render. new Meta\Archives(); new Meta\Title(); new Meta\HeadTags(); new Meta\Social(); new Meta\Schema(); // The main query decides what Context resolves to, so anything cached from // an earlier query in the same request (a preview render, a REST call that // ran a WP_Query) has to be dropped before the real page is built. add_action('wp', [$this, 'flushResolvedContext'], 1); add_filter('rankify_admin_js_vars', [$this, 'addEditorVars']); add_action('rest_api_init', [$this, 'registerRoutes']); } /** * Reports which other SEO plugins left usable data, for the setup wizard. * * Read-only and purely informational — there is nothing to trigger, because * the values are already being served. It exists so the wizard can say "we * can see your old titles" instead of asking the user to trust that. */ public function registerRoutes() { \DaftPlug\Rankify\Helpers\Utils::registerRestRoute('/legacy-seo', [ 'methods' => 'GET', 'permission_callback' => function () { return current_user_can('manage_options'); }, 'callback' => [$this, 'handleLegacySeo'], ]); } public function handleLegacySeo() { return new \WP_REST_Response( [ 'enabled' => Meta\LegacyMeta::enabled(), 'sources' => Meta\LegacyMeta::detect(), ], 200, ); } public function flushResolvedContext() { Meta\Context::flush(); Meta\Resolver::flush(); } /** * Feed the template editor its variable catalog and preview samples. * * The catalog is the single source of what the picker offers, so a variable * the resolver does not implement can never be inserted. Both are only ever * built on a Crownify admin screen — sampleValues() runs a get_posts() call * that has no business firing on the front end. */ public function addEditorVars($vars) { $vars['metaVariables'] = Meta\Variables::catalog(); $vars['metaSamples'] = Meta\Variables::sampleValues(); $vars['metaSeparator'] = Meta\Variables::separator(); return $vars; } }