Support » Plugin: WP PHP Console » Working with plugin debug

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Fulvio Notarstefano

    (@nekojira)

    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.

    viter-z-bayraku

    (@viter-z-bayraku)

    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..

    Plugin Author Fulvio Notarstefano

    (@nekojira)

    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?

    viter-z-bayraku

    (@viter-z-bayraku)

    I want to use your plugin to debug errors from other new plugin in Google Chrome Development Tool (Javascript Console)

    viter-z-bayraku

    (@viter-z-bayraku)

    PC::debug("test"); inside this plugin returning Fatal error: Uncaught Error: Class 'PC' not found

    viter-z-bayraku

    (@viter-z-bayraku)

    I’m sorry. Your code in previous messages is helpful. Thank you!

    viter-z-bayraku

    (@viter-z-bayraku)

    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 );
    
            } );
        }
    Plugin Author Fulvio Notarstefano

    (@nekojira)

    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.

    viter-z-bayraku

    (@viter-z-bayraku)

    It’s only for temporary debugging. I’m looking for quick solution for plugin development, based on php classes.

    viter-z-bayraku

    (@viter-z-bayraku)

    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...
    }
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Working with plugin debug’ is closed to new replies.