wp-seopress
Last commit date
assets
7 months ago
inc
7 months ago
languages
7 months ago
public
7 months ago
src
7 months ago
templates
7 months ago
vendor
7 months ago
contributors.txt
7 months ago
readme.txt
7 months ago
seopress-autoload.php
7 months ago
seopress-functions.php
7 months ago
seopress.php
7 months ago
uninstall.php
7 months ago
wpml-config.xml
7 months ago
seopress.php
669 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin Name: SEOPress |
| 4 | * Plugin URI: https://www.seopress.org/ |
| 5 | * Description: One of the best SEO plugins for WordPress. |
| 6 | * Author: The SEO Guys at SEOPress |
| 7 | * Version: 9.3.0.3 |
| 8 | * Author URI: https://www.seopress.org/ |
| 9 | * License: GPLv3 or later |
| 10 | * Text Domain: wp-seopress |
| 11 | * Domain Path: /languages |
| 12 | * Requires PHP: 7.4 |
| 13 | * Requires at least: 5.0 |
| 14 | * |
| 15 | * @package SEOPress |
| 16 | */ |
| 17 | |
| 18 | /* |
| 19 | Copyright 2016 - 2025 - Benjamin Denis (email : contact@seopress.org) |
| 20 | |
| 21 | This program is free software; you can redistribute it and/or modify |
| 22 | it under the terms of the GNU General Public License, version 3, as |
| 23 | published by the Free Software Foundation. |
| 24 | |
| 25 | This program is distributed in the hope that it will be useful, |
| 26 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 | GNU General Public License for more details. |
| 29 | |
| 30 | You should have received a copy of the GNU General Public License |
| 31 | along with this program; if not, write to the Free Software |
| 32 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 33 | */ |
| 34 | |
| 35 | defined( 'ABSPATH' ) || exit( 'Please don’t call the plugin directly. Thanks :)' ); |
| 36 | |
| 37 | /** |
| 38 | * Define constants |
| 39 | */ |
| 40 | define( 'SEOPRESS_VERSION', '9.3.0.3' ); |
| 41 | define( 'SEOPRESS_AUTHOR', 'Benjamin Denis' ); |
| 42 | define( 'SEOPRESS_PLUGIN_DIR_PATH', plugin_dir_path( __FILE__ ) ); |
| 43 | define( 'SEOPRESS_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) ); |
| 44 | define( 'SEOPRESS_ASSETS_DIR', SEOPRESS_PLUGIN_DIR_URL . 'assets' ); |
| 45 | define( 'SEOPRESS_TEMPLATE_DIR', SEOPRESS_PLUGIN_DIR_PATH . 'templates' ); |
| 46 | define( 'SEOPRESS_TEMPLATE_SITEMAP_DIR', SEOPRESS_TEMPLATE_DIR . '/sitemap' ); |
| 47 | define( 'SEOPRESS_TEMPLATE_JSON_SCHEMAS', SEOPRESS_TEMPLATE_DIR . '/json-schemas' ); |
| 48 | define( 'SEOPRESS_PATH_PUBLIC', SEOPRESS_PLUGIN_DIR_PATH . 'public' ); |
| 49 | define( 'SEOPRESS_URL_PUBLIC', SEOPRESS_PLUGIN_DIR_URL . 'public' ); |
| 50 | define( 'SEOPRESS_URL_ASSETS', SEOPRESS_PLUGIN_DIR_URL . 'assets' ); |
| 51 | |
| 52 | /** |
| 53 | * Kernel |
| 54 | */ |
| 55 | use SEOPress\Core\Kernel; |
| 56 | require_once SEOPRESS_PLUGIN_DIR_PATH . 'seopress-autoload.php'; |
| 57 | |
| 58 | if ( file_exists( SEOPRESS_PLUGIN_DIR_PATH . 'vendor/autoload.php' ) ) { |
| 59 | require_once SEOPRESS_PLUGIN_DIR_PATH . 'seopress-functions.php'; |
| 60 | } |
| 61 | |
| 62 | // Initialize the kernel if the vendor autoload exists. |
| 63 | if ( file_exists( SEOPRESS_PLUGIN_DIR_PATH . 'vendor/autoload.php' ) ) { |
| 64 | Kernel::execute( |
| 65 | array( |
| 66 | 'file' => __FILE__, |
| 67 | 'slug' => 'wp-seopress', |
| 68 | 'main_file' => 'seopress', |
| 69 | 'root' => __DIR__, |
| 70 | ) |
| 71 | ); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Activation hook |
| 76 | * |
| 77 | * @return void |
| 78 | */ |
| 79 | function seopress_activation() { |
| 80 | add_option( 'seopress_activated', 'yes' ); |
| 81 | flush_rewrite_rules( false ); |
| 82 | |
| 83 | do_action( 'seopress_activation' ); |
| 84 | } |
| 85 | register_activation_hook( __FILE__, 'seopress_activation' ); |
| 86 | |
| 87 | /** |
| 88 | * Deactivation hook |
| 89 | * |
| 90 | * @return void |
| 91 | */ |
| 92 | function seopress_deactivation() { |
| 93 | deactivate_plugins( array( 'wp-seopress-pro/seopress-pro.php' ) ); |
| 94 | delete_option( 'seopress_activated' ); |
| 95 | flush_rewrite_rules( false ); |
| 96 | do_action( 'seopress_deactivation' ); |
| 97 | } |
| 98 | register_deactivation_hook( __FILE__, 'seopress_deactivation' ); |
| 99 | |
| 100 | /** |
| 101 | * Redirect User After Plugin Activation |
| 102 | * |
| 103 | * @return void |
| 104 | */ |
| 105 | function seopress_redirect_after_activation() { |
| 106 | // Do not redirect if WP is doing AJAX requests OR multisite page OR incorrect user permissions. |
| 107 | if ( wp_doing_ajax() || is_network_admin() || ! current_user_can( 'manage_options' ) ) { |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | // Check if the plugin was activated. |
| 112 | if ( get_option( 'seopress_activated' ) === 'yes' ) { |
| 113 | |
| 114 | // Delete the activation flag. |
| 115 | delete_option( 'seopress_activated' ); |
| 116 | |
| 117 | // If the wizard has already been completed, do not redirect the user. |
| 118 | $seopress_notices = get_option( 'seopress_notices', array() ); |
| 119 | |
| 120 | if ( empty( $seopress_notices ) || ! isset( $seopress_notices['notice-wizard'] ) ) { |
| 121 | wp_safe_redirect( esc_url_raw( admin_url( 'admin.php?page=seopress-setup&step=welcome&parent=welcome' ) ) ); |
| 122 | exit(); |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | add_action( 'admin_init', 'seopress_redirect_after_activation' ); |
| 127 | |
| 128 | /** |
| 129 | * Loads the SEOPress admin + core + API |
| 130 | * |
| 131 | * @param string $hook Hook. |
| 132 | * @return void |
| 133 | */ |
| 134 | function seopress_plugins_loaded( $hook ) { |
| 135 | global $pagenow, $typenow, $wp_version; |
| 136 | |
| 137 | $plugin_dir = plugin_dir_path( __FILE__ ); |
| 138 | |
| 139 | // Load Docs. |
| 140 | require_once $plugin_dir . 'inc/admin/docs/DocsLinks.php'; |
| 141 | |
| 142 | if ( is_admin() || is_network_admin() ) { |
| 143 | require_once $plugin_dir . 'inc/admin/admin.php'; |
| 144 | |
| 145 | // Load metaboxes only when editing posts or terms. |
| 146 | if ( in_array( $pagenow, array( 'post-new.php', 'post.php' ), true ) && 'seopress_schemas' !== $typenow ) { |
| 147 | require_once $plugin_dir . 'inc/admin/metaboxes/admin-metaboxes.php'; |
| 148 | } elseif ( in_array( $pagenow, array( 'term.php', 'edit-tags.php' ), true ) ) { |
| 149 | require_once $plugin_dir . 'inc/admin/metaboxes/admin-term-metaboxes.php'; |
| 150 | } |
| 151 | |
| 152 | // Load admin header unless explicitly disabled. |
| 153 | if ( ! defined( 'SEOPRESS_WL_ADMIN_HEADER' ) || SEOPRESS_WL_ADMIN_HEADER !== false ) { |
| 154 | require_once $plugin_dir . 'inc/admin/admin-bar/admin-header.php'; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // Load options and admin bar. |
| 159 | require_once $plugin_dir . 'inc/functions/options.php'; |
| 160 | require_once $plugin_dir . 'inc/admin/admin-bar/admin-bar.php'; |
| 161 | |
| 162 | // Load integrations conditionally. |
| 163 | if ( did_action( 'elementor/loaded' ) && apply_filters( 'seopress_elementor_integration_enabled', true ) ) { |
| 164 | include_once $plugin_dir . 'inc/admin/page-builders/elementor/elementor-addon.php'; |
| 165 | } |
| 166 | |
| 167 | if ( version_compare( $wp_version, '5.0', '>=' ) ) { |
| 168 | include_once $plugin_dir . 'inc/admin/page-builders/gutenberg/blocks.php'; |
| 169 | } |
| 170 | |
| 171 | if ( is_admin() ) { |
| 172 | include_once $plugin_dir . 'inc/admin/page-builders/classic/classic-editor.php'; |
| 173 | } |
| 174 | } |
| 175 | add_action( 'plugins_loaded', 'seopress_plugins_loaded', 999 ); |
| 176 | |
| 177 | /** |
| 178 | * Loads the SEOPress i18n + dynamic variables |
| 179 | * |
| 180 | * @return void |
| 181 | */ |
| 182 | function seopress_init() { |
| 183 | // i18n. |
| 184 | load_plugin_textdomain( 'wp-seopress', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
| 185 | |
| 186 | // Preload dynamic variables file. |
| 187 | include_once plugin_dir_path( __FILE__ ) . 'inc/functions/variables/dynamic-variables.php'; |
| 188 | } |
| 189 | add_action( 'init', 'seopress_init' ); |
| 190 | |
| 191 | /** |
| 192 | * Render dynamic variables |
| 193 | * |
| 194 | * @param array $variables Dynamic variables. |
| 195 | * @param object $post Post object. |
| 196 | * @param boolean $is_oembed Is oembed. |
| 197 | * @return array $variables |
| 198 | */ |
| 199 | function seopress_dyn_variables_init( $variables, $post = '', $is_oembed = false ) { |
| 200 | if ( wp_doing_ajax() ) { |
| 201 | return; |
| 202 | } |
| 203 | |
| 204 | // Use memoized function for dynamic variable retrieval. |
| 205 | return SEOPress\Helpers\CachedMemoizeFunctions::memoize( 'seopress_get_dynamic_variables' )( $variables, $post, $is_oembed ); |
| 206 | } |
| 207 | add_filter( 'seopress_dyn_variables_fn', 'seopress_dyn_variables_init', 10, 3 ); |
| 208 | |
| 209 | /** |
| 210 | * Loads the JS/CSS in admin |
| 211 | * |
| 212 | * @param string $hook Hook. |
| 213 | * @return void |
| 214 | */ |
| 215 | function seopress_add_admin_options_scripts( $hook ) { |
| 216 | $prefix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 217 | |
| 218 | // Register stylesheets. |
| 219 | wp_register_style( 'seopress-admin', plugins_url( 'assets/css/seopress' . $prefix . '.css', __FILE__ ), array(), SEOPRESS_VERSION ); |
| 220 | wp_enqueue_style( 'seopress-admin' ); |
| 221 | |
| 222 | // Early return if no page query var. |
| 223 | if ( ! isset( $_GET['page'] ) ) { |
| 224 | return; |
| 225 | } |
| 226 | |
| 227 | // Preload scripts that are required for specific pages. |
| 228 | $page = sanitize_text_field( wp_unslash( $_GET['page'] ) ); |
| 229 | $scripts = array(); |
| 230 | |
| 231 | // Network options page. |
| 232 | if ( 'seopress-network-option' === $page ) { |
| 233 | $scripts[] = 'seopress-network-tabs'; |
| 234 | } |
| 235 | |
| 236 | // Pages needing Toggle / Notices JS. |
| 237 | $pages_with_toggle_js = array_map( |
| 238 | /** |
| 239 | * Get the page name. |
| 240 | * |
| 241 | * @param string $page |
| 242 | * @return string |
| 243 | */ |
| 244 | function ( $page ) { |
| 245 | return 'seopress-' . $page; |
| 246 | }, |
| 247 | array( |
| 248 | 'setup', |
| 249 | 'option', |
| 250 | 'network-option', |
| 251 | 'titles', |
| 252 | 'xml-sitemap', |
| 253 | 'social', |
| 254 | 'google-analytics', |
| 255 | 'pro-page', |
| 256 | 'instant-indexing', |
| 257 | 'advanced', |
| 258 | 'import-export', |
| 259 | 'bot-batch', |
| 260 | 'license', |
| 261 | ) |
| 262 | ); |
| 263 | |
| 264 | if ( in_array( $page, $pages_with_toggle_js, true ) ) { |
| 265 | $scripts[] = 'seopress-dashboard'; |
| 266 | } |
| 267 | |
| 268 | // Setup Wizard page. |
| 269 | if ( 'seopress-setup' === $page ) { |
| 270 | wp_enqueue_style( 'seopress-setup', plugins_url( 'assets/css/seopress-setup' . $prefix . '.css', __FILE__ ), array(), SEOPRESS_VERSION ); |
| 271 | wp_enqueue_script( 'seopress-migrate', plugins_url( 'assets/js/seopress-migrate' . $prefix . '.js', __FILE__ ), array( 'jquery' ), SEOPRESS_VERSION, true ); |
| 272 | wp_enqueue_media(); |
| 273 | wp_enqueue_script( 'seopress-media-uploader', plugins_url( 'assets/js/seopress-media-uploader' . $prefix . '.js', __FILE__ ), array( 'jquery' ), SEOPRESS_VERSION, true ); |
| 274 | } |
| 275 | |
| 276 | // Dashboard page styles. |
| 277 | if ( 'seopress-option' === $page ) { |
| 278 | wp_register_style( 'seopress-admin-dashboard', plugins_url( 'assets/css/seopress-admin-dashboard' . $prefix . '.css', __FILE__ ), array(), SEOPRESS_VERSION ); |
| 279 | wp_enqueue_style( 'seopress-admin-dashboard' ); |
| 280 | } |
| 281 | |
| 282 | // Load common migration scripts for multiple pages. |
| 283 | if ( in_array( $page, array( 'seopress-option', 'seopress-import-export' ), true ) ) { |
| 284 | $scripts[] = 'seopress-migrate'; |
| 285 | } |
| 286 | |
| 287 | // Tabs script. |
| 288 | $pages_with_tabs = array_map( |
| 289 | /** |
| 290 | * Get the page name. |
| 291 | * |
| 292 | * @param string $page |
| 293 | * @return string |
| 294 | */ |
| 295 | function ( $page ) { |
| 296 | return 'seopress-' . $page; |
| 297 | }, |
| 298 | array( |
| 299 | 'titles', |
| 300 | 'xml-sitemap', |
| 301 | 'social', |
| 302 | 'google-analytics', |
| 303 | 'advanced', |
| 304 | 'import-export', |
| 305 | 'instant-indexing', |
| 306 | ) |
| 307 | ); |
| 308 | |
| 309 | if ( in_array( $page, $pages_with_tabs, true ) ) { |
| 310 | $scripts[] = 'seopress-tabs'; |
| 311 | } |
| 312 | |
| 313 | // Load scripts conditionally. |
| 314 | foreach ( $scripts as $script ) { |
| 315 | wp_enqueue_script( $script, plugins_url( 'assets/js/' . $script . $prefix . '.js', __FILE__ ), array( 'jquery' ), SEOPRESS_VERSION, true ); |
| 316 | } |
| 317 | |
| 318 | if ( in_array( $page, $pages_with_toggle_js, true ) ) { |
| 319 | // Features. |
| 320 | $seopress_toggle_features = array( |
| 321 | 'seopress_nonce' => wp_create_nonce( 'seopress_toggle_features_nonce' ), |
| 322 | 'seopress_toggle_features' => admin_url( 'admin-ajax.php' ), |
| 323 | 'i18n' => __( 'has been successfully updated!', 'wp-seopress' ), |
| 324 | ); |
| 325 | wp_localize_script( 'seopress-dashboard', 'seopressAjaxToggleFeatures', $seopress_toggle_features ); |
| 326 | |
| 327 | // Notices. |
| 328 | $seopress_hide_notices = array( |
| 329 | 'seopress_nonce' => wp_create_nonce( 'seopress_hide_notices_nonce' ), |
| 330 | 'seopress_hide_notices' => admin_url( 'admin-ajax.php' ), |
| 331 | ); |
| 332 | wp_localize_script( 'seopress-dashboard', 'seopressAjaxHideNotices', $seopress_hide_notices ); |
| 333 | |
| 334 | if ( 'seopress-option' === $page ) { |
| 335 | // Simple View. |
| 336 | $seopress_switch_view = array( |
| 337 | 'seopress_nonce' => wp_create_nonce( 'seopress_switch_view_nonce' ), |
| 338 | 'seopress_switch_view' => admin_url( 'admin-ajax.php' ), |
| 339 | ); |
| 340 | wp_localize_script( 'seopress-dashboard', 'seopressAjaxSwitchView', $seopress_switch_view ); |
| 341 | |
| 342 | // News panel. |
| 343 | $seopress_news = array( |
| 344 | 'seopress_nonce' => wp_create_nonce( 'seopress_news_nonce' ), |
| 345 | 'seopress_news' => admin_url( 'admin-ajax.php' ), |
| 346 | ); |
| 347 | wp_localize_script( 'seopress-dashboard', 'seopressAjaxNews', $seopress_news ); |
| 348 | |
| 349 | // Display panel. |
| 350 | $seopress_display = array( |
| 351 | 'seopress_nonce' => wp_create_nonce( 'seopress_display_nonce' ), |
| 352 | 'seopress_display' => admin_url( 'admin-ajax.php' ), |
| 353 | ); |
| 354 | wp_localize_script( 'seopress-dashboard', 'seopressAjaxDisplay', $seopress_display ); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | // Google Analytics color picker. |
| 359 | if ( 'seopress-google-analytics' === $page ) { |
| 360 | wp_enqueue_style( 'wp-color-picker' ); |
| 361 | wp_enqueue_script( 'wp-color-picker-alpha', plugins_url( 'assets/js/wp-color-picker-alpha' . $prefix . '.js', __FILE__ ), array( 'wp-color-picker' ), SEOPRESS_VERSION, true ); |
| 362 | wp_localize_script( |
| 363 | 'wp-color-picker-alpha', |
| 364 | 'wpColorPickerL10n', |
| 365 | array( |
| 366 | 'clear' => __( 'Clear', 'wp-seopress' ), |
| 367 | 'clearAriaLabel' => __( 'Clear color', 'wp-seopress' ), |
| 368 | 'defaultString' => __( 'Default', 'wp-seopress' ), |
| 369 | 'defaultAriaLabel' => __( 'Select default color', 'wp-seopress' ), |
| 370 | 'pick' => __( 'Select Color', 'wp-seopress' ), |
| 371 | 'defaultLabel' => __( 'Color value', 'wp-seopress' ), |
| 372 | ), |
| 373 | ); |
| 374 | |
| 375 | $settings = wp_enqueue_code_editor( array( 'type' => 'text/html' ) ); |
| 376 | wp_add_inline_script( |
| 377 | 'code-editor', |
| 378 | sprintf( |
| 379 | 'jQuery(function($) { |
| 380 | function initializeEditor(elementId, settings) { |
| 381 | var $textarea = $("#" + elementId); |
| 382 | if (!$textarea.data("codeMirrorInitialized")) { |
| 383 | wp.codeEditor.initialize(elementId, settings); |
| 384 | $textarea.data("codeMirrorInitialized", true); |
| 385 | } |
| 386 | } |
| 387 | function initializeEditors() { |
| 388 | initializeEditor("seopress_google_analytics_other_tracking", %s); |
| 389 | initializeEditor("seopress_google_analytics_other_tracking_body", %s); |
| 390 | initializeEditor("seopress_google_analytics_other_tracking_footer", %s); |
| 391 | } |
| 392 | $(document).ready(function() { |
| 393 | initializeEditors(); |
| 394 | setTimeout(initializeEditors, 100); |
| 395 | }); |
| 396 | });', |
| 397 | wp_json_encode( $settings ), |
| 398 | wp_json_encode( $settings ), |
| 399 | wp_json_encode( $settings ) |
| 400 | ) |
| 401 | ); |
| 402 | } |
| 403 | |
| 404 | // Localize migration data once for all migration pages. |
| 405 | if ( in_array( $page, array( 'seopress-option', 'seopress-import-export', 'seopress-setup' ), true ) ) { |
| 406 | $seopress_migrate = array( |
| 407 | 'seopress_aio_migrate' => array( |
| 408 | 'seopress_nonce' => wp_create_nonce( 'seopress_aio_migrate_nonce' ), |
| 409 | 'seopress_aio_migration' => admin_url( 'admin-ajax.php' ), |
| 410 | ), |
| 411 | 'seopress_yoast_migrate' => array( |
| 412 | 'seopress_nonce' => wp_create_nonce( 'seopress_yoast_migrate_nonce' ), |
| 413 | 'seopress_yoast_migration' => admin_url( 'admin-ajax.php' ), |
| 414 | ), |
| 415 | 'seopress_seo_framework_migrate' => array( |
| 416 | 'seopress_nonce' => wp_create_nonce( 'seopress_seo_framework_migrate_nonce' ), |
| 417 | 'seopress_seo_framework_migration' => admin_url( 'admin-ajax.php' ), |
| 418 | ), |
| 419 | 'seopress_rk_migrate' => array( |
| 420 | 'seopress_nonce' => wp_create_nonce( 'seopress_rk_migrate_nonce' ), |
| 421 | 'seopress_rk_migration' => admin_url( 'admin-ajax.php' ), |
| 422 | ), |
| 423 | 'seopress_squirrly_migrate' => array( |
| 424 | 'seopress_nonce' => wp_create_nonce( 'seopress_squirrly_migrate_nonce' ), |
| 425 | 'seopress_squirrly_migration' => admin_url( 'admin-ajax.php' ), |
| 426 | ), |
| 427 | 'seopress_seo_ultimate_migrate' => array( |
| 428 | 'seopress_nonce' => wp_create_nonce( 'seopress_seo_ultimate_migrate_nonce' ), |
| 429 | 'seopress_seo_ultimate_migration' => admin_url( 'admin-ajax.php' ), |
| 430 | ), |
| 431 | 'seopress_wp_meta_seo_migrate' => array( |
| 432 | 'seopress_nonce' => wp_create_nonce( 'seopress_meta_seo_migrate_nonce' ), |
| 433 | 'seopress_wp_meta_seo_migration' => admin_url( 'admin-ajax.php' ), |
| 434 | ), |
| 435 | 'seopress_premium_seo_pack_migrate' => array( |
| 436 | 'seopress_nonce' => wp_create_nonce( 'seopress_premium_seo_pack_migrate_nonce' ), |
| 437 | 'seopress_premium_seo_pack_migration' => admin_url( 'admin-ajax.php' ), |
| 438 | ), |
| 439 | 'seopress_wpseo_migrate' => array( |
| 440 | 'seopress_nonce' => wp_create_nonce( 'seopress_wpseo_migrate_nonce' ), |
| 441 | 'seopress_wpseo_migration' => admin_url( 'admin-ajax.php' ), |
| 442 | ), |
| 443 | 'seopress_smart_crawl_migrate' => array( |
| 444 | 'seopress_nonce' => wp_create_nonce( 'seopress_smart_crawl_migrate_nonce' ), |
| 445 | 'seopress_smart_crawl_migration' => admin_url( 'admin-ajax.php' ), |
| 446 | ), |
| 447 | 'seopress_slim_seo_migrate' => array( |
| 448 | 'seopress_nonce' => wp_create_nonce( 'seopress_slim_seo_migrate_nonce' ), |
| 449 | 'seopress_slim_seo_migration' => admin_url( 'admin-ajax.php' ), |
| 450 | ), |
| 451 | 'seopress_siteseo_migrate' => array( |
| 452 | 'seopress_nonce' => wp_create_nonce( 'seopress_siteseo_migrate_nonce' ), |
| 453 | 'seopress_siteseo_migration' => admin_url( 'admin-ajax.php' ), |
| 454 | ), |
| 455 | 'seopress_metadata_csv' => array( |
| 456 | 'seopress_nonce' => wp_create_nonce( 'seopress_export_csv_metadata_nonce' ), |
| 457 | 'seopress_metadata_export' => admin_url( 'admin-ajax.php' ), |
| 458 | ), |
| 459 | 'i18n' => array( |
| 460 | 'migration' => __( 'Migration completed!', 'wp-seopress' ), |
| 461 | 'export' => __( 'Export completed!', 'wp-seopress' ), |
| 462 | ), |
| 463 | ); |
| 464 | wp_localize_script( 'seopress-migrate', 'seopressAjaxMigrate', $seopress_migrate ); |
| 465 | } |
| 466 | |
| 467 | // Media uploader for social page. |
| 468 | if ( 'seopress-social' === $page ) { |
| 469 | wp_enqueue_script( 'seopress-media-uploader', plugins_url( 'assets/js/seopress-media-uploader' . $prefix . '.js', __FILE__ ), array( 'jquery' ), SEOPRESS_VERSION, false ); |
| 470 | wp_enqueue_media(); |
| 471 | } |
| 472 | |
| 473 | // Instant Indexing page. |
| 474 | if ( 'seopress-instant-indexing' === $page ) { |
| 475 | $seopress_instant_indexing_post = array( |
| 476 | 'seopress_nonce' => wp_create_nonce( 'seopress_instant_indexing_post_nonce' ), |
| 477 | 'seopress_instant_indexing_post' => admin_url( 'admin-ajax.php' ), |
| 478 | ); |
| 479 | wp_localize_script( 'seopress-dashboard', 'seopressAjaxInstantIndexingPost', $seopress_instant_indexing_post ); |
| 480 | |
| 481 | $seopress_instant_indexing_generate_api_key = array( |
| 482 | 'seopress_nonce' => wp_create_nonce( 'seopress_instant_indexing_generate_api_key_nonce' ), |
| 483 | 'seopress_instant_indexing_generate_api_key' => admin_url( 'admin-ajax.php' ), |
| 484 | ); |
| 485 | wp_localize_script( 'seopress-dashboard', 'seopressAjaxInstantIndexingApiKey', $seopress_instant_indexing_generate_api_key ); |
| 486 | |
| 487 | $settings = wp_enqueue_code_editor( array( 'type' => 'application/json' ) ); |
| 488 | |
| 489 | wp_add_inline_script( |
| 490 | 'code-editor', |
| 491 | sprintf( |
| 492 | 'jQuery(function($) { |
| 493 | function initializeEditor(elementId, settings) { |
| 494 | var $textarea = $("#" + elementId); |
| 495 | if (!$textarea.data("codeMirrorInitialized")) { |
| 496 | wp.codeEditor.initialize(elementId, settings); |
| 497 | $textarea.data("codeMirrorInitialized", true); |
| 498 | } |
| 499 | } |
| 500 | function initializeEditors() { |
| 501 | initializeEditor("seopress_instant_indexing_google_api_key", %s); |
| 502 | } |
| 503 | $(document).ready(function() { |
| 504 | initializeEditors(); |
| 505 | setTimeout(initializeEditors, 100); |
| 506 | }); |
| 507 | });', |
| 508 | wp_json_encode( $settings ) |
| 509 | ) |
| 510 | ); |
| 511 | } |
| 512 | |
| 513 | // CSV Importer. |
| 514 | if ( 'seopress_csv_importer' === $_GET['page'] ) { |
| 515 | wp_enqueue_style( 'seopress-setup', plugins_url( 'assets/css/seopress-setup' . $prefix . '.css', __FILE__ ), array( 'dashicons' ), SEOPRESS_VERSION ); |
| 516 | } |
| 517 | } |
| 518 | add_action( 'admin_enqueue_scripts', 'seopress_add_admin_options_scripts', 10, 1 ); |
| 519 | |
| 520 | /** |
| 521 | * Admin bar CSS. |
| 522 | * |
| 523 | * @return void |
| 524 | */ |
| 525 | function seopress_admin_bar_css() { |
| 526 | // Only run when the admin bar is showing and the user is logged in. |
| 527 | if ( is_user_logged_in() && is_admin_bar_showing() ) { |
| 528 | // Get the appearance setting only once. |
| 529 | $appearance_option = seopress_get_service( 'AdvancedOption' )->getAppearanceAdminBar(); |
| 530 | |
| 531 | // Enqueue the style only if the appearance option is not '1'. |
| 532 | if ( '1' !== $appearance_option ) { |
| 533 | $prefix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 534 | wp_enqueue_style( 'seopress-admin-bar', plugins_url( 'assets/css/seopress-admin-bar' . $prefix . '.css', __FILE__ ), array(), SEOPRESS_VERSION ); |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | add_action( 'init', 'seopress_admin_bar_css', 12 ); |
| 539 | |
| 540 | /** |
| 541 | * Quick Edit - Enqueue Scripts for All Post Types. |
| 542 | * |
| 543 | * @return void |
| 544 | */ |
| 545 | function seopress_add_admin_options_scripts_quick_edit() { |
| 546 | $screen = get_current_screen(); |
| 547 | if ( 'edit' !== $screen->base ) { |
| 548 | return; |
| 549 | } |
| 550 | |
| 551 | if ( is_plugin_active( 'admin-columns-pro/admin-columns-pro.php' ) ) { |
| 552 | return; |
| 553 | } |
| 554 | |
| 555 | $prefix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 556 | $script_url = plugins_url( 'assets/js/seopress-quick-edit' . $prefix . '.js', __FILE__ ); |
| 557 | |
| 558 | wp_enqueue_script( 'seopress-quick-edit', $script_url, array( 'jquery', 'inline-edit-post' ), SEOPRESS_VERSION, true ); |
| 559 | } |
| 560 | add_action( 'admin_print_scripts-edit.php', 'seopress_add_admin_options_scripts_quick_edit' ); |
| 561 | |
| 562 | /** |
| 563 | * Add custom body classes for specific SEOPress admin pages. |
| 564 | * |
| 565 | * @param string $classes Existing body classes. |
| 566 | * @return string Updated body classes. |
| 567 | */ |
| 568 | function seopress_admin_body_class( $classes ) { |
| 569 | if ( empty( $_GET['page'] ) ) { |
| 570 | return $classes; |
| 571 | } |
| 572 | |
| 573 | // List of pages to apply classes. |
| 574 | $seopress_pages = array( |
| 575 | 'seopress_csv_importer', |
| 576 | 'seopress-setup', |
| 577 | 'seopress-option', |
| 578 | 'seopress-network-option', |
| 579 | 'seopress-titles', |
| 580 | 'seopress-xml-sitemap', |
| 581 | 'seopress-social', |
| 582 | 'seopress-google-analytics', |
| 583 | 'seopress-advanced', |
| 584 | 'seopress-import-export', |
| 585 | 'seopress-pro-page', |
| 586 | 'seopress-instant-indexing', |
| 587 | 'seopress-bot-batch', |
| 588 | 'seopress-license', |
| 589 | ); |
| 590 | |
| 591 | $current_page = sanitize_text_field( wp_unslash( $_GET['page'] ) ); |
| 592 | |
| 593 | // Check if current page is in the defined pages. |
| 594 | if ( in_array( $current_page, $seopress_pages, true ) ) { |
| 595 | $classes .= ' seopress-styles'; |
| 596 | |
| 597 | // Additional class for specific pages. |
| 598 | if ( 'seopress-option' === $current_page ) { |
| 599 | $classes .= ' seopress-dashboard'; |
| 600 | } elseif ( in_array( $current_page, array( 'seopress_csv_importer', 'seopress-setup' ), true ) ) { |
| 601 | $classes .= ' seopress-setup'; |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | // Add white-label class if applicable. |
| 606 | if ( defined( 'SEOPRESS_WL_ADMIN_HEADER' ) && SEOPRESS_WL_ADMIN_HEADER === false ) { |
| 607 | $classes .= ' seopress-white-label'; |
| 608 | } |
| 609 | |
| 610 | // Add simple view class if applicable. |
| 611 | if ( ! empty( get_option( 'seopress_dashboard' ) ) ) { |
| 612 | if ( 'simple' === get_option( 'seopress_dashboard' )['view'] ) { |
| 613 | $classes .= ' seopress-simple-view'; |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | return $classes; |
| 618 | } |
| 619 | add_filter( 'admin_body_class', 'seopress_admin_body_class', 100 ); |
| 620 | |
| 621 | /** |
| 622 | * Plugin action links. |
| 623 | * |
| 624 | * @param string $links Plugin action links. |
| 625 | * @param string $file Plugin file. |
| 626 | * @return array $links Plugin action links. |
| 627 | */ |
| 628 | function seopress_plugin_action_links( $links, $file ) { |
| 629 | static $this_plugin; |
| 630 | if ( ! $this_plugin ) { |
| 631 | $this_plugin = plugin_basename( __FILE__ ); |
| 632 | } |
| 633 | |
| 634 | if ( $file === $this_plugin ) { |
| 635 | // Define action links. |
| 636 | $settings_link = '<a href="' . admin_url( 'admin.php?page=seopress-option' ) . '">' . __( 'Settings', 'wp-seopress' ) . '</a>'; |
| 637 | $wizard_link = '<a href="' . admin_url( 'admin.php?page=seopress-setup&step=welcome&parent=welcome' ) . '">' . __( 'Configuration Wizard', 'wp-seopress' ) . '</a>'; |
| 638 | $website_link = '<a href="https://www.seopress.org/support/" target="_blank">' . __( 'Docs', 'wp-seopress' ) . '</a>'; |
| 639 | |
| 640 | // Add "GO PRO!" link for non-PRO users. |
| 641 | if ( ! is_plugin_active( 'wp-seopress-pro/seopress-pro.php' ) ) { |
| 642 | $pro_link = '<a href="https://www.seopress.org/seopress-pro/" style="color:red;font-weight:bold" target="_blank">' . __( 'GO PRO!', 'wp-seopress' ) . '</a>'; |
| 643 | array_unshift( $links, $pro_link ); |
| 644 | } |
| 645 | |
| 646 | // Remove "Deactivate" link if PRO plugins are active. |
| 647 | $is_pro_active = is_plugin_active( 'wp-seopress-pro/seopress-pro.php' ); |
| 648 | if ( $is_pro_active && isset( $links['deactivate'] ) ) { |
| 649 | unset( $links['deactivate'] ); |
| 650 | } |
| 651 | |
| 652 | // Determine white-label behavior. |
| 653 | $use_white_label_links = function_exists( 'seopress_pro_get_service' ) && |
| 654 | '1' === seopress_get_service( 'ToggleOption' )->getToggleWhiteLabel() && |
| 655 | method_exists( seopress_pro_get_service( 'OptionPro' ), 'getWhiteLabelHelpLinks' ) && |
| 656 | '1' === seopress_pro_get_service( 'OptionPro' )->getWhiteLabelHelpLinks(); |
| 657 | |
| 658 | // Add appropriate links. |
| 659 | if ( $use_white_label_links ) { |
| 660 | array_unshift( $links, $settings_link, $wizard_link ); |
| 661 | } else { |
| 662 | array_unshift( $links, $settings_link, $wizard_link, $website_link ); |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | return $links; |
| 667 | } |
| 668 | add_filter( 'plugin_action_links', 'seopress_plugin_action_links', 10, 2 ); |
| 669 |