Skip to content

Commit

Permalink
PSR-4 fixes: rename files, classes, & namespacing
Browse files Browse the repository at this point in the history
avoid deprecation notices when generating autoloader, as of Composer 1.10.0
  • Loading branch information
cliffordp committed Mar 24, 2020
1 parent 6c920e4 commit 6ff4438
Show file tree
Hide file tree
Showing 36 changed files with 145 additions and 144 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The Boilerplate can be installed directly into your plugins folder "as-is". You
1. Find the text `cliff-wp-plugin-boilerplate` and replace with `your-plugin-name` in all files
1. Find the text `wp_plugin_name` and replace with `your_plugin_name` in all files
1. Find the text `WordPress Plugin Boilerplate` and replace with `Your Plugin Name` in all files
1. Find the text `WP_Plugin_Name` and replace with `Your_Plugin_Name` in all files (the *namespace*)
1. Find the text `WpPluginName` and replace with `YourPluginName` in all files (the *namespace*)
1. Rename the `pot` file under `languages` and replace the string `cliff-wp-plugin-boilerplate` with `your-plugin-name`
1. Find the text `https://www.example.com/` and replace with your URI in all files
1. Find the text `Your Name or Your Company` and replace with your name in all files
Expand Down
6 changes: 3 additions & 3 deletions cliff-wp-plugin-boilerplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* https://github.com/cliffordp/cliff-wp-plugin-boilerplate#plugin-structure
* Introduction to the structure of this plugin's files:
*
* cliff-wp-plugin-boilerplate/src/class-Plugin_Data.php - hard-coded information about the plugin, such as plugin-slug and plugin_slug.
* cliff-wp-plugin-boilerplate/src/class-PluginData.php - hard-coded information about the plugin, such as plugin-slug and plugin_slug.
* cliff-wp-plugin-boilerplate/src/class-Bootstrap.php - gets the plugin going, including setting required/recommended plugin dependencies
*
* cliff-wp-plugin-boilerplate/src/Frontend - public-facing functionality
Expand All @@ -22,7 +22,7 @@
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @package WP_Plugin_Name
* @package WpPluginName
*
* @wordpress-plugin
* Plugin Name: WordPress Plugin Boilerplate
Expand Down Expand Up @@ -55,7 +55,7 @@
* You are invited to use it for your own WordPress projects.
*/

namespace WP_Plugin_Name;
namespace WpPluginName;

// Abort if this file is called directly.
if ( ! defined( 'ABSPATH' ) ) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"autoload": {
"psr-4": {
"WP_Plugin_Name\\": "src/"
"WpPluginName\\": "src/"
}
},
"config": {
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Stable tag: 1.0.0
License: GPL version 3 or any later version
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Here is a short description of the plugin. This should be no more than 150 characters. No markup here.
Here is a short description of the plugin's purpose & functionality. It should be no more than 150 characters or fewer. No markup is allowed in here.

== Description ==

Expand Down
6 changes: 3 additions & 3 deletions src/Admin/class-Assets.php → src/Admin/Assets.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace WP_Plugin_Name\Admin;
namespace WpPluginName\Admin;

use WP_Plugin_Name\Common\Assets as Common_Assets;
use WP_Plugin_Name\Plugin_Data as Plugin_Data;
use WpPluginName\Common\Assets as Common_Assets;
use WpPluginName\PluginData as PluginData;

// Abort if this file is called directly.
if ( ! defined( 'ABSPATH' ) ) {
Expand Down
40 changes: 20 additions & 20 deletions src/Admin/Settings/class-Main.php → src/Admin/Settings/Main.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace WP_Plugin_Name\Admin\Settings;
namespace WpPluginName\Admin\Settings;

use WP_Plugin_Name\Common\Settings\Choices;
use WP_Plugin_Name\Plugin_Data as Plugin_Data;
use WP_Plugin_Name\Common\Common as Common;
use WP_Plugin_Name\Common\Settings\Main as Common_Settings;
use WpPluginName\Common\Settings\Choices;
use WpPluginName\PluginData as PluginData;
use WpPluginName\Common\Common as Common;
use WpPluginName\Common\Settings\Main as Common_Settings;
use WP_Screen;

// Abort if this file is called directly.
Expand Down Expand Up @@ -67,8 +67,8 @@ public function customize_action_links( array $links ): array {
*/
public function add_plugin_admin_menu(): void {
$hook_suffix = add_options_page(
Plugin_Data::get_plugin_display_name(),
Plugin_Data::get_plugin_display_name(),
PluginData::get_plugin_display_name(),
PluginData::get_plugin_display_name(),
$this->common->required_capability(),
$this->settings->get_settings_page_slug(),
[ $this, 'settings_page' ]
Expand All @@ -86,49 +86,49 @@ public function add_plugin_admin_menu(): void {
public function enqueue_settings_page_assets() {
// CSS for our Settings Page.
wp_enqueue_style(
Plugin_Data::get_asset_handle( 'admin-settings' ),
Plugin_Data::get_assets_url_base() . 'admin-settings.css',
PluginData::get_asset_handle( 'admin-settings' ),
PluginData::get_assets_url_base() . 'admin-settings.css',
[
'wp-components',
],
Plugin_Data::plugin_version(),
PluginData::plugin_version(),
'all'
);

// JS for our Settings Page.
wp_enqueue_script(
Plugin_Data::get_asset_handle( 'admin-settings' ),
Plugin_Data::get_assets_url_base() . 'admin-settings.js',
PluginData::get_asset_handle( 'admin-settings' ),
PluginData::get_assets_url_base() . 'admin-settings.js',
[
'wp-api',
'wp-i18n',
'wp-components',
'wp-element',
],
Plugin_Data::plugin_version(),
PluginData::plugin_version(),
true
);

$choices = new Choices();

wp_localize_script(
Plugin_Data::get_asset_handle( 'admin-settings' ),
PluginData::get_asset_handle( 'admin-settings' ),
'settingsData', // Only loads when on the page so shouldn't be a conflicting name.
[
// The CSS ID into which our React app inserts its content.
'entryId' => Plugin_Data::plugin_text_domain(),
'entryId' => PluginData::plugin_text_domain(),
// Helpful for things like generating the <h1>.
'pluginInfo' => [
'name' => Plugin_Data::get_plugin_display_name(),
'version' => Plugin_Data::plugin_version(),
'name' => PluginData::get_plugin_display_name(),
'version' => PluginData::plugin_version(),
],
// The root location where we store images specific to the Admin area.
'imagesBaseUrl' => Plugin_Data::plugin_dir_url() . 'src/Admin/images/',
'imagesBaseUrl' => PluginData::plugin_dir_url() . 'src/Admin/images/',
'optionsInfo' => [
/**
* The option prefix, in case we want to do any filtering for just our stuff.
*
* @see \WP_Plugin_Name\Common\Settings\Main::get_option_prefix()
* @see \WpPluginName\Common\Settings\Main::get_option_prefix()
*/
'prefix' => $this->settings->get_option_prefix(),
// The list of each of our option names, regardless of 'show_in_rest'.
Expand Down Expand Up @@ -184,7 +184,7 @@ public function settings_page(): void {

printf(
'<div class="wrap" id="%s"></div>',
Plugin_Data::plugin_text_domain()
PluginData::plugin_text_domain()
);
}

Expand Down
34 changes: 17 additions & 17 deletions src/class-Bootstrap.php → src/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace WP_Plugin_Name;
namespace WpPluginName;

// Abort if this file is called directly.
use WP_Plugin_Name\Core as Core;
use WpPluginName\Core as Core;

if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand Down Expand Up @@ -67,7 +67,7 @@ class Bootstrap {
'external_url' => 'https://toolset.com/?aid=5336&affiliate_key=Lsvk04DjJOhq',
'version' => '2.8.0.1',
],
[
/*[
'name' => 'WooCommerce',
'slug' => 'woocommerce',
'source' => 'repo',
Expand All @@ -81,7 +81,7 @@ class Bootstrap {
'required' => true,
'external_url' => 'https://woocommerce.com/products/woocommerce-bookings/?aff=11845',
'version' => '1.14.0',
],
],*/
];

/**
Expand Down Expand Up @@ -126,7 +126,7 @@ public function tgmpa_register_required_plugins(): void {
* Array of configuration settings. Amend each line as needed.
*/
$config = [
'id' => Plugin_Data::plugin_text_domain(), // Unique ID for hashing notices for multiple instances of TGMPA.
'id' => PluginData::plugin_text_domain(), // Unique ID for hashing notices for multiple instances of TGMPA.
'parent_slug' => 'plugins.php', // Parent menu slug.
'capability' => 'activate_plugins', // Capability needed to view plugin install page, should be a capability associated with the parent menu used.
'has_notices' => true, // Show admin notices or not.
Expand All @@ -137,20 +137,20 @@ public function tgmpa_register_required_plugins(): void {
'strings' => [
'notice_can_install_required' => _n_noop(
// translators: 1: plugin name(s).
Plugin_Data::get_plugin_display_name() . ' requires the following plugin: %1$s.',
Plugin_Data::get_plugin_display_name() . ' requires the following plugins: %1$s.',
PluginData::get_plugin_display_name() . ' requires the following plugin: %1$s.',
PluginData::get_plugin_display_name() . ' requires the following plugins: %1$s.',
'cliff-wp-plugin-boilerplate'
),
'notice_can_install_recommended' => _n_noop(
// translators: 1: plugin name(s).
Plugin_Data::get_plugin_display_name() . ' recommends the following plugin: %1$s.',
Plugin_Data::get_plugin_display_name() . ' recommends the following plugins: %1$s.',
PluginData::get_plugin_display_name() . ' recommends the following plugin: %1$s.',
PluginData::get_plugin_display_name() . ' recommends the following plugins: %1$s.',
'cliff-wp-plugin-boilerplate'
),
'notice_ask_to_update' => _n_noop(
// translators: 1: plugin name(s).
'The following plugin needs to be updated to its latest version to ensure maximum compatibility with ' . Plugin_Data::get_plugin_display_name() . ': %1$s.',
'The following plugins need to be updated to their latest version to ensure maximum compatibility with ' . Plugin_Data::get_plugin_display_name() . ': %1$s.',
'The following plugin needs to be updated to its latest version to ensure maximum compatibility with ' . PluginData::get_plugin_display_name() . ': %1$s.',
'The following plugins need to be updated to their latest version to ensure maximum compatibility with ' . PluginData::get_plugin_display_name() . ': %1$s.',
'cliff-wp-plugin-boilerplate'
),
// translators: 1: plugin name
Expand All @@ -174,8 +174,8 @@ public function notice_old_php_version(): void {
$message = sprintf(
// translators: 1: plugin display name, 2: required minimum PHP version, 3: current PHP version, help link
__( '%1$s requires at least PHP version %2$s in order to work. You have version %3$s. Please see %4$s for more information.', 'cliff-wp-plugin-boilerplate' ),
'<strong>' . Plugin_Data::get_plugin_display_name() . '</strong>',
'<strong>' . Plugin_Data::required_min_php_version() . '</strong>',
'<strong>' . PluginData::get_plugin_display_name() . '</strong>',
'<strong>' . PluginData::required_min_php_version() . '</strong>',
'<strong>' . PHP_VERSION . '</strong>',
$help_link
);
Expand All @@ -190,7 +190,7 @@ public function notice_old_php_version(): void {
* @param string $type
*/
public function do_admin_notice( string $message, string $type = 'error' ): void {
$class = sprintf( '%s %s', $type, sanitize_html_class( Plugin_Data::plugin_text_domain() ) );
$class = sprintf( '%s %s', $type, sanitize_html_class( PluginData::plugin_text_domain() ) );

printf( '<div class="%s"><p>%s</p></div>', $class, $message );
}
Expand Down Expand Up @@ -250,7 +250,7 @@ public function notice_missing_required_theme(): void {
$message = sprintf(
// translators: 1: plugin display name, 2: parent theme name, 3: child theme name message, 4: wp-admin link to themes, if applicable
__( 'The %1$s plugin requires the %2$s parent theme%3$sin order to work.%4$s', 'cliff-wp-plugin-boilerplate' ),
'<strong>' . Plugin_Data::get_plugin_display_name() . '</strong>',
'<strong>' . PluginData::get_plugin_display_name() . '</strong>',
'<strong>' . $parent_name . '</strong>',
$child_message,
$admin_link
Expand All @@ -267,7 +267,7 @@ public function notice_missing_required_theme(): void {
public function is_ready(): bool {
$success = true;

if ( version_compare( PHP_VERSION, Plugin_Data::required_min_php_version(), '<' ) ) {
if ( version_compare( PHP_VERSION, PluginData::required_min_php_version(), '<' ) ) {
add_action( 'admin_notices', [ $this, 'notice_old_php_version' ] );
$success = false;
}
Expand Down Expand Up @@ -338,7 +338,7 @@ private function required_plugins_are_active(): bool {
continue;
}

$plugin_data = get_plugin_data( Plugin_Data::all_plugins_dir() . $basename );
$plugin_data = get_plugin_data( PluginData::all_plugins_dir() . $basename );

if (
empty( $plugin_data['Version'] )
Expand Down
14 changes: 7 additions & 7 deletions src/Common/class-Assets.php → src/Common/Assets.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace WP_Plugin_Name\Common;
namespace WpPluginName\Common;

use WP_Plugin_Name\Common\Utilities\Strings as Strings;
use WP_Plugin_Name\Plugin_Data as Plugin_Data;
use WpPluginName\Common\Utilities\Strings as Strings;
use WpPluginName\PluginData as PluginData;

// Abort if this file is called directly.
if ( ! defined( 'ABSPATH' ) ) {
Expand Down Expand Up @@ -31,7 +31,7 @@ public function __construct() {
* @return string
*/
public static function get_assets_url_base(): string {
return Plugin_Data::plugin_dir_url() . 'dist/';
return PluginData::plugin_dir_url() . 'dist/';
}

/**
Expand All @@ -40,7 +40,7 @@ public static function get_assets_url_base(): string {
* @return string
*/
public static function get_assets_path_base(): string {
return Plugin_Data::plugin_dir_path() . 'dist/';
return PluginData::plugin_dir_path() . 'dist/';
}

/**
Expand All @@ -54,7 +54,7 @@ public static function get_assets_path_base(): string {
* @return string
*/
public static function get_asset_handle( string $handle ): string {
return Plugin_Data::plugin_text_domain() . '-' . $handle;
return PluginData::plugin_text_domain() . '-' . $handle;
}

/**
Expand Down Expand Up @@ -207,7 +207,7 @@ private function get_version( string $version = '' ) {
$v = $version;
} else {
// Plugin's version.
$v = Plugin_Data::plugin_version();
$v = PluginData::plugin_version();
}

return (string) $v;
Expand Down
8 changes: 4 additions & 4 deletions src/Common/class-Common.php → src/Common/Common.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace WP_Plugin_Name\Common;
namespace WpPluginName\Common;

use WP_Plugin_Name\Plugin_Data as Plugin_Data;
use WpPluginName\PluginData as PluginData;

// Abort if this file is called directly.
if ( ! defined( 'ABSPATH' ) ) {
Expand Down Expand Up @@ -79,7 +79,7 @@ private function is_rest_api_request() {
* @return string
*/
public function required_capability(): string {
return apply_filters( Plugin_Data::plugin_text_domain_underscores() . '_required_capability', 'customize' );
return apply_filters( PluginData::plugin_text_domain_underscores() . '_required_capability', 'customize' );
}

/**
Expand All @@ -90,7 +90,7 @@ public function required_capability(): string {
* @return string
*/
public function get_wrapper_class(): string {
$class = Plugin_Data::plugin_text_domain_underscores() . '-wrapper';
$class = PluginData::plugin_text_domain_underscores() . '-wrapper';

return esc_attr( $class );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace WP_Plugin_Name\Common\Settings;
namespace WpPluginName\Common\Settings;

use WP_Plugin_Name\Common\Utilities as Utils;
use WpPluginName\Common\Utilities as Utils;

// Abort if this file is called directly.
if ( ! defined( 'ABSPATH' ) ) {
Expand Down
Loading

0 comments on commit 6ff4438

Please sign in to comment.