From 0c8c835592e5706330b0353e17d7b36d370d3b59 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Thu, 30 Aug 2018 16:38:12 +0100 Subject: [PATCH 1/9] Ignore sublime-project files --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index dfd6caa..29c40c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /vendor -composer.lock \ No newline at end of file +composer.lock +*.sublime-project +*.sublime-workspace From 27cdf774b5f3bc877181f787b75840c65d101233 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Thu, 30 Aug 2018 16:39:02 +0100 Subject: [PATCH 2/9] Add grumphp and set it to psr2 --- composer.json | 15 +++------------ grumphp.yml | 6 ++++++ phpcs.xml | 6 ++++++ 3 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 grumphp.yml create mode 100644 phpcs.xml diff --git a/composer.json b/composer.json index c1de9de..7dd5f77 100644 --- a/composer.json +++ b/composer.json @@ -4,8 +4,6 @@ "type": "wordpress-plugin", "license": "GPL-2.0", "require": { - "composer/installers": "^1.4", - "xrstf/composer-php52": "^1.0", "gamajo/template-loader": "^1.3" }, "autoload": { @@ -13,15 +11,8 @@ "includes" ] }, - "scripts": { - "post-install-cmd": [ - "xrstf\\Composer52\\Generator::onPostInstallCmd" - ], - "post-update-cmd": [ - "xrstf\\Composer52\\Generator::onPostInstallCmd" - ], - "post-autoload-dump": [ - "xrstf\\Composer52\\Generator::onPostInstallCmd" - ] + "require-dev": { + "phpro/grumphp": "^0.14.1", + "squizlabs/php_codesniffer": "^3.3" } } diff --git a/grumphp.yml b/grumphp.yml new file mode 100644 index 0000000..2b54adc --- /dev/null +++ b/grumphp.yml @@ -0,0 +1,6 @@ +parameters: + hide_circumvention_tip: true + ignore_unstaged_changes: true + tasks: + phpcs: + standard: "PSR2" diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..fb4d273 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,6 @@ + + + Override to always use PSR2 for this project. + + + From e98d222119032691da99689afbb72820aaaa3c9e Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Thu, 30 Aug 2018 16:39:16 +0100 Subject: [PATCH 3/9] Main file turned into PSR2 --- bootstrap.php | 19 +++++++++++++++++++ wp-plugin-base.php | 27 +++------------------------ 2 files changed, 22 insertions(+), 24 deletions(-) create mode 100644 bootstrap.php diff --git a/bootstrap.php b/bootstrap.php new file mode 100644 index 0000000..3aeb8d4 --- /dev/null +++ b/bootstrap.php @@ -0,0 +1,19 @@ +init(); +} diff --git a/wp-plugin-base.php b/wp-plugin-base.php index c77d5cb..34f3622 100644 --- a/wp-plugin-base.php +++ b/wp-plugin-base.php @@ -1,6 +1,4 @@ init(); -} +require_once 'bootstrap.php'; -add_action( 'plugins_loaded', __NAMESPACE__ . '\\load_plugin' ); +add_action('plugins_loaded', __NAMESPACE__ . '\\load_plugin'); From 6f537718799848eb9897e3db89302202e6e58351 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Thu, 30 Aug 2018 16:40:51 +0100 Subject: [PATCH 4/9] Make grumphp use phpcs.xml --- grumphp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grumphp.yml b/grumphp.yml index 2b54adc..e523a4c 100644 --- a/grumphp.yml +++ b/grumphp.yml @@ -3,4 +3,4 @@ parameters: ignore_unstaged_changes: true tasks: phpcs: - standard: "PSR2" + standard: null From 24129f636a593c03095e653f465ab921f8dfe552 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Thu, 30 Aug 2018 16:51:22 +0100 Subject: [PATCH 5/9] Rework files for PSR2 and PSR4 --- includes/class-cli.php => App/CLI.php | 18 +++--- App/Core.php | 43 ++++++++++++++ .../PluginFactory.php | 20 ++++--- App/TemplateLoader.php | 58 +++++++++++++++++++ bootstrap.php | 2 +- includes/class-core.php | 40 ------------- includes/class-template-loader.php | 57 ------------------ wp-plugin-base.php | 1 + 8 files changed, 121 insertions(+), 118 deletions(-) rename includes/class-cli.php => App/CLI.php (75%) create mode 100644 App/Core.php rename includes/class-wp-plugin-factory.php => App/PluginFactory.php (56%) create mode 100644 App/TemplateLoader.php delete mode 100644 includes/class-core.php delete mode 100644 includes/class-template-loader.php diff --git a/includes/class-cli.php b/App/CLI.php similarity index 75% rename from includes/class-cli.php rename to App/CLI.php index b14c7d7..559aa6e 100644 --- a/includes/class-cli.php +++ b/App/CLI.php @@ -1,13 +1,9 @@ + * @copyright Copyright (c) 2017 Mindsize + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2.0 + */ +class Core +{ + + /** + * Container for template loader instance. + */ + protected $template_loader; + + /** + * Constructor. + */ + public function init() + { + if (defined('WP_CLI') && WP_CLI && class_exists('WP_CLI_Command')) { + WP_CLI::add_command(WP_PLUGIN_BASE_SLUG, __NAMESPACE__ . '\\CLI'); + } + + $this->template_loader = new TemplateLoader(); + } + + /** + * Template loader + */ + public function templateLoader() + { + return $this->template_loader; + } +} diff --git a/includes/class-wp-plugin-factory.php b/App/PluginFactory.php similarity index 56% rename from includes/class-wp-plugin-factory.php rename to App/PluginFactory.php index 4c85a76..e584f6d 100644 --- a/includes/class-wp-plugin-factory.php +++ b/App/PluginFactory.php @@ -1,5 +1,5 @@ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2.0 */ -class WP_Plugin_Factory { - public static function create() { - static $plugin = null; +class PluginFactory +{ + public static function create() + { + static $plugin = null; - if ( null === $plugin ) { - $plugin = new Core(); - } + if (null === $plugin) { + $plugin = new Core(); + } - return $plugin; - } + return $plugin; + } } diff --git a/App/TemplateLoader.php b/App/TemplateLoader.php new file mode 100644 index 0000000..e763100 --- /dev/null +++ b/App/TemplateLoader.php @@ -0,0 +1,58 @@ + + * @copyright Copyright (c) 2017 Mindsize + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2.0 + */ +class TemplateLoader extends Gamajo_Template_Loader +{ + + /** + * Prefix for filter names. + * + * @since 1.0.0 + * + * @var string + */ + protected $filter_prefix = WP_PLUGIN_BASE_SLUG; + + /** + * Directory name where custom templates for this plugin should be found in the theme. + * + * @since 1.0.0 + * + * @var string + */ + protected $theme_template_directory = WP_PLUGIN_BASE_SLUG; + + /** + * Reference to the root directory path of this plugin. + * + * Can either be a defined constant, or a relative reference from where the subclass lives. + * + * @since 1.0.0 + * + * @var string + */ + protected $plugin_directory = WP_PLUGIN_BASE_DIR; + + /** + * Directory name where templates are found in this plugin. + * + * Can either be a defined constant, or a relative reference from where the subclass lives. + * + * e.g. 'templates' or 'includes/templates', etc. + * + * @since 1.1.0 + * + * @var string + */ + protected $plugin_template_directory = 'templates'; +} diff --git a/bootstrap.php b/bootstrap.php index 3aeb8d4..3da71d9 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -9,7 +9,7 @@ function wp_plugin_base() { - return WP_Plugin_Factory::create(); + return App/PluginFactory::create(); } function load_plugin() diff --git a/includes/class-core.php b/includes/class-core.php deleted file mode 100644 index 60cede2..0000000 --- a/includes/class-core.php +++ /dev/null @@ -1,40 +0,0 @@ - - * @copyright Copyright (c) 2017 Mindsize - * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2.0 - */ -class Core { - - /** - * Container for template loader instance. - */ - protected $template_loader; - - /** - * Constructor. - */ - public function init() { - if ( defined( 'WP_CLI' ) && WP_CLI ) { - WP_CLI::add_command( WP_PLUGIN_BASE_SLUG, __NAMESPACE__ . '\\CLI' ); - } - - $this->template_loader = new Template_Loader(); - } - - /** - * Template loader - */ - public function template_loader() { - return $this->template_loader; - } -} diff --git a/includes/class-template-loader.php b/includes/class-template-loader.php deleted file mode 100644 index f34547c..0000000 --- a/includes/class-template-loader.php +++ /dev/null @@ -1,57 +0,0 @@ - - * @copyright Copyright (c) 2017 Mindsize - * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2.0 - */ -class Template_Loader extends Gamajo_Template_Loader { - - /** - * Prefix for filter names. - * - * @since 1.0.0 - * - * @var string - */ - protected $filter_prefix = WP_PLUGIN_BASE_SLUG; - - /** - * Directory name where custom templates for this plugin should be found in the theme. - * - * @since 1.0.0 - * - * @var string - */ - protected $theme_template_directory = WP_PLUGIN_BASE_SLUG; - - /** - * Reference to the root directory path of this plugin. - * - * Can either be a defined constant, or a relative reference from where the subclass lives. - * - * @since 1.0.0 - * - * @var string - */ - protected $plugin_directory = WP_PLUGIN_BASE_DIR; - - /** - * Directory name where templates are found in this plugin. - * - * Can either be a defined constant, or a relative reference from where the subclass lives. - * - * e.g. 'templates' or 'includes/templates', etc. - * - * @since 1.1.0 - * - * @var string - */ - protected $plugin_template_directory = 'templates'; -} diff --git a/wp-plugin-base.php b/wp-plugin-base.php index 34f3622..de90afa 100644 --- a/wp-plugin-base.php +++ b/wp-plugin-base.php @@ -11,6 +11,7 @@ namespace Mindsize\WP_Plugin_Base; +require_once 'vendor/autoloader.php'; require_once 'bootstrap.php'; add_action('plugins_loaded', __NAMESPACE__ . '\\load_plugin'); From 99609affaabae91aec5f98063cf7a64075fbdf95 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Thu, 30 Aug 2018 17:06:03 +0100 Subject: [PATCH 6/9] Rename folders / files / namespaces --- README.md | 4 ++-- bootstrap.php | 4 ++-- {App => includes}/CLI.php | 2 +- {App => includes}/Core.php | 2 +- {App => includes}/PluginFactory.php | 2 +- {App => includes}/TemplateLoader.php | 2 +- wp-plugin-base.php | 8 ++++---- 7 files changed, 12 insertions(+), 12 deletions(-) rename {App => includes}/CLI.php (94%) rename {App => includes}/Core.php (95%) rename {App => includes}/PluginFactory.php (93%) rename {App => includes}/TemplateLoader.php (97%) diff --git a/README.md b/README.md index f62b7f7..ce6f606 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ composer create-project mindsize/wp-plugin-base my-new-plugin | Find | Replace | Why | | :---: | :---: | :--- | -| `Mindsize\WP_Plugin_Base` | `Mindsize\Your_Plugin` | Update the plugin namespace. | +| `Mindsize\HerpADerp` | `Mindsize\Your_Plugin` | Update the plugin namespace. | | `WP_PLUGIN_BASE_` | `YOUR_PLUGIN_` | Update the plugin constants. | | `wp_plugin_base` | `your_plugin` | Update the plugin wrapper function. | @@ -48,4 +48,4 @@ After cloning this repository, run `composer install` in the root directory of t ### From Packaged Releases on WordPress.org -Packaged releases on WordPress.org will automatically include the required autoloaders. \ No newline at end of file +Packaged releases on WordPress.org will automatically include the required autoloaders. diff --git a/bootstrap.php b/bootstrap.php index 3da71d9..1c20eb3 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -1,5 +1,5 @@ Date: Thu, 30 Aug 2018 17:14:07 +0100 Subject: [PATCH 7/9] Un-rename namespace --- README.md | 2 +- bootstrap.php | 2 +- includes/CLI.php | 2 +- includes/Core.php | 2 +- includes/PluginFactory.php | 2 +- includes/TemplateLoader.php | 2 +- wp-plugin-base.php | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ce6f606..b6bb9d0 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ composer create-project mindsize/wp-plugin-base my-new-plugin | Find | Replace | Why | | :---: | :---: | :--- | -| `Mindsize\HerpADerp` | `Mindsize\Your_Plugin` | Update the plugin namespace. | +| `Mindsize\WP_Plugin_Base` | `Mindsize\Your_Plugin` | Update the plugin namespace. | | `WP_PLUGIN_BASE_` | `YOUR_PLUGIN_` | Update the plugin constants. | | `wp_plugin_base` | `your_plugin` | Update the plugin wrapper function. | diff --git a/bootstrap.php b/bootstrap.php index 1c20eb3..9667196 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -1,5 +1,5 @@ Date: Thu, 30 Aug 2018 17:48:12 +0100 Subject: [PATCH 8/9] Rename phpcs.xml file and add non-dist to gitignore --- .gitignore | 8 +++++--- phpcs.xml => phpcs.xml.dist | 0 2 files changed, 5 insertions(+), 3 deletions(-) rename phpcs.xml => phpcs.xml.dist (100%) diff --git a/.gitignore b/.gitignore index 29c40c5..6cf07ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ /vendor -composer.lock -*.sublime-project -*.sublime-workspace +/composer.lock +/*.sublime-project +/*.sublime-workspace +/.phpcs.xml +/phpcs.xml diff --git a/phpcs.xml b/phpcs.xml.dist similarity index 100% rename from phpcs.xml rename to phpcs.xml.dist From 5458b1032af87f0086c214020f3548db56acd304 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Thu, 30 Aug 2018 20:26:08 +0100 Subject: [PATCH 9/9] Undo plugin name / description rename --- wp-plugin-base.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wp-plugin-base.php b/wp-plugin-base.php index 141de9e..70a45bc 100644 --- a/wp-plugin-base.php +++ b/wp-plugin-base.php @@ -1,7 +1,7 @@