Make WordPress Core

Opened 6 years ago

Closed 4 years ago

Last modified 4 years ago

#46261 closed defect (bug) (fixed)

Args for register_post_type() missing blocks $template.

Reported by: milana_cap's profile milana_cap Owned by: noisysocks's profile 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 6 years ago.
46261.2.diff (971 bytes) - added by metalandcoffee 4 years ago.
Add template property to WP post type class
46261.3.diff (1.6 KB) - added by metalandcoffee 4 years ago.
Add template_lock property to WP post type class
46261.4.diff (1.6 KB) - added by metalandcoffee 4 years ago.
Fixing a typo in the previous patch. Sorry about that!

Download all attachments as: .zip

Change History (18)

@milana_cap
6 years ago

#1 @noisysocks
4 years 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 years ago

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

#3 @joyously
4 years 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 years 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
4 years 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
4 years ago

Add template property to WP post type class

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


4 years ago

#7 @davidbaumwald
4 years ago

  • Keywords has-patch added; needs-patch removed

#8 @noisysocks
4 years 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
4 years ago

Add template_lock property to WP post type class

#9 @metalandcoffee
4 years ago

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

@metalandcoffee
4 years ago

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

#10 @noisysocks
4 years 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
4 years ago

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

#12 @SergeyBiryukov
4 years 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
4 years 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
4 years 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.