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