Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme settings max input vars #3327

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 69 additions & 0 deletions framework/core/components/backend/class-fw-settings-form-theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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;
}
}
12 changes: 7 additions & 5 deletions framework/static/js/fw-form-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down