PluginProbe ʕ •ᴥ•ʔ
Rank Math SEO – AI SEO Tools to Dominate SEO Rankings / 1.0.239
Rank Math SEO – AI SEO Tools to Dominate SEO Rankings v1.0.239
1.0.271 1.0.271.1 1.0.270 1.0.269 trunk 1.0.216 1.0.217 1.0.218 1.0.219 1.0.220 1.0.221 1.0.222 1.0.223 1.0.224 1.0.225 1.0.226 1.0.227 1.0.227.1 1.0.228 1.0.229 1.0.230 1.0.231 1.0.232 1.0.233 1.0.234 1.0.234.1 1.0.235 1.0.236 1.0.237 1.0.238 1.0.239 1.0.240 1.0.241 1.0.242 1.0.243 1.0.244 1.0.245 1.0.246 1.0.247 1.0.248 1.0.249 1.0.250 1.0.251 1.0.251.1 1.0.252 1.0.252.1 1.0.253 1.0.254 1.0.255 1.0.256 1.0.257 1.0.258 1.0.259 1.0.259.1 1.0.260 1.0.261 1.0.262 1.0.263 1.0.264 1.0.264.1 1.0.265 1.0.266 1.0.266.1 1.0.267 1.0.268
seo-by-rank-math / includes / module / class-module.php
seo-by-rank-math / includes / module Last commit date
class-base.php 2 years ago class-manager.php 1 year ago class-module.php 1 year ago
class-module.php
246 lines
1 <?php
2 /**
3 * The Module
4 *
5 * @since 1.0.32
6 * @package RankMath
7 * @subpackage RankMath\Module
8 * @author Rank Math <support@rankmath.com>
9 */
10
11 namespace RankMath\Module;
12
13 use RankMath\Helper;
14
15 defined( 'ABSPATH' ) || exit;
16
17 /**
18 * Module class.
19 */
20 class Module {
21
22 /**
23 * Module id.
24 *
25 * @var string
26 */
27 private $id = '';
28
29 /**
30 * Module arguments.
31 *
32 * @var string
33 */
34 private $args = '';
35
36 /**
37 * The Constructor.
38 *
39 * @param string $id Module unique id.
40 * @param array $args Module configuration.
41 */
42 public function __construct( $id, $args ) {
43 $this->id = $id;
44 $this->args = $args;
45 }
46
47 /**
48 * Getter.
49 *
50 * @param string $key Key to get data for.
51 * @param mixed $default_value Defaul value if not found.
52 *
53 * @return mixed
54 */
55 public function get( $key, $default_value = '' ) {
56 return isset( $this->args[ $key ] ) ? $this->args[ $key ] : $default_value;
57 }
58
59 /**
60 * Has.
61 *
62 * @param string $key Key to check data.
63 *
64 * @return bool
65 */
66 public function has( $key ) {
67 return isset( $this->args[ $key ] );
68 }
69
70 /**
71 * Get module id.
72 *
73 * @return string
74 */
75 public function get_id() {
76 return $this->id;
77 }
78
79 /**
80 * Get module icon.
81 *
82 * @return string
83 */
84 public function get_icon() {
85 return isset( $this->args['icon'] ) ? $this->args['icon'] : 'dashicons-category';
86 }
87
88 /**
89 * Echo the setting link.
90 */
91 public function the_link() {
92 if ( empty( $this->args['settings'] ) ) {
93 return;
94 }
95 ?>
96 <a href="<?php echo esc_url( $this->args['settings'] ); ?>" class="module-settings button button-secondary"><?php esc_html_e( 'Settings', 'rank-math' ); ?></a>
97 <?php
98 }
99
100 /**
101 * Is module disabled.
102 *
103 * @return bool
104 */
105 public function is_disabled() {
106 return isset( $this->args['disabled'] ) && $this->args['disabled'];
107 }
108
109 /**
110 * Does module has BETA version?
111 *
112 * @return bool
113 */
114 public function is_betabadge() {
115 return isset( $this->args['betabadge'] ) && $this->args['betabadge'];
116 }
117
118 /**
119 * Does module has PRO version?
120 *
121 * @return bool
122 */
123 public function is_probadge() {
124 return isset( $this->args['probadge'] ) && $this->args['probadge'];
125 }
126
127 /**
128 * Is module upgradeable?
129 *
130 * @return bool
131 */
132 public function is_upgradeable() {
133 return isset( $this->args['upgradeable'] ) && $this->args['upgradeable'];
134 }
135
136 /**
137 * Is PRO module.
138 *
139 * @return bool
140 */
141 public function is_pro_module() {
142 return isset( $this->args['probadge'] ) && $this->args['probadge'] && ! defined( 'RANK_MATH_PRO_FILE' );
143 }
144
145 /**
146 * Get the module dependencies.
147 *
148 * @return array
149 */
150 public function get_dependencies() {
151 return isset( $this->args['dep_modules'] ) ? $this->args['dep_modules'] : [];
152 }
153
154 /**
155 * Is module disabled.
156 *
157 * @return bool
158 */
159 public function is_hidden() {
160 if ( Helper::is_advanced_mode() ) {
161 return false;
162 }
163
164 return in_array( $this->get_id(), [ '404-monitor', 'acf', 'bbpress', 'buddypress', 'redirections', 'role-manager', 'image-seo' ], true );
165 }
166
167 /**
168 * Is module admin only.
169 *
170 * @return bool
171 */
172 public function is_admin() {
173 return $this->only( 'admin' );
174 }
175
176 /**
177 * Is module internal.
178 *
179 * @return bool
180 */
181 public function is_internal() {
182 return $this->only( 'internal' );
183 }
184
185 /**
186 * Is module skip.
187 *
188 * @return bool
189 */
190 public function is_skip() {
191 return $this->only( 'skip' );
192 }
193
194 /**
195 * Is module active.
196 *
197 * @return bool
198 */
199 public function is_active() {
200 if ( $this->is_disabled() ) {
201 return false;
202 }
203
204 $active_modules = get_option( 'rank_math_modules', [] );
205 return is_array( $active_modules ) && in_array( $this->get_id(), $active_modules, true );
206 }
207
208 /**
209 * Can display module on form.
210 *
211 * @return bool
212 */
213 public function can_display() {
214 return ! $this->is_internal();
215 }
216
217 /**
218 * Check if we can load the module.
219 *
220 * @return bool
221 */
222 public function can_load_module() {
223 // If its an internal module should be loaded all the time.
224 if ( $this->is_internal() ) {
225 return true;
226 }
227
228 if ( ! $this->is_active() || $this->is_skip() ) {
229 return false;
230 }
231
232 return true;
233 }
234
235 /**
236 * Check module only for.
237 *
238 * @param string $check Check against.
239 *
240 * @return bool
241 */
242 private function only( $check ) {
243 return isset( $this->args['only'] ) && $check === $this->args['only'];
244 }
245 }
246