| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Helpers; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Models\Indexable; |
| 6 |
|
| 7 |
/** |
| 8 |
* A helper object for the robots meta tag. |
| 9 |
*/ |
| 10 |
class Robots_Helper { |
| 11 |
|
| 12 |
/** |
| 13 |
* Holds the Post_Type_Helper. |
| 14 |
* |
| 15 |
* @var Post_Type_Helper |
| 16 |
*/ |
| 17 |
protected $post_type_helper; |
| 18 |
|
| 19 |
/** |
| 20 |
* Holds the Taxonomy_Helper. |
| 21 |
* |
| 22 |
* @var Taxonomy_Helper |
| 23 |
*/ |
| 24 |
protected $taxonomy_helper; |
| 25 |
|
| 26 |
/** |
| 27 |
* Constructs a Score_Helper. |
| 28 |
* |
| 29 |
* @param Post_Type_Helper $post_type_helper The Post_Type_Helper. |
| 30 |
* @param Taxonomy_Helper $taxonomy_helper The Taxonomy_Helper. |
| 31 |
*/ |
| 32 |
public function __construct( Post_Type_Helper $post_type_helper, Taxonomy_Helper $taxonomy_helper ) { |
| 33 |
$this->post_type_helper = $post_type_helper; |
| 34 |
$this->taxonomy_helper = $taxonomy_helper; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Retrieves whether the Indexable is indexable. |
| 39 |
* |
| 40 |
* @param Indexable $indexable The Indexable. |
| 41 |
* |
| 42 |
* @return bool Whether the Indexable is indexable. |
| 43 |
*/ |
| 44 |
public function is_indexable( Indexable $indexable ) { |
| 45 |
if ( $indexable->is_robots_noindex === null ) { |
| 46 |
// No individual value set, check the global setting. |
| 47 |
switch ( $indexable->object_type ) { |
| 48 |
case 'post': |
| 49 |
return $this->post_type_helper->is_indexable( $indexable->object_sub_type ); |
| 50 |
case 'term': |
| 51 |
return $this->taxonomy_helper->is_indexable( $indexable->object_sub_type ); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
return $indexable->is_robots_noindex === false; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Sets the robots index to noindex. |
| 60 |
* |
| 61 |
* @param array $robots The current robots value. |
| 62 |
* |
| 63 |
* @return array The altered robots string. |
| 64 |
*/ |
| 65 |
public function set_robots_no_index( $robots ) { |
| 66 |
if ( ! \is_array( $robots ) ) { |
| 67 |
\_deprecated_argument( __METHOD__, '14.1', '$robots has to be a key-value paired array.' ); |
| 68 |
return $robots; |
| 69 |
} |
| 70 |
|
| 71 |
$robots['index'] = 'noindex'; |
| 72 |
|
| 73 |
return $robots; |
| 74 |
} |
| 75 |
} |
| 76 |
|