| @@ -1,12 +1,60 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Yoast\WP\SEO\Helpers; |
| 4 | 4 | |
| 5 | +use Yoast\WP\SEO\Models\Indexable; | |
| 6 | + | |
| 5 | 7 | /** |
| 6 | 8 | * A helper object for the robots meta tag. |
| 7 | 9 | */ |
| 8 | 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 | + } | |
| 9 | 57 | |
| 10 | 58 | /** |
| 11 | 59 | * Sets the robots index to noindex. |
| 12 | 60 | * |