Ejemplo n.º 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);
}
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 /**
  * Unlinks Roles/Capabilities.
  *
  * @package s2Member\Roles_Caps
  * @since 110524RC
  *
  * @return null
  */
 public static function unlink_roles()
 {
     do_action('ws_plugin__s2member_before_unlink_roles', get_defined_vars());
     if (!apply_filters('ws_plugin__s2member_lock_roles_caps', FALSE)) {
         if ($role = get_role('subscriber')) {
             $role->remove_cap('access_s2member_level0');
         }
         for ($n = 1; $n <= $GLOBALS['WS_PLUGIN__']['s2member']['c']['max_levels']; $n++) {
             remove_role('s2member_level' . $n);
         }
         $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']['max_levels']; $n++) {
                     $role->remove_cap('access_s2member_level' . $n);
                 }
             }
         }
     }
     do_action('ws_plugin__s2member_after_unlink_roles', get_defined_vars());
 }
/**
 * 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())));
}
Ejemplo n.º 5
0
/**
 * Returns an array of capabilities based on the role that is being requested.
 *
 * @since bbPress (r2994)
 *
 * @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) {
        // Administrator
        case 'administrator':
            $caps = array('publish_forums', 'edit_forums', 'edit_others_forums', 'delete_forums', 'delete_others_forums', 'read_private_forums', 'read_hidden_forums', 'publish_topics', 'edit_topics', 'edit_others_topics', 'delete_topics', 'delete_others_topics', 'read_private_topics', 'publish_replies', 'edit_replies', 'edit_others_replies', 'delete_replies', 'delete_others_replies', 'read_private_replies', 'manage_topic_tags', 'edit_topic_tags', 'delete_topic_tags', 'assign_topic_tags', 'moderate', 'throttle', 'view_trash');
            break;
            // Moderator
        // Moderator
        case bbp_get_moderator_role():
            $caps = array('read_private_forums', 'read_hidden_forums', 'publish_topics', 'edit_topics', 'edit_others_topics', 'delete_topics', 'delete_others_topics', 'read_private_topics', 'publish_replies', 'edit_replies', 'edit_others_replies', 'delete_replies', 'delete_others_replies', 'read_private_replies', 'manage_topic_tags', 'edit_topic_tags', 'delete_topic_tags', 'assign_topic_tags', 'moderate', 'throttle', 'view_trash');
            break;
            // WordPress Core Roles
        // WordPress Core Roles
        case 'editor':
        case 'author':
        case 'contributor':
        case 'subscriber':
            // bbPress Participant Role
        // bbPress Participant Role
        case bbp_get_participant_role():
            // Any other role
        // Any other role
        default:
            $caps = array('read_private_forums', 'publish_topics', 'edit_topics', 'publish_replies', 'edit_replies', 'assign_topic_tags');
            break;
    }
    return apply_filters('bbp_get_caps_for_role', $caps, $role);
}
Ejemplo n.º 6
0
 /**
  * @covers ::bbp_check_for_blacklist
  */
 public function test_should_return_false_for_moderators_to_bypass_blacklist_check()
 {
     // Create a moderator 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->moderator_id = get_current_user_id();
     bbp_set_user_role($this->moderator_id, bbp_get_moderator_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->assertFalse($result);
     // Retore the original user.
     $this->set_current_user($this->old_current_user);
 }
Ejemplo n.º 7
0
/**
 * Handle the processing and feedback of the admin tools page
 *
 * @since bbPress (r2613)
 *
 * @uses check_admin_referer() To verify the nonce and the referer
 * @uses wp_cache_flush() To flush the cache
 */
function bbp_admin_reset_handler()
{
    // Bail if not resetting
    if (!bbp_is_post_request() || empty($_POST['bbpress-are-you-sure'])) {
        return;
    }
    // Only keymasters can proceed
    if (!bbp_is_user_keymaster()) {
        return;
    }
    check_admin_referer('bbpress-reset');
    global $wpdb;
    // Stores messages
    $messages = array();
    $failed = __('Failed', 'bbpress');
    $success = __('Success!', 'bbpress');
    // Flush the cache; things are about to get ugly.
    wp_cache_flush();
    /** Posts *****************************************************************/
    $statement = __('Deleting Posts&hellip; %s', 'bbpress');
    $sql_posts = $wpdb->get_results("SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` IN ('forum', 'topic', 'reply')", OBJECT_K);
    $sql_delete = "DELETE FROM `{$wpdb->posts}` WHERE `post_type` IN ('forum', 'topic', 'reply')";
    $result = is_wp_error($wpdb->query($sql_delete)) ? $failed : $success;
    $messages[] = sprintf($statement, $result);
    /** Post Meta *************************************************************/
    if (!empty($sql_posts)) {
        $sql_meta = array();
        foreach ($sql_posts as $key => $value) {
            $sql_meta[] = $key;
        }
        $statement = __('Deleting Post Meta&hellip; %s', 'bbpress');
        $sql_meta = implode("', '", $sql_meta);
        $sql_delete = "DELETE FROM `{$wpdb->postmeta}` WHERE `post_id` IN ('{$sql_meta}');";
        $result = is_wp_error($wpdb->query($sql_delete)) ? $failed : $success;
        $messages[] = sprintf($statement, $result);
    }
    /** Topic Tags ************************************************************/
    $statement = __('Deleting Topic Tags&hellip; %s', 'bbpress');
    $sql_delete = "DELETE a,b,c FROM `{$wpdb->terms}` AS a LEFT JOIN `{$wpdb->term_taxonomy}` AS c ON a.term_id = c.term_id LEFT JOIN `{$wpdb->term_relationships}` AS b ON b.term_taxonomy_id = c.term_taxonomy_id WHERE c.taxonomy = 'topic-tag';";
    $result = is_wp_error($wpdb->query($sql_delete)) ? $failed : $success;
    $messages[] = sprintf($statement, $result);
    /** User ******************************************************************/
    // Delete users
    if (!empty($_POST['bbpress-delete-imported-users'])) {
        $sql_users = $wpdb->get_results("SELECT `user_id` FROM `{$wpdb->usermeta}` WHERE `meta_key` = '_bbp_user_id'", OBJECT_K);
        if (!empty($sql_users)) {
            $sql_meta = array();
            foreach ($sql_users as $key => $value) {
                $sql_meta[] = $key;
            }
            $statement = __('Deleting User&hellip; %s', 'bbpress');
            $sql_meta = implode("', '", $sql_meta);
            $sql_delete = "DELETE FROM `{$wpdb->users}` WHERE `ID` IN ('{$sql_meta}');";
            $result = is_wp_error($wpdb->query($sql_delete)) ? $failed : $success;
            $messages[] = sprintf($statement, $result);
            $statement = __('Deleting User Meta&hellip; %s', 'bbpress');
            $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `user_id` IN ('{$sql_meta}');";
            $result = is_wp_error($wpdb->query($sql_delete)) ? $failed : $success;
            $messages[] = sprintf($statement, $result);
        }
        // Delete imported user metadata
    } else {
        $statement = __('Deleting User Meta&hellip; %s', 'bbpress');
        $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` LIKE '%%_bbp_%%';";
        $result = is_wp_error($wpdb->query($sql_delete)) ? $failed : $success;
        $messages[] = sprintf($statement, $result);
    }
    /** Converter *************************************************************/
    $statement = __('Deleting Conversion Table&hellip; %s', 'bbpress');
    $table_name = $wpdb->prefix . 'bbp_converter_translator';
    if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") === $table_name) {
        $wpdb->query("DROP TABLE {$table_name}");
        $result = $success;
    } else {
        $result = $failed;
    }
    $messages[] = sprintf($statement, $result);
    /** Options ***************************************************************/
    $statement = __('Deleting Settings&hellip; %s', 'bbpress');
    bbp_delete_options();
    $messages[] = sprintf($statement, $success);
    /** Roles *****************************************************************/
    $statement = __('Deleting Roles and Capabilities&hellip; %s', 'bbpress');
    remove_role(bbp_get_moderator_role());
    remove_role(bbp_get_participant_role());
    bbp_remove_caps();
    $messages[] = sprintf($statement, $success);
    /** Output ****************************************************************/
    if (count($messages)) {
        foreach ($messages as $message) {
            bbp_admin_tools_feedback($message);
        }
    }
}
Ejemplo n.º 8
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()))));
}
Ejemplo n.º 9
0
/**
 * bbPress's version updater looks at what the current database version is, and
 * runs whatever other code is needed.
 *
 * This is most-often used when the data schema changes, but should also be used
 * to correct issues with bbPress meta-data silently on software update.
 *
 * @since bbPress (r4104)
 */
function bbp_version_updater()
{
    // Get the raw database version
    $raw_db_version = (int) bbp_get_db_version_raw();
    /** 2.0 Branch ************************************************************/
    // 2.0, 2.0.1, 2.0.2, 2.0.3
    if ($raw_db_version < 200) {
        // No changes
    }
    /** 2.1 Branch ************************************************************/
    // 2.1, 2.1.1
    if ($raw_db_version < 211) {
        /**
         * Repair private and hidden forum data
         *
         * @link http://bbpress.trac.wordpress.org/ticket/1891
         */
        bbp_admin_repair_forum_visibility();
    }
    /** 2.2 Branch ************************************************************/
    // 2.2
    if ($raw_db_version < 220) {
        // Remove the Moderator role from the database
        remove_role(bbp_get_moderator_role());
        // Remove the Participant role from the database
        remove_role(bbp_get_participant_role());
        // Remove capabilities
        bbp_remove_caps();
    }
    /** 2.3 Branch ************************************************************/
    // 2.3
    if ($raw_db_version < 230) {
        // No changes
    }
    /** All done! *************************************************************/
    // Bump the version
    bbp_version_bump();
    // Delete rewrite rules to force a flush
    bbp_delete_rewrite_rules();
}
Ejemplo n.º 10
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));
 }
Ejemplo n.º 11
0
 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;
 }
Ejemplo n.º 12
0
/**
 * Return a user's main role for display
 *
 * @since bbPress (r3860)
 *
 * @param int $user_id
 * @uses bbp_get_user_role() To get the main user role
 * @uses bbp_get_moderator_role() To get the moderator role
 * @uses bbp_get_participant_role() To get the participant role
 * @uses bbp_get_moderator_role() To get the moderator role
 * @uses apply_filters() Calls 'bbp_get_user_display_role' with the
 *                        display role, user id, and user role
 * @return string
 */
function bbp_get_user_display_role($user_id = 0)
{
    // Validate user id
    $user_id = bbp_get_user_id($user_id, false, false);
    $user_role = bbp_get_user_role($user_id);
    // Capes earn Vinz Clortho status
    if (is_super_admin($user_id)) {
        $role = __('Key Master', 'bbpress');
        // Not the keymaster of Gozer
    } else {
        // Get the user's main role for display
        switch ($user_role) {
            /** bbPress Roles *********************************************/
            // Anonymous
            case bbp_get_anonymous_role():
                $role = __('Guest', 'bbpress');
                break;
                // Multisite Participant Role
            // Multisite Participant Role
            case bbp_get_participant_role():
                $role = __('Member', 'bbpress');
                break;
                // Moderator
            // Moderator
            case bbp_get_moderator_role():
                $role = __('Moderator', 'bbpress');
                break;
                /** WordPress Core Roles **************************************/
            /** WordPress Core Roles **************************************/
            case 'administrator':
            case 'editor':
            case 'author':
            case 'contributor':
            case 'subscriber':
            default:
                // Any other role (plugins, etc...)
                global $wp_roles;
                // Load roles if not set
                if (!isset($wp_roles)) {
                    $wp_roles = new WP_Roles();
                }
                // Get a translated role name
                if (!empty($wp_roles->role_names[$user_role])) {
                    $role = translate_user_role($wp_roles->role_names[$user_role]);
                } else {
                    $role = __('Member', 'bbpress');
                }
                break;
        }
    }
    return apply_filters('bbp_get_user_display_role', $role, $user_id, $user_role);
}
Ejemplo n.º 13
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())));
}
Ejemplo n.º 14
0
 /**
  * Unlinks Roles/Capabilities.
  *
  * @package s2Member\Roles_Caps
  * @since 110524RC
  *
  * @return null
  */
 public static function unlink_roles()
 {
     do_action("ws_plugin__s2member_before_unlink_roles", get_defined_vars());
     if (!apply_filters("ws_plugin__s2member_lock_roles_caps", FALSE)) {
         if ($role = get_role("subscriber")) {
             $role->remove_cap("access_s2member_level0");
         }
         for ($n = 1; $n <= $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["max_levels"]; $n++) {
             remove_role("s2member_level" . $n);
         }
         $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"]["max_levels"]; $n++) {
                     $role->remove_cap("access_s2member_level" . $n);
                 }
             }
         }
     }
     do_action("ws_plugin__s2member_after_unlink_roles", get_defined_vars());
 }
Ejemplo n.º 15
0
/**
 * Handle the processing and feedback of the admin tools page
 *
 * @since bbPress (r2613)
 *
 * @uses check_admin_referer() To verify the nonce and the referer
 * @uses wp_cache_flush() To flush the cache
 */
function bbp_admin_reset_handler()
{
    if ('post' == strtolower($_SERVER['REQUEST_METHOD']) && !empty($_POST['bbpress-are-you-sure'])) {
        check_admin_referer('bbpress-reset');
        global $wpdb;
        // Stores messages
        $messages = array();
        $failed = __('Failed', 'bbpress');
        $success = __('Success!', 'bbpress');
        // Flush the cache; things are about to get ugly.
        wp_cache_flush();
        /** Posts *************************************************************/
        $statement = __('Deleting Posts&hellip; %s', 'bbpress');
        $sql_posts = $wpdb->get_results("SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` IN ('forum', 'topic', 'reply')", OBJECT_K);
        $sql_delete = "DELETE FROM `{$wpdb->posts}` WHERE `post_type` IN ('forum', 'topic', 'reply')";
        $result = is_wp_error($wpdb->query($sql_delete)) ? $failed : $success;
        $messages[] = sprintf($statement, $result);
        /** Post Meta *********************************************************/
        if (!empty($sql_posts)) {
            foreach ($sql_posts as $key => $value) {
                $sql_meta[] = $key;
            }
            $statement = __('Deleting Post Meta&hellip; %s', 'bbpress');
            $sql_meta = implode("', '", $sql_meta);
            $sql_delete = "DELETE FROM `{$wpdb->postmeta}` WHERE `post_id` IN ('{$sql_meta}');";
            $result = is_wp_error($wpdb->query($sql_delete)) ? $failed : $success;
            $messages[] = sprintf($statement, $result);
        }
        /** Topic Tags ********************************************************/
        // @todo
        /** User Meta *********************************************************/
        $statement = __('Deleting User Meta&hellip; %s', 'bbpress');
        $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` LIKE '%%_bbp_%%';";
        $result = is_wp_error($wpdb->query($sql_delete)) ? $failed : $success;
        $messages[] = sprintf($statement, $result);
        /** Converter *********************************************************/
        $statement = __('Deleting Conversion Table&hellip; %s', 'bbpress');
        $table_name = $wpdb->prefix . 'bbp_converter_translator';
        if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") == $table_name) {
            $wpdb->query("DROP TABLE {$table_name}");
            $result = $success;
        } else {
            $result = $failed;
        }
        $messages[] = sprintf($statement, $result);
        /** Options ***********************************************************/
        $statement = __('Deleting Settings&hellip; %s', 'bbpress');
        bbp_delete_options();
        $messages[] = sprintf($statement, $success);
        /** Roles *************************************************************/
        $statement = __('Deleting Roles and Capabilities&hellip; %s', 'bbpress');
        remove_role(bbp_get_moderator_role());
        remove_role(bbp_get_participant_role());
        bbp_remove_caps();
        $messages[] = sprintf($statement, $success);
        /** Output ************************************************************/
        if (count($messages)) {
            foreach ($messages as $message) {
                bbp_admin_tools_feedback($message);
            }
        }
    }
}
Ejemplo n.º 16
0
/**
 * Get moderators for a specific object ID. Will return global moderators when
 * object ID is empty.
 *
 * @since 2.6.0 bbPress
 *
 * @param int $object_id
 *
 * @return array
 */
function bbp_get_moderators($object_id = 0)
{
    // Get global moderators
    if (empty($object_id)) {
        $users = get_users(array('role__in' => bbp_get_moderator_role()));
        // Get object moderators
    } else {
        $users = get_users(array('include' => bbp_get_moderator_ids($object_id)));
    }
    return apply_filters('bbp_get_moderators', $users, $object_id);
}