admin管理员组文章数量:1287593
Is it possible to vardump the variable inside the action function? i am not able to echo or see results when i am doing so.
This is not a woo commerce question but i am having problems with
add_action('woocommerce_order_status_changed','wc_order_uppdate_to_cancelled_status', 20, 4);
Is it possible to vardump the variable inside the action function? i am not able to echo or see results when i am doing so.
This is not a woo commerce question but i am having problems with
add_action('woocommerce_order_status_changed','wc_order_uppdate_to_cancelled_status', 20, 4);
Share
Improve this question
edited Oct 19, 2018 at 14:01
asked Oct 19, 2018 at 12:50
user145078user145078
2
|
1 Answer
Reset to default 5If you want to use debugging from an action where you won't see the output, you can send things to error_log
. First, you need to enable debug logging. In your /wp-config.php
add the lines:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
This will create a file called /wp-content/debug.log
Next, in your code, add some calls to error_log
and var_export
:
add_action( 'init', 'some_function' );
function some_function( $var ) {
error_log( var_export( $var, 1 ) );
}
Now, when init
runs our function, the contents of $var
will be dumped to /wp-content/debug.log
. Note the second parameter to var_export
says to return the output instead of trying to send it to be displayed.
Edit: 2021/09/17
Lately I've been using Ray for debugging things in general, and it's particularly helpful when you can't see the output of the script you're running readily.
Installation
- Download the Ray app
- Install the package (they have a WordPress-specific plugin, I tend to just use the package directly)
composer require spatie/ray --dev
Usage
- Open the Ray app
- In your PHP, call
ray()
, e.g.
ray($var);
The Ray window will populate with the variable's information:
本文标签: theme developmentUse debugging for add action events
版权声明:本文标题:theme development - Use debugging for add action events 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741314543a2371838.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
var_dump
in this? To be honest I don't really understand your question. You can usevar_dump()
inside the function that is called from that action, yes – kero Commented Oct 19, 2018 at 13:24