Skip to content

Commit

Permalink
v1.0.3
Browse files Browse the repository at this point in the history
* 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
* 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"
  • Loading branch information
Log1x committed Mar 28, 2020
1 parent e452b33 commit 99d9b3d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 27 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/poet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
73 changes: 47 additions & 26 deletions src/Poet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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', [])
);
}
});
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 99d9b3d

Please sign in to comment.