PluginProbe ʕ •ᴥ•ʔ
PublishPress Capabilities – User Role Editor, Access Permissions, User Capabilities, Admin Menus / 1.7
PublishPress Capabilities – User Role Editor, Access Permissions, User Capabilities, Admin Menus v1.7
2.45.0 2.44.0 trunk 1.10 1.10.1 1.4.1 1.4.10 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5 1.5.1 1.5.10 1.5.11 1.5.2 1.5.3 1.5.4 1.5.5 1.5.7 1.5.8 1.5.9 1.6 1.6.1 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.8.1 1.9 1.9.10 1.9.12 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.9 2.0 2.0.2 2.0.3 2.1 2.1.1 2.10.0 2.10.1 2.10.2 2.10.3 2.11.1 2.12.1 2.12.2 2.13.0 2.14.0 2.15.0 2.16.0 2.17.0 2.18.0 2.18.2 2.19.0 2.19.1 2.19.2 2.2 2.2.1 2.20.0 2.21.0 2.22.0 2.23.0 2.3 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.30.0 2.31.0 2.32.0 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.40.0 2.41.0 2.42.0 2.43.0 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.7.0 2.7.1 2.8.0 2.8.1 2.9.0 2.9.1
capability-manager-enhanced / framework / lib / users.php
capability-manager-enhanced / framework / lib Last commit date
formating.php 10 years ago users.php 12 years ago
users.php
109 lines
1 <?php
2 /**
3 * Users, Roles and Capabilities related functions.
4 *
5 * @version $Rev: 203758 $
6 * @author Jordi Canals
7 * @copyright Copyright (C) 2008, 2009, 2010 Jordi Canals
8 * @license GNU General Public License version 2
9 * @link http://alkivia.org
10 * @package Alkivia
11 * @subpackage Framework
12 *
13
14 Copyright 2008, 2009, 2010 Jordi Canals <devel@jcanals.cat>
15
16 This program is free software; you can redistribute it and/or
17 modify it under the terms of the GNU General Public License
18 version 2 as published by the Free Software Foundation.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 */
28
29 /**
30 * Returns all valid roles.
31 * The returned list can be translated or not.
32 *
33 * @uses apply_filters() Calls the 'alkivia_roles_translate' hook on translated roles array.
34 * @since 0.5
35 *
36 * @param boolean $translate If the returned roles have to be translated or not.
37 * @return array All defined roles. If translated, the key is the role name and value is the translated role.
38 */
39 function ak_get_roles( $translate = false ) {
40 global $wp_roles;
41 if ( ! isset( $wp_roles ) ) {
42 $wp_roles = new WP_Roles();
43 }
44
45 $roles = $wp_roles->get_names();
46 if ( $translate ) {
47 foreach ($roles as $k => $r) {
48 $roles[$k] = _x($r, 'User role');
49 }
50 asort($roles);
51 return apply_filters('alkivia_roles_translate', $roles);
52 } else {
53 $roles = array_keys($roles);
54 asort($roles);
55 return $roles;
56 }
57 }
58
59 /**
60 * Generates the caps names from user level.
61 *
62 * @since 0.5
63 *
64 * @param int $level Level to convert to caps
65 * @return array Generated caps
66 */
67 function ak_level2caps( $level ) {
68 $caps = array();
69 $level = min(10, intval($level));
70
71 for ( $i = $level; $i >= 0; $i--) {
72 $caps["level_{$i}"] = true;
73 }
74
75 return $caps;
76 }
77
78 /**
79 * Finds the proper level from a capabilities list.
80 *
81 * @since 0.5
82 *
83 * @uses _ak_level_reduce()
84 * @param array $caps List of capabilities.
85 * @return int Level found, if no level found, will return 0.
86 */
87 function ak_caps2level( $caps ) {
88 $level = array_reduce( array_keys( $caps ), '_ak_caps2level_CB', 0);
89 return $level;
90 }
91
92 /**
93 * Callback function to find the level from caps.
94 * Taken from WordPress 2.7.1
95 *
96 * @since 0.5
97 * @access private
98 *
99 * @return int level Level found.
100 */
101 function _ak_caps2level_CB( $max, $item ) {
102 if ( preg_match( '/^level_(10|[0-9])$/i', $item, $matches ) ) {
103 $level = intval( $matches[1] );
104 return max( $max, $level );
105 } else {
106 return $max;
107 }
108 }
109