Skip to:
Content

BuddyPress.org

Ticket #5357: 5357.option2.02.diff

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

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

    diff --git bp-core/bp-core-template.php bp-core/bp-core-template.php
    index 51c1b38..128a9f7 100644
    function bp_get_options_nav() { 
    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

    diff --git bp-groups/bp-groups-loader.php bp-groups/bp-groups-loader.php
    index 0dc2f8a..5a28f1b 100644
    class BP_Groups_Component extends BP_Component { 
    427427                        // member and does not have an outstanding invitation,
    428428                        // show a "Request Membership" nav item.
    429429                        if ( is_user_logged_in() &&
    430                                  ! bp_current_user_can( 'bp_moderate' ) &&
    431430                                 ! $this->current_group->is_user_member &&
    432431                                 ! groups_check_for_membership_request( bp_loggedin_user_id(), $this->current_group->id ) &&
    433432                                 $this->current_group->status == 'private' &&
  • bp-groups/bp-groups-screens.php

    diff --git bp-groups/bp-groups-screens.php bp-groups/bp-groups-screens.php
    index aef0c90..38e9897 100644
    function groups_screen_group_request_membership() { 
    480480                        bp_core_add_message( __( 'Your membership request was sent to the group administrator successfully. You will be notified when the group administrator responds to your request.', 'buddypress' ) );
    481481                }
    482482                bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
     483
     484        } else if( bp_current_user_can( 'bp_moderate') ) {
     485               
     486                /**
     487                 * the template loaded in this case will default to 'groups/single/plugins'
     488                 * So to avoid modifying the home template and maximize compatibility with
     489                 * themes, we'll use the bp_template_action of this hook to load the
     490                 * 'groups/single/request-membership' template part
     491                 */
     492                add_action( 'bp_template_content', create_function( '', 'return bp_get_template_part("groups/single/request-membership");' ) );
    483493        }
    484494
    485495        do_action( 'groups_screen_group_request_membership', $bp->groups->current_group->id );
    function groups_screen_group_admin_manage_members() { 
    728738                        if ( !check_admin_referer( 'groups_ban_member' ) )
    729739                                return false;
    730740
     741                        $redirect = bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/';
     742
     743                        if ( bp_user_can( $user_id, 'bp_moderate' ) ) {
     744                                bp_core_add_message( __( 'The site Administrator cannot be banned from a group.', 'buddypress' ), 'error' );
     745                                bp_core_redirect( $redirect );
     746                        }
     747
    731748                        // Ban a user.
    732749                        if ( !groups_ban_member( $user_id, $bp->groups->current_group->id ) )
    733750                                bp_core_add_message( __( 'There was an error when banning that user, please try again', 'buddypress' ), 'error' );
    function groups_screen_group_admin_manage_members() { 
    736753
    737754                        do_action( 'groups_banned_member', $user_id, $bp->groups->current_group->id );
    738755
    739                         bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' );
     756                        bp_core_redirect( $redirect );
    740757                }
    741758
    742759                if ( bp_is_action_variable( 'unban', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) {
  • bp-templates/bp-legacy/buddypress/groups/single/admin.php

    diff --git bp-templates/bp-legacy/buddypress/groups/single/admin.php bp-templates/bp-legacy/buddypress/groups/single/admin.php
    index 449a7bf..ef26a93 100644
     
    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>
     273
     274                                                                <?php endif; ?>
    269275
    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>
    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