예제 #1
0
/**
 * Returns an array of capabilities based on the role that is being requested.
 *
 * @since 2.0.0 bbPress (r2994)
 *
 * @todo Map all of these and deprecate
 *
 * @param string $role Optional. Defaults to The role to load caps for
 * @uses apply_filters() Allow return value to be filtered
 *
 * @return array Capabilities for $role
 */
function bbp_get_caps_for_role($role = '')
{
    // Which role are we looking for?
    switch ($role) {
        // Keymaster
        case bbp_get_keymaster_role():
            $caps = array('keep_gate' => true, 'spectate' => true, 'participate' => true, 'moderate' => true, 'throttle' => true, 'view_trash' => true, 'assign_moderators' => true, 'publish_forums' => true, 'edit_forums' => true, 'edit_others_forums' => true, 'delete_forums' => true, 'delete_others_forums' => true, 'read_private_forums' => true, 'read_hidden_forums' => true, 'publish_topics' => true, 'edit_topics' => true, 'edit_others_topics' => true, 'delete_topics' => true, 'delete_others_topics' => true, 'read_private_topics' => true, 'publish_replies' => true, 'edit_replies' => true, 'edit_others_replies' => true, 'delete_replies' => true, 'delete_others_replies' => true, 'read_private_replies' => true, 'manage_topic_tags' => true, 'edit_topic_tags' => true, 'delete_topic_tags' => true, 'assign_topic_tags' => true);
            break;
            // Moderator
        // Moderator
        case bbp_get_moderator_role():
            $caps = array('spectate' => true, 'participate' => true, 'moderate' => true, 'throttle' => true, 'view_trash' => true, 'assign_moderators' => true, 'publish_forums' => true, 'edit_forums' => true, 'read_private_forums' => true, 'read_hidden_forums' => true, 'publish_topics' => true, 'edit_topics' => true, 'edit_others_topics' => true, 'delete_topics' => true, 'delete_others_topics' => true, 'read_private_topics' => true, 'publish_replies' => true, 'edit_replies' => true, 'edit_others_replies' => true, 'delete_replies' => true, 'delete_others_replies' => true, 'read_private_replies' => true, 'manage_topic_tags' => true, 'edit_topic_tags' => true, 'delete_topic_tags' => true, 'assign_topic_tags' => true);
            break;
            // Spectators can only read
        // Spectators can only read
        case bbp_get_spectator_role():
            $caps = array('spectate' => true);
            break;
            // Explicitly blocked
        // Explicitly blocked
        case bbp_get_blocked_role():
            $caps = array('spectate' => false, 'participate' => false, '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' => false, 'read_hidden_forums' => false, 'publish_topics' => false, 'edit_topics' => false, 'edit_others_topics' => false, 'delete_topics' => false, 'delete_others_topics' => false, 'read_private_topics' => false, 'publish_replies' => false, 'edit_replies' => false, 'edit_others_replies' => false, 'delete_replies' => false, 'delete_others_replies' => false, 'read_private_replies' => false, 'manage_topic_tags' => false, 'edit_topic_tags' => false, 'delete_topic_tags' => false, 'assign_topic_tags' => false);
            break;
            // Participant/Default
        // Participant/Default
        case bbp_get_participant_role():
        default:
            $caps = array('spectate' => true, 'participate' => true, 'read_private_forums' => true, 'publish_topics' => true, 'edit_topics' => true, 'publish_replies' => true, 'edit_replies' => true, 'assign_topic_tags' => true);
            break;
    }
    return apply_filters('bbp_get_caps_for_role', $caps, $role);
}
예제 #2
0
 public function setUp()
 {
     parent::setUp();
     $this->old_current_user = get_current_user_id();
     $this->set_current_user($this->factory->user->create(array('role' => 'administrator')));
     $this->keymaster_id = get_current_user_id();
     bbp_set_user_role($this->keymaster_id, bbp_get_keymaster_role());
 }
예제 #3
0
 /**
  * @covers ::bbp_move_topic_handler
  */
 public function test_bbp_move_topic_handler()
 {
     $old_current_user = 0;
     $this->old_current_user = get_current_user_id();
     $this->set_current_user($this->factory->user->create(array('role' => 'administrator')));
     $this->keymaster_id = get_current_user_id();
     bbp_set_user_role($this->keymaster_id, bbp_get_keymaster_role());
     $old_forum_id = $this->factory->forum->create();
     $topic_id = $this->factory->topic->create(array('post_parent' => $old_forum_id, 'topic_meta' => array('forum_id' => $old_forum_id)));
     $reply_id = $this->factory->reply->create(array('post_parent' => $topic_id, 'reply_meta' => array('forum_id' => $old_forum_id, 'topic_id' => $topic_id)));
     // Topic post parent
     $topic_parent = wp_get_post_parent_id($topic_id);
     $this->assertSame($old_forum_id, $topic_parent);
     // Forum meta
     $this->assertSame(1, bbp_get_forum_topic_count($old_forum_id, true, true));
     $this->assertSame(1, bbp_get_forum_reply_count($old_forum_id, true, true));
     $this->assertSame($topic_id, bbp_get_forum_last_topic_id($old_forum_id));
     $this->assertSame($reply_id, bbp_get_forum_last_reply_id($old_forum_id));
     $this->assertSame($reply_id, bbp_get_forum_last_active_id($old_forum_id));
     // Topic meta
     $this->assertSame($old_forum_id, bbp_get_topic_forum_id($topic_id));
     $this->assertSame(1, bbp_get_topic_voice_count($topic_id, true));
     $this->assertSame(1, bbp_get_topic_reply_count($topic_id, true));
     $this->assertSame($reply_id, bbp_get_topic_last_reply_id($topic_id));
     $this->assertSame($reply_id, bbp_get_topic_last_active_id($topic_id));
     // Reply Meta
     $this->assertSame($old_forum_id, bbp_get_reply_forum_id($reply_id));
     $this->assertSame($topic_id, bbp_get_reply_topic_id($reply_id));
     // Create a new forum
     $new_forum_id = $this->factory->forum->create();
     // Move the topic into the new forum
     bbp_move_topic_handler($topic_id, $old_forum_id, $new_forum_id);
     // Topic post parent
     $topic_parent = wp_get_post_parent_id($topic_id);
     $this->assertSame($new_forum_id, $topic_parent);
     // Forum meta
     $this->assertSame(1, bbp_get_forum_topic_count($new_forum_id, true, true));
     $this->assertSame(1, bbp_get_forum_reply_count($new_forum_id, true, true));
     $this->assertSame($topic_id, bbp_get_forum_last_topic_id($new_forum_id));
     $this->assertSame($reply_id, bbp_get_forum_last_reply_id($new_forum_id));
     $this->assertSame($reply_id, bbp_get_forum_last_active_id($new_forum_id));
     // Topic meta
     $this->assertSame($new_forum_id, bbp_get_topic_forum_id($topic_id));
     $this->assertSame(1, bbp_get_topic_voice_count($topic_id, true));
     $this->assertSame(1, bbp_get_topic_reply_count($topic_id, true));
     $this->assertSame($reply_id, bbp_get_topic_last_reply_id($topic_id));
     $this->assertSame($reply_id, bbp_get_topic_last_active_id($topic_id));
     // Reply Meta
     $this->assertSame($new_forum_id, bbp_get_reply_forum_id($reply_id));
     $this->assertSame($topic_id, bbp_get_reply_topic_id($reply_id));
     // Old Topic/Reply Counts
     $this->assertSame(0, bbp_get_forum_topic_count($old_forum_id, true, true));
     $this->assertSame(0, bbp_get_forum_reply_count($old_forum_id, true, true));
     // Retore the user
     $this->set_current_user($this->old_current_user);
 }
예제 #4
0
파일: tools.php 프로젝트: joeyblake/bbpress
 public function setUp()
 {
     parent::setUp();
     $this->old_current_user = get_current_user_id();
     $this->set_current_user($this->factory->user->create(array('role' => 'administrator')));
     $this->keymaster_id = get_current_user_id();
     bbp_set_user_role($this->keymaster_id, bbp_get_keymaster_role());
     if (!function_exists('bbp_admin_repair')) {
         require_once BBP_PLUGIN_DIR . 'includes/admin/tools.php';
     }
 }
예제 #5
0
파일: roles.php 프로젝트: 082net/bbpresskr
 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;
 }
예제 #6
0
 /**
  * Process bulk dropdown form submission from the WordPress Users
  * Table
  *
  * @uses current_user_can() to check for 'promote users' capability
  * @uses bbp_get_dynamic_roles() to get forum roles
  * @uses bbp_get_user_role() to get a user's current forums role
  * @uses bbp_set_user_role() to set the user's new forums role
  * @return bool Always false
  */
 public function user_role_bulk_change()
 {
     // Bail if no users specified
     if (empty($_REQUEST['users'])) {
         return;
     }
     // Bail if this isn't a bbPress action
     if (empty($_REQUEST['bbp-new-role']) || empty($_REQUEST['bbp-change-role'])) {
         return;
     }
     // Check that the new role exists
     $dynamic_roles = bbp_get_dynamic_roles();
     if (empty($dynamic_roles[$_REQUEST['bbp-new-role']])) {
         return;
     }
     // Bail if nonce check fails
     check_admin_referer('bbp-bulk-users', 'bbp-bulk-users-nonce');
     // Bail if current user cannot promote users
     if (!current_user_can('promote_users')) {
         return;
     }
     // Get the current user ID
     $current_user_id = (int) bbp_get_current_user_id();
     // Run through user ids
     foreach ((array) $_REQUEST['users'] as $user_id) {
         $user_id = (int) $user_id;
         // Don't let a user change their own role
         if ($user_id === $current_user_id) {
             continue;
         }
         // Set up user and role data
         $user_role = bbp_get_user_role($user_id);
         $new_role = sanitize_text_field($_REQUEST['bbp-new-role']);
         // Only keymasters can set other keymasters
         if (in_array(bbp_get_keymaster_role(), array($user_role, $new_role)) && !bbp_is_user_keymaster()) {
             continue;
         }
         // Set the new forums role
         if ($new_role !== $user_role) {
             bbp_set_user_role($user_id, $new_role);
         }
     }
 }
예제 #7
0
 /**
  * @covers ::bbp_check_for_blacklist
  */
 public function test_should_return_true_for_keymasterss_to_bypass_blacklist_check()
 {
     // Create a keymaster user.
     $old_current_user = 0;
     $this->old_current_user = get_current_user_id();
     $this->set_current_user($this->factory->user->create(array('role' => 'subscriber')));
     $this->keymaster_id = get_current_user_id();
     bbp_set_user_role($this->keymaster_id, bbp_get_keymaster_role());
     $t = $this->factory->topic->create(array('post_author' => bbp_get_current_user_id(), 'post_title' => 'Sting', 'post_content' => 'Beware, there maybe bees hibernating.'));
     $anonymous_data = false;
     $author_id = bbp_get_topic_author_id($t);
     $title = bbp_get_topic_title($t);
     $content = bbp_get_topic_content($t);
     update_option('blacklist_keys', "hibernating\nfoo");
     $result = bbp_check_for_blacklist($anonymous_data, $author_id, $title, $content);
     $this->assertTrue($result);
     // Retore the original user.
     $this->set_current_user($this->old_current_user);
 }
/**
 * Return a map of WordPress roles to bbPress roles. Used to automatically grant
 * appropriate bbPress roles to WordPress users that wouldn't already have a
 * role in the forums. Also guarantees WordPress admins get the Keymaster role.
 *
 * @since bbPress (r4334)
 *
 * @return array Filtered array of WordPress roles to bbPress roles
 */
function bbp_get_user_role_map()
{
    // Get the default role once here
    $default_role = bbp_get_default_role();
    // Return filtered results, forcing admins to keymasters.
    return (array) apply_filters('bbp_get_user_role_map', array('administrator' => bbp_get_keymaster_role(), 'editor' => $default_role, 'author' => $default_role, 'contributor' => $default_role, 'subscriber' => $default_role));
}
예제 #9
0
 /**
  * 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;
 }
예제 #10
0
/**
 * Output forum role selector (for user edit)
 *
 * @since 2.2.0 bbPress (r4284)
 */
function bbp_edit_user_forums_role()
{
    // Return if no user is being edited
    if (!bbp_is_single_user_edit()) {
        return;
    }
    // Get the user's current forum role
    $user_role = bbp_get_user_role(bbp_get_displayed_user_id());
    // Get the folum roles
    $dynamic_roles = bbp_get_dynamic_roles();
    // Only keymasters can set other keymasters
    if (!bbp_is_user_keymaster()) {
        unset($dynamic_roles[bbp_get_keymaster_role()]);
    }
    ?>

	<select name="bbp-forums-role" id="bbp-forums-role">
		<option value=""><?php 
    esc_html_e('&mdash; No role for these forums &mdash;', 'bbpress');
    ?>
</option>

		<?php 
    foreach ($dynamic_roles as $role => $details) {
        ?>

			<option <?php 
        selected($user_role, $role);
        ?>
 value="<?php 
        echo esc_attr($role);
        ?>
"><?php 
        echo bbp_translate_user_role($details['name']);
        ?>
</option>

		<?php 
    }
    ?>

	</select>

	<?php 
}
예제 #11
0
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())));
}
예제 #12
0
/**
 * 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()))));
}
예제 #13
0
 /**
  * Adds support for bbPress v2.2+ dynamic roles.
  *
  * @package optimizeMember\Roles_Caps
  * @since 112512
  *
  * @attaches-to ``add_filter("bbp_get_caps_for_role");``
  *
  * @return array
  */
 public static function bbp_dynamic_role_caps($caps = FALSE, $role = FALSE)
 {
     if (function_exists("bbp_get_dynamic_roles") && $role !== bbp_get_blocked_role()) {
         $caps = array_merge($caps, array("read" => true, "level_0" => true));
         $caps = array_merge($caps, array("access_optimizemember_level0" => true));
         /**/
         if (in_array($role, array(bbp_get_keymaster_role(), bbp_get_moderator_role()), TRUE)) {
             for ($n = 0; $n <= $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["levels"]; $n++) {
                 $caps = array_merge($caps, array("access_optimizemember_level" . $n => true));
             }
         }
     }
     return $caps;
 }
예제 #14
0
/**
 * Hooked to the 'bbp_activate' action, this helper function automatically makes
 * the current user a Key Master in the forums if they just activated bbPress,
 * regardless of the bbp_allow_global_access() setting.
 *
 * @since bbPress (r4910)
 *
 * @internal Used to internally make the current user a keymaster on activation
 *
 * @uses current_user_can() to bail if user cannot activate plugins
 * @uses get_current_user_id() to get the current user ID
 * @uses get_current_blog_id() to get the current blog ID
 * @uses is_user_member_of_blog() to bail if the current user does not have a role
 * @uses bbp_is_user_keymaster() to bail if the user is already a keymaster
 * @uses bbp_set_user_role() to make the current user a keymaster
 *
 * @return If user can't activate plugins or is already a keymaster
 */
function bbp_make_current_user_keymaster()
{
    // Bail if the current user can't activate plugins since previous pageload
    if (!current_user_can('activate_plugins')) {
        return;
    }
    // Get the current user ID
    $user_id = get_current_user_id();
    $blog_id = get_current_blog_id();
    // Bail if user is not actually a member of this site
    if (!is_user_member_of_blog($user_id, $blog_id)) {
        return;
    }
    // Bail if the current user already has a forum role to prevent
    // unexpected role and capability escalation.
    if (bbp_get_user_role($user_id)) {
        return;
    }
    // Make the current user a keymaster
    bbp_set_user_role($user_id, bbp_get_keymaster_role());
    // Reload the current user so caps apply immediately
    wp_get_current_user();
}
예제 #15
0
파일: core.php 프로젝트: 082net/bbpresskr
 function get_user_roles()
 {
     $bbp_roles = bbp_get_dynamic_roles();
     $keymaster = bbp_get_keymaster_role();
     $moderator = bbp_get_moderator_role();
     $blocked = bbp_get_blocked_role();
     // double check if the role exists
     if (isset($bbp_roles[$keymaster])) {
         unset($bbp_roles[$keymaster]);
     }
     if (isset($bbp_roles[$moderator])) {
         unset($bbp_roles[$moderator]);
     }
     if (isset($bbp_roles[$blocked])) {
         unset($bbp_roles[$blocked]);
     }
     $bbp_roles['bbpkr_anonymous'] = array('name' => __('Anonymous', 'bbpresskr'), 'caps' => array('spectate' => true));
     return $bbp_roles;
 }
예제 #16
0
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;
}
예제 #17
0
 /**
  * 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));
 }
/**
 * 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())));
}
예제 #19
0
 /**
  * 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;
 }
예제 #20
0
 /**
  * Adds support for bbPress v2.2+ dynamic roles.
  *
  * @package s2Member\Roles_Caps
  * @since 112512
  *
  * @param array  $caps Array of BBP capabilities.
  * @param string $role Role ID in WordPress.
  *
  * @attaches-to ``add_filter('bbp_get_caps_for_role');``
  *
  * @return array
  */
 public static function bbp_dynamic_role_caps($caps = array(), $role = '')
 {
     if (function_exists('bbp_get_dynamic_roles') && function_exists('bbp_get_blocked_role') && $role !== bbp_get_blocked_role()) {
         if (!did_action('bbp_deactivation') && !did_action('bbp_uninstall') && function_exists('bbp_get_keymaster_role') && function_exists('bbp_get_moderator_role')) {
             $caps = array_merge($caps, array('read' => TRUE, 'level_0' => TRUE));
             $caps = array_merge($caps, array('access_s2member_level0' => TRUE));
             if (in_array($role, array(bbp_get_keymaster_role(), bbp_get_moderator_role()), TRUE)) {
                 for ($n = 0; $n <= $GLOBALS['WS_PLUGIN__']['s2member']['c']['levels']; $n++) {
                     $caps = array_merge($caps, array('access_s2member_level' . $n => TRUE));
                 }
             }
         }
     }
     return $caps;
 }
예제 #21
0
 /**
  * Adds support for bbPress v2.2+ dynamic roles.
  *
  * @package s2Member\Roles_Caps
  * @since 112512
  *
  * @attaches-to ``add_filter("bbp_get_caps_for_role");``
  *
  * @return array
  */
 public static function bbp_dynamic_role_caps($caps = FALSE, $role = FALSE)
 {
     if (function_exists("bbp_get_dynamic_roles") && $role !== bbp_get_blocked_role()) {
         if (!did_action("bbp_deactivation") && !did_action("bbp_uninstall")) {
             $caps = array_merge($caps, array("read" => TRUE, "level_0" => TRUE));
             $caps = array_merge($caps, array("access_s2member_level0" => TRUE));
             if (in_array($role, array(bbp_get_keymaster_role(), bbp_get_moderator_role()), TRUE)) {
                 for ($n = 0; $n <= $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n++) {
                     $caps = array_merge($caps, array("access_s2member_level" . $n => TRUE));
                 }
             }
         }
     }
     return $caps;
 }