darrenjacoby / intervention

WordPress plugin to configure wp-admin and application state using a single config file.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CPT registration - add support for 'supports' new array of arguments, which leads the way to adding 'template' support

grahammtbr opened this issue · comments

This is more about the second item (yeah, I'm finally starting to deal with Gutenberg for CPT's), but the format it accepts is the same as the newly optional array of arguments in the supports key. Neither work, an array to string conversion error is returned. I tried to add a Register->setTemplate() method figuring I could mimic the setSupports() method, but it doesn't support the nested arrays. Then I ended up spending too much time reading Laravel docs to figure out your code, so you get this instead of a PR.

There's no rush on this, I can still add my CPT's the "old fashioned way"!

Example:

'supports' => [
    'title',
    'editor',
    'thumbnail',
    [ 'my_feature', [                // newly added support, likely for Gutenberg
	  'field' => 'value',
    ] ],
 ],

'template' => [                     // added with Gutenberg, but wasn't documented until recently
     [ 'core/paragraph', [
           'placeholder' => 'Add a description...',
     ]  ],
],
'template_lock' => 'all',

https://developer.wordpress.org/reference/functions/register_post_type/#changelog
https://core.trac.wordpress.org/browser/tags/5.6/src/wp-includes/class-wp-post-type.php#L395

Yea, I may need to relook how arrays are handled for registering post types and taxonomies. Perhaps an array helper function so that it helps with contributions, and a solution that adapts to future possible attributes better.

I'll look into the options over this coming week.

@grahammtbr I still need to apply this to the post type update method, however if you're registering a custom post type via Intervention, then you can pull down the latest push and give it a go.

Reference d181fe7

I'll test this shortly.

Both register and update should be working now. (eg. application.posts.post.template = [...a sickening amount of arrays])

Just noticed from the original message that I need to add recursive array support to “supports” still

@grahammtbr

This should be working now, and will be far more robust and future proof. Removed some of the array manipulation for the application config to avoid unwanted side effects.

Changes; 7fe348d

And with that I think we're close to a stable 2.0.0 release now!