PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / helpers / robots-helper.php

robots-helper.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI trunk, at src/helpers/robots-helper.php

76 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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