What happens when two plugins have the same 3rd party class included into them?

I am building a plugin that uses Stripe for the payment processing. I have included Stripe’s PHP library into my plugin and everything works great. But what if someone else makes a plugin that also uses Stripe … or worse, an older version of Stripe that isn’t compatible with mine? Sounds like there could be conflicts if someone had both of our plugins activated at the same time.

Do I need to namespace Stripe’s classes? Is that advisable? I imagine that being a maintenance nightmare if I ever want to upgrade to a newer version of Stripe’s library.

I’m totally OK doing that, but I want to make sure I’m following best practices here.

Thanks!
Tony

2 Answers
2

I went ahead and namespaced Stripe. Everything worked just great. And now I don’t have to worry about any one else’s Stripe library messing up my stuff.

Original:

namespace Stripe;

New:

namespace MyRadNamespace\Stripe;

If anyone is interested in seeing how it’s done, feel free to browse my repo:

https://github.com/Spokane-Wordpress-Development/Freezy-Stripe

Cheers!

Leave a Comment