PluginProbe
User Access Manager / 2.0.12
User Access Manager v2.0.12
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.12, at src/UserAccessManager/Wrapper/Wordpress.php

868 lines 18.4 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 \wp_parse_id_list()
399 *
400 * @param array|string $list
401 *
402 * @return array
403 */
404 public function parseIdList($list)
405 {
406 return \wp_parse_id_list($list);
407 }
408
409 /**
410 * @see \wp_die()
411 *
412 * @param string $message
413 * @param string $title
414 * @param array $arguments
415 */
416 public function wpDie($message = '', $title = '', array $arguments = [])
417 {
418 \wp_die($message, $title, $arguments);
419 }
420
421 /**
422 * @see \is_feed()
423 *
424 * @param string|array $feeds
425 *
426 * @return bool
427 */
428 public function isFeed($feeds = '')
429 {
430 return \is_feed($feeds);
431 }
432
433 /**
434 * @see \is_user_logged_in()
435 *
436 * @return bool
437 */
438 public function isUserLoggedIn()
439 {
440 return \is_user_logged_in();
441 }
442
443 /**
444 * @see \get_page_by_path()
445 *
446 * @param string $pagePath
447 * @param string $output
448 * @param string $postType
449 *
450 * @return array|null|\WP_Post
451 */
452 public function getPageByPath($pagePath, $output = OBJECT, $postType = 'page')
453 {
454 return \get_page_by_path($pagePath, $output, $postType);
455 }
456
457 /**
458 * @see \wp_redirect()
459 *
460 * @param string $location
461 * @param int $status
462 *
463 * @return bool
464 */
465 public function wpRedirect($location, $status = 302)
466 {
467 return \wp_redirect($location, $status);
468 }
469
470 /**
471 * @param bool|int|\WP_Post $post
472 * @param bool $leaveName
473 * @param bool $sample
474 *
475 * @return string The page permalink.
476 */
477 public function getPageLink($post = false, $leaveName = false, $sample = false)
478 {
479 return \get_page_link($post, $leaveName, $sample);
480 }
481
482 /**
483 * Returns the wp_query object.
484 *
485 * @return \WP_Query
486 */
487 public function getWpQuery()
488 {
489 global $wp_query;
490 return $wp_query;
491 }
492
493 /**
494 * @see \is_admin()
495 *
496 * @return bool
497 */
498 public function isAdmin()
499 {
500 return \is_admin();
501 }
502
503 /**
504 * @see \wp_create_nonce()
505 *
506 * @param int|string $action
507 *
508 * @return string
509 */
510 public function createNonce($action)
511 {
512 return \wp_create_nonce($action);
513 }
514
515 /**
516 * @see \wp_nonce_field()
517 *
518 * @param int|string $action
519 * @param string $name
520 * @param bool $referrer
521 * @param bool $echo
522 *
523 * @return string
524 */
525 public function getNonceField($action = -1, $name = '_wpnonce', $referrer = true, $echo = true)
526 {
527 return \wp_nonce_field($action, $name, $referrer, $echo);
528 }
529
530 /**
531 * @see \wp_verify_nonce()
532 *
533 * @param string $nonce
534 * @param string|int $action
535 *
536 * @return false|int
537 */
538 public function verifyNonce($nonce, $action = -1)
539 {
540 return \wp_verify_nonce($nonce, $action);
541 }
542
543 /**
544 * Returns the wordpress roles.
545 *
546 * @return \WP_Roles
547 */
548 public function getRoles()
549 {
550 global $wp_roles;
551 return $wp_roles;
552 }
553
554 /**
555 * @see \add_menu_page()
556 *
557 * @param string $pageTitle
558 * @param string $menuTitle
559 * @param string $capability
560 * @param string $menuSlug
561 * @param mixed $function
562 * @param string $iconUrl
563 * @param null $position
564 *
565 * @return string
566 */
567 public function addMenuPage(
568 $pageTitle,
569 $menuTitle,
570 $capability,
571 $menuSlug,
572 $function = '',
573 $iconUrl = '',
574 $position = null
575 ) {
576 return \add_menu_page($pageTitle, $menuTitle, $capability, $menuSlug, $function, $iconUrl, $position);
577 }
578
579 /**
580 * @see \add_submenu_page()
581 *
582 * @param string $parentSlug
583 * @param string $pageTitle
584 * @param string $menuTitle
585 * @param string $capability
586 * @param string $menuSlug
587 * @param string|callable $function
588 *
589 * @return false|string
590 */
591 public function addSubMenuPage($parentSlug, $pageTitle, $menuTitle, $capability, $menuSlug, $function = '')
592 {
593 return \add_submenu_page($parentSlug, $pageTitle, $menuTitle, $capability, $menuSlug, $function);
594 }
595
596 /**
597 * @see \add_meta_box()
598 *
599 * @param string $id
600 * @param string $title
601 * @param callable $callback
602 * @param string|array|\WP_Screen $screen
603 * @param string $context
604 * @param string $priority
605 * @param array $callbackArguments
606 */
607 public function addMetaBox(
608 $id,
609 $title,
610 $callback,
611 $screen = null,
612 $context = 'advanced',
613 $priority = 'default',
614 $callbackArguments = null
615 ) {
616 \add_meta_box($id, $title, $callback, $screen, $context, $priority, $callbackArguments);
617 }
618
619 /**
620 * @see \get_pages()
621 *
622 * @param array|string $arguments
623 *
624 * @return array|false
625 */
626 public function getPages($arguments)
627 {
628 return \get_pages($arguments);
629 }
630
631 /**
632 * @see \wp_register_style()
633 *
634 * @param string $handle
635 * @param string $source
636 * @param array $depends
637 * @param string|bool|null $version
638 * @param string $media
639 *
640 * @return bool
641 */
642 public function registerStyle($handle, $source, $depends = [], $version = false, $media = 'all')
643 {
644 return \wp_register_style($handle, $source, $depends, $version, $media);
645 }
646
647 /**
648 * @see \wp_register_script()
649 *
650 * @param string $handle
651 * @param string $source
652 * @param array $depends
653 * @param string|bool|null $version
654 * @param bool $inFooter
655 *
656 * @return bool
657 */
658 public function registerScript($handle, $source, $depends = [], $version = false, $inFooter = false)
659 {
660 return \wp_register_script($handle, $source, $depends, $version, $inFooter);
661 }
662
663 /**
664 * @see \wp_enqueue_style()
665 *
666 * @param string $handle
667 * @param string $source
668 * @param array $depends
669 * @param string|bool|null $version
670 * @param string $media
671 */
672 public function enqueueStyle($handle, $source = '', $depends = [], $version = false, $media = 'all')
673 {
674 \wp_enqueue_style($handle, $source, $depends, $version, $media);
675 }
676
677 /**
678 * @see \wp_enqueue_script()
679 *
680 * @param string $handle
681 * @param string $source
682 * @param array $depends
683 * @param string|bool|null $version
684 * @param bool $inFooter
685 */
686 public function enqueueScript($handle, $source = '', $depends = [], $version = false, $inFooter = false)
687 {
688 \wp_enqueue_script($handle, $source, $depends, $version, $inFooter);
689 }
690
691 /**
692 * Returns the wordpress meta boxes.
693 *
694 * @return array
695 */
696 public function getMetaBoxes()
697 {
698 global $wp_meta_boxes;
699 return $wp_meta_boxes;
700 }
701
702 /**
703 * Sets the wordpress meta boxes.
704 *
705 * @param array $wpMetaBoxes
706 */
707 public function setMetaBoxes(array $wpMetaBoxes)
708 {
709 global $wp_meta_boxes;
710 $wp_meta_boxes= $wpMetaBoxes;
711 }
712
713 /**
714 * @see \get_sites()
715 *
716 * @param array $arguments
717 *
718 * @return array
719 */
720 public function getSites(array $arguments = [])
721 {
722 if (function_exists('\get_sites') === true && class_exists('\WP_Site_Query') === true) {
723 return \get_sites($arguments);
724 }
725
726 return [];
727 }
728
729 /**
730 * @see \apply_filters()
731 *
732 * @param string $tag
733 * @param mixed $value
734 *
735 * @return mixed
736 */
737 public function applyFilters($tag, $value)
738 {
739 return call_user_func_array('\apply_filters', func_get_args());
740 }
741
742 /**
743 * @see \get_bloginfo()
744 *
745 * @param string $show
746 * @param string $filter
747 *
748 * @return string
749 */
750 public function getBlogInfo($show = '', $filter = 'raw')
751 {
752 return \get_bloginfo($show, $filter);
753 }
754
755 /**
756 * @see \esc_html()
757 *
758 * @param string $text
759 *
760 * @return string
761 */
762 public function escHtml($text)
763 {
764 return \esc_html($text);
765 }
766
767 /**
768 * @see \is_single()
769 *
770 * @param int|string|array $post
771 *
772 * @return bool
773 */
774 public function isSingle($post = '')
775 {
776 return \is_single($post);
777 }
778
779 /**
780 * @see \is_page()
781 *
782 * @param int|string|array $page
783 *
784 * @return bool
785 */
786 public function isPage($page = '')
787 {
788 return \is_page($page);
789 }
790
791 /**
792 * @see \WP_PLUGIN_DIR
793 *
794 * @return string
795 */
796 public function getPluginDir()
797 {
798 return WP_PLUGIN_DIR;
799 }
800
801 /**
802 * @see \plugins_url()
803 *
804 * @param string $path
805 * @param string $plugin
806 *
807 * @return string
808 */
809 public function pluginsUrl($path = '', $plugin = '')
810 {
811 return \plugins_url($path, $plugin);
812 }
813
814 /**
815 * @see \plugin_basename()
816 *
817 * @param $file
818 *
819 * @return string
820 */
821 public function pluginBasename($file)
822 {
823 return \plugin_basename($file);
824 }
825
826 /**
827 * @see wp_attachment_is_image()
828 *
829 * @param int|\WP_Post $post
830 *
831 * @return bool
832 */
833 public function attachmentIsImage($post)
834 {
835 return wp_attachment_is_image($post);
836 }
837
838 /**
839 * @see current_user_can()
840 *
841 * @param string $capability
842 *
843 * @return bool
844 */
845 public function currentUserCan($capability)
846 {
847 return current_user_can($capability);
848 }
849
850 /**
851 * @return \WP_Hook[]
852 */
853 public function getFilters()
854 {
855 global $wp_filter;
856 return $wp_filter;
857 }
858
859 /**
860 * @param array $filters
861 */
862 public function setFilters(array $filters)
863 {
864 global $wp_filter;
865 $wp_filter = $filters;
866 }
867 }
868