Support Forum
Support › MB Settings Page › Options escaping quotes
On the setting page I have a metabox with an textarea. If I write "'" in that field and then save I get "\'". Then after another save I get "\\\'" and so on with every save.
I'm trying to save HTML/JS code as an option. Is there any way to filter user input before it is saved to DB?
Ok, I think this code fixed the issue:
function filter_html_options( $new_value, $old_value ) {
array_walk_recursive($new_value, function(&$value) {
$value = stripslashes ($value);
});
return $new_value;
}
function plugin_init() {
add_filter( 'pre_update_option', 'filter_html_options', 10, 2 );
}
add_action( 'init', 'plugin_init' );
Hi,
Are you using the latest version of Meta Box and MB Settings Page? I've updated the plugins yesterday with a fix for this bug. I use wp_unslash()
function to remove slashes from submitted value before saving.
Updated to 1.3 but problem still exists. But I changed my code to use wp_unslash and it works fine
Hmm, can you post your full code here to check? Also, what is your PHP version and OS?
I work currently on windows 10 with XAMPP installed, PHP version 7.1.6. WordPress 4.8.
Everything is basically copied from docs. Metabox and extensions are included directly in my plugin files. Metabox 4.12.2 and MB Settings Page 1.3
(I don't know how to format code because the editor here has no buttons)
the field:
$meta_boxes[] = array(
'id' => 'brt-header-scripts',
'title' => __( 'Scripts before </head> tag', 'brt' ),
'settings_pages' => 'brt-scripts',
'fields' => array(
array(
'id' => 'brt-head-scripts',
'type' => 'textarea',
'clone' => true,
'sort_clone' => true,
'add_button' => __('Add another', 'brt'),
'attributes' => array(
'style' => 'height:250px',
),
)
)
);
the setting page:
$settings_pages[] = array(
'id' => 'brt-scripts',
'menu_title' => __( 'Additional scripts', 'brt' ),
'parent' => 'brt-options',
);
Somehow my code that remove slashed was removed from the released version. Probably it was an error while merging. I've just pushed a fix for that. Also added 2 options: submit_button
and message
for the text of submit button and successful message.
Please update.
PS: Can you post the screenshot of your screen when replying this thread? Don't you see any button in the reply box?
Saving and new options works great. Thx.
The editor on the page looks like this:
http://tinypic.com/view.php?pic=2cr39yg&s=9
I'm using Windows 10, latest Chrome but I get the same problem in Firefox.
I get this in the console:
Uncaught ReferenceError: Backbone is not defined
at notes-common-v2.js:32
at notes-common-v2.js:158
admin-bar-v2.js:2 Uncaught ReferenceError: _ is not defined
at admin-bar-v2.js:2
Thanks a lot. Just fixed the bug with the editor!
Cheers
Anh