-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add WordPress Area CPT #15014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add WordPress Area CPT #15014
Conversation
lib/widgets.php
Outdated
| 'wp_area', | ||
| array( | ||
| 'labels' => array( | ||
| 'name' => _x( 'WordPress Area', 'post type general name' ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block Area is probably a better name like suggested by @mapk
lib/widgets.php
Outdated
| 'public' => false, | ||
| 'show_ui' => true, | ||
| 'show_in_menu' => false, | ||
| 'show_in_rest' => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we following-up with the REST endpoints PR? we might want to disable the built-in ones if it's the case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My plan was to leave the built-in ones. The REST endpoints that we are following up are specific to widget areas, and they receive as the identifier a widget area name. What if I want to change wp_area by its id (numeric)? What if I want to do other actions (list all areas widget/navigations..., search areas or use other nice features from the posts endpoint)?
It seemed to allow direct access to the wp_areas endpoint did have big cons and had some advantages.
The new endpoint may end up referencing the same thing but it references using a different identifier, and the new endpoint is widget specific (returning widget specific information besides the post itself being referenced)
lib/widgets.php
Outdated
| 'item_updated' => __( 'WordPress area updated.' ), | ||
| ), | ||
| 'public' => false, | ||
| 'show_ui' => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, show_ui should be false, it is true to make testing easier.
61f7fd7 to
f4c17ed
Compare
f4c17ed to
a64d42a
Compare
lib/widgets.php
Outdated
| add_filter( 'block_editor_settings', 'gutenberg_legacy_widget_settings' ); | ||
|
|
||
|
|
||
| function create_wp_area_post_type() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be prefixed with gutenberg_ ? I'd suggest it, unless the plan is for this function to be ported upstream directly, which I don't think is how it would be adopted.
lib/widgets.php
Outdated
| add_filter( 'block_editor_settings', 'gutenberg_legacy_widget_settings' ); | ||
|
|
||
|
|
||
| function create_wp_area_post_type() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing PHPDoc?
a64d42a to
1868ca2
Compare
|
Hi @aduth, thank you for the review, your comments were addressed. |
1868ca2 to
db638b0
Compare
db638b0 to
6c278e6
Compare
|
Do you think we can start landing some of these widgets related PRs to move forward? |
Hi @youknowriad, yes I think widget related PR's should be merged allowing us to have a prototype and try different approaches if we find problems. |
| 'public' => false, | ||
| 'show_ui' => false, | ||
| 'show_in_menu' => false, | ||
| 'show_in_rest' => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we assign a rest_base ? The post type wp_block was defined with rest_base of 'blocks' (source), following the general pattern of exposing on the plural form of the base name "block".
| 'show_in_rest' => true, | |
| 'show_in_rest' => true, | |
| 'rest_base' => 'areas', |
Alternatively, the original RFC proposed the base 'widget-areas':
Perhaps 'block-areas' if that's the desired naming, per prior review comments in this pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I updated the rest_base to 'block-areas'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also wonder if it's worth considering to include in an experimental namespace, like at #15015
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In CPT's adding a namespace does not work. I used __experimental/block-areas as the rest base which works well but is a little bit "hacky". I can revert this change if people prefer the previous version without "__experimental/".
lib/widgets.php
Outdated
| 'capabilities' => array( | ||
| // You need to be able to edit posts, in order to read blocks in their raw form. | ||
| 'read' => 'edit_posts', | ||
| // You need to be able to publish posts, in order to create blocks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These comments seem to be copy-paste from the registration of 'wp_block', but aren't representative of what the actual values are (i.e. you need to be able to edit theme options, not publish posts).
Are they necessary at all to include? At least need to be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree I don't think comments are required in this situation and I removed them.
6c278e6 to
13c93a3
Compare
aduth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a related comment on the Widgets RFC at #14812 (comment) which, if considered, might call into question whether this post type be necessary at all.
That being said, I'd like to see some iterations in this space, and the proposed implementation looks in good shape for the current proposal.
| 'public' => false, | ||
| 'show_ui' => false, | ||
| 'show_in_menu' => false, | ||
| 'show_in_rest' => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also wonder if it's worth considering to include in an experimental namespace, like at #15015
13c93a3 to
1358940
Compare
Description
This PR is straight to the point and just proposes an implementation for the wp_area CPT required to implement the widgets RFC described in https://github.com/WordPress/gutenberg/blob/add/blocks-in-widget-areas-rfc/docs/rfcs/blocks-in-widget-areas.md
How has this been tested?
I verified the CPT works as expected by going to /edit.php?post_type=wp_area (this probably should be disabled but it is useful for testing).
I verified I can use the rest API with this CPT e.g: