Created
October 19, 2016 12:35
-
-
Save Netzberufler/b33fe1407fd83ddf619115b9e44a2b6e to your computer and use it in GitHub Desktop.
WordPress Plugin Boilerplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Plugin Boilerplate | |
Plugin URI: https://themecoder.de/ | |
Description: My boilerplate for WordPress Plugins | |
Author: Thomas Weichselbaumer | |
Author URI: http://netzberufler.de | |
Version: 1.0 | |
Text Domain: plugin-boilerplate | |
Domain Path: /languages/ | |
License: GPL v3 | |
License URI: http://www.gnu.org/licenses/gpl-3.0.html | |
Plugin Boilerplate | |
Copyright(C) 2016, Thomas Weichselbaumer - kontakt@themecoder.de | |
*/ | |
// Exit if accessed directly. | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
/** | |
* Main Plugin_Boilerplate Class | |
* | |
* @package Plugin Boilerplate | |
*/ | |
class Plugin_Boilerplate { | |
/** | |
* Call all Functions to setup the Plugin | |
* | |
* @uses Plugin_Boilerplate::constants() Setup the constants needed | |
* @uses Plugin_Boilerplate::includes() Include the required files | |
* @uses Plugin_Boilerplate::setup_actions() Setup the hooks and actions | |
* @return void | |
*/ | |
static function setup() { | |
// Setup Constants. | |
self::constants(); | |
// Setup Translation. | |
add_action( 'plugins_loaded', array( __CLASS__, 'translation' ) ); | |
// Include Files. | |
self::includes(); | |
// Setup Action Hooks. | |
self::setup_actions(); | |
} | |
/** | |
* Setup plugin constants | |
* | |
* @return void | |
*/ | |
static function constants() { | |
// Define Plugin Name. | |
define( 'PLUGIN_BOILERPLATE_NAME', 'Plugin Boilerplate' ); | |
// Define Version Number. | |
define( 'PLUGIN_BOILERPLATE_VERSION', 1.0 ); | |
// Plugin Folder Path. | |
define( 'PLUGIN_BOILERPLATE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); | |
// Plugin Folder URL. | |
define( 'PLUGIN_BOILERPLATE_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); | |
// Plugin Root File. | |
define( 'PLUGIN_BOILERPLATE_PLUGIN_FILE', __FILE__ ); | |
} | |
/** | |
* Load Translation File | |
* | |
* @return void | |
*/ | |
static function translation() { | |
load_plugin_textdomain( 'plugin-boilerplate', false, dirname( plugin_basename( PLUGIN_BOILERPLATE_PLUGIN_FILE ) ) . '/languages/' ); | |
} | |
/** | |
* Include required files | |
* | |
* @return void | |
*/ | |
static function includes() { | |
// Include Admin Classes. | |
require_once PLUGIN_BOILERPLATE_PLUGIN_DIR . '/includes/admin/class-plugin-boilerplate-settings.php'; | |
require_once PLUGIN_BOILERPLATE_PLUGIN_DIR . '/includes/admin/class-plugin-boilerplate-settings-page.php'; | |
// Include Plugin Classes. | |
require_once PLUGIN_BOILERPLATE_PLUGIN_DIR . '/includes/class-plugin-features.php'; | |
} | |
/** | |
* Setup Action Hooks | |
* | |
* @see https://codex.wordpress.org/Function_Reference/add_action WordPress Codex | |
* @return void | |
*/ | |
static function setup_actions() { | |
// Enqueue Stylesheet. | |
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_styles' ) ); | |
} | |
/** | |
* Enqueue Stylesheet | |
* | |
* @return void | |
*/ | |
static function enqueue_styles() { | |
// Enqueue Plugin Stylesheet. | |
wp_enqueue_style( 'plugin-boilerplate', PLUGIN_BOILERPLATE_PLUGIN_URL . 'assets/css/plugin-boilerplate.css', array(), PLUGIN_BOILERPLATE_VERSION ); | |
} | |
} | |
// Run Plugin. | |
Plugin_Boilerplate::setup(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment