public function get_title($textlen = 70, $trailing = '', $use_post = false, $use_cache = true, $add_hashtags = false, $encode = true, $md_idx = 'og_title', $src_id = '') { if ($this->p->debug->enabled) { $this->p->debug->args(array('textlen' => $textlen, 'trailing' => $trailing, 'use_post' => $use_post, 'use_cache' => $use_cache, 'add_hashtags' => $add_hashtags, 'encode' => $encode, 'md_idx' => $md_idx, 'src_id' => $src_id)); } $title = false; $hashtags = ''; $post_id = 0; $paged_suffix = ''; $separator = html_entity_decode($this->p->options['og_title_sep'], ENT_QUOTES, get_bloginfo('charset')); // setup filters to save and restore original / pre-filtered title value if (empty($this->p->options['plugin_filter_title'])) { add_filter('wp_title', array(&$this, 'wp_title_save'), -9000, 3); add_filter('wp_title', array(&$this, 'wp_title_restore'), 9000, 3); } if (is_singular() || $use_post !== false) { if (($obj = $this->p->util->get_post_object($use_post)) === false) { if ($this->p->debug->enabled) { $this->p->debug->log('exiting early: invalid object type'); } return $title; } $post_id = empty($obj->ID) || empty($obj->post_type) ? 0 : $obj->ID; } // skip if no metadata index / key name if (!empty($md_idx)) { if (is_singular() || $use_post !== false) { if (!empty($post_id)) { $title = $this->p->util->get_mod_options('post', $post_id, array($md_idx, 'og_title')); } } elseif (SucomUtil::is_term_page()) { $term = $this->p->util->get_term_object(); if (!empty($term->term_id)) { $title = $this->p->util->get_mod_options('taxonomy', $term->term_id, $md_idx); } } elseif (SucomUtil::is_author_page()) { $author = $this->p->util->get_author_object(); if (!empty($author->ID)) { $title = $this->p->util->get_mod_options('user', $author->ID, $md_idx); } } } // get seed if no custom meta title if (empty($title)) { $title = apply_filters($this->p->cf['lca'] . '_title_seed', '', $use_post, $add_hashtags, $md_idx, $src_id); if (!empty($title)) { if ($this->p->debug->enabled) { $this->p->debug->log('title seed = "' . $title . '"'); } } } // check for hashtags in meta or seed title, remove and then add again after shorten if (preg_match('/(.*)(( #[a-z0-9\\-]+)+)$/U', $title, $match)) { $title = $match[1]; $hashtags = trim($match[2]); } elseif (is_singular() || $use_post !== false) { if (!empty($add_hashtags) && !empty($this->p->options['og_desc_hashtags'])) { $hashtags = $this->get_hashtags($post_id, $add_hashtags); } // add_hashtags = true/false/numeric } // construct a title of our own if (empty($title)) { // $obj and $post_id are defined above, with the same test, so we should be good if (is_singular() || $use_post !== false) { if (is_singular()) { $title = wp_title($separator, false, 'right'); if ($this->p->debug->enabled) { $this->p->debug->log('is_singular wp_title() = "' . $title . '"'); } } elseif (!empty($post_id)) { $title = apply_filters('wp_title', get_the_title($post_id) . ' ' . $separator . ' ', $separator, 'right'); if ($this->p->debug->enabled) { $this->p->debug->log('post_id get_the_title() = "' . $title . '"'); } } // by default, use the wordpress title if an seo plugin is available } elseif ($this->p->is_avail['seo']['*'] == true) { // use separator on right for compatibility with aioseo $title = wp_title($separator, false, 'right'); if ($this->p->debug->enabled) { $this->p->debug->log('seo wp_title() = "' . $title . '"'); } } elseif (SucomUtil::is_term_page()) { $term = $this->p->util->get_term_object(); $title = apply_filters('wp_title', $term->name . ' ' . $separator . ' ', $separator, 'right'); } elseif (SucomUtil::is_author_page()) { $author = $this->p->util->get_author_object(); $title = apply_filters('wp_title', $author->display_name . ' ' . $separator . ' ', $separator, 'right'); // category title, with category parents } elseif (SucomUtil::is_category_page()) { $title = $this->get_category_title(); // includes parents in title string } else { /* The title text depends on the query: * single post = the title of the post * date-based archive = the date (e.g., "2006", "2006 - January") * category = the name of the category * author page = the public name of the user */ $title = wp_title($separator, false, 'right'); if ($this->p->debug->enabled) { $this->p->debug->log('default wp_title() = "' . $title . '"'); } } // just in case if (empty($title)) { $title = get_bloginfo('name', 'display'); if ($this->p->debug->enabled) { $this->p->debug->log('last resort get_bloginfo() = "' . $title . '"'); } } } if (empty($this->p->options['plugin_filter_title'])) { remove_filter('wp_title', array(&$this, 'wp_title_save'), -9000); remove_filter('wp_title', array(&$this, 'wp_title_restore'), 9000); } $title = $this->p->util->cleanup_html_tags($title); // strip html tags before removing separator if (!empty($separator)) { $title = preg_replace('/ *' . preg_quote($separator, '/') . ' *$/', '', $title); } // trim excess separator // apply title filter before adjusting it's length $title = apply_filters($this->p->cf['lca'] . '_title_pre_limit', $title); // check title against string length limits if ($textlen > 0) { // seo-like title modifications if ($this->p->is_avail['seo']['*'] === false) { $paged = get_query_var('paged'); if ($paged > 1) { if (!empty($separator)) { $paged_suffix .= $separator . ' '; } $paged_suffix .= sprintf('Page %s', $paged); $textlen = $textlen - strlen($paged_suffix) - 1; } } if (!empty($add_hashtags) && !empty($hashtags)) { $textlen = $textlen - strlen($hashtags) - 1; } $title = $this->p->util->limit_text_length($title, $textlen, $trailing, false); // don't run cleanup_html_tags() } if (!empty($paged_suffix)) { $title .= ' ' . $paged_suffix; } if (!empty($add_hashtags) && !empty($hashtags)) { $title .= ' ' . $hashtags; } if ($encode === true) { $title = wp_encode_emoji(htmlentities($title, ENT_QUOTES, get_bloginfo('charset'), false)); } // double_encode = false return apply_filters($this->p->cf['lca'] . '_title', $title, $use_post, $add_hashtags, $md_idx, $src_id); }