PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.3
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.3
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 / values / robots / user-agent-list.php

user-agent-list.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.3, at src/values/robots/user-agent-list.php

89 lines 1.8 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\Values\Robots;
4
5 /**
6 * Class User_Agent_List
7 */
8 class User_Agent_List {
9
10 /**
11 * The list of user agents.
12 *
13 * @var array
14 */
15 private $user_agent_list;
16
17 /**
18 * User Agent list constructor.
19 */
20 public function __construct() {
21 $this->user_agent_list = [];
22 }
23
24 /**
25 * Checks if given user_agent is already registered.
26 *
27 * @param string $user_agent The user agent identifier.
28 *
29 * @return bool
30 */
31 public function has_user_agent( $user_agent ) {
32 return \array_key_exists( $user_agent, $this->user_agent_list );
33 }
34
35 /**
36 * Gets the user agent object. If it is not yet registered it creates it.
37 *
38 * @param string $user_agent The user agent identifier.
39 *
40 * @return User_Agent
41 */
42 public function get_user_agent( $user_agent ) {
43 if ( $this->has_user_agent( $user_agent ) ) {
44 return $this->user_agent_list[ $user_agent ];
45 }
46
47 $this->user_agent_list[ $user_agent ] = new User_Agent( $user_agent );
48
49 return $this->user_agent_list[ $user_agent ];
50 }
51
52 /**
53 * Gets the list of user agents.
54 *
55 * @return array
56 */
57 public function get_user_agents() {
58 return $this->user_agent_list;
59 }
60
61 /**
62 * Gets a list of all disallow directives by user agent.
63 *
64 * @return array
65 */
66 public function get_disallow_directives() {
67 $directives = [];
68 foreach ( $this->user_agent_list as $user_agent ) {
69 $directives[ $user_agent->get_user_agent() ] = $user_agent->get_disallow_paths();
70 }
71
72 return $directives;
73 }
74
75 /**
76 * Gets a list of all sallow directives by user agent.
77 *
78 * @return array
79 */
80 public function get_allow_directives() {
81 $directives = [];
82 foreach ( $this->user_agent_list as $user_agent ) {
83 $directives[ $user_agent->get_user_agent() ] = $user_agent->get_allow_paths();
84 }
85
86 return $directives;
87 }
88 }
89