PluginProbe
User Access Manager / 2.0.6
User Access Manager v2.0.6
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
user-access-manager / src / UserAccessManager / Wrapper / Wordpress.php

Wordpress.php in User Access Manager 2.0.6, at src/UserAccessManager/Wrapper/Wordpress.php

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