Last active
December 27, 2019 00:42
-
-
Save johnregan3/5868f4349f825a9b50b9 to your computer and use it in GitHub Desktop.
Basic Demonstration of Using OOP in a WordPress Plugin
This file contains hidden or 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
/* | |
* Plugin Header... | |
* | |
* Note: This particular block of code won't actually run because it doesn't have | |
* the details of the register_post_type and register_taxonomy functions filled in. | |
*/ | |
class JR3_Books { | |
/** | |
* Fires all hooks for this plugin | |
*/ | |
static function setup() { | |
add_action( 'init', array( __CLASS__, 'register_books_cpt' ) ); | |
add_action( 'init', array( __CLASS__, 'register_genres_taxonomy' ) ); | |
} | |
/** | |
* Basic setup of a Custom Post Type | |
* @see http://codex.wordpress.org/Function_Reference/register_post_type | |
*/ | |
static function register_books_cpt() { | |
register_post_type( 'jr3_books', array(...) ); | |
} | |
/** | |
* Register Custom Taxonomy for this Custom Post Type | |
* @see http://codex.wordpress.org/Function_Reference/register_taxonomy | |
*/ | |
static function register_genres_taxonomy() { | |
register_taxonomy( 'jr3_genres', 'jr3_books', array(...) ); | |
} | |
} | |
//Load the plugin by firing the setup() method. | |
add_action( 'plugins_loaded', array( 'JR3_Books', 'setup' ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment