PluginProbe
Search Atlas SEO – OTTO AI SEO Automation for WordPress / 2.7.2
Search Atlas SEO – OTTO AI SEO Automation for WordPress v2.7.2
2.7.1 2.7.2 2.7.0 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 All 141 releases
metasync / includes / class-metasync-admin-assets.php

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

218 lines 8.2 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) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only page check to enqueue wizard assets
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 wp_enqueue_script(
110 $plugin_name . '-color-palette',
111 $admin_dir_url . 'js/metasync-color-palette.js',
112 array('jquery'),
113 $version,
114 true
115 );
116
117 $options = Metasync::get_option('general');
118 $general_settings = Metasync::get_option('general');
119 $searchatlas_api_key = isset($general_settings['searchatlas_api_key']) ? $general_settings['searchatlas_api_key'] : '';
120 $otto_pixel_uuid = isset($general_settings['otto_pixel_uuid']) ? $general_settings['otto_pixel_uuid'] : '';
121
122 // SECURITY FIX (CVE-2025-14386): Only generate Search Atlas connect nonce for administrators
123 $sa_connect_nonce = '';
124 if (current_user_can('manage_options')) {
125 $sa_connect_nonce = wp_create_nonce('metasync_sa_connect_nonce');
126 }
127
128 $heartbeat_state = Metasync_Heartbeat_Manager::instance()->get_heartbeat_state();
129 wp_localize_script( $plugin_name, 'metaSync', array(
130 'ajax_url' => admin_url( 'admin-ajax.php' ),
131 'admin_url'=>admin_url('admin.php'),
132 'sa_connect_nonce' => $sa_connect_nonce,
133 'reset_auth_nonce' => wp_create_nonce('metasync_reset_auth_nonce'),
134 'burst_ping_nonce' => wp_create_nonce('metasync_burst_ping'),
135 'clear_otto_cache_nonce' => wp_create_nonce('metasync_clear_otto_cache'),
136 'lglogin_nonce' => wp_create_nonce('metasync_lglogin'),
137 'heartbeat_state' => $heartbeat_state,
138 'dashboard_domain' => Metasync_Admin::get_effective_dashboard_domain(),
139 'support_email' => Metasync::SUPPORT_EMAIL,
140 'documentation_domain' => Metasync::DOCUMENTATION_DOMAIN,
141 'debug_enabled' => WP_DEBUG || (defined('METASYNC_DEBUG') && constant('METASYNC_DEBUG')),
142 'searchatlas_api_key' => !empty($searchatlas_api_key),
143 'otto_pixel_uuid' => $otto_pixel_uuid,
144 'is_connected' => (bool)Metasync_Heartbeat_Manager::instance()->is_heartbeat_connected()
145 ));
146
147 wp_enqueue_script('wp-util');
148
149 $inline_script = "
150 if (typeof ajaxurl === 'undefined') {
151 var ajaxurl = '" . esc_js(admin_url('admin-ajax.php')) . "';
152 }
153
154 // Add Plugin Auth Token refresh functionality
155 jQuery(document).ready(function($) {
156 $('#refresh-plugin-auth-token').click(function() {
157 var button = $(this);
158 var originalText = button.text();
159
160 if (confirm('Are you sure you want to refresh the Plugin Auth Token? This will generate a new token and update the heartbeat API.')) {
161 // Disable button and show loading
162 button.prop('disabled', true).text('🔄 Refreshing...');
163
164 $.post(ajaxurl, {
165 action: 'metasync_refresh_plugin_auth_token',
166 nonce: '" . wp_create_nonce('metasync_refresh_plugin_auth_token') . "'
167 })
168 .done(function(response) {
169 if (response.success && response.data && response.data.new_token) {
170 // Update the field value immediately
171 $('#apikey').val(response.data.new_token);
172
173 // Visual feedback with green border
174 $('#apikey').css('border', '2px solid #28a745').animate({borderColor: '#ddd'}, 2000);
175
176 alert('�
177 Plugin Auth Token refreshed successfully!\\n\\nNew token: ' + response.data.new_token.substring(0, 8) + '...');
178 } else {
179 alert('❌ Error refreshing token: ' + (response.data ? response.data.message : 'Unknown error'));
180 }
181 })
182 .fail(function() {
183 alert('❌ Network error while refreshing token');
184 })
185 .always(function() {
186 // Re-enable button
187 button.prop('disabled', false).text(originalText);
188 });
189 }
190 });
191 });
192 ";
193 wp_add_inline_script($plugin_name, $inline_script);
194
195 if (isset($_GET['page']) && strpos($_GET['page'], '-setup-wizard') !== false) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only page check to enqueue wizard assets
196 wp_enqueue_script(
197 $plugin_name . '-setup-wizard',
198 $admin_dir_url . 'js/metasync-setup-wizard.js',
199 array('jquery'),
200 $version,
201 true
202 );
203
204 wp_localize_script($plugin_name . '-setup-wizard', 'metasyncWizardData', array(
205 'nonce' => wp_create_nonce('metasync_wizard'),
206 'ssoNonce' => wp_create_nonce('metasync_sso_nonce'),
207 'importNonce' => wp_create_nonce('metasync_import_external_data'),
208 'dashboardUrl' => admin_url('admin.php?page=' . Metasync_Admin::$page_slug . '-dashboard'),
209 'currentStep' => 1,
210 'totalSteps' => 6,
211 'pluginName' => Metasync::get_effective_plugin_name()
212 ));
213 }
214
215 wp_enqueue_script('heartbeat');
216 }
217 }
218