0 ) { foreach ( self::$errors as $error ) { echo '
' . esc_html( $error ) . '
' . esc_html( $message ) . '
' . wptexturize( wp_kses_post( $options['desc'] ) ) . '
'; } if ( isset( $options['sections'] ) ) { foreach ( $options['sections'] as $id => $section ) { if ( ! isset( $section['type'] ) ) { continue; } if ( 'card' === $section['type'] ) { $section_id = isset( $section['id'] ) ? "id='". $section['id'] . "'" : ''; $settings .= '' . wptexturize( wp_kses_post( $section['desc'] ) ) . '
'; } $settings .= '
';
$settings .= '' . wp_kses_post( $description ) . '
'; } elseif ( $description && in_array( $value['type'], array( 'checkbox' ) ) ) { $description = wp_kses_post( $description ); } elseif ( $description ) { $description = ' ' . wp_kses_post( $description ) . ' '; } if ( $desc_field && in_array( $value['type'], array( 'textarea', 'radio', 'checkbox' ) ) ) { $desc_field = '' . wp_kses_post( $desc_field ) . '
'; } elseif ( $desc_field ) { $desc_field = ' ' . wp_kses_post( $desc_field ) . ' '; } if ( $tooltip_html ) { $tooltip_html = ur_help_tip( $tooltip_html ); } return array( 'description' => $description, 'desc_field' => $desc_field, 'tooltip_html' => $tooltip_html, ); } /** * Save admin fields. * * Loops though the user registration options array and outputs each field. * * @param array $options Options array to output. * * @return bool */ public static function save_fields( $options ) { if ( empty( $_POST ) ) { // phpcs:ignore WordPress.Security.NonceVerification return false; } // Options to update will be stored here and saved later. $update_options = array(); if ( empty( $options ) ) { return false; } // Return if default wp_login is disabled and no redirect url is set. $is_wp_login_disabled_error = apply_filters( 'user_registration_settings_prevent_default_login', $_POST ); if ( $is_wp_login_disabled_error && 'redirect_login_error' === $is_wp_login_disabled_error ) { return; } // Loop options and get values to save. foreach ( $options['sections'] as $id => $section ) { if ( ! isset( $id ) || ! isset( $section['type'] ) ) { continue; } foreach ( $section['settings'] as $option ) { // Get posted value. if ( null !== $option['id'] ) { if ( strstr( $option['id'], '[' ) ) { parse_str( $option['id'], $option_name_array ); $option_name = sanitize_text_field( current( array_keys( $option_name_array ) ) ); $setting_name = key( $option_name_array[ $option_name ] ); $raw_value = isset( $_POST[ $option_name ][ $setting_name ] ) ? wp_unslash( $_POST[ $option_name ][ $setting_name ] ) : null; // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized } else { $option_name = sanitize_text_field( $option['id'] ); $setting_name = ''; $raw_value = isset( $_POST[ $option['id'] ] ) ? wp_unslash( $_POST[ $option['id'] ] ) : null; // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized } } // Format the value based on option type. switch ( $option['type'] ) { case 'checkbox': case 'toggle': $value = ur_string_to_bool( $raw_value ); break; case 'textarea': $value = wp_kses_post( trim( $raw_value ) ); break; case 'multiselect': $value = array_filter( array_map( 'ur_clean', (array) $raw_value ) ); break; case 'select': $allowed_values = empty( $option['options'] ) ? array() : array_keys( $option['options'] ); if ( empty( $option['default'] ) && empty( $allowed_values ) ) { $value = null; break; } $default = ( empty( $option['default'] ) ? $allowed_values[0] : $option['default'] ); $value = in_array( $raw_value, $allowed_values ) ? sanitize_text_field( $raw_value ) : sanitize_text_field( $default ); break; case 'tinymce': $value = wpautop( $raw_value ); break; default: $value = ur_clean( $raw_value ); break; } /** * Filter to Sanitize the value of an option. * * @param boolean $value String converted to Boolean * @param mixed $option Option to save * @param string $raw_value Option value to save */ $value = apply_filters( 'user_registration_admin_settings_sanitize_option', $value, $option, $raw_value ); /** * Filter to Sanitize the value of an option by option name. * * @param boolean $value String converted to Boolean * @param mixed $option Option value to save * @param string $raw_value Option value to save */ $value = apply_filters( "user_registration_admin_settings_sanitize_option_$option_name", $value, $option, $raw_value ); if ( is_null( $value ) || count( self::$errors ) > 0 ) { continue; } // Check if option is an array and handle that differently to single values. if ( $option_name && $setting_name ) { if ( ! isset( $update_options[ $option_name ] ) ) { $update_options[ $option_name ] = get_option( $option_name, array() ); } if ( ! is_array( $update_options[ $option_name ] ) ) { $update_options[ $option_name ] = array(); } $update_options[ $option_name ][ $setting_name ] = $value; } else { $update_options[ $option_name ] = $value; } } }// End foreach(). // Save all options in our array. foreach ( $update_options as $name => $value ) { update_option( $name, $value ); } return true; } /** * Capitalize Settings Title Phrase. * * @param string $text Setting Label. */ public static function capitalize_title( $text = null ) { $prepositions = array( 'at', 'by', 'for', 'in', 'on', 'to', 'or' ); $words = explode( ' ', $text ); $capitalized_words = array(); foreach ( $words as $word ) { $word = trim( $word ); if ( ! in_array( $word, $prepositions ) ) { // Check if the word is a shash separated terms. Eg: "Hide/Show". if ( strpos( $word, '/' ) ) { $separate_terms = explode( '/', $word ); $capitalized_terms = array(); foreach ( $separate_terms as $term ) { $capitalized_terms[] = ucfirst( $term ); } $word = implode( '/', $capitalized_terms ); } elseif ( strpos( $word, 'CAPTCHA' ) ) { $word = $word; } else { $word = ucfirst( $word ); } } $capitalized_words[] = $word; } return implode( ' ', $capitalized_words ); } /** * Search GLobal Settings. */ public static function search_settings() { $search_string = isset( $_POST['search_string'] ) ? sanitize_text_field( wp_unslash( $_POST['search_string'] ) ) : ''; //phpcs:ignore; $search_url = ''; $found = false; // Create an array of results to return as JSON. $autocomplete_results = array(); $index = 0; $settings = self::get_settings_pages(); if ( ! empty( $settings ) ) { foreach ( $settings as $key => $section ) { if ( is_bool( $section ) || ! method_exists( $section, 'get_settings' ) ) { unset( $settings[ $key ] ); continue; } $reflection = new ReflectionProperty( get_class( $section ), 'id' ); if ( ! $reflection->isPublic() ) { unset( $settings[ $key ] ); continue; } } foreach ( $settings as $section ) { $subsections = array_values( array_unique( array_merge( array( '' ), array_keys( $section->get_sections() ) ) ) ); if ( ! empty( $subsections ) ) { foreach ( $subsections as $subsection ) { if ( 'user-registration-invite-codes' === $section->id ) { if ( '' !== $subsection ) { $subsection_array = $section->get_settings( $subsection ); } } else { switch ( $subsection ) { case 'login-options': $subsection_array = get_login_options_settings(); break; case 'frontend-messages': $subsection_array = $section->get_frontend_messages_settings(); break; default: $subsection_array = $section->get_settings( $subsection ); break; } } if ( is_array( $subsection_array ) && ! empty( $subsection_array ) ) { $flattened_array = self::flatten_array( $subsection_array ); $result = self::search_string_in_array( $search_string, $flattened_array ); if ( ! empty( $result ) ) { foreach ( $result as $key => $value ) { $match = array_search( $value['title'], array_column( $autocomplete_results, 'label' ), true ); //phpcs:ignore; if ( false === $match ) { $autocomplete_results[ $index ]['label'] = $value['title']; $autocomplete_results[ $index ]['desc'] = $value['desc']; if ( ! empty( $subsection ) ) { $autocomplete_results[ $index ]['value'] = admin_url( 'admin.php?page=user-registration-settings&tab=' . $section->id . '§ion=' . $subsection . '&searched_option=' . $value['id'] ); } else { $autocomplete_results[ $index ]['value'] = admin_url( 'admin.php?page=user-registration-settings&tab=' . $section->id . '&searched_option=' . $value['id'] ); } ++$index; } } continue; } } } } } } if ( ! empty( $autocomplete_results ) ) { wp_send_json_success( array( 'results' => $autocomplete_results, ) ); } else { $autocomplete_results[ $index ]['label'] = __( 'No Search result found !', 'user-registration' ); $autocomplete_results[ $index ]['desc'] = ''; $autocomplete_results[ $index ]['value'] = 'no_result_found'; wp_send_json_success( array( 'results' => $autocomplete_results, ) ); } } /** * Search String in Array. * * @param string $string_to_search String to Search. * @param array $array Search Array. */ public static function search_string_in_array( $string_to_search, $array ) { $result = array(); if ( is_object( $array ) ) { $array = (array) $array; } $index = 0; foreach ( $array as $key => $value ) { if ( is_array( $value ) ) { foreach ( $value as $text ) { if ( ! is_array( $text ) ) { if ( stripos( $text, $string_to_search ) !== false ) { $result[ $index ]['id'] = isset( $value['id'] ) ? $value['id'] : 'true'; $result[ $index ]['title'] = isset( $value['title'] ) ? $value['title'] : 'true'; $desc_tip = isset( $value['desc_tip'] ) && true !== $value['desc_tip'] ? $value['desc_tip'] : ''; $desc = isset( $value['desc'] ) && true !== $value['desc'] ? $value['desc'] : ''; $result[ $index ]['desc'] = ! empty( $desc_tip ) ? $desc_tip : $desc; ++$index; break; } } } } } return $result; } /** * Return Non Nested Array from Nested Settings Array * * @param array $nested_array Nested Settings Array. * * @return array */ public static function flatten_array( $nested_array ) { $settings_array = array(); // create an empty array to store the list of settings. if ( isset( $nested_array['sections'] ) ) { // loop through each section in the array. foreach ( $nested_array['sections'] as $section ) { if ( isset( $section['settings'] ) ) { if ( is_string( $section['settings'] ) ) { continue; } // loop through each setting in the section and add it to the $settings_array. foreach ( $section['settings'] as $setting ) { $settings_array[] = $setting; } } else { $inner_settings = self::flatten_array( $section ); if ( ! empty( $inner_settings ) ) { $settings_array[] = $inner_settings; } } } } return $settings_array; } }