Exemplo n.º 1
0
 /**
  * The role name column callback.
  *
  * @since  1.0.0
  * @access protected
  * @param  string     $role
  * @return string
  */
 protected function column_title($role)
 {
     $states = array();
     $role_states = '';
     // If the role is the default role.
     if ($role == get_option('default_role')) {
         $states[] = esc_html__('Default Role', 'members');
     }
     // If the current user has this role.
     if (members_current_user_has_role($role)) {
         $states[] = esc_html__('Your Role', 'members');
     }
     // Allow devs to filter the role states.
     $states = apply_filters('members_role_states', $states, $role);
     // If we have states, string them together.
     if (!empty($states)) {
         foreach ($states as $state) {
             $role_states .= sprintf('<span class="role-state">%s</span>', $state);
         }
         $role_states = ' &ndash; ' . $role_states;
     }
     // Add the title and role states.
     $title = sprintf('<strong><a class="row-title" href="%s">%s</a>%s</strong>', esc_url(members_get_edit_role_url($role)), esc_html(members_get_role_name($role)), $role_states);
     return apply_filters('members_manage_roles_column_role_name', $title, $role);
 }
Exemplo n.º 2
0
/**
 * Provide/restrict access to specific roles or capabilities. This content should not be shown
 * in feeds.  Note that capabilities are checked first.  If a capability matches, any roles
 * added will *not* be checked.  Users should choose between using either capabilities or roles
 * for the check rather than both.  The best option is to always use a capability.
 *
 * @since  0.1.0
 * @access public
 * @param  array   $attr
 * @param  string  $content
 * @return string
 */
function members_access_check_shortcode($attr, $content = null)
{
    // If there's no content or if viewing a feed, return an empty string.
    if (is_null($content) || is_feed()) {
        return '';
    }
    // Set up the default attributes.
    $defaults = array('capability' => '', 'role' => '');
    // Merge the input attributes and the defaults.
    $attr = shortcode_atts($defaults, $attr, 'members_access');
    // If the current user has the capability, show the content.
    if ($attr['capability']) {
        // Get the capabilities.
        $caps = explode(',', $attr['capability']);
        // Loop through each capability.
        foreach ($caps as $cap) {
            // If the current user can perform the capability, return the content.
            if (current_user_can(trim($cap))) {
                return do_shortcode($content);
            }
        }
    }
    // If the current user has the role, show the content.
    if ($attr['role']) {
        // Get the roles.
        $roles = explode(',', $attr['role']);
        // Loop through each of the roles.
        foreach ($roles as $role) {
            // If the current user has the role, return the content.
            if (members_current_user_has_role(trim($role))) {
                return do_shortcode($content);
            }
        }
    }
    // Return an empty string if we've made it to this point.
    return '';
}