multisite_defaults(); $options = get_wpseo_options(); if ( isset( $options['stripcategorybase'] ) && $options['stripcategorybase'] ) { add_action( 'created_category', 'flush_rewrite_rules' ); add_action( 'edited_category', 'flush_rewrite_rules' ); add_action( 'delete_category', 'flush_rewrite_rules' ); } if ( $this->grant_access() ) { add_action( 'admin_init', array( $this, 'options_init' ) ); // Needs the lower than default priority so other plugins can hook underneath it without issue. add_action( 'admin_menu', array( $this, 'register_settings_page' ), 5 ); add_action( 'network_admin_menu', array( $this, 'register_network_settings_page' ) ); add_filter( 'plugin_action_links', array( $this, 'add_action_link' ), 10, 2 ); add_action( 'admin_print_scripts', array( $this, 'config_page_scripts' ) ); if ( '0' == get_option( 'blog_public' ) ) add_action( 'admin_footer', array( $this, 'blog_public_warning' ) ); } add_action( 'admin_init', array( $this, 'maybe_upgrade' ) ); add_filter( 'name_save_pre', array( $this, 'remove_stopwords_from_slug' ), 0 ); add_action( 'show_user_profile', array( $this, 'user_profile' ) ); add_action( 'edit_user_profile', array( $this, 'user_profile' ) ); add_action( 'personal_options_update', array( $this, 'process_user_option_update' ) ); add_action( 'edit_user_profile_update', array( $this, 'process_user_option_update' ) ); add_filter( 'user_contactmethods', array( $this, 'update_contactmethods' ), 10, 1 ); add_action( 'update_option_wpseo_titles', array( $this, 'clear_cache' ) ); add_action( 'update_option_wpseo', array( $this, 'clear_cache' ) ); add_action( 'update_option_wpseo_permalinks', array( $this, 'clear_rewrites' ) ); add_action( 'update_option_wpseo_xml', array( $this, 'clear_rewrites' ) ); } /** * Clears the cache */ function clear_cache() { if ( function_exists( 'w3tc_pgcache_flush' ) ) { w3tc_pgcache_flush(); } else if ( function_exists( 'wp_cache_clear_cache' ) ) { wp_cache_clear_cache(); } } /** * Clear rewrites */ function clear_rewrites() { delete_option( 'rewrite_rules' ); } /** * Register all the options needed for the configuration pages. */ function options_init() { register_setting( 'yoast_wpseo_options', 'wpseo' ); register_setting( 'yoast_wpseo_permalinks_options', 'wpseo_permalinks' ); register_setting( 'yoast_wpseo_titles_options', 'wpseo_titles' ); register_setting( 'yoast_wpseo_rss_options', 'wpseo_rss' ); register_setting( 'yoast_wpseo_internallinks_options', 'wpseo_internallinks' ); register_setting( 'yoast_wpseo_xml_sitemap_options', 'wpseo_xml' ); register_setting( 'yoast_wpseo_social_options', 'wpseo_social' ); if ( function_exists( 'is_multisite' ) && is_multisite() ) { if ( get_option( 'wpseo' ) == '1pseo_social' ) delete_option( 'wpseo' ); register_setting( 'yoast_wpseo_multisite_options', 'wpseo_multisite' ); } } function multisite_defaults() { $option = get_option( 'wpseo' ); if ( function_exists( 'is_multisite' ) && is_multisite() && !is_array( $option ) ) { $options = get_site_option( 'wpseo_ms' ); if ( is_array( $options ) && isset( $options['defaultblog'] ) && !empty( $options['defaultblog'] ) && $options['defaultblog'] != 0 ) { foreach ( get_wpseo_options_arr() as $wpseo_option ) { update_option( $wpseo_option, get_blog_option( $options['defaultblog'], $wpseo_option ) ); } } $option['ms_defaults_set'] = true; update_option( 'wpseo', $option ); } } /** * Check whether the current user is allowed to access the configuration. * * @return boolean */ function grant_access() { if ( !function_exists( 'is_multisite' ) || !is_multisite() ) return true; $options = get_site_option( 'wpseo_ms' ); if ( !is_array( $options ) || !isset( $options['access'] ) ) return true; if ( $options['access'] == 'superadmin' && !is_super_admin() ) return false; return true; } /** * Register the menu item and its sub menu's. * * @global array $submenu used to change the label on the first item. */ function register_settings_page() { add_menu_page( __( 'WordPress SEO Configuration', 'wordpress-seo' ), __( 'SEO', 'wordpress-seo' ), 'manage_options', 'wpseo_dashboard', array( $this, 'config_page' ), WPSEO_URL . 'images/yoast-icon.png' ); add_submenu_page( 'wpseo_dashboard', __( 'Titles & Metas', 'wordpress-seo' ), __( 'Titles & Metas', 'wordpress-seo' ), 'manage_options', 'wpseo_titles', array( $this, 'titles_page' ) ); add_submenu_page( 'wpseo_dashboard', __( 'Social', 'wordpress-seo' ), __( 'Social', 'wordpress-seo' ), 'manage_options', 'wpseo_social', array( $this, 'social_page' ) ); add_submenu_page( 'wpseo_dashboard', __( 'XML Sitemaps', 'wordpress-seo' ), __( 'XML Sitemaps', 'wordpress-seo' ), 'manage_options', 'wpseo_xml', array( $this, 'xml_sitemaps_page' ) ); add_submenu_page( 'wpseo_dashboard', __( 'Permalinks', 'wordpress-seo' ), __( 'Permalinks', 'wordpress-seo' ), 'manage_options', 'wpseo_permalinks', array( $this, 'permalinks_page' ) ); add_submenu_page( 'wpseo_dashboard', __( 'Internal Links', 'wordpress-seo' ), __( 'Internal Links', 'wordpress-seo' ), 'manage_options', 'wpseo_internal-links', array( $this, 'internallinks_page' ) ); add_submenu_page( 'wpseo_dashboard', __( 'RSS', 'wordpress-seo' ), __( 'RSS', 'wordpress-seo' ), 'manage_options', 'wpseo_rss', array( $this, 'rss_page' ) ); add_submenu_page( 'wpseo_dashboard', __( 'Import & Export', 'wordpress-seo' ), __( 'Import & Export', 'wordpress-seo' ), 'manage_options', 'wpseo_import', array( $this, 'import_page' ) ); if ( !( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT ) && !( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) ) { // Make sure on a multi site install only super admins can edit .htaccess and robots.txt if ( !function_exists( 'is_multisite' ) || !is_multisite() ) add_submenu_page( 'wpseo_dashboard', __( 'Edit files', 'wordpress-seo' ), __( 'Edit files', 'wordpress-seo' ), 'manage_options', 'wpseo_files', array( $this, 'files_page' ) ); else add_submenu_page( 'wpseo_dashboard', __( 'Edit files', 'wordpress-seo' ), __( 'Edit files', 'wordpress-seo' ), 'delete_users', 'wpseo_files', array( $this, 'files_page' ) ); } global $submenu; if ( isset( $submenu['wpseo_dashboard'] ) ) $submenu['wpseo_dashboard'][0][0] = __( 'Dashboard', 'wordpress-seo' ); } /** * Register the settings page for the Network settings. */ function register_network_settings_page() { add_menu_page( __( 'WordPress SEO Configuration', 'wordpress-seo' ), __( 'SEO', 'wordpress-seo' ), 'delete_users', 'wpseo_dashboard', array( $this, 'network_config_page' ), WPSEO_URL . 'images/yoast-icon.png' ); } /** * Loads the form for the network configuration page. */ function network_config_page() { require( WPSEO_PATH . '/admin/pages/network.php' ); } /** * Loads the form for the import/export page. */ function import_page() { if ( isset( $_GET['page'] ) && 'wpseo_import' == $_GET['page'] ) include( WPSEO_PATH . '/admin/pages/import.php' ); } /** * Loads the form for the titles & metas page. */ function titles_page() { if ( isset( $_GET['page'] ) && 'wpseo_titles' == $_GET['page'] ) include( WPSEO_PATH . '/admin/pages/metas.php' ); } /** * Loads the form for the permalinks page. */ function permalinks_page() { if ( isset( $_GET['page'] ) && 'wpseo_permalinks' == $_GET['page'] ) include( WPSEO_PATH . '/admin/pages/permalinks.php' ); } /** * Loads the form for the internal links / breadcrumbs page. */ function internallinks_page() { if ( isset( $_GET['page'] ) && 'wpseo_internal-links' == $_GET['page'] ) include( WPSEO_PATH . '/admin/pages/internal-links.php' ); } /** * Loads the form for the file edit page. */ function files_page() { if ( isset( $_GET['page'] ) && 'wpseo_files' == $_GET['page'] ) include( WPSEO_PATH . '/admin/pages/files.php' ); } /** * Loads the form for the RSS page. */ function rss_page() { if ( isset( $_GET['page'] ) && 'wpseo_rss' == $_GET['page'] ) include( WPSEO_PATH . '/admin/pages/rss.php' ); } /** * Loads the form for the XML Sitemaps page. */ function xml_sitemaps_page() { if ( isset( $_GET['page'] ) && 'wpseo_xml' == $_GET['page'] ) include( WPSEO_PATH . '/admin/pages/xml-sitemaps.php' ); } /** * Loads the form for the Dashboard page. */ function config_page() { if ( isset( $_GET['page'] ) && 'wpseo_dashboard' == $_GET['page'] ) include( WPSEO_PATH . '/admin/pages/dashboard.php' ); } /** * Loads the form for the Social Settings page. */ function social_page() { if ( isset( $_GET['page'] ) && 'wpseo_social' == $_GET['page'] ) require( WPSEO_PATH . '/admin/pages/social.php' ); } /** * Display an error message when the blog is set to private. */ function blog_public_warning() { if ( function_exists( 'is_network_admin' ) && is_network_admin() ) return; $options = get_option( 'wpseo' ); if ( isset( $options['ignore_blog_public_warning'] ) && $options['ignore_blog_public_warning'] == 'ignore' ) return; echo "
" . __( "Huge SEO Issue: You're blocking access to robots.", 'wordpress-seo' ) . " " . sprintf( __( "You must %sgo to your Reading Settings%s and uncheck the box for Search Engine Visibility.", 'wordpress-seo' ), "", "" ) . " " . __( "I know, don't bug me.", 'wordpress-seo' ) . "