1
0
Fork 0
mirror of https://github.com/inretio/WordPress-Plugin-Boilerplate synced 2024-12-22 11:53:53 +02:00

Documenting classes

Documenting classes that are core to each plugin, while also leaving other classes undocumented for an implementation-specific basis.
This commit is contained in:
Tom McFarlin 2014-07-29 16:56:18 -04:00
parent f09ca373d8
commit 560e5959a5
6 changed files with 137 additions and 135 deletions

View file

@ -24,29 +24,27 @@
class Plugin_Name_Admin { class Plugin_Name_Admin {
/** /**
* Short description. (use period) * The version of this plugin.
* *
* @since 1.0.0 * @since 1.0.0
* @access private * @access private
* @var type $var Description. * @var string $version The current version of this plugin.
*/ */
private $version; private $version;
/** /**
* Short description. (use period) * Initialize the class and set its properties.
* *
* @since 1.0.0 * @since 1.0.0
* @access private * @access public
* @var type $var Description. * @var string $version The version of this plugin.
*/ */
public function __construct( $version ) { public function __construct( $version ) {
$this->version = $version; $this->version = $version;
} }
/** /**
* Short description. (use period) * Register the stylesheets for the Dashboard.
*
* Long description.
* *
* @since 1.0.0 * @since 1.0.0
*/ */
@ -69,9 +67,7 @@ class Plugin_Name_Admin {
} }
/** /**
* Short description. (use period) * Register the JavaScript for the dashboard.
*
* Long description.
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View file

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

View file

@ -1,22 +1,25 @@
<?php <?php
/** /**
* Define a short description for what this class does (no period) * Define the internationalization functionality.
*
* Loads and defines the internationalization files for this plugin
* so that its ready for translation.
*
* @link http://example.com
* @since 1.0.0
* *
* @package Plugin_Name * @package Plugin_Name
* @subpackage Plugin_Name/includes * @subpackage Plugin_Name/includes
* @author Your Name <email@example.com>
* @license GPL-2.0+
* @link http://example.com
* @copyright 2014 Your Name or Company Name
* @since 1.0.0
*/ */
/** /**
* Define a short description for what this class does. * Define the internationalization functionality.
* *
* Define a longer description for the purpose of this class. * Loads and defines the internationalization files for this plugin
* so that its ready for translation.
* *
* @since 1.0.0
* @package Plugin_Name * @package Plugin_Name
* @subpackage Plugin_Name/includes * @subpackage Plugin_Name/includes
* @author Your Name <email@example.com> * @author Your Name <email@example.com>
@ -24,7 +27,7 @@
class Plugin_Name_i18n { class Plugin_Name_i18n {
/** /**
* Short description. (use period) * Short Description. (use period)
* *
* @since 1.0.0 * @since 1.0.0
* @access private * @access private
@ -33,27 +36,25 @@ class Plugin_Name_i18n {
private $domain; private $domain;
/** /**
*
* Load the plugin text domain for translation. * Load the plugin text domain for translation.
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function load_plugin_textdomain() { public function load_plugin_textdomain() {
$locale = apply_filters( 'plugin_locale', get_locale(), $this->domain ); load_plugin_textdomain(
$this->domain,
load_textdomain( $this->domain, trailingslashit( WP_LANG_DIR ) . $this->domain . '/' . $this->domain . '-' . $locale . '.mo' ); FALSE,
load_plugin_textdomain( $this->domain, FALSE, basename( plugin_dir_path( dirname( __FILE__ ) ) ) . '/languages/' ); dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
);
} }
/** /**
* Short description. (use period) * Set the domain equal to that of the specified domain.
*
* Long description.
* *
* @since 1.0.0 * @since 1.0.0
* @param float $domain TODO * @param string $domain The domain that represents the locale of this plugin.
*/ */
public function set_domain( $domain ) { public function set_domain( $domain ) {
$this->domain = $domain; $this->domain = $domain;

View file

@ -1,7 +1,7 @@
<?php <?php
/** /**
* Define a short description for what this class does (no period) * Register all actions and filters
* *
* @package Plugin_Name * @package Plugin_Name
* @subpackage Plugin_Name/includes * @subpackage Plugin_Name/includes
@ -13,9 +13,11 @@
*/ */
/** /**
* Define a short description for what this class does. * Register all actions and filters.
* *
* Define a longer description for the purpose of this class. * 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 * @package Plugin_Name
* @subpackage Plugin_Name/includes * @subpackage Plugin_Name/includes
@ -24,28 +26,28 @@
class Plugin_Name_Loader { class Plugin_Name_Loader {
/** /**
* Short description. (use period) * The array of actions registered with WordPress.
* *
* @since 1.0.0 * @since 1.0.0
* @access private * @access protected
* @var type $var Description. * @var array $actions The actions registered with WordPress to fire when the plugin loads.
*/ */
protected $actions; protected $actions;
/** /**
* Short description. (use period) * The array of filters registered with WordPress.
* *
* @since 1.0.0 * @since 1.0.0
* @access private * @access protected
* @var type $var Description. * @var array $filters The filters registered with WordPress to fire when the plugin loads.
*/ */
protected $filters; protected $filters;
/** /**
* Short description. (use period) * Initialize the collections used to maintain the actions and filters.
* *
* @since 1.0.0 * @since 1.0.0
* @access private * @access public
*/ */
public function __construct() { public function __construct() {
@ -55,51 +57,57 @@ class Plugin_Name_Loader {
} }
/** /**
* Short description. (use period) * Add a new action to the collection to be registered with WordPress.
* *
* @since 1.0.0 * @since 1.0.0
* @access private * @access public
* @var type $var Description. * @var string $hook The name of the WordPress action that is being registered.
* @var type $var Description. * @var object $component A reference to the instance of the object on which the action is defined.
* @var type $var Description. * @var string $callback The name of the function definition on the $component.
* @var type Optional $var Description. * @var int Optional $priority The priority at which the function should be fired.
* @var array Optional $accepted_args The collection of arguments that should be passed to the $callback.
*/ */
public function add_action( $hook, $component, $callback, $priority = 10 ) { public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = array() ) {
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority ); $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
} }
/** /**
* Short description. (use period) * Add a new filter to the collection to be registered with WordPress.
* *
* @since 1.0.0 * @since 1.0.0
* @access private * @access public
* @var type $var Description. * @var string $hook The name of the WordPress filter that is being registered.
* @var type $var Description. * @var object $component A reference to the instance of the object on which the filter is defined.
* @var type $var Description. * @var string $callback The name of the function definition on the $component.
* @var type Optional $var Description. * @var int Optional $priority The priority at which the function should be fired.
* @var array Optional $accepted_args The collection of arguments that should be passed to the $callback.
*/ */
public function add_filter( $hook, $component, $callback, $priority = 10 ) { public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = array() ) {
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority ); $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args = array() );
} }
/** /**
* Short description. (use period) * A utility function that is used to register the actions and hooks into a single
* collection.
* *
* @since 1.0.0 * @since 1.0.0
* @access private * @access private
* @var type $var Description. * @var array $hooks The collection of hooks that is being registered (that is, actions or filters).
* @var type $var Description. * @var string $hook The name of the WordPress filter that is being registered.
* @var type $var Description. * @var object $component A reference to the instance of the object on which the filter is defined.
* @var type $var Description. * @var string $callback The name of the function definition on the $component.
* @var type Optional $var Description. * @var int Optional $priority The priority at which the function should be fired.
* @var array Optional $accepted_args The collection 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 ) { private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
$hooks[] = array( $hooks[] = array(
'hook' => $hook, 'hook' => $hook,
'component' => $component, 'component' => $component,
'callback' => $callback, 'callback' => $callback,
'priority' => $priority 'priority' => $priority,
'accepted_args' => $accepted_args
); );
return $hooks; return $hooks;
@ -107,28 +115,18 @@ class Plugin_Name_Loader {
} }
/** /**
* Short description. (use period) * Register the filters and actions with WordPress.
*
* Long description.
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function run() { public function run() {
/**
* TODO:
* This function is used to define the various hooks that are shared in the
* both the dashboard and the public-facing areas of the plugin. This is
* achieved via dependency injection by passing an instance of Plugin_Name
* into this class.
*/
foreach ( $this->filters as $hook ) { foreach ( $this->filters as $hook ) {
add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'] ); add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
} }
foreach ( $this->actions as $hook ) { foreach ( $this->actions as $hook ) {
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'] ); add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
} }
} }

View file

@ -1,11 +1,15 @@
<?php <?php
/** /**
* Short Description (no period) * The core plugin file
* *
* Long Description. * This is the core plugin file that is used to define internationalization,
* dashboard-specific hooks, and public-facing site hooks.
* *
* @link http://example.com/ * Also maintains the unique identifier of this plugin as well as the current
* version of the plugin.
*
* @link http://example.com
* @since 1.0.0 * @since 1.0.0
* *
* @package Plugin_Name * @package Plugin_Name
@ -25,34 +29,39 @@
class Plugin_Name { class Plugin_Name {
/** /**
* Short Description. (use period) * The loader that's responsible for maintaining and registering all hooks that power
* the plugin.
* *
* @since 1.0.0 * @since 1.0.0
* @access (private, protected, or public) * @access protected
* @var type $var Description. * @var type Plugin_Name_Loader Maintains and registers all hooks for the plugin.
*/ */
protected $loader; protected $loader;
/** /**
* Short Description. (use period) * The unique identifier of this plugin.
* *
* @since 1.0.0 * @since 1.0.0
* @access (private, protected, or public) * @access protected
* @var type $var Description. * @var string $plugin_slug The slug used to uniquely identify this plugin.
*/ */
protected $plugin_slug; protected $plugin_slug;
/** /**
* Short Description. (use period) * The current version of the plugin.
* *
* @since 1.0.0 * @since 1.0.0
* @access (private, protected, or public) * @access protected
* @var type $var Description. * @var string $version The current version of the plugin.
*/ */
protected $version; protected $version;
/** /**
* Short Description. (use period) * Define the core functionality of the plugin.
*
* Set the plugin slug 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
* the public-facing side of the site.
* *
* @since 1.0.0 * @since 1.0.0
*/ */
@ -69,12 +78,20 @@ class Plugin_Name {
} }
/** /**
* Short Description. (use period) * Load the required dependencies for this plugin.
* *
* Long Description. * 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 dashboard.
* - 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 * @since 1.0.0
* @access (for functions: only use if private) * @access private
*/ */
private function load_dependencies() { private function load_dependencies() {
@ -106,57 +123,57 @@ class Plugin_Name {
} }
/** /**
* Short Description. (use period) * Define the locale for this plugin for internationalization.
* *
* Long Description. * Uses the Plugin_Name_i18n class in order to set the domain and to register the hook
* with WordPress.
* *
* @since 1.0.0 * @since 1.0.0
* @access (for functions: only use if private) * @access private
*/ */
private function set_locale() { private function set_locale() {
$plugin_i18n = new Plugin_Name_i18n(); $plugin_i18n = new Plugin_Name_i18n();
$plugin_i18n->set_domain( $this->get_plugin_slug() ); $plugin_i18n->set_domain( $this->get_plugin_slug() );
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
} }
/** /**
* Short Description. (use period) * Register all of the hooks related to the dashboard functionality
* * of the plugin.
* Long Description.
* *
* @since 1.0.0 * @since 1.0.0
* @access (for functions: only use if private) * @access private
*/ */
private function define_admin_hooks() { private function define_admin_hooks() {
$plugin_admin = new Plugin_Name_Admin( $this->get_version() ); $plugin_admin = new Plugin_Name_Admin( $this->get_version() );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
} }
/** /**
* Short Description. (use period) * Register all of the hooks related to the public-facing functionality
* * of the plugin.
* Long Description.
* *
* @since 1.0.0 * @since 1.0.0
* @access (for functions: only use if private) * @access private
*/ */
private function define_public_hooks() { private function define_public_hooks() {
$plugin_public = new Plugin_Name_Public( $this->get_version() ); $plugin_public = new Plugin_Name_Public( $this->get_version() );
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); $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_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
} }
/** /**
* Short Description. (use period) * Execute the loader to execute all of the hooks with WordPress.
*
* Long Description.
* *
* @since 1.0.0 * @since 1.0.0
*/ */
@ -165,36 +182,31 @@ class Plugin_Name {
} }
/** /**
* Short Description. (use period) * The slug of the plugin used to uniquely identify it within the context of
* * WordPress and to define internationalization functionality.
* Long Description.
* *
* @since 1.0.0 * @since 1.0.0
* @return type Description * @return string The slug of the plugin.
*/ */
public function get_plugin_slug() { public function get_plugin_slug() {
return $this->plugin_slug; return $this->plugin_slug;
} }
/** /**
* Short Description. (use period) * The reference to the class that orchestrates the hooks with the plugin.
*
* Long Description.
* *
* @since 1.0.0 * @since 1.0.0
* @return type Description * @return Plugin_Name_Loader Orchestrates the hooks of the plugin.
*/ */
public function get_loader() { public function get_loader() {
return $this->loader; return $this->loader;
} }
/** /**
* Short Description. (use period) * Retrieve the version number of the plugin.
*
* Long Description.
* *
* @since 1.0.0 * @since 1.0.0
* @return type Description * @return string The version number of the plugin.
*/ */
public function get_version() { public function get_version() {
return $this->version; return $this->version;

View file

@ -24,30 +24,27 @@
class Plugin_Name_Public { class Plugin_Name_Public {
/** /**
* Short description. (use period) * The version of this plugin.
* *
* @since 1.0.0 * @since 1.0.0
* @access private * @access private
* @var type $var Description. * @var string $version The current version of this plugin.
*/ */
private $version; private $version;
/** /**
* Short description. (use period) * Initialize the class and set its properties.
*
* Long description.
* *
* @since 1.0.0 * @since 1.0.0
* @param float $version TODO * @access public
* @var string $version The version of this plugin.
*/ */
public function __construct( $version ) { public function __construct( $version ) {
$this->version = $version; $this->version = $version;
} }
/** /**
* Short description. (use period) * Register the stylesheets for the public-facing side of the site.
*
* Long description.
* *
* @since 1.0.0 * @since 1.0.0
*/ */
@ -70,9 +67,7 @@ class Plugin_Name_Public {
} }
/** /**
* Short description. (use period) * Register the stylesheets for the public-facing side of the site.
*
* Long description.
* *
* @since 1.0.0 * @since 1.0.0
*/ */