wordpress-seo
Last commit date
admin
3 years ago
css
3 years ago
images
3 years ago
inc
3 years ago
js
3 years ago
lib
3 years ago
packages
3 years ago
src
3 years ago
vendor
3 years ago
vendor_prefixed
3 years ago
index.php
10 years ago
license.txt
8 years ago
readme.txt
3 years ago
wp-seo-main.php
3 years ago
wp-seo.php
3 years ago
wpml-config.xml
3 years ago
wp-seo-main.php
570 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WPSEO plugin file. |
| 4 | * |
| 5 | * @package WPSEO\Main |
| 6 | */ |
| 7 | |
| 8 | if ( ! function_exists( 'add_filter' ) ) { |
| 9 | header( 'Status: 403 Forbidden' ); |
| 10 | header( 'HTTP/1.1 403 Forbidden' ); |
| 11 | exit(); |
| 12 | } |
| 13 | |
| 14 | /** |
| 15 | * {@internal Nobody should be able to overrule the real version number as this can cause |
| 16 | * serious issues with the options, so no if ( ! defined() ).}} |
| 17 | */ |
| 18 | define( 'WPSEO_VERSION', '20.2.1' ); |
| 19 | |
| 20 | |
| 21 | if ( ! defined( 'WPSEO_PATH' ) ) { |
| 22 | define( 'WPSEO_PATH', plugin_dir_path( WPSEO_FILE ) ); |
| 23 | } |
| 24 | |
| 25 | if ( ! defined( 'WPSEO_BASENAME' ) ) { |
| 26 | define( 'WPSEO_BASENAME', plugin_basename( WPSEO_FILE ) ); |
| 27 | } |
| 28 | |
| 29 | /* |
| 30 | * {@internal The prefix constants are used to build prefixed versions of dependencies. |
| 31 | * These should not be changed on run-time, thus missing the ! defined() check.}} |
| 32 | */ |
| 33 | define( 'YOAST_VENDOR_NS_PREFIX', 'YoastSEO_Vendor' ); |
| 34 | define( 'YOAST_VENDOR_DEFINE_PREFIX', 'YOASTSEO_VENDOR__' ); |
| 35 | define( 'YOAST_VENDOR_PREFIX_DIRECTORY', 'vendor_prefixed' ); |
| 36 | |
| 37 | define( 'YOAST_SEO_PHP_REQUIRED', '5.6' ); |
| 38 | define( 'YOAST_SEO_WP_TESTED', '6.1.1' ); |
| 39 | define( 'YOAST_SEO_WP_REQUIRED', '6.0' ); |
| 40 | |
| 41 | if ( ! defined( 'WPSEO_NAMESPACES' ) ) { |
| 42 | define( 'WPSEO_NAMESPACES', true ); |
| 43 | } |
| 44 | |
| 45 | |
| 46 | /* ***************************** CLASS AUTOLOADING *************************** */ |
| 47 | |
| 48 | /** |
| 49 | * Autoload our class files. |
| 50 | * |
| 51 | * @param string $class_name Class name. |
| 52 | * |
| 53 | * @return void |
| 54 | */ |
| 55 | function wpseo_auto_load( $class_name ) { |
| 56 | static $classes = null; |
| 57 | |
| 58 | if ( $classes === null ) { |
| 59 | $classes = [ |
| 60 | 'wp_list_table' => ABSPATH . 'wp-admin/includes/class-wp-list-table.php', |
| 61 | 'walker_category' => ABSPATH . 'wp-includes/category-template.php', |
| 62 | ]; |
| 63 | } |
| 64 | |
| 65 | $cn = strtolower( $class_name ); |
| 66 | |
| 67 | if ( ! class_exists( $class_name ) && isset( $classes[ $cn ] ) ) { |
| 68 | require_once $classes[ $cn ]; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | $yoast_autoload_file = WPSEO_PATH . 'vendor/autoload.php'; |
| 73 | |
| 74 | if ( is_readable( $yoast_autoload_file ) ) { |
| 75 | $yoast_autoloader = require $yoast_autoload_file; |
| 76 | } |
| 77 | elseif ( ! class_exists( 'WPSEO_Options' ) ) { // Still checking since might be site-level autoload R. |
| 78 | add_action( 'admin_init', 'yoast_wpseo_missing_autoload', 1 ); |
| 79 | |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | if ( function_exists( 'spl_autoload_register' ) ) { |
| 84 | spl_autoload_register( 'wpseo_auto_load' ); |
| 85 | } |
| 86 | require_once WPSEO_PATH . 'src/functions.php'; |
| 87 | |
| 88 | /* ********************* DEFINES DEPENDING ON AUTOLOADED CODE ********************* */ |
| 89 | |
| 90 | /** |
| 91 | * Defaults to production, for safety. |
| 92 | */ |
| 93 | if ( ! defined( 'YOAST_ENVIRONMENT' ) ) { |
| 94 | define( 'YOAST_ENVIRONMENT', 'production' ); |
| 95 | } |
| 96 | |
| 97 | if ( YOAST_ENVIRONMENT === 'development' && isset( $yoast_autoloader ) ) { |
| 98 | add_action( |
| 99 | 'plugins_loaded', |
| 100 | /** |
| 101 | * Reregisters the autoloader so that Yoast SEO is at the front. |
| 102 | * This prevents conflicts with the development versions of our addons. |
| 103 | * An anonymous function is used so we can use the autoloader variable. |
| 104 | * As this is only loaded in development removing this action is not a concern. |
| 105 | * |
| 106 | * @return void |
| 107 | */ |
| 108 | static function() use ( $yoast_autoloader ) { |
| 109 | $yoast_autoloader->unregister(); |
| 110 | $yoast_autoloader->register( true ); |
| 111 | }, |
| 112 | 1 |
| 113 | ); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Only use minified assets when we are in a production environment. |
| 118 | */ |
| 119 | if ( ! defined( 'WPSEO_CSSJS_SUFFIX' ) ) { |
| 120 | define( 'WPSEO_CSSJS_SUFFIX', ( YOAST_ENVIRONMENT !== 'development' ) ? '.min' : '' ); |
| 121 | } |
| 122 | |
| 123 | /* ***************************** PLUGIN (DE-)ACTIVATION *************************** */ |
| 124 | |
| 125 | /** |
| 126 | * Run single site / network-wide activation of the plugin. |
| 127 | * |
| 128 | * @param bool $networkwide Whether the plugin is being activated network-wide. |
| 129 | */ |
| 130 | function wpseo_activate( $networkwide = false ) { |
| 131 | if ( ! is_multisite() || ! $networkwide ) { |
| 132 | _wpseo_activate(); |
| 133 | } |
| 134 | else { |
| 135 | /* Multi-site network activation - activate the plugin for all blogs. */ |
| 136 | wpseo_network_activate_deactivate( true ); |
| 137 | } |
| 138 | |
| 139 | // This is done so that the 'uninstall_{$file}' is triggered. |
| 140 | register_uninstall_hook( WPSEO_FILE, '__return_false' ); |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Run single site / network-wide de-activation of the plugin. |
| 145 | * |
| 146 | * @param bool $networkwide Whether the plugin is being de-activated network-wide. |
| 147 | */ |
| 148 | function wpseo_deactivate( $networkwide = false ) { |
| 149 | if ( ! is_multisite() || ! $networkwide ) { |
| 150 | _wpseo_deactivate(); |
| 151 | } |
| 152 | else { |
| 153 | /* Multi-site network activation - de-activate the plugin for all blogs. */ |
| 154 | wpseo_network_activate_deactivate( false ); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Run network-wide (de-)activation of the plugin. |
| 160 | * |
| 161 | * @param bool $activate True for plugin activation, false for de-activation. |
| 162 | */ |
| 163 | function wpseo_network_activate_deactivate( $activate = true ) { |
| 164 | global $wpdb; |
| 165 | |
| 166 | $network_blogs = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE site_id = %d", $wpdb->siteid ) ); |
| 167 | |
| 168 | if ( is_array( $network_blogs ) && $network_blogs !== [] ) { |
| 169 | foreach ( $network_blogs as $blog_id ) { |
| 170 | switch_to_blog( $blog_id ); |
| 171 | |
| 172 | if ( $activate === true ) { |
| 173 | _wpseo_activate(); |
| 174 | } |
| 175 | else { |
| 176 | _wpseo_deactivate(); |
| 177 | } |
| 178 | |
| 179 | restore_current_blog(); |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Runs on activation of the plugin. |
| 186 | */ |
| 187 | function _wpseo_activate() { |
| 188 | require_once WPSEO_PATH . 'inc/wpseo-functions.php'; |
| 189 | require_once WPSEO_PATH . 'inc/class-wpseo-installation.php'; |
| 190 | |
| 191 | wpseo_load_textdomain(); // Make sure we have our translations available for the defaults. |
| 192 | |
| 193 | new WPSEO_Installation(); |
| 194 | |
| 195 | WPSEO_Options::get_instance(); |
| 196 | if ( ! is_multisite() ) { |
| 197 | WPSEO_Options::initialize(); |
| 198 | } |
| 199 | else { |
| 200 | WPSEO_Options::maybe_set_multisite_defaults( true ); |
| 201 | } |
| 202 | WPSEO_Options::ensure_options_exist(); |
| 203 | |
| 204 | if ( is_multisite() && ms_is_switched() ) { |
| 205 | update_option( 'rewrite_rules', '' ); |
| 206 | } |
| 207 | else { |
| 208 | if ( WPSEO_Options::get( 'stripcategorybase' ) === true ) { |
| 209 | // Constructor has side effects so this registers all hooks. |
| 210 | $GLOBALS['wpseo_rewrite'] = new WPSEO_Rewrite(); |
| 211 | } |
| 212 | add_action( 'shutdown', 'flush_rewrite_rules' ); |
| 213 | } |
| 214 | |
| 215 | // Reset tracking to be disabled by default. |
| 216 | if ( ! YoastSEO()->helpers->product->is_premium() ) { |
| 217 | WPSEO_Options::set( 'tracking', false ); |
| 218 | } |
| 219 | |
| 220 | WPSEO_Options::set( 'indexing_reason', 'first_install' ); |
| 221 | WPSEO_Options::set( 'first_time_install', true ); |
| 222 | if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) { |
| 223 | WPSEO_Options::set( 'should_redirect_after_install_free', true ); |
| 224 | } |
| 225 | else { |
| 226 | WPSEO_Options::set( 'activation_redirect_timestamp_free', \time() ); |
| 227 | } |
| 228 | |
| 229 | do_action( 'wpseo_register_roles' ); |
| 230 | WPSEO_Role_Manager_Factory::get()->add(); |
| 231 | |
| 232 | do_action( 'wpseo_register_capabilities' ); |
| 233 | WPSEO_Capability_Manager_Factory::get()->add(); |
| 234 | |
| 235 | // Clear cache so the changes are obvious. |
| 236 | WPSEO_Utils::clear_cache(); |
| 237 | |
| 238 | do_action( 'wpseo_activate' ); |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * On deactivation, flush the rewrite rules so XML sitemaps stop working. |
| 243 | */ |
| 244 | function _wpseo_deactivate() { |
| 245 | require_once WPSEO_PATH . 'inc/wpseo-functions.php'; |
| 246 | |
| 247 | if ( is_multisite() && ms_is_switched() ) { |
| 248 | update_option( 'rewrite_rules', '' ); |
| 249 | } |
| 250 | else { |
| 251 | add_action( 'shutdown', 'flush_rewrite_rules' ); |
| 252 | } |
| 253 | |
| 254 | // Register capabilities, to make sure they are cleaned up. |
| 255 | do_action( 'wpseo_register_roles' ); |
| 256 | do_action( 'wpseo_register_capabilities' ); |
| 257 | |
| 258 | // Clean up capabilities. |
| 259 | WPSEO_Role_Manager_Factory::get()->remove(); |
| 260 | WPSEO_Capability_Manager_Factory::get()->remove(); |
| 261 | |
| 262 | // Clear cache so the changes are obvious. |
| 263 | WPSEO_Utils::clear_cache(); |
| 264 | |
| 265 | do_action( 'wpseo_deactivate' ); |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Run wpseo activation routine on creation / activation of a multisite blog if WPSEO is activated |
| 270 | * network-wide. |
| 271 | * |
| 272 | * Will only be called by multisite actions. |
| 273 | * |
| 274 | * {@internal Unfortunately will fail if the plugin is in the must-use directory. |
| 275 | * {@link https://core.trac.wordpress.org/ticket/24205} }} |
| 276 | * |
| 277 | * @param int|WP_Site $blog_id Blog ID. |
| 278 | */ |
| 279 | function wpseo_on_activate_blog( $blog_id ) { |
| 280 | if ( ! function_exists( 'is_plugin_active_for_network' ) ) { |
| 281 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 282 | } |
| 283 | |
| 284 | if ( $blog_id instanceof WP_Site ) { |
| 285 | $blog_id = (int) $blog_id->blog_id; |
| 286 | } |
| 287 | |
| 288 | if ( is_plugin_active_for_network( WPSEO_BASENAME ) ) { |
| 289 | switch_to_blog( $blog_id ); |
| 290 | wpseo_activate( false ); |
| 291 | restore_current_blog(); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | /* ***************************** PLUGIN LOADING *************************** */ |
| 296 | |
| 297 | /** |
| 298 | * Load translations. |
| 299 | */ |
| 300 | function wpseo_load_textdomain() { |
| 301 | $wpseo_path = str_replace( '\\', '/', WPSEO_PATH ); |
| 302 | $mu_path = str_replace( '\\', '/', WPMU_PLUGIN_DIR ); |
| 303 | |
| 304 | if ( stripos( $wpseo_path, $mu_path ) !== false ) { |
| 305 | load_muplugin_textdomain( 'wordpress-seo', dirname( WPSEO_BASENAME ) . '/languages/' ); |
| 306 | } |
| 307 | else { |
| 308 | load_plugin_textdomain( 'wordpress-seo', false, dirname( WPSEO_BASENAME ) . '/languages/' ); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | add_action( 'plugins_loaded', 'wpseo_load_textdomain' ); |
| 313 | |
| 314 | |
| 315 | /** |
| 316 | * On plugins_loaded: load the minimum amount of essential files for this plugin. |
| 317 | */ |
| 318 | function wpseo_init() { |
| 319 | require_once WPSEO_PATH . 'inc/wpseo-functions.php'; |
| 320 | require_once WPSEO_PATH . 'inc/wpseo-functions-deprecated.php'; |
| 321 | |
| 322 | // Make sure our option and meta value validation routines and default values are always registered and available. |
| 323 | WPSEO_Options::get_instance(); |
| 324 | WPSEO_Meta::init(); |
| 325 | |
| 326 | if ( version_compare( WPSEO_Options::get( 'version', 1 ), WPSEO_VERSION, '<' ) ) { |
| 327 | if ( function_exists( 'opcache_reset' ) ) { |
| 328 | // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Prevent notices when opcache.restrict_api is set. |
| 329 | @opcache_reset(); |
| 330 | } |
| 331 | |
| 332 | new WPSEO_Upgrade(); |
| 333 | // Get a cleaned up version of the $options. |
| 334 | } |
| 335 | |
| 336 | if ( WPSEO_Options::get( 'stripcategorybase' ) === true ) { |
| 337 | $GLOBALS['wpseo_rewrite'] = new WPSEO_Rewrite(); |
| 338 | } |
| 339 | |
| 340 | if ( WPSEO_Options::get( 'enable_xml_sitemap' ) === true ) { |
| 341 | $GLOBALS['wpseo_sitemaps'] = new WPSEO_Sitemaps(); |
| 342 | } |
| 343 | |
| 344 | if ( ! wp_doing_ajax() ) { |
| 345 | require_once WPSEO_PATH . 'inc/wpseo-non-ajax-functions.php'; |
| 346 | } |
| 347 | |
| 348 | // Init it here because the filter must be present on the frontend as well or it won't work in the customizer. |
| 349 | new WPSEO_Customizer(); |
| 350 | |
| 351 | $integrations = []; |
| 352 | $integrations[] = new WPSEO_Slug_Change_Watcher(); |
| 353 | |
| 354 | foreach ( $integrations as $integration ) { |
| 355 | $integration->register_hooks(); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * Loads the rest api endpoints. |
| 361 | */ |
| 362 | function wpseo_init_rest_api() { |
| 363 | // We can't do anything when requirements are not met. |
| 364 | if ( ! WPSEO_Utils::is_api_available() ) { |
| 365 | return; |
| 366 | } |
| 367 | |
| 368 | // Boot up REST API. |
| 369 | $statistics_service = new WPSEO_Statistics_Service( new WPSEO_Statistics() ); |
| 370 | |
| 371 | $endpoints = []; |
| 372 | $endpoints[] = new WPSEO_Endpoint_File_Size( new WPSEO_File_Size_Service() ); |
| 373 | $endpoints[] = new WPSEO_Endpoint_Statistics( $statistics_service ); |
| 374 | |
| 375 | foreach ( $endpoints as $endpoint ) { |
| 376 | $endpoint->register(); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * Used to load the required files on the plugins_loaded hook, instead of immediately. |
| 382 | */ |
| 383 | function wpseo_admin_init() { |
| 384 | new WPSEO_Admin_Init(); |
| 385 | } |
| 386 | |
| 387 | /* ***************************** BOOTSTRAP / HOOK INTO WP *************************** */ |
| 388 | $spl_autoload_exists = function_exists( 'spl_autoload_register' ); |
| 389 | $filter_exists = function_exists( 'filter_input' ); |
| 390 | |
| 391 | if ( ! $spl_autoload_exists ) { |
| 392 | add_action( 'admin_init', 'yoast_wpseo_missing_spl', 1 ); |
| 393 | } |
| 394 | |
| 395 | if ( ! $filter_exists ) { |
| 396 | add_action( 'admin_init', 'yoast_wpseo_missing_filter', 1 ); |
| 397 | } |
| 398 | |
| 399 | if ( ! wp_installing() && ( $spl_autoload_exists && $filter_exists ) ) { |
| 400 | add_action( 'plugins_loaded', 'wpseo_init', 14 ); |
| 401 | add_action( 'rest_api_init', 'wpseo_init_rest_api' ); |
| 402 | |
| 403 | if ( is_admin() ) { |
| 404 | |
| 405 | new Yoast_Notifications(); |
| 406 | |
| 407 | $yoast_addon_manager = new WPSEO_Addon_Manager(); |
| 408 | $yoast_addon_manager->register_hooks(); |
| 409 | |
| 410 | if ( wp_doing_ajax() ) { |
| 411 | require_once WPSEO_PATH . 'admin/ajax.php'; |
| 412 | |
| 413 | // Plugin conflict ajax hooks. |
| 414 | new Yoast_Plugin_Conflict_Ajax(); |
| 415 | |
| 416 | if ( filter_input( INPUT_POST, 'action' ) === 'inline-save' ) { |
| 417 | add_action( 'plugins_loaded', 'wpseo_admin_init', 15 ); |
| 418 | } |
| 419 | } |
| 420 | else { |
| 421 | add_action( 'plugins_loaded', 'wpseo_admin_init', 15 ); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | add_action( 'plugins_loaded', 'load_yoast_notifications' ); |
| 426 | |
| 427 | add_action( 'init', [ 'WPSEO_Replace_Vars', 'setup_statics_once' ] ); |
| 428 | |
| 429 | // Initializes the Yoast indexables for the first time. |
| 430 | YoastSEO(); |
| 431 | |
| 432 | /** |
| 433 | * Action called when the Yoast SEO plugin file has loaded. |
| 434 | */ |
| 435 | do_action( 'wpseo_loaded' ); |
| 436 | } |
| 437 | |
| 438 | // Activation and deactivation hook. |
| 439 | register_activation_hook( WPSEO_FILE, 'wpseo_activate' ); |
| 440 | register_deactivation_hook( WPSEO_FILE, 'wpseo_deactivate' ); |
| 441 | |
| 442 | // Wpmu_new_blog has been deprecated in 5.1 and replaced by wp_insert_site. |
| 443 | global $wp_version; |
| 444 | if ( version_compare( $wp_version, '5.1', '<' ) ) { |
| 445 | add_action( 'wpmu_new_blog', 'wpseo_on_activate_blog' ); |
| 446 | } |
| 447 | else { |
| 448 | add_action( 'wp_initialize_site', 'wpseo_on_activate_blog', 99 ); |
| 449 | } |
| 450 | |
| 451 | add_action( 'activate_blog', 'wpseo_on_activate_blog' ); |
| 452 | |
| 453 | // Registers SEO capabilities. |
| 454 | $wpseo_register_capabilities = new WPSEO_Register_Capabilities(); |
| 455 | $wpseo_register_capabilities->register_hooks(); |
| 456 | |
| 457 | // Registers SEO roles. |
| 458 | $wpseo_register_capabilities = new WPSEO_Register_Roles(); |
| 459 | $wpseo_register_capabilities->register_hooks(); |
| 460 | |
| 461 | /** |
| 462 | * Wraps for notifications center class. |
| 463 | */ |
| 464 | function load_yoast_notifications() { |
| 465 | // Init Yoast_Notification_Center class. |
| 466 | Yoast_Notification_Center::get(); |
| 467 | } |
| 468 | |
| 469 | |
| 470 | /** |
| 471 | * Throw an error if the PHP SPL extension is disabled (prevent white screens) and self-deactivate plugin. |
| 472 | * |
| 473 | * @since 1.5.4 |
| 474 | * |
| 475 | * @return void |
| 476 | */ |
| 477 | function yoast_wpseo_missing_spl() { |
| 478 | if ( is_admin() ) { |
| 479 | add_action( 'admin_notices', 'yoast_wpseo_missing_spl_notice' ); |
| 480 | |
| 481 | yoast_wpseo_self_deactivate(); |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | /** |
| 486 | * Returns the notice in case of missing spl extension. |
| 487 | */ |
| 488 | function yoast_wpseo_missing_spl_notice() { |
| 489 | $message = esc_html__( 'The Standard PHP Library (SPL) extension seem to be unavailable. Please ask your web host to enable it.', 'wordpress-seo' ); |
| 490 | yoast_wpseo_activation_failed_notice( $message ); |
| 491 | } |
| 492 | |
| 493 | /** |
| 494 | * Throw an error if the Composer autoload is missing and self-deactivate plugin. |
| 495 | * |
| 496 | * @return void |
| 497 | */ |
| 498 | function yoast_wpseo_missing_autoload() { |
| 499 | if ( is_admin() ) { |
| 500 | add_action( 'admin_notices', 'yoast_wpseo_missing_autoload_notice' ); |
| 501 | |
| 502 | yoast_wpseo_self_deactivate(); |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | /** |
| 507 | * Returns the notice in case of missing Composer autoload. |
| 508 | */ |
| 509 | function yoast_wpseo_missing_autoload_notice() { |
| 510 | /* translators: %1$s expands to Yoast SEO, %2$s / %3$s: links to the installation manual in the Readme for the Yoast SEO code repository on GitHub */ |
| 511 | $message = esc_html__( 'The %1$s plugin installation is incomplete. Please refer to %2$sinstallation instructions%3$s.', 'wordpress-seo' ); |
| 512 | $message = sprintf( $message, 'Yoast SEO', '<a href="https://github.com/Yoast/wordpress-seo#installation">', '</a>' ); |
| 513 | yoast_wpseo_activation_failed_notice( $message ); |
| 514 | } |
| 515 | |
| 516 | /** |
| 517 | * Throw an error if the filter extension is disabled (prevent white screens) and self-deactivate plugin. |
| 518 | * |
| 519 | * @since 2.0 |
| 520 | * |
| 521 | * @return void |
| 522 | */ |
| 523 | function yoast_wpseo_missing_filter() { |
| 524 | if ( is_admin() ) { |
| 525 | add_action( 'admin_notices', 'yoast_wpseo_missing_filter_notice' ); |
| 526 | |
| 527 | yoast_wpseo_self_deactivate(); |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | /** |
| 532 | * Returns the notice in case of missing filter extension. |
| 533 | */ |
| 534 | function yoast_wpseo_missing_filter_notice() { |
| 535 | $message = esc_html__( 'The filter extension seem to be unavailable. Please ask your web host to enable it.', 'wordpress-seo' ); |
| 536 | yoast_wpseo_activation_failed_notice( $message ); |
| 537 | } |
| 538 | |
| 539 | /** |
| 540 | * Echo's the Activation failed notice with any given message. |
| 541 | * |
| 542 | * @param string $message Message string. |
| 543 | */ |
| 544 | function yoast_wpseo_activation_failed_notice( $message ) { |
| 545 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- This function is only called in 3 places that are safe. |
| 546 | echo '<div class="error"><p>' . esc_html__( 'Activation failed:', 'wordpress-seo' ) . ' ' . strip_tags( $message, '<a>' ) . '</p></div>'; |
| 547 | } |
| 548 | |
| 549 | /** |
| 550 | * The method will deactivate the plugin, but only once, done by the static $is_deactivated. |
| 551 | */ |
| 552 | function yoast_wpseo_self_deactivate() { |
| 553 | static $is_deactivated; |
| 554 | |
| 555 | if ( $is_deactivated === null ) { |
| 556 | $is_deactivated = true; |
| 557 | deactivate_plugins( WPSEO_BASENAME ); |
| 558 | if ( isset( $_GET['activate'] ) ) { |
| 559 | unset( $_GET['activate'] ); |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | /** |
| 565 | * Aliasses added in order to keep compatibility with Yoast SEO: Local. |
| 566 | */ |
| 567 | class_alias( '\Yoast\WP\SEO\Initializers\Initializer_Interface', '\Yoast\WP\SEO\WordPress\Initializer' ); |
| 568 | class_alias( '\Yoast\WP\SEO\Loadable_Interface', '\Yoast\WP\SEO\WordPress\Loadable' ); |
| 569 | class_alias( '\Yoast\WP\SEO\Integrations\Integration_Interface', '\Yoast\WP\SEO\WordPress\Integration' ); |
| 570 |