wc_query_string_form_fields()
Outputs hidden form inputs for each query string variable.
Хуков нет.
Возвращает
Строку
.
Использование
wc_query_string_form_fields( $values, $exclude, $current_key, $return );
- $values(строка|массив)
- Name value pairs, or a URL to parse.
По умолчанию: null - $exclude(массив)
- Keys to exclude.
По умолчанию: array() - $current_key(строка)
- Current key we are outputting.
По умолчанию: '' - $return(true|false)
- Whether to return.
По умолчанию: false
Список изменений
С версии 3.0.0 | Введена. |
Код wc_query_string_form_fields() wc query string form fields WC 9.8.1
function wc_query_string_form_fields( $values = null, $exclude = array(), $current_key = '', $return = false ) { if ( is_null( $values ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $values = $_GET; } elseif ( is_string( $values ) ) { $url_parts = wp_parse_url( $values ); $values = array(); if ( ! empty( $url_parts['query'] ) ) { // This is to preserve full-stops, pluses and spaces in the query string when ran through parse_str. $replace_chars = array( '.' => '{dot}', '+' => '{plus}', ); $query_string = str_replace( array_keys( $replace_chars ), array_values( $replace_chars ), $url_parts['query'] ); // Parse the string. parse_str( $query_string, $parsed_query_string ); // Convert the full-stops, pluses and spaces back and add to values array. foreach ( $parsed_query_string as $key => $value ) { $new_key = str_replace( array_values( $replace_chars ), array_keys( $replace_chars ), $key ); $new_value = str_replace( array_values( $replace_chars ), array_keys( $replace_chars ), $value ); $values[ $new_key ] = $new_value; } } } $html = ''; foreach ( $values as $key => $value ) { if ( in_array( $key, $exclude, true ) ) { continue; } if ( $current_key ) { $key = $current_key . '[' . $key . ']'; } if ( is_array( $value ) ) { $html .= wc_query_string_form_fields( $value, $exclude, $key, true ); } else { $html .= '<input type="hidden" name="' . esc_attr( $key ) . '" value="' . esc_attr( wp_unslash( $value ) ) . '" />'; } } if ( $return ) { return $html; } echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped }