Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

Thanks.

share|improve this question
    
have you tried var_dump? –  Bainternet Apr 13 '11 at 22:19
    
I do love me some var_dump. 90% of the time, it gives you everything you need, every time. –  Drew Gourley Apr 14 '11 at 1:50
    
Yeah it looks like var_dump does the trick. I also noticed that print_r works too, but just a plain old echo does not output to the screen, strangely enough. –  mike Apr 14 '11 at 13:06
    
That's probably because $input contains an array of data, you can't echo arrays. –  t31os Apr 15 '11 at 10:45
    
You can echo arrays, it will just print Array... Even if you do echo 'hi'; it will not output. Give it a try. Debugging this function is a PIA. –  mike Apr 15 '11 at 14:43

3 Answers 3

The dirty and only way I've founded:

function myplugin_validate_options($input) {
    var_dump($input);
    exit;

}
share|improve this answer

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?

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.