Headline
CVE-2023-3343: functions-ur-core.php in user-registration/tags/3.0.1/includes – WordPress Plugin Repository
The User Registration plugin for WordPress is vulnerable to PHP Object Injection in versions up to, and including, 3.0.1 via deserialization of untrusted input from the ‘profile-pic-url’ parameter. This allows authenticated attackers, with subscriber-level permissions and above, to inject a PHP Object. No POP chain is present in the vulnerable plugin. If a POP chain is present via an additional plugin or theme installed on the target system, it could allow the attacker to delete arbitrary files, retrieve sensitive data, or execute code.
1<?php2/**3 * UserRegistration Functions.4 *5 * General core functions available on both the front-end and admin.6 *7 * @package UserRegistration/Functions8 * @version 1.0.09 */1011defined( ‘ABSPATH’ ) || exit;1213// Include core functions (available in both admin and frontend).14require UR_ABSPATH . 'includes/functions-ur-page.php’;15require UR_ABSPATH . 'includes/functions-ur-account.php’;16require UR_ABSPATH . 'includes/functions-ur-deprecated.php’;1718/**19 * Define a constant if it is not already defined.20 *21 * @param string $name Constant name.22 * @param string $value Value.23 */24function ur_maybe_define_constant( $name, $value ) {25 if ( ! defined( $name ) ) {26 define( $name, $value );27 }28}2930if ( ! function_exists( ‘is_ur_endpoint_url’ ) ) {3132 /**33 * Check if an endpoint is showing.34 *35 * @param string $endpoint User registration myaccount endpoints.36 *37 * @return bool38 */39 function is_ur_endpoint_url( $endpoint = false ) {40 global $wp;4142 $ur_endpoints = UR()->query->get_query_vars();4344 if ( false !== $endpoint ) {45 if ( ! isset( $ur_endpoints[ $endpoint ] ) ) {46 return false;47 } else {48 $endpoint_var = $ur_endpoints[ $endpoint ];49 }5051 return isset( $wp->query_vars[ $endpoint_var ] );52 } else {53 foreach ( $ur_endpoints as $key => $value ) {54 if ( isset( $wp->query_vars[ $key ] ) ) {55 return true;56 }57 }5859 return false;60 }61 }62}6364if ( ! function_exists( ‘is_ur_account_page’ ) ) {6566 /**67 * Returns true when viewing an account page.68 *69 * @return bool70 */71 function is_ur_account_page() {72 return is_page( ur_get_page_id( ‘myaccount’ ) ) || ur_post_content_has_shortcode( ‘user_registration_my_account’ ) || apply_filters( 'user_registration_is_account_page’, false );73 }74}7576if ( ! function_exists( ‘is_ur_login_page’ ) ) {7778 /**79 * Returns true when viewing an login page.80 *81 * @return bool82 */83 function is_ur_login_page() {84 return is_page( ur_get_page_id( ‘login’ ) ) || ur_post_content_has_shortcode( ‘user_registration_login’ ) || apply_filters( 'user_registration_is_login_page’, false );85 }86}8788if ( ! function_exists( ‘is_ur_edit_account_page’ ) ) {8990 /**91 * Check for edit account page.92 * Returns true when viewing the edit account page.93 *94 * @return bool95 */96 function is_ur_edit_account_page() {97 global $wp;9899 return ( is_ur_account_page() && isset( $wp->query_vars[‘edit-password’] ) );100 }101}102103if ( ! function_exists( ‘is_ur_lost_password_page’ ) ) {104105 /**106 * Returns true when viewing the lost password page.107 *108 * @return bool109 */110 function is_ur_lost_password_page() {111 global $wp;112113 return ( is_ur_account_page() && isset( $wp->query_vars[‘ur-lost-password’] ) );114 }115}116117/**118 * Clean variables using sanitize_text_field. Arrays are cleaned recursively.119 * Non-scalar values are ignored.120 *121 * @param string|array $var Variable.122 *123 * @return string|array124 */125function ur_clean( $var ) {126 if ( is_array( $var ) ) {127 return array_map( 'ur_clean’, $var );128 } else {129 return is_scalar( $var ) ? sanitize_text_field( $var ) : $var;130 }131}132133/**134 * Sanitize a string destined to be a tooltip.135 *136 * @since 1.0.0 Tooltips are encoded with htmlspecialchars to prevent XSS. Should not be used in conjunction with esc_attr()137 *138 * @param string $var Value to sanitize.139 *140 * @return string141 */142function ur_sanitize_tooltip( $var ) {143 return htmlspecialchars(144 wp_kses(145 html_entity_decode( $var ),146 array(147 ‘br’ => array(),148 ‘em’ => array(),149 ‘strong’ => array(),150 ‘small’ => array(),151 ‘span’ => array(),152 ‘ul’ => array(),153 ‘li’ => array(),154 ‘ol’ => array(),155 ‘p’ => array(),156 )157 )158 );159}160161/**162 * Format dimensions for display.163 *164 * @since 1.7.0165 * @param array $dimensions Array of dimensions.166 * @param array $unit Unit, defaults to 'px’.167 * @return string168 */169function ur_sanitize_dimension_unit( $dimensions = array(), $unit = ‘px’ ) {170 return ur_array_to_string( ur_suffix_array( $dimensions, $unit ) );171}172173/**174 * Add a suffix into an array.175 *176 * @since 1.7.0177 * @param array $array Raw array data.178 * @param string $suffix Suffix to be added.179 * @return array Modified array with suffix added.180 */181function ur_suffix_array( $array = array(), $suffix = ‘’ ) {182 return preg_filter( '/$/’, $suffix, $array );183}184/**185 * Implode an array into a string by $glue and remove empty values.186 *187 * @since 1.7.0188 * @param array $array Array to convert.189 * @param string $glue Glue, defaults to ' '.190 * @return string191 */192function ur_array_to_string( $array = array(), $glue = ' ' ) {193 return is_string( $array ) ? $array : implode( $glue, array_filter( $array ) );194}195/**196 * Explode a string into an array by $delimiter and remove empty values.197 *198 * @since 1.7.0199 * @param string $string String to convert.200 * @param string $delimiter Delimiter, defaults to ',’.201 * @return array202 */203function ur_string_to_array( $string, $delimiter = ‘,’ ) {204 return is_array( $string ) ? $string : array_filter( explode( $delimiter, $string ) );205}206207/**208 * Converts a string (e.g. ‘yes’ or ‘no’) to a bool.209 *210 * @param string $string String to convert.211 * @return bool212 */213function ur_string_to_bool( $string ) {214 return is_bool( $string ) ? $string : ( ‘yes’ === $string || ‘on’ === $string || 1 === $string || ‘true’ === $string || ‘1’ === $string || ‘today’ === $string || ‘range’ === $string );215}216217/**218 * Converts a bool to a ‘yes’ or 'no’.219 *220 * @param bool $bool String to convert.221 * @return string222 */223function ur_bool_to_string( $bool ) {224 if ( ! is_bool( $bool ) ) {225 $bool = ur_string_to_bool( $bool );226 }227 return true === $bool ? ‘yes’ : 'no’;228}229230/**231 * Get other templates (e.g. my account) passing attributes and including the file.232 *233 * @param string $template_name Template Name.234 * @param array $args Extra arguments(default: array()).235 * @param string $template_path Path of template provided (default: ‘’).236 * @param string $default_path Default path of template provided(default: ‘’).237 */238function ur_get_template( $template_name, $args = array(), $template_path = '’, $default_path = ‘’ ) {239 if ( ! empty( $args ) && is_array( $args ) ) {240 extract( $args ); // phpcs:ignore241 }242243 $located = ur_locate_template( $template_name, $template_path, $default_path );244245 // Allow 3rd party plugin filter template file from their plugin.246 $located = apply_filters( 'ur_get_template’, $located, $template_name, $args, $template_path, $default_path );247248 if ( ! file_exists( $located ) ) {249 _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.’, esc_html( $located ) ), ‘1.0’ );250251 return;252 }253254 do_action( 'user_registration_before_template_part’, $template_name, $template_path, $located, $args );255256 include $located;257258 do_action( 'user_registration_after_template_part’, $template_name, $template_path, $located, $args );259}260261/**262 * Locate a template and return the path for inclusion.263 *264 * This is the load order:265 *266 * yourtheme / $template_path / $template_name267 * yourtheme / $template_name268 * $default_path / $template_name269 *270 * @param string $template_name Template Name.271 * @param string $template_path Path of template provided (default: ‘’).272 * @param string $default_path Default path of template provided(default: ‘’).273 *274 * @return string275 */276function ur_locate_template( $template_name, $template_path = '’, $default_path = ‘’ ) {277 if ( ! $template_path ) {278 $template_path = UR()->template_path();279 }280281 if ( ! $default_path ) {282 $default_path = UR()->plugin_path() . '/templates/’;283 }284285 // Look within passed path within the theme - this is priority.286 $template = locate_template(287 array(288 trailingslashit( $template_path ) . $template_name,289 $template_name,290 )291 );292293 // Get default template.294 if ( ! $template || UR_TEMPLATE_DEBUG_MODE ) {295 $template = $default_path . $template_name;296 }297298 // Return what we found.299 return apply_filters( 'user_registration_locate_template’, $template, $template_name, $template_path );300}301302/**303 * Display a UserRegistration help tip.304 *305 * @param string $tip Help tip text.306 * @param bool $allow_html Allow sanitized HTML if true or escape.307 * @param string $classname Classname.308 *309 * @return string310 */311function ur_help_tip( $tip, $allow_html = false, $classname = ‘user-registration-help-tip’ ) {312 if ( $allow_html ) {313 $tip = ur_sanitize_tooltip( $tip );314 } else {315 $tip = esc_attr( $tip );316 }317318 return sprintf( '<span class="%s" data-tip="%s"></span>’, $classname, $tip );319}320321/**322 * Checks whether the content passed contains a specific short code.323 *324 * @param string $tag Shortcode tag to check.325 *326 * @return bool327 */328function ur_post_content_has_shortcode( $tag = ‘’ ) {329 global $post;330 $new_shortcode = '’;331 $wp_version = '5.0’;332 if ( version_compare( $GLOBALS[‘wp_version’], $wp_version, ‘>=’ ) ) {333 if ( is_object( $post ) ) {334 $blocks = parse_blocks( $post->post_content );335 foreach ( $blocks as $block ) {336337 if ( ( ‘core/shortcode’ === $block[‘blockName’] || ‘core/paragraph’ === $block[‘blockName’] ) && isset( $block[‘innerHTML’] ) ) {338 $new_shortcode = $block[‘innerHTML’];339 } elseif ( ‘user-registration/form-selector’ === $block[‘blockName’] && isset( $block[‘attrs’][‘shortcode’] ) ) {340 $new_shortcode = '[' . $block[‘attrs’][‘shortcode’] . ']';341 }342 }343 }344 return ( is_singular() || is_front_page() ) && is_a( $post, ‘WP_Post’ ) && has_shortcode( $new_shortcode, $tag );345 } else {346 return ( is_singular() || is_front_page() ) && is_a( $post, ‘WP_Post’ ) && has_shortcode( $post->post_content, $tag );347 }348}349350/**351 * Wrapper for ur_doing_it_wrong.352 *353 * @since 1.0.0354 *355 * @param string $function Callback function name.356 * @param string $message Message to display.357 * @param string $version Version of the plugin.358 */359function ur_doing_it_wrong( $function, $message, $version ) {360 $message .= ' Backtrace: ' . wp_debug_backtrace_summary();361362 if ( defined( ‘DOING_AJAX’ ) ) {363 do_action( 'doing_it_wrong_run’, $function, $message, $version );364 error_log( “{$function} was called incorrectly. {$message}. This message was added in version {$version}.” );365 } else {366 _doing_it_wrong( esc_html( $function ), esc_html( $message ), esc_html( $version ) );367 }368}369370/**371 * Set a cookie - wrapper for setcookie using WP constants.372 *373 * @param string $name Name of the cookie being set.374 * @param string $value Value of the cookie.375 * @param integer $expire Expiry of the cookie.376 * @param string $secure Whether the cookie should be served only over https.377 */378function ur_setcookie( $name, $value, $expire = 0, $secure = false ) {379 if ( ! headers_sent() ) {380 setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : ‘/’, COOKIE_DOMAIN, $secure );381 } elseif ( defined( ‘WP_DEBUG’ ) && WP_DEBUG ) {382 headers_sent( $file, $line );383 trigger_error( “{$name} cookie cannot be set - headers already sent by {$file} on line {$line}", E_USER_NOTICE ); //phpcs:ignore384 }385}386387/**388 * Read in UserRegistration headers when reading plugin headers.389 *390 * @since 1.1.0391 *392 * @param array $headers header.393 *394 * @return array $headers395 */396function ur_enable_ur_plugin_headers( $headers ) {397 if ( ! class_exists( 'UR_Plugin_Updates’, false ) ) {398 include_once dirname( __FILE__ ) . '/admin/updater/class-ur-plugin-updates.php’;399 }400401 $headers[‘URRequires’] = UR_Plugin_Updates::VERSION_REQUIRED_HEADER;402 $headers[‘URTested’] = UR_Plugin_Updates::VERSION_TESTED_HEADER;403404 return $headers;405}406407add_filter( 'extra_plugin_headers’, ‘ur_enable_ur_plugin_headers’ );408409/**410 * Set field type for all registrered field keys411 *412 * @param string $field_key field’s field key.413 * @return string $field_type414 */415function ur_get_field_type( $field_key ) {416 $fields = ur_get_registered_form_fields();417418 $field_type = 'text’;419420 if ( in_array( $field_key, $fields ) ) {421422 switch ( $field_key ) {423424 case 'user_email’:425 case 'user_confirm_email’:426 case 'email’:427 $field_type = 'email’;428 break;429 case 'user_confirm_password’:430 case 'password’:431 case 'user_pass’:432 $field_type = 'password’;433 break;434 case 'user_login’:435 case 'nickname’:436 case 'first_name’:437 case 'last_name’:438 case 'display_name’:439 case 'text’:440 $field_type = 'text’;441 break;442 case 'user_url’:443 $field_type = 'url’;444 break;445 case 'description’:446 case 'textarea’:447 $field_type = 'textarea’;448 break;449 case 'select’:450 case 'country’:451 $field_type = 'select’;452 break;453 case 'file’:454 $field_type = 'file’;455 break;456 case 'privacy_policy’:457 case 'mailchimp’:458 case 'mailerlite’:459 case 'checkbox’:460 $field_type = 'checkbox’;461 break;462 case 'number’:463 $field_type = 'number’;464 break;465 case 'date’:466 $field_type = 'date’;467 break;468 case 'radio’:469 $field_type = 'radio’;470 break;471 }472 }473474 return apply_filters( 'user_registration_field_keys’, $field_type, $field_key );475}476477/**478 * Get user table fields.479 *480 * @return array481 */482function ur_get_user_table_fields() {483 return apply_filters(484 'user_registration_user_table_fields’,485 array(486 'user_email’,487 'user_pass’,488 'user_login’,489 'user_url’,490 'display_name’,491 )492 );493}494495/**496 * Get required fields.497 *498 * @return array499 */500function ur_get_required_fields() {501 return apply_filters(502 'user_registration_required_form_fields’,503 array(504 'user_email’,505 'user_pass’,506 )507 );508}509510/**511 * Get one time draggable fields fields.512 *513 * @return array514 */515function ur_get_one_time_draggable_fields() {516 $form_fields = ur_get_user_field_only();517 return apply_filters( 'user_registration_one_time_draggable_form_fields’, $form_fields );518}519520/**521 * Get fields excluding in profile tab522 *523 * @return array524 */525function ur_exclude_profile_details_fields() {526527 $fields_to_exclude = array(528 'user_pass’,529 'user_confirm_password’,530 'user_confirm_email’,531 'invite_code’,532 'learndash_course’,533 );534535 // Check if the my account page contains [user_registration_my_account] shortcode.536 if ( ur_post_content_has_shortcode( ‘user_registration_my_account’ ) || ur_post_content_has_shortcode( ‘user_registration_edit_profile’ ) ) {537 // Push profile_picture field to fields_to_exclude array.538 array_push( $fields_to_exclude, ‘profile_picture’ );539 }540541 return apply_filters(542 'user_registration_exclude_profile_fields’,543 $fields_to_exclude544 );545}546547/**548 * Get readonly fields in profile tab549 *550 * @return array551 */552function ur_readonly_profile_details_fields() {553 return apply_filters(554 'user_registration_readonly_profile_fields’,555 array(556 ‘user_login’ => array(557 ‘message’ => __( 'Username can not be changed.’, ‘user-registration’ ),558 ),559 ‘user_pass’ => array(560 ‘value’ => 'password’,561 ‘message’ => __( 'Passowrd can not be changed.’, ‘user-registration’ ),562 ),563 ‘user_confirm_password’ => array(564 ‘value’ => 'password’,565 ‘message’ => __( 'Confirm password can not be changed.’, ‘user-registration’ ),566 ),567 ‘user_confirm_email’ => array(568 ‘message’ => __( 'Confirm email can not be changed.’, ‘user-registration’ ),569 ),570 )571 );572}573574/**575 * Get profile detail fields.576 *577 * @deprecated 1.4.1578 * @return void579 */580function ur_get_account_details_fields() {581 ur_deprecated_function( 'ur_get_account_details_fields’, '1.4.1’, ‘ur_exclude_profile_details_fields’ );582}583584/**585 * Get all fields appearing in profile tab.586 *587 * @return array588 */589function ur_get_user_profile_field_only() {590 $user_fields = array_diff( ur_get_registered_form_fields(), ur_exclude_profile_details_fields() );591 return apply_filters( 'user_registration_user_profile_field_only’, $user_fields );592}593594/**595 * All fields to update without adding prefix.596 *597 * @return array598 */599function ur_get_fields_without_prefix() {600 $fields = ur_get_user_field_only();601 return apply_filters( 'user_registration_fields_without_prefix’, $fields );602603}604605/**606 * Get all default fields by WordPress.607 *608 * @return array609 */610function ur_get_user_field_only() {611 return apply_filters(612 'user_registration_user_form_fields’,613 array(614 'user_email’,615 'user_confirm_email’,616 'user_pass’,617 'user_confirm_password’,618 'user_login’,619 'nickname’,620 'first_name’,621 'last_name’,622 'user_url’,623 'display_name’,624 'description’,625 )626 );627}628629/**630 * Get all extra form fields631 *632 * @return array633 */634function ur_get_other_form_fields() {635 $registered = ur_get_registered_form_fields();636 $user_fields = ur_get_user_field_only();637 $result = array_diff( $registered, $user_fields );638639 return apply_filters( 'user_registration_other_form_fields’, $result );640}641642/**643 * All default fields storing in usermeta table644 *645 * @return mixed|array646 */647function ur_get_registered_user_meta_fields() {648 return apply_filters(649 'user_registration_registered_user_meta_fields’,650 array(651 'nickname’,652 'first_name’,653 'last_name’,654 'description’,655 )656 );657}658659/**660 * All registered form fields661 *662 * @return mixed|array663 */664function ur_get_registered_form_fields() {665 return apply_filters(666 'user_registration_registered_form_fields’,667 array(668 'user_email’,669 'user_confirm_email’,670 'user_pass’,671 'user_confirm_password’,672 'user_login’,673 'nickname’,674 'first_name’,675 'last_name’,676 'user_url’,677 'display_name’,678 'description’,679 'text’,680 'password’,681 'email’,682 'select’,683 'country’,684 'textarea’,685 'number’,686 'date’,687 'checkbox’,688 'privacy_policy’,689 'radio’,690 )691 );692}693694/**695 * All registered form fields with default labels696 *697 * @return mixed|array698 */699function ur_get_registered_form_fields_with_default_labels() {700 return apply_filters(701 'user_registration_registered_form_fields_with_default_labels’,702 array(703 ‘user_email’ => __( 'User Email’, ‘user-registration’ ),704 ‘user_confirm_email’ => __( 'User Confirm Email’, ‘user-registration’ ),705 ‘user_pass’ => __( 'User Pass’, ‘user-registration’ ),706 ‘user_confirm_password’ => __( 'User Confirm Password’, ‘user-registration’ ),707 ‘user_login’ => __( 'User Login’, ‘user-registration’ ),708 ‘nickname’ => __( 'Nickname’, ‘user-registration’ ),709 ‘first_name’ => __( 'First Name’, ‘user-registration’ ),710 ‘last_name’ => __( 'Last Name’, ‘user-registration’ ),711 ‘user_url’ => __( 'User URL’, ‘user-registration’ ),712 ‘display_name’ => __( 'Display Name’, ‘user-registration’ ),713 ‘description’ => __( 'Description’, ‘user-registration’ ),714 ‘text’ => __( 'Text’, ‘user-registration’ ),715 ‘password’ => __( 'Password’, ‘user-registration’ ),716 ‘email’ => __( 'Secondary Email’, ‘user-registration’ ),717 ‘select’ => __( 'Select’, ‘user-registration’ ),718 ‘country’ => __( 'Country’, ‘user-registration’ ),719 ‘textarea’ => __( 'Textarea’, ‘user-registration’ ),720 ‘number’ => __( 'Number’, ‘user-registration’ ),721 ‘date’ => __( 'Date’, ‘user-registration’ ),722 ‘checkbox’ => __( 'Checkbox’, ‘user-registration’ ),723 ‘privacy_policy’ => __( 'Privacy Policy’, ‘user-registration’ ),724 ‘radio’ => __( 'Radio’, ‘user-registration’ ),725 ‘hidden’ => __( 'Hidden’, ‘user-registration’ ),726 )727 );728}729730/**731 * General settings for each fields732 *733 * @param string $id id for each field.734 * @return mixed|array735 */736function ur_get_general_settings( $id ) {737738 $general_settings = array(739 ‘label’ => array(740 ‘setting_id’ => 'label’,741 ‘type’ => 'text’,742 ‘label’ => __( 'Label’, ‘user-registration’ ),743 ‘name’ => 'ur_general_setting[label]',744 ‘placeholder’ => __( 'Label’, ‘user-registration’ ),745 ‘required’ => true,746 ‘tip’ => __( 'Enter text for the form field label. This is recommended and can be hidden in the Advanced Settings.’, ‘user-registration’ ),747 ),748 ‘description’ => array(749 ‘setting_id’ => 'description’,750 ‘type’ => 'textarea’,751 ‘label’ => __( 'Description’, ‘user-registration’ ),752 ‘name’ => 'ur_general_setting[description]',753 ‘placeholder’ => __( 'Description’, ‘user-registration’ ),754 ‘required’ => true,755 ‘tip’ => __( 'Enter text for the form field description.’, ‘user-registration’ ),756 ),757 ‘field_name’ => array(758 ‘setting_id’ => 'field-name’,759 ‘type’ => 'text’,760 ‘label’ => __( 'Field Name’, ‘user-registration’ ),761 ‘name’ => 'ur_general_setting[field_name]',762 ‘placeholder’ => __( 'Field Name’, ‘user-registration’ ),763 ‘required’ => true,764 ‘tip’ => __( 'Unique key for the field.’, ‘user-registration’ ),765 ),766767 ‘placeholder’ => array(768 ‘setting_id’ => 'placeholder’,769 ‘type’ => 'text’,770 ‘label’ => __( 'Placeholder’, ‘user-registration’ ),771 ‘name’ => 'ur_general_setting[placeholder]',772 ‘placeholder’ => __( 'Placeholder’, ‘user-registration’ ),773 ‘required’ => true,774 ‘tip’ => __( 'Enter placeholder for the field.’, ‘user-registration’ ),775 ),776 ‘required’ => array(777 ‘setting_id’ => 'required’,778 ‘type’ => 'toggle’,779 ‘label’ => __( 'Required’, ‘user-registration’ ),780 ‘name’ => 'ur_general_setting[required]',781 ‘placeholder’ => '’,782 ‘required’ => true,783 ‘default’ => 'false’,784 ‘tip’ => __( 'Check this option to mark the field required. A form will not submit unless all required fields are provided.’, ‘user-registration’ ),785 ),786 ‘hide_label’ => array(787 ‘setting_id’ => 'hide-label’,788 ‘type’ => 'toggle’,789 ‘label’ => __( 'Hide Label’, ‘user-registration’ ),790 ‘name’ => 'ur_general_setting[hide_label]',791 ‘placeholder’ => '’,792 ‘required’ => true,793 ‘default’ => 'false’,794 ‘tip’ => __( 'Check this option to hide the label of this field.’, ‘user-registration’ ),795 ),796 );797798 $exclude_placeholder = apply_filters(799 'user_registration_exclude_placeholder’,800 array(801 'checkbox’,802 'privacy_policy’,803 'radio’,804 'file’,805 'mailchimp’,806 'hidden’,807 )808 );809 $strip_id = str_replace( 'user_registration_’, '’, $id );810811 if ( in_array( $strip_id, $exclude_placeholder, true ) ) {812 unset( $general_settings[‘placeholder’] );813 }814815 $choices_fields = array( 'radio’, 'select’, ‘checkbox’ );816817 if ( in_array( $strip_id, $choices_fields, true ) ) {818819 $settings[‘options’] = array(820 ‘setting_id’ => 'options’,821 ‘type’ => ‘checkbox’ === $strip_id ? ‘checkbox’ : 'radio’,822 ‘label’ => __( 'Options’, ‘user-registration’ ),823 ‘name’ => 'ur_general_setting[options]',824 ‘placeholder’ => '’,825 ‘required’ => true,826 ‘options’ => array(827 __( 'First Choice’, ‘user-registration’ ),828 __( 'Second Choice’, ‘user-registration’ ),829 __( 'Third Choice’, ‘user-registration’ ),830 ),831 );832833 $general_settings = ur_insert_after_helper( $general_settings, $settings, ‘field_name’ );834 }835 if ( ‘privacy_policy’ === $strip_id || ‘user_confirm_email’ === $strip_id || ‘user_confirm_password’ === $strip_id || in_array( $strip_id, ur_get_required_fields() ) ) {836 $general_settings[‘required’] = array(837 ‘setting_id’ => '’,838 ‘type’ => 'hidden’,839 ‘label’ => '’,840 ‘name’ => 'ur_general_setting[required]',841 ‘placeholder’ => '’,842 ‘default’ => true,843 ‘required’ => true,844 );845 }846847 return apply_filters( 'user_registration_field_options_general_settings’, $general_settings, $id );848}849850/**851 * Insert in between the indexes in multidimensional array.852 *853 * @since 1.5.7854 * @param array $items An array of items.855 * @param array $new_items New items to insert inbetween.856 * @param string $after Index to insert after.857 *858 * @return array Ordered array of items.859 */860function ur_insert_after_helper( $items, $new_items, $after ) {861862 // Search for the item position and +1 since is after the selected item key.863 $position = array_search( $after, array_keys( $items ), true ) + 1;864865 // Insert the new item.866 $return_items = array_slice( $items, 0, $position, true );867 $return_items += $new_items;868 $return_items += array_slice( $items, $position, count( $items ) - $position, true );869870 return $return_items;871}872873/**874 * Load form field class.875 *876 * @param string $class_key Class Key.877 */878function ur_load_form_field_class( $class_key ) {879 $exploded_class = explode( '_’, $class_key );880 $class_path = UR_FORM_PATH . 'class-ur-' . join( '-', array_map( 'strtolower’, $exploded_class ) ) . '.php’;881 $class_name = ‘UR_Form_Field_’ . join( '_’, array_map( 'ucwords’, $exploded_class ) );882 $class_path = apply_filters( ‘user_registration_form_field_’ . $class_key . '_path’, $class_path );883 /* Backward Compat since 1.4.0 */884 if ( file_exists( $class_path ) ) {885 $class_name = ‘UR_’ . join( '_’, array_map( 'ucwords’, $exploded_class ) );886 if ( ! class_exists( $class_name ) ) {887 include_once $class_path;888 }889 }890 /* Backward compat end*/891 return $class_name;892}893894/**895 * List of all roles896 *897 * @return array $all_roles898 */899function ur_get_default_admin_roles() {900 global $wp_roles;901902 if ( ! class_exists( ‘WP_Roles’ ) ) {903 return;904 }905906 if ( ! isset( $wp_roles ) ) {907 $wp_roles = new WP_Roles(); // @codingStandardsIgnoreLine908 }909910 $roles = isset( $wp_roles->roles ) ? $wp_roles->roles : array();911 $all_roles = array();912913 foreach ( $roles as $role_key => $role ) {914 $all_roles[ $role_key ] = $role[‘name’];915 }916917 return apply_filters( 'user_registration_user_default_roles’, $all_roles );918}919920921/**922 * Random number generated by time()923 *924 * @return int925 */926function ur_get_random_number() {927 return time();928}929930/**931 * General Form settings932 *933 * @param int $form_id Form ID.934 *935 * @since 1.0.1936 *937 * @return array Form settings.938 */939function ur_admin_form_settings_fields( $form_id ) {940941 $all_roles = ur_get_default_admin_roles();942943 $arguments = array(944 ‘form_id’ => $form_id,945946 ‘setting_data’ => array(947 array(948 ‘label’ => __( 'User Approval And Login Option’, ‘user-registration’ ),949 ‘description’ => __( 'This option lets you choose login option after user registration.’, ‘user-registration’ ),950 ‘id’ => 'user_registration_form_setting_login_options’,951 ‘default’ => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_login_options’, get_option( ‘user_registration_general_setting_login_options’ ) ),952 ‘type’ => 'select’,953 ‘class’ => array( ‘ur-enhanced-select’ ),954 ‘custom_attributes’ => array(),955 ‘input_class’ => array(),956 ‘required’ => false,957 ‘options’ => ur_login_option(),958 ‘tip’ => __( 'Login method that should be used by the users registered through this form.’, ‘user-registration’ ),959 ),960 array(961 ‘label’ => __( 'Send User Approval Link in Email’, ‘user-registration’ ),962 ‘description’ => '’,963 ‘id’ => 'user_registration_form_setting_enable_email_approval’,964 ‘type’ => 'toggle’,965 ‘tip’ => __( 'Check to receive a link with token in email to approve the users directly.’, ‘user-registration’ ),966 ‘css’ => 'min-width: 350px;’,967 ‘default’ => ur_get_approval_default( $form_id ),968 ),969 array(970 ‘type’ => 'select’,971 ‘label’ => __( 'Default User Role’, ‘user-registration’ ),972 ‘description’ => '’,973 ‘required’ => false,974 ‘id’ => 'user_registration_form_setting_default_user_role’,975 ‘class’ => array( ‘ur-enhanced-select’ ),976 ‘input_class’ => array(),977 ‘options’ => $all_roles,978 ‘custom_attributes’ => array(),979 ‘default’ => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_default_user_role’, get_option( 'user_registration_form_setting_default_user_role’, ‘subscriber’ ) ),980 ‘tip’ => __( 'Default role for the users registered through this form.’, ‘user-registration’ ),981 ),982 array(983 ‘type’ => 'toggle’,984 ‘label’ => __( 'Enable Strong Password’, ‘user-registration’ ),985 ‘description’ => '’,986 ‘required’ => false,987 ‘id’ => 'user_registration_form_setting_enable_strong_password’,988 ‘class’ => array( ‘ur-enhanced-select’ ),989 ‘input_class’ => array(),990 ‘custom_attributes’ => array(),991 ‘default’ => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_enable_strong_password’, ur_string_to_bool( get_option( 'user_registration_form_setting_enable_strong_password’, 1 ) ) ),992 ‘tip’ => __( 'Make strong password compulsary.’, ‘user-registration’ ),993 ),994 array(995 ‘type’ => 'radio-group’,996 ‘label’ => __( 'Minimum Password Strength’, ‘user-registration’ ),997 ‘description’ => '’,998 ‘required’ => false,999 ‘id’ => 'user_registration_form_setting_minimum_password_strength’,1000 ‘class’ => array( ‘ur-enhanced-select’ ),1001 ‘input_class’ => array(),1002 ‘options’ => array(1003 ‘0’ => __( 'Very Weak’, ‘user-registration’ ),1004 ‘1’ => __( 'Weak’, ‘user-registration’ ),1005 ‘2’ => __( 'Medium’, ‘user-registration’ ),1006 ‘3’ => __( 'Strong’, ‘user-registration’ ),1007 ),1008 ‘custom_attributes’ => array(),1009 ‘default’ => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_minimum_password_strength’, get_option( 'user_registration_form_setting_minimum_password_strength’, ‘3’ ) ),1010 ‘tip’ => __( 'Set minimum required password strength.’, ‘user-registration’ ),1011 ),1012 array(1013 ‘type’ => 'text’,1014 ‘label’ => __( 'Submit Button Class’, ‘user-registration’ ),1015 ‘description’ => '’,1016 ‘required’ => false,1017 ‘id’ => 'user_registration_form_setting_form_submit_class’,1018 ‘class’ => array( ‘ur-enhanced-select’ ),1019 ‘input_class’ => array(),1020 ‘custom_attributes’ => array(),1021 ‘default’ => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_form_submit_class’, ‘’ ),1022 ‘tip’ => __( 'Enter CSS class names for the Submit Button. Multiple class names should be separated with spaces.’, ‘user-registration’ ),1023 ),1024 array(1025 ‘type’ => 'text’,1026 ‘label’ => __( 'Submit Button Text’, ‘user-registration’ ),1027 ‘description’ => '’,1028 ‘required’ => false,1029 ‘id’ => 'user_registration_form_setting_form_submit_label’,1030 ‘class’ => array( ‘ur-enhanced-select’ ),1031 ‘input_class’ => array(),1032 ‘custom_attributes’ => array(),1033 ‘default’ => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_form_submit_label’, ‘Submit’ ),1034 ‘tip’ => __( 'Enter desired text for the Submit Button.’, ‘user-registration’ ),1035 ),1036 array(1037 ‘type’ => 'select’,1038 ‘label’ => __( 'Success message position’, ‘user-registration’ ),1039 ‘description’ => '’,1040 ‘required’ => false,1041 ‘id’ => 'user_registration_form_setting_success_message_position’,1042 ‘class’ => array( ‘ur-enhanced-select’ ),1043 ‘input_class’ => array(),1044 ‘options’ => array(1045 ‘0’ => __( 'Top’, ‘user-registration’ ),1046 ‘1’ => __( 'Bottom’, ‘user-registration’ ),1047 ),1048 ‘custom_attributes’ => array(),1049 ‘default’ => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_success_message_position’, ‘1’ ),1050 ‘tip’ => __( 'Display success message either at the top or bottom after successful registration.’, ‘user-registration’ ),1051 ),1052 array(1053 ‘type’ => 'toggle’,10541055 /* translators: 1: Link tag open 2:: Link content 3:: Link tag close */1056 ‘label’ => sprintf( __( 'Enable %1$s %2$s Captcha %3$s Support’, ‘user-registration’ ), '<a title="’, 'Please make sure the site key and secret are not empty in setting page.” href="’ . admin_url() . 'admin.php?page=user-registration-settings&tab=captcha" target="_blank">’, ‘</a>’ ),1057 ‘description’ => '’,1058 ‘required’ => false,1059 ‘id’ => 'user_registration_form_setting_enable_recaptcha_support’,1060 ‘class’ => array( ‘ur-enhanced-select’ ),1061 ‘input_class’ => array(),1062 ‘custom_attributes’ => array(),1063 ‘default’ => ur_string_to_bool( ur_get_single_post_meta( $form_id, 'user_registration_form_setting_enable_recaptcha_support’, false ) ),1064 ‘tip’ => __( 'Enable Captcha for strong security from spams and bots.’, ‘user-registration’ ),1065 ),1066 array(1067 ‘type’ => 'select’,1068 ‘label’ => __( 'Form Template’, ‘user-registration’ ),1069 ‘description’ => '’,1070 ‘required’ => false,1071 ‘id’ => 'user_registration_form_template’,1072 ‘class’ => array( ‘ur-enhanced-select’ ),1073 ‘input_class’ => array(),1074 ‘options’ => array(1075 ‘Default’ => __( 'Default’, ‘user-registration’ ),1076 ‘Bordered’ => __( 'Bordered’, ‘user-registration’ ),1077 ‘Flat’ => __( 'Flat’, ‘user-registration’ ),1078 ‘Rounded’ => __( 'Rounded’, ‘user-registration’ ),1079 ‘Rounded Edge’ => __( 'Rounded Edge’, ‘user-registration’ ),1080 ),1081 ‘custom_attributes’ => array(),1082 ‘default’ => ur_get_single_post_meta( $form_id, 'user_registration_form_template’, ucwords( str_replace( '_’, ' ', get_option( 'user_registration_form_template’, ‘default’ ) ) ) ),1083 ‘tip’ => __( 'Choose form template to use.’, ‘user-registration’ ),1084 ),1085 array(1086 ‘type’ => 'text’,1087 ‘label’ => __( 'Form Class’, ‘user-registration’ ),1088 ‘description’ => '’,1089 ‘required’ => false,1090 ‘id’ => 'user_registration_form_custom_class’,1091 ‘class’ => array( ‘ur-enhanced-select’ ),1092 ‘input_class’ => array(),1093 ‘custom_attributes’ => array(),1094 ‘default’ => ur_get_single_post_meta( $form_id, ‘user_registration_form_custom_class’ ),1095 ‘tip’ => __( 'Enter CSS class names for the Form Wrapper. Multiple class names should be separated with spaces.’, ‘user-registration’ ),1096 ),1097 array(1098 ‘type’ => 'select’,1099 ‘label’ => __( 'Redirect After Registration’, ‘user-registration’ ),1100 ‘description’ => '’,1101 ‘required’ => false,1102 ‘id’ => 'user_registration_form_setting_redirect_after_registration’,1103 ‘class’ => array( ‘ur-enhanced-select’ ),1104 ‘input_class’ => array(),1105 ‘options’ => apply_filters(1106 'user_registration_redirect_after_registration_options’,1107 array(1108 ‘no-redirection’ => __( 'No Redirection’, ‘user-registration’ ),1109 ‘internal-page’ => __( 'Internal Page’, ‘user-registration’ ),1110 ‘external-url’ => __( 'External URL’, ‘user-registration’ ),1111 )1112 ),1113 ‘default’ => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_redirect_after_registration’, ‘no-redirection’ ),1114 ‘tip’ => __( 'Choose where to redirect the user after successful registration.’, ‘user-registration’ ),1115 ‘custom_attributes’ => array(),1116 ),1117 array(1118 ‘type’ => 'select’,1119 ‘label’ => __( 'Custom Page’, ‘user-registration’ ),1120 ‘description’ => '’,1121 ‘required’ => false,1122 ‘id’ => 'user_registration_form_setting_redirect_page’,1123 ‘class’ => array( ‘ur-enhanced-select’ ),1124 ‘input_class’ => array(),1125 ‘options’ => ur_get_all_pages(),1126 ‘default’ => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_redirect_page’, ‘’ ),1127 ‘tip’ => __( 'Choose the custom page to redirect after registration’, ‘user-registration’ ),1128 ‘custom_attributes’ => array(),1129 ),1130 array(1131 ‘type’ => 'text’,1132 ‘label’ => __( 'Redirect URL’, ‘user-registration’ ),1133 ‘id’ => 'user_registration_form_setting_redirect_options’,1134 ‘class’ => array( ‘ur-enhanced-select’ ),1135 ‘input_class’ => array(),1136 ‘custom_attributes’ => array(),1137 ‘default’ => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_redirect_options’, get_option( 'user_registration_general_setting_redirect_options’, ‘’ ) ), // Getting redirect options from global settings for backward compatibility.1138 ‘tip’ => __( 'This option lets you enter redirect path after successful user registration.’, ‘user-registration’ ),1139 ),1140 ),1141 );11421143 $arguments = apply_filters( 'user_registration_get_form_settings’, $arguments );11441145 return $arguments[‘setting_data’];1146}11471148/**1149 * User Login Option1150 *1151 * @return array1152 */1153function ur_login_option() {11541155 return apply_filters(1156 'user_registration_login_options’,1157 array(1158 ‘default’ => __( 'Auto approval and manual login’, ‘user-registration’ ),1159 ‘auto_login’ => __( 'Auto approval and auto login ', ‘user-registration’ ),1160 ‘admin_approval’ => __( 'Admin approval’, ‘user-registration’ ),1161 ‘email_confirmation’ => __( 'Auto approval after email confirmation’, ‘user-registration’ ),1162 )1163 );1164}11651166/**1167 * User Login Option1168 *1169 * @return array1170 */1171function ur_login_option_with() {11721173 return apply_filters(1174 'user_registration_login_options_with’,1175 array(1176 ‘default’ => __( 'Username or Email’, ‘user-registration’ ),1177 ‘username’ => __( 'Username’, ‘user-registration’ ),1178 ‘email’ => __( 'Email’, ‘user-registration’ ),1179 )1180 );1181}11821183/**1184 * Get Default value for Enable Email Approval Checkbox1185 *1186 * @param int $form_id Form ID.1187 */1188function ur_get_approval_default( $form_id ) {1189 if ( isset( $form_id ) && 0 != absint( $form_id ) ) {1190 $value = ur_get_single_post_meta( $form_id, ‘user_registration_form_setting_enable_email_approval’ );1191 } else {1192 $value = ur_get_single_post_meta( $form_id, 'user_registration_form_setting_enable_email_approval’, get_option( 'user_registration_login_option_enable_email_approval’, false ) );1193 }1194 $value = ur_string_to_bool( $value ) ? true : false;11951196 return $value;1197}11981199/**1200 * Get Post meta value by meta key.1201 *1202 * @param int $post_id Post ID.1203 * @param string $meta_key Meta Key.1204 * @param mixed $default Default Value.1205 *1206 * @since 1.0.11207 *1208 * @return mixed1209 */1210function ur_get_single_post_meta( $post_id, $meta_key, $default = null ) {12111212 $post_meta = get_post_meta( $post_id, $meta_key );12131214 if ( isset( $post_meta[0] ) ) {1215 if ( ‘user_registration_form_setting_enable_recaptcha_support’ === $meta_key || ‘user_registration_form_setting_enable_strong_password’ === $meta_key1216 || ‘user_registration_pdf_submission_to_admin’ === $meta_key || ‘user_registration_pdf_submission_to_user’ === $meta_key || ‘user_registration_form_setting_enable_assign_user_role_conditionally’ === $meta_key ) {1217 $post_meta[0] = ur_string_to_bool( $post_meta[0] );1218 }1219 return $post_meta[0];1220 }12211222 return $default;1223}12241225/**1226 * Get general form settings by meta key (settings id).1227 *1228 * @param int $form_id Form ID.1229 * @param string $meta_key Meta Key.1230 * @param mixed $default Default Value.1231 *1232 * @since 1.0.11233 *1234 * @return mixed1235 */1236function ur_get_form_setting_by_key( $form_id, $meta_key, $default = ‘’ ) {12371238 $fields = ur_admin_form_settings_fields( $form_id );1239 $value = '’;12401241 foreach ( $fields as $field ) {12421243 if ( isset( $field[‘id’] ) && $meta_key == $field[‘id’] ) {1244 $value = isset( $field[‘default’] ) ? sanitize_text_field( $field[‘default’] ) : $default;1245 break;1246 }1247 }12481249 return $value;1250}12511252/**1253 * Get user status in case of admin approval login option1254 *1255 * @param int $user_id User ID.1256 * @return int1257 */1258function ur_get_user_approval_status( $user_id ) {12591260 $user_status = 1;12611262 $form_id = ur_get_form_id_by_userid( $user_id );12631264 $login_option = ur_get_single_post_meta( $form_id, 'user_registration_form_setting_login_options’, get_option( 'user_registration_general_setting_login_options’, ‘default’ ) );12651266 if ( ‘admin_approval’ === $login_option ) {12671268 $user_status = get_user_meta( $user_id, 'ur_user_status’, true );1269 }12701271 return $user_status;1272}12731274/**1275 * Get form data by field key.1276 *1277 * @param array $form_data Form Data.1278 * @param string $key Field Key.1279 *1280 * @return array1281 */1282function ur_get_form_data_by_key( $form_data, $key = null ) {12831284 $form_data_array = array();12851286 foreach ( $form_data as $data ) {1287 foreach ( $data as $single_data ) {1288 foreach ( $single_data as $field_data ) {12891290 $field_key = isset( $field_data->field_key ) && null !== $field_data->field_key ? $field_data->field_key : '’;12911292 if ( ! empty( $field_key ) ) {1293 $field_name = isset( $field_data->general_setting->field_name ) && null !== $field_data->general_setting->field_name ? $field_data->general_setting->field_name : '’;12941295 if ( null === $key ) {12961297 if ( ! empty( $field_name ) ) {1298 $form_data_array[ $field_name ] = $field_data;1299 } else {1300 $form_data_array[] = $field_data;1301 }1302 } else {13031304 if ( $field_key === $key ) {13051306 if ( ! empty( $field_name ) ) {1307 $form_data_array[ $field_name ] = $field_data;1308 } else {1309 $form_data_array[] = $field_data;1310 }1311 }1312 }1313 }1314 }1315 }1316 }13171318 return $form_data_array;1319}13201321/**1322 * Get a log file path.1323 *1324 * @since 1.0.51325 *1326 * @param string $handle name.1327 *1328 * @return string the log file path.1329 */1330function ur_get_log_file_path( $handle ) {1331 return UR_Log_Handler_File::get_log_file_path( $handle );1332}13331334/**1335 * Registers the default log handler.1336 *1337 * @since 1.0.51338 *1339 * @param array $handlers Log handlers.1340 *1341 * @return array1342 */1343function ur_register_default_log_handler( $handlers ) {13441345 if ( defined( ‘UR_LOG_HANDLER’ ) && class_exists( UR_LOG_HANDLER ) ) {1346 $handler_class = UR_LOG_HANDLER;1347 $default_handler = new $handler_class();1348 } else {1349 $default_handler = new UR_Log_Handler_File();1350 }13511352 array_push( $handlers, $default_handler );13531354 return $handlers;1355}13561357add_filter( 'user_registration_register_log_handlers’, ‘ur_register_default_log_handler’ );135813591360/**1361 * Get a shared logger instance.1362 *1363 * Use the user_registration_logging_class filter to change the logging class. You may provide one of the following:1364 * - a class name which will be instantiated as `new $class` with no arguments1365 * - an instance which will be used directly as the logger1366 * In either case, the class or instance *must* implement UR_Logger_Interface.1367 *1368 * @see UR_Logger_Interface1369 * @since 1.1.01370 * @return UR_Logger1371 */1372function ur_get_logger() {1373 static $logger = null;1374 if ( null === $logger ) {1375 $class = apply_filters( 'user_registration_logging_class’, ‘UR_Logger’ );1376 $implements = class_implements( $class );1377 if ( is_array( $implements ) && in_array( 'UR_Logger_Interface’, $implements ) ) {1378 if ( is_object( $class ) ) {1379 $logger = $class;1380 } else {1381 $logger = new $class();1382 }1383 } else {1384 ur_doing_it_wrong(1385 __FUNCTION__,1386 sprintf(1387 /* translators: %s: Class */1388 __( 'The class <code>%s</code> provided by user_registration_logging_class filter must implement <code>UR_Logger_Interface</code>.’, ‘user-registration’ ),1389 esc_html( is_object( $class ) ? get_class( $class ) : $class )1390 ),1391 '1.0.5’1392 );1393 $logger = new UR_Logger();1394 }1395 }13961397 return $logger;1398}13991400/**1401 * Handles addon plugin updater.1402 *1403 * @param string $file Plugin File.1404 * @param int $item_id Item ID.1405 * @param string $addon_version Addon Version.1406 * @param bool $beta Is beta version.1407 *1408 * @since 1.1.01409 */1410function ur_addon_updater( $file, $item_id, $addon_version, $beta = false ) {1411 $api_endpoint = 'https://wpeverest.com/edd-sl-api/’;1412 $license_key = trim( get_option( ‘user-registration_license_key’ ) );1413 if ( class_exists( ‘UR_AddOn_Updater’ ) ) {1414 new UR_AddOn_Updater(1415 esc_url_raw( $api_endpoint ),1416 $file,1417 array(1418 ‘version’ => $addon_version,1419 ‘license’ => $license_key,1420 ‘item_id’ => $item_id,1421 ‘author’ => 'WPEverest’,1422 ‘url’ => home_url(),1423 ‘beta’ => $beta,1424 )1425 );1426 }1427}14281429/**1430 * Check if username already exists in case of optional username1431 * And while stripping through email address and incremet last number by 1.1432 *1433 * @param string $username Username.1434 * @return string1435 */1436function check_username( $username ) {14371438 if ( username_exists( $username ) ) {1439 preg_match_all( '/\d+$/m’, $username, $matches );14401441 if ( isset( $matches[0][0] ) ) {1442 $last_char = $matches[0][0];1443 $strip_last_char = substr( $username, 0, -( strlen( (string) $last_char ) ) );1444 $last_char++;1445 $username = $strip_last_char . $last_char;1446 $username = check_username( $username );14471448 return $username;1449 } else {1450 $username = $username . '_1’;1451 $username = check_username( $username );14521453 return $username;1454 }1455 }14561457 return $username;1458}14591460/**1461 * Get all user registration forms title with respective id.1462 *1463 * @param int $post_count Post Count.1464 * @return array1465 */1466function ur_get_all_user_registration_form( $post_count = -1 ) {1467 $args = array(1468 ‘status’ => 'publish’,1469 ‘numberposts’ => $post_count,1470 ‘order’ => 'ASC’,1471 );1472 $posts_array = UR()->form->get_form( '’, $args );1473 $all_forms = array();14741475 foreach ( $posts_array as $post ) {1476 $all_forms[ $post->ID ] = $post->post_title;1477 }14781479 return $all_forms;1480}14811482/**1483 * Checks user login option, if not email confirmation force not disable emails.1484 */1485function ur_get_user_login_option() {14861487 if ( ‘email_confirmation’ !== get_option( ‘user_registration_general_setting_login_options’ ) ) {1488 return array(1489 ‘title’ => __( 'Disable emails’, ‘user-registration’ ),1490 ‘desc’ => __( 'Disable all emails sent after registration.’, ‘user-registration’ ),1491 ‘id’ => 'user_registration_email_setting_disable_email’,1492 ‘default’ => 'no’,1493 ‘type’ => 'toggle’,1494 ‘autoload’ => false,1495 );1496 } else {1497 update_option( 'user_registration_email_setting_disable_email’, false );1498 }1499}15001501/**1502 * Get the node to display google reCaptcha1503 *1504 * @param string $context Recaptcha context.1505 * @param string $recaptcha_enabled Is Recaptcha enabled.1506 * @return string1507 */1508function ur_get_recaptcha_node( $context, $recaptcha_enabled = false ) {15091510 $recaptcha_type = get_option( 'user_registration_captcha_setting_recaptcha_version’, ‘v2’ );1511 $invisible_recaptcha = ur_option_checked( 'user_registration_captcha_setting_invisible_recaptcha_v2’, false );15121513 if ( ‘v2’ === $recaptcha_type && ! $invisible_recaptcha ) {1514 $recaptcha_site_key = get_option( ‘user_registration_captcha_setting_recaptcha_site_key’ );1515 $recaptcha_site_secret = get_option( ‘user_registration_captcha_setting_recaptcha_site_secret’ );1516 $enqueue_script = 'ur-google-recaptcha’;1517 } elseif ( ‘v2’ === $recaptcha_type && $invisible_recaptcha ) {1518 $recaptcha_site_key = get_option( ‘user_registration_captcha_setting_recaptcha_invisible_site_key’ );1519 $recaptcha_site_secret = get_option( ‘user_registration_captcha_setting_recaptcha_invisible_site_secret’ );1520 $enqueue_script = 'ur-google-recaptcha’;1521 } elseif ( ‘v3’ === $recaptcha_type ) {1522 $recaptcha_site_key = get_option( ‘user_registration_captcha_setting_recaptcha_site_key_v3’ );1523 $recaptcha_site_secret = get_option( ‘user_registration_captcha_setting_recaptcha_site_secret_v3’ );1524 $enqueue_script = 'ur-google-recaptcha-v3’;1525 } elseif ( ‘hCaptcha’ === $recaptcha_type ) {1526 $recaptcha_site_key = get_option( ‘user_registration_captcha_setting_recaptcha_site_key_hcaptcha’ );1527 $recaptcha_site_secret = get_option( ‘user_registration_captcha_setting_recaptcha_site_secret_hcaptcha’ );1528 $enqueue_script = 'ur-recaptcha-hcaptcha’;1529 }1530 static $rc_counter = 0;15311532 if ( $recaptcha_enabled ) {15331534 if ( 0 === $rc_counter ) {1535 wp_enqueue_script( ‘ur-recaptcha’ );1536 wp_enqueue_script( $enqueue_script );15371538 $ur_google_recaptcha_code = array(1539 ‘site_key’ => $recaptcha_site_key,1540 ‘is_captcha_enable’ => true,1541 ‘version’ => $recaptcha_type,1542 ‘is_invisible’ => $invisible_recaptcha,1543 );15441545 if ( function_exists( ‘wp_is_block_theme’ ) && wp_is_block_theme() ) {1546 ?>1547 <script id="<?php echo esc_attr( $enqueue_script ); ?>">1548 const ur_recaptcha_code = <?php echo wp_json_encode( $ur_google_recaptcha_code ); ?>1549 </script>1550 <?php1551 } else {1552 wp_localize_script( $enqueue_script, 'ur_recaptcha_code’, $ur_google_recaptcha_code );1553 }1554 $rc_counter++;1555 }15561557 if ( ‘v3’ === $recaptcha_type ) {1558 if ( ‘login’ === $context ) {1559 $recaptcha_node = '<div id="node_recaptcha_login" class="g-recaptcha-v3" style="display:none"><textarea id="g-recaptcha-response" name="g-recaptcha-response" ></textarea></div>’;1560 } elseif ( ‘register’ === $context ) {1561 $recaptcha_node = '<div id="node_recaptcha_register" class="g-recaptcha-v3" style="display:none"><textarea id="g-recaptcha-response" name="g-recaptcha-response" ></textarea></div>’;1562 } elseif ( ‘lost_password’ === $context ) {1563 $recaptcha_node = '<div id="node_recaptcha_lost_password" class="g-recaptcha-v3" style="display:none"><textarea id="g-recaptcha-response" name="g-recaptcha-response" ></textarea></div>’;1564 } else {1565 $recaptcha_node = '’;1566 }1567 } elseif ( ‘hCaptcha’ === $recaptcha_type ) {15681569 if ( ‘login’ === $context ) {1570 $recaptcha_node = '<div id="node_recaptcha_login" class="g-recaptcha-hcaptcha"></div>’;15711572 } elseif ( ‘register’ === $context ) {1573 $recaptcha_node = '<div id="node_recaptcha_register" class="g-recaptcha-hcaptcha"></div>’;1574 } elseif ( ‘lost_password’ === $context ) {1575 $recaptcha_node = '<div id="node_recaptcha_lost_password" class="g-recaptcha-hcaptcha"></div>’;1576 } else {1577 $recaptcha_node = '’;1578 }1579 } else {1580 if ( ‘v2’ === $recaptcha_type && $invisible_recaptcha ) {1581 if ( ‘login’ === $context ) {1582 $recaptcha_node = '<div id="node_recaptcha_login" class="g-recaptcha" data-size="invisible"></div>’;1583 } elseif ( ‘register’ === $context ) {1584 $recaptcha_node = '<div id="node_recaptcha_register" class="g-recaptcha" data-size="invisible"></div>’;1585 } elseif ( ‘lost_password’ === $context ) {1586 $recaptcha_node = '<div id="node_recaptcha_lost_password" class="g-recaptcha" data-size="invisible"></div>’;1587 } else {1588 $recaptcha_node = '’;1589 }1590 } else {1591 if ( ‘login’ === $context ) {1592 $recaptcha_node = '<div id="node_recaptcha_login" class="g-recaptcha"></div>’;15931594 } elseif ( ‘register’ === $context ) {1595 $recaptcha_node = '<div id="node_recaptcha_register" class="g-recaptcha"></div>’;1596 } elseif ( ‘lost_password’ === $context ) {1597 $recaptcha_node = '<div id="node_recaptcha_lost_password" class="g-recaptcha"></div>’;1598 } else {1599 $recaptcha_node = '’;1600 }1601 }1602 }1603 } else {1604 $recaptcha_node = '’;1605 }16061607 return $recaptcha_node;1608}16091610/**1611 * Get meta key label pair by form id1612 *1613 * @param int $form_id Form ID.1614 * @since 1.5.01615 * @return array1616 */1617function ur_get_meta_key_label( $form_id ) {16181619 $key_label = array();16201621 $post_content_array = ( $form_id ) ? UR()->form->get_form( $form_id, array( ‘content_only’ => true ) ) : array();16221623 foreach ( $post_content_array as $post_content_row ) {1624 foreach ( $post_content_row as $post_content_grid ) {1625 foreach ( $post_content_grid as $field ) {1626 if ( isset( $field->field_key ) && isset( $field->general_setting->field_name ) ) {1627 $key_label[ $field->general_setting->field_name ] = $field->general_setting->label;1628 }1629 }1630 }1631 }16321633 return apply_filters( 'user_registration_meta_key_label’, $key_label, $form_id, $post_content_array );1634}16351636/**1637 * Get all user registration fields of the user by querying to database.1638 *1639 * @param int $user_id User ID.1640 * @since 1.5.01641 * @return array1642 */1643function ur_get_user_extra_fields( $user_id ) {1644 $name_value = array();16451646 $admin_profile = new UR_Admin_Profile();1647 $extra_data = $admin_profile->get_user_meta_by_form_fields( $user_id );1648 $form_fields = isset( array_column( $extra_data, ‘fields’ )[0] ) ? array_column( $extra_data, ‘fields’ )[0] : array(); //phpcs:ignore1649 if ( ! empty( $form_fields ) ) {1650 foreach ( $form_fields as $field_key => $field_data ) {1651 $value = get_user_meta( $user_id, $field_key, true );1652 $field_key = str_replace( 'user_registration_’, '’, $field_key );16531654 if ( is_serialized( $value ) ) {1655 $value = unserialize( $value, array( ‘allowed_classes’ => false ) ); //phpcs:ignore1656 $value = implode( ‘,’, $value );1657 }16581659 $name_value[ $field_key ] = $value;16601661 }1662 }16631664 return apply_filters( ‘user_registration_user_extra_fields’, $name_value, $user_id );1665}16661667/**1668 * Get User status like approved, pending.1669 *1670 * @param string $user_status Admin approval status of user.1671 * @param string $user_email_status Email confirmation status of user.1672 */1673function ur_get_user_status( $user_status, $user_email_status ) {1674 $status = array();1675 if ( ‘0’ === $user_status || ‘0’ === $user_email_status ) {1676 array_push( $status, ‘Pending’ );1677 } elseif ( '-1’ === $user_status || '-1’ === $user_email_status ) {1678 array_push( $status, ‘Denied’ );1679 } else {1680 if ( $user_email_status ) {1681 array_push( $status, ‘Verified’ );1682 } else {1683 array_push( $status, ‘Approved’ );1684 }1685 }1686 return $status;1687}16881689/**1690 * Get link for back button used on email settings.1691 *1692 * @param string $label Label.1693 * @param string $url URL.1694 */1695function ur_back_link( $label, $url ) {1696 return ‘<small class="ur-admin-breadcrumb"><a href="’ . esc_url( $url ) . ‘" aria-label="’ . esc_attr( $label ) . '">⤴</a></small>’;1697}16981699/**1700 * The function wp_doing ajax() is introduced in core @since 4.7,1701 */1702if ( ! function_exists( ‘wp_doing_ajax’ ) ) {1703 /**1704 * Filters whether the current request is a WordPress Ajax request.1705 */1706 function wp_doing_ajax() {1707 return apply_filters( 'wp_doing_ajax’, defined( ‘DOING_AJAX’ ) && DOING_AJAX );1708 }1709}17101711/**1712 * Checks if the string is json or not1713 *1714 * @param string $str String to check.1715 * @since 1.4.21716 * @return mixed1717 */1718function ur_is_json( $str ) {1719 if ( ! is_string( $str ) ) {1720 return false;1721 }17221723 $json = json_decode( $str );1724 return $json && $str != $json && json_last_error() == JSON_ERROR_NONE;1725}17261727/**1728 * Checks if the form contains a date field or not.1729 *1730 * @param int $form_id Form ID.1731 * @since 1.5.31732 * @return boolean1733 */1734function ur_has_date_field( $form_id ) {17351736 $post_content_array = ( $form_id ) ? UR()->form->get_form( $form_id, array( ‘content_only’ => true ) ) : array();17371738 if ( ! empty( $post_content_array ) ) {1739 foreach ( $post_content_array as $post_content_row ) {1740 foreach ( $post_content_row as $post_content_grid ) {1741 foreach ( $post_content_grid as $field ) {1742 if ( isset( $field->field_key ) && ‘date’ === $field->field_key ) {1743 return true;1744 }1745 }1746 }1747 }1748 }17491750 return false;1751}17521753/**1754 * Get attributes from the shortcode content.1755 *1756 * @param string $content Shortcode content.1757 * @return array Array of attributes within the shortcode.1758 *1759 * @since 1.6.01760 */1761function ur_get_shortcode_attr( $content ) {1762 $pattern = get_shortcode_regex();17631764 $keys = array();1765 $result = array();17661767 if ( preg_match_all( ‘/’ . $pattern . '/s’, $content, $matches ) ) {17681769 foreach ( $matches[0] as $key => $value ) {17701771 // $matches[ 3 ] return the shortcode attribute as string.1772 // replace space with ‘&’ for parse_str() function.1773 $get = str_replace( ' ', '&’, $matches[3][ $key ] );1774 parse_str( $get, $output );17751776 // Get all shortcode attribute keys.1777 $keys = array_unique( array_merge( $keys, array_keys( $output ) ) );1778 $result[] = $output;1779 }17801781 if ( $keys && $result ) {17821783 // Loop the result array and add the missing shortcode attribute key.1784 foreach ( $result as $key => $value ) {17851786 // Loop the shortcode attribute key.1787 foreach ( $keys as $attr_key ) {1788 $result[ $key ][ $attr_key ] = isset( $result[ $key ][ $attr_key ] ) ? $result[ $key ][ $attr_key ] : null;1789 }17901791 // Sort the array key.1792 ksort( $result[ $key ] );1793 }1794 }1795 }17961797 return $result;1798}17991800/**1801 * Print js script by properly sanitizing and escaping.1802 *1803 * @since 1.1.21804 * Output any queued javascript code in the footer.1805 */1806function ur_print_js() {1807 global $ur_queued_js;18081809 if ( ! empty( $ur_queued_js ) ) {1810 // Sanitize.1811 $ur_queued_js = wp_check_invalid_utf8( $ur_queued_js );1812 $ur_queued_js = preg_replace( '/&#(x)?0*(?(1)27|39);?/i’, “’", $ur_queued_js );1813 $ur_queued_js = str_replace( “\r", '’, $ur_queued_js );18141815 $js = “<!-- User Registration JavaScript -->\n<script type=\"text/javascript\">\njQuery(function($) { $ur_queued_js });\n</script>\n";18161817 /**1818 * User Registration js filter.1819 *1820 * @param string $js JavaScript code.1821 */1822 echo wp_kses( apply_filters( 'user_registration_queued_js’, $js ), array( ‘script’ => array( ‘type’ => true ) ) );18231824 unset( $ur_queued_js );1825 }1826}1827/**1828 * Enqueue UR js.1829 *1830 * @since 1.1.21831 * Queue some JavaScript code to be output in the footer.1832 *1833 * @param string $code Code to enqueue.1834 */1835function ur_enqueue_js( $code ) {1836 global $ur_queued_js;18371838 if ( empty( $ur_queued_js ) ) {1839 $ur_queued_js = '’;1840 }18411842 $ur_queued_js .= “\n” . $code . “\n";1843}18441845/**1846 * Delete expired transients.1847 *1848 * Deletes all expired transients. The multi-table delete syntax is used.1849 * to delete the transient record from table a, and the corresponding.1850 * transient_timeout record from table b.1851 *1852 * Based on code inside core’s upgrade_network() function.1853 *1854 * @since 1.2.01855 * @return int Number of transients that were cleared.1856 */1857function ur_delete_expired_transients() {1858 global $wpdb;18591860 $sql = “DELETE a, b FROM $wpdb->options a, $wpdb->options b1861 WHERE a.option_name LIKE %s1862 AND a.option_name NOT LIKE %s1863 AND b.option_name = CONCAT( '_transient_timeout_’, SUBSTRING( a.option_name, 12 ) )1864 AND b.option_value < %d";1865 $rows = $wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( ‘_transient_’ ) . '%’, $wpdb->esc_like( ‘_transient_timeout_’ ) . '%’, time() ) ); // WPCS: unprepared SQL ok.18661867 $sql = “DELETE a, b FROM $wpdb->options a, $wpdb->options b1868 WHERE a.option_name LIKE %s1869 AND a.option_name NOT LIKE %s1870 AND b.option_name = CONCAT( '_site_transient_timeout_’, SUBSTRING( a.option_name, 17 ) )1871 AND b.option_value < %d";1872 $rows2 = $wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( ‘_site_transient_’ ) . '%’, $wpdb->esc_like( ‘_site_transient_timeout_’ ) . '%’, time() ) ); // WPCS: unprepared SQL ok.18731874 return absint( $rows + $rows2 );1875}1876add_action( 'user_registration_installed’, ‘ur_delete_expired_transients’ );18771878/**1879 * String translation function.1880 *1881 * @since 1.7.31882 *1883 * @param int $form_id Form ID.1884 * @param string $field_id Field ID.1885 * @param mixed $variable To be translated for WPML compatibility.1886 */1887function ur_string_translation( $form_id, $field_id, $variable ) {1888 if ( function_exists( ‘icl_register_string’ ) ) {1889 icl_register_string( isset( $form_id ) && 0 !== $form_id ? ‘user_registration_’ . absint( $form_id ) : 'user-registration’, isset( $field_id ) ? $field_id : '’, $variable );1890 }1891 if ( function_exists( ‘icl_t’ ) ) {1892 $variable = icl_t( isset( $form_id ) && 0 !== $form_id ? ‘user_registration_’ . absint( $form_id ) : 'user-registration’, isset( $field_id ) ? $field_id : '’, $variable );1893 }1894 return $variable;1895}18961897/**1898 * Get Form ID from User ID.1899 *1900 * @param int $user_id User ID.1901 *1902 * @return int $form_id Form ID.1903 */1904function ur_get_form_id_by_userid( $user_id ) {1905 $form_id_array = get_user_meta( $user_id, ‘ur_form_id’ );1906 $form_id = 0;19071908 if ( isset( $form_id_array[0] ) ) {1909 $form_id = $form_id_array[0];1910 }1911 return $form_id;1912}19131914/**1915 * Get source ID through which the given user was supposedly registered.1916 *1917 * @since 1.9.01918 *1919 * @param int $user_id User ID.1920 *1921 * @return mixed1922 */1923function ur_get_registration_source_id( $user_id ) {1924 $user_metas = get_user_meta( $user_id );19251926 if ( isset( $user_metas[‘user_registration_social_connect_bypass_current_password’] ) ) {1927 $networks = array( 'facebook’, 'linkedin’, ‘google’, ‘twitter’ );19281929 foreach ( $networks as $network ) {19301931 if ( isset( $user_metas[ ‘user_registration_social_connect_’ . $network . ‘_username’ ] ) ) {1932 return $network;1933 }1934 }1935 } elseif ( isset( $user_metas[‘ur_form_id’] ) ) {1936 return $user_metas[‘ur_form_id’][0];1937 } else {1938 return null;1939 }1940}19411942/**1943 * Check if a datetime falls in a range of time.1944 *1945 * @since 1.9.01946 *1947 * @param string $target_date Target date.1948 * @param string|null $start_date Start date.1949 * @param string|null $end_date End date.1950 *1951 * @return bool1952 */1953function ur_falls_in_date_range( $target_date, $start_date = null, $end_date = null ) {1954 $start_ts = strtotime( $start_date );1955 $end_ts = strtotime( $end_date . ' +1 Day’ );1956 $target_date_ts = strtotime( $target_date );19571958 // If the starting and the ending date are set as same.1959 if ( $start_ts === $end_ts ) {1960 $datetime = new DateTime();1961 $datetime->setTimestamp( $end_ts );19621963 date_add( $datetime, date_interval_create_from_date_string( ‘23 hours 59 mins 59 secs’ ) );1964 $end_ts = $datetime->getTimestamp();1965 }19661967 if ( $start_date && $end_date ) {1968 return ( $start_ts <= $target_date_ts ) && ( $target_date_ts <= $end_ts );1969 } elseif ( $start_date ) {1970 return ( $start_ts <= $target_date_ts );1971 } elseif ( $end_date ) {1972 return ( $target_date_ts <= $end_ts );1973 } else {1974 return false;1975 }1976}19771978/**1979 * Get Post Content By Form ID.1980 *1981 * @param int $form_id Form Id.1982 *1983 * @return array|mixed|null|object1984 */1985function ur_get_post_content( $form_id ) {19861987 $args = array(1988 ‘post_type’ => 'user_registration’,19891990 ‘post_status’ => 'publish’,19911992 ‘post__in’ => array( $form_id ),1993 );1994 $post_data = get_posts( $args );19951996 if ( isset( $post_data[0]->post_content ) ) {19971998 return json_decode( $post_data[0]->post_content );19992000 } else {20012002 return array();2003 }2004}20052006/**2007 * A wp_parse_args() for multi-dimensional array.2008 *2009 * @see https://developer.wordpress.org/reference/functions/wp_parse_args/2010 *2011 * @since 1.9.02012 *2013 * @param array $args Value to merge with $defaults.2014 * @param array $defaults Array that serves as the defaults.2015 *2016 * @return array Merged user defined values with defaults.2017 */2018function ur_parse_args( &$args, $defaults ) {2019 $args = (array) $args;2020 $defaults = (array) $defaults;2021 $result = $defaults;2022 foreach ( $args as $k => &$v ) {2023 if ( is_array( $v ) && isset( $result[ $k ] ) ) {2024 $result[ $k ] = ur_parse_args( $v, $result[ $k ] );2025 } else {2026 $result[ $k ] = $v;2027 }2028 }2029 return $result;2030}20312032/**2033 * Override email content for specific form.2034 *2035 * @param int $form_id Form Id.2036 * @param object $settings Settings for specific email.2037 * @param string $message Message to be sent in email body.2038 * @param string $subject Subject of the email.2039 *2040 * @return array2041 */2042function user_registration_email_content_overrider( $form_id, $settings, $message, $subject ) {2043 // Check if email templates addon is active.2044 if ( class_exists( ‘User_Registration_Email_Templates’ ) ) {2045 $email_content_override = ur_get_single_post_meta( $form_id, 'user_registration_email_content_override’, ‘’ );20462047 // Check if the post meta exists and have contents.2048 if ( $email_content_override ) {20492050 $auto_password_template_overrider = isset( $email_content_override[ $settings->id ] ) ? $email_content_override[ $settings->id ] : '’;20512052 // Check if the email override is enabled.2053 if ( ‘’ !== $auto_password_template_overrider && ur_string_to_bool( $auto_password_template_overrider[‘override’] ) ) {2054 $message = $auto_password_template_overrider[‘content’];2055 $subject = $auto_password_template_overrider[‘subject’];2056 }2057 }2058 }2059 return array( $message, $subject );2060}20612062/** Get User Data in particular array format.2063 *2064 * @param string $new_string Field Key.2065 * @param string $post_key Post Key.2066 * @param array $profile Form Data.2067 * @param mixed $value Value.2068 */2069function ur_get_valid_form_data_format( $new_string, $post_key, $profile, $value ) {2070 $valid_form_data = array();2071 if ( isset( $profile[ $post_key ] ) ) {2072 $field_type = $profile[ $post_key ][‘type’];20732074 switch ( $field_type ) {2075 case 'checkbox’:2076 case 'multi_select2’:2077 if ( ! is_array( $value ) && ! empty( $value ) ) {2078 $value = maybe_unserialize( $value );2079 }2080 break;2081 case 'file’:2082 $files = is_array( $value ) ? $value : explode( ',’, $value );20832084 if ( is_array( $files ) && isset( $files[0] ) ) {2085 $attachment_ids = '’;20862087 foreach ( $files as $key => $file ) {2088 $seperator = 0 < $key ? ‘,’ : '’;20892090 if ( wp_http_validate_url( $file ) ) {20912092 $attachment_ids = $attachment_ids . ‘’ . $seperator . ‘’ . attachment_url_to_postid( $file );2093 }2094 }2095 $value = ! empty( $attachment_ids ) ? $attachment_ids : $value;2096 } else {20972098 if ( wp_http_validate_url( $value ) ) {2099 $value = attachment_url_to_postid( $value );2100 }2101 }2102 break;2103 }2104 $valid_form_data[ $new_string ] = new stdClass();2105 $valid_form_data[ $new_string ]->field_name = $new_string;2106 $valid_form_data[ $new_string ]->value = $value;2107 $valid_form_data[ $new_string ]->field_type = $profile[ $post_key ][‘type’];2108 $valid_form_data[ $new_string ]->label = $profile[ $post_key ][‘label’];2109 $valid_form_data[ $new_string ]->extra_params = array(2110 ‘field_key’ => $profile[ $post_key ][‘field_key’],2111 ‘label’ => $profile[ $post_key ][‘label’],2112 );2113 } else {2114 $valid_form_data[ $new_string ] = new stdClass();2115 $valid_form_data[ $new_string ]->field_name = $new_string;2116 $valid_form_data[ $new_string ]->value = $value;2117 $valid_form_data[ $new_string ]->extra_params = array(2118 ‘field_key’ => $new_string,2119 );2120 }2121 return $valid_form_data;2122}21232124/**2125 * Add our login and my account shortcodes to conflicting shortcodes filter of All In One Seo plugin to resolve the conflict2126 *2127 * @param array $conflict_shortcodes Array of shortcodes that All in one Seo is conflicting with.2128 *2129 * @since 1.9.42130 */2131function ur_resolve_conflicting_shortcodes_with_aioseo( $conflict_shortcodes ) {2132 $ur_shortcodes = array(2133 ‘User Registration My Account’ => '[user_registration_my_account]',2134 ‘User Registration Login’ => '[user_registration_login]',2135 );21362137 $conflict_shortcodes = array_merge( $conflict_shortcodes, $ur_shortcodes );2138 return $conflict_shortcodes;2139}21402141add_filter( 'aioseo_conflicting_shortcodes’, ‘ur_resolve_conflicting_shortcodes_with_aioseo’ );21422143/**2144 * Parse name values and smart tags2145 *2146 * @param int $user_id User ID.2147 * @param int $form_id Form ID.2148 * @param array $valid_form_data Form filled data.2149 *2150 * @since 1.9.62151 *2152 * @return array2153 */2154function ur_parse_name_values_for_smart_tags( $user_id, $form_id, $valid_form_data ) {21552156 $name_value = array();2157 $data_html = '<table class="user-registration-email__entries” cellpadding="0” cellspacing="0"><tbody>’;21582159 // Generate $data_html string to replace for {{all_fields}} smart tag.2160 foreach ( $valid_form_data as $field_meta => $form_data ) {21612162 if ( ‘user_confirm_password’ === $field_meta || ‘user_pass’ === $field_meta || preg_match( '/password_/’, $field_meta ) ) {2163 continue;2164 }21652166 // Donot include privacy policy value.2167 if ( isset( $form_data->extra_params[‘field_key’] ) && ‘privacy_policy’ === $form_data->extra_params[‘field_key’] ) {2168 continue;2169 }21702171 if ( isset( $form_data->extra_params[‘field_key’] ) && ‘country’ === $form_data->extra_params[‘field_key’] && ‘’ !== $form_data->value ) {2172 $country_class = ur_load_form_field_class( $form_data->extra_params[‘field_key’] );2173 $countries = $country_class::get_instance()->get_country();2174 $form_data->value = isset( $countries[ $form_data->value ] ) ? $countries[ $form_data->value ] : $form_data->value;2175 }21762177 $label = isset( $form_data->extra_params[‘label’] ) ? $form_data->extra_params[‘label’] : '’;2178 $field_name = isset( $form_data->field_name ) ? $form_data->field_name : '’;2179 $value = isset( $form_data->value ) ? $form_data->value : '’;21802181 if ( ‘user_pass’ === $field_meta ) {2182 $value = __( 'Chosen Password’, ‘user-registration’ );2183 }21842185 // Check if value contains array.2186 if ( is_array( $value ) ) {2187 $value = implode( ‘,’, $value );2188 }21892190 $data_html .= ‘<tr><td>’ . $label . ' : </td><td>’ . $value . '</td></tr>’;21912192 $name_value[ $field_name ] = $value;2193 }21942195 $data_html .= '</tbody></table>’;21962197 // Smart tag process for extra fields.2198 $name_value = apply_filters( 'user_registration_process_smart_tag’, $name_value, $valid_form_data, $form_id, $user_id );21992200 return array( $name_value, $data_html );2201}22022203/**2204 * Get field data by field_name.2205 *2206 * @param int $form_id Form Id.2207 * @param string $field_name Field Name.2208 *2209 * @return array2210 */2211function ur_get_field_data_by_field_name( $form_id, $field_name ) {2212 $field_data = array();22132214 $post_content_array = ( $form_id ) ? UR()->form->get_form( $form_id, array( ‘content_only’ => true ) ) : array();22152216 foreach ( $post_content_array as $post_content_row ) {2217 foreach ( $post_content_row as $post_content_grid ) {2218 if ( is_array( $post_content_grid ) || is_object( $post_content_grid ) ) {2219 foreach ( $post_content_grid as $field ) {2220 if ( isset( $field->field_key ) && isset( $field->general_setting->field_name ) && $field->general_setting->field_name === $field_name ) {2221 $field_data = array(2222 ‘field_key’ => $field->field_key,2223 ‘general_setting’ => $field->general_setting,2224 ‘advance_setting’ => $field->advance_setting,2225 );2226 }2227 }2228 }2229 }2230 }2231 return $field_data;2232}22332234if ( ! function_exists( ‘user_registration_pro_get_conditional_fields_by_form_id’ ) ) {2235 /**2236 * Get form fields by form id2237 *2238 * @param int $form_id Form ID.2239 * @param string $selected_field_key Field Key.2240 */2241 function user_registration_pro_get_conditional_fields_by_form_id( $form_id, $selected_field_key ) {2242 $args = array(2243 ‘post_type’ => 'user_registration’,2244 ‘post_status’ => 'publish’,2245 ‘post__in’ => array( $form_id ),2246 );2247 $post_data = get_posts( $args );2248 // wrap all fields in array.2249 $fields = array();2250 if ( isset( $post_data[0]->post_content ) ) {2251 $post_content_array = json_decode( $post_data[0]->post_content );22522253 if ( ! is_null( $post_content_array ) ) {2254 foreach ( $post_content_array as $data ) {2255 foreach ( $data as $single_data ) {2256 foreach ( $single_data as $field_data ) {2257 if ( isset( $field_data->general_setting->field_name )2258 && isset( $field_data->general_setting->label ) ) {22592260 $strip_fields = array(2261 'section_title’,2262 'html’,2263 'wysiwyg’,2264 'billing_address_title’,2265 'shipping_address_title’,2266 'stripe_gateway’,2267 'profile_picture’,2268 'file’,2269 );22702271 if ( in_array( $field_data->field_key, $strip_fields, true ) ) {2272 continue;2273 }22742275 $fields[ $field_data->general_setting->field_name ] = array(2276 ‘label’ => $field_data->general_setting->label,2277 ‘field_key’ => $field_data->field_key,2278 );2279 }2280 }2281 }2282 }2283 }2284 }2285 // Unset selected meta key.2286 unset( $fields[ $selected_field_key ] );2287 return $fields;2288 }2289}22902291if ( ! function_exists( ‘user_registration_pro_render_conditional_logic’ ) ) {2292 /**2293 * Render Conditional Logic in form settings of form builder.2294 *2295 * @param array $connection Connection Data.2296 * @param string $integration Integration.2297 * @param int $form_id Form ID.2298 * @return string2299 */2300 function user_registration_pro_render_conditional_logic( $connection, $integration, $form_id ) {2301 $output = '<div class="ur_conditional_logic_container">’;2302 $output .= ‘<h4>’ . esc_html__( 'Conditional Logic’, ‘user-registration’ ) . '</h4>’;2303 $output .= '<div class="ur_use_conditional_logic_wrapper ur-check">’;2304 $checked = '’;23052306 if ( isset( $connection[‘enable_conditional_logic’] ) && ur_string_to_bool( $connection[‘enable_conditional_logic’] ) ) {23072308 $checked = 'checked=checked’;2309 }2310 $output .= '<div class="ur-toggle-section ur-form-builder-toggle">’;2311 $output .= '<span class="user-registration-toggle-form">’;2312 $output .= '<input class="ur-use-conditional-logic” type="checkbox” name="ur_use_conditional_logic” id="ur_use_conditional_logic” ' . $checked . '>’;2313 $output .= '<span class="slider round">’;2314 $output .= '</span>’;2315 $output .= '</span>’;2316 $output .= ‘<label>’ . esc_html__( 'Use conditional logics’, ‘user-registration’ ) . '</label>’;2317 $output .= '</div>’;2318 $output .= '</div>’;23192320 $output .= ‘<div class="ur_conditional_logic_wrapper" data-source="’ . esc_attr( $integration ) . '">’;2321 $output .= ‘<h4>’ . esc_html__( 'Conditional Rules’, ‘user-registration’ ) . '</h4>’;2322 $output .= ‘<div class="ur-logic"><p>’ . esc_html__( 'Send data only if the following matches.’, ‘user-registration’ ) . '</p></div>’;2323 $output .= '<div class="ur-conditional-wrapper">’;2324 $output .= '<select class="ur_conditional_field" name="ur_conditional_field">’;2325 $get_all_fields = user_registration_pro_get_conditional_fields_by_form_id( $form_id, ‘’ );2326 $selected_ur_field_type = '’;23272328 if ( isset( $get_all_fields ) ) {23292330 foreach ( $get_all_fields as $key => $field ) {2331 $selected_attr = '’;23322333 if ( isset( $connection[‘conditional_logic_data’][‘conditional_field’] ) && $connection[‘conditional_logic_data’][‘conditional_field’] === $key ) {2334 $selected_attr = 'selected=selected’;2335 $selected_ur_field_type = $field[‘field_key’];2336 }2337 $output .= ‘<option data-type="’ . esc_attr( $field[‘field_key’] ) . ‘" data-label="’ . esc_attr( $field[‘label’] ) . ‘" value="’ . esc_attr( $key ) . '" ' . $selected_attr . ‘>’ . esc_html( $field[‘label’] ) . '</option>’;2338 }2339 }2340 $output .= '</select>’;2341 $output .= '<select class="ur-conditional-condition" name="ur-conditional-condition">’;2342 $output .= '<option value="is" ' . ( isset( $connection[‘conditional_logic_data’][‘conditional_operator’] ) && ‘is’ === $connection[‘conditional_logic_data’][‘conditional_operator’] ? ‘selected’ : ‘’ ) . '> is </option>’;2343 $output .= '<option value="is_not" ' . ( isset( $connection[‘conditional_logic_data’][‘conditional_operator’] ) && ‘is_not’ === $connection[‘conditional_logic_data’][‘conditional_operator’] ? ‘selected’ : ‘’ ) . '> is not </option>’;2344 $output .= '</select>’;23452346 if ( ‘checkbox’ == $selected_ur_field_type || ‘radio’ == $selected_ur_field_type || ‘select’ == $selected_ur_field_type || ‘country’ == $selected_ur_field_type || ‘billing_country’ == $selected_ur_field_type || ‘shipping_country’ == $selected_ur_field_type || ‘select2’ == $selected_ur_field_type || ‘multi_select2’ == $selected_ur_field_type ) {2347 $choices = user_registration_pro_get_checkbox_choices( $form_id, $connection[‘conditional_logic_data’][‘conditional_field’] );2348 $output .= '<select name="ur-conditional-input" class="ur-conditional-input">’;23492350 if ( is_array( $choices ) && array_filter( $choices ) ) {2351 $output .= '<option>–select–</option>’;23522353 foreach ( $choices as $key => $choice ) {2354 $key = ‘country’ == $selected_ur_field_type ? $key : $choice;2355 $selectedvalue = isset( $connection[‘conditional_logic_data’][‘conditional_value’] ) && $connection[‘conditional_logic_data’][‘conditional_value’] == $key ? ‘selected="selected"’ : '’;2356 $output .= ‘<option ' . $selectedvalue . ' value="’ . esc_attr( $key ) . ‘">’ . esc_html( $choice ) . '</option>’;2357 }2358 } else {2359 $selected = isset( $connection[‘conditional_logic_data’][‘conditional_value’] ) ? $connection[‘conditional_logic_data’][‘conditional_value’] : 0;2360 $output .= ‘<option value="1" ' . ( ur_string_to_bool( $selected ) ? ‘selected="selected"’ : ‘’ ) . ' >’ . esc_html__( 'Checked’, ‘user-registration’ ) . '</option>’;2361 }2362 $output .= '</select>’;2363 } else {2364 $value = isset( $connection[‘conditional_logic_data’][‘conditional_value’] ) ? $connection[‘conditional_logic_data’][‘conditional_value’] : '’;2365 $output .= ‘<input class="ur-conditional-input" type="text" name="ur-conditional-input" value="’ . esc_attr( $value ) . '">’;2366 }2367 $output .= '</div>’;2368 $output .= '</div>’;2369 $output .= '</div>’;2370 return $output;2371 }2372}237323742375if ( ! function_exists( ‘user_registration_pro_get_checkbox_choices’ ) ) {2376 /**2377 * Get Select and Checkbox Fields Choices2378 *2379 * @param int $form_id Form ID.2380 * @param string $field_name Field Name.2381 * @return array $choices2382 */2383 function user_registration_pro_get_checkbox_choices( $form_id, $field_name ) {23842385 $form_data = (object) user_registration_pro_get_field_data( $form_id, $field_name );2386 /* Backward Compatibility. Modified since 1.5.7. To be removed later. */2387 $advance_setting_choices = isset( $form_data->advance_setting->choices ) ? $form_data->advance_setting->choices : '’;2388 $advance_setting_options = isset( $form_data->advance_setting->options ) ? $form_data->advance_setting->options : '’;2389 /* Bacward Compatibility end.*/23902391 $choices = isset( $form_data->general_setting->options ) ? $form_data->general_setting->options : '’;23922393 /* Backward Compatibility. Modified since 1.5.7. To be removed later. */2394 if ( ! empty( $advance_setting_choices ) ) {2395 $choices = explode( ',’, $advance_setting_choices );2396 } elseif ( ! empty( $advance_setting_options ) ) {2397 $choices = explode( ',’, $advance_setting_options );2398 /* Backward Compatibility end. */23992400 } elseif ( ‘country’ === $form_data->field_key ) {2401 $country = new UR_Form_Field_Country();2402 $country->get_country();2403 $choices = $country->get_country();2404 }24052406 return $choices;2407 }2408}24092410if ( ! function_exists( ‘user_registration_pro_get_field_data’ ) ) {2411 /**2412 * Get all fields data2413 *2414 * @param int $form_id Form ID.2415 * @param string $field_name Field Name.2416 * @return array $field_data.2417 */2418 function user_registration_pro_get_field_data( $form_id, $field_name ) {2419 $args = array(2420 ‘post_type’ => 'user_registration’,2421 ‘post_status’ => 'publish’,2422 ‘post__in’ => array( $form_id ),2423 );2424 $post_data = get_posts( $args );24252426 if ( isset( $post_data[0]->post_content ) ) {2427 $post_content_array = json_decode( $post_data[0]->post_content );24282429 foreach ( $post_content_array as $data ) {2430 foreach ( $data as $single_data ) {2431 foreach ( $single_data as $field_data ) {2432 isset( $field_data->general_setting->field_name ) ? $field_data->general_setting->field_name : '’;2433 if ( $field_data->general_setting->field_name === $field_name ) {2434 return $field_data;2435 }2436 }2437 }2438 }2439 }2440 }2441}24422443if ( ! function_exists( ‘ur_install_extensions’ ) ) {2444 /**2445 * This function return boolean according to string to avoid colision of 1, true, yes.2446 *2447 * @param [string] $name Name of the extension.2448 * @param [string] $slug Slug of the extension.2449 * @throws Exception Extension Download and activation unsuccessful message.2450 */2451 function ur_install_extensions( $name, $slug ) {2452 try {24532454 $plugin = ‘user-registration-pro’ === $slug ? plugin_basename( sanitize_text_field( wp_unslash( $slug . ‘/user-registration.php’ ) ) ) : plugin_basename( sanitize_text_field( wp_unslash( $slug . ‘/’ . $slug . ‘.php’ ) ) );2455 $status = array(2456 ‘install’ => 'plugin’,2457 ‘slug’ => sanitize_key( wp_unslash( $slug ) ),2458 );24592460 if ( ! current_user_can( ‘install_plugins’ ) ) {2461 $status[‘errorMessage’] = esc_html__( 'Sorry, you are not allowed to install plugins on this site.’, ‘user-registration’ );24622463 /* translators: %1$s: Activation error message */2464 throw new Exception( sprintf( __( '<strong>Activation error:</strong> %1$s’, ‘user-registration’ ), $status[‘errorMessage’] ) );2465 }24662467 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php’;2468 include_once ABSPATH . 'wp-admin/includes/plugin-install.php’;24692470 if ( file_exists( WP_PLUGIN_DIR . ‘/’ . $slug ) ) {2471 $plugin_data = get_plugin_data( WP_PLUGIN_DIR . ‘/’ . $plugin );2472 $status[‘plugin’] = $plugin;2473 $status[‘pluginName’] = $plugin_data[‘Name’];24742475 if ( current_user_can( 'activate_plugin’, $plugin ) && is_plugin_inactive( $plugin ) ) {2476 $result = activate_plugin( $plugin );24772478 if ( is_wp_error( $result ) ) {2479 $status[‘errorCode’] = $result->get_error_code();2480 $status[‘errorMessage’] = $result->get_error_message();24812482 /* translators: %1$s: Activation error message */2483 throw new Exception( sprintf( __( '<strong>Activation error:</strong> %1$s’, ‘user-registration’ ), $status[‘errorMessage’] ) );2484 }24852486 $status[‘success’] = true;2487 $status[‘message’] = $name . ' has been installed and activated successfully’;24882489 return $status;2490 }2491 }24922493 $api = json_decode(2494 UR_Updater_Key_API::version(2495 array(2496 ‘license’ => get_option( ‘user-registration_license_key’ ),2497 ‘item_name’ => $name,2498 )2499 )2500 );25012502 if ( is_wp_error( $api ) ) {2503 $status[‘errorMessage’] = $api->get_error_message();25042505 /* translators: %1$s: Activation error message */2506 throw new Exception( sprintf( __( '<strong>Activation error:</strong> %1$s’, ‘user-registration’ ), $status[‘errorMessage’] ) );2507 }25082509 $status[‘pluginName’] = $api->name;2510 $api->version = isset( $api->new_version ) ? $api->new_version : '1.0.0’;25112512 $skin = new WP_Ajax_Upgrader_Skin();2513 $upgrader = new Plugin_Upgrader( $skin );2514 $result = $upgrader->install( $api->download_link );25152516 if ( defined( ‘WP_DEBUG’ ) && WP_DEBUG ) {2517 $status[‘debug’] = $skin->get_upgrade_messages();2518 }25192520 if ( is_wp_error( $result ) ) {2521 $status[‘errorCode’] = $result->get_error_code();2522 $status[‘errorMessage’] = $result->get_error_message();25232524 /* translators: %1$s: Activation error message */2525 throw new Exception( sprintf( __( '<strong>Activation error:</strong> %1$s’, ‘user-registration’ ), $status[‘errorMessage’] ) );2526 } elseif ( is_wp_error( $skin->result ) ) {2527 $status[‘errorCode’] = $skin->result->get_error_code();2528 $status[‘errorMessage’] = $skin->result->get_error_message();25292530 /* translators: %1$s: Activation error message */2531 throw new Exception( sprintf( __( '<strong>Activation error:</strong> %1$s’, ‘user-registration’ ), $status[‘errorMessage’] ) );2532 } elseif ( $skin->get_errors()->get_error_code() ) {2533 $status[‘errorMessage’] = $skin->get_error_messages();25342535 /* translators: %1$s: Activation error message */2536 throw new Exception( sprintf( __( '<strong>Activation error:</strong> %1$s’, ‘user-registration’ ), $status[‘errorMessage’] ) );2537 } elseif ( is_null( $result ) ) {2538 global $wp_filesystem;25392540 $status[‘errorCode’] = 'unable_to_connect_to_filesystem’;2541 $status[‘errorMessage’] = esc_html__( 'Unable to connect to the filesystem. Please confirm your credentials.’, ‘user-registration’ );25422543 // Pass through the error from WP_Filesystem if one was raised.2544 if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {2545 $status[‘errorMessage’] = esc_html( $wp_filesystem->errors->get_error_message() );2546 }25472548 /* translators: %1$s: Activation error message */2549 throw new Exception( sprintf( __( '<strong>Activation error:</strong> %1$s’, ‘user-registration’ ), $status[‘errorMessage’] ) );2550 }25512552 $install_status = install_plugin_install_status( $api );25532554 if ( current_user_can( 'activate_plugin’, $install_status[‘file’] ) ) {2555 if ( is_plugin_inactive( $install_status[‘file’] ) ) {2556 $status[‘activateUrl’] =2557 esc_url_raw(2558 add_query_arg(2559 array(2560 ‘action’ => 'activate’,2561 ‘plugin’ => $install_status[‘file’],2562 ‘_wpnonce’ => wp_create_nonce( ‘activate-plugin_’ . $install_status[‘file’] ),2563 ),2564 admin_url( ‘admin.php?page=user-registration-addons’ )2565 )2566 );2567 } else {2568 $status[‘deActivateUrl’] =2569 esc_url_raw(2570 add_query_arg(2571 array(2572 ‘action’ => 'deactivate’,2573 ‘plugin’ => $install_status[‘file’],2574 ‘_wpnonce’ => wp_create_nonce( ‘deactivate-plugin_’ . $install_status[‘file’] ),2575 ),2576 admin_url( ‘admin.php?page=user-registration-addons’ )2577 )2578 );2579 }2580 }25812582 $status[‘success’] = true;2583 $status[‘message’] = $name . ' has been installed and activated successfully’;25842585 return $status;25862587 } catch ( Exception $e ) {25882589 $message = $e->getMessage();2590 $status[‘success’] = false;2591 $status[‘message’] = $message;25922593 return $status;2594 }2595 }2596}25972598add_action( 'user_registration_init’, ‘ur_profile_picture_migration_script’ );25992600if ( ! function_exists( ‘ur_profile_picture_migration_script’ ) ) {26012602 /**2603 * Update usermeta from profile_pic_url to attachemnt id and move files to new directory.2604 *2605 * @since 1.5.0.2606 */2607 function ur_profile_picture_migration_script() {26082609 if ( ! get_option( 'ur_profile_picture_migrated’, false ) ) {26102611 $users = get_users(2612 array(2613 ‘meta_key’ => 'user_registration_profile_pic_url’,2614 )2615 );26162617 foreach ( $users as $user ) {2618 $user_registration_profile_pic_url = get_user_meta( $user->ID, 'user_registration_profile_pic_url’, true );26192620 if ( ! is_numeric( $user_registration_profile_pic_url ) ) {2621 $user_registration_profile_pic_attachment = attachment_url_to_postid( $user_registration_profile_pic_url );2622 if ( 0 != $user_registration_profile_pic_attachment ) {2623 update_user_meta( $user->ID, 'user_registration_profile_pic_url’, absint( $user_registration_profile_pic_attachment ) );2624 }2625 }2626 }26272628 update_option( 'ur_profile_picture_migrated’, true );2629 }2630 }2631}26322633add_action( 'delete_user’, 'ur_delete_user_files_on_user_delete’, 10, 3 );26342635if ( ! function_exists( ‘ur_delete_user_files_on_user_delete’ ) ) {26362637 /**2638 * Delete user uploaded files when user is deleted.2639 *2640 * @param [type] $user_id User Id.2641 * @param [type] $reassign Reassign to another user ( admin ).2642 * @param [type] $user User Data.2643 */2644 function ur_delete_user_files_on_user_delete( $user_id, $reassign, $user ) {26452646 // Return if reassign is set.2647 if ( null !== $reassign ) {2648 return;2649 }26502651 // Delete user uploaded file when user is deleted.2652 if ( class_exists( ‘URFU_Uploaded_Data’ ) ) {2653 $post = get_post( ur_get_form_id_by_userid( $user_id ) );26542655 $form_data_object = json_decode( $post->post_content );26562657 $file_fields = URFU_Uploaded_Data::get_file_field( $form_data_object );26582659 foreach ( $file_fields as $field ) {26602661 $meta_key = isset( $field[‘key’] ) ? $field[‘key’] : '’;26622663 $attachment_ids = explode( ',’, get_user_meta( $user->ID, ‘user_registration_’ . $meta_key, true ) );26642665 foreach ( $attachment_ids as $attachment_id ) {2666 $file_path = get_attached_file( $attachment_id );26672668 if ( file_exists( $file_path ) ) {2669 unlink( $file_path );2670 }2671 }2672 }2673 }26742675 // Delete user uploaded profile image when user is deleted.2676 $profile_pic_attachment_id = get_user_meta( $user_id, 'user_registration_profile_pic_url’, true );26772678 $pic_path = get_attached_file( $profile_pic_attachment_id );26792680 if ( file_exists( $pic_path ) ) {2681 unlink( $pic_path );2682 }2683 }2684}26852686if ( ! function_exists( ‘ur_format_field_values’ ) ) {26872688 /**2689 * Get field type by meta key2690 *2691 * @param int $field_meta_key Field key or meta key.2692 * @param string $field_value Field’s value .2693 */2694 function ur_format_field_values( $field_meta_key, $field_value ) {2695 if ( strpos( $field_meta_key, ‘user_registration_’ ) ) {2696 $field_meta_key = substr( $field_meta_key, 0, strpos( $field_meta_key, ‘user_registration_’ ) );2697 }26982699 $user_id = isset( $_GET[‘user’] ) ? sanitize_text_field( wp_unslash( $_GET[‘user’] ) ) : get_current_user_id();2700 $user_id = isset( $_GET[‘user_id’] ) ? sanitize_text_field( wp_unslash( $_GET[‘user_id’] ) ) : $user_id;2701 $form_id = isset( $_POST[‘form_id’] ) ? sanitize_text_field( wp_unslash( $_POST[‘form_id’] ) ) : ur_get_form_id_by_userid( $user_id ); //phpcs:ignore27022703 $field_name = ur_get_field_data_by_field_name( $form_id, $field_meta_key );2704 $field_key = isset( $field_name[‘field_key’] ) ? $field_name[‘field_key’] : '’;27052706 switch ( $field_key ) {2707 case 'checkbox’:2708 case 'multi_select2’:2709 $field_value = ( is_array( $field_value ) && ! empty( $field_value ) ) ? implode( ', ', $field_value ) : $field_value;2710 break;2711 case 'country’:2712 $countries = UR_Form_Field_Country::get_instance()->get_country();2713 if ( ! isset( $countries[ $field_value ] ) ) {2714 $key = array_search( $field_value, $countries, true );2715 if ( $key ) {2716 $field_value = $key;2717 }2718 }2719 $field_value = isset( $countries[ $field_value ] ) ? $countries[ $field_value ] : '’;2720 break;2721 case 'file’:2722 $attachment_ids = is_array( $field_value ) ? $field_value : explode( ',’, $field_value );2723 $links = array();27242725 foreach ( $attachment_ids as $attachment_id ) {2726 if ( is_numeric( $attachment_id ) ) {2727 $attachment_url = ‘<a href="’ . wp_get_attachment_url( $attachment_id ) . ‘">’ . basename( get_attached_file( $attachment_id ) ) . '</a>’;2728 array_push( $links, $attachment_url );2729 } elseif ( ur_is_valid_url( $attachment_id ) ) {2730 $attachment_url = ‘<a href="’ . $attachment_id . ‘">’ . $attachment_id . '</a>’;2731 array_push( $links, $attachment_url );2732 } else {2733 array_push( $links, $attachment_id );2734 }2735 }27362737 $field_value = implode( ', ', $links );27382739 break;2740 case 'privacy_policy’:2741 if ( ur_string_to_bool( $field_value ) ) {2742 $field_value = 'Checked’;2743 } else {2744 $field_value = 'Not Checked’;2745 }2746 break;2747 case 'wysiwyg’:2748 $field_value = html_entity_decode( $field_value );2749 break;2750 case 'profile_picture’:2751 $field_value = ‘<img class="profile-preview" alt="Profile Picture" width="50px" height="50px" src="’ . ( is_numeric( $field_value ) ? esc_url( wp_get_attachment_url( $field_value ) ) : esc_url( $field_value ) ) . '" />’;2752 $field_value = wp_kses_post( $field_value );2753 break;2754 default:2755 $field_value = $field_value;2756 break;2757 }27582759 return $field_value;2760 }2761}27622763add_action( 'admin_init’, ‘user_registration_install_pages_notice’ );27642765if ( ! function_exists( ‘user_registration_install_pages_notice’ ) ) {2766 /**2767 * Display install pages notice if the user has skipped getting started.2768 *2769 * @since 2.2.32770 */2771 function user_registration_install_pages_notice() {27722773 if ( get_option( 'user_registration_onboarding_skipped’, false ) ) {2774 UR_Admin_Notices::add_notice( ‘install’ );2775 }27762777 if ( isset( $_POST[‘user_registration_myaccount_page_id’] ) ) { //phpcs:ignore2778 $my_account_page = $_POST[‘user_registration_myaccount_page_id’]; //phpcs:ignore2779 } else {2780 $my_account_page = get_option( 'user_registration_myaccount_page_id’, 0 );2781 }27822783 $matched = 0;2784 $myaccount_page = array();27852786 if ( $my_account_page ) {2787 $myaccount_page = get_post( $my_account_page );2788 }27892790 if ( ! empty( $myaccount_page ) ) {2791 $shortcodes = parse_blocks( $myaccount_page->post_content );2792 $matched = ur_find_my_account_in_page( $shortcodes, $myaccount_page, $matched );2793 }27942795 if ( 0 === $matched ) {2796 $my_account_setting_link = admin_url() . 'admin.php?page=user-registration-settings#user_registration_myaccount_page_id’;27972798 $message = sprintf(2799 /* translators: %1$s - My account Link. */2800 __( 'Please choose a <strong title="A page with [user_registration_my_account] shortcode">My Account</strong> page in <a href="%1$s" style="text-decoration:none;">General Settings</a>. <br/><strong>Got Stuck? Read</strong> <a href="https://docs.wpuserregistration.com/docs/how-to-show-account-profile/" style="text-decoration:none;" target="_blank">How to setup My Account page</a>.’, ‘user-registration’ ),2801 $my_account_setting_link2802 );2803 UR_Admin_Notices::add_custom_notice( 'select_my_account’, $message );2804 } else {2805 UR_Admin_Notices::remove_notice( ‘select_my_account’ );2806 }2807 }2808}28092810if ( ! function_exists( ‘ur_find_my_account_in_page’ ) ) {28112812 /**2813 * Find My Account Shortcode.2814 *2815 * @param array $shortcodes Shortcode.2816 * @param mixed $myaccount_page My Account Page.2817 * @param int $matched Default 0.2818 * @return int If matched then 1 else 0.2819 * @since 2.2.72820 */2821 function ur_find_my_account_in_page( $shortcodes, $myaccount_page, $matched ) {28222823 foreach ( $shortcodes as $shortcode ) {2824 if ( ! empty( $shortcode[‘blockName’] ) ) {2825 if ( ‘user-registration/form-selector’ === $shortcode[‘blockName’] && isset( $shortcode[‘attrs’][‘shortcode’] ) ) {2826 $matched = 1;2827 return $matched;2828 } elseif ( ( ‘core/shortcode’ === $shortcode[‘blockName’] || ‘core/paragraph’ === $shortcode[‘blockName’] ) && isset( $shortcode[‘innerHTML’] ) ) {2829 $matched = preg_match( '/\[user_registration_my_account(\s\S+){0,3}\]|\[user_registration_login(\s\S+){0,3}\]/’, $shortcode[‘innerHTML’] );2830 if ( 1 > absint( $matched ) ) {2831 $matched = preg_match( '/\[woocommerce_my_account(\s\S+){0,3}\]/’, $shortcode[‘innerHTML’] );2832 }2833 if ( 0 < absint( $matched ) ) {2834 return $matched;2835 }2836 } elseif ( ‘core/group’ === $shortcode[‘blockName’] ) {2837 if ( isset( $shortcode[‘innerBlocks’] ) && ! empty( $shortcode[‘innerBlocks’] ) ) {2838 foreach ( $shortcode[‘innerBlocks’] as $inner_block ) {2839 if ( ‘user-registration/form-selector’ === $inner_block[‘blockName’] && isset( $inner_block[‘attrs’][‘shortcode’] ) ) {2840 $matched = 1;2841 return $matched;2842 } elseif ( ( ‘core/shortcode’ === $inner_block[‘blockName’] || ‘core/paragraph’ === $inner_block[‘blockName’] ) && isset( $inner_block[‘innerHTML’] ) ) {2843 $matched = preg_match( '/\[user_registration_my_account(\s\S+){0,3}\]|\[user_registration_login(\s\S+){0,3}\]/’, $inner_block[‘innerHTML’] );2844 if ( 1 > absint( $matched ) ) {2845 $matched = preg_match( '/\[woocommerce_my_account(\s\S+){0,3}\]/’, $shortcode[‘innerHTML’] );2846 }2847 if ( 0 < absint( $matched ) ) {2848 return $matched;2849 }2850 } elseif ( ‘core/group’ === $inner_block[‘blockName’] || ‘core/column’ === $inner_block[‘blockName’] || ‘core/columns’ === $inner_block[‘blockName’] ) {28512852 $matched = ur_find_my_account_in_page( $shortcode[‘innerBlocks’], $myaccount_page, $matched );2853 if ( 0 < absint( $matched ) ) {2854 return $matched;2855 }2856 } elseif ( ‘core/block’ === $inner_block[‘blockName’] ) {2857 if ( isset( $inner_block[‘attrs’][‘ref’] ) && ! empty( $inner_block[‘attrs’][‘ref’] ) ) {2858 $resuable_block_page = get_post( $inner_block[‘attrs’][‘ref’] );2859 if ( ! empty( $resuable_block_page ) ) {2860 $resuable_block = parse_blocks( $resuable_block_page->post_content );2861 $matched = ur_find_my_account_in_page( $resuable_block, $resuable_block_page, $matched );2862 if ( 0 < absint( $matched ) ) {2863 return $matched;2864 }2865 }2866 }2867 }2868 }2869 }2870 } elseif ( ‘core/columns’ === $shortcode[‘blockName’] ) {2871 if ( isset( $shortcode[‘innerBlocks’] ) && ! empty( $shortcode[‘innerBlocks’] ) ) {2872 foreach ( $shortcode[‘innerBlocks’] as $inner_block ) {2873 if ( ‘user-registration/form-selector’ === $inner_block[‘blockName’] && isset( $inner_block[‘attrs’][‘shortcode’] ) ) {2874 $matched = 1;2875 return $matched;2876 } elseif ( ( ‘core/shortcode’ === $inner_block[‘blockName’] || ‘core/paragraph’ === $inner_block[‘blockName’] ) && isset( $inner_block[‘innerHTML’] ) ) {2877 $matched = preg_match( '/\[user_registration_my_account(\s\S+){0,3}\]|\[user_registration_login(\s\S+){0,3}\]/’, $inner_block[‘innerHTML’] );2878 if ( 1 > absint( $matched ) ) {2879 $matched = preg_match( '/\[woocommerce_my_account(\s\S+){0,3}\]/’, $shortcode[‘innerHTML’] );2880 }2881 if ( 0 < absint( $matched ) ) {2882 return $matched;2883 }2884 } elseif ( ‘core/group’ === $inner_block[‘blockName’] || ‘core/column’ === $inner_block[‘blockName’] || ‘core/columns’ === $inner_block[‘blockName’] ) {28852886 $matched = ur_find_my_account_in_page( $inner_block[‘innerBlocks’], $myaccount_page, $matched );28872888 if ( 0 < absint( $matched ) ) {2889 return $matched;2890 }2891 } elseif ( ‘core/block’ === $inner_block[‘blockName’] ) {2892 if ( isset( $inner_block[‘attrs’][‘ref’] ) && ! empty( $inner_block[‘attrs’][‘ref’] ) ) {2893 $resuable_block_page = get_post( $inner_block[‘attrs’][‘ref’] );2894 if ( ! empty( $resuable_block_page ) ) {2895 $resuable_block = parse_blocks( $resuable_block_page->post_content );2896 $matched = ur_find_my_account_in_page( $resuable_block, $resuable_block_page, $matched );2897 if ( 0 < absint( $matched ) ) {2898 return $matched;2899 }2900 }2901 }2902 }2903 }2904 }2905 } elseif ( ‘core/block’ === $shortcode[‘blockName’] ) {29062907 if ( isset( $shortcode[‘attrs’][‘ref’] ) && ! empty( $shortcode[‘attrs’][‘ref’] ) ) {2908 $resuable_block_page = get_post( $shortcode[‘attrs’][‘ref’] );2909 if ( ! empty( $resuable_block_page ) ) {2910 $resuable_block = parse_blocks( $resuable_block_page->post_content );2911 $matched = ur_find_my_account_in_page( $resuable_block, $resuable_block_page, $matched );2912 if ( 0 < absint( $matched ) ) {2913 return $matched;2914 }2915 }2916 }2917 }2918 } else {2919 $matched = preg_match( '/\[user_registration_my_account(\s\S+){0,3}\]|\[user_registration_login(\s\S+){0,3}\]/’, $myaccount_page->post_content );2920 if ( 1 > absint( $matched ) ) {2921 $matched = preg_match( '/\[woocommerce_my_account(\s\S+){0,3}\]/’, $myaccount_page->post_content );2922 }2923 if ( 0 < absint( $matched ) ) {2924 return $matched;2925 }2926 }2927 }2928 return $matched;2929 }2930}29312932if ( ! function_exists( ‘ur_get_license_plan’ ) ) {29332934 /**2935 * Get a license plan.2936 *2937 * @return bool|string Plan on success, false on failure.2938 * @since 2.2.42939 */2940 function ur_get_license_plan() {2941 $license_key = get_option( ‘user-registration_license_key’ );29422943 if ( ! function_exists( ‘is_plugin_active’ ) ) {2944 include_once ABSPATH . 'wp-admin/includes/plugin.php’;2945 }29462947 if ( $license_key && is_plugin_active( ‘user-registration-pro/user-registration.php’ ) ) {2948 $license_data = get_transient( ‘ur_pro_license_plan’ );29492950 if ( false === $license_data ) {2951 $license_data = json_decode(2952 UR_Updater_Key_API::check(2953 array(2954 ‘license’ => $license_key,2955 )2956 )2957 );29582959 if ( ! empty( $license_data->item_name ) ) {2960 $license_data->item_plan = strtolower( str_replace( 'LifeTime’, '’, str_replace( 'User Registration’, '’, $license_data->item_name ) ) );2961 set_transient( 'ur_pro_license_plan’, $license_data, WEEK_IN_SECONDS );2962 }2963 }29642965 return isset( $license_data ) ? $license_data : false;2966 }29672968 return false;2969 }2970}29712972if ( ! function_exists( ‘ur_get_json_file_contents’ ) ) {29732974 /**2975 * UR Get json file contents.2976 *2977 * @param mixed $file File path.2978 * @param mixed $to_array Returned data in array.2979 * @since 2.2.42980 */2981 function ur_get_json_file_contents( $file, $to_array = false ) {2982 if ( $to_array ) {2983 return json_decode( ur_file_get_contents( $file ), true );2984 }2985 return json_decode( ur_file_get_contents( $file ) );2986 }2987}29882989if ( ! function_exists( ‘ur_is_valid_url’ ) ) {29902991 /**2992 * UR file get contents.2993 *2994 * @param mixed $url URL.2995 */2996 function ur_is_valid_url( $url ) {2997 // Must start with http:// or https://.2998 if ( 0 !== strpos( $url, ‘http://’ ) && 0 !== strpos( $url, ‘https://’ ) ) {2999 return false;3000 }30013002 // Must pass validation.3003 if ( ! filter_var( $url, FILTER_VALIDATE_URL ) ) {3004 return false;3005 }30063007 return true;3008 }3009}30103011if ( ! function_exists( ‘ur_file_get_contents’ ) ) {30123013 /**3014 * UR file get contents.3015 *3016 * @param mixed $file File path.3017 * @since 2.2.43018 */3019 function ur_file_get_contents( $file ) {30203021 if ( $file ) {3022 global $wp_filesystem;3023 require_once ABSPATH . '/wp-admin/includes/file.php’;3024 WP_Filesystem();3025 $local_file = preg_replace( '/\\\\|\/\//’, '/’, plugin_dir_path( UR_PLUGIN_FILE ) . $file );30263027 if ( $wp_filesystem->exists( $local_file ) ) {3028 $response = $wp_filesystem->get_contents( $local_file );3029 return $response;3030 }3031 }3032 return;3033 }3034}30353036if ( ! function_exists( ‘crypt_the_string’ ) ) {3037 /**3038 * Encrypt/Decrypt the provided string.3039 * Encrypt while setting token and updating to database, decrypt while comparing the stored token.3040 *3041 * @param string $string String to encrypt/decrypt.3042 * @param string $action Encrypt/decrypt action. ‘e’ for encrypt and ‘d’ for decrypt.3043 * @return string Encrypted/Decrypted string.3044 */3045 function crypt_the_string( $string, $action = ‘e’ ) {3046 $secret_key = 'ur_secret_key’;3047 $secret_iv = 'ur_secret_iv’;30483049 $output = false;3050 $encrypt_method = 'AES-256-CBC’;3051 $key = hash( 'sha256’, $secret_key );3052 $iv = substr( hash( 'sha256’, $secret_iv ), 0, 16 );30533054 if ( ‘e’ == $action ) {3055 if ( function_exists( ‘openssl_encrypt’ ) ) {3056 $output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) );3057 } else {3058 $output = base64_encode( $string );3059 }3060 } elseif ( ‘d’ == $action ) {3061 if ( function_exists( ‘openssl_decrypt’ ) ) {3062 $output = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv );3063 } else {3064 $output = base64_decode( $string );3065 }3066 }30673068 return $output;3069 }3070} //phpcs:ignore307130723073if ( ! function_exists( ‘ur_clean_tmp_files’ ) ) {3074 /**3075 * Clean up the tmp folder - remove all old files every day (filterable interval).3076 */3077 function ur_clean_tmp_files() {3078 $files = glob( trailingslashit( ur_get_tmp_dir() ) . ‘*’ );30793080 if ( ! is_array( $files ) || empty( $files ) ) {3081 return;3082 }30833084 $lifespan = (int) apply_filters( 'user_registration_clean_tmp_files_lifespan’, DAY_IN_SECONDS );30853086 foreach ( $files as $file ) {3087 if ( ! is_file( $file ) ) {3088 continue;3089 }30903091 // In some cases filemtime() can return false, in that case - pretend this is a new file and do nothing.3092 $modified = (int) filemtime( $file );3093 if ( empty( $modified ) ) {3094 $modified = time();3095 }30963097 if ( ( time() - $modified ) >= $lifespan ) {3098 @unlink( $file ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged3099 }3100 }3101 }3102}31033104if ( ! function_exists( ‘ur_get_tmp_dir’ ) ) {3105 /**3106 * Get tmp dir for files.3107 *3108 * @return string3109 */3110 function ur_get_tmp_dir() {3111 $tmp_root = UR_UPLOAD_PATH . 'temp-uploads’;31123113 if ( ! file_exists( $tmp_root ) || ! wp_is_writable( $tmp_root ) ) {3114 wp_mkdir_p( $tmp_root );3115 }31163117 $index = trailingslashit( $tmp_root ) . 'index.html’;31183119 if ( ! file_exists( $index ) ) {3120 file_put_contents( $index, ‘’ ); // phpcs:ignore WordPress.WP.AlternativeFunctions3121 }31223123 return $tmp_root;3124 }3125}31263127if ( ! function_exists( ‘ur_get_user_roles’ ) ) {3128 /**3129 * Returns an array of all roles associated with the user.3130 *3131 * @param [int] $user_id User Id.3132 *3133 * @returns array3134 */3135 function ur_get_user_roles( $user_id ) {3136 $roles = array();31373138 if ( $user_id ) {3139 $user_meta = get_userdata( $user_id );3140 $roles = isset( $user_meta->roles ) ? $user_meta->roles : array();3141 }31423143 $user_roles = array_map( 'ucfirst’, $roles );31443145 return $user_roles;3146 }3147}31483149if ( ! function_exists( ‘ur_upload_profile_pic’ ) ) {3150 /**3151 * Upload Profile Picture3152 *3153 * @param [array] $valid_form_data Valid Form Data.3154 * @param [int] $user_id User Id.3155 */3156 function ur_upload_profile_pic( $valid_form_data, $user_id ) {3157 $attachment_id = array();3158 $upload_path = UR_UPLOAD_PATH . 'profile-pictures’; /*Get path of upload dir of User Registration for profile pictures*/31593160 // Checks if the upload directory exists and create one if not.3161 if ( ! file_exists( $upload_path ) ) {3162 wp_mkdir_p( $upload_path );3163 }31643165 $upload_file = $valid_form_data[‘profile_pic_url’]->value;31663167 if ( ! is_numeric( $upload_file ) ) {3168 $upload = maybe_unserialize( crypt_the_string( $upload_file, ‘d’ ) );3169 if ( isset( $upload[‘file_name’] ) && isset( $upload[‘file_path’] ) && isset( $upload[‘file_extension’] ) ) {3170 $upload_path = $upload_path . '/’;3171 $file_name = wp_unique_filename( $upload_path, $upload[‘file_name’] );3172 $file_path = $upload_path . sanitize_file_name( $file_name );3173 // Check the type of file. We’ll use this as the 'post_mime_type’.3174 $filetype = wp_check_filetype( basename( $file_name ), null );3175 $moved = rename( $upload[‘file_path’], $file_path );31763177 if ( $moved ) {3178 $attachment_id = wp_insert_attachment(3179 array(3180 ‘guid’ => $file_path,3181 ‘post_mime_type’ => $filetype[‘type’],3182 ‘post_title’ => preg_replace( '/\.[^.]+$/’, '’, sanitize_file_name( $file_name ) ),3183 ‘post_content’ => '’,3184 ‘post_status’ => 'inherit’,3185 ),3186 $file_path3187 );31883189 if ( ! is_wp_error( $attachment_id ) ) {3190 include_once ABSPATH . 'wp-admin/includes/image.php’;31913192 // Generate and save the attachment metas into the database.3193 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file_path ) );3194 }3195 }3196 }3197 } else {3198 $attachment_id = $upload_file;3199 }3200 $attachment_id = ! empty( $attachment_id ) ? $attachment_id : '’;3201 update_user_meta( $user_id, 'user_registration_profile_pic_url’, $attachment_id );3202 }3203}32043205/**3206 * Check given string is valid url or not.3207 */3208if ( ! function_exists( ‘ur_is_valid_url’ ) ) {3209 /**3210 * Checks if url is valid.3211 *3212 * @param [string] $url URL.3213 * @return bool3214 */3215 function ur_is_valid_url( $url ) {32163217 // Must start with http:// or https://.3218 if ( 0 !== strpos( $url, ‘http://’ ) && 0 !== strpos( $url, ‘https://’ ) ) {3219 return false;3220 }32213222 // Must pass validation.3223 if ( ! filter_var( $url, FILTER_VALIDATE_URL ) ) {3224 return false;3225 }32263227 return true;3228 }3229}32303231if ( ! function_exists( ‘ur_option_checked’ ) ) {3232 /**3233 * Returns whether a setting checkbox or toggle is enabled.3234 *3235 * @param string $option_name Option Name.3236 * @param string $default Default Value.3237 * @return boolean3238 */3239 function ur_option_checked( $option_name = '’, $default = ‘’ ) {32403241 if ( empty( $option_name ) ) {3242 return false;3243 }32443245 $option_value = get_option( $option_name, $default );32463247 // Handling Backward Compatibility.3248 if ( ‘yes’ === $option_value ) {3249 return true;3250 } elseif ( ‘no’ === $option_value ) {3251 return false;3252 }32533254 return ur_string_to_bool( $option_value );3255 }3256}32573258if ( ! function_exists( ‘ur_check_captch_keys’ ) ) {3259 /**3260 * Check the site key and secret key for the selected captcha type, are valid or not.3261 *3262 * @return bool3263 */3264 function ur_check_captch_keys() {3265 $recaptcha_type = get_option( 'user_registration_captcha_setting_recaptcha_version’, ‘v2’ );3266 $invisible_recaptcha = ur_option_checked( 'user_registration_captcha_setting_invisible_recaptcha_v2’, false );32673268 $site_key = '’;3269 $secret_key = '’;32703271 if ( ‘v2’ === $recaptcha_type ) {3272 if ( $invisible_recaptcha ) {3273 $site_key = get_option( ‘user_registration_captcha_setting_recaptcha_invisible_site_key’ );3274 $secret_key = get_option( ‘user_registration_captcha_setting_recaptcha_invisible_site_secret’ );3275 } else {3276 $site_key = get_option( ‘user_registration_captcha_setting_recaptcha_site_key’ );3277 $secret_key = get_option( ‘user_registration_captcha_setting_recaptcha_site_secret’ );3278 }3279 } elseif ( ‘v3’ === $recaptcha_type ) {3280 $site_key = get_option( ‘user_registration_captcha_setting_recaptcha_site_key_v3’ );3281 $secret_key = get_option( ‘user_registration_captcha_setting_recaptcha_site_secret_v3’ );3282 } elseif ( ‘hCaptcha’ === $recaptcha_type ) {3283 $site_key = get_option( ‘user_registration_captcha_setting_recaptcha_site_key_hcaptcha’ );3284 $secret_key = get_option( ‘user_registration_captcha_setting_recaptcha_site_secret_hcaptcha’ );3285 }32863287 if ( ! empty( $site_key ) && ! empty( $secret_key ) ) {3288 return true;3289 }32903291 return false;32923293 }3294}329532963297if ( ! function_exists( ‘ur_premium_settings_tab’ ) ) {32983299 /**3300 * Settings tab list to display as premium tabs.3301 *3302 * @since 3.03303 */3304 function ur_premium_settings_tab() {33053306 $premium_tabs = array(3307 ‘woocommerce’ => array(3308 ‘label’ => esc_html__( 'WooCommerce’, ‘user-registration’ ),3309 ‘plugin’ => 'user-registration-woocommerce’,3310 ‘plan’ => array( 'personal’, 'plus’, ‘professional’ ),3311 ‘name’ => esc_html__( 'User Registration - WooCommerce’, ‘user-registration’ ),3312 ),3313 ‘content_restriction’ => array(3314 ‘label’ => esc_html__( 'Content Restriction’, ‘user-registration’ ),3315 ‘plugin’ => 'user-registration-content-restriction’,3316 ‘plan’ => array( 'personal’, 'plus’, ‘professional’ ),3317 ‘name’ => esc_html__( 'User Registration - Content Restriction’, ‘user-registration’ ),3318 ),3319 ‘file_upload’ => array(3320 ‘label’ => esc_html__( 'File Uploads’, ‘user-registration’ ),3321 ‘plugin’ => 'user-registration-file-upload’,3322 ‘plan’ => array( 'personal’, 'plus’, ‘professional’ ),3323 ‘name’ => esc_html__( 'User Registration - File Upload’, ‘user-registration’ ),3324 ),3325 ‘user-registration-customize-my-account’ => array(3326 ‘label’ => esc_html__( 'Customize My Account’, ‘user-registration’ ),3327 ‘plugin’ => 'user-registration-customize-my-account’,3328 ‘plan’ => array( 'plus’, ‘professional’ ),3329 ‘name’ => esc_html__( 'User Registration customize my account’, ‘user-registration’ ),3330 ),3331 );33323333 return apply_filters( 'user_registration_premium_settings_tab’, $premium_tabs );3334 }3335}33363337add_action( 'user_registration_settings_tabs’, ‘ur_display_premium_settings_tab’ );33383339if ( ! function_exists( ‘ur_display_premium_settings_tab’ ) ) {33403341 /**3342 * Method to display premium settings tabs.3343 *3344 * @since 3.03345 */3346 function ur_display_premium_settings_tab() {3347 $license_data = ur_get_license_plan();3348 $license_plan = ! empty( $license_data->item_plan ) ? $license_data->item_plan : false;3349 $premium_tabs = ur_premium_settings_tab();3350 $tabs_to_display = array();3351 $tab_html = '’;33523353 foreach ( $premium_tabs as $tab => $detail ) {3354 $tooltip_html = '’;3355 $button = '’;3356 if ( ‘woocommerce’ === $tab && ! is_plugin_active( $detail[‘plugin’] . ‘/’ . $detail[‘plugin’] . ‘.php’ ) ) {3357 continue;3358 }33593360 if ( ! empty( $license_plan ) ) {3361 if ( ! in_array( $license_plan, $detail[‘plan’], true ) ) {3362 if ( is_plugin_active( $detail[‘plugin’] . ‘/’ . $detail[‘plugin’] . ‘.php’ ) ) {3363 continue;3364 }33653366 /* translators: %s: License Plan Name. */3367 $tooltip_html = sprintf( __( 'You have been subscribed to %s plan. Please upgrade to higher plans to use this feature.’, ‘user-registration’ ), ucfirst( $license_plan ) );3368 $button = ‘<a target="_blank" href="https://wpuserregistration.com/pricing/?utm_source=pro-fields&utm_medium=popup-button&utm_campaign=ur-upgrade-to-pro">’ . esc_html__( 'Upgrade Plan’, ‘user-registration’ ) . '</a>’;3369 array_push( $tabs_to_display, $tab );3370 } else {3371 $plugin_name = $detail[‘name’];3372 $action = '’;33733374 if ( file_exists( WP_PLUGIN_DIR . ‘/’ . $detail[‘plugin’] ) ) {3375 if ( ! is_plugin_active( $detail[‘plugin’] . ‘/’ . $detail[‘plugin’] . ‘.php’ ) ) {3376 $action = 'Activate’;3377 } else {3378 continue;3379 }3380 } else {3381 $action = 'Install’;3382 }33833384 /* translators: %s: Addon Name. */3385 $tooltip_html = sprintf( __( 'Please %1$s %2$s addon to use this feature.’, ‘user-registration’ ), $action, ucwords( str_replace( '-', ' ', $detail[‘plugin’] ) ) );33863387 /* translators: %s: Action Name. */3388 $button = '<a href="#" class="user-registration-settings-addon-' . strtolower( $action ) . ‘" data-slug="’ . $detail[‘plugin’] . ‘" data-name="’ . $plugin_name . ‘">’ . sprintf( esc_html__( '%s Addon’, ‘user-registration’ ), $action ) . '</a>’;3389 array_push( $tabs_to_display, $tab );3390 }3391 } else {33923393 if ( is_plugin_active( $detail[‘plugin’] . ‘/’ . $detail[‘plugin’] . ‘.php’ ) ) {3394 continue;3395 }33963397 $tooltip_html = __( 'You are currently using the free version of our plugin. Please upgrade to premium version to use this feature.’, ‘user-registration’ );3398 $button = ‘<a target="_blank" href="https://wpuserregistration.com/pricing/?utm_source=pro-fields&utm_medium=popup-button&utm_campaign=ur-upgrade-to-pro">’ . esc_html__( 'Upgrade to Pro’, ‘user-registration’ ) . '</a>’;3399 array_push( $tabs_to_display, $tab );3400 }34013402 if ( in_array( $tab, $tabs_to_display, true ) ) {3403 $tab_html .= '<button class="nav-tab ur-nav__link ur-nav-premium" disabled>’;3404 $tab_html .= ‘<span class="ur-tooltip">’ . esc_html( $tooltip_html ) . wp_kses_post( $button ) . '</span>’;3405 $tab_html .= '<span class="ur-nav__link-icon">’;3406 $tab_html .= ur_file_get_contents( ‘/assets/images/settings-icons/’ . $tab . ‘.svg’ );3407 $tab_html .= '</span>’;3408 $tab_html .= '<span class="ur-nav__link-label">’;3409 $tab_html .= ‘<p>’ . esc_html( $detail[‘label’] ) . '</p>’;3410 $tab_html .= '<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="0.5" y="0.5" width="19" height="19" rx="2.5" fill="#5462FF" stroke="#5462FF"/><path d="M10 5L13 13H7L10 5Z" fill="#EFEFEF"/><path fill-rule="evenodd" clip-rule="evenodd" d="M5 7L5.71429 13H14.2857L15 7L10 11.125L5 7ZM14.2857 13.5714H5.71427V15H14.2857V13.5714Z" fill="white"/></svg>’;3411 $tab_html .= '</span>’;3412 $tab_html .= '</button>’;3413 }3414 }34153416 echo $tab_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped3417 }3418}34193420if ( ! function_exists( ‘ur_is_ajax_login_enabled’ ) ) {3421 /**3422 * Check whether the ajax login is enabled or not.3423 *3424 * @return bool3425 */3426 function ur_is_ajax_login_enabled() {3427 return ur_option_checked( 'ur_login_ajax_submission’, false );3428 }3429}34303431if ( ! function_exists( ‘ur_process_login’ ) ) {3432 /**3433 * Process the login form.3434 *3435 * @param string $nonce_value Nonce.3436 * @throws Exception Login errors.3437 *3438 * @since 3.03439 */3440 function ur_process_login( $nonce_value ) {3441 try {3442 // Custom error messages.3443 $messages = array(3444 ‘empty_username’ => get_option( 'user_registration_message_username_required’, esc_html__( 'Username is required.’, ‘user-registration’ ) ),3445 ‘empty_password’ => get_option( 'user_registration_message_empty_password’, null ),3446 ‘invalid_username’ => get_option( 'user_registration_message_invalid_username’, null ),3447 ‘unknown_email’ => get_option( 'user_registration_message_unknown_email’, esc_html__( 'A user could not be found with this email address.’, ‘user-registration’ ) ),3448 ‘pending_approval’ => get_option( 'user_registration_message_pending_approval’, null ),3449 ‘denied_access’ => get_option( 'user_registration_message_denied_account’, null ),3450 );34513452 $post = $_POST; // phpcs:ignore WordPress.Security.NonceVerification34533454 $hcaptca_response = isset( $post[‘h-captcha-response’] ) ? sanitize_text_field( wp_unslash( $post[‘h-captcha-response’] ) ) : '’;3455 $recaptcha_value = isset( $post[‘g-recaptcha-response’] ) ? sanitize_text_field( wp_unslash( $post[‘g-recaptcha-response’] ) ) : $hcaptca_response;3456 $captcha_response = isset( $post[‘CaptchaResponse’] ) ? $post[‘CaptchaResponse’] : '’; //phpcs:ignore3457 $recaptcha_enabled = ur_option_checked( 'user_registration_login_options_enable_recaptcha’, false );3458 $recaptcha_type = get_option( 'user_registration_captcha_setting_recaptcha_version’, ‘v2’ );3459 $invisible_recaptcha = ur_option_checked( 'user_registration_captcha_setting_invisible_recaptcha_v2’, false );34603461 if ( ur_is_ajax_login_enabled() ) {3462 $hcaptca_response = $captcha_response;3463 $recaptcha_value = $captcha_response;3464 }34653466 $login_data = array(3467 ‘user_password’ => isset( $post[‘password’] ) ? wp_unslash( $post[‘password’] ) : '’, //phpcs:ignore;3468 ‘remember’ => isset( $post[‘rememberme’] ),3469 );34703471 $username = isset( $post[‘username’] ) ? trim( sanitize_user( wp_unslash( $post[‘username’] ) ) ) : '’;34723473 if ( ‘v2’ === $recaptcha_type && ! $invisible_recaptcha ) {3474 $site_key = get_option( ‘user_registration_captcha_setting_recaptcha_site_key’ );3475 $secret_key = get_option( ‘user_registration_captcha_setting_recaptcha_site_secret’ );3476 } elseif ( ‘v2’ === $recaptcha_type && $invisible_recaptcha ) {3477 $site_key = get_option( ‘user_registration_captcha_setting_recaptcha_invisible_site_key’ );3478 $secret_key = get_option( ‘user_registration_captcha_setting_recaptcha_invisible_site_secret’ );3479 } elseif ( ‘v3’ === $recaptcha_type ) {3480 $site_key = get_option( ‘user_registration_captcha_setting_recaptcha_site_key_v3’ );3481 $secret_key = get_option( ‘user_registration_captcha_setting_recaptcha_site_secret_v3’ );3482 } elseif ( ‘hCaptcha’ === $recaptcha_type ) {3483 $site_key = get_option( ‘user_registration_captcha_setting_recaptcha_site_key_hcaptcha’ );3484 $secret_key = get_option( ‘user_registration_captcha_setting_recaptcha_site_secret_hcaptcha’ );3485 }34863487 if ( $recaptcha_enabled && ! empty( $site_key ) && ! empty( $secret_key ) ) {3488 if ( ! empty( $recaptcha_value ) ) {3489 if ( ‘hCaptcha’ === $recaptcha_type ) {3490 $data = wp_remote_get( ‘https://hcaptcha.com/siteverify?secret=’ . $secret_key . ‘&response=’ . $recaptcha_value );3491 $data = json_decode( wp_remote_retrieve_body( $data ) );34923493 if ( empty( $data->success ) || ( isset( $data->score ) && $data->score < apply_filters( 'user_registration_hcaptcha_threshold’, 0.5 ) ) ) {3494 throw new Exception( ‘<strong>’ . esc_html__( 'ERROR:’, ‘user-registration’ ) . ‘</strong>’ . esc_html__( 'Error on hCaptcha. Contact your site administrator.’, ‘user-registration’ ) );3495 }3496 } else {3497 $data = wp_remote_get( ‘https://www.google.com/recaptcha/api/siteverify?secret=’ . $secret_key . ‘&response=’ . $recaptcha_value );3498 $data = json_decode( wp_remote_retrieve_body( $data ) );3499 if ( empty( $data->success ) || ( isset( $data->score ) && $data->score <= get_option( 'user_registration_captcha_setting_recaptcha_threshold_score_v3’, apply_filters( 'user_registration_recaptcha_v3_threshold’, 0.5 ) ) ) ) {3500 throw new Exception( ‘<strong>’ . esc_html__( 'ERROR:’, ‘user-registration’ ) . ‘</strong>’ . esc_html__( 'Error on google reCaptcha. Contact your site administrator.’, ‘user-registration’ ) );3501 }3502 }3503 } else {3504 throw new Exception( ‘<strong>’ . esc_html__( 'ERROR:’, ‘user-registration’ ) . ‘</strong>’ . get_option( 'user_registration_form_submission_error_message_recaptcha’, esc_html__( 'Captcha code error, please try again.’, ‘user-registration’ ) ) );3505 }3506 }35073508 do_action( 'user_registration_login_process_before_username_validation’, $post, $username, $nonce_value, $messages );35093510 $validation_error = new WP_Error();3511 $validation_error = apply_filters( 'user_registration_process_login_errors’, $validation_error, sanitize_user( wp_unslash( $post[‘username’] ) ), sanitize_user( wp_unslash( $post[‘password’] ) ) );35123513 if ( $validation_error->get_error_code() ) {3514 throw new Exception( ‘<strong>’ . esc_html__( 'ERROR:’, ‘user-registration’ ) . ‘</strong>’ . $validation_error->get_error_message() );3515 }35163517 if ( empty( $username ) ) {3518 throw new Exception( ‘<strong>’ . esc_html__( 'ERROR:’, ‘user-registration’ ) . ‘</strong>’ . $messages[‘empty_username’] );3519 }35203521 if ( is_email( $username ) && apply_filters( 'user_registration_get_username_from_email’, true ) ) {3522 $user = get_user_by( 'email’, $username );35233524 if ( isset( $user->user_login ) ) {3525 $login_data[‘user_login’] = $user->user_login;3526 } else {3527 if ( empty( $messages[‘unknown_email’] ) ) {3528 $messages[‘unknown_email’] = esc_html__( 'A user could not be found with this email address.’, ‘user-registration’ );3529 }35303531 throw new Exception( ‘<strong>’ . esc_html__( 'ERROR: ', ‘user-registration’ ) . ‘</strong>’ . $messages[‘unknown_email’] );3532 }3533 } else {3534 $login_data[‘user_login’] = $username;3535 }35363537 // On multisite, ensure user exists on current site, if not add them before allowing login.3538 if ( is_multisite() ) {3539 $user_data = get_user_by( 'login’, $username );35403541 if ( $user_data && ! is_user_member_of_blog( $user_data->ID, get_current_blog_id() ) ) {3542 add_user_to_blog( get_current_blog_id(), $user_data->ID, ‘customer’ );3543 }3544 }35453546 // To check the specific login.3547 if ( ‘email’ === get_option( 'user_registration_general_setting_login_options_with’, array() ) ) {3548 $user_data = get_user_by( 'email’, $username );3549 $login_data[‘user_login’] = isset( $user_data->user_email ) ? $user_data->user_email : is_email( $username );3550 } elseif ( ‘username’ === get_option( 'user_registration_general_setting_login_options_with’, array() ) ) {3551 $user_data = get_user_by( 'login’, $username );3552 $login_data[‘user_login’] = isset( $user_data->user_login ) ? $user_data->user_login : ! is_email( $username );3553 } else {3554 $login_data[‘user_login’] = $username;3555 }35563557 // Perform the login.3558 $user = wp_signon( apply_filters( 'user_registration_login_credentials’, $login_data ), is_ssl() );35593560 if ( is_wp_error( $user ) ) {3561 // Set custom error messages.3562 if ( ! empty( $user->errors[‘empty_username’] ) && ! empty( $messages[‘empty_username’] ) ) {3563 $user->errors[‘empty_username’][0] = sprintf( '<strong>%s:</strong> %s’, __( 'ERROR’, ‘user-registration’ ), $messages[‘empty_username’] );3564 }3565 if ( ! empty( $user->errors[‘empty_password’] ) && ! empty( $messages[‘empty_password’] ) ) {3566 $user->errors[‘empty_password’][0] = sprintf( '<strong>%s:</strong> %s’, __( 'ERROR’, ‘user-registration’ ), $messages[‘empty_password’] );3567 }3568 if ( ! empty( $user->errors[‘invalid_username’] ) && ! empty( $messages[‘invalid_username’] ) ) {3569 $user->errors[‘invalid_username’][0] = $messages[‘invalid_username’];3570 }3571 if ( ! empty( $user->errors[‘pending_approval’] ) && ! empty( $messages[‘pending_approval’] ) ) {3572 $user->errors[‘pending_approval’][0] = sprintf( '<strong>%s:</strong> %s’, __( 'ERROR’, ‘user-registration’ ), $messages[‘pending_approval’] );3573 }3574 if ( ! empty( $user->errors[‘denied_access’] ) && ! empty( $messages[‘denied_access’] ) ) {3575 $user->errors[‘denied_access’][0] = sprintf( '<strong>%s:</strong> %s’, __( 'ERROR’, ‘user-registration’ ), $messages[‘denied_access’] );3576 }35773578 $message = $user->get_error_message();3579 $message = str_replace( ‘<strong>’ . esc_html( $login_data[‘user_login’] ) . '</strong>’, ‘<strong>’ . esc_html( $username ) . '</strong>’, $message );3580 throw new Exception( $message );3581 } else {3582 if ( in_array( 'administrator’, $user->roles, true ) && ur_option_checked( 'user_registration_login_options_prevent_core_login’, true ) ) {3583 $redirect = admin_url();3584 } else {3585 if ( ! empty( $post[‘redirect’] ) ) {3586 $redirect = esc_url_raw( wp_unslash( $post[‘redirect’] ) );3587 } elseif ( wp_get_raw_referer() ) {3588 $redirect = wp_get_raw_referer();3589 } else {3590 $redirect = get_home_url();3591 }3592 }35933594 $redirect = apply_filters( 'user_registration_login_redirect’, $redirect, $user );35953596 if ( ur_is_ajax_login_enabled() ) {3597 wp_send_json_success( array( ‘message’ => $redirect ) );3598 wp_send_json( $user );3599 } else {3600 wp_redirect( wp_validate_redirect( $redirect, $redirect ) );3601 exit;3602 }36033604 if ( ur_is_ajax_login_enabled() ) {3605 wp_send_json( $user );3606 }3607 }3608 } catch ( Exception $e ) {3609 $status_code = $e->getCode();3610 $message = $e->getMessage();36113612 if ( $status_code >= 200 && $status_code < 300 ) {3613 if ( ur_is_ajax_login_enabled() ) {3614 wp_send_json_success(3615 array(3616 ‘message’ => $message,3617 ‘status’ => true,3618 )3619 );3620 }36213622 ur_add_notice( $message, ‘success’ );3623 } else {36243625 if ( ur_is_ajax_login_enabled() ) {3626 wp_send_json_error(3627 array(3628 ‘message’ => $message,3629 )3630 );3631 }36323633 ur_add_notice( apply_filters( 'login_errors’, $message ), ‘error’ );3634 do_action( ‘user_registration_login_failed’ );3635 }3636 }3637 }3638}36393640if ( ! function_exists( ‘ur_generate_onetime_token’ ) ) {3641 /**3642 * Generate a one-time token for the given user ID and action.3643 *3644 * @param int $user_id The ID of the user for whom to generate the token.3645 * @param string $action The action for which to generate the token.3646 * @param int $key_length The length of the random key to be generated. Defaults to 32.3647 * @param int $expiration_time The duration of the token’s validity in minutes. Defaults to 60.3648 * @return string The generated one-time token.3649 */3650 function ur_generate_onetime_token( $user_id = 0, $action = '’, $key_length = 32, $expiration_time = 60 ) {3651 $time = time();3652 $key = wp_generate_password( $key_length, false );36533654 // Concatenate the key, action, and current time to form the token string.3655 $string = $key . $action . $time;36563657 // Generate the token hash.3658 $token = wp_hash( $string );36593660 // Set the token expiration time in seconds.3661 $expiration = apply_filters( $action . '_onetime_token_expiration’, $expiration_time * 60 );36623663 // Set the user meta values for the token and expiration time.3664 update_user_meta( $user_id, $action . ‘_token’ . $user_id, $token );3665 update_user_meta( $user_id, $action . ‘_token_expiration’ . $user_id, $time + $expiration );36663667 return $token;3668 }3669}36703671if ( ! function_exists( ‘ur_get_current_page_url’ ) ) {3672 /**3673 * Get the current page URL.3674 *3675 * @return string The URL of the current page.3676 */3677 function ur_get_current_page_url() {3678 $page_url = '’;36793680 if ( isset( $_SERVER[‘HTTPS’] ) && ‘on’ === $_SERVER[‘HTTPS’] ) {3681 $page_url .= 'https://’;3682 } else {3683 $page_url .= 'http://’;3684 }36853686 if ( isset( $_SERVER[‘HTTP_HOST’] ) ) {3687 $page_url .= sanitize_text_field( wp_unslash( $_SERVER[‘HTTP_HOST’] ) );3688 }36893690 if ( isset( $_SERVER[‘REQUEST_URI’] ) ) {3691 $page_url .= sanitize_text_field( wp_unslash( $_SERVER[‘REQUEST_URI’] ) );3692 }36933694 return $page_url;3695 }3696}36973698if ( ! function_exists( ‘ur_is_passwordless_login_enabled’ ) ) {3699 /**3700 * Check whether the passwordless login is enabled or not.3701 *3702 * @return bool3703 */3704 function ur_is_passwordless_login_enabled() {3705 return ur_option_checked( 'user_registration_pro_passwordless_login’, false );3706 }3707}37083709if ( ! function_exists( ‘ur_get_ip_address’ ) ) {37103711 /**3712 * Get current user IP Address.3713 *3714 * @return string3715 */3716 function ur_get_ip_address() {3717 if ( isset( $_SERVER[‘HTTP_X_REAL_IP’] ) ) { // WPCS: input var ok, CSRF ok.3718 return sanitize_text_field( wp_unslash( $_SERVER[‘HTTP_X_REAL_IP’] ) ); // WPCS: input var ok, CSRF ok.3719 } elseif ( isset( $_SERVER[‘HTTP_X_FORWARDED_FOR’] ) ) { // WPCS: input var ok, CSRF ok.3720 // Proxy servers can send through this header like this: X-Forwarded-For: client1, proxy1, proxy23721 // Make sure we always only send through the first IP in the list which should always be the client IP.3722 return (string) rest_is_ip_address( trim( current( preg_split( '/[,:]/’, sanitize_text_field( wp_unslash( $_SERVER[‘HTTP_X_FORWARDED_FOR’] ) ) ) ) ) ); // WPCS: input var ok, CSRF ok.3723 } elseif ( isset( $_SERVER[‘REMOTE_ADDR’] ) ) { // @codingStandardsIgnoreLine3724 return sanitize_text_field( wp_unslash( $_SERVER[‘REMOTE_ADDR’] ) ); // @codingStandardsIgnoreLine3725 }3726 return '’;3727 }3728}37293730if ( ! function_exists( ‘ur_get_all_pages’ ) ) {3731 /**3732 * Returns map of published pages as id->title format.3733 *3734 * @return array3735 */3736 function ur_get_all_pages() {3737 $pages = get_pages();37383739 $pages_array = array();37403741 foreach ( $pages as $page ) {3742 $pages_array[ $page->ID ] = $page->post_title;3743 }37443745 return $pages_array;3746 }3747}37483749add_action( 'user_registration_after_user_meta_update’, 'ur_parse_and_update_hidden_field’, 10, 3 );37503751if ( ! function_exists( ‘ur_parse_and_update_hidden_field’ ) ) {3752 /**3753 * Parse the hidden field value and update.3754 *3755 * @param array $form_data form data.3756 * @param int $form_id form id.3757 * @param int $user_id user id.3758 */3759 function ur_parse_and_update_hidden_field( $form_data, $form_id, $user_id ) {3760 $values = array(3761 ‘form_id’ => $form_id,3762 ‘process_type’ => 'ur_parse_after_meta_update’,3763 );37643765 foreach ( $form_data as $key => $value ) {3766 if ( ‘user_email’ === $value->field_name ) {3767 $values[‘email’] = ur_format_field_values( $value->field_name, $value->value );3768 }37693770 $values[ $value->field_name ] = ur_format_field_values( $value->field_name, $value->value );3771 }37723773 foreach ( $form_data as $key => $value ) {3774 if ( isset( $value->extra_params[‘field_key’] ) && ‘hidden’ === $value->extra_params[‘field_key’] ) {3775 $content = $value->value;3776 $field_name = ‘user_registration_’ . $value->field_name;3777 if ( ‘’ !== $content ) {3778 $content = apply_filters( 'user_registration_process_smart_tags’, $content, $values );3779 update_user_meta( $user_id, $field_name, $content );3780 }3781 }3782 }3783 }3784}