diff --git a/framework/core/components/backend/class-fw-settings-form-theme.php b/framework/core/components/backend/class-fw-settings-form-theme.php index 4844239e..acfe36f4 100644 --- a/framework/core/components/backend/class-fw-settings-form-theme.php +++ b/framework/core/components/backend/class-fw-settings-form-theme.php @@ -11,6 +11,12 @@ protected function _init() { ->set_is_side_tabs( fw()->theme->get_config('settings_form_side_tabs') ) ->set_string( 'title', __('Theme Settings', 'fw') ); + if ( isset( $_POST['fw_theme_settings_form'] ) ) { + $this->parse_str( $_POST['fw_theme_settings_form'], $parsed ); + unset( $_POST['fw_theme_settings_form'] ); + $_POST = array_merge( $_POST, $parsed ); + } + { add_action('admin_init', array($this, '_action_get_title_from_menu')); add_action('admin_menu', array($this, '_action_admin_menu')); @@ -215,4 +221,67 @@ public function _action_admin_enqueue_scripts() } } } + + // The same than parse_str without max_input_vars limitation + private function parse_str( $string, &$result ) + { + if ( $string==='') { + return false; + } + + parse_str( $string, $fuck ); + + $result = array(); + // find the pairs "name=value" + $pairs = explode( '&', $string ); + + foreach ( $pairs as $pair ) { + // use the original parse_str() on each element + parse_str( $pair, $params ); + $params = $this->wp_slash( $params ); + + $k = key( $params ); + + if ( ! isset( $result[ $k ] ) ) { + $result += $params; + } else { + $result[ $k ] = $this->array_merge_recursive_distinct( $result[ $k ], $params[ $k ] ); + } + } + + return true; + } + + function wp_slash( $value ) { + if ( is_array( $value ) ) { + foreach ( $value as $k => $v ) { + if ( is_array( $v ) ) { + $value[ $k ] = $this->wp_slash( $v ); + } else { + $value[ $k ] = str_replace( "\\\\'", "'", addslashes( $v ) ); + } + } + } else { + $value = str_replace( "\\\\'", "'", addslashes( $value ) ); + } + + return $value; + } + + // better recursive array merge function listed on the array_merge_recursive PHP page in the comments + private function array_merge_recursive_distinct( array &$array1, array &$array2 ) + { + $merged = $array1; + + foreach ( $array2 as $key => &$value ) { + + if ( is_array( $value ) && isset( $merged[ $key ] ) && is_array( $merged[ $key ] ) ){ + $merged[ $key ] = array_merge_recursive( $merged[ $key ], $value ); + } else { + $merged[ $key ] = $value; + } + } + + return $merged; + } } \ No newline at end of file diff --git a/framework/static/js/fw-form-helpers.js b/framework/static/js/fw-form-helpers.js index 226fb589..bc06c6c5 100644 --- a/framework/static/js/fw-form-helpers.js +++ b/framework/static/js/fw-form-helpers.js @@ -150,14 +150,16 @@ var fwForm = { opts.afterSubmitDelay(elements); } + var data = $form.serialize() + ( $submitButton.length ? '&' + $submitButton.attr( 'name' ) + '=' + $submitButton.attr( 'value' ) : '' ); + + if ( $form.attr( 'data-fw-form-id' ) === 'fw-settings-form:theme-settings' ) { + data = {'fw_theme_settings_form': data}; + } + jQuery.ajax({ type: "POST", url: opts.ajaxUrl, - data: $form.serialize() + ( - $submitButton.length - ? '&'+ $submitButton.attr('name') +'='+ $submitButton.attr('value') - : '' - ), + data: data, dataType: 'json' }).done(function(r){ isBusy = false;