mirror of
https://github.com/inretio/WordPress-Plugin-Boilerplate
synced 2024-12-22 20:03: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:
parent
029ced6dea
commit
efb0a5b275
3 changed files with 56 additions and 29 deletions
|
@ -1,3 +1,3 @@
|
||||||
jQuery(function($) {
|
(function($) {
|
||||||
// Place your administration-specific code here
|
// Place your administration-specific code here
|
||||||
});
|
})(jQuery);
|
|
@ -1,3 +1,3 @@
|
||||||
jQuery(function($) {
|
(function($) {
|
||||||
// Place your public facing JavaScript here
|
// Place your public facing JavaScript here
|
||||||
});
|
})(jQuery);
|
53
plugin.php
53
plugin.php
|
@ -6,6 +6,7 @@ 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)
|
||||||
|
@ -26,7 +27,16 @@ License:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -88,17 +109,6 @@ class TODO {
|
||||||
*/
|
*/
|
||||||
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
|
||||||
*
|
*
|
||||||
* Define this as the name of your plugin. This is what shows
|
* Define this as the name of your plugin. This is what shows
|
||||||
|
@ -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();
|
||||||
?>
|
?>
|
Loading…
Reference in a new issue