'; echo '
'; echo ''; } /** * Enqueue the widget bundle on the Dashboard screen only. * * @param string $hook_suffix Current admin page hook. * @return void */ public function enqueue_assets(string $hook_suffix): void { // Core Dashboard screen only, and only for users who can see the widget. if ($hook_suffix !== 'index.php' || !current_user_can(self::CAPABILITY)) { return; } $asset_file = THINKRANK_PLUGIN_DIR . 'assets/dashboard-widget.asset.php'; $asset = file_exists($asset_file) ? include $asset_file : [ 'dependencies' => ['wp-element', 'wp-components', 'wp-api-fetch', 'wp-i18n'], 'version' => THINKRANK_VERSION, ]; wp_enqueue_script( 'thinkrank-dashboard-widget', THINKRANK_PLUGIN_URL . 'assets/dashboard-widget.js', $asset['dependencies'], $asset['version'], true ); wp_enqueue_style( 'thinkrank-dashboard-widget', THINKRANK_PLUGIN_URL . 'assets/dashboard-widget.css', ['wp-components'], $asset['version'] ); $settings = Settings::instance(); wp_localize_script('thinkrank-dashboard-widget', 'thinkrankDashboardWidget', [ 'apiUrl' => rest_url('thinkrank/v1/'), 'restNonce' => wp_create_nonce('wp_rest'), 'connected' => (bool) $settings->get('google_account_connected', false), 'isPro' => Plan_Config::is_pro(), // is_pro() is licence-aware, so it is false on an activated-but- // unlicensed install and the bar upsold Pro to someone who already // had it. The widget needs the installed-state separately. 'isProInstalled' => defined('THINKRANK_PRO_VERSION'), 'licenseUrl' => admin_url('admin.php?page=thinkrank-license'), // Pro upsell target for the teaser bar (filterable so campaigns can // point it at a specific landing page). 'upgradeUrl' => apply_filters( 'thinkrank_dashboard_widget_upgrade_url', 'https://thinkrank.ai/#pricing' ), // The "Connect to Google Search Console" button starts the OAuth // flow directly. JS only ever gets a nonce-signed admin-post URL — // the consent URL, client id, and scopes are assembled by the proxy, // never in the browser. The flow returns to the Dashboard when done. 'connectUrl' => Google_OAuth_Proxy::get_connect_url(admin_url('index.php')), // "View More" (connected state) deep-links to Analytics › Dashboard // inside the Essential SEO SPA (nav_section/nav_item drive the tab). 'settingsUrl' => admin_url('admin.php?page=thinkrank-essential-seo&nav_section=analytics&nav_item=dashboard'), // Where the Search Console property is picked — the fix for the most // common widget error (connected account, no property selected). 'propertyUrl' => admin_url('admin.php?page=thinkrank-essential-seo&nav_section=integrations&nav_item=google-services'), ]); } }