Created
September 25, 2012 03:04
-
-
Save twright/3779749 to your computer and use it in GitHub Desktop.
Basic outline of a wordpress plugin
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 | |
class ExampleWordpressPlugin { | |
const PLUGIN_NAME = 'example-plugin'; | |
const PLUGIN_VERSION = '0.01'; | |
/** | |
* The constructor of the class. | |
*/ | |
public function __construct() { | |
$this->hooks(); | |
} | |
/** | |
* Include the required scripts / styles for the plugin. | |
*/ | |
public function scripts_and_styles() { | |
// Include the CSS | |
wp_enqueue_style( self::PLUGIN_NAME . '-style', | |
plugins_url( 'css/style.css', __FILE__ ), array(), | |
self::PLUGIN_VERSION, 'all' ); | |
// Include the JavaScript | |
wp_enqueue_script( self::PLUGIN_NAME . '-script', | |
plugins_url( 'js/script.js' ), array( 'jquery' ), | |
self::PLUGIN_VERSION, true ); | |
} | |
/** | |
* Register hooks with WordPress to call the desired functions when | |
* required. | |
*/ | |
public function hooks() { | |
add_action( 'wp_enqueue_scripts', | |
array( $this, 'scripts_and_styles' ) ); | |
} | |
} | |
new ExampleWordpressPlugin(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment