Skip to:
Content

BuddyPress.org

Ticket #5357: 5357.option2.diff

File 5357.option2.diff, 5.9 KB (added by imath, 11 years ago)
  • bp-core/bp-core-caps.php

     
    198198        return (bool) apply_filters( 'bp_current_user_can', $retval, $capability, $blog_id );
    199199}
    200200
     201 /**
     202 * Check whether a user has a given capability.
     203 *
     204 * @since BuddyPress (?.?.0)
     205 *
     206 * @global $blog_id
     207 * @param int $user_id the id of the user to check
     208 * @param string $capability Capability or role name.
     209 * @uses bp_get_root_blog_id() to get the blog id where BuddyPress is activated
     210 * @uses switch_to_blog() to eventually switch to BuddyPress root blog id
     211 * @uses restore_current_blog() to switch back to current blog
     212 * @return bool True if the user has the cap for the given blog.
     213 */
     214function bp_user_can( $user_id = 0, $capability = '' ) {
     215        global $blog_id;
     216
     217        if ( empty( $user_id ) || empty( $capability ) ) {
     218                return false;
     219        }
     220
     221        if ( $blog_id != bp_get_root_blog_id() ) {
     222                switch_to_blog( bp_get_root_blog_id() );
     223                $retval = user_can( $user_id, $capability );
     224                restore_current_blog();
     225        } else {
     226                $retval = user_can( $user_id, $capability );
     227        }
     228
     229        return (bool) apply_filters( 'bp_user_can', $retval, $user_id, $capability );
     230}
     231
     232
    201233/**
    202234 * Temporary implementation of 'bp_moderate' cap.
    203235 *
  • bp-core/bp-core-template.php

     
    5353                if ( !$subnav_item['user_has_access'] )
    5454                        continue;
    5555
     56                if ( 'request-membership' == $subnav_item['slug'] && bp_current_user_can( 'bp_moderate' ) )
     57                        continue;
     58
    5659                // If the current action or an action variable matches the nav item id, then add a highlight CSS class.
    5760                if ( $subnav_item['slug'] == bp_current_action() ) {
    5861                        $selected = ' class="current selected"';
  • bp-groups/bp-groups-loader.php

     
    421421                        // member and does not have an outstanding invitation,
    422422                        // show a "Request Membership" nav item.
    423423                        if ( is_user_logged_in() &&
    424                                  ! bp_current_user_can( 'bp_moderate' ) &&
    425424                                 ! $this->current_group->is_user_member &&
    426425                                 ! groups_check_for_membership_request( bp_loggedin_user_id(), $this->current_group->id ) &&
    427426                                 $this->current_group->status == 'private' &&
  • bp-groups/bp-groups-screens.php

     
    728728                        if ( !check_admin_referer( 'groups_ban_member' ) )
    729729                                return false;
    730730
     731                        $redirect = bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/';
     732
     733                        if ( bp_user_can( $user_id, 'bp_moderate' ) ) {
     734                                bp_core_add_message( __( 'The site Administrator cannot be banned from a group.', 'buddypress' ), 'error' );
     735                                bp_core_redirect( $redirect );
     736                        }
     737
    731738                        // Ban a user.
    732739                        if ( !groups_ban_member( $user_id, $bp->groups->current_group->id ) )
    733740                                bp_core_add_message( __( 'There was an error when banning that user, please try again', 'buddypress' ), 'error' );
     
    736743
    737744                        do_action( 'groups_banned_member', $user_id, $bp->groups->current_group->id );
    738745
    739                         bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' );
     746                        bp_core_redirect( $redirect );
    740747                }
    741748
    742749                if ( bp_is_action_variable( 'unban', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) {
  • bp-templates/bp-legacy/buddypress/groups/single/admin.php

     
    265265
    266266                                                                <a href="<?php bp_group_member_unban_link(); ?>" class="button confirm member-unban" title="<?php _e( 'Unban this member', 'buddypress' ); ?>"><?php _e( 'Remove Ban', 'buddypress' ); ?></a>
    267267
    268                                                         <?php else : ?>
     268                                                        <?php else: ?> 
     269 
     270                                                                <?php if ( ! bp_user_can( bp_get_group_member_id(), 'bp_moderate' ) ) : ?>
     271                                                                       
     272                                                                        <a href="<?php bp_group_member_ban_link(); ?>" class="button confirm member-ban" title="<?php _e( 'Kick and ban this member', 'buddypress' ); ?>"><?php _e( 'Kick &amp; Ban', 'buddypress' ); ?></a>
    269273
    270                                                                 <a href="<?php bp_group_member_ban_link(); ?>" class="button confirm member-ban" title="<?php _e( 'Kick and ban this member', 'buddypress' ); ?>"><?php _e( 'Kick &amp; Ban', 'buddypress' ); ?></a>
     274                                                                <?php endif; ?>
     275
    271276                                                                <a href="<?php bp_group_member_promote_mod_link(); ?>" class="button confirm member-promote-to-mod" title="<?php _e( 'Promote to Mod', 'buddypress' ); ?>"><?php _e( 'Promote to Mod', 'buddypress' ); ?></a>
    272277                                                                <a href="<?php bp_group_member_promote_admin_link(); ?>" class="button confirm member-promote-to-admin" title="<?php _e( 'Promote to Admin', 'buddypress' ); ?>"><?php _e( 'Promote to Admin', 'buddypress' ); ?></a>
    273278
  • bp-templates/bp-legacy/buddypress/groups/single/home.php

     
    6969                                // Old group forums
    7070                                elseif ( bp_is_group_forum()      ) : bp_get_template_part( 'groups/single/forum'        );
    7171
     72                                // group membership requests for site admins
     73                                elseif ( bp_is_group_membership_request() && bp_current_user_can( 'bp_moderate' ) ) :
     74                                        bp_get_template_part( 'groups/single/request-membership' );
     75
    7276                                // Anything else (plugins mostly)
    7377                                else                                : bp_get_template_part( 'groups/single/plugins'      );
    7478