From 335655d07295c3c6fe9f62ed0edecc718a832422 Mon Sep 17 00:00:00 2001 From: Jon Ang Date: Mon, 2 Nov 2015 18:21:32 +0800 Subject: [PATCH 1/4] Update class-starter-plugin-taxonomy.php Allows the taxonomy class to be called directly instead of only through the post type registration --- classes/class-starter-plugin-taxonomy.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 +?> From 7552b396d3577c28828fb393fd15efd41bba5210 Mon Sep 17 00:00:00 2001 From: Jon Ang Date: Mon, 2 Nov 2015 18:28:21 +0800 Subject: [PATCH 2/4] Update starter-plugin.php Put an example of how to intiialise a new taxonomy directly instead of being dependent on the post type. --- starter-plugin.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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' ) ); From 7a51e30c8875d233aabd18b2ccd085e6d7862e84 Mon Sep 17 00:00:00 2001 From: Jon Ang Date: Mon, 2 Nov 2015 18:38:05 +0800 Subject: [PATCH 3/4] Update class-starter-plugin-post-type.php Previous taxonomy register call didn't actually call the class. This actually now allows the register_post_type function to also register taxonomies. --- classes/class-starter-plugin-post-type.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/classes/class-starter-plugin-post-type.php b/classes/class-starter-plugin-post-type.php index ac46394..b386adf 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() /** @@ -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 From 0f72e7d9ecf3e13874e86014b40a19acbc2d81c8 Mon Sep 17 00:00:00 2001 From: Jon Ang Date: Mon, 2 Nov 2015 18:41:31 +0800 Subject: [PATCH 4/4] Update class-starter-plugin-post-type.php Fixed php doc @return for non-void method --- classes/class-starter-plugin-post-type.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/class-starter-plugin-post-type.php b/classes/class-starter-plugin-post-type.php index b386adf..a0ac5a2 100644 --- a/classes/class-starter-plugin-post-type.php +++ b/classes/class-starter-plugin-post-type.php @@ -171,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' ) );