Closed szepeviktor closed 2 years ago
I would welcome PSR-4 naming as this class-*.php
nonsense resembles PHP 5.2
Also see Automattic's position on this.
Hello Viktor. Thanks for your suggestions. In fact, the structure of this plugin is mainly a structure I regularly use to create plugins. I know it is not perfect, but the main goal for me was:
I fully understand that the first reason for this will have to evolve (because some of my plugins are now on GitHub) and that a rule that applies to me alone can be totally invalid when several people collaborate on the same code.
Nevertheless, the second reason can't be erased (mainly because I want this plugin - like others - be available in the WordPress directory). Class file names (class-*.php
) and nested directories are (as far as I can remember) "mandatory". Let me read again these guidelines to see if it's true, or if my usage and my coding habits, have misled me...
All right, I am not the one to argue about it. Here are some class files with PSR-4 names: https://github.com/Pierre-Lannoy/wp-decalog/tree/master/includes/libraries/monolog these could easily be Composer autoloaded.
vendor/composer/*
files)You could also load our custom WPCS autoloader in Composer's autoload/files
Hello @szepeviktor ! I have turned in my head countless times your proposals. And they make total sense, and are in the direction of a qualitative gap in the code itself and in its maintenance. However, as long as WordPress does not have a libraries (and dependencies) manager, this can only lead to risks:
This issue will not be fixed or improved.
Thanks again for the suggestions.
Thank you Pierre for your lengthy response!
Meanwhile - in the 3 years of this issue - there is a result. Here is how to write modern plugins for WordPress: https://github.com/szepeviktor/small-project/blob/master/MAIN-FILE-PARTS.md 👀 some code is also include.
We could include Composer's autoloader AND put all of our classes in 1 directory. Now there are two orphans
Of course we still need our own autoloader as this project follows WPCS which - I think - will be deprecated as soon as core gets a namespace.