diff --git a/classes/class-starter-plugin-post-type.php b/classes/class-starter-plugin-post-type.php index ac46394..a0ac5a2 100644 --- a/classes/class-starter-plugin-post-type.php +++ b/classes/class-starter-plugin-post-type.php @@ -139,8 +139,10 @@ public function register_post_type () { * @return void */ public function register_taxonomy () { - $this->taxonomies['thing-category'] = new Starter_Plugin_Taxonomy(); // Leave arguments empty, to use the default arguments. - $this->taxonomies['thing-category']->register(); + foreach ( $taxonomies as $taxonomy ) : + $taxonomy = new Starter_Plugin_Taxonomy( esc_attr( $this->post_type ), $taxonomy, '', '', array() ); // Leave arguments empty, to use the default arguments. + $taxonomy->register(); + endforeach; } // End register_taxonomy() /** @@ -169,7 +171,7 @@ public function register_custom_columns ( $column_name, $id ) { * @access public * @param array $defaults * @since 1.0.0 - * @return void + * @return array $defaults */ public function register_custom_column_headings ( $defaults ) { $new_columns = array( 'image' => __( 'Image', 'starter-plugin' ) ); @@ -413,4 +415,4 @@ private function flush_rewrite_rules () { public function ensure_post_thumbnails_support () { if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); } } // End ensure_post_thumbnails_support() -} // End Class \ No newline at end of file +} // End Class diff --git a/classes/class-starter-plugin-taxonomy.php b/classes/class-starter-plugin-taxonomy.php index 93fa39c..49a3978 100644 --- a/classes/class-starter-plugin-taxonomy.php +++ b/classes/class-starter-plugin-taxonomy.php @@ -73,6 +73,8 @@ public function __construct ( $post_type = 'thing', $token = 'thing-category', $ if ( '' == $this->plural ) $this->plural = __( 'Categories', 'starter-plugin' ); $this->args = wp_parse_args( $args, $this->_get_default_args() ); + + add_action( 'init', array( $this, 'register' ) ); } // End __construct() /** @@ -117,4 +119,4 @@ public function register () { register_taxonomy( esc_attr( $this->token ), esc_attr( $this->post_type ), (array)$this->args ); } // End register() } // End Class -?> \ No newline at end of file +?> diff --git a/starter-plugin.php b/starter-plugin.php index 0fc1457..4a170d0 100644 --- a/starter-plugin.php +++ b/starter-plugin.php @@ -108,6 +108,17 @@ final class Starter_Plugin { */ public $post_types = array(); // Post Types - End + + // Taxonomies - Start + /** + * The taxonomies we're registering. + * @var array + * @access public + * @since 1.0.0 + */ + public $taxonomies = array(); + // Taxonomies - End + /** * Constructor function. * @access public @@ -136,6 +147,10 @@ public function __construct () { // Register an example post type. To register other post types, duplicate this line. $this->post_types['thing'] = new Starter_Plugin_Post_Type( 'thing', __( 'Thing', 'starter-plugin' ), __( 'Things', 'starter-plugin' ), array( 'menu_icon' => 'dashicons-carrot' ) ); // Post Types - End + + //Register an example taxonomy. To register more taxonomies, duplicate this line. + $this->taxonomies['taxonomy'] = new Starter_Plugin_Taxonomy( 'thing', 'taxonomy_name', __( 'Taxonomy Name', 'starter-plugin' ), __( 'Taxonomy Names', 'starter-plugin' ) ); + register_activation_hook( __FILE__, array( $this, 'install' ) ); add_action( 'init', array( $this, 'load_plugin_textdomain' ) );