' ); add_action( 'shutdown', 'flush_rewrite_rules' ); wpseo_remove_capabilities(); // Force unschedule WPSEO_Utils::schedule_yoast_tracking( null, get_option( 'wpseo' ), true ); // Clear cache so the changes are obvious. WPSEO_Utils::clear_cache(); do_action( 'wpseo_deactivate' ); } /** * Run wpseo activation routine on creation / activation of a multisite blog if WPSEO is activated * network-wide. * * Will only be called by multisite actions. * @internal Unfortunately will fail if the plugin is in the must-use directory * @see https://core.trac.wordpress.org/ticket/24205 * * @param int $blog_id */ function wpseo_on_activate_blog( $blog_id ) { if ( ! function_exists( 'is_plugin_active_for_network' ) ) { require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); } if ( is_plugin_active_for_network( plugin_basename( WPSEO_FILE ) ) ) { switch_to_blog( $blog_id ); wpseo_activate( false ); restore_current_blog(); } } /* ***************************** PLUGIN LOADING *************************** */ /** * Load translations */ function wpseo_load_textdomain() { load_plugin_textdomain( 'wordpress-seo', false, dirname( plugin_basename( WPSEO_FILE ) ) . '/languages/' ); } add_action( 'init', 'wpseo_load_textdomain', 1 ); /** * On plugins_loaded: load the minimum amount of essential files for this plugin */ function wpseo_init() { require_once( WPSEO_PATH . 'inc/wpseo-functions.php' ); // Make sure our option and meta value validation routines and default values are always registered and available WPSEO_Options::get_instance(); WPSEO_Meta::init(); $options = WPSEO_Options::get_all(); if ( version_compare( $options['version'], WPSEO_VERSION, '<' ) ) { new WPSEO_Upgrade(); // get a cleaned up version of the $options $options = WPSEO_Options::get_all(); } if ( $options['stripcategorybase'] === true ) { $GLOBALS['wpseo_rewrite'] = new WPSEO_Rewrite; } if ( $options['enablexmlsitemap'] === true ) { $GLOBALS['wpseo_sitemaps'] = new WPSEO_Sitemaps; } if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) { require_once( WPSEO_PATH . 'inc/wpseo-non-ajax-functions.php' ); } } /** * Used to load the required files on the plugins_loaded hook, instead of immediately. */ function wpseo_frontend_init() { add_action( 'init', 'initialize_wpseo_front' ); $options = WPSEO_Options::get_all(); if ( $options['breadcrumbs-enable'] === true ) { /** * If breadcrumbs are active (which they supposedly are if the users has enabled this settings, * there's no reason to have bbPress breadcrumbs as well. * * @internal The class itself is only loaded when the template tag is encountered via * the template tag function in the wpseo-functions.php file */ add_filter( 'bbp_get_breadcrumb', '__return_false' ); } add_action( 'template_redirect', 'wpseo_frontend_head_init', 999 ); } /** * Instantiate the different social classes on the frontend */ function wpseo_frontend_head_init() { $options = WPSEO_Options::get_all(); if ( $options['twitter'] === true ) { add_action( 'wpseo_head', array( 'WPSEO_Twitter', 'get_instance' ), 40 ); } if ( $options['opengraph'] === true ) { $GLOBALS['wpseo_og'] = new WPSEO_OpenGraph; } if ( $options['googleplus'] === true && is_singular() ) { add_action( 'wpseo_head', array( 'WPSEO_GooglePlus', 'get_instance' ), 35 ); } } /** * Used to load the required files on the plugins_loaded hook, instead of immediately. */ function wpseo_admin_init() { new WPSEO_Admin_Init(); } /* ***************************** BOOTSTRAP / HOOK INTO WP *************************** */ $spl_autoload_exists = function_exists( 'spl_autoload_register' ); $filter_exists = function_exists( 'filter_input' ); if ( ! $spl_autoload_exists ) { add_action( 'admin_init', 'yoast_wpseo_missing_spl', 1 ); } if ( ! $filter_exists ) { add_action( 'admin_init', 'yoast_wpseo_missing_filter', 1 ); } if ( ( ! defined( 'WP_INSTALLING' ) || WP_INSTALLING === false ) && ( $spl_autoload_exists && $filter_exists ) ) { add_action( 'plugins_loaded', 'wpseo_init', 14 ); if ( is_admin() ) { if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { require_once( WPSEO_PATH . 'admin/ajax.php' ); } else { add_action( 'plugins_loaded', 'wpseo_admin_init', 15 ); } } else { add_action( 'plugins_loaded', 'wpseo_frontend_init', 15 ); } add_action( 'admin_init', 'load_yoast_notifications' ); } // Activation and deactivation hook register_activation_hook( WPSEO_FILE, 'wpseo_activate' ); register_activation_hook( WPSEO_FILE, array( 'WPSEO_Plugin_Conflict', 'hook_check_for_plugin_conflicts' ) ); register_deactivation_hook( WPSEO_FILE, 'wpseo_deactivate' ); add_action( 'wpmu_new_blog', 'wpseo_on_activate_blog' ); add_action( 'activate_blog', 'wpseo_on_activate_blog' ); /** * Wraps for notifications center class. */ function load_yoast_notifications() { // Init Yoast_Notification_Center class Yoast_Notification_Center::get(); } /** * Throw an error if the PHP SPL extension is disabled (prevent white screens) and self-deactivate plugin * * @since 1.5.4 * * @return void */ function yoast_wpseo_missing_spl() { if ( is_admin() ) { add_action( 'admin_notices', 'yoast_wpseo_missing_spl_notice' ); yoast_wpseo_self_deactivate(); } } /** * Returns the notice in case of missing spl extension */ function yoast_wpseo_missing_spl_notice() { $message = esc_html__( 'The Standard PHP Library (SPL) extension seem to be unavailable. Please ask your web host to enable it.', 'wordpress-seo' ); echo '

' . __( 'Activation failed:', 'wordpress-seo' ) . ' ' . $message . '

'; } /** * Throw an error if the filter extension is disabled (prevent white screens) and self-deactivate plugin * * @since 2.0 * * @return void */ function yoast_wpseo_missing_filter() { if ( is_admin() ) { add_action( 'admin_notices', 'yoast_wpseo_missing_filter_notice' ); yoast_wpseo_self_deactivate(); } } /** * Returns the notice in case of missing filter extension */ function yoast_wpseo_missing_filter_notice() { $message = esc_html__( 'The filter extension seem to be unavailable. Please ask your web host to enable it.', 'wordpress-seo' ); echo '

' . __( 'Activation failed:', 'wordpress-seo' ) . ' ' . $message . '

'; } /** * The method will deactivate the plugin, but only once, done by the static $is_deactivated */ function yoast_wpseo_self_deactivate() { static $is_deactivated; if ( $is_deactivated === null ) { $is_deactivated = true; deactivate_plugins( plugin_basename( WPSEO_FILE ) ); if ( isset( $_GET['activate'] ) ) { unset( $_GET['activate'] ); } } }