Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two Plugin with same namespace #7

Open
shadhin-msa opened this issue Jan 8, 2019 · 7 comments
Open

Two Plugin with same namespace #7

shadhin-msa opened this issue Jan 8, 2019 · 7 comments

Comments

@shadhin-msa
Copy link

shadhin-msa commented Jan 8, 2019

Hi there,
Thanks for your awesome youtube series.

The issue is,
In your plugin, you used "Inc" namespace. What if another plugin uses same "Inc" namespace through composer?

I faced the issue. it loads files from one of the repositories src for both plugins. So one plugin gets broken.

A possible solution could be using a unique identifier for the namespace. But it's not the appropriate solution, is it?
Any solution?

issue1

@bahiirwa
Copy link
Contributor

bahiirwa commented Jan 8, 2019

Look at the lesson (WordPress Plugin Development - Part 10 - Namespaces and Composer Autoload ) https://www.youtube.com/watch?v=nbF4hWJ1hJA. It will explain everything.

@shadhin-msa
Copy link
Author

shadhin-msa commented Jan 8, 2019

I went through the video and have gone through again. The video explains how to use the namespace through composer autoload and it's well explained. My plugin works well. Only gets broken when two custom plugin get installed (after activated) together. Because both are using "Inc" namespace.
Check the screenshot I added.

@bahiirwa
Copy link
Contributor

bahiirwa commented Jan 8, 2019 via email

@shadhin-msa
Copy link
Author

Ok then what if my plugin installed in a website where already a plugin using the same namespace.

@bahiirwa
Copy link
Contributor

You are right. I deregistered all my services, changed initial file names in plugin folder, namespace and did a whole new composer install and something still duplicated.

@ldan4th
Copy link

ldan4th commented Feb 18, 2020

Shadhin...Thanks for your explanation on 1/8/219 of the exact problem I was having. Using the ideas above I changed the inc directory to my plugin name + Inc, changed globally (in the plugin) namespace Inc to namespace my plugin name + Inc, changed globally use Inc to use my plugin name + Inc, and in the main plugin PHP changed the activate, deactivate and Init (2 places) Inc to my plugin name + Inc. I then changed the psr-4 line in composer.json to read "psr-4": { " My plugin Name + Inc \" : "./ My plugin Name + Inc" } and ran composer dump-autoload. I now have three plugins operating independently with no collisions. Thanks to you all!!!

@TonyGravagno
Copy link

Just found this issue too. Did a global Find/Replace with this regex in the new/modified plugin based on the Alecaddd model.
From Inc(\\|;)
To Inc_MYPLUGIN_SLUG$1
Then "composer dumpautoload". This is required, otherwise the $prefixLengthsPsr4 value in the autoload_static.php file has an incorrect count.
When this is complete, multiple plugins can be activated and deactivated in any order, because they no longer share the global 'Inc' namespace.

Thanks for asking this question, @shadhin-msa .

The next question is, what do we do with critical information like this? Add it to the README.md? Add it to a wiki? If this valuable Issue is closed, others lose the benefit of the solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants