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