WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 3 months ago

Last modified 3 months ago

#46261 closed defect (bug) (fixed)

Args for register_post_type() missing blocks $template.

Reported by: milana_cap Owned by: noisysocks
Milestone: 5.6 Priority: normal
Severity: normal Version:
Component: Editor Keywords: has-patch
Focuses: docs Cc:

Description

Blocks template is added through register_post_type() or register_post_type_args hook but it is not documented.

Attachments (4)

46261.patch (1.0 KB) - added by milana_cap 2 years ago.
46261.2.diff (971 bytes) - added by metalandcoffee 3 months ago.
Add template property to WP post type class
46261.3.diff (1.6 KB) - added by metalandcoffee 3 months ago.
Add template_lock property to WP post type class
46261.4.diff (1.6 KB) - added by metalandcoffee 3 months ago.
Fixing a typo in the previous patch. Sorry about that!

Download all attachments as: .zip

Change History (18)

@milana_cap
2 years ago

#1 @noisysocks
4 months ago

In 49041:

Documentation: Add 'template' arg documentation

Add inline documentation for the 'template' arg accepted by
register_post_type().

Props milana_cap.
See #46261.

#2 @noisysocks
4 months ago

  • Milestone changed from Awaiting Review to 5.6
  • Resolution set to fixed
  • Status changed from new to closed

#3 @joyously
4 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

This change doesn't seem to cover it. The register_post_type function simply stores the args in a WP_Post_Type object. That object has no property or method for a 'template'.
Listing a 'template' argument on this function doesn't document it sufficiently.

#4 @johnbillion
4 months ago

  • Keywords needs-patch added; has-patch removed

I agree, this doesn't help much. What can be done to improve the docs for this parameter?

#5 @metalandcoffee
3 months ago

The check for the template property is being performed in wp-admin/edit-form-blocks.php.

if ( ! empty( $post_type_object->template ) ) {
  $editor_settings['template']     = $post_type_object->template;
  $editor_settings['templateLock'] = ! empty( $post_type_object->template_lock ) ? $post_type_object->template_lock : false;
}

I think we should add the template property to the WP_Post_Type class. Then that would clear up the confusion that @joyously pointed out. Happy to do this if this is agreed upon...

@metalandcoffee
3 months ago

Add template property to WP post type class

This ticket was mentioned in Slack in #core by metalandcoffee. View the logs.


3 months ago

#7 @davidbaumwald
3 months ago

  • Keywords has-patch added; needs-patch removed

#8 @noisysocks
3 months ago

  • Owner set to noisysocks
  • Status changed from reopened to reviewing

Thanks for the revised patch @metalandcoffee. It applies cleanly and everything still works when I set template on a post type locally.

Two suggestions:

  1. Could you please also document the related template_lock argument and add a template_lock property to WP_Post_Type?
  1. Let's add a link to the relevant block editor documentation: https://developer.wordpress.org/block-editor/developers/block-api/block-templates/

@metalandcoffee
3 months ago

Add template_lock property to WP post type class

#9 @metalandcoffee
3 months ago

Hi @noisysocks ! I went ahead and updated the patch. Thanks for the great feedback.

@metalandcoffee
3 months ago

Fixing a typo in the previous patch. Sorry about that!

#10 @noisysocks
3 months ago

In 49492:

Editor: Add explicit template and template_lock attributes

Add and document the template and template_lock attributes on WP_Post_Type that
are used by the block editor.

Props metalandcoffee.
See #46261.

#11 @noisysocks
3 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

#12 @SergeyBiryukov
3 months ago

In 49494:

Docs: Adjust documentation for some WP_Post_Type properties:

  • Split the summary for $template per the documentation standards. The summary should be a single sentence.
  • Change the type for $template_lock to string|false, to clarify that true is not supported.
  • Fix typo in $delete_with_user description, adjust for better readability.

Follow-up to [49041], [49492].

See #46261.

#13 @SergeyBiryukov
3 months ago

In 49495:

Docs: Add documentation for the template_lock argument to register_post_type().

Add a @since entry for template and template_lock arguments.

Follow-up to [49041], [49492], [49494].

See #46261.

#14 @SergeyBiryukov
3 months ago

In 49496:

Docs: Change the @since entry for template and template_lock post type arguments to 5.0.0.

These arguments were introduced with the initial block editor, but not documented previously.

Follow-up to [49495].

Props TimothyBlynJacobs.
See #46261.

Note: See TracTickets for help on using tickets.