Commit realizado el 12:13:52 08-04-2024
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* The PostArchive Class
|
||||
*
|
||||
* @since 1.0.22
|
||||
* @package RankMath
|
||||
* @subpackage RankMath\Paper
|
||||
* @author Rank Math <support@rankmath.com>
|
||||
*/
|
||||
|
||||
namespace RankMath\Paper;
|
||||
|
||||
use RankMath\Helper;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Archive class.
|
||||
*/
|
||||
class Archive implements IPaper {
|
||||
|
||||
/**
|
||||
* Build the title for a post type archive.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function title() {
|
||||
$post_type = $this->get_queried_post_type();
|
||||
|
||||
return Paper::get_from_options( "pt_{$post_type}_archive_title", [], '%pt_plural% Archive %page% %sep% %sitename%' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the description for a post type archive.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function description() {
|
||||
$post_type = $this->get_queried_post_type();
|
||||
|
||||
return Paper::get_from_options( "pt_{$post_type}_archive_description", [], '%pt_plural% Archive %page% %sep% %sitename%' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the robots for a post type archive.
|
||||
*
|
||||
* @return string The robots to use on a post type archive.
|
||||
*/
|
||||
public function robots() {
|
||||
$robots = [];
|
||||
$post_type = $this->get_queried_post_type();
|
||||
|
||||
if ( Helper::get_settings( "titles.pt_{$post_type}_custom_robots" ) ) {
|
||||
$robots = Paper::robots_combine( Helper::get_settings( "titles.pt_{$post_type}_robots" ) );
|
||||
}
|
||||
|
||||
return $robots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the advanced robots for a post type archive.
|
||||
*
|
||||
* @return array The advanced robots to use on a post type archive.
|
||||
*/
|
||||
public function advanced_robots() {
|
||||
$robots = [];
|
||||
$post_type = $this->get_queried_post_type();
|
||||
|
||||
if ( Helper::get_settings( "titles.pt_{$post_type}_custom_robots" ) ) {
|
||||
$robots = Paper::advanced_robots_combine( Helper::get_settings( "titles.pt_{$post_type}_advanced_robots" ) );
|
||||
}
|
||||
|
||||
return $robots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the canonical URL.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function canonical() {
|
||||
return [ 'canonical' => get_post_type_archive_link( $this->get_queried_post_type() ) ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the meta keywords.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function keywords() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the queried post type.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_queried_post_type() {
|
||||
$post_type = get_query_var( 'post_type' );
|
||||
if ( is_array( $post_type ) ) {
|
||||
$post_type = reset( $post_type );
|
||||
}
|
||||
|
||||
return $post_type;
|
||||
}
|
||||
}
|
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* The Author Class
|
||||
*
|
||||
* @since 1.0.22
|
||||
* @package RankMath
|
||||
* @subpackage RankMath\Paper
|
||||
* @author Rank Math <support@rankmath.com>
|
||||
*/
|
||||
|
||||
namespace RankMath\Paper;
|
||||
|
||||
use RankMath\User;
|
||||
use RankMath\Helper;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Author class.
|
||||
*/
|
||||
class Author implements IPaper {
|
||||
|
||||
/**
|
||||
* Get the SEO title set in the user metabox.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function title() {
|
||||
$title = User::get_meta( 'title', $this->get_user_id() );
|
||||
if ( '' !== $title ) {
|
||||
return $title;
|
||||
}
|
||||
|
||||
return Paper::get_from_options( 'author_archive_title' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SEO description set in the user metabox.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function description() {
|
||||
$description = User::get_meta( 'description', $this->get_user_id() );
|
||||
if ( '' !== $description ) {
|
||||
return $description;
|
||||
}
|
||||
|
||||
return Paper::get_from_options( 'author_archive_description' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the robots meta value set in the user metabox.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function robots() {
|
||||
$robots = Paper::robots_combine( User::get_meta( 'robots', $this->get_user_id() ) );
|
||||
|
||||
if ( empty( $robots ) && Helper::get_settings( 'titles.author_custom_robots' ) ) {
|
||||
$robots = Paper::robots_combine( Helper::get_settings( 'titles.author_robots' ), true );
|
||||
}
|
||||
|
||||
return $robots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the advanced robots meta set in the user metabox.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function advanced_robots() {
|
||||
$robots = Paper::advanced_robots_combine( User::get_meta( 'advanced_robots', $this->get_user_id() ) );
|
||||
|
||||
if ( empty( $robots ) && Helper::get_settings( 'titles.author_custom_robots' ) ) {
|
||||
$robots = Paper::advanced_robots_combine( Helper::get_settings( 'titles.author_advanced_robots' ), true );
|
||||
}
|
||||
|
||||
return $robots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the canonical URL.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function canonical() {
|
||||
return [
|
||||
'canonical' => get_author_posts_url( $this->get_user_id(), get_query_var( 'author_name' ) ),
|
||||
'canonical_override' => User::get_meta( 'canonical_url', $this->get_user_id() ),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the meta keywords for the user (in our case, the Focus Keywords).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function keywords() {
|
||||
return User::get_meta( 'focus_keyword', $this->get_user_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user ID on the author archive or BBPress profile.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function get_user_id() {
|
||||
$author_id = get_query_var( 'author' );
|
||||
if ( $author_id ) {
|
||||
return $author_id;
|
||||
}
|
||||
|
||||
return get_query_var( 'bbp_user_id' );
|
||||
}
|
||||
}
|
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* The Home Class
|
||||
*
|
||||
* @since 1.0.22
|
||||
* @package RankMath
|
||||
* @subpackage RankMath\Paper
|
||||
* @author Rank Math <support@rankmath.com>
|
||||
*/
|
||||
|
||||
namespace RankMath\Paper;
|
||||
|
||||
use RankMath\Post;
|
||||
use RankMath\Helper;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Blog class.
|
||||
*/
|
||||
class Blog implements IPaper {
|
||||
|
||||
/**
|
||||
* Builds the title for Homepage.
|
||||
*
|
||||
* @return string The title to use on homepage.
|
||||
*/
|
||||
public function title() {
|
||||
return Paper::get_from_options( 'homepage_title' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the description for Homepage.
|
||||
*
|
||||
* @return string The description to use on a homepage.
|
||||
*/
|
||||
public function description() {
|
||||
return Paper::get_from_options( 'homepage_description', [], get_bloginfo( 'description' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the robots for Homepage.
|
||||
*
|
||||
* @return string The robots specified for the homepage.
|
||||
*/
|
||||
public function robots() {
|
||||
$robots = [];
|
||||
|
||||
if ( Helper::get_settings( 'titles.homepage_custom_robots' ) ) {
|
||||
$robots = Paper::robots_combine( Helper::get_settings( 'titles.homepage_robots' ) );
|
||||
}
|
||||
|
||||
if ( is_paged() && Helper::get_settings( 'titles.noindex_paginated_pages' ) ) {
|
||||
$robots['index'] = 'noindex';
|
||||
}
|
||||
|
||||
return $robots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the advanced robots for Homepage.
|
||||
*
|
||||
* @return array The advanced robots specified for the homepage.
|
||||
*/
|
||||
public function advanced_robots() {
|
||||
if ( ! Helper::get_settings( 'titles.homepage_custom_robots' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Paper::advanced_robots_combine( Helper::get_settings( 'titles.homepage_advanced_robots' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the canonical URL.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function canonical() {
|
||||
$canonical = home_url();
|
||||
if ( Post::is_posts_page() ) {
|
||||
$posts_page_id = get_option( 'page_for_posts' );
|
||||
$canonical = Post::get_meta( 'canonical_url', $posts_page_id );
|
||||
if ( empty( $canonical ) ) {
|
||||
$canonical = get_permalink( $posts_page_id );
|
||||
}
|
||||
}
|
||||
|
||||
return [ 'canonical' => $canonical ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the keywords.
|
||||
*
|
||||
* @return string The focus keywords.
|
||||
*/
|
||||
public function keywords() {
|
||||
if ( ! Post::is_posts_page() ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return Post::get_meta( 'focus_keyword', get_option( 'page_for_posts' ) );
|
||||
}
|
||||
}
|
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* The Date Class
|
||||
*
|
||||
* @since 1.0.22
|
||||
* @package RankMath
|
||||
* @subpackage RankMath\Paper
|
||||
* @author Rank Math <support@rankmath.com>
|
||||
*/
|
||||
|
||||
namespace RankMath\Paper;
|
||||
|
||||
use RankMath\Helper;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Date class.
|
||||
*/
|
||||
class Date implements IPaper {
|
||||
|
||||
/**
|
||||
* Get the SEO title for a date archive.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function title() {
|
||||
return Paper::get_from_options( 'date_archive_title' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SEO description for a date archive.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function description() {
|
||||
return Paper::get_from_options( 'date_archive_description' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the robots meta for a date archive.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function robots() {
|
||||
$robots = [];
|
||||
$robots = Paper::robots_combine( Helper::get_settings( 'titles.date_archive_robots' ) );
|
||||
if ( Helper::get_settings( 'titles.disable_date_archives' ) ) {
|
||||
$robots['index'] = 'noindex';
|
||||
}
|
||||
|
||||
return $robots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the advanced robots meta for a date archive.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function advanced_robots() {
|
||||
return Paper::advanced_robots_combine( Helper::get_settings( 'titles.date_advanced_robots' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the canonical URL for the current page.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function canonical() {
|
||||
$canonical = '';
|
||||
if ( is_day() ) {
|
||||
$canonical = get_day_link( get_query_var( 'year' ), get_query_var( 'monthnum' ), get_query_var( 'day' ) );
|
||||
} elseif ( is_month() ) {
|
||||
$canonical = get_month_link( get_query_var( 'year' ), get_query_var( 'monthnum' ) );
|
||||
} elseif ( is_year() ) {
|
||||
$canonical = get_year_link( get_query_var( 'year' ) );
|
||||
}
|
||||
|
||||
return [ 'canonical' => $canonical ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the meta keywords.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function keywords() {
|
||||
return '';
|
||||
}
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* The 404 paper.
|
||||
*
|
||||
* @since 1.0.22
|
||||
* @package RankMath
|
||||
* @subpackage RankMath\Paper
|
||||
* @author Rank Math <support@rankmath.com>
|
||||
*/
|
||||
|
||||
namespace RankMath\Paper;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* 404 Error.
|
||||
*/
|
||||
class Error_404 implements IPaper {
|
||||
|
||||
/**
|
||||
* Retrieves the SEO title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function title() {
|
||||
return Paper::get_from_options( '404_title', [], esc_html__( 'Page not found', 'rank-math' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the SEO description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function description() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the robots.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function robots() {
|
||||
return [ 'index' => 'noindex' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the advanced robots.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function advanced_robots() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the canonical URL.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function canonical() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves meta keywords.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function keywords() {
|
||||
return '';
|
||||
}
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* The Misc paper.
|
||||
*
|
||||
* @since 1.0.28
|
||||
* @package RankMath
|
||||
* @subpackage RankMath\Paper
|
||||
* @author Rank Math <support@rankmath.com>
|
||||
*/
|
||||
|
||||
namespace RankMath\Paper;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Misc class.
|
||||
*/
|
||||
class Misc implements IPaper {
|
||||
|
||||
/**
|
||||
* Retrieves the SEO title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function title() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the SEO description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function description() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the robots.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function robots() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the advanced robots.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function advanced_robots() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the canonical URL.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function canonical() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves meta keywords.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function keywords() {
|
||||
return '';
|
||||
}
|
||||
}
|
@@ -0,0 +1,557 @@
|
||||
<?php
|
||||
/**
|
||||
* The Paper Class
|
||||
*
|
||||
* @since 1.0.22
|
||||
* @package RankMath
|
||||
* @subpackage RankMath\Paper
|
||||
* @author Rank Math <support@rankmath.com>
|
||||
*/
|
||||
|
||||
namespace RankMath\Paper;
|
||||
|
||||
use RankMath\Post;
|
||||
use RankMath\Helper;
|
||||
use RankMath\Sitemap\Router;
|
||||
use RankMath\Traits\Hooker;
|
||||
use RankMath\Helpers\Str;
|
||||
use RankMath\Helpers\Url;
|
||||
use RankMath\Helpers\Security;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Paper class.
|
||||
*/
|
||||
class Paper {
|
||||
|
||||
use Hooker;
|
||||
|
||||
/**
|
||||
* Hold the class instance.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* Hold current paper object.
|
||||
*
|
||||
* @var IPaper
|
||||
*/
|
||||
private $paper = null;
|
||||
|
||||
/**
|
||||
* Hold title.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $title = null;
|
||||
|
||||
/**
|
||||
* Hold description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $description = null;
|
||||
|
||||
/**
|
||||
* Hold robots.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $robots = null;
|
||||
|
||||
/**
|
||||
* Hold canonical.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $canonical = null;
|
||||
|
||||
/**
|
||||
* Hold keywords.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $keywords = null;
|
||||
|
||||
/**
|
||||
* Initialize object
|
||||
*
|
||||
* @return object Post|Term|User.
|
||||
*/
|
||||
public static function get() {
|
||||
if ( ! is_null( self::$instance ) ) {
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
self::$instance = new Paper();
|
||||
self::$instance->setup();
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup paper.
|
||||
*/
|
||||
private function setup() {
|
||||
foreach ( $this->get_papers() as $class_name => $is_valid ) {
|
||||
if ( $this->do_filter( 'paper/is_valid/' . strtolower( $class_name ), $is_valid ) ) {
|
||||
$class_name = '\\RankMath\\Paper\\' . $class_name;
|
||||
$this->paper = new $class_name();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! method_exists( $this->paper, 'set_object' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( Post::is_home_static_page() ) {
|
||||
$this->paper->set_object( get_queried_object() );
|
||||
} elseif ( Post::is_simple_page() ) {
|
||||
$post = Post::get( Post::get_page_id() );
|
||||
$this->paper->set_object( $post->get_object() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get papers types.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_papers() {
|
||||
return $this->do_filter(
|
||||
'paper/hash',
|
||||
[
|
||||
'Search' => is_search(),
|
||||
'Shop' => Post::is_shop_page(),
|
||||
'Singular' => Post::is_home_static_page() || Post::is_simple_page(),
|
||||
'Blog' => Post::is_home_posts_page(),
|
||||
'Author' => is_author() || ( Helper::is_module_active( 'bbpress' ) && function_exists( 'bbp_is_single_user' ) && bbp_is_single_user() ),
|
||||
'Date' => is_date(),
|
||||
'Taxonomy' => is_category() || is_tag() || is_tax(),
|
||||
'Archive' => is_archive(),
|
||||
'Error_404' => is_404(),
|
||||
'Misc' => true,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title after sanitization.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title() {
|
||||
if ( ! is_null( $this->title ) ) {
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow changing the title.
|
||||
*
|
||||
* @param string $title The page title being put out.
|
||||
*/
|
||||
$this->title = $this->do_filter( 'frontend/title', $this->paper->title() );
|
||||
|
||||
// Early Bail!!
|
||||
if ( '' === $this->title ) {
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
// Remove excess whitespace.
|
||||
$this->title = preg_replace( '[\s\s+]', ' ', $this->title );
|
||||
|
||||
// Capitalize Titles.
|
||||
if ( Helper::get_settings( 'titles.capitalize_titles' ) ) {
|
||||
$this->title = Str::mb_ucwords( $this->title );
|
||||
}
|
||||
|
||||
$this->title = wp_strip_all_tags( stripslashes( $this->title ), true );
|
||||
$this->title = esc_html( $this->title );
|
||||
$this->title = convert_smilies( $this->title );
|
||||
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get description after sanitization.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
if ( ! is_null( $this->description ) ) {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow changing the meta description sentence.
|
||||
*
|
||||
* @param string $description The description sentence.
|
||||
*/
|
||||
$this->description = $this->do_filter( 'frontend/description', trim( $this->paper->description() ) );
|
||||
|
||||
// Early Bail!!
|
||||
if ( '' === $this->description ) {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
$this->description = wp_strip_all_tags( stripslashes( $this->description ), true );
|
||||
$this->description = esc_attr( $this->description );
|
||||
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get robots after sanitization.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_robots() {
|
||||
if ( ! is_null( $this->robots ) ) {
|
||||
return $this->robots;
|
||||
}
|
||||
|
||||
$this->robots = $this->paper->robots();
|
||||
if ( empty( $this->robots ) ) {
|
||||
$this->robots = self::robots_combine( Helper::get_settings( 'titles.robots_global' ) );
|
||||
}
|
||||
$this->validate_robots();
|
||||
$this->respect_settings_for_robots();
|
||||
|
||||
/**
|
||||
* Allows filtering of the meta robots.
|
||||
*
|
||||
* @param array $robots The meta robots directives to be echoed.
|
||||
*/
|
||||
$this->robots = $this->do_filter( 'frontend/robots', array_unique( $this->robots ) );
|
||||
$this->advanced_robots();
|
||||
|
||||
return $this->robots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate robots.
|
||||
*/
|
||||
private function validate_robots() {
|
||||
if ( empty( $this->robots ) || ! is_array( $this->robots ) ) {
|
||||
$this->robots = [
|
||||
'index' => 'index',
|
||||
'follow' => 'follow',
|
||||
];
|
||||
return;
|
||||
}
|
||||
|
||||
$this->robots = array_intersect_key(
|
||||
$this->robots,
|
||||
[
|
||||
'index' => '',
|
||||
'follow' => '',
|
||||
'noarchive' => '',
|
||||
'noimageindex' => '',
|
||||
'nosnippet' => '',
|
||||
]
|
||||
);
|
||||
|
||||
// Add Index and Follow.
|
||||
if ( ! isset( $this->robots['index'] ) ) {
|
||||
$this->robots = [ 'index' => 'index' ] + $this->robots;
|
||||
}
|
||||
if ( ! isset( $this->robots['follow'] ) ) {
|
||||
$this->robots = [ 'follow' => 'follow' ] + $this->robots;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Advanced robots.
|
||||
*/
|
||||
private function advanced_robots() {
|
||||
// Early Bail if robots is set to noindex or nosnippet!
|
||||
if ( ( isset( $this->robots['index'] ) && 'noindex' === $this->robots['index'] ) || ( isset( $this->robots['nosnippet'] ) && 'nosnippet' === $this->robots['nosnippet'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$advanced_robots = $this->paper->advanced_robots();
|
||||
if ( ! is_array( $advanced_robots ) ) {
|
||||
$advanced_robots = wp_parse_args(
|
||||
Helper::get_settings( 'titles.advanced_robots_global' ),
|
||||
[
|
||||
'max-snippet' => -1,
|
||||
'max-video-preview' => -1,
|
||||
'max-image-preview' => 'large',
|
||||
]
|
||||
);
|
||||
|
||||
$advanced_robots = self::advanced_robots_combine( $advanced_robots );
|
||||
}
|
||||
|
||||
$advanced_robots = array_intersect_key(
|
||||
$advanced_robots,
|
||||
[
|
||||
'max-snippet' => '',
|
||||
'max-video-preview' => '',
|
||||
'max-image-preview' => '',
|
||||
]
|
||||
);
|
||||
|
||||
/**
|
||||
* Allows filtering of the advanced meta robots.
|
||||
*
|
||||
* @param array $robots The meta robots directives to be echoed.
|
||||
*/
|
||||
$advanced_robots = $this->do_filter( 'frontend/advanced_robots', array_unique( $advanced_robots ) );
|
||||
|
||||
$this->robots = ! empty( $advanced_robots ) ? $this->robots + $advanced_robots : $this->robots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get focus keywords
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_keywords() {
|
||||
if ( ! is_null( $this->keywords ) ) {
|
||||
return $this->keywords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows filtering of the meta keywords.
|
||||
*
|
||||
* @param array $keywords The meta keywords to be echoed.
|
||||
*/
|
||||
$this->keywords = $this->do_filter( 'frontend/keywords', $this->paper->keywords() );
|
||||
|
||||
return $this->keywords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Respect some robots settings.
|
||||
*/
|
||||
private function respect_settings_for_robots() {
|
||||
// If blog is not public or replytocom is set, then force noindex.
|
||||
if ( 0 === absint( get_option( 'blog_public' ) ) || isset( $_GET['replytocom'] ) ) {
|
||||
$this->robots['index'] = 'noindex';
|
||||
$this->robots['follow'] = 'nofollow';
|
||||
}
|
||||
|
||||
// Force noindex for sub-pages.
|
||||
if ( is_paged() && Helper::get_settings( 'titles.noindex_archive_subpages' ) ) {
|
||||
$this->robots['index'] = 'noindex';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get canonical after sanitization.
|
||||
*
|
||||
* @param bool $un_paged Whether or not to return the canonical with or without pagination added to the URL.
|
||||
* @param bool $no_override Whether or not to return a manually overridden canonical.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_canonical( $un_paged = false, $no_override = false ) {
|
||||
if ( is_null( $this->canonical ) ) {
|
||||
$this->generate_canonical();
|
||||
}
|
||||
|
||||
$canonical = $this->canonical['canonical'];
|
||||
if ( $un_paged ) {
|
||||
$canonical = $this->canonical['canonical_unpaged'];
|
||||
} elseif ( $no_override ) {
|
||||
$canonical = $this->canonical['canonical_no_override'];
|
||||
}
|
||||
|
||||
return $canonical;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate canonical URL parts.
|
||||
*/
|
||||
private function generate_canonical() {
|
||||
$this->canonical = wp_parse_args(
|
||||
$this->paper->canonical(),
|
||||
[
|
||||
'canonical' => false,
|
||||
'canonical_unpaged' => false,
|
||||
'canonical_override' => false,
|
||||
]
|
||||
);
|
||||
extract( $this->canonical ); // phpcs:ignore
|
||||
|
||||
if ( is_front_page() || ( function_exists( 'ampforwp_is_front_page' ) && ampforwp_is_front_page() ) ) {
|
||||
$canonical = user_trailingslashit( home_url() );
|
||||
}
|
||||
|
||||
// If not singular than we can have pagination.
|
||||
if ( ! is_singular() ) {
|
||||
$canonical_unpaged = $canonical;
|
||||
$canonical = $this->get_canonical_paged( $canonical );
|
||||
}
|
||||
|
||||
$this->canonical['canonical_unpaged'] = $canonical_unpaged;
|
||||
$this->canonical['canonical_no_override'] = $canonical;
|
||||
|
||||
// Force absolute URLs for canonicals.
|
||||
$canonical = Str::is_non_empty( $canonical ) && true === Url::is_relative( $canonical ) ? $this->base_url( $canonical ) : $canonical;
|
||||
$canonical = Str::is_non_empty( $canonical_override ) ? $canonical_override : $canonical;
|
||||
|
||||
/**
|
||||
* Filter the canonical URL.
|
||||
*
|
||||
* @param string $canonical The canonical URL.
|
||||
*/
|
||||
$this->canonical['canonical'] = apply_filters( 'rank_math/frontend/canonical', $canonical );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the paged version of the canonical URL if needed.
|
||||
*
|
||||
* @param string $canonical The canonical URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_canonical_paged( $canonical ) {
|
||||
global $wp_rewrite;
|
||||
|
||||
if ( ! $canonical || get_query_var( 'paged' ) < 2 ) {
|
||||
return $canonical;
|
||||
}
|
||||
|
||||
if ( ! $wp_rewrite->using_permalinks() ) {
|
||||
return Security::add_query_arg_raw(
|
||||
'paged',
|
||||
get_query_var( 'paged' ),
|
||||
is_front_page() ? trailingslashit( $canonical ) : $canonical
|
||||
);
|
||||
}
|
||||
|
||||
return user_trailingslashit(
|
||||
trailingslashit( is_front_page() ? Router::get_base_url( '' ) : $canonical ) .
|
||||
trailingslashit( $wp_rewrite->pagination_base ) .
|
||||
get_query_var( 'paged' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base URL for relative URLs by parsing the home URL.
|
||||
*
|
||||
* @copyright Copyright (C) 2008-2019, Yoast BV
|
||||
* The following code is a derivative work of the code from the Yoast (https://github.com/Yoast/wordpress-seo/), which is licensed under GPL v3.
|
||||
*
|
||||
* @param string $path Optional path string.
|
||||
* @return string
|
||||
*/
|
||||
private function base_url( $path = null ) {
|
||||
$parts = wp_parse_url( get_option( 'home' ) );
|
||||
$base_url = trailingslashit( $parts['scheme'] . '://' . $parts['host'] );
|
||||
|
||||
if ( ! is_null( $path ) ) {
|
||||
$base_url .= ltrim( $path, '/' );
|
||||
}
|
||||
|
||||
return $base_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title or description option from the settings.
|
||||
* The results will be run through the Helper::replace_vars() function.
|
||||
*
|
||||
* @param string $id Name of the option we are looking for.
|
||||
* @param object|array $object Object to pass to the replace_vars function.
|
||||
* @param string $default Default value if nothing found.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_from_options( $id, $object = [], $default = '' ) {
|
||||
$value = Helper::get_settings( "titles.$id" );
|
||||
|
||||
// Break loop.
|
||||
if ( ! Str::ends_with( 'default_snippet_name', $value ) && ! Str::ends_with( 'default_snippet_desc', $value ) ) {
|
||||
$value = \str_replace(
|
||||
[ '%seo_title%', '%seo_description%' ],
|
||||
[ '%title%', '%excerpt%' ],
|
||||
$value
|
||||
);
|
||||
}
|
||||
|
||||
return Helper::replace_vars( '' !== $value ? $value : $default, $object );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make robots values as keyed array.
|
||||
*
|
||||
* @param array $robots Main instance.
|
||||
* @param bool $default Append default.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function robots_combine( $robots, $default = false ) {
|
||||
if ( empty( $robots ) || ! is_array( $robots ) ) {
|
||||
return ! $default ? [] : [
|
||||
'index' => 'index',
|
||||
'follow' => 'follow',
|
||||
];
|
||||
}
|
||||
|
||||
$robots = array_combine( $robots, $robots );
|
||||
|
||||
// Fix noindex key to index.
|
||||
if ( isset( $robots['noindex'] ) ) {
|
||||
$robots = [ 'index' => $robots['noindex'] ] + $robots;
|
||||
unset( $robots['noindex'] );
|
||||
}
|
||||
|
||||
// Fix nofollow key to follow.
|
||||
if ( isset( $robots['nofollow'] ) ) {
|
||||
$robots = [ 'follow' => $robots['nofollow'] ] + $robots;
|
||||
unset( $robots['nofollow'] );
|
||||
}
|
||||
|
||||
return $robots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make robots values as keyed array.
|
||||
*
|
||||
* @param array $advanced_robots Main instance.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function advanced_robots_combine( $advanced_robots ) {
|
||||
if ( empty( $advanced_robots ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$robots = [];
|
||||
foreach ( $advanced_robots as $key => $data ) {
|
||||
if ( $data ) {
|
||||
$robots[ $key ] = $key . ':' . $data;
|
||||
}
|
||||
}
|
||||
return $robots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should apply shortcode on content.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function should_apply_shortcode() {
|
||||
if (
|
||||
Post::is_woocommerce_page() ||
|
||||
( function_exists( 'is_wcfm_page' ) && is_wcfm_page() )
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return apply_filters( 'rank_math/paper/auto_generated_description/apply_shortcode', false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears and reinitializes the object.
|
||||
*/
|
||||
public static function reset() {
|
||||
self::$instance = null;
|
||||
return self::get();
|
||||
}
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* The Search Results paper.
|
||||
*
|
||||
* @since 1.0.22
|
||||
* @package RankMath
|
||||
* @subpackage RankMath\Paper
|
||||
* @author Rank Math <support@rankmath.com>
|
||||
*/
|
||||
|
||||
namespace RankMath\Paper;
|
||||
|
||||
use RankMath\Helper;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Search results.
|
||||
*/
|
||||
class Search implements IPaper {
|
||||
|
||||
/**
|
||||
* Retrieves the SEO title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function title() {
|
||||
return Paper::get_from_options( 'search_title', [], 'Searched for %search_query% %page% %sep% %sitename%' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the SEO description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function description() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the robots.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function robots() {
|
||||
return Helper::get_settings( 'titles.noindex_search' ) ? [ 'index' => 'noindex' ] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the advanced robots.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function advanced_robots() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the canonical URL.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function canonical() {
|
||||
$search_query = get_search_query();
|
||||
return [ 'canonical' => ! empty( $search_query ) && ! preg_match( '|^page/\d+$|', $search_query ) ? get_search_link() : '' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves meta keywords.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function keywords() {
|
||||
return '';
|
||||
}
|
||||
}
|
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* The Shop paper.
|
||||
*
|
||||
* @since 1.0.22
|
||||
* @package RankMath
|
||||
* @subpackage RankMath\Paper
|
||||
* @author Rank Math <support@rankmath.com>
|
||||
*/
|
||||
|
||||
namespace RankMath\Paper;
|
||||
|
||||
use RankMath\Post;
|
||||
use RankMath\Helper;
|
||||
use RankMath\Helpers\Str;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Shop.
|
||||
*/
|
||||
class Shop extends Singular {
|
||||
|
||||
/**
|
||||
* Retrieves the WooCommerce Shop SEO title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function title() {
|
||||
$post = Post::get( Post::get_shop_page_id() );
|
||||
$title = $this->get_post_title( $post->get_object() );
|
||||
|
||||
// Early Bail!
|
||||
if ( Str::is_non_empty( $title ) ) {
|
||||
return $title;
|
||||
}
|
||||
|
||||
return Paper::get_from_options( 'pt_product_archive_title', [], '%pt_plural% Archive %page% %sep% %sitename%' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the WooCommerce Shop SEO description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function description() {
|
||||
$post = Post::get( Post::get_shop_page_id() );
|
||||
$desc = $this->get_post_description( $post->get_object() );
|
||||
|
||||
return '' !== $desc ? $desc : Paper::get_from_options( 'pt_product_archive_description', [], '%pt_plural% Archive %page% %sep% %sitename%' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the WooCommerce Shop robots.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function robots() {
|
||||
$post = Post::get( Post::get_shop_page_id() );
|
||||
return $this->get_post_robots( $post->get_object() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the WooCommerce Shop advanced robots.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function advanced_robots() {
|
||||
$post = Post::get( Post::get_shop_page_id() );
|
||||
$object = $post->get_object();
|
||||
return $this->get_post_advanced_robots( $object );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves meta keywords.
|
||||
*
|
||||
* @return string The focus keywords.
|
||||
*/
|
||||
public function keywords() {
|
||||
return Post::get_meta( 'focus_keyword', Post::get_shop_page_id() );
|
||||
}
|
||||
}
|
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
/**
|
||||
* The Singular Class
|
||||
*
|
||||
* @since 1.0.22
|
||||
* @package RankMath
|
||||
* @subpackage RankMath\Paper
|
||||
* @author Rank Math <support@rankmath.com>
|
||||
*/
|
||||
|
||||
namespace RankMath\Paper;
|
||||
|
||||
use RankMath\Post;
|
||||
use RankMath\Helper;
|
||||
use RankMath\Helpers\Security;
|
||||
use RankMath\Helpers\Str;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Singular class.
|
||||
*/
|
||||
class Singular implements IPaper {
|
||||
|
||||
/**
|
||||
* Post object.
|
||||
*
|
||||
* @var WP_Post
|
||||
*/
|
||||
private $object;
|
||||
|
||||
/**
|
||||
* Retrieves the SEO title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function title() {
|
||||
return $this->get_post_title( $this->object );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the SEO description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function description() {
|
||||
return $this->get_post_description( $this->object );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the robots.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function robots() {
|
||||
return $this->get_post_robots( $this->object );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the advanced robots.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function advanced_robots() {
|
||||
return $this->get_post_advanced_robots( $this->object );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the canonical URL.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function canonical() {
|
||||
$object_id = Post::get_page_id();
|
||||
$canonical = get_permalink( $object_id );
|
||||
$canonical_unpaged = $canonical;
|
||||
$canonical_override = Post::get_meta( 'canonical_url', $object_id );
|
||||
|
||||
/**
|
||||
* Fix paginated pages canonical, but only if the page is truly paginated.
|
||||
*
|
||||
* @copyright Copyright (C) 2008-2019, Yoast BV
|
||||
* The following code is a derivative work of the code from the Yoast(https://github.com/Yoast/wordpress-seo/), which is licensed under GPL v3.
|
||||
*/
|
||||
if ( is_singular() && get_query_var( 'page' ) > 1 ) {
|
||||
$num_pages = ( substr_count( get_queried_object()->post_content, '<!--nextpage-->' ) + 1 );
|
||||
if ( $num_pages && get_query_var( 'page' ) <= $num_pages ) {
|
||||
global $wp_rewrite;
|
||||
$canonical = ! $wp_rewrite->using_permalinks() ? Security::add_query_arg_raw( 'page', get_query_var( 'page' ), $canonical ) :
|
||||
user_trailingslashit( trailingslashit( $canonical ) . get_query_var( 'page' ) );
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'canonical' => $canonical,
|
||||
'canonical_unpaged' => $canonical,
|
||||
'canonical_override' => $canonical_override,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves meta keywords.
|
||||
*
|
||||
* @return string The focus keywords.
|
||||
*/
|
||||
public function keywords() {
|
||||
return Post::get_meta( 'focus_keyword', $this->object->ID );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set post object.
|
||||
*
|
||||
* @param WP_Post $object Current post object.
|
||||
*/
|
||||
public function set_object( $object ) {
|
||||
$this->object = $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SEO title set in the post metabox.
|
||||
*
|
||||
* @param object|null $object Post object to retrieve the title for.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_post_title( $object = null ) {
|
||||
if ( ! is_object( $object ) ) {
|
||||
return Paper::get_from_options( '404_title', [], esc_html__( 'Page not found', 'rank-math' ) );
|
||||
}
|
||||
|
||||
$title = Post::get_meta( 'title', $object->ID );
|
||||
if ( '' !== $title ) {
|
||||
return $title;
|
||||
}
|
||||
|
||||
$post_type = isset( $object->post_type ) ? $object->post_type : $object->query_var;
|
||||
return Paper::get_from_options( "pt_{$post_type}_title", $object, '%title% %sep% %sitename%' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the SEO description set in the post metabox.
|
||||
*
|
||||
* Retrieve in this order:
|
||||
* 1. Custom meta description set for the post in SERP field
|
||||
* 2. Excerpt
|
||||
* 3. Description template set in the Titles & Meta
|
||||
* 4. Paragraph with the focus keyword
|
||||
* 5. The First paragraph of the content
|
||||
*
|
||||
* @param object|null $object Object to retrieve the description from.
|
||||
*
|
||||
* @return string The SEO description for the specified object, or queried object if not supplied.
|
||||
*/
|
||||
protected function get_post_description( $object = null ) {
|
||||
if ( ! is_object( $object ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// 1. Custom meta description set for the post in SERP field.
|
||||
$description = Post::get_meta( 'description', $object->ID );
|
||||
if ( '' !== $description ) {
|
||||
return $description;
|
||||
}
|
||||
|
||||
// 2. Excerpt
|
||||
if ( ! empty( $object->post_excerpt ) ) {
|
||||
return $object->post_excerpt;
|
||||
}
|
||||
|
||||
// 3. Description template set in the Titles & Meta.
|
||||
$post_type = isset( $object->post_type ) ? $object->post_type : $object->query_var;
|
||||
|
||||
return Str::truncate( Paper::get_from_options( "pt_{$post_type}_description", $object ), 160 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the robots set in the post metabox.
|
||||
*
|
||||
* @param object|null $object Object to retrieve the robots data from.
|
||||
*
|
||||
* @return string The robots for the specified object, or queried object if not supplied.
|
||||
*/
|
||||
protected function get_post_robots( $object = null ) {
|
||||
if ( ! is_object( $object ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$post_type = $object->post_type;
|
||||
$robots = Paper::robots_combine( Post::get_meta( 'robots', $object->ID ) );
|
||||
if ( empty( $robots ) && Helper::get_settings( "titles.pt_{$post_type}_custom_robots" ) ) {
|
||||
$robots = Paper::robots_combine( Helper::get_settings( "titles.pt_{$post_type}_robots" ), true );
|
||||
}
|
||||
|
||||
// `noindex` these conditions.
|
||||
$noindex_private = 'private' === $object->post_status;
|
||||
$no_index_subpages = is_paged() && Helper::get_settings( 'titles.noindex_paginated_pages' );
|
||||
$noindex_password_protected = ! empty( $object->post_password ) && Helper::get_settings( 'titles.noindex_password_protected' );
|
||||
|
||||
if ( $noindex_private || $noindex_password_protected || $no_index_subpages ) {
|
||||
$robots['index'] = 'noindex';
|
||||
}
|
||||
|
||||
return $robots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the advanced robots set in the post metabox.
|
||||
*
|
||||
* @param object|null $object Object to retrieve the robots data from.
|
||||
*
|
||||
* @return string The robots for the specified object, or queried object if not supplied.
|
||||
*/
|
||||
protected function get_post_advanced_robots( $object = null ) {
|
||||
if ( ! is_object( $this->object ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$post_type = $this->object->post_type;
|
||||
$robots = Paper::advanced_robots_combine( Post::get_meta( 'advanced_robots', $this->object->ID ) );
|
||||
if ( ! is_array( $robots ) && Helper::get_settings( "titles.pt_{$post_type}_custom_robots" ) ) {
|
||||
$robots = Paper::advanced_robots_combine( Helper::get_settings( "titles.pt_{$post_type}_advanced_robots" ), true );
|
||||
}
|
||||
|
||||
return $robots;
|
||||
}
|
||||
}
|
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/**
|
||||
* The Term Class
|
||||
*
|
||||
* @since 1.0.22
|
||||
* @package RankMath
|
||||
* @subpackage RankMath\Paper
|
||||
* @author Rank Math <support@rankmath.com>
|
||||
*/
|
||||
|
||||
namespace RankMath\Paper;
|
||||
|
||||
use RankMath\Term;
|
||||
use RankMath\Helper;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Taxonomy class.
|
||||
*/
|
||||
class Taxonomy implements IPaper {
|
||||
|
||||
/**
|
||||
* Retrieves the SEO title for a taxonomy.
|
||||
*
|
||||
* @return string The SEO title for the taxonomy.
|
||||
*/
|
||||
public function title() {
|
||||
$object = get_queried_object();
|
||||
if ( ! is_object( $object ) ) {
|
||||
return Paper::get_from_options( '404_title', [], esc_html__( 'Page not found', 'rank-math' ) );
|
||||
}
|
||||
|
||||
$title = Term::get_meta( 'title', $object, $object->taxonomy );
|
||||
if ( '' !== $title ) {
|
||||
return $title;
|
||||
}
|
||||
|
||||
return Paper::get_from_options( "tax_{$object->taxonomy}_title", $object );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the SEO description for a taxonomy.
|
||||
*
|
||||
* @return string The SEO description for the taxonomy.
|
||||
*/
|
||||
public function description() {
|
||||
$object = get_queried_object();
|
||||
$description = Term::get_meta( 'description', $object, $object->taxonomy );
|
||||
if ( '' !== $description ) {
|
||||
return $description;
|
||||
}
|
||||
|
||||
return Paper::get_from_options( "tax_{$object->taxonomy}_description", $object );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the robots for a taxonomy.
|
||||
*
|
||||
* @return string The robots for the taxonomy
|
||||
*/
|
||||
public function robots() {
|
||||
$object = get_queried_object();
|
||||
$robots = Paper::robots_combine( Term::get_meta( 'robots', $object ) );
|
||||
|
||||
if ( is_object( $object ) && empty( $robots ) && Helper::get_settings( "titles.tax_{$object->taxonomy}_custom_robots" ) ) {
|
||||
$robots = Paper::robots_combine( Helper::get_settings( "titles.tax_{$object->taxonomy}_robots" ), true );
|
||||
}
|
||||
|
||||
if ( $this->noindex_term( $object ) ) {
|
||||
$robots['index'] = 'noindex';
|
||||
}
|
||||
|
||||
return $robots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the advanced robots for a taxonomy.
|
||||
*
|
||||
* @return array The advanced robots for the taxonomy
|
||||
*/
|
||||
public function advanced_robots() {
|
||||
$object = get_queried_object();
|
||||
$robots = Paper::advanced_robots_combine( Term::get_meta( 'advanced_robots', $object ) );
|
||||
|
||||
if ( is_object( $object ) && empty( $robots ) && Helper::get_settings( "titles.tax_{$object->taxonomy}_custom_robots" ) ) {
|
||||
$robots = Paper::advanced_robots_combine( Helper::get_settings( "titles.tax_{$object->taxonomy}_advanced_robots" ), true );
|
||||
}
|
||||
|
||||
return $robots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the canonical URL.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function canonical() {
|
||||
$object = get_queried_object();
|
||||
|
||||
if ( empty( $object ) || Term::is_multiple_terms_query() ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$term_link = get_term_link( $object, $object->taxonomy );
|
||||
|
||||
return [
|
||||
'canonical' => is_wp_error( $term_link ) ? '' : $term_link,
|
||||
'canonical_override' => Term::get_meta( 'canonical_url', $object, $object->taxonomy ),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the keywords.
|
||||
*
|
||||
* @return string The focus keywords.
|
||||
*/
|
||||
public function keywords() {
|
||||
$object = get_queried_object();
|
||||
|
||||
if ( empty( $object ) || Term::is_multiple_terms_query() ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return Term::get_meta( 'focus_keyword', $object, $object->taxonomy );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to noindex empty terms.
|
||||
*
|
||||
* @param object $object Current taxonomy term object.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function noindex_term( $object ) {
|
||||
if ( Term::is_multiple_terms_query() ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( is_object( $object ) && 0 === $object->count && Helper::get_settings( 'titles.noindex_empty_taxonomies' ) ) {
|
||||
$children = get_terms(
|
||||
$object->taxonomy,
|
||||
[
|
||||
'parent' => $object->term_id,
|
||||
'number' => 1,
|
||||
'fields' => 'ids',
|
||||
]
|
||||
);
|
||||
|
||||
if ( empty( $children ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* The Paper Interface
|
||||
*
|
||||
* @since 1.0.22
|
||||
* @package RankMath
|
||||
* @subpackage RankMath\Paper
|
||||
* @author Rank Math <support@rankmath.com>
|
||||
*/
|
||||
|
||||
namespace RankMath\Paper;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Paper interface.
|
||||
*/
|
||||
interface IPaper {
|
||||
|
||||
/**
|
||||
* Retrieves the SEO title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function title();
|
||||
|
||||
/**
|
||||
* Retrieves the SEO description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function description();
|
||||
|
||||
/**
|
||||
* Retrieves the robots.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function robots();
|
||||
|
||||
/**
|
||||
* Retrieves the advanced robots.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function advanced_robots();
|
||||
|
||||
/**
|
||||
* Retrieves the canonical URL.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function canonical();
|
||||
|
||||
/**
|
||||
* Retrieves the keywords.
|
||||
*
|
||||
* @return string The focus keywords.
|
||||
*/
|
||||
public function keywords();
|
||||
}
|
Reference in New Issue
Block a user