PluginProbe
User Access Manager / 2.1.10
User Access Manager v2.1.10
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.10, at src/Wrapper/Wordpress.php

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