public function set_staff() { if (!function_exists('bbp_get_user_role')) { $this->_is_staff = false; return; } $this->_is_staff = bbp_get_user_role($this->get_user_id()) == 'bbp_keymaster'; }
function private_groups_can_user_view_post($user_id, $forum_id = '') { //the $forum_id that needs to be passed to this function is the forum_id that the post belongs to /* Assume the user can view the post at this point. */ $can_view = true; /* Get the groups for the forum */ $groups = get_post_meta($forum_id, '_private_group', false); /* If we have groups set for this forum let's get to work. */ if (!empty($groups) && is_array($groups)) { /** * Since specific groups exist let's assume the user can't view the post at * this point. The rest of this functionality should try to disprove this. */ $can_view = false; /* If the user's not logged in, assume it's blocked at this point. */ if (!is_user_logged_in()) { $can_view = false; } /*Check if user is keymaster*/ if (bbp_is_user_keymaster()) { $can_view = true; } else { $role = bbp_get_user_role($user_id); $check = get_user_meta($user_id, 'private_group', true); //if they are a mod, and they have no forum groups set, then they can moderate and see across all forums if ($role == 'bbp_moderator' && empty($check)) { $can_view = true; } else { /* Loop through each group and set $can_view to true if the user has this group. */ $check = get_user_meta($user_id, 'private_group', true); foreach ($groups as $group) { if ($check == $group) { $can_view = true; } } } } } /* Allow developers to overwrite the final return value. */ return apply_filters('private_groups_can_user_view_post', $can_view, $user_id, $forum_id); }
/** * Returns list of user roles, except 1st one, and bbPress assigned as they are shown by WordPress and bbPress theirselves. * * @param type $user WP_User from wp-includes/capabilities.php * @return array */ public function get_roles_array($user) { if (!is_array($user->roles) || count($user->roles) <= 1) { return array(); } // get bbPress assigned user role if (function_exists('bbp_filter_blog_editable_roles')) { $bb_press_role = bbp_get_user_role($user->ID); } else { $bb_press_role = ''; } $roles = array(); foreach ($user->roles as $key => $value) { if (!empty($bb_press_role) && $bb_press_role === $value) { // exclude bbPress assigned role continue; } $roles[] = $value; } array_shift($roles); // exclude primary role which is shown by WordPress itself return $roles; }
/** * Return user's forums role for display in the WordPress Users list table * * @since bbPress (r4337) * * @param string $retval * @param string $column_name * @param int $user_id * * @return string Displayable bbPress user role */ public static function user_role_row($retval = '', $column_name = '', $user_id = 0) { // Only looking for bbPress's user role column if ('bbp_user_role' === $column_name) { // Get the users role $user_role = bbp_get_user_role($user_id); $retval = false; // Translate user role for display if (!empty($user_role)) { $roles = bbp_get_dynamic_roles(); $retval = translate_user_role($roles[$user_role]['name']); } } // Pass retval through return $retval; }
/** * Add the default role 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 is_user_logged_in() To bail if user is not logged in * @uses bbp_get_user_role() To bail if user already has a role * @uses bbp_is_user_inactive() To bail if user is inactive * @uses bbp_allow_global_access() To know whether to save role to database * @uses bbp_get_user_role_map() To get the WP to BBP role map array * @uses bbp_get_default_role() To get the site's default forums role * @uses get_option() * * @return If not multisite, not global, or user is deleted/spammed */ function bbp_set_current_user_default_role() { /** Sanity ****************************************************************/ // Bail if deactivating bbPress if (bbp_is_deactivation()) { return; } // Catch all, to prevent premature user initialization if (!did_action('set_current_user')) { return; } // Bail if not logged in or already a member of this site if (!is_user_logged_in()) { return; } // Get the current user ID $user_id = bbp_get_current_user_id(); // Bail if user already has a forums role if (bbp_get_user_role($user_id)) { return; } // Bail if user is marked as spam or is deleted if (bbp_is_user_inactive($user_id)) { return; } /** Ready *****************************************************************/ // Load up bbPress once $bbp = bbpress(); // Get whether or not to add a role to the user account $add_to_site = bbp_allow_global_access(); // Get the current user's WordPress role. Set to empty string if none found. $user_role = bbp_get_user_blog_role($user_id); // Get the role map $role_map = bbp_get_user_role_map(); /** Forum Role ************************************************************/ // Use a mapped role if (isset($role_map[$user_role])) { $new_role = $role_map[$user_role]; // Use the default role } else { $new_role = bbp_get_default_role(); } /** Add or Map ************************************************************/ // Add the user to the site if (true === $add_to_site) { // Make sure bbPress roles are added bbp_add_forums_roles(); $bbp->current_user->add_role($new_role); // Don't add the user, but still give them the correct caps dynamically } else { $bbp->current_user->caps[$new_role] = true; $bbp->current_user->get_role_caps(); } }
<?php $isNotForumModerator = bbp_get_user_role(get_current_user_id()) != 'bbp_moderator' && bbp_get_user_role(get_current_user_id()) != 'bbp_keymaster'; if (get_current_user_id() != bp_displayed_user_id() && $isNotForumModerator) { wp_redirect('http://kabacademy.com/dostup-zapreshhen'); exit; } get_header(); ?> <div id="content"> <div class="padder full_width"> <?php do_action('bp_before_blog_page'); ?> <div class="page" id="blog-page" role="main"> <?php if (have_posts()) { while (have_posts()) { the_post(); ?> <h2 class="pagetitle"><?php the_title(); ?> </h2> <div id="post-<?php
/** * 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 }
/** * Update user roles and capabilities * * @global WP_Roles $wp_roles * @param WP_User $user * @return boolean */ protected function update_user($user) { global $wp_roles; if ($this->multisite) { if (!$this->check_blog_user($user)) { return false; } } $primary_role = $_POST['primary_role']; if (empty($primary_role) || !isset($wp_roles->roles[$primary_role])) { $primary_role = ''; } if (function_exists('bbp_filter_blog_editable_roles')) { // bbPress plugin is active $bbp_user_role = bbp_get_user_role($user->ID); } else { $bbp_user_role = ''; } $edit_user_caps_mode = $this->get_edit_user_caps_mode(); if (!$edit_user_caps_mode) { // readonly mode $this->capabilities_to_save = $user->caps; } // revoke all roles and capabilities from this user $user->roles = array(); $user->remove_all_caps(); // restore primary role if (!empty($primary_role)) { $user->add_role($primary_role); } // restore bbPress user role if she had one if (!empty($bbp_user_role)) { $user->add_role($bbp_user_role); } // add other roles to user foreach ($_POST as $key => $value) { $result = preg_match('/^wp_role_(.+)/', $key, $match); if ($result === 1) { $role = $match[1]; if (isset($wp_roles->roles[$role])) { $user->add_role($role); if (!$edit_user_caps_mode && isset($this->capabilities_to_save[$role])) { unset($this->capabilities_to_save[$role]); } } } } // add individual capabilities to user if (count($this->capabilities_to_save) > 0) { foreach ($this->capabilities_to_save as $key => $value) { $user->add_cap($key); } } $user->update_user_level_from_caps(); if ($this->apply_to_all) { // apply update to the all network if (!$this->network_update_user($user)) { return false; } } return true; }
/** * 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(); }
function get_user_role($user_id = 0) { static $roles = array(); if (!$user_id && is_user_logged_in()) { $user_id = get_current_user_id(); } if (!$user_id) { return 'bbpkr_anonymous'; } if (isset($roles[$user_id])) { return $roles[$user_id]; } $user_role = bbp_get_user_role($user_id); return $user_role; }
$this->user_primary_role_dropdown_list($this->user_to_edit->roles); $values = array_values($this->user_to_edit->roles); $primary_role = array_shift($values); // get 1st element from roles array if (function_exists('bbp_filter_blog_editable_roles')) { // bbPress plugin is active ?> <div style="margin-top: 5px;margin-bottom: 5px; font-weight: bold;"><?php esc_html_e('bbPress Role:', 'ure'); ?> </div> <?php // Get the roles $dynamic_roles = bbp_get_dynamic_roles(); $bbp_user_role = bbp_get_user_role($this->user_to_edit->ID); if (!empty($bbp_user_role)) { echo $dynamic_roles[$bbp_user_role]['name']; } } ?> <div style="margin-top: 5px;margin-bottom: 5px; font-weight: bold;"><?php esc_html_e('Other Roles:', 'ure'); ?> </div> <?php foreach ($this->roles as $role_id => $role) { if (($show_admin_role || $role_id != 'administrator') && $role_id !== $primary_role) { if ($this->user_can($role_id)) { $checked = 'checked="checked"'; } else {
/** * 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 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'); // User is not registered } elseif (empty($user_id)) { $role = __('Guest', 'bbpress'); // Not the keymaster of Gozer } else { // Get the user's main role for display switch ($user_role) { 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); }
public function display() { $caps_readable = $this->lib->get('caps_readable'); $show_deprecated_caps = $this->lib->get('show_deprecated_caps'); $edit_user_caps_mode = $this->lib->get_edit_user_caps_mode(); $caps_access_restrict_for_simple_admin = $this->lib->get_option('caps_access_restrict_for_simple_admin', 0); $user_info = $this->get_user_info(); ?> <div class="postbox" style="float:left;min-width:1000px;width: 100%;"> <div id="ure_user_caps_header"> <span id="ure_user_caps_title"><?php esc_html_e('Change capabilities for user', 'user-role-editor'); ?> </span> <?php echo $user_info; ?> </div> <div class="inside"> <table cellpadding="0" cellspacing="0" style="width: 100%;"> <tr> <td> </td> <td style="padding-left: 10px; padding-bottom: 5px;"> <?php if (is_super_admin() || !$this->multisite || !class_exists('User_Role_Editor_Pro') || !$caps_access_restrict_for_simple_admin) { if ($caps_readable) { $checked = 'checked="checked"'; } else { $checked = ''; } ?> <input type="checkbox" name="ure_caps_readable" id="ure_caps_readable" value="1" <?php echo $checked; ?> onclick="ure_turn_caps_readable(<?php echo $this->user_to_edit->ID; ?> );" /> <label for="ure_caps_readable"><?php esc_html_e('Show capabilities in human readable form', 'user-role-editor'); ?> </label> <?php if ($show_deprecated_caps) { $checked = 'checked="checked"'; } else { $checked = ''; } ?> <input type="checkbox" name="ure_show_deprecated_caps" id="ure_show_deprecated_caps" value="1" <?php echo $checked; ?> onclick="ure_turn_deprecated_caps(<?php echo $this->user_to_edit->ID; ?> );"/> <label for="ure_show_deprecated_caps"><?php esc_html_e('Show deprecated capabilities', 'user-role-editor'); ?> </label> <?php } ?> </td> </tr> <tr> <td id="ure_user_roles"> <div class="ure-user-role-section-title"><?php esc_html_e('Primary Role:', 'user-role-editor'); ?> </div> <?php $this->show_primary_role_dropdown_list($this->user_to_edit->roles); if (function_exists('bbp_filter_blog_editable_roles')) { // bbPress plugin is active ?> <div class="ure-user-role-section-title" style="margin-top: 5px;"><?php esc_html_e('bbPress Role:', 'user-role-editor'); ?> </div> <?php $dynamic_roles = bbp_get_dynamic_roles(); $bbp_user_role = bbp_get_user_role($this->user_to_edit->ID); if (!empty($bbp_user_role)) { echo $dynamic_roles[$bbp_user_role]['name']; } } ?> <div style="margin-top: 5px;margin-bottom: 5px; font-weight: bold;"><?php esc_html_e('Other Roles:', 'user-role-editor'); ?> </div> <?php $this->show_secondary_roles(); ?> </td> <td style="padding-left: 5px; padding-top: 5px; border-top: 1px solid #ccc;"> <?php $this->display_caps(false, $edit_user_caps_mode); ?> </td> </tr> </table> <input type="hidden" name="object" value="user" /> <input type="hidden" name="user_id" value="<?php echo $this->user_to_edit->ID; ?> " /> </div> </div> <?php }
/** * 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); }
<td class="ure-user-roles"> <div style="margin-bottom: 5px; font-weight: bold;"><?php echo __('Primary Role:', 'ure'); ?></div> <?php $primary_role = array_shift(array_values($ure_userToEdit->roles)); // get 1st element from roles array if (!empty($primary_role) && isset($ure_roles[$primary_role])) { echo $ure_roles[$primary_role]['name']; } else { echo 'None'; } if (function_exists('bbp_filter_blog_editable_roles') ) { // bbPress plugin is active ?> <div style="margin-top: 5px;margin-bottom: 5px; font-weight: bold;"><?php echo __('bbPress Role:', 'ure'); ?></div> <?php // Get the roles $dynamic_roles = bbp_get_dynamic_roles(); $bbp_user_role = bbp_get_user_role($ure_userToEdit->ID); if (!empty($bbp_user_role)) { echo $dynamic_roles[$bbp_user_role]['name']; } } ?> <div style="margin-top: 5px;margin-bottom: 5px; font-weight: bold;"><?php echo __('Other Roles:', 'ure'); ?></div> <?php $youAreAdmin = defined('URE_SHOW_ADMIN_ROLE') && ure_is_admin(); foreach ($ure_roles as $role_id => $role) { if ( ($youAreAdmin || $role_id!='administrator') && ($role_id!==$primary_role) ) { if ( user_can( $ure_userToEdit->ID, $role_id ) ) { $checked = 'checked="checked"'; } else { $checked = ''; }
/** * Filter the list of roles included in the WordPress site role list * * This ensures bbPress' roles are only displayed under the Forum Role list * in the WordPress Users list table * * @since 2.6.0 bbPress (r6051) * * @return array $roles */ public static function user_role_list_filter($roles, $user) { // Get the users role $user_role = bbp_get_user_role($user->ID); if (!empty($user_role)) { unset($roles[$user_role]); } return $roles; }