diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b889af..95db84c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## v1.0.3 (03/28/19) + +### Bug fixes + +- fix(block): Fix namespace TextDomain fallback returning empty +- fix(post): Fix registering posts with only a string +- fix(taxonomy): Fix registering taxonomies with only a string + +### Enhancements + +- enhance(poet): Clean up and seperate post type and taxonomy registration methods +- enhance(poet): Use `Arr::get()` for handling array getters with fallback values +- chore(config): Lowercase instances of "block" + ## v1.0.2 (03/25/19) ### Enhancements diff --git a/config/poet.php b/config/poet.php index 58595fe..0bc8eb7 100644 --- a/config/poet.php +++ b/config/poet.php @@ -55,7 +55,7 @@ | registering the block with the editor. If no namespace is provided, | the current theme text domain will be used instead. | - | Given the Block `sage/accordion`, your Block view would be located at: + | Given the block `sage/accordion`, your block view would be located at: | ↪ `views/blocks/accordion.blade.php` | | Block views have the following variables available: diff --git a/src/Poet.php b/src/Poet.php index 648b713..d447e06 100644 --- a/src/Poet.php +++ b/src/Poet.php @@ -5,11 +5,12 @@ use WP_Post_Type; use WP_Taxonomy; use Illuminate\Support\Str; +use Illuminate\Support\Arr; class Poet { /** - * Returns the Poet configuration. + * The Poet configuration. * * @var array */ @@ -21,53 +22,73 @@ class Poet * @param array $config * @return void */ - public function __construct($config) + public function __construct($config = []) { $this->config = collect($config); - add_action('init', function () { - $this->registerTypes(); + add_filter('init', function () { + $this->registerPosts(); + $this->registerTaxonomies(); $this->registerBlocks(); }, 20); } /** - * Register the configured post types and taxomonies using Extended CPTs. + * Register the configured post types using Extended CPTs. * ↪ https://github.com/johnbillion/extended-cpts * - * If a post type / taxonomy already exists, the object will be modified instead. + * If a post type already exists, the object will be modified instead. * ↪ https://codex.wordpress.org/Function_Reference/get_post_type_object - * ↪ https://developer.wordpress.org/reference/functions/get_taxonomy/ * * @return void */ - protected function registerTypes() + protected function registerPosts() { - $this->config->only(['post', 'taxonomy'])->each(function ($value, $type) { - foreach ($value as $key => $config) { - $config = collect($config); + $this->config->only('post')->each(function ($post) { + foreach ($post as $key => $value) { + if (empty($key)) { + return register_extended_post_type(...Arr::wrap($value)); + } if ($this->exists($key)) { - if ($config->isEmpty()) { - return; - } + return $this->modify($key, $value); + } + + return register_extended_post_type( + $key, + Arr::get($value, 'links', 'post'), + Arr::get($value, 'labels', []) + ); + } + }); + } - return $this->modify($key, $config->all()); + /** + * Register the configured taxomonies using Extended CPTs. + * ↪ https://github.com/johnbillion/extended-cpts + * + * If a taxonomy already exists, the object will be modified instead. + * ↪ https://developer.wordpress.org/reference/functions/get_taxonomy/ + * + * @return void + */ + protected function registerTaxonomies() + { + $this->config->only('taxonomy')->each(function ($taxonomy) { + foreach ($taxonomy as $key => $value) { + if (empty($key)) { + return register_extended_taxonomy($value, 'post'); } - if (Str::is($type, 'taxonomy')) { - return register_extended_taxonomy( - $key, - $config->get('links', 'post'), - $config->all(), - $config->get('labels', []) - ); + if ($this->exists($key)) { + return $this->modify($key, $value); } - return register_extended_post_type( + return register_extended_taxonomy( $key, - $config->all(), - $config->get('labels', []) + Arr::get($value, 'links', 'post'), + $value, + Arr::get($value, 'labels', []) ); } }); @@ -166,7 +187,7 @@ protected function verify($object) protected function namespace($delimiter = '/') { return (Str::slug( - wp_get_theme()->get('text_domain') + wp_get_theme()->get('TextDomain') ) ?? 'sage') . $delimiter; }