PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.5.1
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.5.1
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 / admin / views / class-yoast-feature-toggle.php

class-yoast-feature-toggle.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.5.1, at admin/views/class-yoast-feature-toggle.php

172 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPSEO plugin file.
4 *
5 * @package WPSEO\Admin
6 */
7
8 /**
9 * Class representing a feature toggle.
10 */
11 class Yoast_Feature_Toggle {
12
13 /**
14 * Feature toggle identifier.
15 *
16 * @var string
17 */
18 protected $name = '';
19
20 /**
21 * Name of the setting the feature toggle is associated with.
22 *
23 * @var string
24 */
25 protected $setting = '';
26
27 /**
28 * Whether the feature is premium or not.
29 *
30 * @var bool
31 */
32 protected $premium = false;
33
34 /**
35 * Feature toggle label.
36 *
37 * @var string
38 */
39 protected $label = '';
40
41 /**
42 * URL to learn more about the feature.
43 *
44 * @var string
45 */
46 protected $read_more_url = '';
47
48 /**
49 * URL to learn more about the premium feature.
50 *
51 * @var string
52 */
53 protected $premium_url = '';
54
55 /**
56 * Label for the learn more link.
57 *
58 * @var string
59 */
60 protected $read_more_label = '';
61
62 /**
63 * Additional help content for the feature.
64 *
65 * @var string
66 */
67 protected $extra = '';
68
69 /**
70 * Additional content to be rendered after the toggle.
71 *
72 * @var string
73 */
74 protected $after = '';
75
76 /**
77 * Value to specify the feature toggle order.
78 *
79 * @var string
80 */
81 protected $order = 100;
82
83 /**
84 * Disable the integration toggle.
85 *
86 * @var bool
87 */
88 protected $disabled = false;
89
90 /**
91 * Whether the feature is new or not.
92 *
93 * @var bool
94 */
95 protected $new = false;
96
97 /**
98 * Constructor.
99 *
100 * Sets the feature toggle arguments.
101 *
102 * @param array $args {
103 * Feature toggle arguments.
104 *
105 * @type string $name Required. Feature toggle identifier.
106 * @type string $setting Required. Name of the setting the feature toggle is associated with.
107 * @type string $disabled Whether the feature is premium or not.
108 * @type string $label Feature toggle label.
109 * @type string $read_more_url URL to learn more about the feature. Default empty string.
110 * @type string $read_more_label Label for the learn more link. Default empty string.
111 * @type string $extra Additional help content for the feature. Default empty string.
112 * @type int $order Value to specify the feature toggle order. A lower value indicates
113 * a higher priority. Default 100.
114 * @type bool $disabled Disable the integration toggle. Default false.
115 * @type string $new Whether the feature is new or not.
116 * }
117 *
118 * @throws InvalidArgumentException Thrown when a required argument is missing.
119 */
120 public function __construct( array $args ) {
121 $required_keys = [ 'name', 'setting' ];
122
123 foreach ( $required_keys as $key ) {
124 if ( empty( $args[ $key ] ) ) {
125 /* translators: %s: argument name */
126 throw new InvalidArgumentException( sprintf( __( '%s is a required feature toggle argument.', 'wordpress-seo' ), $key ) );
127 }
128 }
129
130 foreach ( $args as $key => $value ) {
131 if ( property_exists( $this, $key ) ) {
132 $this->$key = $value;
133 }
134 }
135 }
136
137 /**
138 * Magic isset-er.
139 *
140 * @param string $key Key to check whether a value for it is set.
141 *
142 * @return bool True if set, false otherwise.
143 */
144 public function __isset( $key ) {
145 return isset( $this->$key );
146 }
147
148 /**
149 * Magic getter.
150 *
151 * @param string $key Key to get the value for.
152 *
153 * @return mixed Value for the key, or null if not set.
154 */
155 public function __get( $key ) {
156 if ( isset( $this->$key ) ) {
157 return $this->$key;
158 }
159
160 return null;
161 }
162
163 /**
164 * Checks whether the feature for this toggle is enabled.
165 *
166 * @return bool True if the feature is enabled, false otherwise.
167 */
168 public function is_enabled() {
169 return (bool) WPSEO_Options::get( $this->setting );
170 }
171 }
172