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