PluginProbe
Search Atlas SEO – OTTO AI SEO Automation for WordPress / 2.5.23
Search Atlas SEO – OTTO AI SEO Automation for WordPress v2.5.23
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
metasync / includes / class-metasync-admin-assets.php

class-metasync-admin-assets.php in Search Atlas SEO – OTTO AI SEO Automation for WordPress 2.5.23, at includes/class-metasync-admin-assets.php

208 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) {
3 exit;
4 }
5
6 /**
7 * Admin Asset Enqueuing
8 *
9 * Registers and enqueues all admin-side CSS and JavaScript files.
10 *
11 * @package Metasync
12 * @subpackage Metasync/includes
13 */
14 class Metasync_Admin_Assets
15 {
16 private static $instance = null;
17
18 public static function instance()
19 {
20 if (null === self::$instance) {
21 self::$instance = new self();
22 }
23 return self::$instance;
24 }
25
26 private function __construct() {}
27
28 /**
29 * Register the stylesheets for the admin area.
30 *
31 * @param string $plugin_name The plugin identifier.
32 * @param string $version The plugin version.
33 * @param string $admin_dir_url URL to the admin/ directory (trailing slash).
34 */
35 public function enqueue_styles($plugin_name, $version, $admin_dir_url)
36 {
37 wp_enqueue_style(
38 $plugin_name,
39 $admin_dir_url . 'css/metasync-admin.css',
40 array(),
41 $version,
42 'all'
43 );
44
45 wp_enqueue_style(
46 $plugin_name . '-dashboard',
47 $admin_dir_url . 'css/metasync-dashboard.css',
48 array($plugin_name),
49 $version,
50 'all'
51 );
52
53 if (isset($_GET['page']) && strpos($_GET['page'], '-setup-wizard') !== false) {
54 wp_enqueue_style(
55 $plugin_name . '-setup-wizard',
56 $admin_dir_url . 'css/metasync-setup-wizard.css',
57 array($plugin_name . '-dashboard'),
58 $version,
59 'all'
60 );
61 }
62 }
63
64 /**
65 * Register the JavaScript for the admin area.
66 *
67 * @param string $plugin_name The plugin identifier.
68 * @param string $version The plugin version.
69 * @param string $admin_dir_url URL to the admin/ directory (trailing slash).
70 */
71 public function enqueue_scripts($plugin_name, $version, $admin_dir_url)
72 {
73 wp_enqueue_media();
74
75 wp_enqueue_script(
76 $plugin_name,
77 $admin_dir_url . 'js/metasync-admin.js',
78 array('jquery'),
79 $version,
80 false
81 );
82
83 wp_enqueue_script(
84 $plugin_name . '-dashboard',
85 $admin_dir_url . 'js/metasync-dashboard.js',
86 array('jquery', $plugin_name),
87 $version,
88 true
89 );
90
91 wp_enqueue_script(
92 $plugin_name . '-theme-switcher',
93 $admin_dir_url . 'js/metasync-theme-switcher.js',
94 array('jquery'),
95 $version,
96 true
97 );
98
99 wp_localize_script(
100 $plugin_name . '-theme-switcher',
101 'metasyncThemeData',
102 array(
103 'ajaxUrl' => admin_url('admin-ajax.php'),
104 'nonce' => wp_create_nonce('metasync_theme_nonce'),
105 'currentTheme' => get_option('metasync_theme', 'dark')
106 )
107 );
108
109 $options = Metasync::get_option('general');
110 $general_settings = Metasync::get_option('general');
111 $searchatlas_api_key = isset($general_settings['searchatlas_api_key']) ? $general_settings['searchatlas_api_key'] : '';
112 $otto_pixel_uuid = isset($general_settings['otto_pixel_uuid']) ? $general_settings['otto_pixel_uuid'] : '';
113
114 // SECURITY FIX (CVE-2025-14386): Only generate Search Atlas connect nonce for administrators
115 $sa_connect_nonce = '';
116 if (current_user_can('manage_options')) {
117 $sa_connect_nonce = wp_create_nonce('metasync_sa_connect_nonce');
118 }
119
120 $heartbeat_state = Metasync_Heartbeat_Manager::instance()->get_heartbeat_state();
121 wp_localize_script( $plugin_name, 'metaSync', array(
122 'ajax_url' => admin_url( 'admin-ajax.php' ),
123 'admin_url'=>admin_url('admin.php'),
124 'sa_connect_nonce' => $sa_connect_nonce,
125 'reset_auth_nonce' => wp_create_nonce('metasync_reset_auth_nonce'),
126 'burst_ping_nonce' => wp_create_nonce('metasync_burst_ping'),
127 'heartbeat_state' => $heartbeat_state,
128 'dashboard_domain' => Metasync_Admin::get_effective_dashboard_domain(),
129 'support_email' => Metasync::SUPPORT_EMAIL,
130 'documentation_domain' => Metasync::DOCUMENTATION_DOMAIN,
131 'debug_enabled' => WP_DEBUG || (defined('METASYNC_DEBUG') && constant('METASYNC_DEBUG')),
132 'searchatlas_api_key' => !empty($searchatlas_api_key),
133 'otto_pixel_uuid' => $otto_pixel_uuid,
134 'is_connected' => (bool)Metasync_Heartbeat_Manager::instance()->is_heartbeat_connected()
135 ));
136
137 wp_enqueue_script('wp-util');
138
139 $inline_script = "
140 if (typeof ajaxurl === 'undefined') {
141 var ajaxurl = '" . esc_js(admin_url('admin-ajax.php')) . "';
142 }
143
144 // Add Plugin Auth Token refresh functionality
145 jQuery(document).ready(function($) {
146 $('#refresh-plugin-auth-token').click(function() {
147 var button = $(this);
148 var originalText = button.text();
149
150 if (confirm('Are you sure you want to refresh the Plugin Auth Token? This will generate a new token and update the heartbeat API.')) {
151 // Disable button and show loading
152 button.prop('disabled', true).text('🔄 Refreshing...');
153
154 $.post(ajaxurl, {
155 action: 'refresh_plugin_auth_token',
156 nonce: '" . wp_create_nonce('refresh_plugin_auth_token') . "'
157 })
158 .done(function(response) {
159 if (response.success && response.data && response.data.new_token) {
160 // Update the field value immediately
161 $('#apikey').val(response.data.new_token);
162
163 // Visual feedback with green border
164 $('#apikey').css('border', '2px solid #28a745').animate({borderColor: '#ddd'}, 2000);
165
166 alert('�
167 Plugin Auth Token refreshed successfully!\\n\\nNew token: ' + response.data.new_token.substring(0, 8) + '...');
168 } else {
169 alert('❌ Error refreshing token: ' + (response.data ? response.data.message : 'Unknown error'));
170 }
171 })
172 .fail(function() {
173 alert('❌ Network error while refreshing token');
174 })
175 .always(function() {
176 // Re-enable button
177 button.prop('disabled', false).text(originalText);
178 });
179 }
180 });
181 });
182 ";
183 wp_add_inline_script($plugin_name, $inline_script);
184
185 if (isset($_GET['page']) && strpos($_GET['page'], '-setup-wizard') !== false) {
186 wp_enqueue_script(
187 $plugin_name . '-setup-wizard',
188 $admin_dir_url . 'js/metasync-setup-wizard.js',
189 array('jquery'),
190 $version,
191 true
192 );
193
194 wp_localize_script($plugin_name . '-setup-wizard', 'metasyncWizardData', array(
195 'nonce' => wp_create_nonce('metasync_wizard'),
196 'ssoNonce' => wp_create_nonce('metasync_sso_nonce'),
197 'importNonce' => wp_create_nonce('metasync_import_external_data'),
198 'dashboardUrl' => admin_url('admin.php?page=' . Metasync_Admin::$page_slug . '-dashboard'),
199 'currentStep' => 1,
200 'totalSteps' => 6,
201 'pluginName' => Metasync::get_effective_plugin_name()
202 ));
203 }
204
205 wp_enqueue_script('heartbeat');
206 }
207 }
208