mirror of
https://github.com/inretio/WordPress-Plugin-Boilerplate
synced 2024-12-23 04:13:53 +02:00
Removing constants, updating documentation for activation/deactivation function, adding TODO's
This commit is contained in:
parent
0957a12af4
commit
d62ab3343e
1 changed files with 40 additions and 69 deletions
109
plugin.php
109
plugin.php
|
@ -29,18 +29,6 @@ License:
|
||||||
// TODO: rename this class to a proper name for yuour plugin
|
// TODO: rename this class to a proper name for yuour plugin
|
||||||
class PluginName {
|
class PluginName {
|
||||||
|
|
||||||
/*--------------------------------------------*
|
|
||||||
* Constants
|
|
||||||
*--------------------------------------------*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: update these values to reflect the name and slug of your plugin.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const name = 'Plugin Name';
|
|
||||||
|
|
||||||
const slug = 'plugin-name-slug';
|
|
||||||
|
|
||||||
/*--------------------------------------------*
|
/*--------------------------------------------*
|
||||||
* Constructor
|
* Constructor
|
||||||
*--------------------------------------------*/
|
*--------------------------------------------*/
|
||||||
|
@ -50,13 +38,11 @@ class PluginName {
|
||||||
*/
|
*/
|
||||||
function __construct() {
|
function __construct() {
|
||||||
|
|
||||||
// Define constants used throughout the plugin
|
// TODO: replace "plugin-name-locale" with a unique value for your plugin
|
||||||
$this->init_plugin_constants();
|
load_plugin_textdomain( 'plugin-name-locale', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
|
||||||
|
|
||||||
load_plugin_textdomain( PLUGIN_LOCALE, false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
|
|
||||||
|
|
||||||
// Load JavaScript and stylesheets
|
// Load JavaScript and stylesheets
|
||||||
$this->register_scripts_and_styles();
|
$this->register_scripts_and_styles();
|
||||||
|
|
||||||
register_activation_hook( __FILE__, array( &$this, 'activate' ) );
|
register_activation_hook( __FILE__, array( &$this, 'activate' ) );
|
||||||
register_deactivation_hook( __FILE__, array( &$this, 'deactivate' ) );
|
register_deactivation_hook( __FILE__, array( &$this, 'deactivate' ) );
|
||||||
|
@ -77,19 +63,23 @@ class PluginName {
|
||||||
|
|
||||||
} // end constructor
|
} // end constructor
|
||||||
|
|
||||||
function activate($network_wide) {
|
/**
|
||||||
/*
|
* Fired when the plugin is activated.
|
||||||
TODO define activation functionality here
|
*
|
||||||
$network_wide is true if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog
|
* @params $network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog
|
||||||
*/
|
*/
|
||||||
}
|
function activate( $network_wide ) {
|
||||||
|
// TODO define activation functionality here
|
||||||
|
} // end activate
|
||||||
|
|
||||||
function deactivate($network_wide) {
|
/**
|
||||||
/*
|
* Fired when the plugin is deactivated.
|
||||||
TODO define deactivation functionality here
|
*
|
||||||
$network_wide is true if WPMU superadmin uses "Network Deactivate" action, false if WPMU is disabled or plugin is deactivated on an individual blog
|
* @params $network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog
|
||||||
*/
|
*/
|
||||||
}
|
function deactivate( $network_wide ) {
|
||||||
|
// TODO define deactivation functionality here
|
||||||
|
} // end deactivate
|
||||||
|
|
||||||
/*--------------------------------------------*
|
/*--------------------------------------------*
|
||||||
* Core Functions
|
* Core Functions
|
||||||
|
@ -123,51 +113,26 @@ class PluginName {
|
||||||
* Private Functions
|
* Private Functions
|
||||||
*---------------------------------------------*/
|
*---------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes constants used for convenience throughout
|
|
||||||
* the plugin.
|
|
||||||
*/
|
|
||||||
private function init_plugin_constants() {
|
|
||||||
|
|
||||||
/* TODO
|
|
||||||
*
|
|
||||||
* Define this as the name of your plugin. This is what shows
|
|
||||||
* in the Widgets area of WordPress.
|
|
||||||
*
|
|
||||||
* For example: WordPress Widget Boilerplate.
|
|
||||||
*/
|
|
||||||
if ( !defined( 'PLUGIN_NAME' ) ) {
|
|
||||||
define( 'PLUGIN_NAME', self::name );
|
|
||||||
} // end if
|
|
||||||
|
|
||||||
/* TODO
|
|
||||||
*
|
|
||||||
* this is the slug of your plugin used in initializing it with
|
|
||||||
* the WordPress API.
|
|
||||||
|
|
||||||
* This should also be the
|
|
||||||
* directory in which your plugin resides. Use hyphens.
|
|
||||||
*
|
|
||||||
* For example: wordpress-widget-boilerplate
|
|
||||||
*/
|
|
||||||
if ( !defined( 'PLUGIN_SLUG' ) ) {
|
|
||||||
define( 'PLUGIN_SLUG', self::slug );
|
|
||||||
} // end if
|
|
||||||
|
|
||||||
} // end init_plugin_constants
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers and enqueues stylesheets for the administration panel and the
|
* Registers and enqueues stylesheets for the administration panel and the
|
||||||
* public facing site.
|
* public facing site.
|
||||||
*/
|
*/
|
||||||
private function register_scripts_and_styles() {
|
private function register_scripts_and_styles() {
|
||||||
|
|
||||||
if ( is_admin() ) {
|
if ( is_admin() ) {
|
||||||
$this->load_file( self::slug . '-admin-script', '/js/admin.js', true );
|
|
||||||
$this->load_file( self::slug . '-admin-style', '/css/admin.css' );
|
// TODO replace 'plugin-slug-' with a unique value for your plugin
|
||||||
|
$this->load_file( 'plugin-slug-admin-script', '/js/admin.js', true );
|
||||||
|
$this->load_file( 'plugin-slug-admin-style', '/css/admin.css' );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->load_file( self::slug . '-script', '/js/widget.js', true );
|
|
||||||
$this->load_file( self::slug . '-style', '/css/widget.css' );
|
// TODO replace 'plugin-slug-' with a unique value for your plugin
|
||||||
|
$this->load_file( 'plugin-slug-script', '/js/widget.js', true );
|
||||||
|
$this->load_file( 'plugin-slug-style', '/css/widget.css' );
|
||||||
|
|
||||||
} // end if/else
|
} // end if/else
|
||||||
|
|
||||||
} // end register_scripts_and_styles
|
} // end register_scripts_and_styles
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -179,17 +144,23 @@ class PluginName {
|
||||||
*/
|
*/
|
||||||
private function load_file( $name, $file_path, $is_script = false ) {
|
private function load_file( $name, $file_path, $is_script = false ) {
|
||||||
|
|
||||||
$url = plugins_url($file_path, __FILE__);
|
$url = plugins_url( $file_path, __FILE__ );
|
||||||
$file = plugin_dir_path(__FILE__) . $file_path;
|
$file = plugin_dir_path( __FILE__ ) . $file_path;
|
||||||
|
|
||||||
if( file_exists( $file ) ) {
|
if( file_exists( $file ) ) {
|
||||||
|
|
||||||
if( $is_script ) {
|
if( $is_script ) {
|
||||||
wp_register_script( $name, $url, array('jquery') );
|
|
||||||
|
wp_register_script( $name, $url, array( 'jquery' ) );
|
||||||
wp_enqueue_script( $name );
|
wp_enqueue_script( $name );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
wp_register_style( $name, $url );
|
wp_register_style( $name, $url );
|
||||||
wp_enqueue_style( $name );
|
wp_enqueue_style( $name );
|
||||||
|
|
||||||
} // end if
|
} // end if
|
||||||
|
|
||||||
} // end if
|
} // end if
|
||||||
|
|
||||||
} // end load_file
|
} // end load_file
|
||||||
|
|
Loading…
Reference in a new issue