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