mirror of
https://github.com/inretio/WordPress-Plugin-Boilerplate
synced 2024-05-19 11:42:09 +03:00
Compare commits
76 commits
Author | SHA1 | Date | |
---|---|---|---|
Gytis Repečka | a57e6e7460 | ||
a8291082b5 | |||
d2f6b21b80 | |||
f142df8c45 | |||
611c80cce1 | |||
60940a9761 | |||
b02101400e | |||
bc3e07be2a | |||
95844fec48 | |||
696db21ed7 | |||
7af6de6dd2 | |||
04f90ff5ff | |||
1f36abcedd | |||
65a87940e9 | |||
1f3c2acbe2 | |||
77baf0b2f5 | |||
19809447ec | |||
872c67477a | |||
5af56b19a5 | |||
ded444099b | |||
c719bf9fc7 | |||
923fbaf0c8 | |||
0c099e4208 | |||
579fb9823a | |||
39cb7ccfb3 | |||
6f217e9efd | |||
0ea2ae758e | |||
fcd4669f35 | |||
2508a4567b | |||
1b487de0db | |||
84741e2c1b | |||
4e84183fd4 | |||
360c8ea6e4 | |||
a11edd3138 | |||
1fe19e455f | |||
897fa95e23 | |||
55f28eeb9f | |||
ff46923e03 | |||
5d51804dea | |||
6f0aabf3be | |||
5391e0ca27 | |||
3d3f181924 | |||
a5e181192b | |||
9c14d6e3eb | |||
b469237bda | |||
2683f494ea | |||
474e64911c | |||
582ccadde0 | |||
470d0ec13c | |||
78624f6cdd | |||
629b1628ca | |||
411b1d19b9 | |||
72cda6eeaf | |||
042c13b7b1 | |||
ec4c52c115 | |||
e015b9cd7c | |||
3c47bc0b5a | |||
f51ee23a1f | |||
f11711f07e | |||
2960b6c1c8 | |||
025d61efee | |||
dbf2c73757 | |||
f112840426 | |||
7a12d6aa66 | |||
163c2a86c1 | |||
b08802742d | |||
50bc541455 | |||
f4bbb821c2 | |||
16c93f8548 | |||
d5bb3c526f | |||
8f002bfc4d | |||
06605429d3 | |||
c8bd2e38af | |||
50f2a612f8 | |||
097afb19b7 | |||
d2a71ed513 |
5
CHANGELOG.md
Normal file
5
CHANGELOG.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Changelog
|
||||
* (3 July 2015). Flattened the folder structure so there is no .org repo parent folder.
|
||||
* (4 September 2014). Updating the `README` with Windows symbolic link instructions.
|
||||
* (3 September 2014). Updating the `README` to describe how to install the Boilerplate.
|
||||
* (1 September 2014). Initial Release.
|
|
@ -1,3 +0,0 @@
|
|||
# ChangeLog
|
||||
|
||||
* (1 September 2015). Initial Release
|
65
README.md
65
README.md
|
@ -7,27 +7,32 @@ A standardized, organized, object-oriented foundation for building high-quality
|
|||
The WordPress Plugin Boilerplate includes the following files:
|
||||
|
||||
* `.gitignore`. Used to exclude certain files from the repository.
|
||||
* `ChangeLog.md`. The list of changes to the core project.
|
||||
* `CHANGELOG.md`. The list of changes to the core project.
|
||||
* `README.md`. The file that you’re currently reading.
|
||||
* A `plugin-name` subdirectory that contains the source code - a fully executable WordPress plugin.
|
||||
* A `plugin-name` directory that contains the source code - a fully executable WordPress plugin.
|
||||
|
||||
## Features
|
||||
|
||||
* The Boilerplate is based on the [Plugin API](http://codex.wordpress.org/Plugin_API), [Coding Standards](http://codex.wordpress.org/WordPress_Coding_Standards), and [Documentation Standards](http://make.wordpress.org/core/handbook/inline-documentation-standards/php-documentation-standards/).
|
||||
* All classes, functions, and variables are documented so that you know what you need to be changed.
|
||||
* The Boilerplate uses a strict file organization scheme that correspond both to the WordPress Plugin Repository structure, and that make it easy to organize the files that compose the plugin.
|
||||
* The Boilerplate is based on the [Plugin API](http://codex.wordpress.org/Plugin_API), [Coding Standards](http://codex.wordpress.org/WordPress_Coding_Standards), and [Documentation Standards](https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/php/).
|
||||
* All classes, functions, and variables are documented so that you know what you need to change.
|
||||
* The Boilerplate uses a strict file organization scheme that corresponds both to the WordPress Plugin Repository structure, and that makes it easy to organize the files that compose the plugin.
|
||||
* The project includes a `.pot` file as a starting point for internationalization.
|
||||
|
||||
## Installation
|
||||
|
||||
1. Copy the `plugin-name` directory into your `wp-content/plugins` directory.
|
||||
2. In the WordPress dashboard, navigation to the *Plugins* page
|
||||
Locate the menu item that reads “The WordPress Plugin Boilerplate.”
|
||||
3. Click on *Activate.*
|
||||
The Boilerplate can be installed directly into your plugins folder "as-is". You will want to rename it and the classes inside of it to fit your needs. For example, if your plugin is named 'example-me' then:
|
||||
|
||||
Note that this will activate the source code of the Boilerplate, but because the Boilerplate has no real functionality so no menu items, meta boxes, or custom post types will be added.
|
||||
* rename files from `plugin-name` to `example-me`
|
||||
* change `plugin_name` to `example_me`
|
||||
* change `plugin-name` to `example-me`
|
||||
* change `Plugin_Name` to `Example_Me`
|
||||
* change `PLUGIN_NAME_` to `EXAMPLE_ME_`
|
||||
|
||||
Examples are slated to be added to the [Boilerplate’s website](http://wppb.io) as the site continues to grow.
|
||||
It's safe to activate the plugin at this point. Because the Boilerplate has no real functionality there will be no menu items, meta boxes, or custom post types added until you write the code.
|
||||
|
||||
## WordPress.org Preparation
|
||||
|
||||
The original launch of this version of the boilerplate included the folder structure needed for using your plugin on WordPress.org. That folder structure has been moved to its own repo here: https://github.com/DevinVinson/Plugin-Directory-Boilerplate
|
||||
|
||||
## Recommended Tools
|
||||
|
||||
|
@ -65,48 +70,30 @@ For reference, [here's a discussion](http://make.wordpress.org/themes/2013/03/04
|
|||
|
||||
Note that if you include your own classes, or third-party libraries, there are three locations in which said files may go:
|
||||
|
||||
* `plugin-name/includes` is where functionality shared between the dashboard and the public-facing parts of the side reside
|
||||
* `plugin-name/admin` is for all dashboard-specific functionality
|
||||
* `plugin-name/includes` is where functionality shared between the admin area and the public-facing parts of the site reside
|
||||
* `plugin-name/admin` is for all admin-specific functionality
|
||||
* `plugin-name/public` is for all public-facing functionality
|
||||
|
||||
Note that previous versions of the Boilerplate did not include `Plugin_Name_Loader` but this class is used to register all filters and actions with WordPress.
|
||||
|
||||
The example code provided shows how to register your hooks with the Loader class. More information will be provided in the upcoming documentation on the website.
|
||||
|
||||
### Assets
|
||||
|
||||
The `assets` directory contains three files.
|
||||
|
||||
1. `banner-772x250.png` is used to represent the plugin’s header image.
|
||||
2. `icon-256x256.png` is a used to represent the plugin’s icon image (which is new as of WordPress 4.0).
|
||||
3. `screenshot-1.png` is used to represent a single screenshot of the plugin that corresponds to the “Screenshots” heading in your plugin `README.txt`.
|
||||
|
||||
The WordPress Plugin Repository directory structure contains three directories:
|
||||
|
||||
1. `assets`
|
||||
2. `branches`
|
||||
3. `trunk`
|
||||
|
||||
The Boilerplate offers support for `assets` and `trunk` as `branches` is something that isn’t often used and, when it is, is done so under advanced circumstances.
|
||||
|
||||
When committing code to the WordPress Plugin Repository, all of the banner, icon, and screenshot should be placed in the `assets` directory of the Repository, and the core code should be placed in the `trunk` directory.
|
||||
The example code provided shows how to register your hooks with the Loader class.
|
||||
|
||||
### What About Other Features?
|
||||
|
||||
The previous version of the WordPress Plugin Boilerplate included support for a number of different projects such as the [GitHub Updater](https://github.com/afragen/github-updater).
|
||||
The previous version of the WordPress Plugin Boilerplate included support for a number of different projects such as the [GitHub Updater](https://github.com/afragen/github-updater).
|
||||
|
||||
These tools are not part of the core of this Boilerplate, as I see them as being additions, forks, or other contributions to the Boilerplate.
|
||||
These tools are not part of the core of this Boilerplate, as I see them as being additions, forks, or other contributions to the Boilerplate.
|
||||
|
||||
The same is true of using tools like Grunt, Composer, etc. These are all fantastic tools, but not everyone uses them. In order to keep the core Boilerplate as light as possible, this feature have been removed and will be introduced in other editions, and will be listed and maintained on the project homepage
|
||||
The same is true of using tools like Grunt, Composer, etc. These are all fantastic tools, but not everyone uses them. In order to keep the core Boilerplate as light as possible, these features have been removed and will be introduced in other editions, and will be listed and maintained on the project homepage.
|
||||
|
||||
# Credits
|
||||
|
||||
The WordPress Plugin Boilerplate was started in 2011 by [Tom McFarlin](http://twitter.com/tommcfarlin/) and his since included a number of great contributions.
|
||||
The WordPress Plugin Boilerplate was started in 2011 by [Tom McFarlin](http://twitter.com/tommcfarlin/) and has since included a number of great contributions. In March of 2015 the project was handed over by Tom to Devin Vinson.
|
||||
|
||||
The current version of the Boilerplate was developed in conjunction with [Josh Eaton](https://twitter.com/jjeaton), [Ulrich Pogson](https://twitter.com/grapplerulrich), and [Brad Vincent](https://twitter.com/themergency).
|
||||
The current version of the Boilerplate was developed in conjunction with [Josh Eaton](https://twitter.com/jjeaton), [Ulrich Pogson](https://twitter.com/grapplerulrich), and [Brad Vincent](https://twitter.com/themergency).
|
||||
|
||||
The homepage is based on a design as provided by [HTML5Up](http://html5up.net), the Boilerplate logo was designed by Rob McCaskill of [BungaWeb](http://bungaweb.com), and the site `favicon` was created by [Mickey Kay](https://twitter.com/McGuive7).
|
||||
The homepage is based on a design as provided by [HTML5Up](http://html5up.net), the Boilerplate logo was designed by Rob McCaskill of [BungaWeb](http://bungaweb.com), and the site `favicon` was created by [Mickey Kay](https://twitter.com/McGuive7).
|
||||
|
||||
## Documentation, FAQs, and More
|
||||
|
||||
Because this version is a major rewrite of the core plugin, we’re working to create an entire site around the Boilerplate. If you’re interested, please [let me know](http://tommcfarlin.com/contact) and we’ll see what we can do.
|
||||
If you’re interested in writing any documentation or creating tutorials please [let me know](http://devinvinson.com/contact/) .
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The dashboard-specific functionality of the plugin.
|
||||
* The admin-specific functionality of the plugin.
|
||||
*
|
||||
* @link http://example.com
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Plugin_Name
|
||||
* @subpackage Plugin_Name/includes
|
||||
* @subpackage Plugin_Name/admin
|
||||
*/
|
||||
|
||||
/**
|
||||
* The dashboard-specific functionality of the plugin.
|
||||
* The admin-specific functionality of the plugin.
|
||||
*
|
||||
* Defines the plugin name, version, and two examples hooks for how to
|
||||
* enqueue the dashboard-specific stylesheet and JavaScript.
|
||||
* enqueue the admin-specific stylesheet and JavaScript.
|
||||
*
|
||||
* @package Plugin_Name
|
||||
* @subpackage Plugin_Name/admin
|
||||
|
@ -27,9 +27,9 @@ class Plugin_Name_Admin {
|
|||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
* @var string $name The ID of this plugin.
|
||||
* @var string $plugin_name The ID of this plugin.
|
||||
*/
|
||||
private $name;
|
||||
private $plugin_name;
|
||||
|
||||
/**
|
||||
* The version of this plugin.
|
||||
|
@ -44,18 +44,18 @@ class Plugin_Name_Admin {
|
|||
* Initialize the class and set its properties.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string $name The name of this plugin.
|
||||
* @var string $version The version of this plugin.
|
||||
* @param string $plugin_name The name of this plugin.
|
||||
* @param string $version The version of this plugin.
|
||||
*/
|
||||
public function __construct( $name, $version ) {
|
||||
public function __construct( $plugin_name, $version ) {
|
||||
|
||||
$this->name = $name;
|
||||
$this->plugin_name = $plugin_name;
|
||||
$this->version = $version;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the stylesheets for the Dashboard.
|
||||
* Register the stylesheets for the admin area.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
@ -65,20 +65,20 @@ class Plugin_Name_Admin {
|
|||
* This function is provided for demonstration purposes only.
|
||||
*
|
||||
* An instance of this class should be passed to the run() function
|
||||
* defined in Plugin_Name_Admin_Loader as all of the hooks are defined
|
||||
* defined in Plugin_Name_Loader as all of the hooks are defined
|
||||
* in that particular class.
|
||||
*
|
||||
* The Plugin_Name_Admin_Loader will then create the relationship
|
||||
* The Plugin_Name_Loader will then create the relationship
|
||||
* between the defined hooks and the functions defined in this
|
||||
* class.
|
||||
*/
|
||||
|
||||
wp_enqueue_style( $this->name, plugin_dir_url( __FILE__ ) . 'css/plugin-name-admin.css', array(), $this->version, 'all' );
|
||||
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/plugin-name-admin.css', array(), $this->version, 'all' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the JavaScript for the dashboard.
|
||||
* Register the JavaScript for the admin area.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
@ -88,15 +88,15 @@ class Plugin_Name_Admin {
|
|||
* This function is provided for demonstration purposes only.
|
||||
*
|
||||
* An instance of this class should be passed to the run() function
|
||||
* defined in Plugin_Name_Admin_Loader as all of the hooks are defined
|
||||
* defined in Plugin_Name_Loader as all of the hooks are defined
|
||||
* in that particular class.
|
||||
*
|
||||
* The Plugin_Name_Admin_Loader will then create the relationship
|
||||
* The Plugin_Name_Loader will then create the relationship
|
||||
* between the defined hooks and the functions defined in this
|
||||
* class.
|
||||
*/
|
||||
|
||||
wp_enqueue_script( $this->name, plugin_dir_url( __FILE__ ) . 'js/plugin-name-admin.js', array( 'jquery' ), $this->version, FALSE );
|
||||
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/plugin-name-admin.js', array( 'jquery' ), $this->version, false );
|
||||
|
||||
}
|
||||
|
4
plugin-name/admin/css/plugin-name-admin.css
Normal file
4
plugin-name/admin/css/plugin-name-admin.css
Normal file
|
@ -0,0 +1,4 @@
|
|||
/**
|
||||
* All of the CSS for your admin-specific functionality should be
|
||||
* included in this file.
|
||||
*/
|
32
plugin-name/admin/js/plugin-name-admin.js
Normal file
32
plugin-name/admin/js/plugin-name-admin.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
(function( $ ) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* All of the code for your admin-facing JavaScript source
|
||||
* should reside in this file.
|
||||
*
|
||||
* Note: It has been assumed you will write jQuery code here, so the
|
||||
* $ function reference has been prepared for usage within the scope
|
||||
* of this function.
|
||||
*
|
||||
* This enables you to define handlers, for when the DOM is ready:
|
||||
*
|
||||
* $(function() {
|
||||
*
|
||||
* });
|
||||
*
|
||||
* When the window is loaded:
|
||||
*
|
||||
* $( window ).load(function() {
|
||||
*
|
||||
* });
|
||||
*
|
||||
* ...and/or other possibilities.
|
||||
*
|
||||
* Ideally, it is not considered best practise to attach more than a
|
||||
* single DOM-ready or window-load handler for a particular page.
|
||||
* Although scripts in the WordPress core, Plugins and Themes may be
|
||||
* practising this, we should strive to set a better example in our own work.
|
||||
*/
|
||||
|
||||
})( jQuery );
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Provide a dashboard view for the plugin
|
||||
* Provide a admin area view for the plugin
|
||||
*
|
||||
* This file is used to markup the public-facing aspects of the plugin.
|
||||
* This file is used to markup the admin-facing aspects of the plugin.
|
||||
*
|
||||
* @link http://example.com
|
||||
* @since 1.0.0
|
|
@ -4,7 +4,7 @@
|
|||
* Define the internationalization functionality
|
||||
*
|
||||
* Loads and defines the internationalization files for this plugin
|
||||
* so that its ready for translation.
|
||||
* so that it is ready for translation.
|
||||
*
|
||||
* @link http://example.com
|
||||
* @since 1.0.0
|
||||
|
@ -17,7 +17,7 @@
|
|||
* Define the internationalization functionality.
|
||||
*
|
||||
* Loads and defines the internationalization files for this plugin
|
||||
* so that its ready for translation.
|
||||
* so that it is ready for translation.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @package Plugin_Name
|
||||
|
@ -26,14 +26,6 @@
|
|||
*/
|
||||
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.
|
||||
|
@ -43,21 +35,13 @@ class Plugin_Name_i18n {
|
|||
public function load_plugin_textdomain() {
|
||||
|
||||
load_plugin_textdomain(
|
||||
$this->domain,
|
||||
FALSE,
|
||||
'plugin-name',
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -41,6 +41,15 @@ class Plugin_Name_Loader {
|
|||
*/
|
||||
protected $filters;
|
||||
|
||||
/**
|
||||
* The array of shortcode registered with WordPress.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
* @var array $shortcodes The shortcode registered with WordPress to fire when the plugin loads.
|
||||
*/
|
||||
protected $shortcodes;
|
||||
|
||||
/**
|
||||
* Initialize the collections used to maintain the actions and filters.
|
||||
*
|
||||
|
@ -50,6 +59,7 @@ class Plugin_Name_Loader {
|
|||
|
||||
$this->actions = array();
|
||||
$this->filters = array();
|
||||
$this->shortcodes = array();
|
||||
|
||||
}
|
||||
|
||||
|
@ -57,11 +67,11 @@ class Plugin_Name_Loader {
|
|||
* Add a new action to the collection to be registered with WordPress.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string $hook The name of the WordPress action that is being registered.
|
||||
* @var object $component A reference to the instance of the object on which the action is defined.
|
||||
* @var string $callback The name of the function definition on the $component.
|
||||
* @var int Optional $priority The priority at which the function should be fired.
|
||||
* @var int Optional $accepted_args The number of arguments that should be passed to the $callback.
|
||||
* @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 $priority Optional. The priority at which the function should be fired. Default is 10.
|
||||
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
|
||||
*/
|
||||
public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
|
||||
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
|
||||
|
@ -71,29 +81,41 @@ class Plugin_Name_Loader {
|
|||
* Add a new filter to the collection to be registered with WordPress.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string $hook The name of the WordPress filter that is being registered.
|
||||
* @var object $component A reference to the instance of the object on which the filter is defined.
|
||||
* @var string $callback The name of the function definition on the $component.
|
||||
* @var int Optional $priority The priority at which the function should be fired.
|
||||
* @var int Optional $accepted_args The number of arguments that should be passed to the $callback.
|
||||
* @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 $priority Optional. The priority at which the function should be fired. Default is 10.
|
||||
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
|
||||
*/
|
||||
public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
|
||||
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new shortcode to the collection to be registered with WordPress
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @param string $tag The name of the new shortcode.
|
||||
* @param object $component A reference to the instance of the object on which the shortcode is defined.
|
||||
* @param string $callback The name of the function that defines the shortcode.
|
||||
*/
|
||||
public function add_shortcode( $tag, $component, $callback, $priority = 10, $accepted_args = 1 ) {
|
||||
$this->shortcodes = $this->add( $this->shortcodes, $tag, $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
|
||||
* @var array $hooks The collection of hooks that is being registered (that is, actions or filters).
|
||||
* @var string $hook The name of the WordPress filter that is being registered.
|
||||
* @var object $component A reference to the instance of the object on which the filter is defined.
|
||||
* @var string $callback The name of the function definition on the $component.
|
||||
* @var int Optional $priority The priority at which the function should be fired.
|
||||
* @var 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.
|
||||
* @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 $priority The priority at which the function should be fired.
|
||||
* @param int $accepted_args The number of arguments that should be passed to the $callback.
|
||||
* @return array The collection of actions and filters registered with WordPress.
|
||||
*/
|
||||
private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
|
||||
|
||||
|
@ -124,6 +146,10 @@ class Plugin_Name_Loader {
|
|||
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
|
||||
}
|
||||
|
||||
foreach ( $this->shortcodes as $hook ) {
|
||||
add_shortcode( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
* 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 dashboard.
|
||||
* public-facing side of the site and the admin area.
|
||||
*
|
||||
* @link http://example.com
|
||||
* @since 1.0.0
|
||||
|
@ -16,7 +16,7 @@
|
|||
/**
|
||||
* The core plugin class.
|
||||
*
|
||||
* This is used to define internationalization, dashboard-specific hooks, and
|
||||
* 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
|
||||
|
@ -61,15 +61,18 @@ class Plugin_Name {
|
|||
* 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 Dashboard and
|
||||
* 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() {
|
||||
|
||||
if ( defined( 'PLUGIN_NAME_VERSION' ) ) {
|
||||
$this->version = PLUGIN_NAME_VERSION;
|
||||
} else {
|
||||
$this->version = '1.0.0';
|
||||
}
|
||||
$this->plugin_name = 'plugin-name';
|
||||
$this->version = '1.0.0';
|
||||
|
||||
$this->load_dependencies();
|
||||
$this->set_locale();
|
||||
|
@ -85,7 +88,7 @@ class Plugin_Name {
|
|||
*
|
||||
* - Plugin_Name_Loader. Orchestrates the hooks of the plugin.
|
||||
* - Plugin_Name_i18n. Defines internationalization functionality.
|
||||
* - Plugin_Name_Admin. Defines all hooks for the dashboard.
|
||||
* - 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
|
||||
|
@ -109,7 +112,7 @@ class Plugin_Name {
|
|||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-plugin-name-i18n.php';
|
||||
|
||||
/**
|
||||
* The class responsible for defining all actions that occur in the Dashboard.
|
||||
* 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';
|
||||
|
||||
|
@ -135,14 +138,13 @@ class Plugin_Name {
|
|||
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 dashboard functionality
|
||||
* Register all of the hooks related to the admin area functionality
|
||||
* of the plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
|
@ -171,6 +173,8 @@ class Plugin_Name {
|
|||
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
|
||||
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
|
||||
|
||||
$this->loader->add_shortcode( 'plugin-name-shortcode', $plugin_public, 'plugin_name_shortcode_func' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
|
@ -4,9 +4,9 @@
|
|||
* The plugin bootstrap file
|
||||
*
|
||||
* This file is read by WordPress to generate the plugin information in the plugin
|
||||
* Dashboard. This file also includes all of the dependencies used by the plugin,
|
||||
* admin area. This file also includes all of the dependencies used by the plugin,
|
||||
* registers the activation and deactivation functions, and defines a function
|
||||
* this starts the plugin.
|
||||
* that starts the plugin.
|
||||
*
|
||||
* @link http://example.com
|
||||
* @since 1.0.0
|
||||
|
@ -15,7 +15,7 @@
|
|||
* @wordpress-plugin
|
||||
* Plugin Name: WordPress Plugin Boilerplate
|
||||
* Plugin URI: http://example.com/plugin-name-uri/
|
||||
* Description: This is a short description of what the plugin does. It's displayed in the WordPress dashboard.
|
||||
* Description: This is a short description of what the plugin does. It's displayed in the WordPress admin area.
|
||||
* Version: 1.0.0
|
||||
* Author: Your Name or Your Company
|
||||
* Author URI: http://example.com/
|
||||
|
@ -31,26 +31,38 @@ if ( ! defined( 'WPINC' ) ) {
|
|||
}
|
||||
|
||||
/**
|
||||
* The code that runs during plugin activation.
|
||||
* Currently plugin version.
|
||||
* Start at version 1.0.0 and use SemVer - https://semver.org
|
||||
* Rename this for your plugin and update it as you release new versions.
|
||||
*/
|
||||
require_once plugin_dir_path( __FILE__ ) . 'includes/class-plugin-name-activator.php';
|
||||
define( 'PLUGIN_NAME_VERSION', '1.0.0' );
|
||||
|
||||
/**
|
||||
* The code that runs during plugin activation.
|
||||
* This action is documented in includes/class-plugin-name-activator.php
|
||||
*/
|
||||
function activate_plugin_name() {
|
||||
require_once plugin_dir_path( __FILE__ ) . 'includes/class-plugin-name-activator.php';
|
||||
Plugin_Name_Activator::activate();
|
||||
}
|
||||
|
||||
/**
|
||||
* The code that runs during plugin deactivation.
|
||||
* This action is documented in includes/class-plugin-name-deactivator.php
|
||||
*/
|
||||
require_once plugin_dir_path( __FILE__ ) . 'includes/class-plugin-name-deactivator.php';
|
||||
function deactivate_plugin_name() {
|
||||
require_once plugin_dir_path( __FILE__ ) . 'includes/class-plugin-name-deactivator.php';
|
||||
Plugin_Name_Deactivator::deactivate();
|
||||
}
|
||||
|
||||
/** This action is documented in includes/class-plugin-name-activator.php */
|
||||
register_activation_hook( __FILE__, array( 'Plugin_Name_Activator', 'activate' ) );
|
||||
|
||||
/** This action is documented in includes/class-plugin-name-deactivator.php */
|
||||
register_activation_hook( __FILE__, array( 'Plugin_Name_Deactivator', 'deactivate' ) );
|
||||
register_activation_hook( __FILE__, 'activate_plugin_name' );
|
||||
register_deactivation_hook( __FILE__, 'deactivate_plugin_name' );
|
||||
|
||||
/**
|
||||
* The core plugin class that is used to define internationalization,
|
||||
* dashboard-specific hooks, and public-facing site hooks.
|
||||
* admin-specific hooks, and public-facing site hooks.
|
||||
*/
|
||||
require_once plugin_dir_path( __FILE__ ) . 'includes/class-plugin-name.php';
|
||||
require plugin_dir_path( __FILE__ ) . 'includes/class-plugin-name.php';
|
||||
|
||||
/**
|
||||
* Begins execution of the plugin.
|
|
@ -7,17 +7,17 @@
|
|||
* @since 1.0.0
|
||||
*
|
||||
* @package Plugin_Name
|
||||
* @subpackage Plugin_Name/includes
|
||||
* @subpackage Plugin_Name/public
|
||||
*/
|
||||
|
||||
/**
|
||||
* The public-facing functionality of the plugin.
|
||||
*
|
||||
* Defines the plugin name, version, and two examples hooks for how to
|
||||
* enqueue the dashboard-specific stylesheet and JavaScript.
|
||||
* enqueue the public-facing stylesheet and JavaScript.
|
||||
*
|
||||
* @package Plugin_Name
|
||||
* @subpackage Plugin_Name/admin
|
||||
* @subpackage Plugin_Name/public
|
||||
* @author Your Name <email@example.com>
|
||||
*/
|
||||
class Plugin_Name_Public {
|
||||
|
@ -27,9 +27,9 @@ class Plugin_Name_Public {
|
|||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
* @var string $name The ID of this plugin.
|
||||
* @var string $plugin_name The ID of this plugin.
|
||||
*/
|
||||
private $name;
|
||||
private $plugin_name;
|
||||
|
||||
/**
|
||||
* The version of this plugin.
|
||||
|
@ -44,12 +44,12 @@ class Plugin_Name_Public {
|
|||
* Initialize the class and set its properties.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string $name The name of the plugin.
|
||||
* @var string $version The version of this plugin.
|
||||
* @param string $plugin_name The name of the plugin.
|
||||
* @param string $version The version of this plugin.
|
||||
*/
|
||||
public function __construct( $name, $version ) {
|
||||
public function __construct( $plugin_name, $version ) {
|
||||
|
||||
$this->name = $name;
|
||||
$this->plugin_name = $plugin_name;
|
||||
$this->version = $version;
|
||||
|
||||
}
|
||||
|
@ -65,20 +65,20 @@ class Plugin_Name_Public {
|
|||
* This function is provided for demonstration purposes only.
|
||||
*
|
||||
* An instance of this class should be passed to the run() function
|
||||
* defined in Plugin_Name_Public_Loader as all of the hooks are defined
|
||||
* defined in Plugin_Name_Loader as all of the hooks are defined
|
||||
* in that particular class.
|
||||
*
|
||||
* The Plugin_Name_Public_Loader will then create the relationship
|
||||
* The Plugin_Name_Loader will then create the relationship
|
||||
* between the defined hooks and the functions defined in this
|
||||
* class.
|
||||
*/
|
||||
|
||||
wp_enqueue_style( $this->name, plugin_dir_url( __FILE__ ) . 'css/plugin-name-public.css', array(), $this->version, 'all' );
|
||||
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/plugin-name-public.css', array(), $this->version, 'all' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the stylesheets for the public-facing side of the site.
|
||||
* Register the JavaScript for the public-facing side of the site.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
@ -88,16 +88,30 @@ class Plugin_Name_Public {
|
|||
* This function is provided for demonstration purposes only.
|
||||
*
|
||||
* An instance of this class should be passed to the run() function
|
||||
* defined in Plugin_Name_Public_Loader as all of the hooks are defined
|
||||
* defined in Plugin_Name_Loader as all of the hooks are defined
|
||||
* in that particular class.
|
||||
*
|
||||
* The Plugin_Name_Public_Loader will then create the relationship
|
||||
* The Plugin_Name_Loader will then create the relationship
|
||||
* between the defined hooks and the functions defined in this
|
||||
* class.
|
||||
*/
|
||||
|
||||
wp_enqueue_script( $this->name, plugin_dir_url( __FILE__ ) . 'js/plugin-name-public.js', array( 'jquery' ), $this->version, FALSE );
|
||||
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/plugin-name-public.js', array( 'jquery' ), $this->version, false );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcode processing function.
|
||||
* Shortcode can take arguments like [plugin-name-shortcode argm='123']
|
||||
*/
|
||||
public function plugin_name_shortcode_func($atts) {
|
||||
$a = shortcode_atts( array(
|
||||
'argm' => '0',
|
||||
), $atts
|
||||
);
|
||||
return (
|
||||
$a['argm']
|
||||
);
|
||||
}
|
||||
|
||||
}
|
32
plugin-name/public/js/plugin-name-public.js
Normal file
32
plugin-name/public/js/plugin-name-public.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
(function( $ ) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* All of the code for your public-facing JavaScript source
|
||||
* should reside in this file.
|
||||
*
|
||||
* Note: It has been assumed you will write jQuery code here, so the
|
||||
* $ function reference has been prepared for usage within the scope
|
||||
* of this function.
|
||||
*
|
||||
* This enables you to define handlers, for when the DOM is ready:
|
||||
*
|
||||
* $(function() {
|
||||
*
|
||||
* });
|
||||
*
|
||||
* When the window is loaded:
|
||||
*
|
||||
* $( window ).load(function() {
|
||||
*
|
||||
* });
|
||||
*
|
||||
* ...and/or other possibilities.
|
||||
*
|
||||
* Ideally, it is not considered best practise to attach more than a
|
||||
* single DOM-ready or window-load handler for a particular page.
|
||||
* Although scripts in the WordPress core, Plugins and Themes may be
|
||||
* practising this, we should strive to set a better example in our own work.
|
||||
*/
|
||||
|
||||
})( jQuery );
|
|
@ -1,4 +0,0 @@
|
|||
/**
|
||||
* All of the CSS for your dashboard-specific functionality should be
|
||||
* included in this file.
|
||||
*/
|
|
@ -1,32 +0,0 @@
|
|||
(function( $ ) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* All of the code for your Dashboard-specific JavaScript source
|
||||
* should reside in this file.
|
||||
*
|
||||
* Note that this assume you're going to use jQuery, so it prepares
|
||||
* the $ function reference to be used within the scope of this
|
||||
* function.
|
||||
*
|
||||
* From here, you're able to define handlers for when the DOM is
|
||||
* ready:
|
||||
*
|
||||
* $(function() {
|
||||
*
|
||||
* });
|
||||
*
|
||||
* Or when the window is loaded:
|
||||
*
|
||||
* $( window ).load(function() {
|
||||
*
|
||||
* });
|
||||
*
|
||||
* ...and so on.
|
||||
*
|
||||
* Remember that ideally, we should not attach any more than a single DOM-ready or window-load handler
|
||||
* for any particular page. Though other scripts in WordPress core, other plugins, and other themes may
|
||||
* be doing this, we should try to minimize doing that in our own work.
|
||||
*/
|
||||
|
||||
})( jQuery );
|
|
@ -1,32 +0,0 @@
|
|||
(function( $ ) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* All of the code for your public-facing JavaScript source
|
||||
* should reside in this file.
|
||||
*
|
||||
* Note that this assume you're going to use jQuery, so it prepares
|
||||
* the $ function reference to be used within the scope of this
|
||||
* function.
|
||||
*
|
||||
* From here, you're able to define handlers for when the DOM is
|
||||
* ready:
|
||||
*
|
||||
* $(function() {
|
||||
*
|
||||
* });
|
||||
*
|
||||
* Or when the window is loaded:
|
||||
*
|
||||
* $( window ).load(function() {
|
||||
*
|
||||
* });
|
||||
*
|
||||
* ...and so on.
|
||||
*
|
||||
* Remember that ideally, we should not attach any more than a single DOM-ready or window-load handler
|
||||
* for any particular page. Though other scripts in WordPress core, other plugins, and other themes may
|
||||
* be doing this, we should try to minimize doing that in our own work.
|
||||
*/
|
||||
|
||||
})( jQuery );
|
Loading…
Reference in a new issue