How do I debug a WordPress plugin?

前端 未结 6 1055
栀梦
栀梦 2020-12-03 04:19

I\'ve recently inherited a WordPress plugin that has a few bugs in it. My problem is that I\'m also new to WordPress and I don\'t know how to log debug messages so that I ca

6条回答
  •  庸人自扰
    2020-12-03 05:12

    According to your comment where you Much rather use a system where debug messages can be turned off and on in one place:

    It can be done in WordPress. There is a constant called WP_DEBUG that you can set to true or false from your wp-config.php file in your WordPress folder (that file where you add database parameters ).

    So, you can use:

    if( WP_DEBUG ){
    echo ""; 
    }
    

    The alert will show only when you have WP_DEBUG set to true (for example on a development version of the website like on your localhost) while it won't show on your production version of the website(You just have to set WP_DEBUG to false there).

提交回复
热议问题