本文整理汇总了PHP中bbp_get_keymaster_role函数的典型用法代码示例。如果您正苦于以下问题:PHP bbp_get_keymaster_role函数的具体用法?PHP bbp_get_keymaster_role怎么用?PHP bbp_get_keymaster_role使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bbp_get_keymaster_role函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bbp_get_caps_for_role
/**
* 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: setUp
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: test_bbp_move_topic_handler
/**
* @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: setUp
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: user_has_cap
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: user_role_bulk_change
/**
* 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: test_should_return_true_for_keymasterss_to_bypass_blacklist_check
/**
* @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);
}
示例8: bbp_get_user_role_map
/**
* 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: get_caps
/**
* 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: bbp_edit_user_forums_role
/**
* 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('— No role for these forums —', '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: ntwb_bbpress_custom_role_names
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: bbp_get_dynamic_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()))));
}
示例13: bbp_dynamic_role_caps
/**
* 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: bbp_make_current_user_keymaster
/**
* 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: get_user_roles
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;
}