From cca540472f41b7f7f70c90926e4af8fd5c386b3b Mon Sep 17 00:00:00 2001 From: William Patton Date: Sun, 10 Feb 2019 14:45:13 +0000 Subject: [PATCH 1/7] Add a class constructor to handle setup of properties at instantiation. --- AbstractPostType.php | 24 +++++++++++++++++++----- changelog.md | 10 ++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/AbstractPostType.php b/AbstractPostType.php index bcaaad1..969fb73 100644 --- a/AbstractPostType.php +++ b/AbstractPostType.php @@ -7,7 +7,7 @@ * class before calling 'register'. * * @package PattonWebz Post Type Registration Class - * @version 0.2.0 + * @version 0.2.2-dev * @since 0.1.0 * @author William Patton * @copyright Copyright (c) 2018-2019, William Patton @@ -48,6 +48,22 @@ abstract class AbstractPostType { */ public $labels = []; + /** + * Sets up the properties for use when registering. + * + * @method __construct + * @since 0.2.2 + * @param array $args The array of args to use when registering the CPT. + * @param array $labels A custom labels array to use when registering the + * post. NOTE: If you are passing a custom $args array + * then this will not be included automatticaly so + * include it in $args['labels'] directly. + */ + public function __construct( array $args = [], array $labels = [] ) { + $this->labels = ( ! empty( $labels ) ) ? $labels : $this->get_labels(); + $this->args = ( ! empty( $args ) ) ? $args : $this->get_args(); + } + /** * Hook in and register the post type. * @@ -94,13 +110,11 @@ public function get_labels() { * @return array */ public function get_args() { - $labels = $this->get_labels(); - $name = ( isset( $labels['menu_name'] ) ) ? $labels['menu_name'] : ucfirst( $this->name ); + $name = ( isset( $labels['menu_name'] ) ) ? $labels['menu_name'] : $this->name; return ( ! empty( $this->args ) ) ? $this->args : [ 'post_type' => $name, - 'label' => $name, - 'labels' => $labels, + 'labels' => $this->labels, 'public' => true, ]; } diff --git a/changelog.md b/changelog.md index 8117b62..36293b4 100644 --- a/changelog.md +++ b/changelog.md @@ -22,3 +22,13 @@ _No documentation available about unreleased changes as of yet._ - When the `$name` property is used to backfill the `label` arg is has the first letter uppercased. - Post Types now register as `public` by default. + +## [0.2.1] - 2019-02-10 + +- Changed where the uppercase first letter when backfilling is done for 'label' + +## [0.2.2] - 2019-02-10 + +### Added + +- Added a class constructor method to handle setup of properties at instantiation for overriding defaults. From 1d853e13a1be2e8be7e3a2698d5a9167ffae427d Mon Sep 17 00:00:00 2001 From: William Patton Date: Tue, 26 Feb 2019 23:00:19 +0000 Subject: [PATCH 2/7] By default upercase the words in CPT name --- AbstractPostType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AbstractPostType.php b/AbstractPostType.php index 969fb73..7d3a41a 100644 --- a/AbstractPostType.php +++ b/AbstractPostType.php @@ -97,7 +97,7 @@ public function get_name() { public function get_labels() { return ( ! empty( $this->labels ) ) ? $this->labels : [ - 'name' => $this->name, + 'name' => ucwords( $this->name ), ]; } From 256bf6144f16dab93bf15437050f5e60d322e4e3 Mon Sep 17 00:00:00 2001 From: William Patton Date: Tue, 26 Feb 2019 23:06:38 +0000 Subject: [PATCH 3/7] Add @since tags to the properties --- AbstractPostType.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AbstractPostType.php b/AbstractPostType.php index 7d3a41a..3da9a5c 100644 --- a/AbstractPostType.php +++ b/AbstractPostType.php @@ -26,6 +26,7 @@ abstract class AbstractPostType { /** * The identifier for this post type. * + * @since 0.1.0 * @var string */ public $name = 'post'; @@ -35,6 +36,7 @@ abstract class AbstractPostType { * * NOTE: This is PHP 7+ only. * + * @since 0.1.0 * @var array */ public $args = []; @@ -44,6 +46,7 @@ abstract class AbstractPostType { * * NOTE: This is PHP 7+ only. * + * @since 0.1.0 * @var array */ public $labels = []; From 72fb438098dcc8cd2311be4dfcdd603290d05f37 Mon Sep 17 00:00:00 2001 From: William Patton Date: Tue, 26 Feb 2019 23:06:53 +0000 Subject: [PATCH 4/7] Add a property to hold icon to be used --- AbstractPostType.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/AbstractPostType.php b/AbstractPostType.php index 3da9a5c..58a534f 100644 --- a/AbstractPostType.php +++ b/AbstractPostType.php @@ -32,9 +32,15 @@ abstract class AbstractPostType { public $name = 'post'; /** - * The arguments used when registering this post type. + * Icon to use for this post type. * - * NOTE: This is PHP 7+ only. + * @since 0.2.2 + * @var string + */ + public $icon = 'dashicons-admin-post'; + + /** + * The arguments used when registering this post type. * * @since 0.1.0 * @var array @@ -44,8 +50,6 @@ abstract class AbstractPostType { /** * The arguments used when registering this post type. * - * NOTE: This is PHP 7+ only. - * * @since 0.1.0 * @var array */ From def2001c2a1dd23ac30300fd39541248cc7b2f3d Mon Sep 17 00:00:00 2001 From: William Patton Date: Tue, 26 Feb 2019 23:08:40 +0000 Subject: [PATCH 5/7] Add menu_icon to the default args array --- AbstractPostType.php | 1 + 1 file changed, 1 insertion(+) diff --git a/AbstractPostType.php b/AbstractPostType.php index 58a534f..05ca949 100644 --- a/AbstractPostType.php +++ b/AbstractPostType.php @@ -122,6 +122,7 @@ public function get_args() { return ( ! empty( $this->args ) ) ? $this->args : [ 'post_type' => $name, 'labels' => $this->labels, + 'menu_icon' => ( ! empty( $this->icon ) ) ? $this->icon : 'dashicons-admin-post', 'public' => true, ]; } From e7ca71fd0d1c9a187783c0866289264cd2af425a Mon Sep 17 00:00:00 2001 From: William Patton Date: Tue, 26 Feb 2019 23:09:01 +0000 Subject: [PATCH 6/7] Pass labels and names more clearly in args array --- AbstractPostType.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/AbstractPostType.php b/AbstractPostType.php index 05ca949..915a394 100644 --- a/AbstractPostType.php +++ b/AbstractPostType.php @@ -117,11 +117,13 @@ public function get_labels() { * @return array */ public function get_args() { - $name = ( isset( $labels['menu_name'] ) ) ? $labels['menu_name'] : $this->name; + $labels = $this->get_labels(); + $name = ( isset( $labels['menu_name'] ) ) ? $labels['menu_name'] : $this->name; return ( ! empty( $this->args ) ) ? $this->args : [ 'post_type' => $name, - 'labels' => $this->labels, + 'label' => $name, + 'labels' => $labels, 'menu_icon' => ( ! empty( $this->icon ) ) ? $this->icon : 'dashicons-admin-post', 'public' => true, ]; From 6a9c73c6a768c6ce27f6fc3ec5828f9347cb477a Mon Sep 17 00:00:00 2001 From: William Patton Date: Tue, 26 Feb 2019 23:10:09 +0000 Subject: [PATCH 7/7] Version bump to 0.2.2 --- AbstractPostType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AbstractPostType.php b/AbstractPostType.php index 915a394..11a5d92 100644 --- a/AbstractPostType.php +++ b/AbstractPostType.php @@ -7,7 +7,7 @@ * class before calling 'register'. * * @package PattonWebz Post Type Registration Class - * @version 0.2.2-dev + * @version 0.2.2 * @since 0.1.0 * @author William Patton * @copyright Copyright (c) 2018-2019, William Patton