/** * Resets roles to WordPress defaults. * * @return void */ function backupToolReset() { check_admin_referer('capsman-reset-defaults'); require_once ABSPATH . 'wp-admin/includes/schema.php'; if (!function_exists('populate_roles')) { ak_admin_error(__('Needed function to create default roles not found!', 'capsman-enhanced')); return; } $roles = array_keys(ak_get_roles(true)); foreach ($roles as $role) { remove_role($role); } populate_roles(); $this->cm->setAdminCapability(); $msg = __('Roles and Capabilities reset to WordPress defaults', 'capsman-enhanced'); if (function_exists('pp_populate_roles')) { pp_populate_roles(); } else { // force PP to repopulate roles $pp_ver = get_option('pp_c_version', true); if ($pp_ver && is_array($pp_ver)) { $pp_ver['version'] = preg_match("/dev|alpha|beta|rc/i", $pp_ver['version']) ? '0.1-beta' : 0.1; } else { $pp_ver = array('version' => '0.1', 'db_version' => '1.0'); } update_option('pp_c_version', $pp_ver); delete_option('ppperm_added_role_caps_10beta'); } ak_admin_notify($msg); }
/** * Generates an array with the user capability names. * If user has 'administrator' role, system roles are generated. * The key is the capability and the value the created screen name. * A user cannot manage more capabilities that has himself (Except for administrators). * * @uses self::_capNamesCB() * @return void */ function generateNames() { if (current_user_can('administrator') || is_multisite() && is_super_admin()) { $this->generateSysNames(); } else { global $user_ID; $user = new WP_User($user_ID); $this->max_level = ak_caps2level($user->allcaps); $keys = array_keys($user->allcaps); $names = array_map(array($this, '_capNamesCB'), $keys); $this->capabilities = $keys ? array_combine($keys, $names) : array(); $roles = ak_get_roles(true); unset($roles['administrator']); if (defined('CME_LEGACY_USER_EDIT_FILTER') && CME_LEGACY_USER_EDIT_FILTER || !empty($_REQUEST['page']) && 'capsman' == $_REQUEST['page']) { foreach ($user->roles as $role) { // Unset the roles from capability list. unset($this->capabilities[$role]); unset($roles[$role]); // User cannot manage his roles. } } asort($this->capabilities); foreach (array_keys($roles) as $role) { $r = get_role($role); $level = ak_caps2level($r->capabilities); if ($level > $this->max_level) { unset($roles[$role]); } } $this->roles = $roles; } }
/** * Creates a new role/capability name from user input name. * Name rules are: * - 2-40 charachers lenght. * - Only letters, digits, spaces and underscores. * - Must to start with a letter. * * @param string $name Name from user input. * @return array|false An array with the name and display_name, or false if not valid $name. */ private function createNewName($name) { // Allow max 40 characters, letters, digits and spaces $name = trim(substr($name, 0, 40)); $pattern = '/^[a-zA-Z][a-zA-Z0-9 _]+$/'; if (preg_match($pattern, $name)) { $roles = ak_get_roles(); $name = strtolower($name); $name = str_replace(' ', '_', $name); if (in_array($name, $roles) || array_key_exists($name, $this->cm->capabilities)) { return false; // Already a role or capability with this name. } $display = explode('_', $name); $display = array_map('ucfirst', $display); $display = implode(' ', $display); return compact('name', 'display'); } else { return false; } }
Copyright 2009, 2010 Jordi Canals <*****@*****.**> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ $roles = ak_get_roles(true); // Available roles (translated) $dt_format = get_option('date_format') . ' | ' . get_option('time_format'); // Date-Time format ?> <div id="mini-profiles"> <?php foreach ($users as $user) { ?> <h1 class="user-name"><?php echo $user['display_name']; ?> </h1> <div class="short-profile"> <?php /* Sample to get the thumbnail instead the avatar.
/** * Counts the total users based on roles list. * * @param array|string $roles Roles names users to be counted from. Can be an string with only one role name. * @return int Total users with any of the roles. */ private function countUsersByRoles($roles = '') { global $wpdb; if (empty($roles)) { $roles = ak_get_roles(); } if (!is_array($roles)) { $roles = array($roles); } $keys = array(); foreach ($roles as $value) { $keys[] = "meta_value LIKE '%{$value}%'"; } $query = "SELECT COUNT(*) FROM {$wpdb->usermeta} INNER JOIN {$wpdb->users} " . "ON {$wpdb->usermeta}.user_id = {$wpdb->users}.id " . "WHERE meta_key='{$wpdb->prefix}capabilities' AND (" . implode(' OR ', $keys) . ")"; return $wpdb->get_var($query); }
/** * Generates an array with the user capability names. * If user has 'administrator' role, system roles are generated. * The key is the capability and the value the created screen name. * A user cannot manage more capabilities that has himself (Except for administrators). * * @uses self::_capNamesCB() * @return void */ function generateNames() { if (current_user_can('administrator') || is_super_admin()) { $this->generateSysNames(); } else { global $user_ID; $user = new WP_User($user_ID); $this->max_level = ak_caps2level($user->allcaps); $keys = array_keys($user->allcaps); $names = array_map(array($this, '_capNamesCB'), $keys); $this->capabilities = $keys ? array_combine($keys, $names) : array(); $roles = ak_get_roles(true); unset($roles['administrator']); foreach ($user->roles as $role) { // Unset the roles from capability list. unset($this->capabilities[$role]); unset($roles[$role]); // User cannot manage his roles. } asort($this->capabilities); foreach (array_keys($roles) as $role) { $r = get_role($role); $level = ak_caps2level($r->capabilities); if ($level > $this->max_level) { unset($roles[$role]); } } $this->roles = $roles; } }
/** * Updates the component settings. * @return void */ protected function componentUpdate($version) { // Delete unusued settings. $this->deleteOption('upload'); if (version_compare($version, '0.8', '<')) { // Change Widget settings to new class names. $widget = get_option('akucom_gallery_widget'); if (false !== $widget) { add_option('widget_aoc_updated_gallery', $widget); delete_option('akucom_gallery_widget'); } } if (version_compare($version, '0.10', '<')) { $admin = get_role('administrator'); $admin->add_cap('aoc_view_images'); $roles = ak_get_roles(); foreach ($roles as $name) { $role = get_role($name); if ($role->has_cap('akuc_manage_galleries')) { $role->add_cap('aoc_manage_galleries'); $role->remove_cap('akuc_manage_galleries'); } if ($role->has_cap('akuc_view_images')) { $role->add_cap('aoc_view_images'); $role->remove_cap('akuc_view_images'); } if ($role->has_cap('akuc_upload_images')) { $role->add_cap('aoc_upload_images'); $role->remove_cap('akuc_upload_images'); } } } }
/** * Update to Community 0.10 * We create the components old version swetting to fire the components update. * * @since 0.10 * * @return void */ private function update0100($version) { add_option('akucom_activity_version', $version); $options = get_option('akucom_activity'); if (false != $options) { add_option('akucom_activity_settings', $options); delete_option('akucom_activity'); } add_option('akucom_gallery_version', $version); $options = get_option('akucom_gallery'); if (false != $options) { add_option('akucom_gallery_settings', $options); delete_option('akucom_gallery'); } add_option('akucom_login_form_version', $version); $options = get_option('akucom_login-form'); if (false != $options) { add_option('akucom_login_form_settings', $options); delete_option('akucom_login-form'); } add_option('akucom_profiles_version', $version); $options = get_option('akucom_profiles'); if (false != $options) { $options['order_by'] = $options['order']['by']; $options['order_dir'] = $options['order']['type']; unset($options['order']); add_option('akucom_profiles_settings', $options); delete_option('akucom_profiles'); } $roles = ak_get_roles(); foreach ($roles as $name) { $role = get_role($name); if ($role->has_cap('akuc_unmoderated')) { $role->add_cap('aoc_unmoderated'); $role->remove_cap('akuc_unmoderated'); } if ($role->has_cap('akuc_manage_settings')) { $role->add_cap('aoc_manage_settings'); $role->remove_cap('akuc_manage_settings'); } } }
?> <?php } ?> </td> </tr> <tr> <th scope="row"><?php _e('Show only users with this roles:', $this->PID); ?> </th> <td> <?php if ($this->allowAdmin('roles')) { $roles = $this->getAllowedRoles(false); foreach (ak_get_roles(true) as $name => $label) { echo '<label for="profiles[roles][' . $name . ']"><input type="checkbox" name="profiles[roles][' . $name . ']" value="1" tabindex="1" '; checked(1, $roles[$name]); echo ' /> ' . $label . '</label><br />'; } } ?> </td> </tr> </table> </dd> </dl> <dl> <dt><?php _e('List Options', $this->PID);