PluginProbe
User Access Manager / 2.2.2
User Access Manager v2.2.2
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 +402 -327 2.3.152.2.2 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;
@@ -42,9 +53,8 @@
42 53 use function get_pages;
43 54 use function get_post;
44 55 use function get_post_type_object;
45 56 use function get_post_types;
46 -use function get_queried_object_id;
47 57 use function get_sites;
48 58 use function get_taxonomies;
49 59 use function get_taxonomy;
50 60 use function get_term;
@@ -64,9 +74,8 @@
64 74 use function is_user_logged_in;
65 75 use function plugin_basename;
66 76 use function plugins_url;
67 77 use function register_widget;
68 -use function remove_action;
69 78 use function remove_filter;
70 79 use function site_url;
71 80 use function switch_to_blog;
72 81 use function update_option;
@@ -88,15 +97,19 @@
88 97 use function wp_registration_url;
89 98 use function wp_upload_dir;
90 99 use function wp_verify_nonce;
91 100
101 +/**
102 + * Class Wordpress
103 + *
104 + * @package UserAccessManager\Wrapper
105 + */
92 106 class Wordpress
93 107 {
94 - public const REST_READING_METHODS = ['GET', 'HEAD'];
95 -
96 - private bool $restRequestDispatched = false;
97 - private bool $editingRestRequestDetected = false;
98 -
108 + /**
109 + * Returns the database.
110 + * @return wpdb
111 + */
99 112 public function getDatabase(): wpdb
100 113 {
101 114 global $wpdb;
102 115 return $wpdb;
@@ -101,8 +114,12 @@
101 114 global $wpdb;
102 115 return $wpdb;
103 116 }
104 117
118 + /**
119 + * Returns true if web server is nginx.
120 + * @return bool
121 + */
105 122 public function isNginx(): bool
106 123 {
107 124 global $is_nginx;
108 125 return $is_nginx;
@@ -108,26 +125,12 @@
108 125 return $is_nginx;
109 126 }
110 127
111 128 /**
112 - * @see wp_using_ext_object_cache
129 + * @param string $postType
130 + * @return bool
131 + * @see \is_post_type_hierarchical()
113 132 */
114 - public function isUsingExtObjectCache(): bool
115 - {
116 - return function_exists('wp_using_ext_object_cache') && wp_using_ext_object_cache() === true;
117 - }
118 -
119 - /**
120 - * @see apache_get_modules
121 - */
122 - public function isApacheModuleLoaded(string $module): bool
123 - {
124 - return function_exists('apache_get_modules') && in_array($module, apache_get_modules(), true);
125 - }
126 -
127 - /**
128 - * @see is_post_type_hierarchical
129 - */
130 133 public function isPostTypeHierarchical(string $postType): bool
131 134 {
132 135 return is_post_type_hierarchical($postType);
133 136 }
@@ -132,9 +135,11 @@
132 135 return is_post_type_hierarchical($postType);
133 136 }
134 137
135 138 /**
136 - * @see is_taxonomy_hierarchical
139 + * @param string $taxonomy
140 + * @return bool
141 + * @see \is_taxonomy_hierarchical()
137 142 */
138 143 public function isTaxonomyHierarchical(string $taxonomy): bool
139 144 {
140 145 return is_taxonomy_hierarchical($taxonomy);
@@ -140,81 +145,99 @@
140 145 return is_taxonomy_hierarchical($taxonomy);
141 146 }
142 147
143 148 /**
144 - * @see get_userdata
149 + * @param int|string $id
150 + * @return false|WP_User
151 + * @see \get_userdata()
145 152 */
146 - public function getUserData(int|string|null $id): WP_User|bool
153 + public function getUserData($id)
147 154 {
148 155 return get_userdata($id);
149 156 }
150 157
151 158 /**
152 - * @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()
153 164 */
154 - public function getPostTypes(
155 - array|string|int $arguments = [],
156 - string $output = 'names',
157 - string $operator = 'and'
158 - ): array {
165 + public function getPostTypes($arguments = [], $output = 'names', $operator = 'and'): array
166 + {
159 167 return get_post_types($arguments, $output, $operator);
160 168 }
161 169
162 170 /**
163 - * @return string[]|WP_Taxonomy[]
164 - * @see get_taxonomies
171 + * @param array $arguments
172 + * @param string $output
173 + * @param string $operator
174 + * @return array
175 + * @see \get_taxonomies()
165 176 */
166 - public function getTaxonomies(array $arguments = [], string $output = 'names', string $operator = 'and'): array
177 + public function getTaxonomies(array $arguments = [], $output = 'names', $operator = 'and'): array
167 178 {
168 179 return get_taxonomies($arguments, $output, $operator);
169 180 }
170 181
171 182 /**
172 - * @see get_taxonomy
183 + * @param string $taxonomy
184 + * @return false|WP_Taxonomy
185 + * @see \get_taxonomy()
173 186 */
174 - public function getTaxonomy(string $taxonomy): WP_Taxonomy|bool
187 + public function getTaxonomy(string $taxonomy)
175 188 {
176 189 return get_taxonomy($taxonomy);
177 190 }
178 191
179 192 /**
180 - * @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()
181 198 */
182 - public function getPost(
183 - int|string|null $id,
184 - string $output = OBJECT,
185 - string $filter = 'raw'
186 - ): WP_Post|array|bool|null {
199 + public function getPost($id, $output = OBJECT, $filter = 'raw')
200 + {
187 201 return get_post($id, $output, $filter);
188 202 }
189 203
190 204 /**
191 - * @see get_post_type_object
205 + * @param string $postType
206 + * @return null|WP_Post_Type
207 + * @see \get_post_type_object()
192 208 */
193 - public function getPostTypeObject(int|string $postType): ?WP_Post_Type
209 + public function getPostTypeObject(string $postType): ?WP_Post_Type
194 210 {
195 211 return get_post_type_object($postType);
196 212 }
197 213
198 214 /**
199 - * @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()
200 221 */
201 - public function getTerm(
202 - int|string $id,
203 - string $taxonomy = '',
204 - string $output = OBJECT,
205 - string $filter = 'raw'
206 - ): WP_Term|WP_Error|array|bool|null {
222 + public function getTerm($id, string $taxonomy = '', string $output = OBJECT, string $filter = 'raw')
223 + {
207 224 return get_term($id, $taxonomy, $output, $filter);
208 225 }
209 226
210 227
211 228 /**
212 - * @see dbDelta
229 + * @param array|string $queries
230 + * @param bool $execute
231 + * @return array
232 + * @see \dbDelta()
213 233 */
214 - public function dbDelta(array|string $queries = '', bool $execute = true): array
234 + public function dbDelta($queries = '', $execute = true): array
215 235 {
216 236 if (function_exists('\dbDelta') === false) {
237 + /**
238 + * @noinspection PhpIncludeInspection
239 + */
217 240 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
218 241 }
219 242
220 243 return dbDelta($queries, $execute);
@@ -220,11 +243,13 @@
220 243 return dbDelta($queries, $execute);
221 244 }
222 245
223 246 /**
224 - * @see switch_to_blog
247 + * @param integer $blogId
248 + * @return int|true
249 + * @see \switch_to_blog()
225 250 */
226 - public function switchToBlog(int|string|null $blogId): bool
251 + public function switchToBlog(int $blogId)
227 252 {
228 253 if (function_exists('\switch_to_blog') === true) {
229 254 return switch_to_blog($blogId);
230 255 }
@@ -232,8 +257,9 @@
232 257 return true;
233 258 }
234 259
235 260 /**
261 + * @return bool
236 262 * @see \restore_current_blog()
237 263 */
238 264 public function restoreCurrentBlog(): bool
239 265 {
@@ -244,9 +270,10 @@
244 270 return true;
245 271 }
246 272
247 273 /**
248 - * @see is_multisite
274 + * @return bool
275 + * @see \is_multisite()
249 276 */
250 277 public function isMultiSite(): bool
251 278 {
252 279 return is_multisite();
@@ -252,85 +279,83 @@
252 279 return is_multisite();
253 280 }
254 281
255 282 /**
256 - * @see do_action
283 + * @param string $tag
284 + * @param mixed $arguments
285 + * @see \do_action()
257 286 */
258 - public function doAction(string $tag, mixed $arguments = ''): void
287 + public function doAction(string $tag, $arguments = '')
259 288 {
260 289 do_action($tag, $arguments);
261 290 }
262 291
263 292 /**
264 - * @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()
265 299 */
266 - public function addAction(
267 - string $tag,
268 - callable $functionToAdd,
269 - int $priority = 10,
270 - int $acceptedArguments = 1
271 - ): bool {
300 + public function addAction(string $tag, callable $functionToAdd, $priority = 10, $acceptedArguments = 1)
301 + {
272 302 return add_action($tag, $functionToAdd, $priority, $acceptedArguments);
273 303 }
274 304
275 305 /**
276 - * @see remove_action
306 + * @param string $tag
307 + * @param bool|callable $functionToCheck
308 + * @return bool|false|int
309 + * @see \has_filter()
277 310 */
278 - public function removeAction(string $hookName, callable $callback, int $priority = 10): bool
311 + public function hasFilter(string $tag, $functionToCheck = false)
279 312 {
280 - return remove_action($hookName, $callback, $priority);
313 + return has_filter($tag, $functionToCheck);
281 314 }
282 315
283 316 /**
284 - * @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()
285 323 */
286 - public function hasFilter(string $tag, callable|bool $functionToCheck = false): bool|int
324 + public function addFilter(string $tag, callable $functionToAdd, $priority = 10, $acceptedArguments = 1)
287 325 {
288 - return has_filter($tag, $functionToCheck);
289 - }
290 -
291 - /**
292 - * @see add_filter
293 - */
294 - public function addFilter(
295 - string $tag,
296 - callable $functionToAdd,
297 - int $priority = 10,
298 - int $acceptedArguments = 1
299 - ): bool {
300 326 return add_filter($tag, $functionToAdd, $priority, $acceptedArguments);
301 327 }
302 328
303 329 /**
304 - * @see WP_Error
330 + * @param string $tag
331 + * @param callable $functionToRemove
332 + * @param int $priority
333 + * @return bool
334 + * @see \remove_filter()
305 335 */
306 - public function getWpError(string|int $code = '', string $message = '', mixed $data = ''): WP_Error
336 + public function removeFilter(string $tag, callable $functionToRemove, $priority = 10): bool
307 337 {
308 - return new WP_Error($code, $message, $data);
338 + return remove_filter($tag, $functionToRemove, $priority);
309 339 }
310 340
311 341 /**
312 - * @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()
313 348 */
314 - public function removeFilter(string $tag, callable $functionToRemove, int $priority = 10): bool
349 + public function addOption(string $option, $value = '', $deprecated = '', $autoload = 'yes'): bool
315 350 {
316 - return remove_filter($tag, $functionToRemove, $priority);
317 - }
318 -
319 - /**
320 - * @see add_option
321 - */
322 - public function addOption(
323 - string $option,
324 - mixed $value = '',
325 - string $deprecated = '',
326 - bool|string $autoload = 'yes'
327 - ): bool {
328 351 return add_option($option, $value, $deprecated, $autoload);
329 352 }
330 353
331 354 /**
332 - * @see delete_option
355 + * @param string $option
356 + * @return bool
357 + * @see \delete_option()
333 358 */
334 359 public function deleteOption(string $option): bool
335 360 {
336 361 return delete_option($option);
@@ -336,57 +361,43 @@
336 361 return delete_option($option);
337 362 }
338 363
339 364 /**
340 - * @see update_option
365 + * @param string $option
366 + * @param mixed $value
367 + * @param string|bool $autoload
368 + * @return bool
369 + * @see \update_option()
341 370 */
342 - public function updateOption(string $option, mixed $value = '', bool|string $autoload = 'yes'): bool
371 + public function updateOption(string $option, $value = '', $autoload = 'yes'): bool
343 372 {
344 373 return update_option($option, $value, $autoload);
345 374 }
346 375
347 376 /**
348 - * @see get_option
377 + * @param string $option
378 + * @param mixed $default
379 + * @return mixed
380 + * @see \get_option()
349 381 */
350 - public function getOption(string $option, mixed $default = false)
382 + public function getOption(string $option, $default = false)
351 383 {
352 384 return get_option($option, $default);
353 385 }
354 386
355 387 /**
356 - * @see wp_cache_set
388 + * @param int|bool $userId
389 + * @return bool
390 + * @see \is_super_admin()
357 391 */
358 - public function wpCacheSet(string $key, mixed $data, string $group = '', int $expire = 0): bool
392 + public function isSuperAdmin($userId = false): bool
359 393 {
360 - return wp_cache_set($key, $data, $group, $expire);
361 - }
362 -
363 - /**
364 - * @see wp_cache_get
365 - */
366 - public function wpCacheGet(string $key, string $group = ''): mixed
367 - {
368 - return wp_cache_get($key, $group);
369 - }
370 -
371 - /**
372 - * @see wp_cache_delete
373 - */
374 - public function wpCacheDelete(string $key, string $group = ''): bool
375 - {
376 - return wp_cache_delete($key, $group);
377 - }
378 -
379 - /**
380 - * @see is_super_admin
381 - */
382 - public function isSuperAdmin(bool|int|string|null $userId = false): bool
383 - {
384 394 return is_super_admin($userId);
385 395 }
386 396
387 397 /**
388 - * @see wp_get_current_user
398 + * @return WP_User
399 + * @see \wp_get_current_user()
389 400 */
390 401 public function getCurrentUser(): WP_User
391 402 {
392 403 if (function_exists('\wp_get_current_user') === false) {
@@ -396,50 +407,55 @@
396 407 return wp_get_current_user();
397 408 }
398 409
399 410 /**
400 - * @see get_allowed_mime_types
411 + * @param int|WP_User $user
412 + * @return array
413 + * @see \get_allowed_mime_types()
401 414 */
402 - public function getAllowedMimeTypes(WP_User|int|string|null $user = null): array
415 + public function getAllowedMimeTypes($user = null): array
403 416 {
404 417 return get_allowed_mime_types($user);
405 418 }
406 419
407 420 /**
408 - * @see wp_upload_dir
421 + * @param string $time
422 + * @param bool $createDir
423 + * @param bool $refreshCache
424 + * @return array
425 + * @see \wp_upload_dir()
409 426 */
410 - public function getUploadDir(?string $time = null, bool $createDir = true, bool $refreshCache = false): array
427 + public function getUploadDir($time = null, $createDir = true, $refreshCache = false): array
411 428 {
412 429 return wp_upload_dir($time, $createDir, $refreshCache);
413 430 }
414 431
415 432 /**
416 - * @see home_url
433 + * @param string $path
434 + * @param null|string $scheme
435 + * @return string
436 + * @see \home_url()
417 437 */
418 - public function getHomeUrl(string $path = '', ?string $scheme = null): string
438 + public function getHomeUrl($path = '', $scheme = null): string
419 439 {
420 440 return home_url($path, $scheme);
421 441 }
422 442
423 443 /**
424 - * @see site_url
444 + * @param string $path
445 + * @param null|string $scheme
446 + * @return string
447 + * @see \site_url();
425 448 */
426 - public function getSiteUrl(string $path = '', ?string $scheme = null): string
449 + public function getSiteUrl($path = '', $scheme = null): string
427 450 {
428 451 return site_url($path, $scheme);
429 452 }
430 453
431 454 /**
432 - * @see add_query_arg
455 + * @return string
456 + * @see \get_home_path()
433 457 */
434 - public function addQueryArg(array $arguments, string $url): string
435 - {
436 - return add_query_arg($arguments, $url);
437 - }
438 -
439 - /**
440 - * @see get_home_path
441 - */
442 458 public function getHomePath(): string
443 459 {
444 460 if (function_exists('\get_home_path') === false) {
445 461 require_once(ABSPATH . 'wp-admin/includes/file.php');
@@ -448,34 +464,41 @@
448 464 return get_home_path();
449 465 }
450 466
451 467 /**
452 - * @see wp_parse_id_list
468 + * @param array|string $list
469 + * @return array
470 + * @see \wp_parse_id_list()
453 471 */
454 - public function parseIdList(array|string|int $list): array
472 + public function parseIdList($list): array
455 473 {
456 474 return wp_parse_id_list($list);
457 475 }
458 476
459 477 /**
460 - * @see wp_die
478 + * @param string $message
479 + * @param string $title
480 + * @param array $arguments
481 + * @see \wp_die()
461 482 */
462 - #[NoReturn]
463 - public function wpDie(string $message = '', string $title = '', array $arguments = []): void
483 + public function wpDie($message = '', $title = '', array $arguments = [])
464 484 {
465 485 wp_die($message, $title, $arguments);
466 486 }
467 487
468 488 /**
469 - * @see is_feed
489 + * @param string|array $feeds
490 + * @return bool
491 + * @see \is_feed()
470 492 */
471 - public function isFeed(array|string|int $feeds = ''): bool
493 + public function isFeed($feeds = ''): bool
472 494 {
473 495 return is_feed($feeds);
474 496 }
475 497
476 498 /**
477 - * @see is_user_logged_in
499 + * @return bool
500 + * @see \is_user_logged_in()
478 501 */
479 502 public function isUserLoggedIn(): bool
480 503 {
481 504 return is_user_logged_in();
@@ -481,42 +504,45 @@
481 504 return is_user_logged_in();
482 505 }
483 506
484 507 /**
485 - * @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()
486 513 */
487 - public function getPageByPath(
488 - string $pagePath,
489 - string $output = OBJECT,
490 - string $postType = 'page'
491 - ): array|WP_Post|null {
514 + public function getPageByPath(string $pagePath, $output = OBJECT, $postType = 'page')
515 + {
492 516 return get_page_by_path($pagePath, $output, $postType);
493 517 }
494 518
495 519 /**
496 - * @see wp_redirect
520 + * @param string $location
521 + * @param int $status
522 + * @return bool
523 + * @see \wp_redirect()
497 524 */
498 - public function wpRedirect(string $location, int $status = 302): bool
525 + public function wpRedirect(string $location, $status = 302): bool
499 526 {
500 527 return wp_redirect($location, $status);
501 528 }
502 529
503 530 /**
504 - * @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.
505 535 */
506 - public function getReferer(): string|false
536 + public function getPageLink($post = false, $leaveName = false, $sample = false): string
507 537 {
508 - return wp_get_referer();
509 - }
510 -
511 - public function getPageLink(
512 - bool|int|string|WP_Post $post = false,
513 - bool $leaveName = false,
514 - bool $sample = false
515 - ): string {
516 538 return get_page_link($post, $leaveName, $sample);
517 539 }
518 540
541 + /**
542 + * Returns the wp_query object.
543 + * @return WP_Query
544 + */
519 545 public function getWpQuery(): WP_Query
520 546 {
521 547 global $wp_query;
522 548 return $wp_query;
@@ -521,86 +547,64 @@
521 547 global $wp_query;
522 548 return $wp_query;
523 549 }
524 550
525 - public function isRestRequest(): bool
526 - {
527 - return defined('REST_REQUEST') === true && REST_REQUEST === true;
528 - }
529 -
530 - public function setRestRequestContext(bool $isEditingRequest): void
531 - {
532 - $this->restRequestDispatched = true;
533 - //Nested requests, like the ones for embedded objects, must not lower the context again.
534 - $this->editingRestRequestDetected = $this->editingRestRequestDetected || $isEditingRequest;
535 - }
536 -
537 - private function isReadingRestMethod(string $method): bool
538 - {
539 - return in_array(strtoupper($method), self::REST_READING_METHODS, true);
540 - }
541 -
542 - private function isEditingRestRequest(): bool
543 - {
544 - if ($this->isRestRequest() === false) {
545 - return false;
546 - }
547 -
548 - if ($this->restRequestDispatched === true) {
549 - return $this->editingRestRequestDetected;
550 - }
551 -
552 - //Undispatched requests only expose the raw data, so an editing request is assumed.
553 - return $this->isReadingRestMethod((string) ($_SERVER['REQUEST_METHOD'] ?? 'GET')) === false
554 - || ($_REQUEST['context'] ?? '') === 'edit';
555 - }
556 -
557 551 /**
558 - * @see is_admin
552 + * @return bool
553 + * @see \is_admin()
559 554 */
560 555 public function isAdmin(): bool
561 556 {
562 - //Ajax request are always identified as an administrative interface page
563 - if (wp_doing_ajax() === true || $this->isRestRequest() === true) {
557 + //Ajax request are always identified as administrative interface page
558 + if (wp_doing_ajax() === true) {
564 559 //So let's check if we are calling the ajax data for the frontend or backend
565 560 //If the referer is an admin url we are requesting the data for the backend
566 561 $adminUrl = get_admin_url();
567 - return str_starts_with((string)($_SERVER['HTTP_REFERER'] ?? ''), $adminUrl)
568 - || $this->isEditingRestRequest() === true;
562 + return (substr($_SERVER['HTTP_REFERER'], 0, strlen($adminUrl)) === $adminUrl);
569 563 }
570 564
571 - //No ajax request just uses the normal function
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,33 +840,42 @@
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 current_user_can
875 + * @param string $capability
876 + * @return bool
877 + * @see \current_user_can()
811 878 */
812 879 public function currentUserCan(string $capability): bool
813 880 {
814 881 return current_user_can($capability);
@@ -814,9 +881,11 @@
814 881 return current_user_can($capability);
815 882 }
816 883
817 884 /**
818 - * @see get_users
885 + * @param array $arguments
886 + * @return array
887 + * @see \get_users()
819 888 */
820 889 public function getUsers(array $arguments = []): array
821 890 {
822 891 return get_users($arguments);
@@ -830,9 +899,12 @@
830 899 global $wp_filter;
831 900 return $wp_filter;
832 901 }
833 902
834 - public function setFilters(array $filters): void
903 + /**
904 + * @param array $filters
905 + */
906 + public function setFilters(array $filters)
835 907 {
836 908 global $wp_filter;
837 909 $wp_filter = $filters;
838 910 }
@@ -837,15 +909,23 @@
837 909 $wp_filter = $filters;
838 910 }
839 911
840 912 /**
841 - * @see current_time
913 + * @param string $type
914 + * @param int $gmt
915 + * @return int|string
916 + * @see \current_time()
842 917 */
843 - public function currentTime(string $type, int $gmt = 0): int|string
918 + public function currentTime(string $type, $gmt = 0)
844 919 {
845 920 return current_time($type, $gmt);
846 921 }
847 922
923 + /**
924 + * Formats the date like wordpress does it.
925 + * @param string $date
926 + * @return string
927 + */
848 928 public function formatDate(string $date): string
849 929 {
850 930 $dateFormat = __('M j, Y @ H:i');
851 931 return date_i18n($dateFormat, strtotime($date));
@@ -851,33 +931,40 @@
851 931 return date_i18n($dateFormat, strtotime($date));
852 932 }
853 933
854 934 /**
855 - * @see register_widget
935 + * @param mixed $widgetClass
936 + * @see \register_widget()
856 937 */
857 - public function registerWidget(mixed $widgetClass): void
938 + public function registerWidget($widgetClass)
858 939 {
859 940 register_widget($widgetClass);
860 941 }
861 942
862 943 /**
863 - * @see wp_login_url
944 + * @param string $redirect
945 + * @param bool $forceReauth
946 + * @return string
947 + * @see \wp_login_url()
864 948 */
865 - public function wpLoginUrl(string $redirect = '', bool $forceReauth = false): string
949 + public function wpLoginUrl($redirect = '', $forceReauth = false): string
866 950 {
867 951 return wp_login_url($redirect, $forceReauth);
868 952 }
869 953
870 954 /**
871 - * @see wp_logout_url
955 + * @param string $redirect
956 + * @return string
957 + * @see \wp_logout_url()
872 958 */
873 - public function wpLogoutUrl(string $redirect = ''): string
959 + public function wpLogoutUrl($redirect = ''): string
874 960 {
875 961 return wp_logout_url($redirect);
876 962 }
877 963
878 964 /**
879 - * @see wp_registration_url
965 + * @return string
966 + * @see \wp_registration_url()
880 967 */
881 968 public function wpRegistrationUrl(): string
882 969 {
883 970 return wp_registration_url();
@@ -883,33 +970,42 @@
883 970 return wp_registration_url();
884 971 }
885 972
886 973 /**
887 - * @see wp_lostpassword_url
974 + * @param string $redirect
975 + * @return string
976 + * @see \wp_lostpassword_url()
888 977 */
889 - public function wpLostPasswordUrl(string $redirect = ''): string
978 + public function wpLostPasswordUrl($redirect = ''): string
890 979 {
891 980 return wp_lostpassword_url($redirect);
892 981 }
893 982
894 983 /**
895 - * @see add_shortcode
984 + * @param string $tag
985 + * @param callable $function
986 + * @see \add_shortcode()
896 987 */
897 - public function addShortCode(string $tag, callable $function): void
988 + public function addShortCode(string $tag, callable $function)
898 989 {
899 990 add_shortcode($tag, $function);
900 991 }
901 992
902 993 /**
903 - * @see do_shortcode
994 + * @param string $content
995 + * @param bool $ignoreHtml
996 + * @return string
997 + * @see \do_shortcode()
904 998 */
905 - public function doShortCode(string $content, bool $ignoreHtml = false): string
999 + public function doShortCode(string $content, $ignoreHtml = false): string
906 1000 {
907 1001 return do_shortcode($content, $ignoreHtml);
908 1002 }
909 1003
910 1004 /**
911 - * @see attachment_url_to_postid
1005 + * @param string $url
1006 + * @return int
1007 + * @see \attachment_url_to_postid()
912 1008 */
913 1009 public function attachmentUrlToPostId(string $url): int
914 1010 {
915 1011 return attachment_url_to_postid($url);
@@ -915,9 +1011,10 @@
915 1011 return attachment_url_to_postid($url);
916 1012 }
917 1013
918 1014 /**
919 - * @see got_mod_rewrite
1015 + * @return bool
1016 + * @see \got_mod_rewrite()
920 1017 */
921 1018 public function gotModRewrite(): bool
922 1019 {
923 1020 if (function_exists('\got_mod_rewirte') === false) {
@@ -924,28 +1021,6 @@
924 1021 require_once(ABSPATH . 'wp-admin/includes/misc.php');
925 1022 }
926 1023
927 1024 return got_mod_rewrite();
928 - }
929 -
930 - /**
931 - * @see is_user_member_of_blog()
932 - */
933 - public function isUserMemberOfBlog(): bool
934 - {
935 - return is_user_member_of_blog();
936 - }
937 -
938 - /**
939 - * @see get_queried_object_id
940 - */
941 - public function getQueriedObjectId(): int
942 - {
943 - return get_queried_object_id();
944 - }
945 -
946 - public function getCurrentPost(): array|WP_Post|null
947 - {
948 - global $post;
949 - return $post;
950 1025 }
951 1026 }