I am trying to debug a plugin and am using error_log() in various places to see what various things are. I am using the following:

error_log( print_r( $variable ) );

When I look at debug.log, all I see is 1 and the actual output of the error_log() function is sent to the browser instead.

I know another plugin is not doing this as all are disabled with the exception of the one I am writing. In my wp-config.php, I have defined WP_DEBUG_DISPLAY as false.

The same thing happens if I use var_dump() and var_export(). Other functions like gettype() work just fine.

Is there any way to get the output into debug.log?

3 s
3

The print_r function accept second parameter for return so it retrun the variable instead of printing it.

print_r($expression, $return)

So you can do

error_log( print_r( $variable, true ) );

Leave a Reply

Your email address will not be published. Required fields are marked *