| 1 | Index: src/bp-members/bp-members-screens.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- src/bp-members/bp-members-screens.php (revision 11231) |
|---|
| 4 | +++ src/bp-members/bp-members-screens.php (working copy) |
|---|
| 5 | @@ -149,10 +149,7 @@ |
|---|
| 6 | |
|---|
| 7 | // Loop through the posted fields formatting any datebox values then validate the field. |
|---|
| 8 | foreach ( (array) $profile_field_ids as $field_id ) { |
|---|
| 9 | - if ( !isset( $_POST['field_' . $field_id] ) ) { |
|---|
| 10 | - if ( !empty( $_POST['field_' . $field_id . '_day'] ) && !empty( $_POST['field_' . $field_id . '_month'] ) && !empty( $_POST['field_' . $field_id . '_year'] ) ) |
|---|
| 11 | - $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', strtotime( $_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year'] ) ); |
|---|
| 12 | - } |
|---|
| 13 | + bp_xprofile_maybe_format_datebox_post_data( $field_id ); |
|---|
| 14 | |
|---|
| 15 | // Create errors for required fields without values. |
|---|
| 16 | if ( xprofile_check_is_required_field( $field_id ) && empty( $_POST[ 'field_' . $field_id ] ) && ! bp_current_user_can( 'bp_moderate' ) ) |
|---|
| 17 | @@ -218,19 +215,10 @@ |
|---|
| 18 | // Let's compact any profile field info into usermeta. |
|---|
| 19 | $profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] ); |
|---|
| 20 | |
|---|
| 21 | - // Loop through the posted fields formatting any datebox values then add to usermeta - @todo This logic should be shared with the same in xprofile_screen_edit_profile(). |
|---|
| 22 | + // Loop through the posted fields formatting any datebox values then add to usermeta |
|---|
| 23 | foreach ( (array) $profile_field_ids as $field_id ) { |
|---|
| 24 | - if ( ! isset( $_POST['field_' . $field_id] ) ) { |
|---|
| 25 | + bp_xprofile_maybe_format_datebox_post_data( $field_id ); |
|---|
| 26 | |
|---|
| 27 | - if ( ! empty( $_POST['field_' . $field_id . '_day'] ) && ! empty( $_POST['field_' . $field_id . '_month'] ) && ! empty( $_POST['field_' . $field_id . '_year'] ) ) { |
|---|
| 28 | - // Concatenate the values. |
|---|
| 29 | - $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year']; |
|---|
| 30 | - |
|---|
| 31 | - // Turn the concatenated value into a timestamp. |
|---|
| 32 | - $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', strtotime( $date_value ) ); |
|---|
| 33 | - } |
|---|
| 34 | - } |
|---|
| 35 | - |
|---|
| 36 | if ( !empty( $_POST['field_' . $field_id] ) ) |
|---|
| 37 | $usermeta['field_' . $field_id] = $_POST['field_' . $field_id]; |
|---|
| 38 | Index: src/bp-xprofile/bp-xprofile-functions.php |
|---|
| 39 | =================================================================== |
|---|
| 40 | --- src/bp-xprofile/bp-xprofile-functions.php (revision 11231) |
|---|
| 41 | +++ src/bp-xprofile/bp-xprofile-functions.php (working copy) |
|---|
| 42 | @@ -1287,3 +1287,26 @@ |
|---|
| 43 | |
|---|
| 44 | return $field_ids; |
|---|
| 45 | } |
|---|
| 46 | + |
|---|
| 47 | +/** |
|---|
| 48 | + * Formats any datebox values passed through a POST request |
|---|
| 49 | + * |
|---|
| 50 | + * @since 2.8.0 |
|---|
| 51 | + * |
|---|
| 52 | + * @param int $field_id The id of the current field being looped through. |
|---|
| 53 | + * @return void This function only changes the global $_POST that should contain the datebox data. |
|---|
| 54 | + */ |
|---|
| 55 | +function bp_xprofile_maybe_format_datebox_post_data( $field_id ) { |
|---|
| 56 | + if ( ! isset( $_POST['field_' . $field_id ] ) ) { |
|---|
| 57 | + if ( ! empty( $_POST['field_' . $field_id . '_day'] ) && ! empty( $_POST['field_' . $field_id . '_month'] ) && ! empty( $_POST['field_' . $field_id . '_year'] ) ) { |
|---|
| 58 | + // Concatenate the values. |
|---|
| 59 | + $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year']; |
|---|
| 60 | + |
|---|
| 61 | + // Check that the concatenated value can be turned into a timestamp. |
|---|
| 62 | + if ( $timestamp = strtotime( $date_value ) ) { |
|---|
| 63 | + // Add the timestamp to the global $_POST that should contain the datebox data. |
|---|
| 64 | + $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', $timestamp ); |
|---|
| 65 | + } |
|---|
| 66 | + } |
|---|
| 67 | + } |
|---|
| 68 | +} |
|---|
| 69 | Index: src/bp-xprofile/bp-xprofile-screens.php |
|---|
| 70 | =================================================================== |
|---|
| 71 | --- src/bp-xprofile/bp-xprofile-screens.php (revision 11231) |
|---|
| 72 | +++ src/bp-xprofile/bp-xprofile-screens.php (working copy) |
|---|
| 73 | @@ -85,21 +85,10 @@ |
|---|
| 74 | $posted_field_ids = wp_parse_id_list( $_POST['field_ids'] ); |
|---|
| 75 | $is_required = array(); |
|---|
| 76 | |
|---|
| 77 | - // Loop through the posted fields formatting any datebox values |
|---|
| 78 | - // then validate the field. |
|---|
| 79 | + // Loop through the posted fields formatting any datebox values then validate the field. |
|---|
| 80 | foreach ( (array) $posted_field_ids as $field_id ) { |
|---|
| 81 | - if ( !isset( $_POST['field_' . $field_id] ) ) { |
|---|
| 82 | + bp_xprofile_maybe_format_datebox_post_data( $field_id ); |
|---|
| 83 | |
|---|
| 84 | - if ( !empty( $_POST['field_' . $field_id . '_day'] ) && !empty( $_POST['field_' . $field_id . '_month'] ) && !empty( $_POST['field_' . $field_id . '_year'] ) ) { |
|---|
| 85 | - // Concatenate the values. |
|---|
| 86 | - $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year']; |
|---|
| 87 | - |
|---|
| 88 | - // Turn the concatenated value into a timestamp. |
|---|
| 89 | - $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', strtotime( $date_value ) ); |
|---|
| 90 | - } |
|---|
| 91 | - |
|---|
| 92 | - } |
|---|
| 93 | - |
|---|
| 94 | $is_required[ $field_id ] = xprofile_check_is_required_field( $field_id ) && ! bp_current_user_can( 'bp_moderate' ); |
|---|
| 95 | if ( $is_required[$field_id] && empty( $_POST['field_' . $field_id] ) ) { |
|---|
| 96 | $errors = true; |
|---|
| 97 | Index: src/bp-xprofile/classes/class-bp-xprofile-user-admin.php |
|---|
| 98 | =================================================================== |
|---|
| 99 | --- src/bp-xprofile/classes/class-bp-xprofile-user-admin.php (revision 11231) |
|---|
| 100 | +++ src/bp-xprofile/classes/class-bp-xprofile-user-admin.php (working copy) |
|---|
| 101 | @@ -227,17 +227,8 @@ |
|---|
| 102 | |
|---|
| 103 | // Loop through the posted fields formatting any datebox values then validate the field. |
|---|
| 104 | foreach ( (array) $posted_field_ids as $field_id ) { |
|---|
| 105 | - if ( ! isset( $_POST['field_' . $field_id ] ) ) { |
|---|
| 106 | - if ( ! empty( $_POST['field_' . $field_id . '_day'] ) && ! empty( $_POST['field_' . $field_id . '_month'] ) && ! empty( $_POST['field_' . $field_id . '_year'] ) ) { |
|---|
| 107 | + bp_xprofile_maybe_format_datebox_post_data( $field_id ); |
|---|
| 108 | |
|---|
| 109 | - // Concatenate the values. |
|---|
| 110 | - $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year']; |
|---|
| 111 | - |
|---|
| 112 | - // Turn the concatenated value into a timestamp. |
|---|
| 113 | - $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', strtotime( $date_value ) ); |
|---|
| 114 | - } |
|---|
| 115 | - } |
|---|
| 116 | - |
|---|
| 117 | $is_required[ $field_id ] = xprofile_check_is_required_field( $field_id ) && ! bp_current_user_can( 'bp_moderate' ); |
|---|
| 118 | if ( $is_required[ $field_id ] && empty( $_POST['field_' . $field_id ] ) ) { |
|---|
| 119 | $redirect_to = add_query_arg( 'error', '2', $redirect_to ); |
|---|