PluginProbe ʕ •ᴥ•ʔ
Nested Pages / 3.0.8
Nested Pages v3.0.8
3.3.1 3.2.15 3.2.14 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.3.0 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.2 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.3.1 1.6.3.2 1.6.4 1.6.5 1.6.5.1 1.6.5.2 1.6.6 1.6.7 1.6.8 1.7.0 1.7.1 2.0.1 2.0.2 2.0.3 2.0.4 3.0.1 3.0.10 3.0.11 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.21 3.1.22 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7
wp-nested-pages / app / Entities / User / UserRepository.php
wp-nested-pages / app / Entities / User Last commit date
UserRepository.php 7 years ago
UserRepository.php
142 lines
1 <?php
2 namespace NestedPages\Entities\User;
3
4 use NestedPages\Entities\PluginIntegration\IntegrationFactory;
5
6 /**
7 * User Repository
8 * @since 1.1.7
9 */
10 class UserRepository
11 {
12 /**
13 * Plugin Integrations
14 * @var object
15 */
16 private $integrations;
17
18 public function __construct()
19 {
20 $this->integrations = new IntegrationFactory;
21 }
22
23 /**
24 * Return Current User's Roles
25 * @return array
26 * @since 1.1.7
27 */
28 public function getRoles()
29 {
30 global $current_user;
31
32 // If current user is superadmin (WP Multisite) add administrator to the roles array
33 if (function_exists('is_multisite') && is_multisite() && is_super_admin()) {
34 $current_user->roles[] = 'administrator';
35 }
36
37 return $current_user->roles;
38 }
39
40 /**
41 * Get all roles that arent admin, contributor or subscriber
42 * @return array
43 * @since 1.1.7
44 */
45 public function allRoles($exclude = array('Administrator', 'Contributor', 'Subscriber', 'Author') )
46 {
47 global $wp_roles;
48 $all_roles = $wp_roles->roles;
49 $editable_roles = apply_filters('editable_roles', $all_roles);
50 $roles = [];
51 if ( !is_array($exclude) ) $exclude = [];
52 foreach($editable_roles as $key=>$editable_role){
53 if ( !in_array($editable_role['name'], $exclude) ){
54 $role = [
55 'name' => $key,
56 'label' => $editable_role['name']
57 ];
58 array_push($roles, $role);
59 }
60 }
61 return $roles;
62 }
63
64 /**
65 * Get a single role
66 * @since 3.0
67 */
68 public function getSingleRole($role = 'administrator')
69 {
70 global $wp_roles;
71 if ( isset($wp_roles->roles[$role]) ) return $wp_roles->roles[$role];
72 return false;
73 }
74
75 /**
76 * Can current user sort pages
77 * @return boolean
78 * @since 1.1.7
79 */
80 public function canSortPages()
81 {
82 $roles = $this->getRoles();
83 $cansort = get_option('nestedpages_allowsorting', []);
84 if ( $cansort == "" ) $cansort = [];
85
86 foreach($roles as $role){
87 if ( $role == 'administrator' ) return true;
88 if ( in_array($role, $cansort) ) return true;
89 }
90 return false;
91 }
92
93 /**
94 * Can the user publish to post type
95 */
96 public function canPublish($post_type = 'post')
97 {
98 if ( $post_type == 'page' ) {
99 return ( current_user_can('publish_pages') ) ? true : false;
100 }
101 if ( current_user_can('publish_posts') ) return true;
102 return false;
103 }
104
105 /**
106 * Get an array of all users/ids
107 * @since 1.3.0
108 * @return array
109 */
110 public function allUsers()
111 {
112 $users = get_users([
113 'fields' => ['ID', 'display_name']
114 ]);
115 return $users;
116 }
117
118 /**
119 * Get User's Visible Pages
120 * @since 1.3.4
121 * @return array - array of pages user has toggled visible
122 */
123 public function getVisiblePages()
124 {
125 return unserialize(get_user_meta(get_current_user_id(), 'np_visible_posts', true));
126 }
127
128 /**
129 * Update User's Visible Pages
130 */
131 public function updateVisiblePages($post_type, $ids)
132 {
133 $visible = $this->getVisiblePages();
134 if ( $this->integrations->plugins->wpml->installed ) $ids = $this->integrations->plugins->wpml->getAllTranslatedIds($ids);
135 $visible[$post_type] = $ids;
136 update_user_meta(
137 get_current_user_id(),
138 'np_visible_posts',
139 serialize($visible)
140 );
141 }
142 }