There’s a FAQ. The PC class is used to print variables in your Chrome JavaScript console.
For example
<?php
$foo = 'bar';
add_action( 'plugins_loaded', function () use ( $foo ) {
if ( ! class_exists( 'PC', false ) ) {
PhpConsole\Helper::register();
}
PC::my_tag( $foo );
} );
This will output bar
in your Chrome console.
Thank you, Fulvio. I understand it. But this class working only in theme templates. But I can not understand, how it integrate for debugging new plugin.. In other plugin I have unavailable PC class error..
Are you able to use the other functions of the plugin, like the console terminal or the Google Chrome JavaScript console for variable and error dumping?
I want to use your plugin to debug errors from other new plugin in Google Chrome Development Tool (Javascript Console)
PC::debug("test");
inside this plugin returning Fatal error: Uncaught Error: Class 'PC' not found
I’m sorry. Your code in previous messages is helpful. Thank you!
One question. Can be your code used as a public function inside another class?
Like:
public function debug($foo){
add_action( 'plugins_loaded', function () use ( $foo ) {
if ( ! class_exists( 'PC', false ) ) {
PhpConsole\Helper::register();
}
PC::my_tag( $foo );
} );
}
I certainly believe so. Mind that this is intended for temporary debugging and you shouldn’t roll PHP Console on a production site.
If you need to debug some variable in WordPress, another way of doing it is to store the data you want to output in the console in a WordPress option, e.g.
update_option( 'my_test', $data );
Then in the console you’d do return get_option( 'my_test' );
from the terminal and check results.
It’s only for temporary debugging. I’m looking for quick solution for plugin development, based on php classes.
That is helpful for me.. Thank you 🙂
add_action( 'plugins_loaded', array( 'Test_Class', 'init' ));
class Test_Class {
public static function init() {
$class = __CLASS__;
new $class;
}
public function __construct() {
Test_Class::my_debug(555777);
//construct what you see fit here...
}
public function my_debug($foo) {
if ( ! class_exists( 'PC', false ) ) {
PhpConsole\Helper::register();
}
PC::my_tag($foo);
}
//etc...
}