| 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 | */ |
| 1216 | function 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 | } |
| 1241 | add_action( 'bp_parse_query', 'bp_core_avatar_reset_query', 10, 1 ); |