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

Improving JavaScript sources, adding references to Filters and Actions, and removing locale constant (WordPress requires a string parameter)

This commit is contained in:
Tom McFarlin 2011-12-02 23:28:54 -05:00
parent 029ced6dea
commit efb0a5b275
3 changed files with 56 additions and 29 deletions

View file

@ -1,3 +1,3 @@
jQuery(function($) { (function($) {
// Place your administration-specific code here // Place your administration-specific code here
}); })(jQuery);

View file

@ -1,3 +1,3 @@
jQuery(function($) { (function($) {
// Place your public facing JavaScript here // Place your public facing JavaScript here
}); })(jQuery);

View file

@ -6,27 +6,37 @@ Description: TODO
Version: 1.0 Version: 1.0
Author: TODO Author: TODO
Author URI: TODO Author URI: TODO
Author Email: TODO
License: License:
Copyright 2011 TODO (email@domain.com) Copyright 2011 TODO (email@domain.com)
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation. published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
// TODO: rename this class to a proper name for yuour plugin // TODO: rename this class to a proper name for yuour plugin
class TODO { class PluginName {
/**
* TODO: update these values to reflect the name, locale, and slug
* of your plugin.
*/
const name = 'Plugin Name';
const slug = 'plugin-name-slug';
/*--------------------------------------------* /*--------------------------------------------*
* Constructor * Constructor
@ -42,6 +52,9 @@ class TODO {
load_plugin_textdomain( PLUGIN_LOCALE, false, dirname( plugin_basename( __FILE__ ) ) . '/lang' ); load_plugin_textdomain( PLUGIN_LOCALE, false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
// Load JavaScript and stylesheets
$this->register_scripts_and_styles();
/* /*
* TODO: * TODO:
* Define the custom functionality for your plugin. The first parameter of the * Define the custom functionality for your plugin. The first parameter of the
@ -65,6 +78,10 @@ class TODO {
/** /**
* Note: Actions are points in the execution of a page or process * Note: Actions are points in the execution of a page or process
* lifecycle that WordPress fires. * lifecycle that WordPress fires.
*
* WordPress Actions: http://codex.wordpress.org/Plugin_API#Actions
* Action Reference: http://codex.wordpress.org/Plugin_API/Action_Reference
*
*/ */
function action_method_name() { function action_method_name() {
// TODO define your action method here // TODO define your action method here
@ -73,6 +90,10 @@ class TODO {
/** /**
* Note: Filters are points of execution in which WordPress modifies data * Note: Filters are points of execution in which WordPress modifies data
* before saving it or sending it to the browser. * before saving it or sending it to the browser.
*
* WordPress Filters: http://codex.wordpress.org/Plugin_API#Filters
* Filter Reference: http://codex.wordpress.org/Plugin_API/Filter_Reference
*
*/ */
function filter_method_name() { function filter_method_name() {
// TODO define your filter method here // TODO define your filter method here
@ -87,17 +108,6 @@ class TODO {
* the plugin. * the plugin.
*/ */
private function init_plugin_constants() { private function init_plugin_constants() {
/* TODO
*
* This provides the unique identifier for your plugin used in
* localizing the strings used throughout.
*
* For example: wordpress-widget-boilerplate-locale.
*/
if ( !defined( 'PLUGIN_LOCALE' ) ) {
define( 'PLUGIN_LOCALE', 'plugin-name-locale' );
} // end if
/* TODO /* TODO
* *
@ -126,6 +136,20 @@ class TODO {
} // end init_plugin_constants } // end init_plugin_constants
/**
* Registers and enqueues stylesheets for the administration panel and the
* public facing site.
*/
private function register_scripts_and_styles() {
if ( is_admin() ) {
$this->load_file( plugin_dir_path(__FILE__) . '/js/admin.js', true );
$this->load_file( plugin_dir_path(__FILE__) . '/css/admin.css' );
} else {
$this->load_file( plugin_dir_path(__FILE__) . '/js/widget.js', true );
$this->load_file( plugin_dir_path(__FILE__) . '/css/widget.css' );
} // end if/else
} // end register_scripts_and_styles
/** /**
* Helper function for registering and loading scripts and styles. * Helper function for registering and loading scripts and styles.
* *
@ -134,8 +158,10 @@ class TODO {
* @is_script Optional argument for if the incoming file_path is a JavaScript source file. * @is_script Optional argument for if the incoming file_path is a JavaScript source file.
*/ */
private function load_file( $name, $file_path, $is_script = false ) { private function load_file( $name, $file_path, $is_script = false ) {
$url = WP_PLUGIN_URL . $file_path; $url = WP_PLUGIN_URL . $file_path;
$file = WP_PLUGIN_DIR . $file_path; $file = WP_PLUGIN_DIR . $file_path;
if( file_exists( $file ) ) { if( file_exists( $file ) ) {
if( $is_script ) { if( $is_script ) {
wp_register_script( $name, $url ); wp_register_script( $name, $url );
@ -145,9 +171,10 @@ class TODO {
wp_enqueue_style( $name ); wp_enqueue_style( $name );
} // end if } // end if
} // end if } // end if
} // end _load_file } // end _load_file
} // end class } // end class
// TODO: update the instantiation call of your plugin to the name given at the class definition // TODO: update the instantiation call of your plugin to the name given at the class definition
new TODO(); new PluginName();
?> ?>