Example #1
0
 /**
  * Resets the site to the default WordPress SEO settings and runs a title test to check whether force rewrite needs to be on.
  */
 function reset_defaults()
 {
     foreach (get_wpseo_options_arr() as $opt) {
         delete_option($opt);
     }
     wpseo_defaults();
     wpseo_title_test();
 }
/**
 * Set the default settings.
 *
 * This uses the currently available custom post types and taxonomies.
 */
function wpseo_defaults()
{
    $options = get_option('wpseo');
    if (!is_array($options)) {
        $opt = array('disableadvanced_meta' => 'on', 'version' => WPSEO_VERSION);
        update_option('wpseo', $opt);
        // Test theme on activate
        wpseo_description_test();
    } else {
        // Re-check theme on re-activate
        wpseo_description_test();
        return;
    }
    if (!is_array(get_option('wpseo_titles'))) {
        $opt = array('title-home' => '%%sitename%% %%page%% %%sep%% %%sitedesc%%', 'title-author' => sprintf(__('%s, Author at %s', 'wordpress-seo'), '%%name%%', '%%sitename%%') . ' %%page%% ', 'title-archive' => '%%date%% %%page%% %%sep%% %%sitename%%', 'title-search' => sprintf(__('You searched for %s', 'wordpress-seo'), '%%searchphrase%%') . ' %%page%% %%sep%% %%sitename%%', 'title-404' => __('Page Not Found', 'wordpress-seo') . ' %%sep%% %%sitename%%', 'noindex-archive' => 'on', 'noindex-post_format' => 'on');
        foreach (get_post_types(array('public' => true), 'objects') as $pt) {
            $opt['title-' . $pt->name] = '%%title%% %%page%% %%sep%% %%sitename%%';
            if ($pt->has_archive) {
                $opt['title-ptarchive-' . $pt->name] = sprintf(__('%s Archive', 'wordpress-seo'), '%%pt_plural%%') . ' %%page%% %%sep%% %%sitename%%';
            }
        }
        foreach (get_taxonomies(array('public' => true)) as $tax) {
            $opt['title-' . $tax] = sprintf(__('%s Archives', 'wordpress-seo'), '%%term_title%%') . ' %%page%% %%sep%% %%sitename%%';
        }
        update_option('wpseo_titles', $opt);
        wpseo_title_test();
    }
    if (!is_array(get_option('wpseo_xml'))) {
        $opt = array('enablexmlsitemap' => 'on', 'post_types-attachment-not_in_sitemap' => true);
        update_option('wpseo_xml', $opt);
    }
    if (!is_array(get_option('wpseo_social'))) {
        $opt = array('opengraph' => 'on');
        update_option('wpseo_social', $opt);
    }
    if (!is_array(get_option('wpseo_rss'))) {
        $opt = array('rssafter' => sprintf(__('The post %s appeared first on %s.', 'wordpress-seo'), '%%POSTLINK%%', '%%BLOGLINK%%'));
        update_option('wpseo_rss', $opt);
    }
    if (!is_array(get_option('wpseo_permalinks'))) {
        $opt = array('cleanslugs' => 'on');
        update_option('wpseo_permalinks', $opt);
    }
    // Force WooThemes to use WordPress SEO data.
    if (function_exists('woo_version_init')) {
        update_option('seo_woo_use_third_party_data', 'true');
    }
}
 /**
  * Determine whether the wpseo option holds the current version, if it doesn't, run
  * the upgrade procedures.
  */
 function maybe_upgrade()
 {
     $options = get_option('wpseo');
     $current_version = isset($options['version']) ? $options['version'] : 0;
     if (version_compare($current_version, WPSEO_VERSION, '==')) {
         return;
     }
     delete_option('rewrite_rules');
     // <= 0.3.5: flush rewrite rules for new XML sitemaps
     if ($current_version == 0) {
         flush_rewrite_rules();
     }
     if (version_compare($current_version, '0.4.2', '<')) {
         $xml_opt = array();
         // Move XML Sitemap settings from general array to XML specific array, general settings first
         foreach (array('enablexmlsitemap', 'xml_include_images', 'xml_ping_google', 'xml_ping_bing', 'xml_ping_yahoo', 'xml_ping_ask', 'xmlnews_posttypes') as $opt) {
             if (isset($options[$opt])) {
                 $xml_opt[$opt] = $options[$opt];
                 unset($options[$opt]);
             }
         }
         // Per post type settings
         foreach (get_post_types() as $post_type) {
             if (in_array($post_type, array('revision', 'nav_menu_item', 'attachment'))) {
                 continue;
             }
             if (isset($options['post_types-' . $post_type . '-not_in_sitemap'])) {
                 $xml_opt['post_types-' . $post_type . '-not_in_sitemap'] = $options['post_types-' . $post_type . '-not_in_sitemap'];
                 unset($options['post_types-' . $post_type . '-not_in_sitemap']);
             }
         }
         // Per taxonomy settings
         foreach (get_taxonomies() as $taxonomy) {
             if (in_array($taxonomy, array('nav_menu', 'link_category', 'post_format'))) {
                 continue;
             }
             if (isset($options['taxonomies-' . $taxonomy . '-not_in_sitemap'])) {
                 $xml_opt['taxonomies-' . $taxonomy . '-not_in_sitemap'] = $options['taxonomies-' . $taxonomy . '-not_in_sitemap'];
                 unset($options['taxonomies-' . $taxonomy . '-not_in_sitemap']);
             }
         }
         if (get_option('wpseo_xml') === false) {
             update_option('wpseo_xml', $xml_opt);
         }
         unset($xml_opt);
         // Clean up other no longer used settings
         unset($options['wpseodir'], $options['wpseourl']);
     }
     if (version_compare($current_version, '1.0.2.2', '<')) {
         $opt = (array) get_option('wpseo_indexation');
         unset($opt['hideindexrel'], $opt['hidestartrel'], $opt['hideprevnextpostlink'], $opt['hidewpgenerator']);
         update_option('wpseo_indexation', $opt);
     }
     if (version_compare($current_version, '1.0.4', '<')) {
         $opt = (array) get_option('wpseo_indexation');
         $newopt = array('opengraph' => isset($opt['opengraph']) ? $opt['opengraph'] : '', 'fb_adminid' => isset($opt['fb_adminid']) ? $opt['fb_adminid'] : '', 'fb_appid' => isset($opt['fb_appid']) ? $opt['fb_appid'] : '');
         update_option('wpseo_social', $newopt);
         unset($opt['opengraph'], $opt['fb_pageid'], $opt['fb_adminid'], $opt['fb_appid']);
         update_option('wpseo_indexation', $opt);
     }
     if (version_compare($current_version, '1.2', '<')) {
         $opt = get_option('wpseo_indexation');
         $metaopt = get_option('wpseo_titles');
         $metaopt['noindex-author'] = isset($opt['noindexauthor']) ? $opt['noindexauthor'] : '';
         $metaopt['disable-author'] = isset($opt['disableauthor']) ? $opt['disableauthor'] : '';
         $metaopt['noindex-archive'] = isset($opt['noindexdate']) ? $opt['noindexdate'] : '';
         $metaopt['noindex-category'] = isset($opt['noindexcat']) ? $opt['noindexcat'] : '';
         $metaopt['noindex-post_tag'] = isset($opt['noindextag']) ? $opt['noindextag'] : '';
         $metaopt['noindex-post_format'] = isset($opt['noindexpostformat']) ? $opt['noindexpostformat'] : '';
         $metaopt['noindex-subpages'] = isset($opt['noindexsubpages']) ? $opt['noindexsubpages'] : '';
         $metaopt['hide-rsdlink'] = isset($opt['hidersdlink']) ? $opt['hidersdlink'] : '';
         $metaopt['hide-feedlinks'] = isset($opt['hidefeedlinks']) ? $opt['hidefeedlinks'] : '';
         $metaopt['hide-wlwmanifest'] = isset($opt['hidewlwmanifest']) ? $opt['hidewlwmanifest'] : '';
         $metaopt['hide-shortlink'] = isset($opt['hideshortlink']) ? $opt['hideshortlink'] : '';
         update_option('wpseo_titles', $metaopt);
         delete_option('wpseo_indexation');
         wpseo_title_test();
     }
     // Clean up the wrong wpseo options
     if (version_compare($current_version, '1.2.3', '<')) {
         $opt = get_option('wpseo');
         if (is_array($opt)) {
             foreach ($opt as $key => $val) {
                 if (!in_array($key, array('ignore_blog_public_warning', 'ignore_tour', 'ignore_page_comments', 'ignore_permalink', 'ms_defaults_set', 'version', 'disableadvanced_meta', 'googleverify', 'msverify', 'alexaverify'))) {
                     unset($opt[$key]);
                 }
             }
             update_option('wpseo', $opt);
             unset($opt);
         }
     }
     // Fix wrongness created by buggy version 1.2.2
     if (version_compare($current_version, '1.2.4', '<')) {
         $options = get_option('wpseo_titles');
         if (is_array($options) && isset($options['title-home']) && $options['title-home'] == '%%sitename%% - %%sitedesc%% - 12345') {
             $options['title-home'] = '%%sitename%% - %%sitedesc%%';
             update_option('wpseo_titles', $options);
         }
     }
     if (version_compare($current_version, '1.2.8', '<')) {
         $options = get_option('wpseo');
         if (is_array($options) && isset($options['presstrends'])) {
             $options['yoast_tracking'] = 'on';
             unset($options['presstrends']);
             update_option('wpseo', $options);
         }
     }
     if (version_compare($current_version, '1.2.8.2', '<')) {
         $options = get_option('wpseo');
         if (is_array($options) && isset($options['presstrends'])) {
             $options['yoast_tracking'] = 'on';
             unset($options['presstrends']);
         }
         if (is_array($options) && isset($options['presstrends_popup'])) {
             $options['tracking_popup'] = 'on';
             unset($options['presstrends_popup']);
         }
         update_option('wpseo', $options);
     }
     if (version_compare($current_version, '1.3.2', '<')) {
         $options = get_option('wpseo_xml');
         $options['post_types-attachment-not_in_sitemap'] = true;
         update_option('wpseo_xml', $options);
     }
     $options = get_option('wpseo');
     $options['version'] = WPSEO_VERSION;
     update_option('wpseo', $options);
 }
/**
 * Abuse a filter to check if the current theme was updated and if so, test the updated theme
 * for the title and meta description tag
 *
 * @since 1.4.14
 *
 * @param   array   $update_actions
 * @param   mixed   $updated_theme
 * @return  array  $update_actions    Unchanged array
 */
function wpseo_update_theme_complete_actions( $update_actions, $updated_theme ) {
	$options = get_option( 'wpseo' );

	// Break if admin_notice already in place
	if ( ( ( isset( $options['theme_has_description'] ) && $options['theme_has_description'] === true ) || $options['theme_description_found'] !== '' ) && $options['ignore_meta_description_warning'] !== true ) {
		return $update_actions;
	}

	$theme = get_stylesheet();
	if ( is_object( $updated_theme ) ) {
		/* Bulk update and $updated_theme only contains info on which theme was last in the list
		   of updated themes, so go & test */
		wpseo_title_test();
		wpseo_description_test();
	}
	elseif ( $updated_theme === $theme ) {
		/* Single theme update for the active theme */
		wpseo_title_test();
		wpseo_description_test();
	}
	return $update_actions;
}
Example #5
0
 /**
  * Initialize some options on first install/activate/reset
  *
  * @static
  * @return void
  */
 public static function initialize()
 {
     /* Make sure title_test and description_test function are available even when called
        from the isolated activation */
     require_once WPSEO_PATH . 'inc/wpseo-non-ajax-functions.php';
     wpseo_title_test();
     wpseo_description_test();
     /* Force WooThemes to use WordPress SEO data. */
     if (function_exists('woo_version_init')) {
         update_option('seo_woo_use_third_party_data', 'true');
     }
 }