1
0
Fork 0
mirror of https://github.com/inretio/WordPress-Plugin-Boilerplate synced 2024-05-19 11:42:09 +03:00

Compare commits

...

76 commits

Author SHA1 Message Date
Gytis Repečka a57e6e7460
Add shortcode support. 2020-07-17 16:58:32 +03:00
Devin a8291082b5
Merge pull request #508 from alertmybanjos/patch-2
Update README.md
2019-02-22 11:15:41 -05:00
Devin d2f6b21b80
Merge pull request #507 from alertmybanjos/patch-1
Update README.md
2019-02-22 11:15:26 -05:00
Jason Tremblay f142df8c45
Update README.md
More specific, case sensitive string changes for initial setup.
2019-02-22 06:29:41 -05:00
Jason Tremblay 611c80cce1
Update README.md
Clarify the renaming step to align with the actual file names, which are currently named with dashes, not underscores.
2019-02-22 05:56:58 -05:00
Devin 60940a9761
Merge pull request #456 from manzoorwanijk/patch-1
Typo correction
2018-01-06 15:40:49 -05:00
Manzoor Wani b02101400e
Typo correction 2017-12-07 14:29:48 +05:30
Devin bc3e07be2a
Merge pull request #453 from Ipstenu/Ipstenu-rtfm
Documentation update for Plugin Version constant. Thank you @Ipstenu
2017-11-27 17:34:45 -05:00
Ipstenu (Mika Epstein) 95844fec48
Inline doc 2017-11-27 14:09:08 -08:00
Ipstenu (Mika Epstein) 696db21ed7
Clarifying directions 2017-11-27 14:07:36 -08:00
Devin 7af6de6dd2 Merge pull request #446 from jonathanbossenger/master
Updating PLUGIN_VERSION constant. Fixes #446
2017-09-27 19:37:57 -04:00
Jonathan Bossenger 04f90ff5ff Updating PLUGIN_VERSION to PLUGIN_NAME_VERSION to follow plugin standards for renaming 2017-09-27 16:13:29 +02:00
Devin 1f36abcedd Merge pull request #443 from Tmeister/master
Wraps the PLUGIN_VERSION constant in single quotes
2017-09-12 08:53:40 -04:00
Enrique Chavez 65a87940e9 Wraps the PLUGIN_VERSION constant in single quotes
* Fix #442
* Avoids the notice output
2017-09-11 11:33:00 -05:00
Devin 1f3c2acbe2 Merge pull request #417 from davidshq/patch-1
Small Spelling / Grammar Changes
2017-08-30 09:13:14 -04:00
Devin 77baf0b2f5 Merge pull request #429 from cliffordp/patch-2
Typo: "he" to "The"
2017-08-30 09:11:44 -04:00
Devin 19809447ec Merge pull request #353 from TalAter/patch-1
Fixed mistake in comment.
2017-08-30 09:11:20 -04:00
Devin 872c67477a Merge pull request #439 from jonathanbossenger/feature/version-constant
Adding a version constant
2017-08-30 09:04:32 -04:00
Jonathan Bossenger 5af56b19a5 Adding a version constant 2017-07-17 10:04:31 +02:00
Clifford ded444099b Typo: "he" to "The" 2017-05-19 17:39:12 -05:00
Dave Mackey c719bf9fc7 Small Spelling / Grammar Changes
Corrected a few small spelling / grammar issues throughout - very minor.
2017-01-19 21:41:23 -05:00
Devin Vinson 923fbaf0c8 Merge branch 'remove-var-translation' 2015-12-11 12:58:15 -05:00
Devin Vinson 0c099e4208 Use plugin-name directly instead of passing a variable through
This should fix the incorrect pattern of using a variable where we
should be using the plugin-name instead. Same goes for any translatable
strings within the plugin (no more using $this->plugin-name etc).
2015-12-05 20:46:30 -05:00
Tal Ater 579fb9823a Fixed mistake in comment. 2015-11-25 20:48:25 -05:00
Devin 39cb7ccfb3 Merge pull request #350 from hareesh-pillai/master
Update URL for Documentation Standards
2015-11-20 11:42:26 -05:00
Devin 6f217e9efd Merge pull request #349 from pieroit/patch-1
Update plugin-name-admin.js
2015-11-20 11:42:00 -05:00
Hareesh 0ea2ae758e Update URL for Documentation Standards 2015-11-15 01:23:52 +05:30
Piero Savastano fcd4669f35 Update plugin-name-admin.js
typo in the comment
2015-11-11 16:33:27 +01:00
Devin 2508a4567b Merge pull request #340 from LeeRobertsMe/patch-1
Update class-plugin-name-public.php so the correct file type is defined.
2015-11-03 08:25:04 -05:00
Devin 1b487de0db Merge pull request #342 from LeeRobertsMe/patch-5
Update plugin-name-public.js
2015-11-03 08:24:26 -05:00
Devin 84741e2c1b Merge pull request #343 from LeeRobertsMe/patch-4
Update plugin-name-admin.js
2015-11-03 08:24:03 -05:00
Devin 4e84183fd4 Merge pull request #339 from Shelob9/loader-docs-338
Add corrected inline docs in the loader class
2015-10-21 08:36:14 -04:00
LeeRobertsMe 360c8ea6e4 Update plugin-name-admin.js 2015-10-08 13:35:24 +01:00
LeeRobertsMe a11edd3138 Update plugin-name-public.js 2015-10-08 13:29:18 +01:00
LeeRobertsMe 1fe19e455f Update class-plugin-name-public.php 2015-10-08 12:25:28 +01:00
Josh Pollock 897fa95e23 Add inline docs in the loader class #338 2015-10-02 15:35:30 -04:00
Devin 55f28eeb9f Merge pull request #324 from javy-/patch-1
Update CHANGELOG with correct year.md
2015-08-13 09:45:17 -04:00
javy- ff46923e03 Update CHANGELOG.md
Fix latest change date year (2014->2015)
2015-08-08 16:48:17 -04:00
Devin 5d51804dea Merge pull request #323 from davidshq/master
Update README.md
2015-08-01 01:01:05 -04:00
Dave Mackey 6f0aabf3be Update README.md
Changed "this feature" to "these features"
2015-07-31 12:48:05 -04:00
Devin Vinson 5391e0ca27 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
2015-07-03 23:33:03 -04:00
Devin 3d3f181924 Merge pull request #266 from jancbeck/admin-area-dashboard-wording
changed wording from "dashboard" to "admin area"
2015-03-09 09:58:10 -04:00
Devin Vinson a5e181192b Updated Readme
Added a note about current project lead and pointing inquires away from
Tom’s contact form.
2015-03-04 15:21:25 -05:00
Jan Beck 9c14d6e3eb changed "dashboard" to "admin area"
dashboard-specific becomes admin-specific
2015-02-13 14:31:40 -04:00
Tom McFarlin b469237bda Merge pull request #260 from slushman/master
Function docs should be @param not @var.
2015-02-03 12:18:42 -05:00
Chris Wilcoxson 2683f494ea Function docs should be @param not @var. 2015-02-03 11:15:28 -06:00
Tom McFarlin 474e64911c Merge pull request #254 from donnapep/chore/change-loader-class-names
Fix incorrect class names
2015-01-19 09:51:22 -05:00
Donna Murphy 582ccadde0 Fix incorrect class names 2015-01-17 12:45:15 -05:00
Tom McFarlin 470d0ec13c Merge pull request #250 from swalkinshaw/CHANGELOG-fix
Fix CHANGELOG filename
2015-01-05 13:01:35 -05:00
Scott Walkinshaw 78624f6cdd Fix CHANGELOG filename 2015-01-05 11:42:45 -05:00
Tom McFarlin 629b1628ca Merge pull request #243 from tnorthcutt/patch-1
Fix minor typo in README.md
2014-12-01 14:52:30 -05:00
Travis Northcutt 411b1d19b9 Fix minor typo in README.md 2014-11-26 09:57:22 -06:00
Tom McFarlin 72cda6eeaf Merge pull request #238 from gosukiwi/patch-1
Use the same syntax for all included files.

Fixes #238
2014-11-19 13:59:21 -05:00
Federico Ramirez 042c13b7b1 Use the same syntax for all included files
I was having issues activating the plugin, and it was because of the way the files were beeing included, this fixes it.
2014-11-19 09:25:59 -03:00
Tom McFarlin ec4c52c115 Merge pull request #237 from feskehau/master
Create functions for activation and deactivation hooks.
2014-11-17 12:32:39 -05:00
Tony Hesjevik e015b9cd7c Create functions for activation and deactivation hooks.
Moving the activation and deactivation hooks into its own functions, makes so we dont have to include class-plugin-name-deactivator and class-plugin-name-activator on every page load.
2014-11-17 23:33:00 +11:00
Tom McFarlin 3c47bc0b5a Merge pull request #235 from barryceelen/patch-1
Fix code comment typo
2014-11-10 14:15:37 -05:00
Barry Ceelen f51ee23a1f Fix code comment typo 2014-11-10 16:57:08 +01:00
Tom McFarlin f11711f07e Merge pull request #231 from NikV/patch-1
Fixing require() vs require_once()
2014-11-05 12:08:34 -05:00
Nikhil Vimal 2960b6c1c8 Fixing require() vs require_once()
See : https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate/issues/222. I believe this was in favor of doing it "correctly"?
2014-11-04 16:47:16 -06:00
Tom McFarlin 025d61efee Merge pull request #224 from mAAdhaTTah/variable-fix
Change name -> plugin_name for consistency
2014-10-07 16:46:49 -04:00
mAAdhaTTah dbf2c73757 Change name -> plugin_name for consistency 2014-10-07 16:43:55 -04:00
Tom McFarlin f112840426 Merge pull request #220 from iamdmitrymayorov/master
Minor comment fix.
2014-10-07 16:34:23 -04:00
Dmitry Mayorov 7a12d6aa66 Update class-plugin-name-public.php
Updated @subpackage from 'admin' to 'public'
2014-10-05 19:36:55 +06:00
Dmitry Mayorov 163c2a86c1 Update class-plugin-name-admin.php
Changed @subpackage from 'includes' to 'admin'.
2014-10-05 19:35:03 +06:00
Tom McFarlin b08802742d Merge pull request #216 from JustinSainton/please-stop-shouting-at-me
Please stop shouting at me. I do hate when my parents shout.
2014-09-11 06:46:59 -04:00
Justin Sainton 50bc541455 Please stop shouting at me. I do hate when my parents shout.
But in all seriousness, shouting types is bad form.
2014-09-10 21:19:37 -07:00
Tom McFarlin f4bbb821c2 Merge branch 'master' of https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate 2014-09-04 09:45:48 -04:00
Tom McFarlin 16c93f8548 Adding instructions for Windows symlinks
Fixes #213
2014-09-04 09:44:54 -04:00
Tom McFarlin d5bb3c526f Merge pull request #214 from jessertaylor/master
Fixed deactivation hook in plugin_name.php
2014-09-03 10:57:25 -04:00
jessertaylor 8f002bfc4d Fixed deactivation hook in plugin_name.php 2014-09-03 15:11:55 +01:00
Tom McFarlin 06605429d3 describe how to install the Boilerplate.
Updating the `README` to describe how to install the Boilerplate.

Fixes #213
2014-09-03 09:26:49 -04:00
Tom McFarlin c8bd2e38af Merge pull request #211 from rob/patch-1
Fix typo in plugin-name.php
2014-09-02 13:55:18 -04:00
Rob Gabaree 50f2a612f8 Fix typo in plugin-name.php 2014-09-02 13:16:20 -04:00
Tom McFarlin 097afb19b7 Merge pull request #210 from rob/patch-1
Fix incorrect date in ChangeLog.md
2014-09-02 12:27:35 -04:00
Rob Gabaree d2a71ed513 Fix incorrect date in ChangeLog.md 2014-09-02 12:26:08 -04:00
31 changed files with 235 additions and 206 deletions

5
CHANGELOG.md Normal file
View 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.

View file

@ -1,3 +0,0 @@
# ChangeLog
* (1 September 2015). Initial Release

View file

@ -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 youre 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 [Boilerplates 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 plugins header image.
2. `icon-256x256.png` is a used to represent the plugins 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 isnt 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, were working to create an entire site around the Boilerplate. If youre interested, please [let me know](http://tommcfarlin.com/contact) and well see what we can do.
If youre interested in writing any documentation or creating tutorials please [let me know](http://devinvinson.com/contact/) .

View file

@ -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 );
}

View file

@ -0,0 +1,4 @@
/**
* All of the CSS for your admin-specific functionality should be
* included in this file.
*/

View 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 );

View file

@ -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

View file

@ -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;
}
}

View file

@ -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'] );
}
}
}

View file

@ -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' );
}
/**

View file

@ -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.

View file

@ -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']
);
}
}

View 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 );

View file

@ -1,4 +0,0 @@
/**
* All of the CSS for your dashboard-specific functionality should be
* included in this file.
*/

View 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 );

View file

@ -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 );