Skip to:
Content

BuddyPress.org

Changeset 11140


Ignore:
Timestamp:
09/21/2016 05:38:04 PM (9 years ago)
Author:
dcavins
Message:

WP Users List: Refinements to member type bulk change controls and filters.

Apply code improvements from related work on group type (#7175).

  • Improve error message presentation.
  • Escape strings before output.
  • Use strict comparison operators.

Props dcavins, djpaul.

See #6060

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/classes/class-bp-members-admin.php

    r11120 r11140  
    20642064
    20652065        // Bail if current user cannot promote users.
    2066         if ( ! current_user_can( 'promote_users' ) ) {
     2066        if ( ! bp_current_user_can( 'promote_users' ) ) {
    20672067            return;
    20682068        }
     
    20852085            <?php foreach( $types as $type ) : ?>
    20862086
    2087                 <option value="<?php echo esc_attr( $type->name ); ?>"><?php echo $type->labels['name']; ?></option>
     2087                <option value="<?php echo esc_attr( $type->name ); ?>"><?php esc_html_e( $type->labels['singular_name'] ); ?></option>
    20882088
    20892089            <?php endforeach; ?>
     
    21062106        $this->users_type_change_notice();
    21072107
    2108         // Bail if no users specified.
    2109         if ( empty( $_REQUEST['users'] ) ) {
    2110             return;
    2111         }
    2112 
    2113         // Bail if this isn't a BuddyPress action.
    2114         if ( ( empty( $_REQUEST['bp_change_type'] ) && empty( $_REQUEST['bp_change_type2'] ) )
     2108        // Bail if no users are specified or if this isn't a BuddyPress action.
     2109        if ( empty( $_REQUEST['users'] )
     2110            || ( empty( $_REQUEST['bp_change_type'] ) && empty( $_REQUEST['bp_change_type2'] ) )
    21152111            || empty( $_REQUEST['bp_change_member_type'] )
    21162112        ) {
     
    21222118
    21232119        // Bail if current user cannot promote users.
    2124         if ( ! current_user_can( 'promote_users' ) ) {
     2120        if ( ! bp_current_user_can( 'promote_users' ) ) {
    21252121            return;
    21262122        }
     
    21342130
    21352131        // Check that the selected type actually exists.
    2136         if ( 'remove_member_type' != $new_type && null == bp_get_member_type_object( $new_type ) ) {
    2137             return;
    2138         }
    2139 
    2140         // Run through user ids.
    2141         $error = false;
    2142         foreach ( (array) $_REQUEST['users'] as $user_id ) {
    2143             $user_id = (int) $user_id;
    2144 
    2145             // Get the old member type to check against.
    2146             $member_type = bp_get_member_type( $user_id );
    2147 
    2148             if ( 'remove_member_type' == $new_type ) {
    2149                 // Remove the current member type, if there's one to remove.
    2150                 if ( $member_type ) {
    2151                     $removed = bp_remove_member_type( $user_id, $member_type );
    2152                     if ( false == $removed || is_wp_error( $removed ) ) {
    2153                         $error = true;
     2132        if ( 'remove_member_type' != $new_type && null === bp_get_member_type_object( $new_type ) ) {
     2133            $error = true;
     2134        } else {
     2135            // Run through user ids.
     2136            $error = false;
     2137            foreach ( (array) $_REQUEST['users'] as $user_id ) {
     2138                $user_id = (int) $user_id;
     2139
     2140                // Get the old member type to check against.
     2141                $member_type = bp_get_member_type( $user_id );
     2142
     2143                if ( 'remove_member_type' === $new_type ) {
     2144                    // Remove the current member type, if there's one to remove.
     2145                    if ( $member_type ) {
     2146                        $removed = bp_remove_member_type( $user_id, $member_type );
     2147                        if ( false === $removed || is_wp_error( $removed ) ) {
     2148                            $error = true;
     2149                        }
    21542150                    }
    2155                 }
    2156             } else {
    2157                 // Set the new member type.
    2158                 if ( $new_type !== $member_type ) {
    2159                     $set = bp_set_member_type( $user_id, $new_type );
    2160                     if ( false == $set || is_wp_error( $set ) ) {
    2161                         $error = true;
     2151                } else {
     2152                    // Set the new member type.
     2153                    if ( $new_type !== $member_type ) {
     2154                        $set = bp_set_member_type( $user_id, $new_type );
     2155                        if ( false === $set || is_wp_error( $set ) ) {
     2156                            $error = true;
     2157                        }
    21622158                    }
    21632159                }
     
    21852181
    21862182        // Display feedback.
    2187         if ( $updated && in_array( $updated, array( 'member-type-change-error', 'member-type-change-success' ) ) ) {
     2183        if ( $updated && in_array( $updated, array( 'member-type-change-error', 'member-type-change-success' ), true ) ) {
    21882184
    21892185            if ( 'member-type-change-error' === $updated ) {
    21902186                $notice = __( 'There was an error while changing member type. Please try again.', 'buddypress' );
     2187                $type   = 'error';
    21912188            } else {
    21922189                $notice = __( 'Member type was changed successfully.', 'buddypress' );
     2190                $type   = 'updated';
    21932191            }
    21942192
    2195             bp_core_add_admin_notice( $notice );
     2193            bp_core_add_admin_notice( $notice, $type );
    21962194        }
    21972195    }
     
    22352233        if ( $type_obj = bp_get_member_type_object( $type ) ) {
    22362234            $url = add_query_arg( array( 'bp-member-type' => urlencode( $type ) ) );
    2237             $retval = '<a href="' . esc_url( $url ) . '">' . $type_obj->labels['singular_name'] . '</a>';
     2235            $retval = '<a href="' . esc_url( $url ) . '">' . esc_html( $type_obj->labels['singular_name'] ) . '</a>';
    22382236        }
    22392237
Note: See TracChangeset for help on using the changeset viewer.