Thread Starter
polev
(@polev)
Example code:
add_action('loop_start', function($query) {
trigger_error(print_r($query, true));
});
Thread Starter
polev
(@polev)
Other example code:
// PHP Console autoload
require_once dirname( __FILE__ ) . '/wp-php-console/vendor/autoload.php';
// make PC object available
PhpConsole\Helper::register();
// example use of PC:debug()
PC::debug($_SERVER);
// example use of PC:db()
add_action('wp', function ($wp) {
PC::db($wp, 'wp');
});
here’s a lot on the topic:
http://codex.wordpress.org/Debugging_in_WordPress
you can use this link as starting point
for the rest, the same rules apply for debugging any php application, so you can google for debug php if you want to learn more on the subject
as on how WordPress handles errors, it extends trigger_error with a php class of its own:
http://codex.wordpress.org/Class_Reference/WP_Error
as for PHP Console, if WP_DEBUG and error_reporting are set to return all errors, PHP Console will capture those and display them in your Chrome Dev Tools javascript console, alongside with other javascript (not php) code notices. So, if you defined custom errors with trigger_error or using the WP_Error class, they will appear there, without you need to use PHP Console code at all.
if you want to test specific functions of wordpress inside a terminal, just as if it were a javascript terminal, you need to use the terminal, you can access to wordpress functions too
Thread Starter
polev
(@polev)
Part of this support question is obsolete as this plugin includes the registration option since version 1.3.0
See https://github.com/nekojira/wp-php-console#register-pc-class
After you installed the plugin and enabled Register PC Class
you can write debug statements like PC::debug( $my_var ) to print $my_var to Chrome’s Javascript Console