• Hi.
    Firstly thanks for this plugin.
    I’m developing a plugin for handling Paypal payments.
    In the main plugin’s file i have code like this:

    require 'classes/class.server.php';
    add_action('plugins_loaded', array('CRPP_IPN_Server_Class', 'init'));

    and in the class.server.php I’ve set up code like this

        class CRPP_IPN_Server_Class extends WP_Plugin_Class
        {
            
            /**
             * Class' instance
             *
             * @access public
             * @var class instance
             */
            static $instance;
        
            /**
             * Init()
             * 
             * Class' instance initialization
             *
             * @access public 
             * @return instance
             * @author Raffaele Candeliere
             */
            static function init()
            {
                is_null( self::$instance ) AND self::$instance = new self;
            
                return self::$instance;
            }
        
            /**
             * __construct()
             *
             * Class' constructor
             *
             * @access public
             * @return void
             * @author Raffaele Candeliere
             */
            function __construct()
            {
                /*
                 .
                 .
                 .
                 */
                add_action( 'paypal_ipn_for_wordpress_payment_status_completed', array($this, 'ipn_payment_status_confirmed_handler'), 10, 1);
            }
    
            public function ipn_payment_status_confirmed_handler($posted) {
                error_log(var_export($posted, true));
            }

    Well, the problem is that if I define the hook like this, the $posted parameter doesn’t get populated. I do receive the notification but the $posted var is empty.
    Viceversa, if i hook into your plugin directly in my main’s plugin file, like this:

    add_action('plugins_loaded', 'crpp_init');
    
    function crpp_init() {
        add_action( 'paypal_ipn_for_wordpress_payment_status_completed', 'crpp_ipn_payment_satus_confirmed', 10, 1);
    }
    
    function crpp_ipn_payment_satus_confirmed($posted) {
        error_log(var_export($posted, true));
    }

    then the $posted param is populated!
    I’d like to stick with my (standardized) programming pattern where i confine each functional block of code in the relevant class.
    What am I doing wrong in using/registering, calling your hook?
    Thanks

    • This topic was modified 7 years, 6 months ago by caraffande.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor angelleye

    (@angelleye)

    I’d have to get our lead coder involved to know for sure, and I can’t pull him off his current projects for things like this unless they are paid projects, unfortunately. I can try to help think it through with you, though.

    My first thought would have something to do with $_POST not getting loaded as expected when run through your class for some reason. $posted is basically just $_POST with a couple of extra value pairs added. Can you check $_POST directly to see if it’s empty, too, inside your class? If you’re getting the log file then the hook is triggering, so we just need to figure out where that data is getting lost..??

    Maybe that doesn’t help you at all, but hopefully it’ll lead you in the right direction. This seems like something you might be able to get answered more quickly on StackOverflow in a general WordPress/WooCommerce tag.

    I can try to have one of my guys take a quick look a little later, but it can be tough to pull them away.

    Thread Starter caraffande

    (@caraffande)

    Thank you very much for your detailed answer.
    I’ve followed your hint. I’ve error_log’d the $_POST superglobal. You’re right. It’s empty.
    In any case thank you for your effort. At the moment, I’ll go the “main’s plugin file” way, hoping to have some other hint from you and/or the community in the future.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hook params not defined within PHP class’ is closed to new replies.