query->get_query_vars();
if ( false !== $endpoint ) {
if ( ! isset( $ur_endpoints[ $endpoint ] ) ) {
return false;
} else {
$endpoint_var = $ur_endpoints[ $endpoint ];
}
return isset( $wp->query_vars[ $endpoint_var ] );
} else {
foreach ( $ur_endpoints as $key => $value ) {
if ( isset( $wp->query_vars[ $key ] ) ) {
return true;
}
}
return false;
}
}
}
if ( ! function_exists( 'is_ur_account_page' ) ) {
/**
* Returns true when viewing an account page.
*
* @return bool
*/
function is_ur_account_page() {
/**
* Filter hook to modify the result of determining if the current page is an
* account page in user registration.
*
* @param bool $is_account_page The result of determining if the current page is
* a user registration account page. Default is false.
*/
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 );
}
}
if ( ! function_exists( 'is_ur_login_page' ) ) {
/**
* Returns true when viewing an login page.
*
* @return bool
*/
function is_ur_login_page() {
/**
* Filter hook to modify the result of determining if the current page is an
* login page in user registration.
*
* @param bool $is_login_page The result of determining if the current page is
* a user registration login page. Default is false.
*/
return is_page( ur_get_page_id( 'login' ) ) || ur_post_content_has_shortcode( 'user_registration_login' ) || apply_filters( 'user_registration_is_login_page', false );
}
}
if ( ! function_exists( 'is_ur_edit_account_page' ) ) {
/**
* Check for edit account page.
* Returns true when viewing the edit account page.
*
* @return bool
*/
function is_ur_edit_account_page() {
global $wp;
return ( is_ur_account_page() && isset( $wp->query_vars['edit-password'] ) );
}
}
if ( ! function_exists( 'is_ur_lost_password_page' ) ) {
/**
* Returns true when viewing the lost password page.
*
* @return bool
*/
function is_ur_lost_password_page() {
global $wp;
$lost_password_page_id = get_option( 'user_registration_lost_password_page_id', false );
return ( is_ur_account_page() && isset( $wp->query_vars['ur-lost-password'] ) ) || is_page( $lost_password_page_id );
}
}
/**
* Clean variables using sanitize_text_field. Arrays are cleaned recursively.
* Non-scalar values are ignored.
*
* @param string|array $var Variable.
*
* @return string|array
*/
function ur_clean( $var ) {
if ( is_array( $var ) ) {
return array_map( 'ur_clean', $var );
} else {
return is_scalar( $var ) ? sanitize_text_field( $var ) : $var;
}
}
/**
* Sanitize a string destined to be a tooltip.
*
* @since 1.0.0 Tooltips are encoded with htmlspecialchars to prevent XSS. Should not be used in conjunction with esc_attr()
*
* @param string $var Value to sanitize.
*
* @return string
*/
function ur_sanitize_tooltip( $var ) {
return htmlspecialchars(
wp_kses(
html_entity_decode( $var ),
array(
'br' => array(),
'em' => array(),
'strong' => array(),
'small' => array(),
'span' => array(),
'ul' => array(),
'li' => array(),
'ol' => array(),
'p' => array(),
)
)
);
}
/**
* Format dimensions for display.
*
* @since 1.7.0
* @param array $dimensions Array of dimensions.
* @param array $unit Unit, defaults to 'px'.
* @return string
*/
function ur_sanitize_dimension_unit( $dimensions = array(), $unit = 'px' ) {
return ur_array_to_string( ur_suffix_array( $dimensions, $unit ) );
}
/**
* Add a suffix into an array.
*
* @since 1.7.0
* @param array $array Raw array data.
* @param string $suffix Suffix to be added.
* @return array Modified array with suffix added.
*/
function ur_suffix_array( $array = array(), $suffix = '' ) {
return preg_filter( '/$/', $suffix, $array );
}
/**
* Implode an array into a string by $glue and remove empty values.
*
* @since 1.7.0
* @param array $array Array to convert.
* @param string $glue Glue, defaults to ' '.
* @return string
*/
function ur_array_to_string( $array = array(), $glue = ' ' ) {
return is_string( $array ) ? $array : implode( $glue, array_filter( $array ) );
}
/**
* Explode a string into an array by $delimiter and remove empty values.
*
* @since 1.7.0
* @param string $string String to convert.
* @param string $delimiter Delimiter, defaults to ','.
* @return array
*/
function ur_string_to_array( $string, $delimiter = ',' ) {
return is_array( $string ) ? $string : array_filter( explode( $delimiter, $string ) );
}
/**
* Converts a string (e.g. 'yes' or 'no') to a bool.
*
* @param string $string String to convert.
* @return bool
*/
function ur_string_to_bool( $string ) {
return is_bool( $string ) ? $string : ( ( 'yes' === $string || 'on' === $string || 1 === $string || 'true' === $string || '1' === $string || 'today' === $string || 'range' === $string ) ? true : ( null === $string ? '0' : false ) );
}
/**
* Converts a bool to a 'yes' or 'no'.
*
* @param bool $bool String to convert.
* @return string
*/
function ur_bool_to_string( $bool ) {
if ( ! is_bool( $bool ) ) {
$bool = ur_string_to_bool( $bool );
}
return true === $bool ? 'yes' : 'no';
}
/**
* Get other templates (e.g. my account) passing attributes and including the file.
*
* @param string $template_name Template Name.
* @param array $args Extra arguments(default: array()).
* @param string $template_path Path of template provided (default: '').
* @param string $default_path Default path of template provided(default: '').
*/
function ur_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
if ( ! empty( $args ) && is_array( $args ) ) {
extract( $args ); // phpcs:ignore.
}
$located = ur_locate_template( $template_name, $template_path, $default_path );
/** Allow 3rd party plugin filter template file from their plugin.
*
* @param string $located Template locate.
* @param string $template_name Template Name.
* @param array $args Extra arguments(default: array()).
* @param string $template_path Path of template provided (default: '').
* @param string $default_path Default path of template provided(default: '').
*/
$located = apply_filters( 'ur_get_template', $located, $template_name, $args, $template_path, $default_path );
if ( ! file_exists( $located ) ) {
_doing_it_wrong( __FUNCTION__, sprintf( '%s does not exist.', esc_html( $located ) ), '1.0' );
return;
}
ob_start();
/**
* Executes an action before including a template part.
*
* @param string $template_name Name of the template part.
* @param string $template_path Path to the template part.
* @param string $located Path to the located template file.
* @param array $args Additional arguments passed to the template part.
*/
do_action( 'user_registration_before_template_part', $template_name, $template_path, $located, $args );
include $located;
/**
* Executes an action after including a template part.
*
* @param string $template_name Name of the template part.
* @param string $template_path Path to the template part.
* @param string $located Path to the located template file.
* @param array $args Additional arguments passed to the template part.
*/
do_action( 'user_registration_after_template_part', $template_name, $template_path, $located, $args );
$template_content = ob_get_clean();
/**
* Filter hook to process the smart tags in the template content.
*
* @param string $template_content The template content.
*/
$template_content = apply_filters( 'user_registration_process_smart_tags', $template_content, array(), array() );
echo $template_content; // phpcs:ignore.
}
/**
* Locate a template and return the path for inclusion.
*
* This is the load order:
*
* yourtheme / $template_path / $template_name
* yourtheme / $template_name
* $default_path / $template_name
*
* @param string $template_name Template Name.
* @param string $template_path Path of template provided (default: '').
* @param string $default_path Default path of template provided(default: '').
*
* @return string
*/
function ur_locate_template( $template_name, $template_path = '', $default_path = '' ) {
if ( ! $template_path ) {
$template_path = UR()->template_path();
}
if ( ! $default_path ) {
$default_path = UR()->plugin_path() . '/templates/';
}
// Look within passed path within the theme - this is priority.
$template = locate_template(
array(
trailingslashit( $template_path ) . $template_name,
$template_name,
)
);
// Get default template.
if ( ! $template || UR_TEMPLATE_DEBUG_MODE ) {
$template = $default_path . $template_name;
}
/**
* Filters the located template file path before including it.
*
* @param string $template The located template file path.
* @param string $template_name The name of the template file.
* @param string $template_path The path to the template file.
*/
return apply_filters( 'user_registration_locate_template', $template, $template_name, $template_path );
}
/**
* Display a UserRegistration help tip.
*
* @param string $tip Help tip text.
* @param bool $allow_html Allow sanitized HTML if true or escape.
* @param string $classname Classname.
*
* @return string
*/
function ur_help_tip( $tip, $allow_html = false, $classname = 'user-registration-help-tip' ) {
if ( $allow_html ) {
$tip = ur_sanitize_tooltip( $tip );
} else {
$tip = esc_attr( $tip );
}
return sprintf( '', $classname, $tip );
}
/**
* Checks whether the content passed contains a specific short code.
*
* @param string $tag Shortcode tag to check.
*
* @return bool
*/
function ur_post_content_has_shortcode( $tag = '' ) {
global $post;
$new_shortcode = '';
$wp_version = '5.0';
if ( version_compare( $GLOBALS['wp_version'], $wp_version, '>=' ) ) {
if ( is_object( $post ) ) {
$blocks = parse_blocks( $post->post_content );
foreach ( $blocks as $block ) {
if ( ( 'core/shortcode' === $block['blockName'] || 'core/paragraph' === $block['blockName'] ) && isset( $block['innerHTML'] ) ) {
$new_shortcode = ( 'core/shortcode' === $block['blockName'] ) ? $block['innerHTML'] : wp_strip_all_tags( $block['innerHTML'] );
} elseif ( 'user-registration/form-selector' === $block['blockName'] && isset( $block['attrs']['shortcode'] ) ) {
$new_shortcode = '[' . $block['attrs']['shortcode'] . ']';
}
}
}
return ( is_singular() || is_front_page() ) && is_a( $post, 'WP_Post' ) && has_shortcode( $new_shortcode, $tag );
} else {
return ( is_singular() || is_front_page() ) && is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, $tag );
}
}
/**
* Wrapper for ur_doing_it_wrong.
*
* @since 1.0.0
*
* @param string $function Callback function name.
* @param string $message Message to display.
* @param string $version Version of the plugin.
*/
function ur_doing_it_wrong( $function, $message, $version ) {
$message .= ' Backtrace: ' . wp_debug_backtrace_summary();
if ( defined( 'DOING_AJAX' ) ) {
/**
* The 'doing_it_wrong_run' action is triggered when the function is called incorrectly.
*
* @param string $function The function that was called incorrectly.
* @param string $message Error message providing details about the incorrect usage.
* @param string $version The version when the incorrect usage was introduced.
*/
do_action( 'doing_it_wrong_run', $function, $message, $version );
error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." );
} else {
_doing_it_wrong( esc_html( $function ), esc_html( $message ), esc_html( $version ) );
}
}
/**
* Set a cookie - wrapper for setcookie using WP constants.
*
* @param string $name Name of the cookie being set.
* @param string $value Value of the cookie.
* @param integer $expire Expiry of the cookie.
* @param string $secure Whether the cookie should be served only over https.
*/
function ur_setcookie( $name, $value, $expire = 0, $secure = false ) {
if ( ! headers_sent() ) {
setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure );
} elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
headers_sent( $file, $line );
trigger_error( "{$name} cookie cannot be set - headers already sent by {$file} on line {$line}", E_USER_NOTICE ); //phpcs:ignore.
}
}
/**
* Read in UserRegistration headers when reading plugin headers.
*
* @since 1.1.0
*
* @param array $headers header.
*
* @return array $headers
*/
function ur_enable_ur_plugin_headers( $headers ) {
if ( ! class_exists( 'UR_Plugin_Updates', false ) ) {
include_once __DIR__ . '/admin/updater/class-ur-plugin-updates.php';
}
$headers['URRequires'] = UR_Plugin_Updates::VERSION_REQUIRED_HEADER;
$headers['URTested'] = UR_Plugin_Updates::VERSION_TESTED_HEADER;
return $headers;
}
add_filter( 'extra_plugin_headers', 'ur_enable_ur_plugin_headers' );
/**
* Set field type for all registrered field keys
*
* @param string $field_key field's field key.
* @return string $field_type
*/
function ur_get_field_type( $field_key ) {
$fields = ur_get_registered_form_fields();
if ( ur_check_module_activation( 'coupon' ) ) {
$fields[] = 'coupon';
}
$field_type = 'text';
if ( in_array( $field_key, $fields ) ) {
switch ( $field_key ) {
case 'user_email':
case 'user_confirm_email':
case 'email':
$field_type = 'email';
break;
case 'user_confirm_password':
case 'password':
case 'user_pass':
$field_type = 'password';
break;
case 'user_login':
case 'nickname':
case 'first_name':
case 'last_name':
case 'display_name':
case 'text':
$field_type = 'text';
break;
case 'user_url':
$field_type = 'url';
break;
case 'description':
case 'textarea':
$field_type = 'textarea';
break;
case 'select':
case 'country':
$field_type = 'select';
break;
case 'file':
$field_type = 'file';
break;
case 'privacy_policy':
case 'mailchimp':
case 'mailerlite':
case 'checkbox':
$field_type = 'checkbox';
break;
case 'number':
$field_type = 'number';
break;
case 'date':
$field_type = 'date';
break;
case 'radio':
$field_type = 'radio';
break;
case 'coupon':
$field_type = 'coupon';
break;
}
}
/**
* Filters the field keys before rendering or processing.
*
* @param string $field_type The type of the user registration field.
* @param string $field_key The key identifying the specific field.
*/
return apply_filters( 'user_registration_field_keys', $field_type, $field_key );
}
/**
* Get user table fields.
*
* @return array
*/
function ur_get_user_table_fields() {
/**
* Filters the user table fields before rendering or processing.
*
* @param array $user_table_fields An array of user table fields to be displayed
* or processed during user registration.
*/
return apply_filters(
'user_registration_user_table_fields',
array(
'user_email',
'user_pass',
'user_login',
'user_url',
'display_name',
)
);
}
/**
* Get required fields.
*
* @return array
*/
function ur_get_required_fields() {
/**
* Filters the list of required form fields during user registration.
*
* @param array $required_form_fields An array of user fields that are required.
*/
return apply_filters(
'user_registration_required_form_fields',
array(
'user_email',
'user_pass',
)
);
}
/**
* Get one time draggable fields fields.
*
* @return array
*/
function ur_get_one_time_draggable_fields() {
$form_fields = ur_get_user_field_only();
/**
* Filters the list of one-time draggable form fields during user registration.
*
* @param array $form_fields An array of user fields to be used as one-time draggable form fields.
*/
return apply_filters( 'user_registration_one_time_draggable_form_fields', $form_fields );
}
/**
* Get fields excluding in profile tab
*
* @return array
*/
function ur_exclude_profile_details_fields() {
$fields_to_exclude = array(
'user_pass',
'user_confirm_password',
'user_confirm_email',
'invite_code',
'learndash_course',
);
// Check if the my account page contains [user_registration_my_account] shortcode.
if ( ur_post_content_has_shortcode( 'user_registration_my_account' ) || ur_post_content_has_shortcode( 'user_registration_edit_profile' ) ) {
// Push profile_picture field to fields_to_exclude array.
array_push( $fields_to_exclude, 'profile_picture' );
}
/**
* Filters the list of profile fields to be excluded during user registration.
*
* @param array $fields_to_exclude An array of profile fields to be excluded.
*/
return apply_filters(
'user_registration_exclude_profile_fields',
$fields_to_exclude
);
}
/**
* Get readonly fields in profile tab
*
* @return array
*/
function ur_readonly_profile_details_fields() {
/**
* Filters the list of readonly profile fields during user registration.
*
* @param array $readonly_profile_fields An associative array where keys are the
* profile fields to be marked as readonly,
* and values are arrays containing optional
* messages or values associated with each field.
*/
return apply_filters(
'user_registration_readonly_profile_fields',
array(
'user_login' => array(
'message' => __( 'Username can not be changed.', 'user-registration' ),
),
'user_pass' => array(
'value' => 'password',
'message' => __( 'Passowrd can not be changed.', 'user-registration' ),
),
'user_confirm_password' => array(
'value' => 'password',
'message' => __( 'Confirm password can not be changed.', 'user-registration' ),
),
'user_confirm_email' => array(
'message' => __( 'Confirm email can not be changed.', 'user-registration' ),
),
)
);
}
/**
* Get profile detail fields.
*
* @deprecated 1.4.1
* @return void
*/
function ur_get_account_details_fields() {
ur_deprecated_function( 'ur_get_account_details_fields', '1.4.1', 'ur_exclude_profile_details_fields' );
}
/**
* Get all fields appearing in profile tab.
*
* @return array
*/
function ur_get_user_profile_field_only() {
$user_fields = array_diff( ur_get_registered_form_fields(), ur_exclude_profile_details_fields() );
/**
* Filters the list of user profile fields during user registration.
*
* @param array $user_fields An array of user profile fields to be used during user registration.
*/
return apply_filters( 'user_registration_user_profile_field_only', $user_fields );
}
/**
* All fields to update without adding prefix.
*
* @return array
*/
function ur_get_fields_without_prefix() {
$fields = ur_get_user_field_only();
/**
* Filters the list of user registration fields without the field prefix.
*
* @param array $fields An array of user registration fields without the field prefix.
*/
return apply_filters( 'user_registration_fields_without_prefix', $fields );
}
/**
* Get all default fields by WordPress.
*
* @return array
*/
function ur_get_user_field_only() {
/**
* Filters the list of user form fields during user registration.
*
* @param array $user_form_fields An array of user form fields to be used during user registration.
*/
return apply_filters(
'user_registration_user_form_fields',
array(
'user_email',
'user_confirm_email',
'user_pass',
'user_confirm_password',
'user_login',
'nickname',
'first_name',
'last_name',
'user_url',
'display_name',
'description',
)
);
}
/**
* Get all extra form fields
*
* @return array
*/
function ur_get_other_form_fields() {
$registered = ur_get_registered_form_fields();
$user_fields = ur_get_user_field_only();
$result = array_diff( $registered, $user_fields );
/**
* Filters the list of other form fields during user registration.
*
* @param mixed $result The result of processing other form fields during user registration.
*/
return apply_filters( 'user_registration_other_form_fields', $result );
}
/**
* All default fields storing in usermeta table
*
* @return mixed|array
*/
function ur_get_registered_user_meta_fields() {
/**
* Filters the list of user meta fields for a registered user during user registration.
*
* @param array $registered_user_meta_fields An array of user meta fields associated with a registered user.
*/
return apply_filters(
'user_registration_registered_user_meta_fields',
array(
'nickname',
'first_name',
'last_name',
'description',
)
);
}
if ( ! function_exists( 'ur_get_field_name_with_prefix_usermeta' ) ) {
/**
* Returns user registration meta fields with prefix before registration.
*
* @param string $field_name Field name.
*
* @return string
*/
function ur_get_field_name_with_prefix_usermeta( $field_name ) {
$default_fields = array_merge_recursive( ur_get_user_table_fields(), ur_get_registered_user_meta_fields() );
if ( ! in_array( $field_name, $default_fields ) ) {
$field_name = 'user_registration_' . $field_name;
}
return $field_name;
}
}
/**
* All registered form fields
*
* @return mixed|array
*/
function ur_get_registered_form_fields() {
/**
* Filters the list of form fields for a registered user during user registration.
*
* @param array $registered_form_fields An array of form fields associated with a registered user during registration.
*/
return apply_filters(
'user_registration_registered_form_fields',
array(
'user_email',
'user_confirm_email',
'user_pass',
'user_confirm_password',
'user_login',
'nickname',
'first_name',
'last_name',
'user_url',
'display_name',
'description',
'text',
'password',
'email',
'select',
'country',
'textarea',
'number',
'date',
'checkbox',
'privacy_policy',
'radio',
)
);
}
/**
* All registered form fields with default labels
*
* @return mixed|array
*/
function ur_get_registered_form_fields_with_default_labels() {
/**
* Filters the list of form fields for a registered user with default labels during user registration.
*
* @param array $registered_form_fields_with_labels An associative array where keys
* are form field keys, and values are
* the corresponding default labels.
*/
return apply_filters(
'user_registration_registered_form_fields_with_default_labels',
array(
'user_email' => __( 'User Email', 'user-registration' ),
'user_confirm_email' => __( 'User Confirm Email', 'user-registration' ),
'user_pass' => __( 'User Pass', 'user-registration' ),
'user_confirm_password' => __( 'User Confirm Password', 'user-registration' ),
'user_login' => __( 'User Login', 'user-registration' ),
'nickname' => __( 'Nickname', 'user-registration' ),
'first_name' => __( 'First Name', 'user-registration' ),
'last_name' => __( 'Last Name', 'user-registration' ),
'user_url' => __( 'User URL', 'user-registration' ),
'display_name' => __( 'Display Name', 'user-registration' ),
'description' => __( 'Description', 'user-registration' ),
'text' => __( 'Text', 'user-registration' ),
'password' => __( 'Password', 'user-registration' ),
'email' => __( 'Secondary Email', 'user-registration' ),
'select' => __( 'Select', 'user-registration' ),
'country' => __( 'Country', 'user-registration' ),
'textarea' => __( 'Textarea', 'user-registration' ),
'number' => __( 'Number', 'user-registration' ),
'date' => __( 'Date', 'user-registration' ),
'checkbox' => __( 'Checkbox', 'user-registration' ),
'privacy_policy' => __( 'Privacy Policy', 'user-registration' ),
'radio' => __( 'Radio', 'user-registration' ),
'hidden' => __( 'Hidden', 'user-registration' ),
)
);
}
/**
* General settings for each fields
*
* @param string $id id for each field.
* @return mixed|array
*/
function ur_get_general_settings( $id ) {
$general_settings = array(
'label' => array(
'setting_id' => 'label',
'type' => 'text',
'label' => __( 'Label', 'user-registration' ),
'name' => 'ur_general_setting[label]',
'placeholder' => __( 'Label', 'user-registration' ),
'required' => true,
'tip' => __( 'Enter text for the form field label. This is recommended and can be hidden in the Advanced Settings.', 'user-registration' ),
),
'description' => array(
'setting_id' => 'description',
'type' => 'textarea',
'label' => __( 'Description', 'user-registration' ),
'name' => 'ur_general_setting[description]',
'placeholder' => __( 'Description', 'user-registration' ),
'required' => true,
'tip' => __( 'Enter text for the form field description.', 'user-registration' ),
),
'field_name' => array(
'setting_id' => 'field-name',
'type' => 'text',
'label' => __( 'Field Name', 'user-registration' ),
'name' => 'ur_general_setting[field_name]',
'placeholder' => __( 'Field Name', 'user-registration' ),
'required' => true,
'tip' => __( 'Unique key for the field.', 'user-registration' ),
),
'placeholder' => array(
'setting_id' => 'placeholder',
'type' => 'text',
'label' => __( 'Placeholder', 'user-registration' ),
'name' => 'ur_general_setting[placeholder]',
'placeholder' => __( 'Placeholder', 'user-registration' ),
'required' => true,
'tip' => __( 'Enter placeholder for the field.', 'user-registration' ),
),
'required' => array(
'setting_id' => 'required',
'type' => 'toggle',
'label' => __( 'Required', 'user-registration' ),
'name' => 'ur_general_setting[required]',
'placeholder' => '',
'required' => true,
'default' => 'false',
'tip' => __( 'Check this option to mark the field required. A form will not submit unless all required fields are provided.', 'user-registration' ),
),
'hide_label' => array(
'setting_id' => 'hide-label',
'type' => 'toggle',
'label' => __( 'Hide Label', 'user-registration' ),
'name' => 'ur_general_setting[hide_label]',
'placeholder' => '',
'required' => true,
'default' => 'false',
'tip' => __( 'Check this option to hide the label of this field.', 'user-registration' ),
),
);
/**
* Filters the list of form field types to exclude placeholders.
*
* @param array $exclude_placeholder_fields An array of form field types to exclude placeholders.
*/
$exclude_placeholder = apply_filters(
'user_registration_exclude_placeholder',
array(
'checkbox',
'privacy_policy',
'radio',
'file',
'mailchimp',
'hidden',
'signature',
)
);
$strip_id = str_replace( 'user_registration_', '', $id );
if ( in_array( $strip_id, $exclude_placeholder, true ) ) {
unset( $general_settings['placeholder'] );
}
$choices_fields = array( 'radio', 'select', 'checkbox' );
if ( in_array( $strip_id, $choices_fields, true ) ) {
$settings['options'] = array(
'setting_id' => 'options',
'type' => 'checkbox' === $strip_id ? 'checkbox' : 'radio',
'label' => __( 'Options', 'user-registration' ),
'name' => 'ur_general_setting[options]',
'placeholder' => '',
'required' => true,
'options' => array(
__( 'First Choice', 'user-registration' ),
__( 'Second Choice', 'user-registration' ),
__( 'Third Choice', 'user-registration' ),
),
);
$general_settings = ur_insert_after_helper( $general_settings, $settings, 'field_name' );
}
if ( 'privacy_policy' === $strip_id || 'user_confirm_email' === $strip_id || 'user_confirm_password' === $strip_id || in_array( $strip_id, ur_get_required_fields() ) ) {
$general_settings['required'] = array(
'setting_id' => '',
'type' => 'hidden',
'label' => '',
'name' => 'ur_general_setting[required]',
'placeholder' => '',
'default' => true,
'required' => true,
);
}
/**
* Filters the general settings for a specific field type during user registration.
*
* @param array $general_settings An array of general settings/options for a specific
* field type during user registration.
* @param string $id The identifier for the specific field type.
*/
return apply_filters( 'user_registration_field_options_general_settings', $general_settings, $id );
}
/**
* Insert in between the indexes in multidimensional array.
*
* @since 1.5.7
* @param array $items An array of items.
* @param array $new_items New items to insert inbetween.
* @param string $after Index to insert after.
*
* @return array Ordered array of items.
*/
function ur_insert_after_helper( $items, $new_items, $after ) {
// Search for the item position and +1 since is after the selected item key.
$position = array_search( $after, array_keys( $items ), true ) + 1;
// Insert the new item.
$return_items = array_slice( $items, 0, $position, true );
$return_items += $new_items;
$return_items += array_slice( $items, $position, count( $items ) - $position, true );
return $return_items;
}
/**
* Load form field class.
*
* @param string $class_key Class Key.
*/
function ur_load_form_field_class( $class_key ) {
$exploded_class = explode( '_', $class_key );
$class_path = UR_FORM_PATH . 'class-ur-' . join( '-', array_map( 'strtolower', $exploded_class ) ) . '.php';
$class_name = 'UR_Form_Field_' . join( '_', array_map( 'ucwords', $exploded_class ) );
/**
* Filter the path of the form field class file and class name before loading.
*
* Dynamic portion of hook name, $class_key.
*
* @param string $class_path The path to the form field class file.
* @param string $class_key The key identifying the form field class.
*/
$class_path = apply_filters( 'user_registration_form_field_' . $class_key . '_path', $class_path );
/* Backward Compat since 1.4.0 */
if ( null != $class_path && file_exists( $class_path ) ) {
$class_name = 'UR_' . join( '_', array_map( 'ucwords', $exploded_class ) );
if ( ! class_exists( $class_name ) ) {
include_once $class_path;
}
}
/* Backward compat end*/
return $class_name;
}
/**
* List of all roles
*
* @return array $all_roles
*/
function ur_get_default_admin_roles() {
global $wp_roles;
if ( ! class_exists( 'WP_Roles' ) ) {
return;
}
if ( ! isset( $wp_roles ) ) {
$wp_roles = new WP_Roles(); // @codingStandardsIgnoreLine
}
$roles = isset( $wp_roles->roles ) ? $wp_roles->roles : array();
$all_roles = array();
foreach ( $roles as $role_key => $role ) {
$all_roles[ $role_key ] = $role['name'];
}
/**
* Filters the default user roles available.
*
* @param array $all_roles An array of all available user roles.
*/
return apply_filters( 'user_registration_user_default_roles', $all_roles );
}
/**
* Random number generated by time()
*
* @return int
*/
function ur_get_random_number() {
return time();
}
/**
* General Form settings
*
* @param int $form_id Form ID.
*
* @since 1.0.1
*
* @return array Form settings.
*/
function ur_admin_form_settings_fields( $form_id ) {
$all_roles = ur_get_default_admin_roles();
$ur_captchas = ur_get_captcha_integrations();
$ur_enabled_captchas = array(
'' => __( 'Select Enabled Captcha', 'user-registration' ),
);
foreach ( $ur_captchas as $key => $value ) {
if ( get_option( 'user_registration_captcha_setting_recaptcha_enable_' . $key, false ) ) {
$ur_enabled_captchas[ $key ] = $value;
}
}
$arguments = array(
'form_id' => $form_id,
'setting_data' => array(
array(
'type' => 'toggle',
'label' => __( 'Enable form title and description', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_enable_form_title_description',
'class' => array( 'ur-enhanced-select' ),
'input_class' => array(),
'custom_attributes' => array(),
'default' => ur_string_to_bool( ur_get_single_post_meta( $form_id, 'user_registration_enable_form_title_description', false ) ),
'tip' => __( 'Enable to show form title and description on form', 'user-registration' ),
),
array(
'type' => 'text',
'label' => __( 'Form Title', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_title',
'class' => array( 'ur-enhanced-select' ),
'input_class' => array(),
'custom_attributes' => array(),
'default' => ur_get_single_post_meta( $form_id, 'user_registration_form_title', __('Register' , 'user-registration') ),
'tip' => __( 'Enter the title of the form.', 'user-registration' ),
),
array(
'type' => 'textarea',
'label' => __( 'Form Description', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_description',
'class' => array( 'ur-enhanced-select' ),
'input_class' => array(),
'custom_attributes' => array(),
'default' => ur_get_single_post_meta( $form_id, 'user_registration_form_description', __('Fill the form below to create an account.' , 'user-registration') ),
'tip' => __( 'Enter the description of the form.', 'user-registration' ),
),
array(
'label' => __( 'User Approval And Login Option', 'user-registration' ),
'description' => __( 'This option lets you choose login option after user registration.', 'user-registration' ),
'id' => 'user_registration_form_setting_login_options',
'default' => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_login_options', get_option( 'user_registration_general_setting_login_options' ) ),
'type' => 'select',
'class' => array( 'ur-enhanced-select' ),
'custom_attributes' => array(),
'input_class' => array(),
'required' => false,
'options' => ur_login_option(),
'tip' => __( 'Login method that should be used by the users registered through this form.', 'user-registration' ),
),
array(
'label' => __( 'Select Phone Fields for SMS Verification', 'user-registration' ),
'description' => '',
'id' => 'user_registration_form_setting_default_phone_field',
'default' => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_default_phone_field', '' ),
'type' => 'select',
'class' => array( 'ur-enhanced-select' ),
'custom_attributes' => array(),
'input_class' => array(),
'required' => false,
'options' => user_registration_get_form_fields_for_dropdown( $form_id ),
'tip' => __( 'This option is to map phone field for sms verification.', 'user-registration' ),
),
array(
'label' => __( 'SMS Verification message', 'user-registration' ),
'description' => '',
'id' => 'user_registration_form_setting_sms_verification_msg',
'default' => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_sms_verification_msg', ur_get_sms_verification_default_message_content() ),
'type' => 'textarea',
'class' => array(),
'custom_attributes' => array(),
'input_class' => array(),
'required' => false,
'tip' => __( 'This is sms verification message content.', 'user-registration' ),
),
array(
'type' => 'select',
'label' => __( 'Default User Role', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_setting_default_user_role',
'class' => array( 'ur-enhanced-select' ),
'input_class' => array(),
'options' => $all_roles,
'custom_attributes' => array(),
'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' ) ),
'tip' => __( 'Default role for the users registered through this form.', 'user-registration' ),
),
array(
'type' => 'toggle',
'label' => __( 'Enable Strong Password', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_setting_enable_strong_password',
'class' => array( 'ur-enhanced-select' ),
'input_class' => array(),
'custom_attributes' => array(),
'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 ) ) ),
'tip' => __( 'Make strong password compulsary.', 'user-registration' ),
),
array(
'type' => 'radio-group',
'label' => __( 'Minimum Password Strength', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_setting_minimum_password_strength',
'class' => array( 'ur-enhanced-select' ),
'input_class' => array(),
'options' => array(
'0' => __( 'Very Weak', 'user-registration' ),
'1' => __( 'Weak', 'user-registration' ),
'2' => __( 'Medium', 'user-registration' ),
'3' => __( 'Strong', 'user-registration' ),
'4' => __( 'Custom', 'user-registration' ),
),
'custom_attributes' => array(),
'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' ) ),
'tip' => __( 'Set minimum required password strength.', 'user-registration' ),
),
array(
'type' => 'number',
'label' => __( 'Minimum Uppercase', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_setting_form_minimum_uppercase',
'class' => array( 'ur-enhanced-select custom-password-params' ),
'input_class' => array(),
'custom_attributes' => array(),
'min' => '0',
'default' => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_form_minimum_uppercase', '0' ),
'tip' => __( 'Enter the minimum amount of uppercase you want to allow for password strength.', 'user-registration' ),
),
array(
'type' => 'number',
'label' => __( 'Minimum digits', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_setting_form_minimum_digits',
'class' => array( 'ur-enhanced-select custom-password-params' ),
'input_class' => array(),
'custom_attributes' => array(),
'min' => '0',
'default' => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_form_minimum_digits', '0' ),
'tip' => __( 'Set the minimum number of digits/numbers required for password strength.', 'user-registration' ),
),
array(
'type' => 'number',
'label' => __( 'Minimum Special Characters', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_setting_form_minimum_special_chars',
'class' => array( 'ur-enhanced-select custom-password-params' ),
'input_class' => array(),
'custom_attributes' => array(),
'min' => '0',
'default' => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_form_minimum_special_chars', '0' ),
'tip' => __( 'Set the minimum number of special characters required for password strength.', 'user-registration' ),
),
array(
'type' => 'number',
'label' => __( 'Minimum Password Length', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_setting_form_minimum_pass_length',
'class' => array( 'ur-enhanced-select custom-password-params' ),
'input_class' => array(),
'custom_attributes' => array(),
'min' => '6',
'default' => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_form_minimum_pass_length', '6' ),
'tip' => __( 'Set the minimum password length required for password strength.', 'user-registration' ),
),
array(
'type' => 'toggle',
'label' => __( 'Limit Repetitive letters', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_setting_no_repeat_chars',
'class' => array( 'ur-enhanced-select custom-password-params' ),
'input_class' => array(),
'custom_attributes' => array(),
'default' => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_no_repeat_chars', ur_string_to_bool( get_option( 'user_registration_form_setting_no_repeat_chars', 0 ) ) ),
'tip' => __( 'Check repetitive letters.', 'user-registration' ),
),
array(
'type' => 'number',
'label' => __( 'Max Repeat Length', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_setting_form_max_char_repeat_length',
'class' => array( 'ur-enhanced-select custom-password-params' ),
'input_class' => array(),
'custom_attributes' => array(),
'min' => '1',
'default' => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_form_max_char_repeat_length', '' ),
'tip' => __( 'Set the Maximum repeat amount for letters in a password.', 'user-registration' ),
),
array(
'type' => 'text',
'label' => __( 'Submit Button Class', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_setting_form_submit_class',
'class' => array( 'ur-enhanced-select' ),
'input_class' => array(),
'custom_attributes' => array(),
'default' => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_form_submit_class', '' ),
'tip' => __( 'Enter CSS class names for the Submit Button. Multiple class names should be separated with spaces.', 'user-registration' ),
),
array(
'type' => 'text',
'label' => __( 'Submit Button Text', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_setting_form_submit_label',
'class' => array( 'ur-enhanced-select' ),
'input_class' => array(),
'custom_attributes' => array(),
'default' => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_form_submit_label', 'Submit' ),
'tip' => __( 'Enter desired text for the Submit Button.', 'user-registration' ),
),
array(
'type' => 'select',
'label' => __( 'Success message display', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_setting_success_message_position',
'class' => array( 'ur-enhanced-select' ),
'input_class' => array(),
'options' => array(
'0' => esc_html__( 'Top', 'user-registration' ),
'1' => esc_html__( 'Bottom', 'user-registration' ),
'2' => esc_html__( 'Hide Form After Successful Submission', 'user-registration' ),
),
'custom_attributes' => array(),
'default' => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_success_message_position', '1' ),
'tip' => __( 'Display success message either at the top or bottom after successful registration.', 'user-registration' ),
),
array(
'type' => 'toggle',
/* translators: 1: Link tag open 2:: Link content 3:: Link tag close */
'label' => sprintf( __( 'Enable %1$s %2$s Captcha %3$s Support', 'user-registration' ), '', '' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_setting_enable_recaptcha_support',
'class' => array( 'ur-enhanced-select' ),
'input_class' => array(),
'custom_attributes' => array(),
'default' => ur_string_to_bool( ur_get_single_post_meta( $form_id, 'user_registration_form_setting_enable_recaptcha_support', false ) ),
'tip' => __( 'Enable Captcha for strong security from spams and bots.', 'user-registration' ),
),
array(
'type' => 'select',
'label' => __( 'Select Configured Captcha', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_setting_configured_captcha_type',
'class' => array( 'ur-enhanced-select' ),
'input_class' => array(),
'options' => $ur_enabled_captchas,
'custom_attributes' => array(),
'default' => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_configured_captcha_type', '1' ),
'tip' => __( 'Select the type of Captcha you want in this form.', 'user-registration' ),
),
array(
'type' => 'select',
'label' => __( 'Form Template', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_template',
'class' => array( 'ur-enhanced-select' ),
'input_class' => array(),
'options' => array(
'Default' => __( 'Default', 'user-registration' ),
'Bordered' => __( 'Bordered', 'user-registration' ),
'Flat' => __( 'Flat', 'user-registration' ),
'Rounded' => __( 'Rounded', 'user-registration' ),
'Rounded Edge' => __( 'Rounded Edge', 'user-registration' ),
),
'custom_attributes' => array(),
'default' => ur_get_single_post_meta( $form_id, 'user_registration_form_template', ucwords( str_replace( '_', ' ', get_option( 'user_registration_form_template', 'default' ) ) ) ),
'tip' => __( 'Choose form template to use.', 'user-registration' ),
),
array(
'type' => 'text',
'label' => __( 'Form Class', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_custom_class',
'class' => array( 'ur-enhanced-select' ),
'input_class' => array(),
'custom_attributes' => array(),
'default' => ur_get_single_post_meta( $form_id, 'user_registration_form_custom_class' ),
'tip' => __( 'Enter CSS class names for the Form Wrapper. Multiple class names should be separated with spaces.', 'user-registration' ),
),
array(
'type' => 'select',
'label' => __( 'Redirect After Registration', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_setting_redirect_after_registration',
'class' => array( 'ur-enhanced-select' ),
'input_class' => array(),
/**
* Filters the redirection options after user registration.
*
* @param array $redirection_options An associative array where keys represent
* the option values, and values represent the labels
* for the redirection options.
*/
'options' => apply_filters(
'user_registration_redirect_after_registration_options',
array(
'no-redirection' => __( 'No Redirection', 'user-registration' ),
'internal-page' => __( 'Internal Page', 'user-registration' ),
'external-url' => __( 'External URL', 'user-registration' ),
'previous-page' => __( 'Previous Page', 'user-registration' ),
)
),
'default' => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_redirect_after_registration', 'no-redirection' ),
'tip' => __( 'Choose where to redirect the user after successful registration.', 'user-registration' ),
'custom_attributes' => array(),
),
array(
'type' => 'select',
'label' => __( 'Custom Page', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_setting_redirect_page',
'class' => array( 'ur-enhanced-select' ),
'input_class' => array(),
'options' => ur_get_all_pages(),
'default' => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_redirect_page', '' ),
'tip' => __( 'Choose the custom page to redirect after registration', 'user-registration' ),
'custom_attributes' => array(),
),
array(
'type' => 'text',
'label' => __( 'Redirect URL', 'user-registration' ),
'id' => 'user_registration_form_setting_redirect_options',
'class' => array( 'ur-enhanced-select' ),
'input_class' => array(),
'custom_attributes' => array(),
'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.
'tip' => __( 'This option lets you enter redirect path after successful user registration.', 'user-registration' ),
),
array(
'type' => 'number',
'label' => __( 'Waiting Period Before Redirection ( In seconds )', 'user-registration' ),
'description' => '',
'required' => false,
'id' => 'user_registration_form_setting_redirect_after',
'class' => array(),
'input_class' => array(),
'custom_attributes' => array(),
'min' => '0',
'default' => ur_get_single_post_meta( $form_id, 'user_registration_form_setting_redirect_after', '2' ),
'tip' => __( 'Time to wait after registration before redirecting user to another page.', 'user-registration' ),
),
array(
'type' => 'toggle',
'label' => __( 'Activate Spam Protection By Akismet', 'user-registration' ),
'required' => false,
'id' => 'user_registration_enable_akismet',
'class' => array( 'ur-enhanced-select' ),
'custom_attributes' => array(),
'default' => ur_get_single_post_meta( $form_id, 'user_registration_enable_akismet', false ),
'tip' => __( 'Enable anti-spam for this form with akismet.', 'user-registration' ),
),
array(
'type' => 'label',
'id' => 'user_registration_akismet_warning',
'description' => ur_check_akismet_installation(),
),
),
);
/**
* Filters the form settings before processing or rendering.
*
* @param array $arguments An array of form settings.
*/
$arguments = apply_filters( 'user_registration_get_form_settings', $arguments );
$arguments['setting_data'] = apply_filters( 'user_registration_settings_text_format', $arguments['setting_data'] );
return $arguments['setting_data'];
}
/**
* User Login Option
*
* @return array
*/
function ur_login_option() {
/**
* Filters the login options available during user registration.
*
* @param array $login_options An associative array where keys represent the
* option values, and values represent the labels
* for the login options.
*/
return apply_filters(
'user_registration_login_options',
array(
'default' => __( 'Auto approval and manual login', 'user-registration' ),
'auto_login' => __( 'Auto approval and auto login ', 'user-registration' ),
'admin_approval' => __( 'Admin approval', 'user-registration' ),
'email_confirmation' => __( 'Auto approval after email confirmation', 'user-registration' ),
)
);
}
/**
* User Login Option
*
* @return array
*/
function ur_login_option_with() {
/**
* Filters the login options with specific identification types during login.
*
* @param array $login_options_with An associative array where keys represent the
* identification types, and values represent the labels
* for the corresponding login options.
*/
return apply_filters(
'user_registration_login_options_with',
array(
'default' => __( 'Username or Email', 'user-registration' ),
'username' => __( 'Username', 'user-registration' ),
'email' => __( 'Email', 'user-registration' ),
)
);
}
/**
* Get Post meta value by meta key.
*
* @param int $post_id Post ID.
* @param string $meta_key Meta Key.
* @param mixed $default Default Value.
*
* @since 1.0.1
*
* @return mixed
*/
function ur_get_single_post_meta( $post_id, $meta_key, $default = null ) {
$post_meta = get_post_meta( $post_id, $meta_key );
if ( isset( $post_meta[0] ) ) {
if (
'user_registration_form_setting_enable_recaptcha_support' === $meta_key || 'user_registration_form_setting_enable_strong_password' === $meta_key
|| '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
) {
$post_meta[0] = ur_string_to_bool( $post_meta[0] );
}
return $post_meta[0];
}
return $default;
}
/**
* Get general form settings by meta key (settings id).
*
* @param int $form_id Form ID.
* @param string $meta_key Meta Key.
* @param mixed $default Default Value.
*
* @since 1.0.1
*
* @return mixed
*/
function ur_get_form_setting_by_key( $form_id, $meta_key, $default = '' ) {
$fields = ur_admin_form_settings_fields( $form_id );
$value = '';
foreach ( $fields as $field ) {
if ( isset( $field['id'] ) && $meta_key == $field['id'] ) {
$value = isset( $field['default'] ) ? sanitize_text_field( $field['default'] ) : $default;
break;
}
}
return $value;
}
/**
* Get user status in case of admin approval login option
*
* @param int $user_id User ID.
* @return int
*/
function ur_get_user_approval_status( $user_id ) {
$user_status = 1;
$login_option = ur_get_user_login_option( $user_id );
if ( 'admin_approval' === $login_option ) {
$user_status = get_user_meta( $user_id, 'ur_user_status', true );
}
return $user_status;
}
/**
* Get form data by field key.
*
* @param array $form_data Form Data.
* @param string $key Field Key.
*
* @return array
*/
function ur_get_form_data_by_key( $form_data, $key = null ) {
$form_data_array = array();
foreach ( $form_data as $data ) {
foreach ( $data as $single_data ) {
foreach ( $single_data as $field_data ) {
$field_key = isset( $field_data->field_key ) && null !== $field_data->field_key ? $field_data->field_key : '';
if ( ! empty( $field_key ) ) {
$field_name = isset( $field_data->general_setting->field_name ) && null !== $field_data->general_setting->field_name ? $field_data->general_setting->field_name : '';
if ( null === $key ) {
if ( ! empty( $field_name ) ) {
$form_data_array[ $field_name ] = $field_data;
} else {
$form_data_array[] = $field_data;
}
} elseif ( $field_key === $key ) {
if ( ! empty( $field_name ) ) {
$form_data_array[ $field_name ] = $field_data;
} else {
$form_data_array[] = $field_data;
}
}
}
}
}
}
return $form_data_array;
}
/**
* Get a log file path.
*
* @since 1.0.5
*
* @param string $handle name.
*
* @return string the log file path.
*/
function ur_get_log_file_path( $handle ) {
return UR_Log_Handler_File::get_log_file_path( $handle );
}
/**
* Registers the default log handler.
*
* @since 1.0.5
*
* @param array $handlers Log handlers.
*
* @return array
*/
function ur_register_default_log_handler( $handlers ) {
if ( defined( 'UR_LOG_HANDLER' ) && class_exists( UR_LOG_HANDLER ) ) {
$handler_class = UR_LOG_HANDLER;
$default_handler = new $handler_class();
} else {
$default_handler = new UR_Log_Handler_File();
}
array_push( $handlers, $default_handler );
return $handlers;
}
add_filter( 'user_registration_register_log_handlers', 'ur_register_default_log_handler' );
/**
* Get a shared logger instance.
*
* Use the user_registration_logging_class filter to change the logging class. You may provide one of the following:
* - a class name which will be instantiated as `new $class` with no arguments
* - an instance which will be used directly as the logger
* In either case, the class or instance *must* implement UR_Logger_Interface.
*
* @see UR_Logger_Interface
* @since 1.1.0
* @return UR_Logger
*/
function ur_get_logger() {
static $logger = null;
if ( null === $logger ) {
/**
* Applies the 'user_registration_logging_class' filter to customize the logger class.
*
* @since 1.1.0
*
* @param string|object $class The class name or an instance of the logger.
*/
$class = apply_filters( 'user_registration_logging_class', 'UR_Logger' );
$implements = class_implements( $class );
if ( is_array( $implements ) && in_array( 'UR_Logger_Interface', $implements ) ) {
if ( is_object( $class ) ) {
$logger = $class;
} else {
$logger = new $class();
}
} else {
ur_doing_it_wrong(
__FUNCTION__,
sprintf(
/* translators: %s: Class */
__( 'The class %s provided by user_registration_logging_class filter must implement UR_Logger_Interface.', 'user-registration' ),
esc_html( is_object( $class ) ? get_class( $class ) : $class )
),
'1.0.5'
);
$logger = new UR_Logger();
}
}
return $logger;
}
/**
* Handles addon plugin updater.
*
* @param string $file Plugin File.
* @param int $item_id Item ID.
* @param string $addon_version Addon Version.
* @param bool $beta Is beta version.
*
* @since 1.1.0
*/
function ur_addon_updater( $file, $item_id, $addon_version, $beta = false ) {
$api_endpoint = 'https://wpeverest.com/edd-sl-api/';
$license_key = trim( get_option( 'user-registration_license_key' ) );
if ( class_exists( 'UR_AddOn_Updater' ) ) {
new UR_AddOn_Updater(
esc_url_raw( $api_endpoint ),
$file,
array(
'version' => $addon_version,
'license' => $license_key,
'item_id' => $item_id,
'author' => 'WPEverest',
'url' => home_url(),
'beta' => $beta,
)
);
}
}
/**
* Check if username already exists in case of optional username
* And while stripping through email address and incremet last number by 1.
*
* @param string $username Username.
* @return string
*/
function check_username( $username ) {
if ( username_exists( $username ) ) {
preg_match_all( '/\d+$/m', $username, $matches );
if ( isset( $matches[0][0] ) ) {
$last_char = $matches[0][0];
$strip_last_char = substr( $username, 0, - ( strlen( (string) $last_char ) ) );
++$last_char;
$username = $strip_last_char . $last_char;
$username = check_username( $username );
return $username;
} else {
$username = $username . '_1';
$username = check_username( $username );
return $username;
}
}
return $username;
}
/**
* Get all user registration forms title with respective id.
*
* @param int $post_count Post Count.
* @return array
*/
function ur_get_all_user_registration_form( $post_count = -1 ) {
$args = array(
'status' => 'publish',
'numberposts' => $post_count,
'order' => 'ASC',
);
$posts_array = UR()->form->get_form( '', $args );
$all_forms = array();
foreach ( $posts_array as $post ) {
$all_forms[ $post->ID ] = $post->post_title;
}
return $all_forms;
}
/**
* Get the node to display google reCaptcha
*
* @param string $context Recaptcha context.
* @param string $recaptcha_enabled Is Recaptcha enabled.
* @return string
*/
function ur_get_recaptcha_node( $context, $recaptcha_enabled = false, $form_id = 0 ) {
$recaptcha_type = get_option( 'user_registration_captcha_setting_recaptcha_version', 'v2' );
$invisible_recaptcha = ur_option_checked( 'user_registration_captcha_setting_invisible_recaptcha_v2', false );
$theme_mod = '';
$enqueue_script = '';
$recaptcha_site_key = '';
$recaptcha_site_secret = '';
$empty_credentials = false;
$global_captcha_enabled = false;
if ( 'login' === $context ) {
$recaptcha_type = get_option( 'user_registration_login_options_configured_captcha_type', $recaptcha_type );
} elseif ( 'register' === $context && $form_id ) {
$recaptcha_type = ur_get_single_post_meta( $form_id, 'user_registration_form_setting_configured_captcha_type', $recaptcha_type );
} elseif ( 'test_captcha' === $context && false !== $recaptcha_enabled ) {
$recaptcha_type = $recaptcha_enabled;
} elseif ( 'lost_password' === $context ) {
//Same recaptcha type as login.
$recaptcha_type = get_option( 'user_registration_login_options_configured_captcha_type', $recaptcha_type );
$recaptcha_type = apply_filters( 'user_registration_lost_password_captcha_type', $recaptcha_type );
}
if ( 'v2' === $recaptcha_type && ! $invisible_recaptcha ) {
$recaptcha_site_key = get_option( 'user_registration_captcha_setting_recaptcha_site_key' );
$recaptcha_site_secret = get_option( 'user_registration_captcha_setting_recaptcha_site_secret' );
$global_captcha_enabled = get_option( 'user_registration_captcha_setting_recaptcha_enable_v2', false );
$enqueue_script = 'ur-google-recaptcha';
} elseif ( 'v2' === $recaptcha_type && $invisible_recaptcha ) {
$recaptcha_site_key = get_option( 'user_registration_captcha_setting_recaptcha_invisible_site_key' );
$recaptcha_site_secret = get_option( 'user_registration_captcha_setting_recaptcha_invisible_site_secret' );
$global_captcha_enabled = get_option( 'user_registration_captcha_setting_recaptcha_enable_v2', false );
$enqueue_script = 'ur-google-recaptcha';
} elseif ( 'v3' === $recaptcha_type ) {
$recaptcha_site_key = get_option( 'user_registration_captcha_setting_recaptcha_site_key_v3' );
$recaptcha_site_secret = get_option( 'user_registration_captcha_setting_recaptcha_site_secret_v3' );
$global_captcha_enabled = get_option( 'user_registration_captcha_setting_recaptcha_enable_v3', false );
$enqueue_script = 'ur-google-recaptcha-v3';
} elseif ( 'hCaptcha' === $recaptcha_type ) {
$recaptcha_site_key = get_option( 'user_registration_captcha_setting_recaptcha_site_key_hcaptcha' );
$recaptcha_site_secret = get_option( 'user_registration_captcha_setting_recaptcha_site_secret_hcaptcha' );
$global_captcha_enabled = get_option( 'user_registration_captcha_setting_recaptcha_enable_hcaptcha', false );
$enqueue_script = 'ur-recaptcha-hcaptcha';
} elseif ( 'cloudflare' === $recaptcha_type ) {
$recaptcha_site_key = get_option( 'user_registration_captcha_setting_recaptcha_site_key_cloudflare' );
$recaptcha_site_secret = get_option( 'user_registration_captcha_setting_recaptcha_site_secret_cloudflare' );
$theme_mod = get_option( 'user_registration_captcha_setting_recaptcha_cloudflare_theme' );
$global_captcha_enabled = get_option( 'user_registration_captcha_setting_recaptcha_enable_cloudflare', false );
$enqueue_script = 'ur-recaptcha-cloudflare';
}
static $rc_counter = 0;
if ( empty( $recaptcha_site_key ) && empty( $recaptcha_site_secret ) ) {
$empty_credentials = true;
}
//Exit early if recaptcha is not enabled in global settings or has messing credentials.
if ( ! $global_captcha_enabled || $empty_credentials ) {
return '';
}
if ( $recaptcha_enabled ) {
if ( 0 === $rc_counter || 'test_captcha' === $context ) {
wp_enqueue_script( 'ur-recaptcha' );
wp_enqueue_script( $enqueue_script );
$ur_google_recaptcha_code = array(
'site_key' => $recaptcha_site_key,
'is_captcha_enable' => true,
'version' => $recaptcha_type,
'is_invisible' => $invisible_recaptcha,
'theme_mode' => $theme_mod,
);
if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) {
?>
';
} elseif ( 'test_captcha' === $context ) {
$recaptcha_node = '
| ' . $value . ' | |
| ' . $label . ' : | |
| ' . $label . ' : | ' . $value . ' |
' . esc_html__( 'Send data only if the following matches.', 'user-registration' ) . '