Esempio n. 1
0
/**
 * Compares The SEO Framework dot versions.
 *
 * @since 2.4.0
 *
 * @param string version The two dot version: x.v
 * @return bool False plugin inactive or version compare yields negative results.
 */
function the_seo_framework_dot_version($version = '2.4')
{
    $current_version = the_seo_framework_version();
    if ($current_version) {
        $version_len = strlen($version);
        $current_version_len = strlen($current_version);
        //* Only allow 3 length.
        if (3 !== $version_len) {
            $version = substr($version, 0, 3);
        }
        if (3 !== $current_version_len) {
            $current_version = substr($current_version, 0, 3);
        }
        if ($current_version === $version) {
            return true;
        }
    }
    return false;
}
 /**
  * Start plugin at get_header. A semi constructor.
  *
  * @since 1.0.0
  */
 public function start_plugin()
 {
     /**
      * Don't fix the title in admin.
      * get_header doesn't run in admin, but another plugin might init it.
      */
     if (false === is_admin()) {
         if (false === $this->current_theme_supports_title_tag()) {
             /**
              * Applies filters 'the_seo_framework_force_title_fix'
              * @since 1.0.1
              * @param bool Whether to force the title fixing.
              */
             $this->force_title_fix = (bool) apply_filters('the_seo_framework_force_title_fix', version_compare(the_seo_framework_version(), '2.6.99', '<'));
         }
         /**
          * Only do something if the theme is doing it wrong. Or when the filter has been applied.
          * Requires initial load after theme switch.
          */
         if ($this->force_title_fix || false === the_seo_framework()->theme_title_doing_it_right()) {
             /**
              * First run.
              * Start at HTTP header.
              * Stop right at where wp_head is run.
              */
             add_action('get_header', array($this, 'start_ob'), 0);
             add_action('wp_head', array($this, 'maybe_rewrite_title'), 0);
             add_action('wp_head', array($this, 'maybe_stop_ob'), 0);
             /**
              * Second run. Capture WP head.
              * 		{add_action( 'wp_head', 'wp_title' );.. who knows?}
              * Start at where wp_head is run (last run left off).
              * Stop right at the end of wp_head.
              */
             add_action('wp_head', array($this, 'maybe_start_ob'), 0);
             add_action('wp_head', array($this, 'maybe_rewrite_title'), 9999);
             add_action('wp_head', array($this, 'maybe_stop_ob'), 9999);
             /**
              * Third run. Capture the page.
              * Start at where wp_head has ended (last run left off),
              *		or at wp_head start (first run left off).
              * Stop at the footer.
              */
             add_action('wp_head', array($this, 'maybe_start_ob'), 9999);
             add_action('get_footer', array($this, 'maybe_rewrite_title'), -1);
             add_action('get_footer', array($this, 'maybe_stop_ob'), -1);
             /**
              * Stop OB if it's still running at shutdown.
              * Might prevent AJAX issues, if any.
              */
             add_action('shutdown', array($this, 'stop_ob'), 0);
         }
     }
 }