PluginProbe
User Access Manager / 2.1.9
User Access Manager v2.1.9
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.9, at src/Wrapper/Wordpress.php

1,036 lines 21.5 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 null|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 \site_url();
399 *
400 * @param string $path
401 * @param null|string $scheme
402 *
403 * @return string
404 */
405 public function getSiteUrl($path = '', $scheme = null)
406 {
407 return \site_url($path, $scheme);
408 }
409
410 /**
411 * @see \get_home_path()
412 *
413 * @return string
414 */
415 public function getHomePath()
416 {
417 if (function_exists('\get_home_path') === false) {
418 require_once(ABSPATH.'wp-admin/includes/file.php');
419 }
420
421 return \get_home_path();
422 }
423
424 /**
425 * @see \wp_parse_id_list()
426 *
427 * @param array|string $list
428 *
429 * @return array
430 */
431 public function parseIdList($list)
432 {
433 return \wp_parse_id_list($list);
434 }
435
436 /**
437 * @see \wp_die()
438 *
439 * @param string $message
440 * @param string $title
441 * @param array $arguments
442 */
443 public function wpDie($message = '', $title = '', array $arguments = [])
444 {
445 \wp_die($message, $title, $arguments);
446 }
447
448 /**
449 * @see \is_feed()
450 *
451 * @param string|array $feeds
452 *
453 * @return bool
454 */
455 public function isFeed($feeds = '')
456 {
457 return \is_feed($feeds);
458 }
459
460 /**
461 * @see \is_user_logged_in()
462 *
463 * @return bool
464 */
465 public function isUserLoggedIn()
466 {
467 return \is_user_logged_in();
468 }
469
470 /**
471 * @see \get_page_by_path()
472 *
473 * @param string $pagePath
474 * @param string $output
475 * @param string $postType
476 *
477 * @return array|null|\WP_Post
478 */
479 public function getPageByPath($pagePath, $output = OBJECT, $postType = 'page')
480 {
481 return \get_page_by_path($pagePath, $output, $postType);
482 }
483
484 /**
485 * @see \wp_redirect()
486 *
487 * @param string $location
488 * @param int $status
489 *
490 * @return bool
491 */
492 public function wpRedirect($location, $status = 302)
493 {
494 return \wp_redirect($location, $status);
495 }
496
497 /**
498 * @param bool|int|\WP_Post $post
499 * @param bool $leaveName
500 * @param bool $sample
501 *
502 * @return string The page permalink.
503 */
504 public function getPageLink($post = false, $leaveName = false, $sample = false)
505 {
506 return \get_page_link($post, $leaveName, $sample);
507 }
508
509 /**
510 * Returns the wp_query object.
511 *
512 * @return \WP_Query
513 */
514 public function getWpQuery()
515 {
516 global $wp_query;
517 return $wp_query;
518 }
519
520 /**
521 * @see \is_admin()
522 *
523 * @return bool
524 */
525 public function isAdmin()
526 {
527 return \is_admin();
528 }
529
530 /**
531 * @see \wp_create_nonce()
532 *
533 * @param int|string $action
534 *
535 * @return string
536 */
537 public function createNonce($action)
538 {
539 return \wp_create_nonce($action);
540 }
541
542 /**
543 * @see \wp_nonce_field()
544 *
545 * @param int|string $action
546 * @param string $name
547 * @param bool $referrer
548 * @param bool $echo
549 *
550 * @return string
551 */
552 public function getNonceField($action = -1, $name = '_wpnonce', $referrer = true, $echo = true)
553 {
554 return \wp_nonce_field($action, $name, $referrer, $echo);
555 }
556
557 /**
558 * @see \wp_verify_nonce()
559 *
560 * @param string $nonce
561 * @param string|int $action
562 *
563 * @return false|int
564 */
565 public function verifyNonce($nonce, $action = -1)
566 {
567 return \wp_verify_nonce($nonce, $action);
568 }
569
570 /**
571 * Returns the wordpress roles.
572 *
573 * @return \WP_Roles
574 */
575 public function getRoles()
576 {
577 global $wp_roles;
578 return $wp_roles;
579 }
580
581 /**
582 * @see \add_menu_page()
583 *
584 * @param string $pageTitle
585 * @param string $menuTitle
586 * @param string $capability
587 * @param string $menuSlug
588 * @param mixed $function
589 * @param string $iconUrl
590 * @param null $position
591 *
592 * @return string
593 */
594 public function addMenuPage(
595 $pageTitle,
596 $menuTitle,
597 $capability,
598 $menuSlug,
599 $function = '',
600 $iconUrl = '',
601 $position = null
602 ) {
603 return \add_menu_page($pageTitle, $menuTitle, $capability, $menuSlug, $function, $iconUrl, $position);
604 }
605
606 /**
607 * @see \add_submenu_page()
608 *
609 * @param string $parentSlug
610 * @param string $pageTitle
611 * @param string $menuTitle
612 * @param string $capability
613 * @param string $menuSlug
614 * @param string|callable $function
615 *
616 * @return false|string
617 */
618 public function addSubMenuPage($parentSlug, $pageTitle, $menuTitle, $capability, $menuSlug, $function = '')
619 {
620 return \add_submenu_page($parentSlug, $pageTitle, $menuTitle, $capability, $menuSlug, $function);
621 }
622
623 /**
624 * @see \add_meta_box()
625 *
626 * @param string $id
627 * @param string $title
628 * @param callable $callback
629 * @param string|array|\WP_Screen $screen
630 * @param string $context
631 * @param string $priority
632 * @param array $callbackArguments
633 */
634 public function addMetaBox(
635 $id,
636 $title,
637 $callback,
638 $screen = null,
639 $context = 'advanced',
640 $priority = 'default',
641 $callbackArguments = null
642 ) {
643 \add_meta_box($id, $title, $callback, $screen, $context, $priority, $callbackArguments);
644 }
645
646 /**
647 * @see \get_pages()
648 *
649 * @param array|string $arguments
650 *
651 * @return array|false
652 */
653 public function getPages($arguments)
654 {
655 return \get_pages($arguments);
656 }
657
658 /**
659 * @see \wp_register_style()
660 *
661 * @param string $handle
662 * @param string $source
663 * @param array $depends
664 * @param string|bool|null $version
665 * @param string $media
666 *
667 * @return bool
668 */
669 public function registerStyle($handle, $source, $depends = [], $version = false, $media = 'all')
670 {
671 return \wp_register_style($handle, $source, $depends, $version, $media);
672 }
673
674 /**
675 * @see \wp_register_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 * @return bool
684 */
685 public function registerScript($handle, $source, $depends = [], $version = false, $inFooter = false)
686 {
687 return \wp_register_script($handle, $source, $depends, $version, $inFooter);
688 }
689
690 /**
691 * @see \wp_enqueue_style()
692 *
693 * @param string $handle
694 * @param string $source
695 * @param array $depends
696 * @param string|bool|null $version
697 * @param string $media
698 */
699 public function enqueueStyle($handle, $source = '', $depends = [], $version = false, $media = 'all')
700 {
701 \wp_enqueue_style($handle, $source, $depends, $version, $media);
702 }
703
704 /**
705 * @see \wp_enqueue_script()
706 *
707 * @param string $handle
708 * @param string $source
709 * @param array $depends
710 * @param string|bool|null $version
711 * @param bool $inFooter
712 */
713 public function enqueueScript($handle, $source = '', $depends = [], $version = false, $inFooter = false)
714 {
715 \wp_enqueue_script($handle, $source, $depends, $version, $inFooter);
716 }
717
718 /**
719 * Returns the wordpress meta boxes.
720 *
721 * @return array
722 */
723 public function getMetaBoxes()
724 {
725 global $wp_meta_boxes;
726 return $wp_meta_boxes;
727 }
728
729 /**
730 * Sets the wordpress meta boxes.
731 *
732 * @param array $wpMetaBoxes
733 */
734 public function setMetaBoxes(array $wpMetaBoxes)
735 {
736 global $wp_meta_boxes;
737 $wp_meta_boxes = $wpMetaBoxes;
738 }
739
740 /**
741 * @see \get_sites()
742 *
743 * @param array $arguments
744 *
745 * @return array
746 */
747 public function getSites(array $arguments = [])
748 {
749 if (function_exists('\get_sites') === true && class_exists('\WP_Site_Query') === true) {
750 return \get_sites($arguments);
751 }
752
753 return [];
754 }
755
756 /**
757 * @see \apply_filters()
758 *
759 * @param string $tag
760 * @param mixed $value
761 *
762 * @return mixed
763 */
764 public function applyFilters($tag, $value)
765 {
766 return call_user_func_array('\apply_filters', func_get_args());
767 }
768
769 /**
770 * @see \get_bloginfo()
771 *
772 * @param string $show
773 * @param string $filter
774 *
775 * @return string
776 */
777 public function getBlogInfo($show = '', $filter = 'raw')
778 {
779 return \get_bloginfo($show, $filter);
780 }
781
782 /**
783 * @see \esc_html()
784 *
785 * @param string $text
786 *
787 * @return string
788 */
789 public function escHtml($text)
790 {
791 return \esc_html($text);
792 }
793
794 /**
795 * @see \is_single()
796 *
797 * @param int|string|array $post
798 *
799 * @return bool
800 */
801 public function isSingle($post = '')
802 {
803 return \is_single($post);
804 }
805
806 /**
807 * @see \is_page()
808 *
809 * @param int|string|array $page
810 *
811 * @return bool
812 */
813 public function isPage($page = '')
814 {
815 return \is_page($page);
816 }
817
818 /**
819 * @see \WP_PLUGIN_DIR
820 *
821 * @return string
822 */
823 public function getPluginDir()
824 {
825 return WP_PLUGIN_DIR;
826 }
827
828 /**
829 * @see \plugins_url()
830 *
831 * @param string $path
832 * @param string $plugin
833 *
834 * @return string
835 */
836 public function pluginsUrl($path = '', $plugin = '')
837 {
838 return \plugins_url($path, $plugin);
839 }
840
841 /**
842 * @see \plugin_basename()
843 *
844 * @param $file
845 *
846 * @return string
847 */
848 public function pluginBasename($file)
849 {
850 return \plugin_basename($file);
851 }
852
853 /**
854 * @see \wp_attachment_is_image()
855 *
856 * @param int|\WP_Post $post
857 *
858 * @return bool
859 */
860 public function attachmentIsImage($post)
861 {
862 return \wp_attachment_is_image($post);
863 }
864
865 /**
866 * @see \current_user_can()
867 *
868 * @param string $capability
869 *
870 * @return bool
871 */
872 public function currentUserCan($capability)
873 {
874 return \current_user_can($capability);
875 }
876
877 /**
878 * @see \get_users()
879 *
880 * @param array $arguments
881 *
882 * @return array
883 */
884 public function getUsers(array $arguments = [])
885 {
886 return \get_users($arguments);
887 }
888
889 /**
890 * @return \WP_Hook[]
891 */
892 public function getFilters()
893 {
894 global $wp_filter;
895 return $wp_filter;
896 }
897
898 /**
899 * @param array $filters
900 */
901 public function setFilters(array $filters)
902 {
903 global $wp_filter;
904 $wp_filter = $filters;
905 }
906
907 /**
908 * @see \current_time()
909 *
910 * @param string $type
911 * @param int $gmt
912 *
913 * @return int|string
914 */
915 public function currentTime($type, $gmt = 0)
916 {
917 return \current_time($type, $gmt);
918 }
919
920 /**
921 * Formats the date like wordpress does it.
922 *
923 * @param string $date
924 *
925 * @return string
926 */
927 public function formatDate($date)
928 {
929 $dateFormat = __('M j, Y @ H:i');
930 return \date_i18n($dateFormat, strtotime($date));
931 }
932
933 /**
934 * @see \register_widget()
935 *
936 * @param mixed $widgetClass
937 */
938 public function registerWidget($widgetClass)
939 {
940 \register_widget($widgetClass);
941 }
942
943 /**
944 * @see \wp_login_url()
945 *
946 * @param string $redirect
947 * @param bool $forceReauth
948 *
949 * @return string
950 */
951 public function wpLoginUrl($redirect = '', $forceReauth = false)
952 {
953 return \wp_login_url($redirect, $forceReauth);
954 }
955
956 /**
957 * @see \wp_logout_url()
958 *
959 * @param string $redirect
960 *
961 * @return string
962 */
963 public function wpLogoutUrl($redirect = '')
964 {
965 return \wp_logout_url($redirect);
966 }
967
968 /**
969 * @see \wp_registration_url()
970 *
971 * @return string
972 */
973 public function wpRegistrationUrl()
974 {
975 return \wp_registration_url();
976 }
977
978 /**
979 * @see \wp_lostpassword_url()
980 *
981 * @param string $redirect
982 *
983 * @return string
984 */
985 public function wpLostPasswordUrl($redirect = '')
986 {
987 return \wp_lostpassword_url($redirect);
988 }
989
990 /**
991 * @see \add_shortcode()
992 *
993 * @param string $tag
994 * @param callable $function
995 */
996 public function addShortCode($tag, $function)
997 {
998 \add_shortcode($tag, $function);
999 }
1000
1001 /**
1002 * @see \do_shortcode()
1003 *
1004 * @param string $content
1005 * @param bool $ignoreHtml
1006 *
1007 * @return string
1008 */
1009 public function doShortCode($content, $ignoreHtml = false)
1010 {
1011 return \do_shortcode($content, $ignoreHtml);
1012 }
1013
1014 /**
1015 * @see \attachment_url_to_postid()
1016 *
1017 * @param string $url
1018 *
1019 * @return int
1020 */
1021 public function attachmentUrlToPostId($url)
1022 {
1023 return \attachment_url_to_postid($url);
1024 }
1025
1026 /**
1027 * @see \got_mod_rewrite()
1028 *
1029 * @return bool
1030 */
1031 public function gotModRewrite()
1032 {
1033 return \got_mod_rewrite();
1034 }
1035 }
1036