PluginProbe
User Access Manager / 2.1.6
User Access Manager v2.1.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 / Wrapper / Wordpress.php

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

1,013 lines 21.1 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 /**
176 * @noinspection PhpIncludeInspection
177 */
178 require_once(ABSPATH.'wp-admin/includes/upgrade.php');
179 }
180
181 return \dbDelta($queries, $execute);
182 }
183
184 /**
185 * @see \switch_to_blog()
186 *
187 * @param integer $blogId
188 *
189 * @return int|true
190 */
191 public function switchToBlog($blogId)
192 {
193 if (function_exists('\switch_to_blog') === true) {
194 return \switch_to_blog($blogId);
195 }
196
197 return true;
198 }
199
200 /**
201 * @see \is_multisite()
202 *
203 * @return bool
204 */
205 public function isMultiSite()
206 {
207 return \is_multisite();
208 }
209
210 /**
211 * @see \do_action()
212 *
213 * @param string $tag
214 * @param mixed $arguments
215 */
216 public function doAction($tag, $arguments = '')
217 {
218 \do_action($tag, $arguments);
219 }
220
221 /**
222 * @see \add_action()
223 *
224 * @param string $tag
225 * @param callable $functionToAdd
226 * @param int $priority
227 * @param int $acceptedArguments
228 *
229 * @return true
230 */
231 public function addAction($tag, $functionToAdd, $priority = 10, $acceptedArguments = 1)
232 {
233 return \add_action($tag, $functionToAdd, $priority, $acceptedArguments);
234 }
235
236 /**
237 * @see \has_filter()
238 *
239 * @param string $tag
240 * @param bool|callable $functionToCheck
241 *
242 * @return bool|false|int
243 */
244 public function hasFilter($tag, $functionToCheck = false)
245 {
246 return \has_filter($tag, $functionToCheck);
247 }
248
249 /**
250 * @see \add_filter()
251 *
252 * @param string $tag
253 * @param callable $functionToAdd
254 * @param int $priority
255 * @param int $acceptedArguments
256 *
257 * @return true
258 */
259 public function addFilter($tag, $functionToAdd, $priority = 10, $acceptedArguments = 1)
260 {
261 return \add_filter($tag, $functionToAdd, $priority, $acceptedArguments);
262 }
263
264 /**
265 * @see \remove_filter()
266 *
267 * @param string $tag
268 * @param callable $functionToRemove
269 * @param int $priority
270 *
271 * @return bool
272 */
273 public function removeFilter($tag, $functionToRemove, $priority = 10)
274 {
275 return \remove_filter($tag, $functionToRemove, $priority);
276 }
277
278 /**
279 * @see \add_option()
280 *
281 * @param string $option
282 * @param mixed $value
283 * @param string $deprecated
284 * @param string|bool $autoload
285 *
286 * @return bool
287 */
288 public function addOption($option, $value = '', $deprecated = '', $autoload = 'yes')
289 {
290 return \add_option($option, $value, $deprecated, $autoload);
291 }
292
293 /**
294 * @see \delete_option()
295 *
296 * @param string $option
297 *
298 * @return bool
299 */
300 public function deleteOption($option)
301 {
302 return \delete_option($option);
303 }
304
305 /**
306 * @see \update_option()
307 *
308 * @param string $option
309 * @param mixed $value
310 * @param string|bool $autoload
311 *
312 * @return bool
313 */
314 public function updateOption($option, $value = '', $autoload = 'yes')
315 {
316 return \update_option($option, $value, $autoload);
317 }
318
319 /**
320 * @see \get_option()
321 *
322 * @param string $option
323 * @param mixed $default
324 *
325 * @return mixed
326 */
327 public function getOption($option, $default = false)
328 {
329 return \get_option($option, $default);
330 }
331
332 /**
333 * @see \is_super_admin()
334 *
335 * @param int|bool $userId
336 *
337 * @return bool
338 */
339 public function isSuperAdmin($userId = false)
340 {
341 return \is_super_admin($userId);
342 }
343
344 /**
345 * @see \wp_get_current_user()
346 *
347 * @return \WP_User
348 */
349 public function getCurrentUser()
350 {
351 if (function_exists('\wp_get_current_user') === false) {
352 require_once(ABSPATH.'wp-includes/pluggable.php');
353 }
354
355 return \wp_get_current_user();
356 }
357
358 /**
359 * @see \get_allowed_mime_types()
360 *
361 * @param int|\WP_User $user
362 *
363 * @return array
364 */
365 public function getAllowedMimeTypes($user = null)
366 {
367 return \get_allowed_mime_types($user);
368 }
369
370 /**
371 * @see \wp_upload_dir()
372 *
373 * @param string $time
374 * @param bool $createDir
375 * @param bool $refreshCache
376 *
377 * @return array
378 */
379 public function getUploadDir($time = null, $createDir = true, $refreshCache = false)
380 {
381 return \wp_upload_dir($time, $createDir, $refreshCache);
382 }
383
384 /**
385 * @see \home_url()
386 *
387 * @param string $path
388 * @param string $scheme
389 *
390 * @return string
391 */
392 public function getHomeUrl($path = '', $scheme = null)
393 {
394 return \home_url($path, $scheme);
395 }
396
397 /**
398 * @see \get_home_path()
399 *
400 * @return string
401 */
402 public function getHomePath()
403 {
404 if (function_exists('\get_home_path') === false) {
405 require_once(ABSPATH.'wp-admin/includes/file.php');
406 }
407
408 return \get_home_path();
409 }
410
411 /**
412 * @see \wp_parse_id_list()
413 *
414 * @param array|string $list
415 *
416 * @return array
417 */
418 public function parseIdList($list)
419 {
420 return \wp_parse_id_list($list);
421 }
422
423 /**
424 * @see \wp_die()
425 *
426 * @param string $message
427 * @param string $title
428 * @param array $arguments
429 */
430 public function wpDie($message = '', $title = '', array $arguments = [])
431 {
432 \wp_die($message, $title, $arguments);
433 }
434
435 /**
436 * @see \is_feed()
437 *
438 * @param string|array $feeds
439 *
440 * @return bool
441 */
442 public function isFeed($feeds = '')
443 {
444 return \is_feed($feeds);
445 }
446
447 /**
448 * @see \is_user_logged_in()
449 *
450 * @return bool
451 */
452 public function isUserLoggedIn()
453 {
454 return \is_user_logged_in();
455 }
456
457 /**
458 * @see \get_page_by_path()
459 *
460 * @param string $pagePath
461 * @param string $output
462 * @param string $postType
463 *
464 * @return array|null|\WP_Post
465 */
466 public function getPageByPath($pagePath, $output = OBJECT, $postType = 'page')
467 {
468 return \get_page_by_path($pagePath, $output, $postType);
469 }
470
471 /**
472 * @see \wp_redirect()
473 *
474 * @param string $location
475 * @param int $status
476 *
477 * @return bool
478 */
479 public function wpRedirect($location, $status = 302)
480 {
481 return \wp_redirect($location, $status);
482 }
483
484 /**
485 * @param bool|int|\WP_Post $post
486 * @param bool $leaveName
487 * @param bool $sample
488 *
489 * @return string The page permalink.
490 */
491 public function getPageLink($post = false, $leaveName = false, $sample = false)
492 {
493 return \get_page_link($post, $leaveName, $sample);
494 }
495
496 /**
497 * Returns the wp_query object.
498 *
499 * @return \WP_Query
500 */
501 public function getWpQuery()
502 {
503 global $wp_query;
504 return $wp_query;
505 }
506
507 /**
508 * @see \is_admin()
509 *
510 * @return bool
511 */
512 public function isAdmin()
513 {
514 return \is_admin();
515 }
516
517 /**
518 * @see \wp_create_nonce()
519 *
520 * @param int|string $action
521 *
522 * @return string
523 */
524 public function createNonce($action)
525 {
526 return \wp_create_nonce($action);
527 }
528
529 /**
530 * @see \wp_nonce_field()
531 *
532 * @param int|string $action
533 * @param string $name
534 * @param bool $referrer
535 * @param bool $echo
536 *
537 * @return string
538 */
539 public function getNonceField($action = -1, $name = '_wpnonce', $referrer = true, $echo = true)
540 {
541 return \wp_nonce_field($action, $name, $referrer, $echo);
542 }
543
544 /**
545 * @see \wp_verify_nonce()
546 *
547 * @param string $nonce
548 * @param string|int $action
549 *
550 * @return false|int
551 */
552 public function verifyNonce($nonce, $action = -1)
553 {
554 return \wp_verify_nonce($nonce, $action);
555 }
556
557 /**
558 * Returns the wordpress roles.
559 *
560 * @return \WP_Roles
561 */
562 public function getRoles()
563 {
564 global $wp_roles;
565 return $wp_roles;
566 }
567
568 /**
569 * @see \add_menu_page()
570 *
571 * @param string $pageTitle
572 * @param string $menuTitle
573 * @param string $capability
574 * @param string $menuSlug
575 * @param mixed $function
576 * @param string $iconUrl
577 * @param null $position
578 *
579 * @return string
580 */
581 public function addMenuPage(
582 $pageTitle,
583 $menuTitle,
584 $capability,
585 $menuSlug,
586 $function = '',
587 $iconUrl = '',
588 $position = null
589 ) {
590 return \add_menu_page($pageTitle, $menuTitle, $capability, $menuSlug, $function, $iconUrl, $position);
591 }
592
593 /**
594 * @see \add_submenu_page()
595 *
596 * @param string $parentSlug
597 * @param string $pageTitle
598 * @param string $menuTitle
599 * @param string $capability
600 * @param string $menuSlug
601 * @param string|callable $function
602 *
603 * @return false|string
604 */
605 public function addSubMenuPage($parentSlug, $pageTitle, $menuTitle, $capability, $menuSlug, $function = '')
606 {
607 return \add_submenu_page($parentSlug, $pageTitle, $menuTitle, $capability, $menuSlug, $function);
608 }
609
610 /**
611 * @see \add_meta_box()
612 *
613 * @param string $id
614 * @param string $title
615 * @param callable $callback
616 * @param string|array|\WP_Screen $screen
617 * @param string $context
618 * @param string $priority
619 * @param array $callbackArguments
620 */
621 public function addMetaBox(
622 $id,
623 $title,
624 $callback,
625 $screen = null,
626 $context = 'advanced',
627 $priority = 'default',
628 $callbackArguments = null
629 ) {
630 \add_meta_box($id, $title, $callback, $screen, $context, $priority, $callbackArguments);
631 }
632
633 /**
634 * @see \get_pages()
635 *
636 * @param array|string $arguments
637 *
638 * @return array|false
639 */
640 public function getPages($arguments)
641 {
642 return \get_pages($arguments);
643 }
644
645 /**
646 * @see \wp_register_style()
647 *
648 * @param string $handle
649 * @param string $source
650 * @param array $depends
651 * @param string|bool|null $version
652 * @param string $media
653 *
654 * @return bool
655 */
656 public function registerStyle($handle, $source, $depends = [], $version = false, $media = 'all')
657 {
658 return \wp_register_style($handle, $source, $depends, $version, $media);
659 }
660
661 /**
662 * @see \wp_register_script()
663 *
664 * @param string $handle
665 * @param string $source
666 * @param array $depends
667 * @param string|bool|null $version
668 * @param bool $inFooter
669 *
670 * @return bool
671 */
672 public function registerScript($handle, $source, $depends = [], $version = false, $inFooter = false)
673 {
674 return \wp_register_script($handle, $source, $depends, $version, $inFooter);
675 }
676
677 /**
678 * @see \wp_enqueue_style()
679 *
680 * @param string $handle
681 * @param string $source
682 * @param array $depends
683 * @param string|bool|null $version
684 * @param string $media
685 */
686 public function enqueueStyle($handle, $source = '', $depends = [], $version = false, $media = 'all')
687 {
688 \wp_enqueue_style($handle, $source, $depends, $version, $media);
689 }
690
691 /**
692 * @see \wp_enqueue_script()
693 *
694 * @param string $handle
695 * @param string $source
696 * @param array $depends
697 * @param string|bool|null $version
698 * @param bool $inFooter
699 */
700 public function enqueueScript($handle, $source = '', $depends = [], $version = false, $inFooter = false)
701 {
702 \wp_enqueue_script($handle, $source, $depends, $version, $inFooter);
703 }
704
705 /**
706 * Returns the wordpress meta boxes.
707 *
708 * @return array
709 */
710 public function getMetaBoxes()
711 {
712 global $wp_meta_boxes;
713 return $wp_meta_boxes;
714 }
715
716 /**
717 * Sets the wordpress meta boxes.
718 *
719 * @param array $wpMetaBoxes
720 */
721 public function setMetaBoxes(array $wpMetaBoxes)
722 {
723 global $wp_meta_boxes;
724 $wp_meta_boxes = $wpMetaBoxes;
725 }
726
727 /**
728 * @see \get_sites()
729 *
730 * @param array $arguments
731 *
732 * @return array
733 */
734 public function getSites(array $arguments = [])
735 {
736 if (function_exists('\get_sites') === true && class_exists('\WP_Site_Query') === true) {
737 return \get_sites($arguments);
738 }
739
740 return [];
741 }
742
743 /**
744 * @see \apply_filters()
745 *
746 * @param string $tag
747 * @param mixed $value
748 *
749 * @return mixed
750 */
751 public function applyFilters($tag, $value)
752 {
753 return call_user_func_array('\apply_filters', func_get_args());
754 }
755
756 /**
757 * @see \get_bloginfo()
758 *
759 * @param string $show
760 * @param string $filter
761 *
762 * @return string
763 */
764 public function getBlogInfo($show = '', $filter = 'raw')
765 {
766 return \get_bloginfo($show, $filter);
767 }
768
769 /**
770 * @see \esc_html()
771 *
772 * @param string $text
773 *
774 * @return string
775 */
776 public function escHtml($text)
777 {
778 return \esc_html($text);
779 }
780
781 /**
782 * @see \is_single()
783 *
784 * @param int|string|array $post
785 *
786 * @return bool
787 */
788 public function isSingle($post = '')
789 {
790 return \is_single($post);
791 }
792
793 /**
794 * @see \is_page()
795 *
796 * @param int|string|array $page
797 *
798 * @return bool
799 */
800 public function isPage($page = '')
801 {
802 return \is_page($page);
803 }
804
805 /**
806 * @see \WP_PLUGIN_DIR
807 *
808 * @return string
809 */
810 public function getPluginDir()
811 {
812 return WP_PLUGIN_DIR;
813 }
814
815 /**
816 * @see \plugins_url()
817 *
818 * @param string $path
819 * @param string $plugin
820 *
821 * @return string
822 */
823 public function pluginsUrl($path = '', $plugin = '')
824 {
825 return \plugins_url($path, $plugin);
826 }
827
828 /**
829 * @see \plugin_basename()
830 *
831 * @param $file
832 *
833 * @return string
834 */
835 public function pluginBasename($file)
836 {
837 return \plugin_basename($file);
838 }
839
840 /**
841 * @see \wp_attachment_is_image()
842 *
843 * @param int|\WP_Post $post
844 *
845 * @return bool
846 */
847 public function attachmentIsImage($post)
848 {
849 return \wp_attachment_is_image($post);
850 }
851
852 /**
853 * @see \current_user_can()
854 *
855 * @param string $capability
856 *
857 * @return bool
858 */
859 public function currentUserCan($capability)
860 {
861 return \current_user_can($capability);
862 }
863
864 /**
865 * @see \get_users()
866 *
867 * @param array $arguments
868 *
869 * @return array
870 */
871 public function getUsers(array $arguments = [])
872 {
873 return \get_users($arguments);
874 }
875
876 /**
877 * @return \WP_Hook[]
878 */
879 public function getFilters()
880 {
881 global $wp_filter;
882 return $wp_filter;
883 }
884
885 /**
886 * @param array $filters
887 */
888 public function setFilters(array $filters)
889 {
890 global $wp_filter;
891 $wp_filter = $filters;
892 }
893
894 /**
895 * @see \current_time()
896 *
897 * @param string $type
898 * @param int $gmt
899 *
900 * @return int|string
901 */
902 public function currentTime($type, $gmt = 0)
903 {
904 return \current_time($type, $gmt);
905 }
906
907 /**
908 * Formats the date like wordpress does it.
909 *
910 * @param string $date
911 *
912 * @return string
913 */
914 public function formatDate($date)
915 {
916 $dateFormat = __('M j, Y @ H:i');
917 return \date_i18n($dateFormat, strtotime($date));
918 }
919
920 /**
921 * @see \register_widget()
922 *
923 * @param mixed $widgetClass
924 */
925 public function registerWidget($widgetClass)
926 {
927 \register_widget($widgetClass);
928 }
929
930 /**
931 * @see \wp_login_url()
932 *
933 * @param string $redirect
934 * @param bool $forceReauth
935 *
936 * @return string
937 */
938 public function wpLoginUrl($redirect = '', $forceReauth = false)
939 {
940 return \wp_login_url($redirect, $forceReauth);
941 }
942
943 /**
944 * @see \wp_logout_url()
945 *
946 * @param string $redirect
947 *
948 * @return string
949 */
950 public function wpLogoutUrl($redirect = '')
951 {
952 return \wp_logout_url($redirect);
953 }
954
955 /**
956 * @see \wp_registration_url()
957 *
958 * @return string
959 */
960 public function wpRegistrationUrl()
961 {
962 return \wp_registration_url();
963 }
964
965 /**
966 * @see \wp_lostpassword_url()
967 *
968 * @param string $redirect
969 *
970 * @return string
971 */
972 public function wpLostPasswordUrl($redirect = '')
973 {
974 return \wp_lostpassword_url($redirect);
975 }
976
977 /**
978 * @see \add_shortcode()
979 *
980 * @param string $tag
981 * @param callable $function
982 */
983 public function addShortCode($tag, $function)
984 {
985 \add_shortcode($tag, $function);
986 }
987
988 /**
989 * @see \do_shortcode()
990 *
991 * @param string $content
992 * @param bool $ignoreHtml
993 *
994 * @return string
995 */
996 public function doShortCode($content, $ignoreHtml = false)
997 {
998 return \do_shortcode($content, $ignoreHtml);
999 }
1000
1001 /**
1002 * @see \attachment_url_to_postid()
1003 *
1004 * @param string $url
1005 *
1006 * @return int
1007 */
1008 public function attachmentUrlToPostId($url)
1009 {
1010 return \attachment_url_to_postid($url);
1011 }
1012 }
1013