/** * 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); }
/** * 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()); }
private static function setup() { self::$failure_title = __('Failed to download', 'download-mgr'); self::$upload_perms = array(bbp_get_participant_role()); self::$download_perms = array(bbp_get_participant_role()); self::$wp_download_level = 'public'; self::$defaults['wrong_level_msg'] = __('Sorry, you don\'t have the right user level for downloads.', 'bbpresskr'); self::$defaults['no_login_msg'] = sprintf(__('You must be a %s user and logged in to download.', 'bbpresskr'), get_option('blogname')); self::$conf = array_merge(self::$defaults, get_option('bbpkr_attachment_settings', array())); }
static function init() { if (!did_action('after_setup_theme')) { add_action('init', array(__CLASS__, 'wp_init')); } self::wp_init(); // add_filter( 'bbp_include_all_forums', '__return_true' ); // remove_action( 'pre_get_posts', 'bbp_pre_get_posts_normalize_forum_visibility', 4 ); self::$upload_perms = array(bbp_get_participant_role()); self::$download_perms = array(bbp_get_participant_role()); }
/** * 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; } }
/** * 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… %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… %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… %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… %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… %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… %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… %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… %s', 'bbpress'); bbp_delete_options(); $messages[] = sprintf($statement, $success); /** Roles *****************************************************************/ $statement = __('Deleting Roles and Capabilities… %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); } } }
/** * Get the default site options and their values. * * These option * * @since 2.0.0 bbPress (r3421) * * @return array Filtered option names and values */ function bbp_get_default_options() { // Default options return apply_filters('bbp_get_default_options', array('_bbp_db_version' => bbpress()->db_version, '_bbp_edit_lock' => 5, '_bbp_throttle_time' => 10, '_bbp_enable_favorites' => 1, '_bbp_enable_subscriptions' => 1, '_bbp_allow_anonymous' => 0, '_bbp_allow_global_access' => 1, '_bbp_allow_revisions' => 1, '_bbp_allow_topic_tags' => 1, '_bbp_allow_forum_mods' => 1, '_bbp_allow_threaded_replies' => 0, '_bbp_allow_search' => 1, '_bbp_thread_replies_depth' => 2, '_bbp_use_wp_editor' => 1, '_bbp_use_autoembed' => 0, '_bbp_theme_package_id' => 'default', '_bbp_default_role' => bbp_get_participant_role(), '_bbp_settings_integration' => 0, '_bbp_topics_per_page' => 15, '_bbp_replies_per_page' => 15, '_bbp_forums_per_page' => 50, '_bbp_topics_per_rss_page' => 25, '_bbp_replies_per_rss_page' => 25, '_bbp_page_for_forums' => 0, '_bbp_page_for_topics' => 0, '_bbp_page_for_login' => 0, '_bbp_page_for_register' => 0, '_bbp_page_for_lost_pass' => 0, '_bbp_root_slug' => 'forums', '_bbp_show_on_root' => 'forums', '_bbp_include_root' => 1, '_bbp_forum_slug' => 'forum', '_bbp_topic_slug' => 'topic', '_bbp_reply_slug' => 'reply', '_bbp_topic_tag_slug' => 'topic-tag', '_bbp_user_slug' => 'users', '_bbp_user_favs_slug' => 'favorites', '_bbp_user_subs_slug' => 'subscriptions', '_bbp_topic_archive_slug' => 'topics', '_bbp_reply_archive_slug' => 'replies', '_bbp_view_slug' => 'view', '_bbp_search_slug' => 'search', '_bbp_title_max_length' => 80, '_bbp_super_sticky_topics' => '', '_bbp_private_forums' => '', '_bbp_hidden_forums' => '', '_bbp_enable_group_forums' => 1, '_bbp_group_forums_root_id' => 0, '_bbp_enable_akismet' => 1)); }
private function setup_globals() { global $wpdb; /** Get database connections ******************************************/ $this->wpdb = $wpdb; $this->max_rows = (int) $_POST['_bbp_converter_rows']; $this->opdb = new wpdb($_POST['_bbp_converter_db_user'], $_POST['_bbp_converter_db_pass'], $_POST['_bbp_converter_db_name'], $_POST['_bbp_converter_db_server']); $this->opdb->prefix = $_POST['_bbp_converter_db_prefix']; /** * Error Reporting */ $this->wpdb->show_errors(); $this->opdb->show_errors(); /** * Syncing */ $this->sync_table_name = $this->wpdb->prefix . 'bbp_converter_translator'; if ($this->wpdb->get_var("SHOW TABLES LIKE '" . $this->sync_table_name . "'") == $this->sync_table_name) { $this->sync_table = true; } else { $this->sync_table = false; } /** * Charset */ if (empty($this->wpdb->charset)) { $this->charset = 'UTF8'; } else { $this->charset = $this->wpdb->charset; } /** * Default mapping. */ /** Forum Section *****************************************************/ $this->field_map[] = array('to_type' => 'forum', 'to_fieldname' => 'post_status', 'default' => 'publish'); $this->field_map[] = array('to_type' => 'forum', 'to_fieldname' => 'comment_status', 'default' => 'closed'); $this->field_map[] = array('to_type' => 'forum', 'to_fieldname' => 'ping_status', 'default' => 'closed'); $this->field_map[] = array('to_type' => 'forum', 'to_fieldname' => 'post_type', 'default' => 'forum'); /** Topic Section *****************************************************/ $this->field_map[] = array('to_type' => 'topic', 'to_fieldname' => 'post_status', 'default' => 'publish'); $this->field_map[] = array('to_type' => 'topic', 'to_fieldname' => 'comment_status', 'default' => 'closed'); $this->field_map[] = array('to_type' => 'topic', 'to_fieldname' => 'ping_status', 'default' => 'closed'); $this->field_map[] = array('to_type' => 'topic', 'to_fieldname' => 'post_type', 'default' => 'topic'); /** Post Section ******************************************************/ $this->field_map[] = array('to_type' => 'reply', 'to_fieldname' => 'post_status', 'default' => 'publish'); $this->field_map[] = array('to_type' => 'reply', 'to_fieldname' => 'comment_status', 'default' => 'closed'); $this->field_map[] = array('to_type' => 'reply', 'to_fieldname' => 'ping_status', 'default' => 'closed'); $this->field_map[] = array('to_type' => 'reply', 'to_fieldname' => 'post_type', 'default' => 'reply'); /** User Section ******************************************************/ $default_role = is_multisite() && get_option('_bbp_allow_global_access') ? bbp_get_participant_role() : get_option('default_role'); $this->field_map[] = array('to_type' => 'user', 'to_fieldname' => 'role', 'default' => $default_role); }
/** * 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())))); }
/** * 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(); }
/** * 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)); }
/** * 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); }
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()))); }
/** * 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… %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… %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… %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… %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… %s', 'bbpress'); bbp_delete_options(); $messages[] = sprintf($statement, $success); /** Roles *************************************************************/ $statement = __('Deleting Roles and Capabilities… %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); } } } }