| 1199 | |
| 1200 | /** |
| 1201 | * Is the user changing an avatar (profile or group) ? |
| 1202 | * |
| 1203 | * @since BuddyPress (2.2.0) |
| 1204 | * |
| 1205 | * @uses bp_is_group_create() |
| 1206 | * @uses bp_is_group_admin_page() |
| 1207 | * @uses bp_is_group_admin_screen() to check for a group admin screen |
| 1208 | * @uses bp_action_variable() to check for the group's avatar creation step |
| 1209 | * @uses bp_is_user_change_avatar() to check for the user's change profile screen |
| 1210 | * @return bool true if on a "change avatar" screen, false otherwise |
| 1211 | */ |
| 1212 | function bp_core_avatar_is_crop_step() { |
| 1213 | $retval = false; |
| 1214 | |
| 1215 | /** |
| 1216 | * Use core template functions checks before specific to the groups component ones. |
| 1217 | */ |
| 1218 | if ( bp_is_group_admin_page() ) { |
| 1219 | $retval = (bool) bp_is_group_admin_screen( 'group-avatar' ); |
| 1220 | } else if ( bp_is_group_create() ) { |
| 1221 | // we can't use bp_get_groups_current_create_step() as it's not set yet |
| 1222 | $retval = (bool) 'group-avatar' == bp_action_variable( 1 ); |
| 1223 | } else { |
| 1224 | $retval = bp_is_user_change_avatar(); |
| 1225 | } |
| 1226 | |
| 1227 | return $retval; |
| 1228 | } |
| 1229 | |
| 1230 | /** |
| 1231 | * Reset the week argument of the main query if needed |
| 1232 | * |
| 1233 | * When cropping an avatar, a $_POST['w'] var is sent, setting |
| 1234 | * the 'week' paramater of WordPress main query to this posted var. |
| 1235 | * To avoid notices we need to make sure this query var is reset to 0 |
| 1236 | * |
| 1237 | * @since BuddyPress (2.2.0) |
| 1238 | * |
| 1239 | * @param WP_Quert $posts_query the main query object |
| 1240 | */ |
| 1241 | function bp_core_avatar_reset_query( $posts_query = null ) { |
| 1242 | if ( bp_core_avatar_is_crop_step() && isset( $_POST['avatar-crop-submit'] ) ) { |
| 1243 | $posts_query->set( 'w', 0 ); |
| 1244 | } |
| 1245 | } |
| 1246 | add_action( 'bp_parse_query', 'bp_core_avatar_reset_query', 10, 1 ); |