LLMS_Form_Field::prepare_value()
Prepare the field’s value.
Return Return
(void)
Source Source
File: includes/forms/class-llms-form-field.php
protected function prepare_value() { // Never autoload passwords and or fields with an explicit value (except radio and checkbox). if ( 'password' === $this->settings['type'] || ! empty( $this->settings['value'] && ! in_array( $this->settings['type'], array( 'checkbox', 'radio' ), true ) ) ) { return; } $user_val = null; // Attempt to populate field data from the most recent $_POST action. if ( 'POST' === strtoupper( getenv( 'REQUEST_METHOD' ) ) ) { $posted = wp_unslash( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce is verified prior to reaching this method. if ( isset( $posted[ $this->settings['name'] ] ) ) { $filter_options = is_array( $posted[ $this->settings['name'] ] ) ? array( FILTER_REQUIRE_ARRAY ) : array(); $user_val = llms_filter_input_sanitize_string( INPUT_POST, $this->settings['name'], $filter_options ); } } // Auto-populate field from the datastore if we have a user and datastore information. if ( is_null( $user_val ) && ( isset( $this->data_source ) && 'wp_user' === $this->data_source_type ) && $this->settings['data_store_key'] ) { $user_val = $this->data_source->get( $this->settings['data_store_key'] ); } // Set the value to the user's submitted or stored value. if ( ! is_null( $user_val ) ) { if ( in_array( $this->settings['type'], array( 'checkbox', 'radio' ), true ) && ! $this->is_input_group() ) { $this->settings['checked'] = ( $this->settings['value'] === $user_val ); } else { $this->settings['value'] = $user_val; } } // Handle "default" alias "selected". if ( isset( $this->settings['selected'] ) && '' !== $this->settings['selected'] ) { $this->settings['default'] = $this->settings['selected']; } // Add default value if there's no explicit value and a default value is set. if ( ! $this->settings['value'] && ! is_array( $this->settings['value'] ) && '' !== $this->settings['default'] ) { $this->settings['value'] = $this->settings['default']; } }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
5.9.0 | Stop using deprecated FILTER_SANITIZE_STRING . |
5.0.0 | Introduced. |