Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UR-1170 Fix - User fields not saving #600

Merged
merged 4 commits into from
Sep 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions includes/functions-ur-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,8 @@ function ur_get_registered_user_meta_fields() {
/**
* Returns user registration meta fields with prefix before registration.
*
* @param string $field_name Field name.
*
* @return string
*/
function ur_get_field_name_with_prefix_usermeta( $field_name ) {
Expand Down Expand Up @@ -2867,12 +2869,12 @@ function ur_find_my_account_in_page( $login_page_id ) {
$post_meta_table = $wpdb->prefix . 'postmeta';

$matched = $wpdb->get_var(
$wpdb->prepare("SELECT COUNT(*) FROM {$post_table} WHERE ID = '{$login_page_id}' AND ( post_content LIKE '%[user_registration_login%' OR post_content LIKE '%[user_registration_my_account%' OR post_content LIKE '%[woocommerce_my_account%' )" )
$wpdb->prepare( "SELECT COUNT(*) FROM {$post_table} WHERE ID = '{$login_page_id}' AND ( post_content LIKE '%[user_registration_login%' OR post_content LIKE '%[user_registration_my_account%' OR post_content LIKE '%[woocommerce_my_account%' )" ) //phpcs:ignore
);

if ( $matched <= 0 ){
if ( $matched <= 0 ) {
$matched = $wpdb->get_var(
$wpdb->prepare("SELECT COUNT(*) FROM {$post_meta_table} WHERE post_id = '{$login_page_id}' AND ( meta_value LIKE '%[user_registration_login%' OR meta_value LIKE '%[user_registration_my_account%' OR meta_value LIKE '%[woocommerce_my_account%' )" )
$wpdb->prepare( "SELECT COUNT(*) FROM {$post_meta_table} WHERE post_id = '{$login_page_id}' AND ( meta_value LIKE '%[user_registration_login%' OR meta_value LIKE '%[user_registration_my_account%' OR meta_value LIKE '%[woocommerce_my_account%' )" ) //phpcs:ignore
);
}
return $matched;
Expand Down Expand Up @@ -3855,6 +3857,8 @@ function ur_parse_and_update_hidden_field( $form_data, $form_id, $user_id ) {
* UR Unserialize data.
*
* @param string $data Data that might be unserialized.
* @param array $options Options.
*
* @return mixed Unserialized data can be any type.
*
* @since 3.0.2
Expand All @@ -3864,7 +3868,7 @@ function ur_maybe_unserialize( $data, $options = array() ) {
if ( is_serialized( $data ) ) {
if ( version_compare( PHP_VERSION, '7.1.0', '>=' ) ) {
$options = wp_parse_args( $options, array( 'allowed_classes' => false ) );
return @unserialize( trim( $data ), $options );
return @unserialize( trim( $data ), $options ); //phpcs:ignore
}
return @unserialize( trim( $data ) );
}
Expand All @@ -3873,46 +3877,45 @@ function ur_maybe_unserialize( $data, $options = array() ) {
}
}

if ( ! function_exists( 'user_registration_conditional_user_meta_filter') ) {
if ( ! function_exists( 'user_registration_conditional_user_meta_filter' ) ) {
/**
* Filter user meta field when conditinal logic applied.
*
* @param array $valid_form_data Form Data.
* @param int $user_id User Id.
* @param int $form_id Form Id.
* @param int $user_id User Id.
* @param int $form_id Form Id.
* @return array array of form data.
*
* @since 3.0.4
*/
function user_registration_conditional_user_meta_filter( $valid_form_data, $user_id, $form_id ) {
if ( $user_id <= 0 ) {
return;
return $valid_form_data;
}

$field_name = '';
$hidden_field = $_POST['urcl_hide_fields'];
$hidden_field = isset( $_POST['urcl_hide_fields'] ) ? ur_clean( $_POST['urcl_hide_fields'] ) : array(); //phpcs:ignore

if ( ! isset( $hidden_field ) ) {
return;
if ( empty( $hidden_field ) ) {
return $valid_form_data;
}

$hidden_array_field = json_decode( stripslashes( $hidden_field ) );

if ( isset( $_POST['action'] ) && 'user_registration_user_form_submit' === $_POST['action'] ) {
if ( isset( $_POST['action'] ) && 'user_registration_user_form_submit' === $_POST['action'] ) { //phpcs:ignore
foreach ( $hidden_array_field as $field ) {
$field_name = $field;
if ( in_array( $field_name, array_keys( $valid_form_data ) ) ) {
unset( $valid_form_data[$field_name] );
unset( $valid_form_data[ $field_name ] );
}
}
} else {
foreach ( $hidden_array_field as $field ) {
$field_name = 'user_registration_' . $field;
if ( in_array( $field_name, array_keys( $valid_form_data ) ) ) {
unset( $valid_form_data[$field_name] );
unset( $valid_form_data[ $field_name ] );
}
}

}

return $valid_form_data;
Expand Down
Loading