[wp-meta] [Making WordPress.org] #3692: Add CamelCase support from plugin names as per PSR-4 Autoloaders standard

Making WordPress.org noreply at wordpress.org
Thu Jun 28 14:11:01 UTC 2018


#3692: Add CamelCase support from plugin names as per PSR-4 Autoloaders standard
------------------------------+-------------------------------------
 Reporter:  KestutisIT        |      Owner:  (none)
     Type:  enhancement       |     Status:  new
 Priority:  high              |  Milestone:  Plugin Directory v3.0
Component:  Plugin Directory  |   Keywords:  has-patch needs-testing
------------------------------+-------------------------------------
 == PROLOG:
 WP Core team lead Dion (@dd32) showed me at WordCamp Europe 2018 via his
 laptop screen and send me via e-mail, and it appears I can see the code of
 "class-upload-handled.php" (at least today it is not [YET / ANYMORE]
 closed source)
 -
 https://meta.trac.wordpress.org/browser/sites/trunk/wordpress.org/public_html
 /wp-content/plugins/plugin-directory/shortcodes/class-upload-
 handler.php?marks=87-91#L84 ), while still I don't see a way that I could
 create a "pull request" like I do in GitHub to contribute code edits to
 that file directly, but after discussion with Ma.tt on WordCamp Europe
 2018 Conference Day 1, Matt advised that I still should create this
 ticket, to discuss this and may will get a priority to go into one of the
 upcoming updates to w.org plugin's directory.

 == GOAL & MOTIVATION:
 The goal is to add support for plugins that are created in S.O.L.I.D. MVC
 - way. They are based on cross-plaftorm / cross-CMS coding standards like
 PSR-2 and PSR-4 Autoloaders, which is actually not just PHP coding
 standard, but it is almost a full match to coding standards used by
 majority of JAVA & C# developers, that are fully object-oriented
 languages.
 S.O.L.I.D. MVC-based plugin use Camel-cased plugin folder names instead of
 lowercased & dash-separated plugin folder name, that is default.

 Last year I have successfully tested S.O.L.I.D. MVC plugin development in
 Vilnius University's (World's TOP 500 University) Master Degree's Software
 Engineering Field studies for "Software Architecture & Design Patterns"
 course, that was mostly in JAVA for last 8 years, and for last year it was
 in C#. And I was able to process this task via WordPress plugin in PHP
 language, as I was able to port C# OOP code straight to WordPress plugin
 with some small modification, as it was enough to follow the PSR coding
 standards and have a basic wrapper of main initializer controller for
 WordPress hooks and filters and class autoloader model.

 And that is not just that. Last month, I needed to update one of PHP-
 Fusion CMS Website's ReCaptcha and I just ditched the existing code and
 instead of that I just took my existing S.O.L.I.D. MVC plugin for
 ReCaptcha for WordPress and it WORKED AS WELL. And it took me to do this
 only one day. So as Ma.tt says that now everything is not just about
 WordPress, not even PHP - as Guttenberg goes beyond that and can be used
 pretty much in any CMS for PHP or EVEN ANY OTHER OOP CODING LANGUAGE (!).
 So this is a perfect model to convert other CMSes plugin developers, the
 C# and JAVA OOP developers to WordPress plugin developers without ANY NEED
 to learn any new coding standard - S.O.L.I.D. MVC is enough for that.

 But as everyone know from Jordan Belford's ("Wolf of Wall Street") book
 "The way of the wolf" we have 4 seconds to make our new developer to
 believe in WordPress and if we fail, it will take at least additional 8
 long meetings to make him believe. And if we have to start from the
 sentence that MVC / Camelcased namespaces will work everywhere in the
 plugin, but EXCEPT for the plugin folder, and you will have to use the
 HACK there, he get that 4 seconds negative impact, and that is enough for
 at least University Students to NOT choose to do their course task in
 WordPress plugin via S.O.L.I.D. MVC and they would rather go with C# and
 ASP.NET. And that is a lost believer of WordPress. So we need to fix that,
 and add a support for S.O.L.I.D. MVC in w.org plugins directory, or at
 least to add a check that it would not reset the plugin's folder name to
 dash-separated after update, as this is like a broken backbone of the
 skyscraper - S.O.L.I.D. MVC + Templates allows you to make plugins for
 WordPress (i.e. Booking), then each plugin may have different extensions
 (i.e. Hotel, Villa) and each extension can have dozens of themes that each
 can have a full visual overriding of the VIEW, as in S.O.L.I.D. MVC the
 visual part (HTML templates with .php extension, JavaScript files & all
 assets - Images, CSS files with CSS4 Variables, Icons) is fully separated
 from the plugin's logic (Models, Controllers & 3rd Party Libraries).

 Also even if you use a HACK this may look as resolvable with
 "/EnvatoTookit/" <=> "/envato-toolkit/" folder, but with "/SOLID_MVC/" it
 would get a tragic folder name of "/s-o-l-i-d---m-v-c/". And the
 S.O.L.I.D. MVC allows you to have a separate units tests with PHPUnit via
 "_Tests" plugin (to make the plugin lightweight and not to include the
 tests code into plugin's folder", so for "/SOLID_MVC_Tests/" the HACK code
 would loose it's head to "/s-o-l-i-d---m-v-c---tests/". While it should
 allow to have me "/solid-mvc/" and "/solid-mvc-tests/" URL's for the
 plugin in w.org, but allow me to download the plugins as "SOLID_MVC.zip"
 and "SOLID_MVC_Tests.zip", as well as with the first example
 "EnvatoToolkit.zip". And will keep that name for the folder name as well.
 The folder name can be taken from the ZIP's archive name, or via
 additional "Namespace" plugin header's META parameter.

 == CURRENT STATUS:
 Currently you can create a S.O.L.I.D. MVC plugin and publish in into web-
 app stores like Envato's CodeCanyon, or you can have it hosted on GitHub,
 but it gets issues if you want to host the plugin on W.org, which is a
 'default' repository. Additionally, even it the plugin got downloaded from
 other repository, that supports camelcased plugin names, and it has the
 update link in plugins META header to w.org, after you will click "Update
 the plugin" button, it will RESET the plugins folder name from i.e. "/wp-
 content/plugins/EnvatoToolkit/" to "/wp-content/plugins/envato-toolkit/"

 === THINGS THAT NEEDS TO GET DONE:
 1. Edit the code of "class-upload-handled.php" -
 https://meta.trac.wordpress.org/browser/sites/trunk/wordpress.org/public_html
 /wp-content/plugins/plugin-directory/shortcodes/class-upload-
 handler.php?marks=87-91#L84 )
 2. Add these 32 (if it is based on upload folder name) or 23 (if
 "Namespace" META header param would be allowed) additional lines of code
 to w.org plugins directory at the point where plugin name is assigned.
 * 32 lines version (based on uploaded plugin folder name):
 {{{#!php
 <?php
 // Retrieve uploaded plugin folder name
 $tmp_plugin_dir = "";
 foreach ( $plugin_files as $plugin_file ) {
         $plugin_data = get_plugin_data( $plugin_file, false, false ); //
 No markup/translation needed.
         if ( ! empty( $plugin_data['Name'] ) ) {
                 $tmp_plugin_dir = basename( $plugin_file )); // I.e.
 "EnvatoToolkit"
         }
 }

 // Determine the plugin slug based on the name of the plugin in the main
 plugin file.
 $this->plugin_slug = remove_accents( $this->plugin['Name'] );
 $this->plugin_slug = preg_replace( '/[^a-z0-9 _.-]/i', '',
 $this->plugin_slug );
 $this->plugin_slug = str_replace( '_', '-', $this->plugin_slug );
 // TODO: I have no idea why this function is used here if the three lines
 above already did the work
 $this->plugin_slug = sanitize_title_with_dashes( $this->plugin_slug );

 $this->plugin_folder_name = "";
 if (strtolower($tmp_plugin_dir) != $tmp_plugin_dir)
 {
         // --- Upper-case letters found in $tmp_plugin_dir ---
         // Determine the final plugin folder name based on the plugin
 folder name
         $this->plugin_folder_name = remove_accents( $tmp_plugin_dir );
         $this->plugin_folder_name = preg_replace( '/[^a-zA-Z0-9]/', '',
 $tmp_plugin_dir );
         // Upper-case the first letter
         $this->plugin_folder_name = ucfirst($this->plugin_folder_name);
 } else
 {
         // --- No upper-case letters found - use the existing way
         // Determine the final plugin folder name based on plugin slug
         $this->plugin_folder_name = $this->plugin_slug;
 }
 }}}
 * 23 lines version (based on "Namespace" META plugin header).
 {{{#!php
 <?php
 // Determine the plugin slug based on the name of the plugin in the main
 plugin file.
 $this->plugin_slug = remove_accents( $this->plugin['Name'] );
 $this->plugin_slug = preg_replace( '/[^a-z0-9 _.-]/i', '',
 $this->plugin_slug );
 $this->plugin_slug = str_replace( '_', '-', $this->plugin_slug );
 // TODO: I have no idea why this function is used here if the three lines
 above already did the work
 $this->plugin_slug = sanitize_title_with_dashes( $this->plugin_slug );

 $this->plugin_folder_name = "";
 if (strtolower($tmp_plugin_dir) != $tmp_plugin_dir)
 {
         // --- Upper-case letters found in $tmp_plugin_dir ---
         // Determine the final plugin folder name based on the plugin
 folder name
         $this->plugin_folder_name = remove_accents(
 $this->plugin['Namespace'] );
         $this->plugin_folder_name = preg_replace( '/[^a-zA-Z0-9]/', '',
 $this->plugin_folder_name );
         // Upper-case the first letter
         $this->plugin_folder_name = ucfirst($this->plugin_folder_name);
 } else
 {
         // --- No upper-case letters found - use the existing way
         // Determine the final plugin folder name based on plugin slug
         $this->plugin_folder_name = $this->plugin_slug;
 }

 }}}

 === NOTES:
 1. Dion (@dd32) said that this code depends on two plugin repositories:
 https://meta.trac.wordpress.org/browser/sites/trunk/wordpress.org/public_html
 /wp-content/plugins/plugin-directory
 https://meta.trac.wordpress.org/browser/sites/trunk/wordpress.org/public_html
 /wp-content/themes/pub/wporg-plugins

 2. Initial slug creation code:
 https://meta.trac.wordpress.org/browser/sites/trunk/wordpress.org/public_html
 /wp-content/plugins/plugin-directory/shortcodes/class-upload-
 handler.php?marks=87-91#L84

 3. I'm totally confused where to created ticket as in "**META TRAC**" I
 can select a component of "**PLUGIN DIRECTORY**", but there is also
 separate "**PLUGINS TRAC**" that looks like forgot-one as there are very
 few tickets in recent years:
 https://plugins.trac.wordpress.org/report/1?sort=created&asc=0&page=1

-- 
Ticket URL: <https://meta.trac.wordpress.org/ticket/3692>
Making WordPress.org <https://meta.trac.wordpress.org/>
Making WordPress.org


More information about the wp-meta mailing list