function wuw_deactivate() { $admin_role = get_role('administrator'); if ($admin_role->has_cap('whats_up_wordpress') === true) { $admin_role->remove_cap('whats_up_wordpress'); } }
/** * Filter on `user_has_cap` to explicitly deny caps if there are conflicting caps when a * user has multiple roles. WordPress doesn't consistently handle two or more roles that * have the same capability but a conflict between being granted or denied. Core WP * merges the role caps so that the last role the user has will take precedence. This * has the potential for granting permission for things that a user shouldn't have * permission to do. * * @since 1.0.0 * @access public * @param array $allcaps * @param array $caps * @param array $args * @param object $user * @return array */ function members_user_has_cap_filter($allcaps, $caps, $args, $user) { // If the user doesn't have more than one role, bail. if (1 >= count((array) $user->roles)) { return $allcaps; } // Get the denied caps. $denied_caps = array_keys($allcaps, false); // Loop through the user's roles and find any denied caps. foreach ((array) $user->roles as $role) { // Get the role object. $role_obj = get_role($role); // If we have an object, merge it's denied caps. if (!is_null($role_obj)) { $denied_caps = array_merge($denied_caps, array_keys($role_obj->capabilities, false)); } } // If there are any denied caps, make sure they take precedence. if ($denied_caps) { foreach ($denied_caps as $denied_cap) { $allcaps[$denied_cap] = false; } } // Return all the user caps. return $allcaps; }
/** * Remove custom user capability to a given role. * * @param $roleKey * @param $cap * * @since 1.0.0 */ public function removeCustomCapability($roleKey, $cap) { do_action('wwp_action_before_remove_custom_cap', $roleKey, $cap); $role = get_role($roleKey); $role->remove_cap($cap); do_action('wwp_action_after_remove_custom_cap', $roleKey, $cap); }
/** * Runs checks for necessary config options. * * @return void Method does not return. */ public function run_checks() { $role = get_role('administrator'); $current_user = get_userdata(get_current_user_id()); if (!is_object($role) || !is_object($current_user) || !$role->has_cap('manage_ai1ec_options') || defined('DOING_AJAX') && DOING_AJAX) { return; } global $plugin_page; $settings = $this->_registry->get('model.settings'); $notification = $this->_registry->get('notification.admin'); $notifications = array(); // check if is set calendar page if (!$settings->get('calendar_page_id')) { $msg = Ai1ec_I18n::__('Select an option in the <strong>Calendar page</strong> dropdown list.'); $notifications[] = $msg; } if ($plugin_page !== AI1EC_PLUGIN_NAME . '-settings' && !empty($notifications)) { if ($current_user->has_cap('manage_ai1ec_options')) { $msg = sprintf(Ai1ec_I18n::__('The plugin is installed, but has not been configured. <a href="%s">Click here to set it up now »</a>'), admin_url(AI1EC_SETTINGS_BASE_URL)); $notification->store($msg, 'updated', 2, array(Ai1ec_Notification_Admin::RCPT_ADMIN)); } else { $msg = Ai1ec_I18n::__('The plugin is installed, but has not been configured. Please log in as an Administrator to set it up.'); $notification->store($msg, 'updated', 2, array(Ai1ec_Notification_Admin::RCPT_ALL)); } return; } foreach ($notifications as $msg) { $notification->store($msg, 'updated', 2, array(Ai1ec_Notification_Admin::RCPT_ADMIN)); } }
function __construct() { add_filter('user_contactmethods', array($this, 'additional_contact_fields'), 10, 1); $role = get_role('editor'); $role->add_cap('edit_theme_options'); add_action('admin_menu', array($this, 'custom_admin_menu')); }
public function capability_filter($allcaps, $cap, $args) { $Admin = get_role('admin'); $Contributor = get_role('contributor'); $Contributor->add_cap('upload_files'); return $allcaps; }
/** * Removes our settings user capabilities * * @return void */ public function remove_capabilities() { // Get user role $role = get_role('administrator'); // Remove the capability $role->remove_cap('easingslider_manage_settings'); }
public function get_role($output = 'name') { if ('object' === $output) { return get_role($this->item->roles[0]); } return $this->item->roles[0]; }
function wps_admin_bar() { global $wp_admin_bar; $wp_admin_bar->remove_menu('wp-logo'); $wp_admin_bar->remove_menu('about'); $wp_admin_bar->remove_menu('wporg'); $wp_admin_bar->remove_menu('documentation'); $wp_admin_bar->remove_menu('support-forums'); $wp_admin_bar->remove_menu('feedback'); $wp_admin_bar->remove_menu('view-site'); $wp_admin_bar->remove_menu('comments'); //$wp_admin_bar->remove_menu('new-post'); $wp_admin_bar->remove_menu('new-media'); $wp_admin_bar->remove_menu('new-link'); //check if we're using posts $roots_option = roots_get_global_options(); $show_posts = $roots_option['roots_show_posts']; $role = get_role('editor'); if ($show_posts == 'no') { $wp_admin_bar->remove_menu('new-post'); $role->remove_cap('edit_posts'); } else { $role->add_cap('edit_posts'); } }
function webbird_permissions_gravity_forms() { $role = get_role('editor'); $role->add_cap('gform_full_access'); $role = get_role('shop_manager'); $role->add_cap('gform_full_access'); }
function removeProcess() { if (is_admin()) { $filename = dirname(__FILE__) . DS . 'uninstall.sql'; $handle = fopen($filename, 'r'); $query = fread($handle, filesize($filename)); fclose($handle); $modelObj =& WYSIJA::get('user', 'model'); $queries = str_replace('DROP TABLE `', 'DROP TABLE `[wysija]', $query); $queries = explode('-- QUERY ---', $queries); $modelWysija = new WYSIJA_model(); global $wpdb; foreach ($queries as $query) { $modelWysija->query($query); } delete_option('wysija'); WYSIJA::update_option('wysija_reinstall', 1); global $wp_roles; foreach ($wp_roles->roles as $rolek => $roled) { if ($rolek == 'administrator') { continue; } $role = get_role($rolek); $arr = array('wysija_newsletters', 'wysija_subscribers', 'wysija_subscriwidget', 'wysija_config'); foreach ($arr as $arrkey) { $role->remove_cap($arrkey); } } return true; } return false; }
function add_theme_caps() { if (!get_role('member')) { $capabilities = array('create_announcements' => true, 'edit_others_announcements' => true, 'delete_pages' => true, 'delete_published_pages' => true, 'edit_pages' => true, 'edit_others_pages' => true, 'edit_published_pages' => true, 'publish_pages' => true, 'gravityforms_edit_forms' => true, 'gravityforms_view_entries' => true, 'read' => true, 'manage_categories' => true, 'delete_posts' => true, 'delete_published_posts' => true, 'edit_posts' => true, 'edit_published_posts' => true, 'edit_others_posts' => true, 'publish_posts' => true); add_role('member', 'Club Member', $capabilities); } $editor = get_role('editor'); if (!$editor->capabilities['create_announcements']) { $editor->add_cap('edit_home_page'); $editor->add_cap('create_announcements'); $editor->add_cap('create_mailchimp_campaigns'); $editor->add_cap('create_speaker_programs'); $editor->add_cap('edit_speaker_programs'); $editor->add_cap('delete_others_announcements'); $editor->add_cap('edit_others_announcements'); } $admin = get_role('administrator'); if (!$admin->capabilities['create_announcements']) { $admin->add_cap('edit_home_page'); $admin->add_cap('create_announcements'); $admin->add_cap('create_mailchimp_campaigns'); $admin->add_cap('create_speaker_programs'); $admin->add_cap('edit_speaker_programs'); $admin->add_cap('delete_others_announcements'); $admin->add_cap('edit_others_announcements'); } }
function trav_after_setup_theme() { add_role('trav_busowner', 'Business Owner'); $role = get_role('trav_busowner'); $role->add_cap('read'); $role->add_cap('upload_files'); }
/** * Create a user * * @param array $args * @param array $assoc_args **/ public function create($args, $assoc_args) { global $blog_id; $user_login = $args[0]; $user_email = $args[1]; if (!$user_login || !$user_email) { WP_CLI::error("Login and email required (see 'wp user help')."); } $defaults = array('role' => get_option('default_role'), 'user_pass' => wp_generate_password(), 'user_registered' => strftime("%F %T", time()), 'display_name' => false); extract(wp_parse_args($assoc_args, $defaults), EXTR_SKIP); if ('none' == $role) { $role = false; } elseif (is_null(get_role($role))) { WP_CLI::error("Invalid role."); } $user_id = wp_insert_user(array('user_email' => $user_email, 'user_login' => $user_login, 'user_pass' => $user_pass, 'user_registered' => $user_registered, 'display_name' => $display_name, 'role' => $role)); if (is_wp_error($user_id)) { WP_CLI::error($user_id); } else { if (false === $role) { delete_user_option($user_id, 'capabilities'); delete_user_option($user_id, 'user_level'); } } WP_CLI::success("Created user {$user_id}."); }
function stats_load() { Jetpack::enable_module_configurable(__FILE__); Jetpack::module_configuration_load(__FILE__, 'stats_configuration_load'); Jetpack::module_configuration_head(__FILE__, 'stats_configuration_head'); Jetpack::module_configuration_screen(__FILE__, 'stats_configuration_screen'); // Generate the tracking code after wp() has queried for posts. add_action('template_redirect', 'stats_template_redirect', 1); add_action('wp_head', 'stats_admin_bar_head', 100); add_action('jetpack_admin_menu', 'stats_admin_menu'); add_action('wp_dashboard_setup', 'stats_register_dashboard_widget'); // Tell HQ about changed settings add_action('update_option_home', 'stats_update_blog'); add_action('update_option_siteurl', 'stats_update_blog'); add_action('update_option_blogname', 'stats_update_blog'); add_action('update_option_blogdescription', 'stats_update_blog'); add_action('update_option_timezone_string', 'stats_update_blog'); add_action('add_option_timezone_string', 'stats_update_blog'); add_action('update_option_gmt_offset', 'stats_update_blog'); add_action('update_option_page_on_front', 'stats_update_blog'); add_action('update_option_permalink_structure', 'stats_update_blog'); add_action('update_option_category_base', 'stats_update_blog'); add_action('update_option_tag_base', 'stats_update_blog'); // Tell HQ about changed posts add_action('save_post', 'stats_update_post', 10, 1); add_filter('jetpack_xmlrpc_methods', 'stats_xmlrpc_methods'); foreach (stats_get_option('roles') as $role) { $role = get_role($role); if ($role) { $role->add_cap('view_stats'); } } }
public function add_roles($roles, $perms) { $obj = $this; add_action('after_setup_theme', function () use($obj, $roles, $perms) { //give default capabilties $permissions = array(); foreach ($obj->post_type_capabilities as $key => $value) { $permissions[$value] = true; } //add passed capabilities if (!empty($perms)) { foreach ($perms as $p) { $permissions[$p] = true; } } if (!empty($roles)) { foreach ($roles as $role) { $r = get_role($role); //returns role object foreach ($permissions as $key => $value) { $r->add_cap($key); //adds capabilities (permissions) to role } } } }); }
/** * Add our master role, "Premise Member". * * @since 0.1.0 */ function accesspress_create_role() { if (get_role('premise_member')) { return; } add_role('premise_member', __('Premise Member', 'premise'), array('access_membership' => true)); }
/** * Remove existing permissions/capabilities to a specific role * * @param string $role * @param string $cap */ function remove_capability($role, $cap) { $role_obj = get_role($role); // get the the role object $role_obj->remove_cap($cap); // add $cap capability to this role object }
/** * Static function for plugin activation. * * @return void */ public function do_activate() { global $wp_version; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; // Check for capability if (!current_user_can('activate_plugins')) { wp_die(__('Sorry, you do not have suffient permissions to activate this plugin.', MP_DOMAIN)); } // Get the capabilities for the administrator $role = get_role('administrator'); // Must have admin privileges in order to activate. if (empty($role)) { wp_die(__('Sorry, you must be an Administrator in order to use Manga+Press', MP_DOMAIN)); } if (version_compare($wp_version, '3.0', '<=')) { wp_die('Sorry, only WordPress 3.0 and later are supported.' . ' Please upgrade to WordPress 3.0', 'Wrong Version'); } self::$_version = strval(get_option('mangapress_ver')); // version_compare will still evaluate against an empty string // so we have to tell it not to. if (version_compare(self::$_version, MP_VERSION, '<') && !(self::$_version == '')) { add_option('mangapress_upgrade', 'yes', '', 'no'); } elseif (self::$_version == '') { add_option('mangapress_ver', MP_VERSION, '', 'no'); add_option('mangapress_options', serialize(MangaPress_Options::get_default_options()), '', 'no'); } $this->_bootstrap = MangaPress_Bootstrap::get_instance(); $this->_bootstrap->init(); $this->after_plugin_activation(); flush_rewrite_rules(false); }
function frontier_post_set_cap() { include FRONTIER_POST_DIR . "/include/frontier_post_defaults.php"; $fps_saved_capabilities = frontier_post_get_capabilities(); // Reinstate roles $fps_roles = new WP_Roles(); $role_list = $fps_roles->get_names(); foreach ($role_list as $key => $item) { $xrole = get_role($key); $tmp_caplist = $fps_saved_capabilities[$key]; foreach ($tmp_caplist as $tmp_cap => $tmp_value) { $fps_cap_name = $tmp_cap; // Check that the name is a capability (not editor or category) if (array_key_exists($fps_cap_name, $fp_capability_list) == true) { if ($tmp_value == "true") { $xrole->add_cap($tmp_cap); } else { $xrole->remove_cap($tmp_cap); } $xrole->remove_cap('frontier_post_' . $tmp_cap); } else { } } // end tmp_caplist } // end role_list }
/** * Removes our "extensions" page user capabilities * * @return void */ public function remove_capabilities() { // Get user role $role = get_role('administrator'); // Remove the capability $role->remove_cap('easingslider_discover_extensions'); }
public static function add_capability() { $role = get_role('administrator'); if (!empty($role)) { $role->add_cap('fbm_edit_background'); } }
function get_actor($actor_id, $actor_type = null, $args = null) { if ($actor_type == null) { $actor_type = 'user'; } $object = null; if ($actor_id != null) { switch ($actor_type) { case 'user': $object = get_userdata($actor_id); if ($object == false) { $object = null; } break; case 'role': $object = get_role($actor_id); if ($object == false) { $object = null; } break; } } if ($object != null) { $factory = $this->get_registry()->get_utility('I_Component_Factory'); $actor = $factory->create('wordpress_security_actor', $actor_type); $entity_props = array('type' => $actor_type, 'id' => $actor_id); $actor->set_entity($object, $entity_props); return $actor; } return $this->object->get_guest_actor(); }
/** * Generate users * * @param array $args * @param array $assoc_args **/ public function users($args, $assoc_args) { global $blog_id; $defaults = array('count' => 100, 'role' => get_option('default_role')); extract(wp_parse_args($assoc_args, $defaults), EXTR_SKIP); if ('none' == $role) { $role = false; } elseif (is_null(get_role($role))) { WP_CLI::warning("invalid role."); exit; } $user_count = count_users(); $total = $user_count['total_users']; $limit = $count + $total; $notify = new \cli\progress\Bar('Generating users', $count); for ($i = $total; $i < $limit; $i++) { $login = sprintf('user_%d_%d', $blog_id, $i); $name = "User {$i}"; $user_id = wp_insert_user(array('user_login' => $login, 'user_pass' => $login, 'nickname' => $name, 'display_name' => $name, 'role' => $role)); if (false === $role) { delete_user_option($user_id, 'capabilities'); delete_user_option($user_id, 'user_level'); } $notify->tick(); } $notify->finish(); }
function draw_user_list() { $users = get_users(); ?> <table class="userlist table table-condensed table-bordered"> <tr> <th>Last Name</th> <th>First Name</th> <th>Username</th> </tr> <?php while ($row = $users->fetch_array()) { $row['role'] = get_role($row['user_id']); echo '<tr class="userlist '; echo 'userlist-' . $row['role']; if ($row['inactive']) { echo ' userlist-inactive'; } echo '" onclick="openEdit(' . $row['user_id'] . ')">'; echo '<td style="cursor:pointer;">' . $row['lname'] . "</td>"; echo '<td style="cursor:pointer;">' . $row['fname'] . "</td>"; echo '<td style="cursor:pointer;">' . $row['username'] . "</td>"; echo '</tr>'; } ?> </table> <?php }
function add_capability() { // get the the role object $editor = get_role('editor'); // add $cap capability to this role object $editor->add_cap('manage_options'); }
/** * Add initial ST options in DB, init roles/permissions * * @return void * @author Amaury Balmer */ public static function activation() { // Put default options $options_from_table = get_option(STAGS_OPTIONS_NAME); if ($options_from_table == false) { $options = (array) (include STAGS_DIR . '/inc/helper.options.default.php'); add_option(STAGS_OPTIONS_NAME, $options); unset($options); } // Init roles if (function_exists('get_role')) { $role = get_role('administrator'); if ($role != null && !$role->has_cap('simple_tags')) { $role->add_cap('simple_tags'); } if ($role != null && !$role->has_cap('admin_simple_tags')) { $role->add_cap('admin_simple_tags'); } $role = get_role('editor'); if ($role != null && !$role->has_cap('simple_tags')) { $role->add_cap('simple_tags'); } // Clean var unset($role); } }
/** * Change what Editor users can see */ function sticky_modify_editor_roles() { // get the the role object $role_object = get_role('editor'); // add $cap capability to this role object $role_object->add_cap('edit_theme_options'); }
function setup_read_touch_easy_seo_caps() { $roles = touch_easy_seo_touch_get_lower_roles(); $allowed_roles = get_field('allowed_roles_for_touch_seo', 'options'); // Do not allow rights modification of administrator and current role if (isset($roles["administrator"])) { unset($roles["administrator"]); } // ALWAYS ALLOW ADMINISTRATORS TO VIEW THE PLUGIN $adminRole = get_role("administrator"); if (current_user_can("administrator") && !current_user_can("read_touch-easy-seo")) { $adminRole->add_cap("read_touch-easy-seo"); } if (current_user_can("administrator") && !current_user_can("read_touch-easy-seo-settings")) { $adminRole->add_cap("read_touch-easy-seo-settings"); } foreach ($roles as $role_name => $role_info) { $role = get_role($role_name); if ($allowed_roles != '' && in_array($role_name, $allowed_roles) && !$role->has_cap("read_touch-easy-seo")) { $role->add_cap("read_touch-easy-seo"); } elseif ($allowed_roles != '' && $role->has_cap("read_touch-easy-seo") && !in_array($role_name, $allowed_roles)) { $role->remove_cap("read_touch-easy-seo"); } elseif ($allowed_roles == '' && $role->has_cap("read_touch-easy-seo")) { $role->remove_cap("read_touch-easy-seo"); } } }
function add_theme_caps() { // Allow subscribers to see Private posts and pages $subRole = get_role('subscriber'); $subRole->add_cap('read_private_posts'); $subRole->add_cap('read_private_pages'); }