PluginProbe
User Access Manager / 2.0.1
User Access Manager v2.0.1
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.1, at src/UserAccessManager/Wrapper/Wordpress.php

839 lines 17.7 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 return \switch_to_blog($blogId);
191 }
192
193 /**
194 * @see \is_multisite()
195 *
196 * @return bool
197 */
198 public function isMultiSite()
199 {
200 return \is_multisite();
201 }
202
203 /**
204 * @see \do_action()
205 *
206 * @param string $tag
207 * @param mixed $arguments
208 */
209 public function doAction($tag, $arguments = '')
210 {
211 \do_action($tag, $arguments);
212 }
213
214 /**
215 * @see \add_action()
216 *
217 * @param string $tag
218 * @param callable $functionToAdd
219 * @param int $priority
220 * @param int $acceptedArguments
221 *
222 * @return true
223 */
224 public function addAction($tag, $functionToAdd, $priority = 10, $acceptedArguments = 1)
225 {
226 return \add_action($tag, $functionToAdd, $priority, $acceptedArguments);
227 }
228
229 /**
230 * @see \has_filter()
231 *
232 * @param string $tag
233 * @param bool|callable $functionToCheck
234 *
235 * @return bool|false|int
236 */
237 public function hasFilter($tag, $functionToCheck = false)
238 {
239 return \has_filter($tag, $functionToCheck);
240 }
241
242 /**
243 * @see \add_filter()
244 *
245 * @param string $tag
246 * @param callable $functionToAdd
247 * @param int $priority
248 * @param int $acceptedArguments
249 *
250 * @return true
251 */
252 public function addFilter($tag, $functionToAdd, $priority = 10, $acceptedArguments = 1)
253 {
254 return \add_filter($tag, $functionToAdd, $priority, $acceptedArguments);
255 }
256
257 /**
258 * @see \remove_filter()
259 *
260 * @param string $tag
261 * @param callable $functionToRemove
262 * @param int $priority
263 *
264 * @return bool
265 */
266 public function removeFilter($tag, $functionToRemove, $priority = 10)
267 {
268 return \remove_filter($tag, $functionToRemove, $priority);
269 }
270
271 /**
272 * @see \add_option()
273 *
274 * @param string $option
275 * @param mixed $value
276 * @param string $deprecated
277 * @param string|bool $autoload
278 *
279 * @return bool
280 */
281 public function addOption($option, $value = '', $deprecated = '', $autoload = 'yes')
282 {
283 return \add_option($option, $value, $deprecated, $autoload);
284 }
285
286 /**
287 * @see \delete_option()
288 *
289 * @param string $option
290 *
291 * @return bool
292 */
293 public function deleteOption($option)
294 {
295 return \delete_option($option);
296 }
297
298 /**
299 * @see \update_option()
300 *
301 * @param string $option
302 * @param mixed $value
303 * @param string|bool $autoload
304 *
305 * @return bool
306 */
307 public function updateOption($option, $value = '', $autoload = 'yes')
308 {
309 return \update_option($option, $value, $autoload);
310 }
311
312 /**
313 * @see \get_option()
314 *
315 * @param string $option
316 * @param mixed $default
317 *
318 * @return mixed
319 */
320 public function getOption($option, $default = false)
321 {
322 return \get_option($option, $default);
323 }
324
325 /**
326 * @see \is_super_admin()
327 *
328 * @param int|bool $userId
329 *
330 * @return bool
331 */
332 public function isSuperAdmin($userId = false)
333 {
334 return \is_super_admin($userId);
335 }
336
337 /**
338 * @see \wp_get_current_user()
339 *
340 * @return \WP_User
341 */
342 public function getCurrentUser()
343 {
344 return \wp_get_current_user();
345 }
346
347 /**
348 * @see \get_allowed_mime_types()
349 *
350 * @param int|\WP_User $user
351 *
352 * @return array
353 */
354 public function getAllowedMimeTypes($user = null)
355 {
356 return \get_allowed_mime_types($user);
357 }
358
359 /**
360 * @see \wp_upload_dir()
361 *
362 * @param string $time
363 * @param bool $createDir
364 * @param bool $refreshCache
365 *
366 * @return array
367 */
368 public function getUploadDir($time = null, $createDir = true, $refreshCache = false)
369 {
370 return \wp_upload_dir($time, $createDir, $refreshCache);
371 }
372
373 /**
374 * @see \home_url()
375 *
376 * @param string $path
377 * @param string $scheme
378 *
379 * @return string
380 */
381 public function getHomeUrl($path = '', $scheme = null)
382 {
383 return \home_url($path, $scheme);
384 }
385
386 /**
387 * @see \wp_parse_id_list()
388 *
389 * @param array|string $list
390 *
391 * @return array
392 */
393 public function parseIdList($list)
394 {
395 return \wp_parse_id_list($list);
396 }
397
398 /**
399 * @see \wp_die()
400 *
401 * @param string $message
402 * @param string $title
403 * @param array $arguments
404 */
405 public function wpDie($message = '', $title = '', array $arguments = [])
406 {
407 \wp_die($message, $title, $arguments);
408 }
409
410 /**
411 * @see \is_feed()
412 *
413 * @param string|array $feeds
414 *
415 * @return bool
416 */
417 public function isFeed($feeds = '')
418 {
419 return \is_feed($feeds);
420 }
421
422 /**
423 * @see \is_user_logged_in()
424 *
425 * @return bool
426 */
427 public function isUserLoggedIn()
428 {
429 return \is_user_logged_in();
430 }
431
432 /**
433 * @see \get_page_by_path()
434 *
435 * @param string $pagePath
436 * @param string $output
437 * @param string $postType
438 *
439 * @return array|null|\WP_Post
440 */
441 public function getPageByPath($pagePath, $output = OBJECT, $postType = 'page')
442 {
443 return \get_page_by_path($pagePath, $output, $postType);
444 }
445
446 /**
447 * @see \wp_redirect()
448 *
449 * @param string $location
450 * @param int $status
451 *
452 * @return bool
453 */
454 public function wpRedirect($location, $status = 302)
455 {
456 return \wp_redirect($location, $status);
457 }
458
459 /**
460 * @param bool|int|\WP_Post $post
461 * @param bool $leaveName
462 * @param bool $sample
463 *
464 * @return string The page permalink.
465 */
466 public function getPageLink($post = false, $leaveName = false, $sample = false)
467 {
468 return \get_page_link($post, $leaveName, $sample);
469 }
470
471 /**
472 * Returns the wp_query object.
473 *
474 * @return \WP_Query
475 */
476 public function getWpQuery()
477 {
478 global $wp_query;
479 return $wp_query;
480 }
481
482 /**
483 * @see \is_admin()
484 *
485 * @return bool
486 */
487 public function isAdmin()
488 {
489 return \is_admin();
490 }
491
492 /**
493 * @see \wp_create_nonce()
494 *
495 * @param int|string $action
496 *
497 * @return string
498 */
499 public function createNonce($action)
500 {
501 return \wp_create_nonce($action);
502 }
503
504 /**
505 * @see \wp_nonce_field()
506 *
507 * @param int|string $action
508 * @param string $name
509 * @param bool $referrer
510 * @param bool $echo
511 *
512 * @return string
513 */
514 public function getNonceField($action = -1, $name = '_wpnonce', $referrer = true, $echo = true)
515 {
516 return \wp_nonce_field($action, $name, $referrer, $echo);
517 }
518
519 /**
520 * @see \wp_verify_nonce()
521 *
522 * @param string $nonce
523 * @param string|int $action
524 *
525 * @return false|int
526 */
527 public function verifyNonce($nonce, $action = -1)
528 {
529 return \wp_verify_nonce($nonce, $action);
530 }
531
532 /**
533 * Returns the wordpress roles.
534 *
535 * @return \WP_Roles
536 */
537 public function getRoles()
538 {
539 global $wp_roles;
540 return $wp_roles;
541 }
542
543 /**
544 * @see \add_menu_page()
545 *
546 * @param string $pageTitle
547 * @param string $menuTitle
548 * @param string $capability
549 * @param string $menuSlug
550 * @param mixed $function
551 * @param string $iconUrl
552 * @param null $position
553 *
554 * @return string
555 */
556 public function addMenuPage(
557 $pageTitle,
558 $menuTitle,
559 $capability,
560 $menuSlug,
561 $function = '',
562 $iconUrl = '',
563 $position = null
564 ) {
565 return \add_menu_page($pageTitle, $menuTitle, $capability, $menuSlug, $function, $iconUrl, $position);
566 }
567
568 /**
569 * @see \add_submenu_page()
570 *
571 * @param string $parentSlug
572 * @param string $pageTitle
573 * @param string $menuTitle
574 * @param string $capability
575 * @param string $menuSlug
576 * @param string|callable $function
577 *
578 * @return false|string
579 */
580 public function addSubMenuPage($parentSlug, $pageTitle, $menuTitle, $capability, $menuSlug, $function = '')
581 {
582 return \add_submenu_page($parentSlug, $pageTitle, $menuTitle, $capability, $menuSlug, $function);
583 }
584
585 /**
586 * @see \add_meta_box()
587 *
588 * @param string $id
589 * @param string $title
590 * @param callable $callback
591 * @param string|array|\WP_Screen $screen
592 * @param string $context
593 * @param string $priority
594 * @param array $callbackArguments
595 */
596 public function addMetaBox(
597 $id,
598 $title,
599 $callback,
600 $screen = null,
601 $context = 'advanced',
602 $priority = 'default',
603 $callbackArguments = null
604 ) {
605 \add_meta_box($id, $title, $callback, $screen, $context, $priority, $callbackArguments);
606 }
607
608 /**
609 * @see \get_pages()
610 *
611 * @param array|string $arguments
612 *
613 * @return array|false
614 */
615 public function getPages($arguments)
616 {
617 return \get_pages($arguments);
618 }
619
620 /**
621 * @see \wp_register_style()
622 *
623 * @param string $handle
624 * @param string $source
625 * @param array $depends
626 * @param string|bool|null $version
627 * @param string $media
628 *
629 * @return bool
630 */
631 public function registerStyle($handle, $source, $depends = [], $version = false, $media = 'all')
632 {
633 return \wp_register_style($handle, $source, $depends, $version, $media);
634 }
635
636 /**
637 * @see \wp_register_script()
638 *
639 * @param string $handle
640 * @param string $source
641 * @param array $depends
642 * @param string|bool|null $version
643 * @param bool $inFooter
644 *
645 * @return bool
646 */
647 public function registerScript($handle, $source, $depends = [], $version = false, $inFooter = false)
648 {
649 return \wp_register_script($handle, $source, $depends, $version, $inFooter);
650 }
651
652 /**
653 * @see \wp_enqueue_style()
654 *
655 * @param string $handle
656 * @param string $source
657 * @param array $depends
658 * @param string|bool|null $version
659 * @param string $media
660 */
661 public function enqueueStyle($handle, $source = '', $depends = [], $version = false, $media = 'all')
662 {
663 \wp_enqueue_style($handle, $source, $depends, $version, $media);
664 }
665
666 /**
667 * @see \wp_enqueue_script()
668 *
669 * @param string $handle
670 * @param string $source
671 * @param array $depends
672 * @param string|bool|null $version
673 * @param bool $inFooter
674 */
675 public function enqueueScript($handle, $source = '', $depends = [], $version = false, $inFooter = false)
676 {
677 \wp_enqueue_script($handle, $source, $depends, $version, $inFooter);
678 }
679
680 /**
681 * Returns the wordpress meta boxes.
682 *
683 * @return array
684 */
685 public function getMetaBoxes()
686 {
687 global $wp_meta_boxes;
688 return $wp_meta_boxes;
689 }
690
691 /**
692 * Sets the wordpress meta boxes.
693 *
694 * @param array $wpMetaBoxes
695 */
696 public function setMetaBoxes(array $wpMetaBoxes)
697 {
698 global $wp_meta_boxes;
699 $wp_meta_boxes= $wpMetaBoxes;
700 }
701
702 /**
703 * @see \get_sites()
704 *
705 * @param array $arguments
706 *
707 * @return array
708 */
709 public function getSites(array $arguments = [])
710 {
711 if (function_exists('get_sites')) {
712 return \get_sites($arguments);
713 }
714
715 return [];
716 }
717
718 /**
719 * @see \apply_filters()
720 *
721 * @param string $tag
722 * @param mixed $value
723 *
724 * @return mixed
725 */
726 public function applyFilters($tag, $value)
727 {
728 return call_user_func_array('\apply_filters', func_get_args());
729 }
730
731 /**
732 * @see \get_bloginfo()
733 *
734 * @param string $show
735 * @param string $filter
736 *
737 * @return string
738 */
739 public function getBlogInfo($show = '', $filter = 'raw')
740 {
741 return \get_bloginfo($show, $filter);
742 }
743
744 /**
745 * @see \esc_html()
746 *
747 * @param string $text
748 *
749 * @return string
750 */
751 public function escHtml($text)
752 {
753 return \esc_html($text);
754 }
755
756 /**
757 * @see \is_single()
758 *
759 * @param int|string|array $post
760 *
761 * @return bool
762 */
763 public function isSingle($post = '')
764 {
765 return \is_single($post);
766 }
767
768 /**
769 * @see \is_page()
770 *
771 * @param int|string|array $page
772 *
773 * @return bool
774 */
775 public function isPage($page = '')
776 {
777 return \is_page($page);
778 }
779
780 /**
781 * @see \WP_PLUGIN_DIR
782 *
783 * @return string
784 */
785 public function getPluginDir()
786 {
787 return WP_PLUGIN_DIR;
788 }
789
790 /**
791 * @see \plugins_url()
792 *
793 * @param string $path
794 * @param string $plugin
795 *
796 * @return string
797 */
798 public function pluginsUrl($path = '', $plugin = '')
799 {
800 return \plugins_url($path, $plugin);
801 }
802
803 /**
804 * @see \plugin_basename()
805 *
806 * @param $file
807 *
808 * @return string
809 */
810 public function pluginBasename($file)
811 {
812 return \plugin_basename($file);
813 }
814
815 /**
816 * @see wp_attachment_is_image()
817 *
818 * @param int|\WP_Post $post
819 *
820 * @return bool
821 */
822 public function attachmentIsImage($post)
823 {
824 return wp_attachment_is_image($post);
825 }
826
827 /**
828 * @see current_user_can()
829 *
830 * @param string $capability
831 *
832 * @return bool
833 */
834 public function currentUserCan($capability)
835 {
836 return current_user_can($capability);
837 }
838 }
839