PluginProbe
User Access Manager / 2.0.2
User Access Manager v2.0.2
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.2, at src/UserAccessManager/Wrapper/Wordpress.php

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