Skip to:
Content

BuddyPress.org

Changeset 9158


Ignore:
Timestamp:
11/21/2014 07:44:11 PM (11 years ago)
Author:
imath
Message:

When cropping an avatar, make sure the "w" crop parameter does not interfere with WP_Query

In the different edit-avatar templates, cropping forms include a field named "w". When posted, this particular posted variable is interpreted as the week parameter of the main WordPress query. This commit introduces a new function bp_core_avatar_reset_query() that will make sure the week parameter is not set when an avatar is being cropped.

props boonebgorges, DJPaul

Fixes #5999

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-avatars.php

    r9125 r9158  
    11971197    return apply_filters( 'bp_core_avatar_thumb', $avatar );
    11981198}
     1199
     1200/**
     1201 * Reset the week parameter of the WordPress main query if needed
     1202 *
     1203 * When cropping an avatar, a $_POST['w'] var is sent, setting the 'week'
     1204 * paramater of the WordPress main query to this posted var. To avoid
     1205 * notices, we need to make sure this 'week' query var is reset to 0
     1206 *
     1207 * @since  BuddyPress (2.2.0)
     1208 *
     1209 * @param  WP_Quert $posts_query the main query object
     1210 * @uses   bp_is_group_create()
     1211 * @uses   bp_is_group_admin_page()
     1212 * @uses   bp_is_group_admin_screen() to check for a group admin screen
     1213 * @uses   bp_action_variable() to check for the group's avatar creation step
     1214 * @uses   bp_is_user_change_avatar() to check for the user's change profile screen
     1215 */
     1216function bp_core_avatar_reset_query( $posts_query = null ) {
     1217    $reset_w = false;
     1218
     1219    // Group's avatar edit screen
     1220    if ( bp_is_group_admin_page() ) {
     1221        $reset_w = bp_is_group_admin_screen( 'group-avatar' );
     1222
     1223    // Group's avatar create screen
     1224    } else if ( bp_is_group_create() ) {
     1225        /**
     1226         * we can't use bp_get_groups_current_create_step()
     1227         * as it's not set yet
     1228         */
     1229        $reset_w = 'group-avatar' === bp_action_variable( 1 );
     1230
     1231    // User's change avatar screen
     1232    } else {
     1233        $reset_w = bp_is_user_change_avatar();
     1234    }
     1235
     1236    // A user or a group is cropping an avatar
     1237    if ( true === $reset_w && isset( $_POST['avatar-crop-submit'] ) ) {
     1238        $posts_query->set( 'w', 0 );
     1239    }
     1240}
     1241add_action( 'bp_parse_query', 'bp_core_avatar_reset_query', 10, 1 );
Note: See TracChangeset for help on using the changeset viewer.