I'm working on an own shipping module and want to print some arrays. But, the module is operating in the background, so I can not print the arrays. Is there a way?


Yes, add this function to your module

function my_print_r( $msg, $name = '' )
    $error_dir = '/path/to/wordpress/wp-content/debug.log';
    $msg = print_r( $msg, true );
    $log = $name . "  |  " . $msg . "\n";
    error_log( $log, 3, $error_dir );

And call my_print_r( $variable_to_inspect, 'description' );. The file debug.log is originally used by WP_DEBUG_LOG, and if you don't have it enabled only your debug info will be there. This plugin of mine shows the content of that file in the dashboard.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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