function px_support_custom_role($bbp_roles) { $arr = array('spectate' => true, 'participate' => true, 'moderate' => false, 'throttle' => false, 'view_trash' => false, 'publish_forums' => false, 'edit_forums' => false, 'edit_others_forums' => false, 'delete_forums' => false, 'delete_others_forums' => false, 'read_private_forums' => true, 'read_hidden_forums' => false, 'publish_topics' => true, 'edit_topics' => true, 'edit_others_topics' => false, 'delete_topics' => false, 'delete_others_topics' => false, 'read_private_topics' => true, 'publish_replies' => true, 'edit_replies' => true, 'edit_others_replies' => false, 'delete_replies' => false, 'delete_others_replies' => false, 'read_private_replies' => true, 'manage_topic_tags' => false, 'edit_topic_tags' => false, 'delete_topic_tags' => false, 'assign_topic_tags' => true); $bbp_roles['px_wpba_customer'] = array('name' => 'WPBA Customer', 'capabilities' => bbp_get_caps_for_role($arr)); $bbp_roles['px_wpgcm_customer'] = array('name' => 'WP GCM Customer', 'capabilities' => bbp_get_caps_for_role($arr)); return $bbp_roles; }
/** * Configures Roles/Capabilities. * * @package s2Member\Roles_Caps * @since 110524RC * * @return null */ public static function config_roles() { do_action("ws_plugin__s2member_before_config_roles", get_defined_vars()); if (!apply_filters("ws_plugin__s2member_lock_roles_caps", false)) { c_ws_plugin__s2member_roles_caps::unlink_roles(); if (function_exists("bbp_get_dynamic_roles")) { foreach (bbp_get_caps_for_role(bbp_get_participant_role()) as $bbp_participant_cap => $bbp_participant_cap_is) { if ($bbp_participant_cap_is) { $bbp_participant_caps[$bbp_participant_cap] = true; } } } else { if (function_exists("bbp_get_caps_for_role")) { foreach (bbp_get_caps_for_role(bbp_get_participant_role()) as $bbp_participant_cap) { $bbp_participant_caps[$bbp_participant_cap] = true; } } } if (0 === 0) { $caps = array("read" => true, "level_0" => true); $caps = array_merge($caps, array("access_s2member_level0" => true)); $caps = !empty($bbp_participant_caps) ? array_merge($caps, $bbp_participant_caps) : $caps; if (!($role =& get_role("subscriber"))) { add_role("subscriber", "Subscriber"); $role =& get_role("subscriber"); } foreach (array_keys($caps) as $cap) { $role->add_cap($cap); } } for ($n = 1; $n <= $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n++) { for ($i = 0, $caps = array("read" => true, "level_0" => true); $i <= $n; $i++) { $caps = array_merge($caps, array("access_s2member_level" . $i => true)); } $caps = !empty($bbp_participant_caps) ? array_merge($caps, $bbp_participant_caps) : $caps; if (!($role =& get_role("s2member_level" . $n))) { add_role("s2member_level" . $n, "s2Member Level " . $n); $role =& get_role("s2member_level" . $n); } foreach (array_keys($caps) as $cap) { $role->add_cap($cap); } } $full_access_roles = array("administrator", "editor", "author", "contributor"); if (function_exists("bbp_get_caps_for_role") && !function_exists("bbp_get_dynamic_roles")) { $full_access_roles = array_merge($full_access_roles, (array) bbp_get_moderator_role()); } foreach ($full_access_roles as $role) { if ($role =& get_role($role)) { for ($n = 0; $n <= $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n++) { $role->add_cap("access_s2member_level" . $n); } } } } do_action("ws_plugin__s2member_after_config_roles", get_defined_vars()); return; }
/** * Configures Roles/Capabilities. * * @package s2Member\Roles_Caps * @since 110524RC * * @return null */ public static function config_roles() { do_action('ws_plugin__s2member_before_config_roles', get_defined_vars()); if (!apply_filters('ws_plugin__s2member_lock_roles_caps', FALSE)) { c_ws_plugin__s2member_roles_caps::unlink_roles(); if (function_exists('bbp_get_dynamic_roles') && function_exists('bbp_get_caps_for_role') && function_exists('bbp_get_participant_role')) { foreach (bbp_get_caps_for_role(bbp_get_participant_role()) as $bbp_participant_cap => $bbp_participant_cap_is) { if ($bbp_participant_cap_is) { $bbp_participant_caps[$bbp_participant_cap] = TRUE; } } } else { if (function_exists('bbp_get_caps_for_role') && function_exists('bbp_get_participant_role')) { foreach (bbp_get_caps_for_role(bbp_get_participant_role()) as $bbp_participant_cap) { $bbp_participant_caps[$bbp_participant_cap] = TRUE; } } } if (0 === 0) { $caps = array('read' => TRUE, 'level_0' => TRUE); $caps = array_merge($caps, array('access_s2member_level0' => TRUE)); $caps = !empty($bbp_participant_caps) ? array_merge($caps, $bbp_participant_caps) : $caps; if (!($role = get_role('subscriber'))) { add_role('subscriber', 'Subscriber'); $role = get_role('subscriber'); } foreach (array_keys($caps) as $cap) { $role->add_cap($cap); } } for ($n = 1; $n <= $GLOBALS['WS_PLUGIN__']['s2member']['c']['levels']; $n++) { for ($i = 0, $caps = array('read' => TRUE, 'level_0' => TRUE); $i <= $n; $i++) { $caps = array_merge($caps, array('access_s2member_level' . $i => TRUE)); } $caps = !empty($bbp_participant_caps) ? array_merge($caps, $bbp_participant_caps) : $caps; if (!($role = get_role('s2member_level' . $n))) { add_role('s2member_level' . $n, 's2Member Level ' . $n); $role = get_role('s2member_level' . $n); } foreach (array_keys($caps) as $cap) { $role->add_cap($cap); } } $full_access_roles = array('administrator', 'editor', 'author', 'contributor'); if (!function_exists('bbp_get_dynamic_roles') && function_exists('bbp_get_caps_for_role') && function_exists('bbp_get_moderator_role')) { $full_access_roles = array_merge($full_access_roles, (array) bbp_get_moderator_role()); } foreach ($full_access_roles as $role) { if ($role = get_role($role)) { for ($n = 0; $n <= $GLOBALS['WS_PLUGIN__']['s2member']['c']['levels']; $n++) { $role->add_cap('access_s2member_level' . $n); } } } } do_action('ws_plugin__s2member_after_config_roles', get_defined_vars()); }
/** * Removes capabilities from WordPress user roles. * * @since 2.0.0 bbPress (r2608) */ function bbp_remove_caps() { // Loop through available roles and remove caps foreach (bbp_get_wp_roles()->role_objects as $role) { foreach (array_keys(bbp_get_caps_for_role($role->name)) as $cap) { $role->remove_cap($cap); } } do_action('bbp_remove_caps'); }
/** * Removes capabilities from WordPress user roles. * * @since bbPress (r2608) */ function bbp_remove_caps() { global $wp_roles; // Load roles if not set if (!isset($wp_roles)) { $wp_roles = new WP_Roles(); } // Loop through available roles and remove caps foreach ($wp_roles->role_objects as $role) { foreach (bbp_get_caps_for_role($role->name) as $cap) { $role->remove_cap($cap); } } do_action('bbp_remove_caps'); }
static function user_has_cap($allcaps, $caps, $args, $user) { static $doing = false; // bypass if non-bbpress contents and avoid infinite loop if ($doing === true || !did_action('wp') || !is_bbpress()) { return $allcaps; } $bbp_allcaps = bbp_get_caps_for_role(bbp_get_keymaster_role()); $check_caps = array_intersect(array_values($caps), array_keys($bbp_allcaps)); if (!$check_caps && in_array('upload_files', $caps)) { $check_caps = array('upload_files'); } // bypass non bbpress caps if (!$check_caps || in_array('keep_gate', $check_caps)) { return $allcaps; } $doing = true; if (!($forum_id = bbp_get_forum_id())) { $doing = false; return $allcaps; } // Give all modorator capabilities to optional forum moderators per forum $moderators = bbpresskr()->forum_option('moderators', $forum_id); if (in_array($user->ID, $moderators) && ($new_caps = bbp_get_caps_for_role(bbp_get_moderator_role()))) { // remove all bbpress capabilities and append for asigned role only $_allcaps = array_diff_assoc($allcaps, $bbp_allcaps); $allcaps = array_merge($_allcaps, $new_caps); $allcaps['upload_files'] = true; } // In case we use usermeta for forum moderator setting /*$metakey = "forum_role_{$forum_id}"; // Dobule check forum role still exists. Role may excluded by plugin or updates. if ( isset( $user->$metakey ) && ($new_caps = bbp_get_caps_for_role( $user->$metakey )) ) { // remove all bbpress capabilities and append for asigned role only $_allcaps = array_diff_assoc( $allcaps, $bbp_allcaps ); $allcaps = array_merge( $_allcaps, $new_caps ); $allcaps['upload_files'] = true; }*/ $doing = false; return $allcaps; }
/** * Returns the array of forum roles for the site. * * "Owner" is an Administrator, with no restrictions. "Moderator" is self explanatory. "Agent" is just a regular user. "No Access" is blocked from seeing anything on the forum. * * @return array Array of forum roles. */ function bhr_forum_role_names() { return array(bbp_get_keymaster_role() => array('name' => 'Owner', 'capabilities' => bbp_get_caps_for_role(bbp_get_keymaster_role())), bbp_get_moderator_role() => array('name' => 'Moderator', 'capabilities' => bbp_get_caps_for_role(bbp_get_moderator_role())), bbp_get_participant_role() => array('name' => 'Agent', 'capabilities' => bbp_get_caps_for_role(bbp_get_participant_role())), bbp_get_blocked_role() => array('name' => 'No Access', 'capabilities' => bbp_get_caps_for_role(bbp_get_blocked_role()))); }
/** * Add the default role and mapped bbPress caps to the current user if needed * * This function will bail if the forum is not global in a multisite * installation of WordPress, or if the user is marked as spam or deleted. * * @since bbPress (r3380) * * @uses bbp_allow_global_access() * @uses bbp_is_user_inactive() * @uses is_user_logged_in() * @uses current_user_can() * @uses get_option() * @uses bbp_get_caps_for_role() * * @return If not multisite, not global, or user is deleted/spammed */ function bbp_global_access_role_mask() { // Bail if not multisite or forum is not global if (!bbp_allow_global_access()) { return; } // Bail if user is marked as spam or is deleted if (bbp_is_user_inactive()) { return; } // Normal user is logged in but has no caps if (is_user_logged_in() && !current_user_can('read')) { // Assign user the minimal participant role to map caps to $default_role = bbp_get_participant_role(); // Get bbPress caps for the default role $caps_for_role = bbp_get_caps_for_role($default_role); // Set all caps to true foreach ($caps_for_role as $cap) { $mapped_meta_caps[$cap] = true; } // Add 'read' cap just in case $mapped_meta_caps['read'] = true; $mapped_meta_caps['bbp_masked'] = true; // Allow global access caps to be manipulated $mapped_meta_caps = apply_filters('bbp_global_access_mapped_meta_caps', $mapped_meta_caps); // Assign the role and mapped caps to the current user $bbp = bbpress(); $bbp->current_user->roles[0] = $default_role; $bbp->current_user->caps = $mapped_meta_caps; $bbp->current_user->allcaps = $mapped_meta_caps; } }
/** * return array with WordPress user roles * * @global WP_Roles $wp_roles * @global type $wp_user_roles * @return array */ public function get_user_roles() { global $wp_roles; if (!isset($wp_roles)) { $wp_roles = new WP_Roles(); } if (function_exists('bbp_filter_blog_editable_roles')) { // bbPress plugin is active $this->roles = bbp_filter_blog_editable_roles($wp_roles->roles); // exclude bbPress roles $bbp_full_caps = bbp_get_caps_for_role(bbp_get_keymaster_role()); // exclude capabilities automatically added by bbPress bbp_dynamic_role_caps() and not bbPress related: read, level_0, all s2Member levels, e.g. access_s2member_level_0, etc. $built_in_wp_caps = $this->get_built_in_wp_caps(); $bbp_only_caps = array(); foreach ($bbp_full_caps as $bbp_cap => $val) { if (isset($built_in_wp_caps[$bbp_cap]) || substr($bbp_cap, 0, 15) == 'access_s2member') { continue; } $bbp_only_caps[$bbp_cap] = $val; } // remove bbPress dynamically created capabilities from WordPress persistent roles in order to not save them to database with any role update $cap_removed = false; foreach ($bbp_only_caps as $bbp_cap => $val) { foreach ($this->roles as &$role) { if (isset($role['capabilities'][$bbp_cap])) { unset($role['capabilities'][$bbp_cap]); $cap_removed = true; } } } } else { $this->roles = $wp_roles->roles; } if (is_array($this->roles) && count($this->roles) > 0) { asort($this->roles); } return $this->roles; }
/** * Fetch a filtered list of forum roles that the current user is * allowed to have. * * Simple function who's main purpose is to allow filtering of the * list of forum roles so that plugins can remove inappropriate ones depending * on the situation or user making edits. * * Specifically because without filtering, anyone with the edit_users * capability can edit others to be administrators, even if they are * only editors or authors. This filter allows admins to delegate * user management. * * @since bbPress (r4284) * * @return array */ function bbp_get_dynamic_roles() { return (array) apply_filters('bbp_get_dynamic_roles', array(bbp_get_keymaster_role() => array('name' => __('Keymaster', 'bbpress'), 'capabilities' => bbp_get_caps_for_role(bbp_get_keymaster_role())), bbp_get_moderator_role() => array('name' => __('Moderator', 'bbpress'), 'capabilities' => bbp_get_caps_for_role(bbp_get_moderator_role())), bbp_get_participant_role() => array('name' => __('Participant', 'bbpress'), 'capabilities' => bbp_get_caps_for_role(bbp_get_participant_role())), bbp_get_spectator_role() => array('name' => __('Spectator', 'bbpress'), 'capabilities' => bbp_get_caps_for_role(bbp_get_spectator_role())), bbp_get_blocked_role() => array('name' => __('Blocked', 'bbpress'), 'capabilities' => bbp_get_caps_for_role(bbp_get_blocked_role())))); }
function ure_getUserRoles() { global $wp_roles, $wpdb; if (!isset($wp_roles)) { $wp_roles = new WP_Roles(); } if (function_exists('bbp_filter_blog_editable_roles')) { // bbPress plugin is active $ure_roles = bbp_filter_blog_editable_roles($wp_roles->roles); // exclude bbPress roles $bbp_full_caps = bbp_get_caps_for_role(bbp_get_keymaster_role()); // remove bbPress dinamically created capabilities from WordPress persistent roles in case we caught some with previouse URE version $cap_removed = false; foreach ($bbp_full_caps as $bbp_cap => $val) { foreach ($ure_roles as &$role) { if (isset($role['capabilities'][$bbp_cap])) { unset($role['capabilities'][$bbp_cap]); $cap_removed = true; } } } if ($cap_removed) { // save changes to database $option_name = $wpdb->prefix . 'user_roles'; update_option($option_name, $ure_roles); } } else { $ure_roles = $wp_roles->roles; } if (is_array($ure_roles) && count($ure_roles) > 0) { asort($ure_roles); } return $ure_roles; }
/** * Initialize forum-specific roles * * @since 2.6.0 */ public function roles_init() { // Get role IDs $keymaster = bbp_get_keymaster_role(); $moderator = bbp_get_moderator_role(); $participant = bbp_get_participant_role(); $spectator = bbp_get_spectator_role(); $blocked = bbp_get_blocked_role(); // Build the roles into one useful array $this->roles[$keymaster] = new WP_Role('Keymaster', bbp_get_caps_for_role($keymaster)); $this->roles[$moderator] = new WP_Role('Moderator', bbp_get_caps_for_role($moderator)); $this->roles[$participant] = new WP_Role('Participant', bbp_get_caps_for_role($participant)); $this->roles[$spectator] = new WP_Role('Spectator', bbp_get_caps_for_role($spectator)); $this->roles[$blocked] = new WP_Role('Blocked', bbp_get_caps_for_role($blocked)); }
function ntwb_bbpress_custom_role_names() { return array(bbp_get_keymaster_role() => array('name' => 'Captain', 'capabilities' => bbp_get_caps_for_role(bbp_get_keymaster_role())), bbp_get_moderator_role() => array('name' => 'Veteran', 'capabilities' => bbp_get_caps_for_role(bbp_get_moderator_role())), bbp_get_participant_role() => array('name' => 'Member', 'capabilities' => bbp_get_caps_for_role(bbp_get_participant_role())), bbp_get_spectator_role() => array('name' => 'Guest', 'capabilities' => bbp_get_caps_for_role(bbp_get_spectator_role())), bbp_get_blocked_role() => array('name' => 'Blocked', 'capabilities' => bbp_get_caps_for_role(bbp_get_blocked_role()))); }
/** * Get full list user capabilities created by bbPress * * @return array */ public function get_caps() { $caps = array_keys(bbp_get_caps_for_role(bbp_get_keymaster_role())); return $caps; }