Options escaping quotes
Support › MB Settings Page › Options escaping quotes
- This topic has 8 replies, 2 voices, and was last updated 7 years, 9 months ago by
Anh Tran.
-
AuthorPosts
-
July 12, 2017 at 7:39 PM #6283
brandoo
ParticipantOn 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?
July 12, 2017 at 8:57 PM #6284brandoo
ParticipantOk, 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' );
July 13, 2017 at 8:39 AM #6294Anh Tran
KeymasterHi,
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.July 13, 2017 at 3:01 PM #6296brandoo
ParticipantUpdated to 1.3 but problem still exists. But I changed my code to use wp_unslash and it works fine
July 13, 2017 at 9:32 PM #6299Anh Tran
KeymasterHmm, can you post your full code here to check? Also, what is your PHP version and OS?
July 13, 2017 at 9:51 PM #6302brandoo
ParticipantI 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', );
July 14, 2017 at 9:25 AM #6307Anh Tran
KeymasterSomehow 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
andmessage
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?
July 14, 2017 at 9:11 PM #6316brandoo
ParticipantSaving and new options works great. Thx.
The editor on the page looks like this:
http://tinypic.com/view.php?pic=2cr39yg&s=9I'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:2July 15, 2017 at 9:10 AM #6325Anh Tran
KeymasterThanks a lot. Just fixed the bug with the editor!
Cheers
Anh -
AuthorPosts
- The topic ‘Options escaping quotes’ is closed to new replies.