PluginProbe
User Access Manager / 2.1.11
User Access Manager v2.1.11
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
← All changes | src/Wrapper/Wordpress.php +634 -452 2.3.14 → 2.1.11 View file →
@@ -1,103 +1,44 @@
1 1 <?php
2 -
3 -declare(strict_types=1);
4 -
2 +/**
3 + * Wordpress.php
4 + *
5 + * The Wordpress class file.
6 + *
7 + * PHP versions 5
8 + *
9 + * @author Alexander Schneider <[email protected]>
10 + * @copyright 2008-2017 Alexander Schneider
11 + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 + * @version SVN: $id$
13 + * @link http://wordpress.org/extend/plugins/user-access-manager/
14 + */
5 15 namespace UserAccessManager\Wrapper;
6 16
7 -use JetBrains\PhpStorm\NoReturn;
8 -use WP_Error;
9 -use WP_Hook;
10 -use WP_Post;
11 -use WP_Post_Type;
12 -use WP_Query;
13 -use WP_Roles;
14 -use WP_Taxonomy;
15 -use WP_Term;
16 -use WP_User;
17 -use wpdb;
18 -use function add_action;
19 -use function add_filter;
20 -use function add_menu_page;
21 -use function add_meta_box;
22 -use function add_option;
23 -use function add_shortcode;
24 -use function add_submenu_page;
25 -use function attachment_url_to_postid;
26 -use function current_time;
27 -use function current_user_can;
28 -use function date_i18n;
29 -use function dbDelta;
30 -use function delete_option;
31 -use function do_action;
32 -use function do_shortcode;
33 -use function esc_html;
34 -use function function_exists;
35 -use function get_allowed_mime_types;
36 -use function get_bloginfo;
37 -use function get_home_path;
38 -use function get_option;
39 -use function get_page_by_path;
40 -use function get_page_link;
41 -use function get_pages;
42 -use function get_post;
43 -use function get_post_type_object;
44 -use function get_post_types;
45 -use function get_queried_object_id;
46 -use function get_sites;
47 -use function get_taxonomies;
48 -use function get_taxonomy;
49 -use function get_term;
50 -use function get_userdata;
51 -use function get_users;
52 -use function got_mod_rewrite;
53 -use function has_filter;
54 -use function home_url;
55 -use function is_admin;
56 -use function is_feed;
57 -use function is_multisite;
58 -use function is_page;
59 -use function is_post_type_hierarchical;
60 -use function is_single;
61 -use function is_super_admin;
62 -use function is_taxonomy_hierarchical;
63 -use function is_user_logged_in;
64 -use function plugin_basename;
65 -use function plugins_url;
66 -use function register_widget;
67 -use function remove_action;
68 -use function remove_filter;
69 -use function site_url;
70 -use function switch_to_blog;
71 -use function update_option;
72 -use function wp_attachment_is_image;
73 -use function wp_create_nonce;
74 -use function wp_die;
75 -use function wp_doing_ajax;
76 -use function wp_enqueue_script;
77 -use function wp_enqueue_style;
78 -use function wp_get_current_user;
79 -use function wp_login_url;
80 -use function wp_logout_url;
81 -use function wp_lostpassword_url;
82 -use function wp_nonce_field;
83 -use function wp_parse_id_list;
84 -use function wp_redirect;
85 -use function wp_register_script;
86 -use function wp_register_style;
87 -use function wp_registration_url;
88 -use function wp_upload_dir;
89 -use function wp_verify_nonce;
90 -
17 +/**
18 + * Class Wordpress
19 + *
20 + * @package UserAccessManager\Wrapper
21 + */
91 22 class Wordpress
92 23 {
93 - public function getDatabase(): wpdb
24 + /**
25 + * Returns the database.
26 + *
27 + * @return \wpdb
28 + */
29 + public function getDatabase()
94 30 {
95 31 global $wpdb;
96 32 return $wpdb;
97 33 }
98 34
99 - public function isNginx(): bool
35 + /**
36 + * Returns true if web server is nginx.
37 + *
38 + * @return bool
39 + */
40 + public function isNginx()
100 41 {
101 42 global $is_nginx;
102 43 return $is_nginx;
103 44 }
@@ -102,126 +43,156 @@
102 43 return $is_nginx;
103 44 }
104 45
105 46 /**
106 - * @see wp_using_ext_object_cache
47 + * @see \is_post_type_hierarchical()
48 + *
49 + * @param string $postType
50 + *
51 + * @return bool
107 52 */
108 - public function isUsingExtObjectCache(): bool
53 + public function isPostTypeHierarchical($postType)
109 54 {
110 - return function_exists('wp_using_ext_object_cache') && wp_using_ext_object_cache() === true;
55 + return \is_post_type_hierarchical($postType);
111 56 }
112 57
113 58 /**
114 - * @see apache_get_modules
59 + * @see \is_taxonomy_hierarchical()
60 + *
61 + * @param string $taxonomy
62 + *
63 + * @return bool
115 64 */
116 - public function isApacheModuleLoaded(string $module): bool
65 + public function isTaxonomyHierarchical($taxonomy)
117 66 {
118 - return function_exists('apache_get_modules') && in_array($module, apache_get_modules(), true);
67 + return \is_taxonomy_hierarchical($taxonomy);
119 68 }
120 69
121 70 /**
122 - * @see is_post_type_hierarchical
71 + * @see \get_userdata()
72 + *
73 + * @param string $id
74 + *
75 + * @return false|\WP_User
123 76 */
124 - public function isPostTypeHierarchical(string $postType): bool
77 + public function getUserData($id)
125 78 {
126 - return is_post_type_hierarchical($postType);
79 + return \get_userdata($id);
127 80 }
128 81
129 82 /**
130 - * @see is_taxonomy_hierarchical
83 + * @see \get_post_types()
84 + *
85 + * @param string|array $arguments
86 + * @param string $output
87 + * @param string $operator
88 + *
89 + * @return array
131 90 */
132 - public function isTaxonomyHierarchical(string $taxonomy): bool
91 + public function getPostTypes($arguments = [], $output = 'names', $operator = 'and')
133 92 {
134 - return is_taxonomy_hierarchical($taxonomy);
93 + return \get_post_types($arguments, $output, $operator);
135 94 }
136 95
137 96 /**
138 - * @see get_userdata
97 + * @see \get_taxonomies()
98 + *
99 + * @param array $arguments
100 + * @param string $output
101 + * @param string $operator
102 + *
103 + * @return array
139 104 */
140 - public function getUserData(int|string|null $id): WP_User|bool
105 + public function getTaxonomies(array $arguments = [], $output = 'names', $operator = 'and')
141 106 {
142 - return get_userdata($id);
107 + return \get_taxonomies($arguments, $output, $operator);
143 108 }
144 109
145 110 /**
146 - * @see get_post_types
111 + * @see \get_taxonomy()
112 + *
113 + * @param string $taxonomy
114 + *
115 + * @return false|\WP_Taxonomy
147 116 */
148 - public function getPostTypes(
149 - array|string|int $arguments = [],
150 - string $output = 'names',
151 - string $operator = 'and'
152 - ): array {
153 - return get_post_types($arguments, $output, $operator);
117 + public function getTaxonomy($taxonomy)
118 + {
119 + return \get_taxonomy($taxonomy);
154 120 }
155 121
156 122 /**
157 - * @return string[]|WP_Taxonomy[]
158 - * @see get_taxonomies
123 + * @see \get_post()
124 + *
125 + * @param string $id The post id.
126 + * @param string $output
127 + * @param string $filter
128 + *
129 + * @return \WP_Post|array|null
159 130 */
160 - public function getTaxonomies(array $arguments = [], string $output = 'names', string $operator = 'and'): array
131 + public function getPost($id, $output = OBJECT, $filter = 'raw')
161 132 {
162 - return get_taxonomies($arguments, $output, $operator);
133 + return \get_post($id, $output, $filter);
163 134 }
164 135
165 136 /**
166 - * @see get_taxonomy
137 + * @see \get_post_type_object()
138 + *
139 + * @param string $postType
140 + *
141 + * @return null|\WP_Post_Type
167 142 */
168 - public function getTaxonomy(string $taxonomy): WP_Taxonomy|bool
143 + public function getPostTypeObject($postType)
169 144 {
170 - return get_taxonomy($taxonomy);
145 + return \get_post_type_object($postType);
171 146 }
172 147
173 148 /**
174 - * @see get_post
149 + * @see \get_term()
150 + *
151 + * @param string $id
152 + * @param string $taxonomy
153 + * @param string $output
154 + * @param string $filter
155 + *
156 + * @return array|null|\WP_Error|\WP_Term
175 157 */
176 - public function getPost(
177 - int|string|null $id,
178 - string $output = OBJECT,
179 - string $filter = 'raw'
180 - ): WP_Post|array|bool|null {
181 - return get_post($id, $output, $filter);
182 - }
183 -
184 - /**
185 - * @see get_post_type_object
186 - */
187 - public function getPostTypeObject(int|string $postType): ?WP_Post_Type
158 + public function getTerm($id, $taxonomy = '', $output = OBJECT, $filter = 'raw')
188 159 {
189 - return get_post_type_object($postType);
160 + return \get_term($id, $taxonomy, $output, $filter);
190 161 }
191 162
192 - /**
193 - * @see get_term
194 - */
195 - public function getTerm(
196 - int|string $id,
197 - string $taxonomy = '',
198 - string $output = OBJECT,
199 - string $filter = 'raw'
200 - ): WP_Term|WP_Error|array|bool|null {
201 - return get_term($id, $taxonomy, $output, $filter);
202 - }
203 163
204 -
205 164 /**
206 - * @see dbDelta
165 + * @see \dbDelta()
166 + *
167 + * @param array|string $queries
168 + * @param bool $execute
169 + *
170 + * @return array
207 171 */
208 - public function dbDelta(array|string $queries = '', bool $execute = true): array
172 + public function dbDelta($queries = '', $execute = true)
209 173 {
210 - if (function_exists('\dbDelta') === false) {
211 - require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
174 + if (\function_exists('\dbDelta') === false) {
175 + /**
176 + * @noinspection PhpIncludeInspection
177 + */
178 + require_once(ABSPATH.'wp-admin/includes/upgrade.php');
212 179 }
213 180
214 - return dbDelta($queries, $execute);
181 + return \dbDelta($queries, $execute);
215 182 }
216 183
217 184 /**
218 - * @see switch_to_blog
185 + * @see \switch_to_blog()
186 + *
187 + * @param integer $blogId
188 + *
189 + * @return int|true
219 190 */
220 - public function switchToBlog(int|string|null $blogId): bool
191 + public function switchToBlog($blogId)
221 192 {
222 193 if (function_exists('\switch_to_blog') === true) {
223 - return switch_to_blog($blogId);
194 + return \switch_to_blog($blogId);
224 195 }
225 196
226 197 return true;
227 198 }
@@ -227,10 +198,12 @@
227 198 }
228 199
229 200 /**
230 201 * @see \restore_current_blog()
202 + *
203 + * @return bool
231 204 */
232 - public function restoreCurrentBlog(): bool
205 + public function restoreCurrentBlog()
233 206 {
234 207 if (function_exists('\restore_current_blog') === true) {
235 208 return restore_current_blog();
236 209 }
@@ -238,248 +211,322 @@
238 211 return true;
239 212 }
240 213
241 214 /**
242 - * @see is_multisite
215 + * @see \is_multisite()
216 + *
217 + * @return bool
243 218 */
244 - public function isMultiSite(): bool
219 + public function isMultiSite()
245 220 {
246 - return is_multisite();
221 + return \is_multisite();
247 222 }
248 223
249 224 /**
250 - * @see do_action
225 + * @see \do_action()
226 + *
227 + * @param string $tag
228 + * @param mixed $arguments
251 229 */
252 - public function doAction(string $tag, mixed $arguments = ''): void
230 + public function doAction($tag, $arguments = '')
253 231 {
254 - do_action($tag, $arguments);
232 + \do_action($tag, $arguments);
255 233 }
256 234
257 235 /**
258 - * @see add_action
236 + * @see \add_action()
237 + *
238 + * @param string $tag
239 + * @param callable $functionToAdd
240 + * @param int $priority
241 + * @param int $acceptedArguments
242 + *
243 + * @return true
259 244 */
260 - public function addAction(
261 - string $tag,
262 - callable $functionToAdd,
263 - int $priority = 10,
264 - int $acceptedArguments = 1
265 - ): bool {
266 - return add_action($tag, $functionToAdd, $priority, $acceptedArguments);
245 + public function addAction($tag, $functionToAdd, $priority = 10, $acceptedArguments = 1)
246 + {
247 + return \add_action($tag, $functionToAdd, $priority, $acceptedArguments);
267 248 }
268 249
269 250 /**
270 - * @see remove_action
251 + * @see \has_filter()
252 + *
253 + * @param string $tag
254 + * @param bool|callable $functionToCheck
255 + *
256 + * @return bool|false|int
271 257 */
272 - public function removeAction(string $hookName, callable $callback, int $priority = 10): bool
258 + public function hasFilter($tag, $functionToCheck = false)
273 259 {
274 - return remove_action($hookName, $callback, $priority);
260 + return \has_filter($tag, $functionToCheck);
275 261 }
276 262
277 263 /**
278 - * @see has_filter
264 + * @see \add_filter()
265 + *
266 + * @param string $tag
267 + * @param callable $functionToAdd
268 + * @param int $priority
269 + * @param int $acceptedArguments
270 + *
271 + * @return true
279 272 */
280 - public function hasFilter(string $tag, callable|bool $functionToCheck = false): bool|int
273 + public function addFilter($tag, $functionToAdd, $priority = 10, $acceptedArguments = 1)
281 274 {
282 - return has_filter($tag, $functionToCheck);
275 + return \add_filter($tag, $functionToAdd, $priority, $acceptedArguments);
283 276 }
284 277
285 278 /**
286 - * @see add_filter
279 + * @see \remove_filter()
280 + *
281 + * @param string $tag
282 + * @param callable $functionToRemove
283 + * @param int $priority
284 + *
285 + * @return bool
287 286 */
288 - public function addFilter(
289 - string $tag,
290 - callable $functionToAdd,
291 - int $priority = 10,
292 - int $acceptedArguments = 1
293 - ): bool {
294 - return add_filter($tag, $functionToAdd, $priority, $acceptedArguments);
295 - }
296 -
297 - /**
298 - * @see WP_Error
299 - */
300 - public function getWpError(string|int $code = '', string $message = '', mixed $data = ''): WP_Error
287 + public function removeFilter($tag, $functionToRemove, $priority = 10)
301 288 {
302 - return new WP_Error($code, $message, $data);
289 + return \remove_filter($tag, $functionToRemove, $priority);
303 290 }
304 291
305 292 /**
306 - * @see remove_filter
293 + * @see \add_option()
294 + *
295 + * @param string $option
296 + * @param mixed $value
297 + * @param string $deprecated
298 + * @param string|bool $autoload
299 + *
300 + * @return bool
307 301 */
308 - public function removeFilter(string $tag, callable $functionToRemove, int $priority = 10): bool
302 + public function addOption($option, $value = '', $deprecated = '', $autoload = 'yes')
309 303 {
310 - return remove_filter($tag, $functionToRemove, $priority);
304 + return \add_option($option, $value, $deprecated, $autoload);
311 305 }
312 306
313 307 /**
314 - * @see add_option
308 + * @see \delete_option()
309 + *
310 + * @param string $option
311 + *
312 + * @return bool
315 313 */
316 - public function addOption(
317 - string $option,
318 - mixed $value = '',
319 - string $deprecated = '',
320 - bool|string $autoload = 'yes'
321 - ): bool {
322 - return add_option($option, $value, $deprecated, $autoload);
323 - }
324 -
325 - /**
326 - * @see delete_option
327 - */
328 - public function deleteOption(string $option): bool
314 + public function deleteOption($option)
329 315 {
330 - return delete_option($option);
316 + return \delete_option($option);
331 317 }
332 318
333 319 /**
334 - * @see update_option
320 + * @see \update_option()
321 + *
322 + * @param string $option
323 + * @param mixed $value
324 + * @param string|bool $autoload
325 + *
326 + * @return bool
335 327 */
336 - public function updateOption(string $option, mixed $value = '', bool|string $autoload = 'yes'): bool
328 + public function updateOption($option, $value = '', $autoload = 'yes')
337 329 {
338 - return update_option($option, $value, $autoload);
330 + return \update_option($option, $value, $autoload);
339 331 }
340 332
341 333 /**
342 - * @see get_option
334 + * @see \get_option()
335 + *
336 + * @param string $option
337 + * @param mixed $default
338 + *
339 + * @return mixed
343 340 */
344 - public function getOption(string $option, mixed $default = false)
341 + public function getOption($option, $default = false)
345 342 {
346 - return get_option($option, $default);
343 + return \get_option($option, $default);
347 344 }
348 345
349 346 /**
350 - * @see is_super_admin
347 + * @see \is_super_admin()
348 + *
349 + * @param int|bool $userId
350 + *
351 + * @return bool
351 352 */
352 - public function isSuperAdmin(bool|int|string|null $userId = false): bool
353 + public function isSuperAdmin($userId = false)
353 354 {
354 - return is_super_admin($userId);
355 + return \is_super_admin($userId);
355 356 }
356 357
357 358 /**
358 - * @see wp_get_current_user
359 + * @see \wp_get_current_user()
360 + *
361 + * @return \WP_User
359 362 */
360 - public function getCurrentUser(): WP_User
363 + public function getCurrentUser()
361 364 {
362 365 if (function_exists('\wp_get_current_user') === false) {
363 - require_once(ABSPATH . 'wp-includes/pluggable.php');
366 + require_once(ABSPATH.'wp-includes/pluggable.php');
364 367 }
365 368
366 - return wp_get_current_user();
369 + return \wp_get_current_user();
367 370 }
368 371
369 372 /**
370 - * @see get_allowed_mime_types
373 + * @see \get_allowed_mime_types()
374 + *
375 + * @param int|\WP_User $user
376 + *
377 + * @return array
371 378 */
372 - public function getAllowedMimeTypes(WP_User|int|string|null $user = null): array
379 + public function getAllowedMimeTypes($user = null)
373 380 {
374 - return get_allowed_mime_types($user);
381 + return \get_allowed_mime_types($user);
375 382 }
376 383
377 384 /**
378 - * @see wp_upload_dir
385 + * @see \wp_upload_dir()
386 + *
387 + * @param string $time
388 + * @param bool $createDir
389 + * @param bool $refreshCache
390 + *
391 + * @return array
379 392 */
380 - public function getUploadDir(?string $time = null, bool $createDir = true, bool $refreshCache = false): array
393 + public function getUploadDir($time = null, $createDir = true, $refreshCache = false)
381 394 {
382 - return wp_upload_dir($time, $createDir, $refreshCache);
395 + return \wp_upload_dir($time, $createDir, $refreshCache);
383 396 }
384 397
385 398 /**
386 - * @see home_url
399 + * @see \home_url()
400 + *
401 + * @param string $path
402 + * @param null|string $scheme
403 + *
404 + * @return string
387 405 */
388 - public function getHomeUrl(string $path = '', ?string $scheme = null): string
406 + public function getHomeUrl($path = '', $scheme = null)
389 407 {
390 - return home_url($path, $scheme);
408 + return \home_url($path, $scheme);
391 409 }
392 410
393 411 /**
394 - * @see site_url
412 + * @see \site_url();
413 + *
414 + * @param string $path
415 + * @param null|string $scheme
416 + *
417 + * @return string
395 418 */
396 - public function getSiteUrl(string $path = '', ?string $scheme = null): string
419 + public function getSiteUrl($path = '', $scheme = null)
397 420 {
398 - return site_url($path, $scheme);
421 + return \site_url($path, $scheme);
399 422 }
400 423
401 424 /**
402 - * @see get_home_path
425 + * @see \get_home_path()
426 + *
427 + * @return string
403 428 */
404 - public function getHomePath(): string
429 + public function getHomePath()
405 430 {
406 431 if (function_exists('\get_home_path') === false) {
407 - require_once(ABSPATH . 'wp-admin/includes/file.php');
432 + require_once(ABSPATH.'wp-admin/includes/file.php');
408 433 }
409 434
410 - return get_home_path();
435 + return \get_home_path();
411 436 }
412 437
413 438 /**
414 - * @see wp_parse_id_list
439 + * @see \wp_parse_id_list()
440 + *
441 + * @param array|string $list
442 + *
443 + * @return array
415 444 */
416 - public function parseIdList(array|string|int $list): array
445 + public function parseIdList($list)
417 446 {
418 - return wp_parse_id_list($list);
447 + return \wp_parse_id_list($list);
419 448 }
420 449
421 450 /**
422 - * @see wp_die
451 + * @see \wp_die()
452 + *
453 + * @param string $message
454 + * @param string $title
455 + * @param array $arguments
423 456 */
424 - #[NoReturn]
425 - public function wpDie(string $message = '', string $title = '', array $arguments = []): void
457 + public function wpDie($message = '', $title = '', array $arguments = [])
426 458 {
427 - wp_die($message, $title, $arguments);
459 + \wp_die($message, $title, $arguments);
428 460 }
429 461
430 462 /**
431 - * @see is_feed
463 + * @see \is_feed()
464 + *
465 + * @param string|array $feeds
466 + *
467 + * @return bool
432 468 */
433 - public function isFeed(array|string|int $feeds = ''): bool
469 + public function isFeed($feeds = '')
434 470 {
435 - return is_feed($feeds);
471 + return \is_feed($feeds);
436 472 }
437 473
438 474 /**
439 - * @see is_user_logged_in
475 + * @see \is_user_logged_in()
476 + *
477 + * @return bool
440 478 */
441 - public function isUserLoggedIn(): bool
479 + public function isUserLoggedIn()
442 480 {
443 - return is_user_logged_in();
481 + return \is_user_logged_in();
444 482 }
445 483
446 484 /**
447 - * @see get_page_by_path
485 + * @see \get_page_by_path()
486 + *
487 + * @param string $pagePath
488 + * @param string $output
489 + * @param string $postType
490 + *
491 + * @return array|null|\WP_Post
448 492 */
449 - public function getPageByPath(
450 - string $pagePath,
451 - string $output = OBJECT,
452 - string $postType = 'page'
453 - ): array|WP_Post|null {
454 - return get_page_by_path($pagePath, $output, $postType);
493 + public function getPageByPath($pagePath, $output = OBJECT, $postType = 'page')
494 + {
495 + return \get_page_by_path($pagePath, $output, $postType);
455 496 }
456 497
457 498 /**
458 - * @see wp_redirect
499 + * @see \wp_redirect()
500 + *
501 + * @param string $location
502 + * @param int $status
503 + *
504 + * @return bool
459 505 */
460 - public function wpRedirect(string $location, int $status = 302): bool
506 + public function wpRedirect($location, $status = 302)
461 507 {
462 - return wp_redirect($location, $status);
508 + return \wp_redirect($location, $status);
463 509 }
464 510
465 511 /**
466 - * @see wp_get_referer
512 + * @param bool|int|\WP_Post $post
513 + * @param bool $leaveName
514 + * @param bool $sample
515 + *
516 + * @return string The page permalink.
467 517 */
468 - public function getReferer(): string|false
518 + public function getPageLink($post = false, $leaveName = false, $sample = false)
469 519 {
470 - return wp_get_referer();
520 + return \get_page_link($post, $leaveName, $sample);
471 521 }
472 522
473 - public function getPageLink(
474 - bool|int|string|WP_Post $post = false,
475 - bool $leaveName = false,
476 - bool $sample = false
477 - ): string {
478 - return get_page_link($post, $leaveName, $sample);
479 - }
480 -
481 - public function getWpQuery(): WP_Query
523 + /**
524 + * Returns the wp_query object.
525 + *
526 + * @return \WP_Query
527 + */
528 + public function getWpQuery()
482 529 {
483 530 global $wp_query;
484 531 return $wp_query;
485 532 }
@@ -484,53 +531,72 @@
484 531 return $wp_query;
485 532 }
486 533
487 534 /**
488 - * @see is_admin
535 + * @see \is_admin()
536 + *
537 + * @return bool
489 538 */
490 - public function isAdmin(): bool
539 + public function isAdmin()
491 540 {
492 - //Ajax request are always identified as an administrative interface page
493 - if (wp_doing_ajax() === true || defined('REST_REQUEST') && REST_REQUEST) {
541 + //Ajax request are always identified as administrative interface page
542 + if (\wp_doing_ajax() === true) {
494 543 //So let's check if we are calling the ajax data for the frontend or backend
495 544 //If the referer is an admin url we are requesting the data for the backend
496 545 $adminUrl = get_admin_url();
497 - return str_starts_with((string)($_SERVER['HTTP_REFERER'] ?? ''), $adminUrl);
546 + return (substr($_SERVER['HTTP_REFERER'], 0, strlen($adminUrl)) === $adminUrl);
498 547 }
499 548
500 - //No ajax request just uses the normal function
501 - return is_admin();
549 + //No ajax request just use the normal function
550 + return \is_admin();
502 551 }
503 552
504 553 /**
505 - * @see wp_create_nonce
554 + * @see \wp_create_nonce()
555 + *
556 + * @param int|string $action
557 + *
558 + * @return string
506 559 */
507 - public function createNonce(int|string $action): string
560 + public function createNonce($action)
508 561 {
509 - return wp_create_nonce($action);
562 + return \wp_create_nonce($action);
510 563 }
511 564
512 565 /**
513 - * @see wp_nonce_field
566 + * @see \wp_nonce_field()
567 + *
568 + * @param int|string $action
569 + * @param string $name
570 + * @param bool $referrer
571 + * @param bool $echo
572 + *
573 + * @return string
514 574 */
515 - public function getNonceField(
516 - int|string $action = -1,
517 - string $name = '_wpnonce',
518 - bool $referrer = true,
519 - bool $echo = true
520 - ): string {
521 - return wp_nonce_field($action, $name, $referrer, $echo);
575 + public function getNonceField($action = -1, $name = '_wpnonce', $referrer = true, $echo = true)
576 + {
577 + return \wp_nonce_field($action, $name, $referrer, $echo);
522 578 }
523 579
524 580 /**
525 - * @see wp_verify_nonce
581 + * @see \wp_verify_nonce()
582 + *
583 + * @param string $nonce
584 + * @param string|int $action
585 + *
586 + * @return false|int
526 587 */
527 - public function verifyNonce(?string $nonce, int|string $action = -1): bool|int
588 + public function verifyNonce($nonce, $action = -1)
528 589 {
529 - return wp_verify_nonce($nonce, $action);
590 + return \wp_verify_nonce($nonce, $action);
530 591 }
531 592
532 - public function getRoles(): WP_Roles
593 + /**
594 + * Returns the wordpress roles.
595 + *
596 + * @return \WP_Roles
597 + */
598 + public function getRoles()
533 599 {
534 600 global $wp_roles;
535 601 return $wp_roles;
536 602 }
@@ -535,118 +601,161 @@
535 601 return $wp_roles;
536 602 }
537 603
538 604 /**
539 - * @see add_menu_page
605 + * @see \add_menu_page()
606 + *
607 + * @param string $pageTitle
608 + * @param string $menuTitle
609 + * @param string $capability
610 + * @param string $menuSlug
611 + * @param mixed $function
612 + * @param string $iconUrl
613 + * @param null $position
614 + *
615 + * @return string
540 616 */
541 617 public function addMenuPage(
542 - string $pageTitle,
543 - string $menuTitle,
544 - string $capability,
545 - string $menuSlug,
546 - mixed $function = '',
547 - string $iconUrl = '',
548 - int|float|null $position = null
549 - ): string {
550 - return add_menu_page($pageTitle, $menuTitle, $capability, $menuSlug, $function, $iconUrl, $position);
618 + $pageTitle,
619 + $menuTitle,
620 + $capability,
621 + $menuSlug,
622 + $function = '',
623 + $iconUrl = '',
624 + $position = null
625 + ) {
626 + return \add_menu_page($pageTitle, $menuTitle, $capability, $menuSlug, $function, $iconUrl, $position);
551 627 }
552 628
553 629 /**
554 - * @see add_submenu_page
630 + * @see \add_submenu_page()
631 + *
632 + * @param string $parentSlug
633 + * @param string $pageTitle
634 + * @param string $menuTitle
635 + * @param string $capability
636 + * @param string $menuSlug
637 + * @param string|callable $function
638 + *
639 + * @return false|string
555 640 */
556 - public function addSubMenuPage(
557 - string $parentSlug,
558 - string $pageTitle,
559 - string $menuTitle,
560 - string $capability,
561 - string $menuSlug,
562 - callable|string $function = ''
563 - ): bool|string {
564 - return add_submenu_page($parentSlug, $pageTitle, $menuTitle, $capability, $menuSlug, $function);
641 + public function addSubMenuPage($parentSlug, $pageTitle, $menuTitle, $capability, $menuSlug, $function = '')
642 + {
643 + return \add_submenu_page($parentSlug, $pageTitle, $menuTitle, $capability, $menuSlug, $function);
565 644 }
566 645
567 646 /**
568 - * @see add_meta_box
647 + * @see \add_meta_box()
648 + *
649 + * @param string $id
650 + * @param string $title
651 + * @param callable $callback
652 + * @param string|array|\WP_Screen $screen
653 + * @param string $context
654 + * @param string $priority
655 + * @param array $callbackArguments
569 656 */
570 657 public function addMetaBox(
571 - string $id,
572 - string $title,
573 - callable $callback,
658 + $id,
659 + $title,
660 + $callback,
574 661 $screen = null,
575 - string $context = 'advanced',
576 - string $priority = 'default',
662 + $context = 'advanced',
663 + $priority = 'default',
577 664 $callbackArguments = null
578 - ): void {
579 - add_meta_box($id, $title, $callback, $screen, $context, $priority, $callbackArguments);
665 + ) {
666 + \add_meta_box($id, $title, $callback, $screen, $context, $priority, $callbackArguments);
580 667 }
581 668
582 669 /**
583 - * @see get_pages
670 + * @see \get_pages()
671 + *
672 + * @param array|string $arguments
673 + *
674 + * @return array|false
584 675 */
585 - public function getPages(array|string|int $arguments): bool|array
676 + public function getPages($arguments)
586 677 {
587 - return get_pages($arguments);
678 + return \get_pages($arguments);
588 679 }
589 680
590 681 /**
591 - * @see wp_register_style
682 + * @see \wp_register_style()
683 + *
684 + * @param string $handle
685 + * @param string $source
686 + * @param array $depends
687 + * @param string|bool|null $version
688 + * @param string $media
689 + *
690 + * @return bool
592 691 */
593 - public function registerStyle(
594 - string $handle,
595 - string $source,
596 - array $depends = [],
597 - bool|string|null $version = false,
598 - string $media = 'all'
599 - ): bool {
600 - return wp_register_style($handle, $source, $depends, $version, $media);
692 + public function registerStyle($handle, $source, $depends = [], $version = false, $media = 'all')
693 + {
694 + return \wp_register_style($handle, $source, $depends, $version, $media);
601 695 }
602 696
603 697 /**
604 - * @see wp_register_script
698 + * @see \wp_register_script()
699 + *
700 + * @param string $handle
701 + * @param string $source
702 + * @param array $depends
703 + * @param string|bool|null $version
704 + * @param bool $inFooter
705 + *
706 + * @return bool
605 707 */
606 - public function registerScript(
607 - string $handle,
608 - string $source,
609 - array $depends = [],
610 - bool|string|null $version = false,
611 - bool $inFooter = false
612 - ): bool {
613 - return wp_register_script($handle, $source, $depends, $version, $inFooter);
708 + public function registerScript($handle, $source, $depends = [], $version = false, $inFooter = false)
709 + {
710 + return \wp_register_script($handle, $source, $depends, $version, $inFooter);
614 711 }
615 712
616 713 /**
617 - * @see wp_enqueue_style
714 + * @see \wp_enqueue_style()
715 + *
716 + * @param string $handle
717 + * @param string $source
718 + * @param array $depends
719 + * @param string|bool|null $version
720 + * @param string $media
618 721 */
619 - public function enqueueStyle(
620 - string $handle,
621 - string $source = '',
622 - array $depends = [],
623 - bool|string|null $version = false,
624 - string $media = 'all'
625 - ): void {
626 - wp_enqueue_style($handle, $source, $depends, $version, $media);
722 + public function enqueueStyle($handle, $source = '', $depends = [], $version = false, $media = 'all')
723 + {
724 + \wp_enqueue_style($handle, $source, $depends, $version, $media);
627 725 }
628 726
629 727 /**
630 - * @see wp_enqueue_script
728 + * @see \wp_enqueue_script()
729 + *
730 + * @param string $handle
731 + * @param string $source
732 + * @param array $depends
733 + * @param string|bool|null $version
734 + * @param bool $inFooter
631 735 */
632 - public function enqueueScript(
633 - string $handle,
634 - string $source = '',
635 - array $depends = [],
636 - bool|string|null $version = false,
637 - bool $inFooter = false
638 - ): void {
639 - wp_enqueue_script($handle, $source, $depends, $version, $inFooter);
736 + public function enqueueScript($handle, $source = '', $depends = [], $version = false, $inFooter = false)
737 + {
738 + \wp_enqueue_script($handle, $source, $depends, $version, $inFooter);
640 739 }
641 740
642 - public function getMetaBoxes(): array
741 + /**
742 + * Returns the wordpress meta boxes.
743 + *
744 + * @return array
745 + */
746 + public function getMetaBoxes()
643 747 {
644 748 global $wp_meta_boxes;
645 749 return $wp_meta_boxes;
646 750 }
647 751
648 - public function setMetaBoxes(array $wpMetaBoxes): void
752 + /**
753 + * Sets the wordpress meta boxes.
754 + *
755 + * @param array $wpMetaBoxes
756 + */
757 + public function setMetaBoxes(array $wpMetaBoxes)
649 758 {
650 759 global $wp_meta_boxes;
651 760 $wp_meta_boxes = $wpMetaBoxes;
652 761 }
@@ -651,14 +760,18 @@
651 760 $wp_meta_boxes = $wpMetaBoxes;
652 761 }
653 762
654 763 /**
655 - * @see get_sites
764 + * @see \get_sites()
765 + *
766 + * @param array $arguments
767 + *
768 + * @return array
656 769 */
657 - public function getSites(array $arguments = []): array
770 + public function getSites(array $arguments = [])
658 771 {
659 772 if (function_exists('\get_sites') === true && class_exists('\WP_Site_Query') === true) {
660 - return get_sites($arguments);
773 + return \get_sites($arguments);
661 774 }
662 775
663 776 return [];
664 777 }
@@ -663,105 +776,153 @@
663 776 return [];
664 777 }
665 778
666 779 /**
667 - * @see apply_filters()
780 + * @see \apply_filters()
781 + *
782 + * @param string $tag
783 + * @param mixed $value
784 + *
785 + * @return mixed
668 786 */
669 - public function applyFilters(string $tag, mixed $value): mixed
787 + public function applyFilters($tag, $value)
670 788 {
671 789 return call_user_func_array('\apply_filters', func_get_args());
672 790 }
673 791
674 792 /**
675 - * @see get_bloginfo
793 + * @see \get_bloginfo()
794 + *
795 + * @param string $show
796 + * @param string $filter
797 + *
798 + * @return string
676 799 */
677 - public function getBlogInfo(string $show = '', string $filter = 'raw'): string
800 + public function getBlogInfo($show = '', $filter = 'raw')
678 801 {
679 - return get_bloginfo($show, $filter);
802 + return \get_bloginfo($show, $filter);
680 803 }
681 804
682 805 /**
683 - * @see esc_html
806 + * @see \esc_html()
807 + *
808 + * @param string $text
809 + *
810 + * @return string
684 811 */
685 - public function escHtml(string $text): string
812 + public function escHtml($text)
686 813 {
687 - return esc_html($text);
814 + return \esc_html($text);
688 815 }
689 816
690 817 /**
691 - * @see is_single
818 + * @see \is_single()
819 + *
820 + * @param int|string|array $post
821 + *
822 + * @return bool
692 823 */
693 - public function isSingle(array|string|int $post = ''): bool
824 + public function isSingle($post = '')
694 825 {
695 - return is_single($post);
826 + return \is_single($post);
696 827 }
697 828
698 829 /**
699 - * @see is_page
830 + * @see \is_page()
831 + *
832 + * @param int|string|array $page
833 + *
834 + * @return bool
700 835 */
701 - public function isPage(array|string|int $page = ''): bool
836 + public function isPage($page = '')
702 837 {
703 - return is_page($page);
838 + return \is_page($page);
704 839 }
705 840
706 841 /**
707 842 * @see \WP_PLUGIN_DIR
843 + *
844 + * @return string
708 845 */
709 - public function getPluginDir(): string
846 + public function getPluginDir()
710 847 {
711 848 return WP_PLUGIN_DIR;
712 849 }
713 850
714 851 /**
715 - * @see plugins_url
852 + * @see \plugins_url()
853 + *
854 + * @param string $path
855 + * @param string $plugin
856 + *
857 + * @return string
716 858 */
717 - public function pluginsUrl(string $path = '', string $plugin = ''): string
859 + public function pluginsUrl($path = '', $plugin = '')
718 860 {
719 - return plugins_url($path, $plugin);
861 + return \plugins_url($path, $plugin);
720 862 }
721 863
722 864 /**
723 - * @see plugin_basename
865 + * @see \plugin_basename()
866 + *
867 + * @param $file
868 + *
869 + * @return string
724 870 */
725 - public function pluginBasename(string $file): string
871 + public function pluginBasename($file)
726 872 {
727 - return plugin_basename($file);
873 + return \plugin_basename($file);
728 874 }
729 875
730 876 /**
731 - * @see wp_attachment_is_image
877 + * @see \wp_attachment_is_image()
878 + *
879 + * @param int|\WP_Post $post
880 + *
881 + * @return bool
732 882 */
733 - public function attachmentIsImage(int|WP_Post $post): bool
883 + public function attachmentIsImage($post)
734 884 {
735 - return wp_attachment_is_image($post);
885 + return \wp_attachment_is_image($post);
736 886 }
737 887
738 888 /**
739 - * @see current_user_can
889 + * @see \current_user_can()
890 + *
891 + * @param string $capability
892 + *
893 + * @return bool
740 894 */
741 - public function currentUserCan(string $capability): bool
895 + public function currentUserCan($capability)
742 896 {
743 - return current_user_can($capability);
897 + return \current_user_can($capability);
744 898 }
745 899
746 900 /**
747 - * @see get_users
901 + * @see \get_users()
902 + *
903 + * @param array $arguments
904 + *
905 + * @return array
748 906 */
749 - public function getUsers(array $arguments = []): array
907 + public function getUsers(array $arguments = [])
750 908 {
751 - return get_users($arguments);
909 + return \get_users($arguments);
752 910 }
753 911
754 912 /**
755 - * @return WP_Hook[]
913 + * @return \WP_Hook[]
756 914 */
757 - public function getFilters(): array
915 + public function getFilters()
758 916 {
759 917 global $wp_filter;
760 918 return $wp_filter;
761 919 }
762 920
763 - public function setFilters(array $filters): void
921 + /**
922 + * @param array $filters
923 + */
924 + public function setFilters(array $filters)
764 925 {
765 926 global $wp_filter;
766 927 $wp_filter = $filters;
767 928 }
@@ -766,115 +927,136 @@
766 927 $wp_filter = $filters;
767 928 }
768 929
769 930 /**
770 - * @see current_time
931 + * @see \current_time()
932 + *
933 + * @param string $type
934 + * @param int $gmt
935 + *
936 + * @return int|string
771 937 */
772 - public function currentTime(string $type, int $gmt = 0): int|string
938 + public function currentTime($type, $gmt = 0)
773 939 {
774 - return current_time($type, $gmt);
940 + return \current_time($type, $gmt);
775 941 }
776 942
777 - public function formatDate(string $date): string
943 + /**
944 + * Formats the date like wordpress does it.
945 + *
946 + * @param string $date
947 + *
948 + * @return string
949 + */
950 + public function formatDate($date)
778 951 {
779 952 $dateFormat = __('M j, Y @ H:i');
780 - return date_i18n($dateFormat, strtotime($date));
953 + return \date_i18n($dateFormat, strtotime($date));
781 954 }
782 955
783 956 /**
784 - * @see register_widget
957 + * @see \register_widget()
958 + *
959 + * @param mixed $widgetClass
785 960 */
786 - public function registerWidget(mixed $widgetClass): void
961 + public function registerWidget($widgetClass)
787 962 {
788 - register_widget($widgetClass);
963 + \register_widget($widgetClass);
789 964 }
790 965
791 966 /**
792 - * @see wp_login_url
967 + * @see \wp_login_url()
968 + *
969 + * @param string $redirect
970 + * @param bool $forceReauth
971 + *
972 + * @return string
793 973 */
794 - public function wpLoginUrl(string $redirect = '', bool $forceReauth = false): string
974 + public function wpLoginUrl($redirect = '', $forceReauth = false)
795 975 {
796 - return wp_login_url($redirect, $forceReauth);
976 + return \wp_login_url($redirect, $forceReauth);
797 977 }
798 978
799 979 /**
800 - * @see wp_logout_url
980 + * @see \wp_logout_url()
981 + *
982 + * @param string $redirect
983 + *
984 + * @return string
801 985 */
802 - public function wpLogoutUrl(string $redirect = ''): string
986 + public function wpLogoutUrl($redirect = '')
803 987 {
804 - return wp_logout_url($redirect);
988 + return \wp_logout_url($redirect);
805 989 }
806 990
807 991 /**
808 - * @see wp_registration_url
992 + * @see \wp_registration_url()
993 + *
994 + * @return string
809 995 */
810 - public function wpRegistrationUrl(): string
996 + public function wpRegistrationUrl()
811 997 {
812 - return wp_registration_url();
998 + return \wp_registration_url();
813 999 }
814 1000
815 1001 /**
816 - * @see wp_lostpassword_url
1002 + * @see \wp_lostpassword_url()
1003 + *
1004 + * @param string $redirect
1005 + *
1006 + * @return string
817 1007 */
818 - public function wpLostPasswordUrl(string $redirect = ''): string
1008 + public function wpLostPasswordUrl($redirect = '')
819 1009 {
820 - return wp_lostpassword_url($redirect);
1010 + return \wp_lostpassword_url($redirect);
821 1011 }
822 1012
823 1013 /**
824 - * @see add_shortcode
1014 + * @see \add_shortcode()
1015 + *
1016 + * @param string $tag
1017 + * @param callable $function
825 1018 */
826 - public function addShortCode(string $tag, callable $function): void
1019 + public function addShortCode($tag, $function)
827 1020 {
828 - add_shortcode($tag, $function);
1021 + \add_shortcode($tag, $function);
829 1022 }
830 1023
831 1024 /**
832 - * @see do_shortcode
1025 + * @see \do_shortcode()
1026 + *
1027 + * @param string $content
1028 + * @param bool $ignoreHtml
1029 + *
1030 + * @return string
833 1031 */
834 - public function doShortCode(string $content, bool $ignoreHtml = false): string
1032 + public function doShortCode($content, $ignoreHtml = false)
835 1033 {
836 - return do_shortcode($content, $ignoreHtml);
1034 + return \do_shortcode($content, $ignoreHtml);
837 1035 }
838 1036
839 1037 /**
840 - * @see attachment_url_to_postid
1038 + * @see \attachment_url_to_postid()
1039 + *
1040 + * @param string $url
1041 + *
1042 + * @return int
841 1043 */
842 - public function attachmentUrlToPostId(string $url): int
1044 + public function attachmentUrlToPostId($url)
843 1045 {
844 - return attachment_url_to_postid($url);
1046 + return \attachment_url_to_postid($url);
845 1047 }
846 1048
847 1049 /**
848 - * @see got_mod_rewrite
1050 + * @see \got_mod_rewrite()
1051 + *
1052 + * @return bool
849 1053 */
850 - public function gotModRewrite(): bool
1054 + public function gotModRewrite()
851 1055 {
852 1056 if (function_exists('\got_mod_rewirte') === false) {
853 - require_once(ABSPATH . 'wp-admin/includes/misc.php');
1057 + require_once(ABSPATH.'wp-admin/includes/misc.php');
854 1058 }
855 1059
856 - return got_mod_rewrite();
857 - }
858 -
859 - /**
860 - * @see is_user_member_of_blog()
861 - */
862 - public function isUserMemberOfBlog(): bool
863 - {
864 - return is_user_member_of_blog();
865 - }
866 -
867 - /**
868 - * @see get_queried_object_id
869 - */
870 - public function getQueriedObjectId(): int
871 - {
872 - return get_queried_object_id();
873 - }
874 -
875 - public function getCurrentPost(): array|WP_Post|null
876 - {
877 - global $post;
878 - return $post;
1060 + return \got_mod_rewrite();
879 1061 }
880 1062 }