query_vars['user-logout'] ) && ! empty( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'], 'user-logout' ) ) { //PHPCS:ignore;
// Logout.
$redirect_url = str_replace( '/user-logout', '', $wp->request );
/**
* Filter the redirect after logout url.
*
* @param string $redirect_url The redirect url.
*/
$redirect_url = apply_filters( 'user_registration_redirect_after_logout', $redirect_url );
// Check if external url is present in URL.
if ( isset( $_GET['redirect_to_on_logout'] ) ) {
wp_logout();
wp_redirect( esc_url_raw( wp_unslash( $_GET['redirect_to_on_logout'] ) ) );
exit;
}
wp_safe_redirect( str_replace( '&', '&', wp_logout_url( $redirect_url ) ) );
exit;
} elseif ( isset( $wp->query_vars['user-logout'] ) && 'true' === $wp->query_vars['user-logout'] ) {
/**
* Filter the redirect after logout url.
*
* @param string $redirect_url The redirect url.
*/
$redirect_url = apply_filters( 'user_registration_redirect_after_logout', esc_url_raw( ur_get_page_permalink( 'user-logout' ) ) );
// Redirect to the correct logout endpoint.
wp_safe_redirect( $redirect_url );
exit;
}
}
if ( ! function_exists( 'ur_get_form_redirect_url' ) ) {
/**
* Returns redirect url setup in form settings.
*
* @param integer $form_id Form Id.
* @param string $redirect_url Fallback Url.
* @param boolean $maybe_translate Whether to translate url.
*
* @return string
*/
function ur_get_form_redirect_url( $form_id = 0, $redirect_url = '', $maybe_translate = true ) {
$login_option = ur_get_form_setting_by_key( $form_id, 'user_registration_form_setting_login_options' );
$paypal_is_enabled = ur_string_to_bool( ur_get_single_post_meta( $form_id, 'user_registration_enable_paypal_standard', false ) );
if ( ! $paypal_is_enabled ) {
if ( empty( $redirect_url ) ) {
// Getting redirect options from global settings for backward compatibility.
$redirect_url = get_option( 'user_registration_general_setting_redirect_options', $redirect_url );
}
if ( ! empty( $form_id ) ) {
$redirect_option = ur_get_single_post_meta( $form_id, 'user_registration_form_setting_redirect_after_registration', 'no-redirection' );
switch ( $redirect_option ) {
case 'no-redirection':
$redirect_url = '';
break;
case 'internal-page':
$selected_page = ur_get_single_post_meta( $form_id, 'user_registration_form_setting_redirect_page', '' );
if ( ! empty( $selected_page ) ) {
$page_url = get_permalink( $selected_page );
$redirect_url = $page_url;
}
break;
case 'external-url':
$external_url = ur_get_single_post_meta( $form_id, 'user_registration_form_setting_redirect_options', $redirect_url );
$redirect_url = $external_url;
break;
case 'previous-page':
$redirect_url = apply_filters( 'user_registration_redirection_back_to_previous_page_url', isset( $_SERVER['HTTP_REFERER'] ) ? esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : $redirect_url, $form_id );
break;
default:
}
if ( empty( $redirect_url ) && 'auto_login' === $login_option ) {
/**
* Filter to modify the auto login redirection.
*
* @param string $my_account_page_url The my account page url.
*/
$redirect_url = apply_filters( 'user_registration_auto_login_redirection', ur_get_my_account_url() );
}
}
if ( $maybe_translate ) {
$redirect_url = ur_string_translation( $form_id, 'user_registration_form_setting_redirect_options', $redirect_url );
}
}
/**
* Filter the form redirect url.
* It depends on the form.
*
* @param string $redirect_url The redirect url.
* @param int $form_id The form ID.
*/
return apply_filters( 'user_registration_form_redirect_url', $redirect_url, $form_id );
}
}
/**
* Add body classes for UR pages.
*
* @param array $classes Classes.
*
* @return array
*/
function ur_body_class( $classes ) {
$classes = (array) $classes;
$classes[] = 'user-registration-page';
if ( is_ur_account_page() ) {
$classes[] = 'user-registration-account';
}
foreach ( UR()->query->query_vars as $key => $value ) {
if ( is_ur_endpoint_url( $key ) ) {
$classes[] = 'user-registration-' . sanitize_html_class( $key );
}
}
return array_unique( $classes );
}
if ( ! function_exists( 'user_registration_form_field' ) ) {
/**
* Outputs a form fields on frontend.
*
* @param string $key Key.
* @param mixed $args Arguments.
* @param string $value (default: null).
* @param string $current_row (default: empty).
*
* @return string
*/
function user_registration_form_field( $key, $args, $value = null, $current_row = '', $is_edit = false ) {
/* Conditional Logic codes */
$rules = array();
$rules['conditional_rules'] = isset( $args['conditional_rules'] ) ? $args['conditional_rules'] : '';
$rules['logic_gate'] = isset( $args['logic_gate'] ) ? $args['logic_gate'] : '';
$rules['rules'] = isset( $args['rules'] ) ? $args['rules'] : array();
$rules['required'] = isset( $args['required'] ) ? $args['required'] : '';
foreach ( $rules['rules'] as $rules_key => $rule ) {
if ( empty( $rule['field'] ) ) {
unset( $rules['rules'][ $rules_key ] );
}
}
$required = '';
$rules['rules'] = array_values( $rules['rules'] );
$rules = ( ! empty( $rules['rules'] ) && isset( $args['enable_conditional_logic'] ) ) ? wp_json_encode( $rules ) : '';
/*Conditonal Logic codes end*/
$defaults = array(
'type' => 'text',
'label' => '',
'description' => '',
'placeholder' => '',
'size' => false,
'min' => false,
'max' => false,
'required' => false,
'autocomplete' => false,
'id' => $key,
'class' => array(),
'input_class' => array(),
'return' => false,
'options' => array(),
'custom_attributes' => array(),
'validate' => array(),
'default' => '',
'autofocus' => '',
'priority' => '',
);
$args = wp_parse_args( $args, $defaults );
/**
* Filters the arguments for a user registration form field.
*
* The 'user_registration_form_field_args' filter allows developers to modify
* the arguments (args) for a specific form field during the user registration
* process. It provides an opportunity to customize the field arguments based on
* the original args, field key, and field value.
*
* @param array $args The original arguments for the form field.
* @param string $key The key identifying the form field.
* @param mixed $value The value of the form field.
*/
$args = apply_filters( 'user_registration_form_field_args', $args, $key, $value );
if ( true === ur_string_to_bool( $args['required'] ) ) {
$args['class'][] = 'validate-required';
$args['custom_attributes']['required'] = 'required';
$required = ' * ';
} else {
$args['required'] = '';
}
if ( ( is_null( $value ) || empty( $value ) ) && ! is_numeric( $value ) ) {
$value = $args['default'];
}
// Custom attribute handling.
$custom_attributes = array();
$args['custom_attributes'] = array_filter( (array) $args['custom_attributes'] );
if ( $args['size'] ) {
$args['custom_attributes']['maxlength'] = absint( $args['size'] );
}
if ( ! empty( $args['min'] ) || '0' === $args['min'] ) {
$args['custom_attributes']['min'] = $args['min'];
}
if ( isset( $args['min-characters'] ) ) {
if ( ! empty( $args['min-characters'] ) || '0' === $args['min-characters'] ) {
$args['custom_attributes']['minlength'] = $args['min-characters'];
}
}
if ( isset( $args['max-characters'] ) ) {
if ( ! empty( $args['max-characters'] ) || '0' === $args['max-characters'] ) {
$args['custom_attributes']['maxlength'] = $args['max-characters'];
}
}
if ( isset( $args['min-words'] ) ) {
if ( ! empty( $args['min-words'] ) || '0' === $args['min-words'] ) {
$args['custom_attributes']['data-min-words'] = $args['min-words'];
}
}
if ( isset( $args['max-words'] ) ) {
if ( ! empty( $args['max-words'] ) || '0' === $args['max-words'] ) {
$args['custom_attributes']['max-words'] = $args['max-words'];
}
}
if ( ! empty( $args['max'] ) || '0' === $args['max'] ) {
$args['custom_attributes']['max'] = $args['max'];
}
if ( ! empty( $args['step'] ) ) {
$args['custom_attributes']['step'] = $args['step'];
}
if ( ! empty( $args['autocomplete'] ) ) {
$args['custom_attributes']['autocomplete'] = $args['autocomplete'];
}
if ( true === $args['autofocus'] ) {
$args['custom_attributes']['autofocus'] = 'autofocus';
}
if ( isset( $args['default_value'] ) && ! empty( $args['default_value'] ) ) {
$args['custom_attributes']['data-default'] = is_array( $args['default_value'] ) ? implode( ', ', $args['default_value'] ) : $args['default_value'];
}
if ( isset( $args['default'] ) && ! empty( $args['default'] ) ) {
$args['custom_attributes']['data-default'] = $args['default'];
}
if ( ! empty( $args['custom_attributes'] ) && is_array( $args['custom_attributes'] ) ) {
foreach ( $args['custom_attributes'] as $attribute => $attribute_value ) {
$attribute_value = is_array( $attribute_value ) ? json_encode( $attribute_value ) : $attribute_value;
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
}
}
if ( ! empty( $args['validate'] ) ) {
foreach ( $args['validate'] as $validate ) {
$args['class'][] = 'validate-' . $validate;
}
}
$tooltip_html = '';
if ( isset( $args['tooltip'] ) && ur_string_to_bool( $args['tooltip'] ) ) {
$tooltip_html = ur_help_tip( $args['tooltip_message'], false, 'ur-portal-tooltip' );
} elseif ( isset( $args['tip'] ) ) {
$tooltip_html = ur_help_tip( $args['tip'], false, 'user-registration-help-tip tooltipstered' );
}
$cl_html = '';
if ( isset( $args['enable_conditional_logic'] ) && true === $args['enable_conditional_logic'] ) {
$cl_map = isset( $args['cl_map'] ) ? $args['cl_map'] : '';
$cl_html = sprintf( 'data-conditional-logic-enabled="1" data-conditional-logic-map="%s"', esc_attr( $cl_map ) );
}
$field = '';
$label_id = $args['id'];
$sort = $args['priority'] ? $args['priority'] : '';
$field_container = '
%3$s
';
$class = '';
if ( ! is_admin() ) {
$form_id = isset( $args['form_id'] ) ? $args['form_id'] : '';
/**
* Filters the enabled class for the icon associated with a user registration form field.
*
* The 'user_registration_field_icon_enabled_class' filter allows developers to modify
* the class name representing the enabled state of the icon associated with a form field.
* It provides an opportunity to customize the enabled class based on the original class
* and the form ID.
*
* @param string $class The original class representing the enabled state of the icon.
* @param int $form_id The ID of the user registration form.
*/
$class = apply_filters( 'user_registration_field_icon_enabled_class', $class, $form_id );
}
switch ( $args['type'] ) {
case 'title':
$field .= '' . esc_html( $args['title'] ) . ' ';
break;
case 'textarea':
$field .= '';
$field .= ' 0
';
$field .= '
' . ( isset( $args['max-words'] ) ? '/' . $args['max-words'] . ' ' . __('words', 'user-registration') : ( isset( $args['max-characters'] ) ? '/' . $args['max-characters'] . ' '. __('characters'. 'user-registration') : ' ' . __('characters', 'user-registration') ) );
$field .= '
';
break;
case 'checkbox':
$field_key = isset( $args['field_key'] ) ? $args['field_key'] : '';
$default_value = isset( $args['default_value'] ) ? $args['default_value'] : ''; // Backward compatibility. Modified since 1.5.7.
$default = ! empty( $value ) ? $value : $default_value;
$select_all = isset( $args['select_all'] ) ? ur_string_to_bool( $args['select_all'] ) : false;
$options = isset( $args['options'] ) ? $args['options'] : array();
$image_options = isset( $args['image_options'] ) ? $args['image_options'] : array();
$choice_limit = isset( $args['choice_limit'] ) ? $args['choice_limit'] : '';
$choice_limit_attr = '';
if ( '' !== $choice_limit ) {
$choice_limit_attr = 'data-choice-limit="' . $choice_limit . '"';
}
if ( isset( $args['image_choice'] ) && ur_string_to_bool( $args['image_choice'] ) && isset( $image_options ) && array_filter( $image_options ) ) {
if ( ! empty( $default ) ) {
$default = ( is_serialized( $default ) ) ? unserialize( $default, array( 'allowed_classes' => false ) ) : $default; //phpcs:ignore;
}
$choices = isset( $image_options ) ? $image_options : array();
$field = '';
$field .= $args['label'] . $required . $tooltip_html . ' ';
$checkbox_start = 0;
$field .= '';
} elseif ( isset( $options ) && array_filter( $options ) ) {
if ( ! empty( $default ) ) {
$default = ( is_serialized( $default ) ) ? unserialize( $default, array( 'allowed_classes' => false ) ) : ( is_array( $default ) ? $default : ( empty( json_decode( $default ) ) ? $default : json_decode( $default ) ) ); //phpcs:ignore;
}
$choices = isset( $options ) ? $options : array();
$field = '';
$field .= $args['label'] . $required . $tooltip_html . ' ';
$checkbox_start = 0;
$field .= '';
} else {
$field = '
'
. $args['label'] . $required . $tooltip_html . ' ';
}
break;
case 'toggle':
$default_value = isset( $args['default_value'] ) ? $args['default_value'] : ''; // Backward compatibility. Modified since 1.5.7.
$value = ! empty( $value ) ? $value : $default_value;
$select_all = isset( $args['select_all'] ) ? ur_string_to_bool( $args['select_all'] ) : false;
$options = isset( $args['options'] ) ? $args['options'] : ( $args['choices'] ? $args['choices'] : array() ); // $args['choices'] for backward compatibility. Modified since 1.5.7.
$choice_limit = isset( $args['choice_limit'] ) ? $args['choice_limit'] : '';
$choice_limit_attr = '';
$field = '';
$field .= '';
$field .= ' ';
$field .= ' ';
$field .= ' ';
$field .= '' . $args['label'] . wp_kses_post( $tooltip_html ) . ' ';
$field .= '
';
break;
case 'radio-group':
$default_value = isset( $args['default_value'] ) ? $args['default_value'] : ''; // Backward compatibility. Modified since 1.5.7.
$default = ! empty( $value ) ? $value : $default_value;
$select_all = isset( $args['select_all'] ) ? ur_string_to_bool( $args['select_all'] ) : false;
$options = isset( $args['options'] ) ? $args['options'] : ( $args['choices'] ? $args['choices'] : array() ); // $args['choices'] for backward compatibility. Modified since 1.5.7.
$choice_limit = isset( $args['choice_limit'] ) ? $args['choice_limit'] : '';
if ( ! empty( $args['options'] ) ) {
$field .= '';
}
break;
case 'password':
$extra_params_key = str_replace( 'user_registration_', 'ur_', $key ) . '_params';
$extra_params = json_decode( get_user_meta( get_current_user_id(), $extra_params_key, true ) );
$field .= ' ';
if ( empty( $extra_params ) ) {
$field_container = '%3$s
';
$field .= '';
$field .= ' ';
if ( ur_option_checked( 'user_registration_login_option_hide_show_password', false ) && ! $is_edit ) {
$field .= ' ';
}
$field .= ' ';
} else {
$field .= ' ';
}
if ( ! is_admin() ) {
/**
* Filters the icon markup for a user registration form field.
*
* The 'user_registration_field_icon' filter allows developers to modify
* the icon markup associated with a specific form field during the user
* registration process. It provides an opportunity to customize the icon
* based on the original icon markup, form ID, and field arguments.
*
* @param string $field The original icon markup associated with the form field.
* @param int $form_id The ID of the user registration form.
* @param array $args The arguments for the form field.
*/
$field = apply_filters( 'user_registration_field_icon', $field, $form_id, $args );
$field .= ' ';
}
break;
case 'text':
case 'email':
case 'tel':
case 'number':
case 'url':
case 'file':
case 'timepicker':
$extra_params_key = str_replace( 'user_registration_', 'ur_', $key ) . '_params';
$extra_params = json_decode( get_user_meta( get_current_user_id(), $extra_params_key, true ) );
$current_time = isset( $args['current_time'] ) ? $args['current_time'] : '';
$time_interval = isset( $args['time_interval'] ) ? $args['time_interval'] : '';
$time_format = isset( $args['time_format'] ) ? $args['time_format'] : '';
$time_range = isset( $args['time_range'] ) ? $args['time_range'] : '';
$time_min = isset( $args['time_min'] ) ? $args['time_min'] : '';
$time_max = isset( $args['time_max'] ) ? $args['time_max'] : '';
$username_length = isset( $args['username_length'] ) ? $args['username_length'] : '';
$username_character = isset( $args['username_character'] ) ? $args['username_character'] : '';
$time_slot_booking = isset( $args['enable_time_slot_booking'] ) ? $args['enable_time_slot_booking'] : '';
$target_date_field = isset( $args['target_date_field'] ) ? isset( $args['target_date_field'] ) : '';
$enable_calculations = $args['enable_calculations'] ?? '';
$calculation_formula = $args['calculation_formula'] ?? '';
$decimal_places = $args['decimal_places'] ?? '';
$attr = '';
if ( '' !== $username_length ) {
$attr .= 'data-username-length="' . $username_length . '"';
}
if ( $username_character ) {
$attr .= 'data-username-character="' . $username_character . '"';
}
if ( '' !== $time_interval ) {
$attr .= 'data-time-interval="' . $time_interval . '"';
}
if ( '' !== $time_format ) {
$attr .= 'data-time-format="' . $time_format . '"';
}
if ( '' !== $time_min ) {
$attr .= 'data-time-min="' . $time_min . '"';
}
if ( '' !== $time_max ) {
$attr .= 'data-time-max="' . $time_max . '"';
}
if ( $time_range ) {
$attr .= 'data-time-range="' . $time_range . '"';
}
if ( $current_time ) {
$attr .= 'data-current-time="' . $current_time . '"';
}
if ( '' !== $enable_calculations && $enable_calculations ) {
$attr .= 'readonly data-decimal-places="' . esc_attr($decimal_places) . '" data-calculation-formula="' . esc_attr($calculation_formula) . '"';
}
if ( ur_string_to_bool( $time_slot_booking ) ) {
$target_date_field = isset( $args['target_date_field'] ) ? $args['target_date_field'] : '';
$attr .= 'data-enable-time-slot-booking="' . $time_slot_booking . '"';
$attr .= 'data-target-date-field="' . $target_date_field . '"';
$class .= ' time-slot-booking ';
}
$field .= ' ';
if ( isset( $args['autocomplete_address'] ) && ur_string_to_bool( $args['autocomplete_address'] ) ) {
$attr .= 'data-autocomplete-address="' . ur_string_to_bool( $args['autocomplete_address'] ) . '"';
$attr .= 'data-address-style="' . $args['address_style'] . '"';
$attr .= 'data-current-location="' . ur_option_checked( 'user_registration_google_map_current_location', false ) . '"';
if ( 'map' == $args['address_style'] ) {
$field .= '
';
}
}
$timpicker_class = '';
if ( 'timepicker' === $args['type'] ) {
$timpicker_class = 'ur-timepicker';
}
if ( empty( $extra_params ) ) {
if ( $time_range ) {
// Extract the start and end time if the time is given in range.
$pattern = '/^(\d{1,2}:\d{2}(?:\s?[APap][Mm])?)\s+to\s+(\d{1,2}:\d{2}(?:\s?[APap][Mm])?)$/';
$start_time = '';
$end_time = '';
if ( preg_match( $pattern, $value, $times ) ) {
$start_time = $times[1];
$end_time = $times[2];
}
$field .= '';
$field .= ' ';
$field .= ' ';
$field .= ' ';
$field .= '
';
} else {
$disabled = ( ( ( isset( $_REQUEST['page'] ) && isset( $args['field_key'] ) && 'user-registration-users' == $_REQUEST['page'] ) && 'user_email' === $args['field_key'] ) || ( isset( $args['repeater_field'] ) && $args['repeater_field'] ) ) ? ' readonly="readonly"' : '';
$field .= ' ';
}
} elseif ( ! empty( $extra_params ) ) {
if ( $time_range ) {
$field .= ' ';
$field .= ' ';
$field .= ' ';
} else {
$field .= ' ';
}
}
if ( isset( $args['field_key'] ) && 'user_email' === $args['field_key'] ) {
$user_id = ! empty( $_REQUEST['user_id'] ) ? absint( $_REQUEST['user_id'] ) : get_current_user_id();
$pending_email = get_user_meta( $user_id, 'user_registration_pending_email', true );
$expiration = get_user_meta( $user_id, 'user_registration_pending_email_expiration', true );
$cancel_url = esc_url(
add_query_arg(
array(
'cancel_email_change' => $user_id,
'_wpnonce' => wp_create_nonce( 'cancel_email_change_nonce' ),
),
ur_get_my_account_url() . get_option( 'user_registration_myaccount_edit_profile_endpoint', 'edit-profile' )
)
);
if ( ! empty( $pending_email ) && time() <= $expiration ) {
$field .= sprintf(
/* translators: %s - Email Change Pending Message. */
'',
sprintf(
/* translators: 1: Pending email message 2: Cancel Link */
__( 'There is a pending change of your email to %1$s. Cancel ', 'user-registration' ),
$pending_email,
$cancel_url
)
);
} else {
// Remove the confirmation key, pending email and expiry date.
UR_Form_Handler::delete_pending_email_change( $user_id );
}
}
if ( ! is_admin() ) {
/**
* Filters the icon markup for a user registration form field.
*
* The 'user_registration_field_icon' filter allows developers to modify
* the icon markup associated with a specific form field during the user
* registration process. It provides an opportunity to customize the icon
* based on the original icon markup, form ID, and field arguments.
*
* @param string $field The original icon markup associated with the form field.
* @param int $form_id The ID of the user registration form.
* @param array $args The arguments for the form field.
*/
$field = apply_filters( 'user_registration_field_icon', $field, $form_id, $args );
$field .= ' ';
}
break;
case 'date':
$extra_params_key = str_replace( 'user_registration_', 'ur_', $key ) . '_params';
$extra_params = json_decode( get_user_meta( get_current_user_id(), $extra_params_key, true ) );
$date_slot_booking = isset( $args['enable_date_slot_booking'] ) ? $args['enable_date_slot_booking'] : '';
if ( ur_string_to_bool( $date_slot_booking ) ) {
$custom_attributes[] = 'data-enable-date-slot-booking="' . $date_slot_booking . '"';
$class .= ' date-slot-booking';
}
$actual_value = $value;
if ( isset( $args['custom_attributes']['data-date-format'] ) ) {
$date_format = $args['custom_attributes']['data-date-format'];
$default_date = isset( $args['custom_attributes']['data-default-date'] ) ? $args['custom_attributes']['data-default-date'] : '';
if ( empty( $value ) && ur_string_to_bool( $default_date ) ) {
$value = date_i18n( $date_format );
$actual_value = date_i18n( $date_format );
}
}
$field .= ' ';
if ( empty( $extra_params ) ) {
$field .= ' ';
$field .= ' ';
$field .= ' ';
} else {
$field .= ' ';
$field .= ' ';
$field .= ' ';
}
if ( ! is_admin() ) {
/**
* Filters the icon markup for a user registration form field.
*
* The 'user_registration_field_icon' filter allows developers to modify
* the icon markup associated with a specific form field during the user
* registration process. It provides an opportunity to customize the icon
* based on the original icon markup, form ID, and field arguments.
*
* @param string $field The original icon markup associated with the form field.
* @param int $form_id The ID of the user registration form.
* @param array $args The arguments for the form field.
*/
$field = apply_filters( 'user_registration_field_icon', $field, $form_id, $args );
}
$field .= ' ';
break;
case 'color':
$field .= ' ';
break;
case 'select':
$default_value = isset( $args['default_value'] ) ? $args['default_value'] : ''; // Backward compatibility. Modified since 1.5.7.
$value = ! empty( $value ) ? $value : $default_value;
$options = $field .= '';
$backtrace = debug_backtrace();
$parent_function = isset( $backtrace[1] ) ? $backtrace[1]['function'] : '';
$args['options'] = ( $parent_function === 'frontend_includes' ) ? apply_filters( 'override_options_for_select_field', $args['options'], $args['id'] ) : $args['options'];
if ( ! empty( $args['options'] ) ) {
// If we have a blank option, select2 needs a placeholder.
if ( '' === $value && ! empty( $args['placeholder'] ) ) {
$options .= '' . esc_html( $args['placeholder'] ) . ' ';
}
if ( isset( $args['field_key'] ) && 'country' === $args['field_key'] && empty( $args['placeholder'] ) && empty( $value ) ) {
$options .= '' . esc_html__( 'Select a country', 'user-registration' ) . ' ';
}
$custom_attributes[] = 'data-allow_clear="true"';
foreach ( $args['options'] as $option_key => $option_text ) {
$selected_attribute = '';
if ( '' !== $value ) {
$selected_attribute = selected( $value, trim( $option_key ), false );
}
$options .= '' . esc_attr( trim( $option_text ) ) . ' ';
}
$field .= '
' . $options . '
';
}
break;
case 'multiselect':
$options = $field .= '';
if ( is_serialized( $value ) ) {
$default_value = unserialize( $value, array( 'allowed_classes' => false ) ); //phpcs:ignore;
} else {
$default_value = $value;
}
$args['options'] = apply_filters( 'override_options_for_select_field', $args['options'] );
if ( ! empty( $args['options'] ) ) {
foreach ( $args['options'] as $option_key => $option_text ) {
if ( '' === $option_key ) {
// If we have a blank option, select2 needs a placeholder.
if ( empty( $args['placeholder'] ) ) {
$args['placeholder'] = $option_text ? $option_text : __( 'Choose an option', 'user-registration' );
}
$custom_attributes[] = 'data-allow_clear="true"';
}
if ( is_array( $default_value ) ) {
$options .= '' . esc_attr( trim( $option_text ) ) . ' ';
} else {
$options .= '' . esc_attr( trim( $option_text ) ) . ' ';
}
}
$field .= '
' . $options . '
';
}
break;
case 'radio':
$default_value = isset( $args['default_value'] ) ? $args['default_value'] : ''; // Backward compatibility. Modified since 1.5.7.
$value = ! empty( $value ) ? $value : $default_value;
$label_id = current( array_keys( $args['options'] ) );
if ( empty( $args['options'] ) ) {
return;
}
if ( isset( $args['image_choice'] ) && ur_string_to_bool( $args['image_choice'] ) ) {
$field .= '';
} else {
$field .= '';
}
break;
case 'html':
$content = isset( $args['html_content'] ) ? $args['html_content'] : '';
$field .= $content;
break;
case 'hidden':
$hidden_value = $args['hidden_value'] ?? $args['default'];
$custom_class = $args['custom_class'] ?? '';
$input_type = ! $is_edit ? 'type="hidden"' : 'type="text"';
if ( $is_edit ) {
$default_value = $args['default'] ?? '';
$hidden_value = ! empty( $value ) ? $value : $default_value;
$label = $args['label'] ?? 'Hidden Field';
$field .= '' . esc_html( $label ) . ' ';
$field .= '';
}
$field .= ' ';
$field .= ( $is_edit ) ? ' ' : '';
break;
case 'tinymce':
$editor_settings = array(
'name' => esc_attr( $args['id'] ),
'id' => esc_attr( $args['id'] ),
'style' => esc_attr( $args['css'] ),
'default' => esc_attr( $args['default'] ),
'class' => esc_attr( $args['class'] ),
'quicktags' => array( 'buttons' => 'em,strong,link' ),
'tinymce' => array(
'theme_advanced_buttons1' => 'bold,italic,strikethrough,separator,bullist,numlist,separator,blockquote,separator,justifyleft,justifycenter,justifyright,separator,link,unlink,separator,undo,redo,separator',
'theme_advanced_buttons2' => '',
),
'editor_css' => '',
);
$value = ! empty( $value ) ? $value : $default_value;
$field .= '';
// Output buffer for tinymce editor.
ob_start();
wp_editor( $value, $args['id'], $editor_settings );
$field .= ob_get_clean();
$field .= '
';
break;
}
// End switch().
if ( $args['description'] ) {
$field .= '' . $args['description'] . ' ';
}
if ( ! empty( $field ) ) {
$field_html = '';
if ( $args['label'] && 'checkbox' != $args['type'] && 'toggle' != $args['type'] && 'hidden' !== $args['type'] ) {
$field_html .= '' . wp_kses(
$args['label'],
array(
'a' => array(
'href' => array(),
'title' => array(),
),
'span' => array(),
)
) . $required . $tooltip_html . ' ';
}
$field_html .= $field;
$container_class = esc_attr( implode( ' ', $args['class'] ) );
$container_id = esc_attr( $args['id'] ) . '_field';
$field = sprintf( $field_container, $container_class, $container_id, $field_html );
}
/**
* Filters the form field based on its type.
*
* The dynamic 'user_registration_form_field_{type}' filter allows developers to modify
* the form field for a specific type during the user registration process. The {type}
* placeholder is replaced with the actual field type, providing a flexible way to customize
* the form field based on its type, field key, arguments, and value.
*
* @param string $field The original form field markup for the specific type.
* @param string $key The key identifying the form field.
* @param array $args The arguments for the form field.
* @param mixed $value The value of the form field.
*/
$field = apply_filters( 'user_registration_form_field_' . $args['type'], $field, $key, $args, $value, $current_row );
if ( $args['return'] ) {
return $field;
} else {
echo $field; //PHPCS:ignore;
}
}
} // End if().
if ( ! function_exists( 'user_registration_form_data' ) ) {
/**
* Get form fields to display on profile tab
*
* @param string $user_id User Id.
* @param string $form_id Form Id.
*
* @return array
*/
function user_registration_form_data( $user_id = 0, $form_id = 0 ) {
$all_meta_value = get_user_meta( $user_id );
$user_details = get_user_by( 'ID', $user_id );
$user_info = (array) $user_details->data;
$allowed_user_roles = array( 'administrator' );
$current_user = wp_get_current_user();
$is_admin = count( array_intersect( $allowed_user_roles, (array) $current_user->roles ) ) > 0;
$fields = array();
$post_content_array = ( $form_id ) ? UR()->form->get_form( $form_id, array( 'content_only' => true ) ) : array();
$all_meta_value_keys = array();
if ( gettype( $all_meta_value ) === 'array' ) {
$all_meta_value_keys = array_keys( $all_meta_value );
}
/**
* Filters all fields in the user registration profile account during rendering.
*
* The 'user_registration_profile_account_filter_all_fields' filter allows developers
* to modify all fields in the user registration profile account when rendering. It provides
* an opportunity to customize the post content array and form ID associated with the
* profile account.
*
* @param array $post_content_array The original post content array for the profile account.
* @param int $form_id The ID of the user registration form associated with the account.
* @param bool $is_admin Is the current logged in user admin
*/
$post_content_array = apply_filters( 'user_registration_profile_account_filter_all_fields', $post_content_array, $form_id, $is_admin );
foreach ( $post_content_array as $post_content_row ) {
foreach ( $post_content_row as $post_content_grid ) {
foreach ( $post_content_grid as $field ) {
$field_name = isset( $field->general_setting->field_name ) ? $field->general_setting->field_name : '';
$field_label = isset( $field->general_setting->label ) ? $field->general_setting->label : '';
$field_description = isset( $field->general_setting->description ) ? $field->general_setting->description : '';
$placeholder = isset( $field->general_setting->placeholder ) ? $field->general_setting->placeholder : '';
$options = isset( $field->general_setting->options ) ? $field->general_setting->options : array();
$field_key = isset( $field->field_key ) ? ( $field->field_key ) : '';
$field_type = isset( $field->field_key ) ? ur_get_field_type( $field_key ) : '';
$required = isset( $field->general_setting->required ) ? $field->general_setting->required : '';
$required = ur_string_to_bool( $required );
$enable_cl = isset( $field->advance_setting->enable_conditional_logic ) && ur_string_to_bool( $field->advance_setting->enable_conditional_logic );
$cl_map = isset( $field->advance_setting->cl_map ) ? $field->advance_setting->cl_map : '';
$custom_attributes = isset( $field->general_setting->custom_attributes ) ? $field->general_setting->custom_attributes : array();
$enable_validate_unique = isset( $field->advance_setting->validate_unique ) ? $field->advance_setting->validate_unique : false;
$validate_message = isset( $field->advance_setting->validation_message ) ? $field->advance_setting->validation_message : esc_html__( 'This field value needs to be unique.', 'user-registration' );
$enable_payment_slider = isset( $field->advance_setting->enable_payment_slider ) ? $field->advance_setting->enable_payment_slider : false;
$enable_image_choice = isset( $field->general_setting->image_choice ) ? $field->general_setting->image_choice : false;
$enable_image_choice = isset( $field->general_setting->image_choice ) ? $field->general_setting->image_choice : false;
$default = '';
if ( isset( $field->general_setting->default_value ) ) {
$default = $field->general_setting->default_value;
} elseif ( isset( $field->advance_setting->default_value ) ) {
$default = $field->advance_setting->default_value;
}
if ( empty( $field_label ) ) {
$field_label_array = explode( '_', $field_name );
$field_label = join( ' ', array_map( 'ucwords', $field_label_array ) );
}
if ( ! empty( $field_name ) ) {
$extra_params = array();
switch ( $field_key ) {
case 'radio':
case 'select':
$advanced_options = isset( $field->advance_setting->options ) ? $field->advance_setting->options : '';
$advanced_options = explode( ',', $advanced_options );
$extra_params['options'] = ! empty( $options ) ? $options : $advanced_options;
$extra_params['options'] = array_map( 'trim', $extra_params['options'] );
$extra_params['options'] = array_combine( $extra_params['options'], $extra_params['options'] );
$extra_params['image_choice'] = $enable_image_choice;
break;
case 'checkbox':
$advanced_options = isset( $field->advance_setting->choices ) ? $field->advance_setting->choices : '';
$advanced_options = explode( ',', $advanced_options );
$extra_params['options'] = ! empty( $options ) ? $options : $advanced_options;
$extra_params['options'] = array_map( 'trim', $extra_params['options'] );
$extra_params['options'] = array_combine( $extra_params['options'], $extra_params['options'] );
$extra_params['image_choice'] = $enable_image_choice;
break;
case 'date':
$date_format = isset( $field->advance_setting->date_format ) ? $field->advance_setting->date_format : '';
$min_date = isset( $field->advance_setting->min_date ) ? str_replace( '/', '-', $field->advance_setting->min_date ) : '';
$max_date = isset( $field->advance_setting->max_date ) ? str_replace( '/', '-', $field->advance_setting->max_date ) : '';
$set_current_date = isset( $field->advance_setting->set_current_date ) ? ur_string_to_bool( $field->advance_setting->set_current_date ) : '';
$enable_date_range = isset( $field->advance_setting->enable_date_range ) ? ur_string_to_bool( $field->advance_setting->enable_date_range ) : '';
$date_localization = isset( $field->advance_setting->date_localization ) ? $field->advance_setting->date_localization : '';
$extra_params['custom_attributes']['data-date-format'] = $date_format;
if ( isset( $field->advance_setting->enable_min_max ) && ur_string_to_bool( $field->advance_setting->enable_min_max ) ) {
$extra_params['custom_attributes']['data-min-date'] = '' !== $min_date ? date_i18n( $date_format, strtotime( $min_date ) ) : '';
$extra_params['custom_attributes']['data-max-date'] = '' !== $max_date ? date_i18n( $date_format, strtotime( $max_date ) ) : '';
}
$extra_params['custom_attributes']['data-default-date'] = $set_current_date;
$extra_params['custom_attributes']['data-mode'] = $enable_date_range;
$extra_params['custom_attributes']['data-locale'] = $date_localization;
break;
case 'country':
$class_name = ur_load_form_field_class( $field_key );
$extra_params['options'] = $class_name::get_instance()->get_selected_countries( $form_id, $field_name );
break;
case 'file':
$extra_params['max_files'] = isset( $field->general_setting->max_files ) ? $field->general_setting->max_files : '';
break;
case 'phone':
$extra_params['phone_format'] = isset( $field->general_setting->phone_format ) ? $field->general_setting->phone_format : '';
break;
default:
break;
}
$extra_params['default'] = isset( $all_meta_value[ 'user_registration_' . $field_name ][0] ) ? $all_meta_value[ 'user_registration_' . $field_name ][0] : ( isset( $all_meta_value[ $field_name ][0] ) ? $all_meta_value[ $field_name ][0] : '' );
if ( empty( $extra_params['default'] ) ) {
$extra_params['default'] = $default;
}
if ( empty( $extra_params['default'] ) ) {
$extra_params['default'] = isset( $user_info[ $field_name ] ) ? $user_info[ $field_name ] : '';
}
$user_profile_fields = ur_get_user_profile_field_only();
$is_admin_request = $_REQUEST['is_admin_user'] ?? false;
if ( $is_admin_request || ( isset( $_REQUEST['action'] ) && sanitize_text_field( $_REQUEST['action'] ) === 'edit' && $user_id !== get_current_user_id() ) ) {
array_push( $user_profile_fields, 'user_pass' );
}
if ( in_array( $field_key, $user_profile_fields ) ) {
$fields[ 'user_registration_' . $field_name ] = array(
'label' => ur_string_translation( $form_id, 'user_registration_' . $field_name . '_label', $field_label ),
'description' => ur_string_translation( $form_id, 'user_registration_' . $field_name . '_description', $field_description ),
'type' => $field_type,
'placeholder' => ur_string_translation( $form_id, 'user_registration_' . $field_name . '_placeholder', $placeholder ),
'field_key' => $field_key,
'required' => $required,
);
if ( true === $enable_cl ) {
$fields[ 'user_registration_' . $field_name ]['enable_conditional_logic'] = $enable_cl;
$fields[ 'user_registration_' . $field_name ]['cl_map'] = $cl_map;
}
}
if ( true === $enable_cl ) {
$fields[ 'user_registration_' . $field_name ]['enable_conditional_logic'] = $enable_cl;
$fields[ 'user_registration_' . $field_name ]['cl_map'] = $cl_map;
}
if ( count( $custom_attributes ) > 0 ) {
$extra_params['custom_attributes'] = $custom_attributes;
}
if ( isset( $field->advance_setting->validate_unique ) ) {
$fields[ 'user_registration_' . $field_name ]['validate_unique'] = $enable_validate_unique;
$fields[ 'user_registration_' . $field_name ]['validate_message'] = ur_string_translation( $form_id, 'ur_validation_message_for_duplicate', $validate_message );
}
if ( isset( $field->advance_setting->enable_payment_slider ) ) {
$fields[ 'user_registration_' . $field_name ]['enable_payment_slider'] = $enable_payment_slider;
}
if ( isset( $fields[ 'user_registration_' . $field_name ] ) && count( $extra_params ) > 0 ) {
$fields[ 'user_registration_' . $field_name ] = array_merge( $fields[ 'user_registration_' . $field_name ], $extra_params );
}
$filter_data = array(
'fields' => $fields,
'field' => $field,
'field_name' => $field_name,
);
/**
* Filters a specific field in the user registration profile account during rendering.
*
* The dynamic 'user_registration_profile_account_filter_{field_key}' filter allows developers
* to modify a specific field in the user registration profile account when rendering. The {field_key}
* placeholder is replaced with the actual field key, providing a flexible way to customize the
* field's filter data and the form ID associated with the account.
*
* @param array $filter_data The original filter data for the specific field.
* @param int $form_id The ID of the user registration form associated with the account.
*/
$filtered_data_array = apply_filters( 'user_registration_profile_account_filter_' . $field_key, $filter_data, $form_id );
if ( isset( $filtered_data_array['fields'] ) ) {
$fields = $filtered_data_array['fields'];
}
} // End if().
} // End foreach().
} // End foreach().
} // End foreach().
/**
* Filter to add extra user data to profile details if any.
*/
$fields = apply_filters( 'user_registration_user_extra_profile_details', $fields, $form_id, $all_meta_value );
return $fields;
}
} // End if().
if ( ! function_exists( 'user_registration_account_content' ) ) {
/**
* My Account content output.
*/
function user_registration_account_content() {
global $wp;
if ( ! empty( $wp->query_vars ) ) {
foreach ( $wp->query_vars as $key => $value ) {
// Ignore pagename param.
if ( 'pagename' === $key ) {
continue;
}
if ( has_action( 'user_registration_account_' . $key . '_endpoint' ) ) {
/**
* Action to add the my account content.
*
* Dynamic portion of hook, $key
*
* @param array $value The key values.
*/
do_action( 'user_registration_account_' . $key . '_endpoint', $value );
return;
}
}
}
// No endpoint found? Default to dashboard.
ur_get_template(
'myaccount/dashboard.php',
array(
'current_user' => get_user_by( 'id', get_current_user_id() ),
'endpoint_label' => ur_get_account_menu_items()['dashboard'],
)
);
}
}
if ( ! function_exists( 'user_registration_account_navigation' ) ) {
/**
* My Account navigation template.
*/
function user_registration_account_navigation() {
ur_get_template( 'myaccount/navigation.php' );
}
}
if ( ! function_exists( 'user_registration_account_dashboard' ) ) {
/**
* My Account > Dashboard template.
*/
function user_registration_account_dashboard() {
ur_get_template(
'myaccount/dashboard.php',
array(
'current_user' => get_user_by( 'id', get_current_user_id() ),
'endpoint_label' => ur_get_account_menu_items()['dashboard'],
)
);
}
}
if ( ! function_exists( 'user_registration_account_edit_profile' ) ) {
/**
* My Account > Edit profile template.
*/
function user_registration_account_edit_profile() {
UR_Shortcode_My_Account::edit_profile();
}
}
if ( ! function_exists( 'user_registration_account_edit_account' ) ) {
/**
* My Account > Edit account template.
*/
function user_registration_account_edit_account() {
UR_Shortcode_My_Account::edit_account();
}
}
/**
* Get logout endpoint.
*
* @param string $redirect URL.
*
* @return string
*/
function ur_logout_url( $redirect = '' ) {
$logout_endpoint = get_option( 'user_registration_logout_endpoint', 'user-logout' );
global $post;
$wp_version = '5.0';
$post_content = isset( $post->post_content ) ? $post->post_content : '';
if ( ( ur_post_content_has_shortcode( 'user_registration_login' ) || ur_post_content_has_shortcode( 'user_registration_my_account' ) ) && is_user_logged_in() ) {
if ( version_compare( $GLOBALS['wp_version'], $wp_version, '>=' ) ) {
$blocks = parse_blocks( $post_content );
$new_shortcode = '';
foreach ( $blocks as $block ) {
if ( ( 'core/shortcode' === $block['blockName'] || 'core/paragraph' === $block['blockName'] ) && isset( $block['innerHTML'] ) ) {
$new_shortcode = ( 'core/shortcode' === $block['blockName'] ) ? $block['innerHTML'] : wp_strip_all_tags( $block['innerHTML'] );
} elseif ( 'user-registration/form-selector' === $block['blockName'] && isset( $block['attrs']['shortcode'] ) ) {
$new_shortcode = '[' . $block['attrs']['shortcode'] . ']';
}
if ( 'user-registration/form-selector' === $block['blockName'] && isset( $block['attrs']['logoutUrl'] ) ) {
$redirect = $block['attrs']['logoutUrl'];
}
}
preg_match( '/' . get_shortcode_regex() . '/s', $new_shortcode, $matches );
} else {
preg_match( '/' . get_shortcode_regex() . '/s', $post_content, $matches );
}
$matches_attr = isset( $matches[3] ) ? $matches[3] : '';
$attributes = shortcode_parse_atts( $matches_attr );
/**
* Introduced logout_redirect parameter in user_registration_my_account shortcode.
*
* @since 1.7.5
*/
if ( isset( $attributes['logout_redirect'] ) ) {
$redirect = isset( $attributes['logout_redirect'] ) ? $attributes['logout_redirect'] : '';
$redirect = trim( $redirect, ']' );
$redirect = trim( $redirect, '"' );
$redirect = trim( $redirect, "'" );
$redirect = '' != $redirect ? ur_check_external_url( $redirect ) : ur_get_page_permalink( 'myaccount' );
}
} else {
$blocks = parse_blocks( $post_content );
foreach ( $blocks as $block ) {
if ( ( 'user-registration/form-selector' === $block['blockName'] || 'user-registration/myaccount' === $block['blockName'] || 'user-registration/login-form' === $block['blockName'] ) && isset( $block['attrs']['logoutUrl'] ) ) {
$redirect = '' != $block['attrs']['logoutUrl'] ? ur_check_external_url( $block['attrs']['logoutUrl'] ) : ur_get_page_permalink( 'myaccount' );
} else {
$new_shortcode = wp_strip_all_tags( $block['innerHTML'] );
$pattern = '/\[user_registration_my_account(?:\s+redirect_url="[^"]*")?(?:\s+logout_redirect="[^"]*")?\s*\]/';
preg_match( $pattern, $new_shortcode, $shortcodes );
if ( ! empty( $shortcodes[0] ) ) {
preg_match( '/' . get_shortcode_regex() . '/s', $shortcodes[0], $matches );
$matches_attr = isset( $matches[3] ) ? $matches[3] : '';
$attributes = shortcode_parse_atts( $matches_attr );
/**
* Introduced logout_redirect parameter in user_registration_my_account shortcode.
*
* @since 1.7.5
*/
if ( isset( $attributes['logout_redirect'] ) ) {
$redirect = isset( $attributes['logout_redirect'] ) ? $attributes['logout_redirect'] : '';
$redirect = trim( $redirect, ']' );
$redirect = trim( $redirect, '"' );
$redirect = trim( $redirect, "'" );
$redirect = '' != $redirect ? ur_check_external_url( $redirect ) : ur_get_page_permalink( 'myaccount' );
}
}
}
}
}
/**
* Filters the redirect URL after user logout.
*
* The 'user_registration_redirect_after_logout' filter allows developers to modify
* the redirect URL after a user logs out. It provides an opportunity to customize
* the redirection based on the original redirect URL.
*
* @param string $redirect The original redirect URL after user logout.
*/
$redirect = apply_filters( 'user_registration_redirect_after_logout', $redirect );
if ( $logout_endpoint && ! is_front_page() ) {
if ( $redirect === home_url( '/' ) ) {
return wp_logout_url( $redirect );
} else {
return wp_nonce_url( ur_get_endpoint_url( 'user-logout', '', $redirect ), 'user-logout' );
}
} else {
if ( '' === $redirect ) {
$redirect = ur_get_page_permalink( 'myaccount' );
}
return wp_logout_url( $redirect );
}
}
/**
* See if current page elementor page for editing.
*
* @return bool
* @since 1.8.5
*/
function is_elementor_editing_page() {
return ( ! empty( $_POST['action'] ) && 'elementor_ajax' === $_POST['action'] ) || //PHPCS:ignore;
! empty( $_GET['elementor-preview'] ) || //PHPCS:ignore;
( ! empty( $_GET['action'] ) && 'elementor' === $_GET['action'] ); //PHPCS:ignore;
}
/**
* Check if the URL is slug or external url.
*
* @param string $url URL.
*
* @return string
*/
function ur_check_external_url( $url ) {
$all_page_slug = ur_get_all_page_slugs();
if ( in_array( $url, $all_page_slug, true ) ) {
$redirect_url = site_url( $url );
} else {
$redirect_url = ur_get_page_permalink( 'myaccount' );
$redirect_url = add_query_arg( 'redirect_to_on_logout', $url, $redirect_url );
}
return $redirect_url;
}