Opened 6 years ago
Last modified 6 years ago
#50110 assigned defect (bug)
Incorrect property docblocks in WP_Block_Type
| Reported by: | nielsdeblaauw | Owned by: | peterwilsoncc |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Editor | Version: | 5.0 |
| Severity: | minor | Keywords: | |
| Cc: | Focuses: | docs, coding-standards |
Description
In the class WP_Block_Type the docblocks declare @var #TYPE# for several properties of the class.
Below I will use attributes as an example, but this counts for all the following properties:
- render_callback
- attributes
- editor_script
- script
- editor_style
- style
The docblock defines that the property must be a certain value ('array' in the case of attributes), but it is not set in the constructor and is optionally set in the set_props() method, if args has been supplied with the correct property.
/** * Block type attributes property schemas. * * @since 5.0.0 * @var array */ public $attributes;
This allows the property to be null, which conflicts with de docblock.
Proposed solution(s)
1. Declare default value:
This might change behavior, where null is expected (see get_attributes() for example)
/** * Block type attributes property schemas. * * @since 5.0.0 * @var array */ public $attributes = array();
2. Add possible null to docblock
This would lead might lead to other conflicts, such as using the the null value as an array without a type check.
/** * Block type attributes property schemas. * * @since 5.0.0 * @var array|null */ public $attributes;
3. Do not declare @var
The set_props() method currently does not do any type checking, so in theory all the properties listed above are mixed.
(intentionally borked example)
new \WP_Block_Type( 'name', array( 'attributes' => 'This is not an array.' ) );
This places responsibility of type checking on implementing code, which would be most 'correct' with the current set_props() method.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Hi @nielsdeblaauw,
This was discussed in a Core triage session today.
It looks like the docblocks have been updated in most instances except for
render_callback(). I've self assigned this to take a look and update.Thanks for the report.