mirror of
https://github.com/inretio/WordPress-Plugin-Boilerplate
synced 2025-04-19 05:35:36 +03:00
Remove .org parent folder structure
Flattening the folder structure for a bit easier auto-inclusion into projects and local development. See: https://github.com/DevinVinson/WordPress-Plugin-Boilerplate/issues/295
This commit is contained in:
parent
3d3f181924
commit
5391e0ca27
27 changed files with 8 additions and 51 deletions
36
plugin-name/includes/class-plugin-name-activator.php
Normal file
36
plugin-name/includes/class-plugin-name-activator.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Fired during plugin activation
|
||||
*
|
||||
* @link http://example.com
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Plugin_Name
|
||||
* @subpackage Plugin_Name/includes
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fired during plugin activation.
|
||||
*
|
||||
* This class defines all code necessary to run during the plugin's activation.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @package Plugin_Name
|
||||
* @subpackage Plugin_Name/includes
|
||||
* @author Your Name <email@example.com>
|
||||
*/
|
||||
class Plugin_Name_Activator {
|
||||
|
||||
/**
|
||||
* Short Description. (use period)
|
||||
*
|
||||
* Long Description.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function activate() {
|
||||
|
||||
}
|
||||
|
||||
}
|
36
plugin-name/includes/class-plugin-name-deactivator.php
Normal file
36
plugin-name/includes/class-plugin-name-deactivator.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Fired during plugin deactivation
|
||||
*
|
||||
* @link http://example.com
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Plugin_Name
|
||||
* @subpackage Plugin_Name/includes
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fired during plugin deactivation.
|
||||
*
|
||||
* This class defines all code necessary to run during the plugin's deactivation.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @package Plugin_Name
|
||||
* @subpackage Plugin_Name/includes
|
||||
* @author Your Name <email@example.com>
|
||||
*/
|
||||
class Plugin_Name_Deactivator {
|
||||
|
||||
/**
|
||||
* Short Description. (use period)
|
||||
*
|
||||
* Long Description.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function deactivate() {
|
||||
|
||||
}
|
||||
|
||||
}
|
63
plugin-name/includes/class-plugin-name-i18n.php
Normal file
63
plugin-name/includes/class-plugin-name-i18n.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Define the internationalization functionality
|
||||
*
|
||||
* Loads and defines the internationalization files for this plugin
|
||||
* so that it is ready for translation.
|
||||
*
|
||||
* @link http://example.com
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Plugin_Name
|
||||
* @subpackage Plugin_Name/includes
|
||||
*/
|
||||
|
||||
/**
|
||||
* Define the internationalization functionality.
|
||||
*
|
||||
* Loads and defines the internationalization files for this plugin
|
||||
* so that it is ready for translation.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @package Plugin_Name
|
||||
* @subpackage Plugin_Name/includes
|
||||
* @author Your Name <email@example.com>
|
||||
*/
|
||||
class Plugin_Name_i18n {
|
||||
|
||||
/**
|
||||
* The domain specified for this plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
* @var string $domain The domain identifier for this plugin.
|
||||
*/
|
||||
private $domain;
|
||||
|
||||
/**
|
||||
* Load the plugin text domain for translation.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function load_plugin_textdomain() {
|
||||
|
||||
load_plugin_textdomain(
|
||||
$this->domain,
|
||||
false,
|
||||
dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the domain equal to that of the specified domain.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @param string $domain The domain that represents the locale of this plugin.
|
||||
*/
|
||||
public function set_domain( $domain ) {
|
||||
$this->domain = $domain;
|
||||
}
|
||||
|
||||
}
|
129
plugin-name/includes/class-plugin-name-loader.php
Normal file
129
plugin-name/includes/class-plugin-name-loader.php
Normal file
|
@ -0,0 +1,129 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Register all actions and filters for the plugin
|
||||
*
|
||||
* @link http://example.com
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Plugin_Name
|
||||
* @subpackage Plugin_Name/includes
|
||||
*/
|
||||
|
||||
/**
|
||||
* Register all actions and filters for the plugin.
|
||||
*
|
||||
* Maintain a list of all hooks that are registered throughout
|
||||
* the plugin, and register them with the WordPress API. Call the
|
||||
* run function to execute the list of actions and filters.
|
||||
*
|
||||
* @package Plugin_Name
|
||||
* @subpackage Plugin_Name/includes
|
||||
* @author Your Name <email@example.com>
|
||||
*/
|
||||
class Plugin_Name_Loader {
|
||||
|
||||
/**
|
||||
* The array of actions registered with WordPress.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
* @var array $actions The actions registered with WordPress to fire when the plugin loads.
|
||||
*/
|
||||
protected $actions;
|
||||
|
||||
/**
|
||||
* The array of filters registered with WordPress.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
* @var array $filters The filters registered with WordPress to fire when the plugin loads.
|
||||
*/
|
||||
protected $filters;
|
||||
|
||||
/**
|
||||
* Initialize the collections used to maintain the actions and filters.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->actions = array();
|
||||
$this->filters = array();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new action to the collection to be registered with WordPress.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @param string $hook The name of the WordPress action that is being registered.
|
||||
* @param object $component A reference to the instance of the object on which the action is defined.
|
||||
* @param string $callback The name of the function definition on the $component.
|
||||
* @param int Optional $priority The priority at which the function should be fired.
|
||||
* @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
|
||||
*/
|
||||
public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
|
||||
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new filter to the collection to be registered with WordPress.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @param string $hook The name of the WordPress filter that is being registered.
|
||||
* @param object $component A reference to the instance of the object on which the filter is defined.
|
||||
* @param string $callback The name of the function definition on the $component.
|
||||
* @param int Optional $priority The priority at which the function should be fired.
|
||||
* @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
|
||||
*/
|
||||
public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
|
||||
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* A utility function that is used to register the actions and hooks into a single
|
||||
* collection.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
* @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
|
||||
* @param string $hook The name of the WordPress filter that is being registered.
|
||||
* @param object $component A reference to the instance of the object on which the filter is defined.
|
||||
* @param string $callback The name of the function definition on the $component.
|
||||
* @param int Optional $priority The priority at which the function should be fired.
|
||||
* @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
|
||||
* @return type The collection of actions and filters registered with WordPress.
|
||||
*/
|
||||
private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
|
||||
|
||||
$hooks[] = array(
|
||||
'hook' => $hook,
|
||||
'component' => $component,
|
||||
'callback' => $callback,
|
||||
'priority' => $priority,
|
||||
'accepted_args' => $accepted_args
|
||||
);
|
||||
|
||||
return $hooks;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the filters and actions with WordPress.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function run() {
|
||||
|
||||
foreach ( $this->filters as $hook ) {
|
||||
add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
|
||||
}
|
||||
|
||||
foreach ( $this->actions as $hook ) {
|
||||
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
216
plugin-name/includes/class-plugin-name.php
Normal file
216
plugin-name/includes/class-plugin-name.php
Normal file
|
@ -0,0 +1,216 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The file that defines the core plugin class
|
||||
*
|
||||
* A class definition that includes attributes and functions used across both the
|
||||
* public-facing side of the site and the admin area.
|
||||
*
|
||||
* @link http://example.com
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Plugin_Name
|
||||
* @subpackage Plugin_Name/includes
|
||||
*/
|
||||
|
||||
/**
|
||||
* The core plugin class.
|
||||
*
|
||||
* This is used to define internationalization, admin-specific hooks, and
|
||||
* public-facing site hooks.
|
||||
*
|
||||
* Also maintains the unique identifier of this plugin as well as the current
|
||||
* version of the plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @package Plugin_Name
|
||||
* @subpackage Plugin_Name/includes
|
||||
* @author Your Name <email@example.com>
|
||||
*/
|
||||
class Plugin_Name {
|
||||
|
||||
/**
|
||||
* The loader that's responsible for maintaining and registering all hooks that power
|
||||
* the plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
* @var Plugin_Name_Loader $loader Maintains and registers all hooks for the plugin.
|
||||
*/
|
||||
protected $loader;
|
||||
|
||||
/**
|
||||
* The unique identifier of this plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
* @var string $plugin_name The string used to uniquely identify this plugin.
|
||||
*/
|
||||
protected $plugin_name;
|
||||
|
||||
/**
|
||||
* The current version of the plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
* @var string $version The current version of the plugin.
|
||||
*/
|
||||
protected $version;
|
||||
|
||||
/**
|
||||
* Define the core functionality of the plugin.
|
||||
*
|
||||
* Set the plugin name and the plugin version that can be used throughout the plugin.
|
||||
* Load the dependencies, define the locale, and set the hooks for the admin area and
|
||||
* the public-facing side of the site.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->plugin_name = 'plugin-name';
|
||||
$this->version = '1.0.0';
|
||||
|
||||
$this->load_dependencies();
|
||||
$this->set_locale();
|
||||
$this->define_admin_hooks();
|
||||
$this->define_public_hooks();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the required dependencies for this plugin.
|
||||
*
|
||||
* Include the following files that make up the plugin:
|
||||
*
|
||||
* - Plugin_Name_Loader. Orchestrates the hooks of the plugin.
|
||||
* - Plugin_Name_i18n. Defines internationalization functionality.
|
||||
* - Plugin_Name_Admin. Defines all hooks for the admin area.
|
||||
* - Plugin_Name_Public. Defines all hooks for the public side of the site.
|
||||
*
|
||||
* Create an instance of the loader which will be used to register the hooks
|
||||
* with WordPress.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*/
|
||||
private function load_dependencies() {
|
||||
|
||||
/**
|
||||
* The class responsible for orchestrating the actions and filters of the
|
||||
* core plugin.
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-plugin-name-loader.php';
|
||||
|
||||
/**
|
||||
* The class responsible for defining internationalization functionality
|
||||
* of the plugin.
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-plugin-name-i18n.php';
|
||||
|
||||
/**
|
||||
* The class responsible for defining all actions that occur in the admin area.
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-plugin-name-admin.php';
|
||||
|
||||
/**
|
||||
* The class responsible for defining all actions that occur in the public-facing
|
||||
* side of the site.
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-plugin-name-public.php';
|
||||
|
||||
$this->loader = new Plugin_Name_Loader();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the locale for this plugin for internationalization.
|
||||
*
|
||||
* Uses the Plugin_Name_i18n class in order to set the domain and to register the hook
|
||||
* with WordPress.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*/
|
||||
private function set_locale() {
|
||||
|
||||
$plugin_i18n = new Plugin_Name_i18n();
|
||||
$plugin_i18n->set_domain( $this->get_plugin_name() );
|
||||
|
||||
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all of the hooks related to the admin area functionality
|
||||
* of the plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*/
|
||||
private function define_admin_hooks() {
|
||||
|
||||
$plugin_admin = new Plugin_Name_Admin( $this->get_plugin_name(), $this->get_version() );
|
||||
|
||||
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
|
||||
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all of the hooks related to the public-facing functionality
|
||||
* of the plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*/
|
||||
private function define_public_hooks() {
|
||||
|
||||
$plugin_public = new Plugin_Name_Public( $this->get_plugin_name(), $this->get_version() );
|
||||
|
||||
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
|
||||
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the loader to execute all of the hooks with WordPress.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function run() {
|
||||
$this->loader->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the plugin used to uniquely identify it within the context of
|
||||
* WordPress and to define internationalization functionality.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return string The name of the plugin.
|
||||
*/
|
||||
public function get_plugin_name() {
|
||||
return $this->plugin_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The reference to the class that orchestrates the hooks with the plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return Plugin_Name_Loader Orchestrates the hooks of the plugin.
|
||||
*/
|
||||
public function get_loader() {
|
||||
return $this->loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the version number of the plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return string The version number of the plugin.
|
||||
*/
|
||||
public function get_version() {
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
}
|
1
plugin-name/includes/index.php
Normal file
1
plugin-name/includes/index.php
Normal file
|
@ -0,0 +1 @@
|
|||
<?php // Silence is golden
|
Loading…
Add table
Add a link
Reference in a new issue