How to debug register_setting callback function

I am using the following code:

register_setting(
        'myplugin_options', //setting group name
        'myplugin_options', //option name that will be stored in the database
        'myplugin_validate_options'//optional callback function
);

function myplugin_validate_options($input) {
    //how can i print $input to the screen or view the output of this function for debugging purpsoses?

}

I just need to know how we can debug our validation callback functions. From what I see they can not be output to the screen so it makes writing correct code inside of them difficult.

Read More

Thanks.

Related posts

Leave a Reply

5 comments

  1. When echoing ( echo($var) ) within ‘library’ code (ie. before the page is being built, as in the case here of register_setting) these statements will typically print just after the opening tag in the HTML but will often not show up there. I use PHP’s built-in function error_log() to print whatever I want directly to PHP’s error log. Then I can just open that file (usually php_error.log somewhere) and see the output. Work for you?

  2. none of the above solutions worked for me,
    I even tried the debug statements to a file.

    A work around which does the job is

    add a call to undefined function after all your debug statements, then the out put is printed to the screen.

  3. You can add the add_settings_error function like this:

        add_settings_error(
            'plugin_settings', // Slug title of setting
            'wporg_message', // Slug-name , Used as part of 'id' attribute in HTML output.
            __( $input ), // HERE YOU CAN DEBUG YOUR CODE
            'updated' // Message type, controls HTML class. Accepts 'error' or 'updated'.
        );