LLMS_Form_Field::prepare_value()
Prepare the field’s value.
Return Return
(void)
Source Source
File: includes/forms/class-llms-form-field.php
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 | 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. |