Options escaping quotes

Support MB Settings Page Options escaping quotes

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #6283
    brandoobrandoo
    Participant

    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?

    #6284
    brandoobrandoo
    Participant

    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' );
    #6294
    Anh TranAnh Tran
    Keymaster

    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.

    #6296
    brandoobrandoo
    Participant

    Updated to 1.3 but problem still exists. But I changed my code to use wp_unslash and it works fine

    #6299
    Anh TranAnh Tran
    Keymaster

    Hmm, can you post your full code here to check? Also, what is your PHP version and OS?

    #6302
    brandoobrandoo
    Participant

    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', 
        );
    #6307
    Anh TranAnh Tran
    Keymaster

    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?

    #6316
    brandoobrandoo
    Participant

    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

    #6325
    Anh TranAnh Tran
    Keymaster

    Thanks a lot. Just fixed the bug with the editor!

    Cheers
    Anh

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘Options escaping quotes’ is closed to new replies.