Skip to content

8. Debug

Yurii Pavlov edited this page Jun 25, 2019 · 5 revisions

Debug

You can use special debug functions wp_dump() and wlog() to debug your code.

wp_dump()

Supports a variable number of arguments

 wp_dump( ...$params );

for example:

 wp_dump($a, $b, $c);

will display value of all variables in a convenient way with <pre></pre>

 array(3) {
   [0]=>
   string(3) "var $a value"
   [1]=>
   string(3) "var $b value"
   [2]=>
   string(3) "var $c value"
 }

wlog()

Writes data to w.log file, that appears in path get_stylesheet_directory() . '/w.log';

wlog( $var, $desc = ' >> ', $clear_log = false );

You can use it with any type of data. For example:

wlog( ['some string', 55, ['some array with data']], '>> My debug note' );

will add to w.log:

[14:11:09]-------------------------
[14:11:09]>> My debug note : Array
(
    [0] => some string
    [1] => 55
    [2] => Array
        (
            [0] => some array with data
        )

)
Clone this wiki locally