1

I'm trying to understand how this block of code in the an existing wordpress plugin which depends on a third party events-manager plugin works. I understand that the 'plugins_loaded' action hook is called to register the 'class-events-manager-stripe' class but the next line then calls a static class 'EM_Gateways' in the 3rd party plugin. I can't see where in the plugin this class is included or loaded as part of the php class loading mechanism.

The code is sample

function emp_stripe_register() {
    //check that EM Pro is installed
    if( ! defined( 'EMP_VERSION' ) ) {
        add_action( 'admin_notices', 'emp_stripe_requirements' );
        return false; //don't load plugin further
    }
    require_once( plugin_dir_path( __FILE__ ) . 'class-events-manager-stripe.php' );
    EM_Gateways::register_gateway('stripe', 'EM_Gateway_Stripe');
}
add_action( 'plugins_loaded', 'emp_stripe_register', 1000);

I've reused the code locally for my own plugin but keep getting this error

[29-Apr-2015 12:23:56 UTC] PHP Fatal error:  Class 'EM_Gateways' not found in /home/xxxx/projects/github/bhaa/public/class-bhaa.php on line 93

What do i need to do to ensure the 'EM_Gateways' class is loaded as part of my plugin start up?

4
  • 1
    Have you installed and activated the EM plugin? It should be noted that plugins don't live in a mini plugin sandbox, it's all just code in the same environment being loaded
    – Tom J Nowell
    Apr 29, 2015 at 12:51
  • Also, /home/xxxx/projects/github/bhaa/public/class-bhaa.php doesn't look like a plugin path, are you attempting to load WordPress APIs without loading WordPress in order to create a custom endpoint?
    – Tom J Nowell
    Apr 29, 2015 at 12:53
  • I have the EM plugin loaded and activated. I'm also in local dev mode here and am using softlinks for my plugin to my development folder, that explains the odd looking path. Apr 29, 2015 at 12:56
  • softlinks? You mean symlinks? Those can cause issues with loading file paths in PHP, the official WP Core stance is that you shouldn't use them
    – Tom J Nowell
    Apr 29, 2015 at 14:54

1 Answer 1

0

The EM_Gateways class lets you add payment gateways to the Pro version of the plugin, not the free one. It seems Pro is a plugin that you install together with the free version, and then you get access to payment gateways feature.

From their website:

Events Manager Pro has a base gateway class which every gateway extends, meaning minimal amounts of code is needed to link gateways to Events Manager. Even more importantly, this allows for developers to create their own plugin which adds a new gateway to Events Manager in an upgrade-safe manner.

Searching github you can get a glimpse of what some random version of the class looks like. If you need a reliable latest copy you will probably have to buy the plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.