| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace UserAccessManager\Wrapper; |
| 6 |
|
| 7 |
use JetBrains\PhpStorm\NoReturn; |
| 8 |
use WP_Error; |
| 9 |
use WP_Hook; |
| 10 |
use WP_Post; |
| 11 |
use WP_Post_Type; |
| 12 |
use WP_Query; |
| 13 |
use WP_Roles; |
| 14 |
use WP_Taxonomy; |
| 15 |
use WP_Term; |
| 16 |
use WP_User; |
| 17 |
use wpdb; |
| 18 |
use function add_action; |
| 19 |
use function add_filter; |
| 20 |
use function add_menu_page; |
| 21 |
use function add_meta_box; |
| 22 |
use function add_option; |
| 23 |
use function add_shortcode; |
| 24 |
use function add_submenu_page; |
| 25 |
use function attachment_url_to_postid; |
| 26 |
use function current_time; |
| 27 |
use function current_user_can; |
| 28 |
use function date_i18n; |
| 29 |
use function dbDelta; |
| 30 |
use function delete_option; |
| 31 |
use function do_action; |
| 32 |
use function do_shortcode; |
| 33 |
use function esc_html; |
| 34 |
use function function_exists; |
| 35 |
use function get_allowed_mime_types; |
| 36 |
use function get_bloginfo; |
| 37 |
use function get_home_path; |
| 38 |
use function get_option; |
| 39 |
use function get_page_by_path; |
| 40 |
use function get_page_link; |
| 41 |
use function get_pages; |
| 42 |
use function get_post; |
| 43 |
use function get_post_type_object; |
| 44 |
use function get_post_types; |
| 45 |
use function get_queried_object_id; |
| 46 |
use function get_sites; |
| 47 |
use function get_taxonomies; |
| 48 |
use function get_taxonomy; |
| 49 |
use function get_term; |
| 50 |
use function get_userdata; |
| 51 |
use function get_users; |
| 52 |
use function got_mod_rewrite; |
| 53 |
use function has_filter; |
| 54 |
use function home_url; |
| 55 |
use function is_admin; |
| 56 |
use function is_feed; |
| 57 |
use function is_multisite; |
| 58 |
use function is_page; |
| 59 |
use function is_post_type_hierarchical; |
| 60 |
use function is_single; |
| 61 |
use function is_super_admin; |
| 62 |
use function is_taxonomy_hierarchical; |
| 63 |
use function is_user_logged_in; |
| 64 |
use function plugin_basename; |
| 65 |
use function plugins_url; |
| 66 |
use function register_widget; |
| 67 |
use function remove_action; |
| 68 |
use function remove_filter; |
| 69 |
use function site_url; |
| 70 |
use function switch_to_blog; |
| 71 |
use function update_option; |
| 72 |
use function wp_attachment_is_image; |
| 73 |
use function wp_create_nonce; |
| 74 |
use function wp_die; |
| 75 |
use function wp_doing_ajax; |
| 76 |
use function wp_enqueue_script; |
| 77 |
use function wp_enqueue_style; |
| 78 |
use function wp_get_current_user; |
| 79 |
use function wp_login_url; |
| 80 |
use function wp_logout_url; |
| 81 |
use function wp_lostpassword_url; |
| 82 |
use function wp_nonce_field; |
| 83 |
use function wp_parse_id_list; |
| 84 |
use function wp_redirect; |
| 85 |
use function wp_register_script; |
| 86 |
use function wp_register_style; |
| 87 |
use function wp_registration_url; |
| 88 |
use function wp_upload_dir; |
| 89 |
use function wp_verify_nonce; |
| 90 |
|
| 91 |
class Wordpress |
| 92 |
{ |
| 93 |
public function getDatabase(): wpdb |
| 94 |
{ |
| 95 |
global $wpdb; |
| 96 |
return $wpdb; |
| 97 |
} |
| 98 |
|
| 99 |
public function isNginx(): bool |
| 100 |
{ |
| 101 |
global $is_nginx; |
| 102 |
return $is_nginx; |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* @see is_post_type_hierarchical |
| 107 |
*/ |
| 108 |
public function isPostTypeHierarchical(string $postType): bool |
| 109 |
{ |
| 110 |
return is_post_type_hierarchical($postType); |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* @see is_taxonomy_hierarchical |
| 115 |
*/ |
| 116 |
public function isTaxonomyHierarchical(string $taxonomy): bool |
| 117 |
{ |
| 118 |
return is_taxonomy_hierarchical($taxonomy); |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* @see get_userdata |
| 123 |
*/ |
| 124 |
public function getUserData(int|string $id): WP_User|bool |
| 125 |
{ |
| 126 |
return get_userdata($id); |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* @see get_post_types |
| 131 |
*/ |
| 132 |
public function getPostTypes( |
| 133 |
array|string $arguments = [], |
| 134 |
string $output = 'names', |
| 135 |
string $operator = 'and' |
| 136 |
): array { |
| 137 |
return get_post_types($arguments, $output, $operator); |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* @return string[]|WP_Taxonomy[] |
| 142 |
* @see get_taxonomies |
| 143 |
*/ |
| 144 |
public function getTaxonomies(array $arguments = [], string $output = 'names', string $operator = 'and'): array |
| 145 |
{ |
| 146 |
return get_taxonomies($arguments, $output, $operator); |
| 147 |
} |
| 148 |
|
| 149 |
/** |
| 150 |
* @see get_taxonomy |
| 151 |
*/ |
| 152 |
public function getTaxonomy(string $taxonomy): WP_Taxonomy|bool |
| 153 |
{ |
| 154 |
return get_taxonomy($taxonomy); |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* @see get_post |
| 159 |
*/ |
| 160 |
public function getPost(int|string $id, string $output = OBJECT, string $filter = 'raw'): array|WP_Post|null |
| 161 |
{ |
| 162 |
return get_post($id, $output, $filter); |
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* @see get_post_type_object |
| 167 |
*/ |
| 168 |
public function getPostTypeObject(int|string $postType): ?WP_Post_Type |
| 169 |
{ |
| 170 |
return get_post_type_object($postType); |
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* @see get_term |
| 175 |
*/ |
| 176 |
public function getTerm( |
| 177 |
int|string $id, |
| 178 |
string $taxonomy = '', |
| 179 |
string $output = OBJECT, |
| 180 |
string $filter = 'raw' |
| 181 |
): WP_Term|WP_Error|array|null { |
| 182 |
return get_term($id, $taxonomy, $output, $filter); |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
/** |
| 187 |
* @see dbDelta |
| 188 |
*/ |
| 189 |
public function dbDelta(array|string $queries = '', bool $execute = true): array |
| 190 |
{ |
| 191 |
if (function_exists('\dbDelta') === false) { |
| 192 |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 193 |
} |
| 194 |
|
| 195 |
return dbDelta($queries, $execute); |
| 196 |
} |
| 197 |
|
| 198 |
/** |
| 199 |
* @see switch_to_blog |
| 200 |
*/ |
| 201 |
public function switchToBlog(int $blogId): bool |
| 202 |
{ |
| 203 |
if (function_exists('\switch_to_blog') === true) { |
| 204 |
return switch_to_blog($blogId); |
| 205 |
} |
| 206 |
|
| 207 |
return true; |
| 208 |
} |
| 209 |
|
| 210 |
/** |
| 211 |
* @see \restore_current_blog() |
| 212 |
*/ |
| 213 |
public function restoreCurrentBlog(): bool |
| 214 |
{ |
| 215 |
if (function_exists('\restore_current_blog') === true) { |
| 216 |
return restore_current_blog(); |
| 217 |
} |
| 218 |
|
| 219 |
return true; |
| 220 |
} |
| 221 |
|
| 222 |
/** |
| 223 |
* @see is_multisite |
| 224 |
*/ |
| 225 |
public function isMultiSite(): bool |
| 226 |
{ |
| 227 |
return is_multisite(); |
| 228 |
} |
| 229 |
|
| 230 |
/** |
| 231 |
* @see do_action |
| 232 |
*/ |
| 233 |
public function doAction(string $tag, mixed $arguments = ''): void |
| 234 |
{ |
| 235 |
do_action($tag, $arguments); |
| 236 |
} |
| 237 |
|
| 238 |
/** |
| 239 |
* @see add_action |
| 240 |
*/ |
| 241 |
public function addAction( |
| 242 |
string $tag, |
| 243 |
callable $functionToAdd, |
| 244 |
int $priority = 10, |
| 245 |
int $acceptedArguments = 1 |
| 246 |
): bool { |
| 247 |
return add_action($tag, $functionToAdd, $priority, $acceptedArguments); |
| 248 |
} |
| 249 |
|
| 250 |
/** |
| 251 |
* @see remove_action |
| 252 |
*/ |
| 253 |
public function removeAction(string $hookName, callable $callback, int $priority = 10): bool |
| 254 |
{ |
| 255 |
return remove_action($hookName, $callback, $priority); |
| 256 |
} |
| 257 |
|
| 258 |
/** |
| 259 |
* @see has_filter |
| 260 |
*/ |
| 261 |
public function hasFilter(string $tag, callable|bool $functionToCheck = false): bool|int |
| 262 |
{ |
| 263 |
return has_filter($tag, $functionToCheck); |
| 264 |
} |
| 265 |
|
| 266 |
/** |
| 267 |
* @see add_filter |
| 268 |
*/ |
| 269 |
public function addFilter( |
| 270 |
string $tag, |
| 271 |
callable $functionToAdd, |
| 272 |
int $priority = 10, |
| 273 |
int $acceptedArguments = 1 |
| 274 |
): bool { |
| 275 |
return add_filter($tag, $functionToAdd, $priority, $acceptedArguments); |
| 276 |
} |
| 277 |
|
| 278 |
/** |
| 279 |
* @see remove_filter |
| 280 |
*/ |
| 281 |
public function removeFilter(string $tag, callable $functionToRemove, int $priority = 10): bool |
| 282 |
{ |
| 283 |
return remove_filter($tag, $functionToRemove, $priority); |
| 284 |
} |
| 285 |
|
| 286 |
/** |
| 287 |
* @see add_option |
| 288 |
*/ |
| 289 |
public function addOption( |
| 290 |
string $option, |
| 291 |
mixed $value = '', |
| 292 |
string $deprecated = '', |
| 293 |
bool|string $autoload = 'yes' |
| 294 |
): bool { |
| 295 |
return add_option($option, $value, $deprecated, $autoload); |
| 296 |
} |
| 297 |
|
| 298 |
/** |
| 299 |
* @see delete_option |
| 300 |
*/ |
| 301 |
public function deleteOption(string $option): bool |
| 302 |
{ |
| 303 |
return delete_option($option); |
| 304 |
} |
| 305 |
|
| 306 |
/** |
| 307 |
* @see update_option |
| 308 |
*/ |
| 309 |
public function updateOption(string $option, mixed $value = '', bool|string $autoload = 'yes'): bool |
| 310 |
{ |
| 311 |
return update_option($option, $value, $autoload); |
| 312 |
} |
| 313 |
|
| 314 |
/** |
| 315 |
* @see get_option |
| 316 |
*/ |
| 317 |
public function getOption(string $option, mixed $default = false) |
| 318 |
{ |
| 319 |
return get_option($option, $default); |
| 320 |
} |
| 321 |
|
| 322 |
/** |
| 323 |
* @see is_super_admin |
| 324 |
*/ |
| 325 |
public function isSuperAdmin(bool|int $userId = false): bool |
| 326 |
{ |
| 327 |
return is_super_admin($userId); |
| 328 |
} |
| 329 |
|
| 330 |
/** |
| 331 |
* @see wp_get_current_user |
| 332 |
*/ |
| 333 |
public function getCurrentUser(): WP_User |
| 334 |
{ |
| 335 |
if (function_exists('\wp_get_current_user') === false) { |
| 336 |
require_once(ABSPATH . 'wp-includes/pluggable.php'); |
| 337 |
} |
| 338 |
|
| 339 |
return wp_get_current_user(); |
| 340 |
} |
| 341 |
|
| 342 |
/** |
| 343 |
* @see get_allowed_mime_types |
| 344 |
*/ |
| 345 |
public function getAllowedMimeTypes(WP_User|int $user = null): array |
| 346 |
{ |
| 347 |
return get_allowed_mime_types($user); |
| 348 |
} |
| 349 |
|
| 350 |
/** |
| 351 |
* @see wp_upload_dir |
| 352 |
*/ |
| 353 |
public function getUploadDir(string $time = null, bool $createDir = true, bool $refreshCache = false): array |
| 354 |
{ |
| 355 |
return wp_upload_dir($time, $createDir, $refreshCache); |
| 356 |
} |
| 357 |
|
| 358 |
/** |
| 359 |
* @see home_url |
| 360 |
*/ |
| 361 |
public function getHomeUrl(string $path = '', string $scheme = null): string |
| 362 |
{ |
| 363 |
return home_url($path, $scheme); |
| 364 |
} |
| 365 |
|
| 366 |
/** |
| 367 |
* @see site_url |
| 368 |
*/ |
| 369 |
public function getSiteUrl(string $path = '', string $scheme = null): string |
| 370 |
{ |
| 371 |
return site_url($path, $scheme); |
| 372 |
} |
| 373 |
|
| 374 |
/** |
| 375 |
* @see get_home_path |
| 376 |
*/ |
| 377 |
public function getHomePath(): string |
| 378 |
{ |
| 379 |
if (function_exists('\get_home_path') === false) { |
| 380 |
require_once(ABSPATH . 'wp-admin/includes/file.php'); |
| 381 |
} |
| 382 |
|
| 383 |
return get_home_path(); |
| 384 |
} |
| 385 |
|
| 386 |
/** |
| 387 |
* @see wp_parse_id_list |
| 388 |
*/ |
| 389 |
public function parseIdList(array|string $list): array |
| 390 |
{ |
| 391 |
return wp_parse_id_list($list); |
| 392 |
} |
| 393 |
|
| 394 |
/** |
| 395 |
* @see wp_die |
| 396 |
*/ |
| 397 |
#[NoReturn] |
| 398 |
public function wpDie(string $message = '', string $title = '', array $arguments = []): void |
| 399 |
{ |
| 400 |
wp_die($message, $title, $arguments); |
| 401 |
} |
| 402 |
|
| 403 |
/** |
| 404 |
* @see is_feed |
| 405 |
*/ |
| 406 |
public function isFeed(array|string $feeds = ''): bool |
| 407 |
{ |
| 408 |
return is_feed($feeds); |
| 409 |
} |
| 410 |
|
| 411 |
/** |
| 412 |
* @see is_user_logged_in |
| 413 |
*/ |
| 414 |
public function isUserLoggedIn(): bool |
| 415 |
{ |
| 416 |
return is_user_logged_in(); |
| 417 |
} |
| 418 |
|
| 419 |
/** |
| 420 |
* @see get_page_by_path |
| 421 |
*/ |
| 422 |
public function getPageByPath( |
| 423 |
string $pagePath, |
| 424 |
string $output = OBJECT, |
| 425 |
string $postType = 'page' |
| 426 |
): array|WP_Post|null { |
| 427 |
return get_page_by_path($pagePath, $output, $postType); |
| 428 |
} |
| 429 |
|
| 430 |
/** |
| 431 |
* @see wp_redirect |
| 432 |
*/ |
| 433 |
public function wpRedirect(string $location, int $status = 302): bool |
| 434 |
{ |
| 435 |
return wp_redirect($location, $status); |
| 436 |
} |
| 437 |
|
| 438 |
public function getPageLink( |
| 439 |
bool|int|WP_Post $post = false, |
| 440 |
bool $leaveName = false, |
| 441 |
bool $sample = false |
| 442 |
): string { |
| 443 |
return get_page_link($post, $leaveName, $sample); |
| 444 |
} |
| 445 |
|
| 446 |
public function getWpQuery(): WP_Query |
| 447 |
{ |
| 448 |
global $wp_query; |
| 449 |
return $wp_query; |
| 450 |
} |
| 451 |
|
| 452 |
/** |
| 453 |
* @see is_admin |
| 454 |
*/ |
| 455 |
public function isAdmin(): bool |
| 456 |
{ |
| 457 |
//Ajax request are always identified as an administrative interface page |
| 458 |
if (wp_doing_ajax() === true || defined('REST_REQUEST') && REST_REQUEST) { |
| 459 |
//So let's check if we are calling the ajax data for the frontend or backend |
| 460 |
//If the referer is an admin url we are requesting the data for the backend |
| 461 |
$adminUrl = get_admin_url(); |
| 462 |
return str_starts_with((string)($_SERVER['HTTP_REFERER'] ?? ''), $adminUrl); |
| 463 |
} |
| 464 |
|
| 465 |
//No ajax request just uses the normal function |
| 466 |
return is_admin(); |
| 467 |
} |
| 468 |
|
| 469 |
/** |
| 470 |
* @see wp_create_nonce |
| 471 |
*/ |
| 472 |
public function createNonce(int|string $action): string |
| 473 |
{ |
| 474 |
return wp_create_nonce($action); |
| 475 |
} |
| 476 |
|
| 477 |
/** |
| 478 |
* @see wp_nonce_field |
| 479 |
*/ |
| 480 |
public function getNonceField( |
| 481 |
int|string $action = -1, |
| 482 |
string $name = '_wpnonce', |
| 483 |
bool $referrer = true, |
| 484 |
bool $echo = true |
| 485 |
): string { |
| 486 |
return wp_nonce_field($action, $name, $referrer, $echo); |
| 487 |
} |
| 488 |
|
| 489 |
/** |
| 490 |
* @see wp_verify_nonce |
| 491 |
*/ |
| 492 |
public function verifyNonce(?string $nonce, int|string $action = -1): bool|int |
| 493 |
{ |
| 494 |
return wp_verify_nonce($nonce, $action); |
| 495 |
} |
| 496 |
|
| 497 |
public function getRoles(): WP_Roles |
| 498 |
{ |
| 499 |
global $wp_roles; |
| 500 |
return $wp_roles; |
| 501 |
} |
| 502 |
|
| 503 |
/** |
| 504 |
* @see add_menu_page |
| 505 |
*/ |
| 506 |
public function addMenuPage( |
| 507 |
string $pageTitle, |
| 508 |
string $menuTitle, |
| 509 |
string $capability, |
| 510 |
string $menuSlug, |
| 511 |
mixed $function = '', |
| 512 |
string $iconUrl = '', |
| 513 |
int|float|null $position = null |
| 514 |
): string { |
| 515 |
return add_menu_page($pageTitle, $menuTitle, $capability, $menuSlug, $function, $iconUrl, $position); |
| 516 |
} |
| 517 |
|
| 518 |
/** |
| 519 |
* @see add_submenu_page |
| 520 |
*/ |
| 521 |
public function addSubMenuPage( |
| 522 |
string $parentSlug, |
| 523 |
string $pageTitle, |
| 524 |
string $menuTitle, |
| 525 |
string $capability, |
| 526 |
string $menuSlug, |
| 527 |
callable|string $function = '' |
| 528 |
): bool|string { |
| 529 |
return add_submenu_page($parentSlug, $pageTitle, $menuTitle, $capability, $menuSlug, $function); |
| 530 |
} |
| 531 |
|
| 532 |
/** |
| 533 |
* @see add_meta_box |
| 534 |
*/ |
| 535 |
public function addMetaBox( |
| 536 |
string $id, |
| 537 |
string $title, |
| 538 |
callable $callback, |
| 539 |
$screen = null, |
| 540 |
string $context = 'advanced', |
| 541 |
string $priority = 'default', |
| 542 |
$callbackArguments = null |
| 543 |
): void { |
| 544 |
add_meta_box($id, $title, $callback, $screen, $context, $priority, $callbackArguments); |
| 545 |
} |
| 546 |
|
| 547 |
/** |
| 548 |
* @see get_pages |
| 549 |
*/ |
| 550 |
public function getPages(array|string $arguments): bool|array |
| 551 |
{ |
| 552 |
return get_pages($arguments); |
| 553 |
} |
| 554 |
|
| 555 |
/** |
| 556 |
* @see wp_register_style |
| 557 |
*/ |
| 558 |
public function registerStyle( |
| 559 |
string $handle, |
| 560 |
string $source, |
| 561 |
array $depends = [], |
| 562 |
bool|string|null $version = false, |
| 563 |
string $media = 'all' |
| 564 |
): bool { |
| 565 |
return wp_register_style($handle, $source, $depends, $version, $media); |
| 566 |
} |
| 567 |
|
| 568 |
/** |
| 569 |
* @see wp_register_script |
| 570 |
*/ |
| 571 |
public function registerScript( |
| 572 |
string $handle, |
| 573 |
string $source, |
| 574 |
array $depends = [], |
| 575 |
bool|string|null $version = false, |
| 576 |
bool $inFooter = false |
| 577 |
): bool { |
| 578 |
return wp_register_script($handle, $source, $depends, $version, $inFooter); |
| 579 |
} |
| 580 |
|
| 581 |
/** |
| 582 |
* @see wp_enqueue_style |
| 583 |
*/ |
| 584 |
public function enqueueStyle( |
| 585 |
string $handle, |
| 586 |
string $source = '', |
| 587 |
array $depends = [], |
| 588 |
bool|string|null $version = false, |
| 589 |
string $media = 'all' |
| 590 |
): void { |
| 591 |
wp_enqueue_style($handle, $source, $depends, $version, $media); |
| 592 |
} |
| 593 |
|
| 594 |
/** |
| 595 |
* @see wp_enqueue_script |
| 596 |
*/ |
| 597 |
public function enqueueScript( |
| 598 |
string $handle, |
| 599 |
string $source = '', |
| 600 |
array $depends = [], |
| 601 |
bool|string|null $version = false, |
| 602 |
bool $inFooter = false |
| 603 |
): void { |
| 604 |
wp_enqueue_script($handle, $source, $depends, $version, $inFooter); |
| 605 |
} |
| 606 |
|
| 607 |
public function getMetaBoxes(): array |
| 608 |
{ |
| 609 |
global $wp_meta_boxes; |
| 610 |
return $wp_meta_boxes; |
| 611 |
} |
| 612 |
|
| 613 |
public function setMetaBoxes(array $wpMetaBoxes): void |
| 614 |
{ |
| 615 |
global $wp_meta_boxes; |
| 616 |
$wp_meta_boxes = $wpMetaBoxes; |
| 617 |
} |
| 618 |
|
| 619 |
/** |
| 620 |
* @see get_sites |
| 621 |
*/ |
| 622 |
public function getSites(array $arguments = []): array |
| 623 |
{ |
| 624 |
if (function_exists('\get_sites') === true && class_exists('\WP_Site_Query') === true) { |
| 625 |
return get_sites($arguments); |
| 626 |
} |
| 627 |
|
| 628 |
return []; |
| 629 |
} |
| 630 |
|
| 631 |
/** |
| 632 |
* @see apply_filters() |
| 633 |
*/ |
| 634 |
public function applyFilters(string $tag, mixed $value): mixed |
| 635 |
{ |
| 636 |
return call_user_func_array('\apply_filters', func_get_args()); |
| 637 |
} |
| 638 |
|
| 639 |
/** |
| 640 |
* @see get_bloginfo |
| 641 |
*/ |
| 642 |
public function getBlogInfo(string $show = '', string $filter = 'raw'): string |
| 643 |
{ |
| 644 |
return get_bloginfo($show, $filter); |
| 645 |
} |
| 646 |
|
| 647 |
/** |
| 648 |
* @see esc_html |
| 649 |
*/ |
| 650 |
public function escHtml(string $text): string |
| 651 |
{ |
| 652 |
return esc_html($text); |
| 653 |
} |
| 654 |
|
| 655 |
/** |
| 656 |
* @see is_single |
| 657 |
*/ |
| 658 |
public function isSingle(int|array|string $post = ''): bool |
| 659 |
{ |
| 660 |
return is_single($post); |
| 661 |
} |
| 662 |
|
| 663 |
/** |
| 664 |
* @see is_page |
| 665 |
*/ |
| 666 |
public function isPage(int|array|string $page = ''): bool |
| 667 |
{ |
| 668 |
return is_page($page); |
| 669 |
} |
| 670 |
|
| 671 |
/** |
| 672 |
* @see \WP_PLUGIN_DIR |
| 673 |
*/ |
| 674 |
public function getPluginDir(): string |
| 675 |
{ |
| 676 |
return WP_PLUGIN_DIR; |
| 677 |
} |
| 678 |
|
| 679 |
/** |
| 680 |
* @see plugins_url |
| 681 |
*/ |
| 682 |
public function pluginsUrl(string $path = '', string $plugin = ''): string |
| 683 |
{ |
| 684 |
return plugins_url($path, $plugin); |
| 685 |
} |
| 686 |
|
| 687 |
/** |
| 688 |
* @see plugin_basename |
| 689 |
*/ |
| 690 |
public function pluginBasename(string $file): string |
| 691 |
{ |
| 692 |
return plugin_basename($file); |
| 693 |
} |
| 694 |
|
| 695 |
/** |
| 696 |
* @see wp_attachment_is_image |
| 697 |
*/ |
| 698 |
public function attachmentIsImage(int|WP_Post $post): bool |
| 699 |
{ |
| 700 |
return wp_attachment_is_image($post); |
| 701 |
} |
| 702 |
|
| 703 |
/** |
| 704 |
* @see current_user_can |
| 705 |
*/ |
| 706 |
public function currentUserCan(string $capability): bool |
| 707 |
{ |
| 708 |
return current_user_can($capability); |
| 709 |
} |
| 710 |
|
| 711 |
/** |
| 712 |
* @see get_users |
| 713 |
*/ |
| 714 |
public function getUsers(array $arguments = []): array |
| 715 |
{ |
| 716 |
return get_users($arguments); |
| 717 |
} |
| 718 |
|
| 719 |
/** |
| 720 |
* @return WP_Hook[] |
| 721 |
*/ |
| 722 |
public function getFilters(): array |
| 723 |
{ |
| 724 |
global $wp_filter; |
| 725 |
return $wp_filter; |
| 726 |
} |
| 727 |
|
| 728 |
public function setFilters(array $filters): void |
| 729 |
{ |
| 730 |
global $wp_filter; |
| 731 |
$wp_filter = $filters; |
| 732 |
} |
| 733 |
|
| 734 |
/** |
| 735 |
* @see current_time |
| 736 |
*/ |
| 737 |
public function currentTime(string $type, int $gmt = 0): int|string |
| 738 |
{ |
| 739 |
return current_time($type, $gmt); |
| 740 |
} |
| 741 |
|
| 742 |
public function formatDate(string $date): string |
| 743 |
{ |
| 744 |
$dateFormat = __('M j, Y @ H:i'); |
| 745 |
return date_i18n($dateFormat, strtotime($date)); |
| 746 |
} |
| 747 |
|
| 748 |
/** |
| 749 |
* @see register_widget |
| 750 |
*/ |
| 751 |
public function registerWidget(mixed $widgetClass): void |
| 752 |
{ |
| 753 |
register_widget($widgetClass); |
| 754 |
} |
| 755 |
|
| 756 |
/** |
| 757 |
* @see wp_login_url |
| 758 |
*/ |
| 759 |
public function wpLoginUrl(string $redirect = '', bool $forceReauth = false): string |
| 760 |
{ |
| 761 |
return wp_login_url($redirect, $forceReauth); |
| 762 |
} |
| 763 |
|
| 764 |
/** |
| 765 |
* @see wp_logout_url |
| 766 |
*/ |
| 767 |
public function wpLogoutUrl(string $redirect = ''): string |
| 768 |
{ |
| 769 |
return wp_logout_url($redirect); |
| 770 |
} |
| 771 |
|
| 772 |
/** |
| 773 |
* @see wp_registration_url |
| 774 |
*/ |
| 775 |
public function wpRegistrationUrl(): string |
| 776 |
{ |
| 777 |
return wp_registration_url(); |
| 778 |
} |
| 779 |
|
| 780 |
/** |
| 781 |
* @see wp_lostpassword_url |
| 782 |
*/ |
| 783 |
public function wpLostPasswordUrl(string $redirect = ''): string |
| 784 |
{ |
| 785 |
return wp_lostpassword_url($redirect); |
| 786 |
} |
| 787 |
|
| 788 |
/** |
| 789 |
* @see add_shortcode |
| 790 |
*/ |
| 791 |
public function addShortCode(string $tag, callable $function): void |
| 792 |
{ |
| 793 |
add_shortcode($tag, $function); |
| 794 |
} |
| 795 |
|
| 796 |
/** |
| 797 |
* @see do_shortcode |
| 798 |
*/ |
| 799 |
public function doShortCode(string $content, bool $ignoreHtml = false): string |
| 800 |
{ |
| 801 |
return do_shortcode($content, $ignoreHtml); |
| 802 |
} |
| 803 |
|
| 804 |
/** |
| 805 |
* @see attachment_url_to_postid |
| 806 |
*/ |
| 807 |
public function attachmentUrlToPostId(string $url): int |
| 808 |
{ |
| 809 |
return attachment_url_to_postid($url); |
| 810 |
} |
| 811 |
|
| 812 |
/** |
| 813 |
* @see got_mod_rewrite |
| 814 |
*/ |
| 815 |
public function gotModRewrite(): bool |
| 816 |
{ |
| 817 |
if (function_exists('\got_mod_rewirte') === false) { |
| 818 |
require_once(ABSPATH . 'wp-admin/includes/misc.php'); |
| 819 |
} |
| 820 |
|
| 821 |
return got_mod_rewrite(); |
| 822 |
} |
| 823 |
|
| 824 |
/** |
| 825 |
* @see is_user_member_of_blog() |
| 826 |
*/ |
| 827 |
public function isUserMemberOfBlog(): bool |
| 828 |
{ |
| 829 |
return is_user_member_of_blog(); |
| 830 |
} |
| 831 |
|
| 832 |
/** |
| 833 |
* @see get_queried_object_id |
| 834 |
*/ |
| 835 |
public function getQueriedObjectId(): int |
| 836 |
{ |
| 837 |
return get_queried_object_id(); |
| 838 |
} |
| 839 |
|
| 840 |
public function getCurrentPost(): array|WP_Post|null |
| 841 |
{ |
| 842 |
global $post; |
| 843 |
return $post; |
| 844 |
} |
| 845 |
} |
| 846 |
|