LLMS_Admin_Settings::save_fields( array $settings )
Save admin fields.
Description Description
Loops though the lifterlms options array and outputs each field.
Parameters Parameters
- $settings
-
(array) (Required) Opens array to output
Return Return
(bool)
Source Source
File: includes/admin/class.llms.admin.settings.php
public static function save_fields( $settings ) { if ( empty( $_POST ) ) { return false; } // Options to update will be stored here $update_options = array(); // Loop options and get values to save foreach ( $settings as $value ) { if ( ! isset( $value['id'] ) ) { continue; } $type = isset( $value['type'] ) ? sanitize_title( $value['type'] ) : ''; // Remove secure options from the database. if ( isset( $value['secure_option'] ) && llms_get_secure_option( $value['secure_option'] ) ) { delete_option( $value['id'] ); continue; } // Get the option name $option_value = null; switch ( $type ) { // Standard types case 'checkbox' : // ooboi this is gross if ( strstr( $value['id'], '[' ) ) { parse_str( $value['id'], $option_data ); $main_option_names = array_keys( $option_data ); $main_option_vals = array_keys( $option_data[ $main_option_names[0] ] ); if ( isset( $_POST[ $main_option_names[0] ] ) && in_array( $main_option_vals[0], array_keys( $_POST[ $main_option_names[0] ] ) ) ) { $option_value = 'yes'; } else { $option_value = 'no'; } } elseif ( isset( $_POST[ $value['id'] ] ) ) { $option_value = 'yes'; } else { $option_value = 'no'; } break; case 'textarea' : case 'wpeditor' : if ( isset( $_POST[ $value['id'] ] ) ) { $option_value = wp_kses_post( trim( stripslashes( $_POST[ $value['id'] ] ) ) ); } else { $option_value = ''; } break; case 'password': case 'text' : case 'email': case 'number': case 'select' : case 'single_select_page' : case 'single_select_membership' : case 'radio' : case 'hidden' : case 'image' : if ( isset( $_POST[ $value['id'] ] ) ) { $option_value = llms_clean( stripslashes( $_POST[ $value['id'] ] ) ); } else { $option_value = ''; } if ( isset( $value['sanitize'] ) && 'slug' === $value['sanitize'] ) { $option_value = sanitize_title( $option_value ); } break; case 'multiselect' : if ( isset( $_POST[ $value['id'] ] ) ) { foreach ( $_POST[ $value['id'] ] as $k => $v ) { $_POST[ $value['id'] ][ $k ] = llms_clean( stripslashes( $v ) ); } $option_value = $_POST[ $value['id'] ]; } else { $option_value = ''; } break; // Custom handling default : do_action( 'lifterlms_update_option_' . $type, $value ); break; }// End switch(). if ( ! is_null( $option_value ) ) { // Check if option is an array if ( strstr( $value['id'], '[' ) ) { parse_str( $value['id'], $option_array ); // Option name is first key $option_name = current( array_keys( $option_array ) ); // Get old option value 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(); } // Set keys and value $key = key( $option_array[ $option_name ] ); $update_options[ $option_name ][ $key ] = $option_value; // Single value } else { $update_options[ $value['id'] ] = $option_value; } } // Custom handling do_action( 'lifterlms_update_option', $value ); }// End foreach(). // Now save the options foreach ( $update_options as $name => $value ) { update_option( $name, $value ); } return true; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |