Commit Graph

18 Commits

Author SHA1 Message Date
gziolo
714e57b2fc Blocks: Allow registering multiple items for all supported asset types
Follow-up #54337, [52069]. Part of https://github.com/WordPress/gutenberg/issues/41236. More details in https://github.com/WordPress/gutenberg/issues/33542.

Allow passing more than one script per block for `editorScript`, `script`, and `viewScript` fields in the `block.json` metadata file. This aligns with the previously added changes for `style` and `editorStyle` fields.

This change impacts the `WP_Block_Type` class and the REST API endpoint for block types. To ensure backward compatibiliy old names were soft deprecated in favor of new fields that work with array values and have `_handles` suffix.

Props zieladam, dlh, timothyblynjacobs, aristath, bernhard-reiter.
Fixes #56408.


Built from https://develop.svn.wordpress.org/trunk@54155


git-svn-id: http://core.svn.wordpress.org/trunk@53714 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-14 10:52:08 +00:00
Sergey Biryukov
c03305852e Code Modernization: Add AllowDynamicProperties attribute to all (parent) classes.
Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0.

There are a number of ways to mitigate this:
* If it is an accidental typo for a declared property: fix the typo.
* For known properties: declare them on the class.
* For unknown properties: add the magic `__get()`, `__set()`, et al. methods to the class or let the class extend `stdClass` which has highly optimized versions of these magic methods built in.
* For unknown ''use'' of dynamic properties, the `#[AllowDynamicProperties]` attribute can be added to the class. The attribute will automatically be inherited by child classes.

Trac ticket #56034 is open to investigate and handle the third and fourth type of situations, however it has become clear this will need more time and will not be ready in time for WP 6.1.

To reduce “noise” in the meantime, both in the error logs of WP users moving onto PHP 8.2, in the test run logs of WP itself, in test runs of plugins and themes, as well as to prevent duplicate tickets from being opened for the same issue, this commit adds the `#[AllowDynamicProperties]` attribute to all “parent” classes in WP.

The logic used for this commit is as follows:
* If a class already has the attribute: no action needed.
* If a class does not `extend`: add the attribute.
* If a class does `extend`:
 - If it extends `stdClass`: no action needed (as `stdClass` supports dynamic properties).
 - If it extends a PHP native class: add the attribute.
 - If it extends a class from one of WP's external dependencies: add the attribute.
* In all other cases: no action — the attribute should not be needed as child classes inherit from the parent.

Whether or not a class contains magic methods has not been taken into account, as a review of the currently existing magic methods has shown that those are generally not sturdy enough and often even set dynamic properties (which they should not). See the [https://www.youtube.com/watch?v=vDZWepDQQVE live stream from August 16, 2022] for more details.

This commit only affects classes in the `src` directory of WordPress core.
* Tests should not get this attribute, but should be fixed to not use dynamic properties instead. Patches for this are already being committed under ticket #56033.
* While a number bundled themes (2014, 2019, 2020, 2021) contain classes, they are not a part of this commit and may be updated separately.

Reference: [https://wiki.php.net/rfc/deprecate_dynamic_properties PHP RFC: Deprecate dynamic properties].

Follow-up to [53922].

Props jrf, hellofromTonya, markjaquith, peterwilsoncc, costdev, knutsp, aristath.
See #56513, #56034.
Built from https://develop.svn.wordpress.org/trunk@54133


git-svn-id: http://core.svn.wordpress.org/trunk@53692 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-12 15:47:14 +00:00
audrasjb
82edcc17f5 Docs: Improve parameter descriptions in render_block and render_block_* filters.
The former `$block_content` parameter descriptions were too opinionated as block content can be appended, prepended, nested, removed, etc.

Props milana_cap.
Fixes #56286.
See #55646.

Built from https://develop.svn.wordpress.org/trunk@53780


git-svn-id: http://core.svn.wordpress.org/trunk@53339 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-26 13:00:16 +00:00
John Blackbourn
9a982b4ae8 Docs: Various docblock corrections.
See #53399

Built from https://develop.svn.wordpress.org/trunk@52299


git-svn-id: http://core.svn.wordpress.org/trunk@51891 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-12-01 12:17:00 +00:00
Andrew Ozz
2dc8f381ca Apply the pre_render_block, render_block_data, and render_block_context filters when rendering inner/nested blocks. Introdices another param to these filters: $parent_block that is the "parent" WP_Block instance for nested blocks and null for top level blocks. Adds unit tests for the filters.
Props noisysocks, gaambo, azaozz.
Fixes #51612.
Built from https://develop.svn.wordpress.org/trunk@51894


git-svn-id: http://core.svn.wordpress.org/trunk@51487 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-10-06 18:49:01 +00:00
John Blackbourn
01ff7448d2 Formatting: Pass the block instance as a parameter to the render_block filters.
This allows filters to access properties and methods on the block instance.

Fixes #53596

Built from https://develop.svn.wordpress.org/trunk@51841


git-svn-id: http://core.svn.wordpress.org/trunk@51446 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-21 21:32:57 +00:00
gziolo
327852393a Build: Split packages and blocks to their webpack configs
It aligns with the changes proposed added in Gutenberg: https://github.com/WordPress/gutenberg/pull/33293.

The idea here is to split the growing webpack config into two parts: blocks and  packages.

We need to add handling for JavaScript files that are going to be used with blocks on the frontend. They didn't work quite well with the current setup for entry points created for packages.

As part of the effort, it adds support for `viewScript` in `block.json` metadata file that is later translated to `$view_script` in `WP_Block_Type` class and exposed as `view_script` from the REST API endpoint for block types.

Props youknowriad, desrosj, aristath.
Fixes #53690.


Built from https://develop.svn.wordpress.org/trunk@51501


git-svn-id: http://core.svn.wordpress.org/trunk@51112 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-07-28 10:06:59 +00:00
John Blackbourn
79685db062 Docs: Corrections and improvements to types used in docblocks for symbols, properties, and filters.
See #53399

Built from https://develop.svn.wordpress.org/trunk@51298


git-svn-id: http://core.svn.wordpress.org/trunk@50907 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-07-01 21:02:57 +00:00
Sergey Biryukov
cb7d0efb45 Editor: Introduce a dynamic filter for the content of a single block:
`render_block_{$this->name}`

This complements the existing `render_block` hook and allows for filtering the content of a specific block without having to use conditionals inside the filter callback.

Props manzoorwani.jk, noisysocks, birgire, johnbillion.
Fixes #46187.
Built from https://develop.svn.wordpress.org/trunk@50123


git-svn-id: http://core.svn.wordpress.org/trunk@49802 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-02-01 18:06:03 +00:00
noisysocks
7aa60ecce9 Editor: Remove render_block hooks from WP_Block
Reverts the move of pre_render_block, render_block_data, and
render_block_context to WP_Block.

This change has more implications than first thought so will be revisted later
in 5.7.

Reverts [49609,49608].
See #51612.

Built from https://develop.svn.wordpress.org/trunk@49695


git-svn-id: http://core.svn.wordpress.org/trunk@49418 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-11-25 01:20:09 +00:00
Sergey Biryukov
b51eeb4eef Docs: Drop src/ from pre_render_block duplicate hook reference.
Follow-up to [49608].

See #51612.
Built from https://develop.svn.wordpress.org/trunk@49609


git-svn-id: http://core.svn.wordpress.org/trunk@49347 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-11-16 10:53:11 +00:00
noisysocks
341704d640 Editor: Move pre_render_block, render_block_data, render_block_context
Move the pre_render_block, render_block_data, and render_block_context
filters from render_block() to WP_Block. This ensures that they are
called for all blocks, including nested blocks, not just top-level
blocks.

Fixes #51612.
Props gaambo, gziolo, TimothyBlynJacobs.

Built from https://develop.svn.wordpress.org/trunk@49608


git-svn-id: http://core.svn.wordpress.org/trunk@49346 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-11-16 00:47:11 +00:00
Sergey Biryukov
2c5607307f Coding Standards: Adjust formatting in WP_Block::render() for better readability.
Follow-up to [49310], [49539].

See #51606.
Built from https://develop.svn.wordpress.org/trunk@49540


git-svn-id: http://core.svn.wordpress.org/trunk@49278 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-11-09 11:01:05 +00:00
Sergey Biryukov
a2d42351c5 Text Changes: Unify various "Back to..." vs. "Return to..." vs. "Go to..." strings.
Standardize on "Go to..." as a more appropriate option for most cases.

Props garrett-eclipse, kharisblank, audrasjb, ramiy, valentinbora.
Fixes #47235.
Built from https://develop.svn.wordpress.org/trunk@49539


git-svn-id: http://core.svn.wordpress.org/trunk@49277 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-11-09 10:53:10 +00:00
youknowriad
bf5917edf3 Block Editor: Fix WP_Block_Supports class compatibility with Gutenberg-provided class.
When using WordPress trunk with Gutenberg master, there's an incompatibility causing 
the dynamic block generated classes to be omitted.
This commit refactors the block supports to fix that problem.

Props nosolosw.
Fixes #51606.

Built from https://develop.svn.wordpress.org/trunk@49310


git-svn-id: http://core.svn.wordpress.org/trunk@49072 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-10-26 08:31:11 +00:00
youknowriad
d6cff7965a Block Editor: Update the WordPress Packages to the latest version.
This includes the packages that match the Gutenberg 9.2 Release.
It is going to be the last block-editor features update for WordPress 5.6.
It also updates the block-supports code base to the latest APIs.

Props isabel_brison, noisysocks, desrosj.
Fixes #51570.

Built from https://develop.svn.wordpress.org/trunk@49226


git-svn-id: http://core.svn.wordpress.org/trunk@48988 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-10-20 13:36:16 +00:00
gziolo
0249959306 Editor: Introduce block context
Backports a new block context feature from Gutenberg. The purpose of this feature is to be able to establish values in a block hierarchy which can be consumed by blocks anywhere lower in the same hierarchy. These values can be established either by the framework, or by other blocks which provide these values. See documentation: https://github.com/WordPress/gutenberg/blob/master/docs/designers-developers/developers/block-api/block-context.md

Props aduth, epiqueras.
Fixes #49927.


Built from https://develop.svn.wordpress.org/trunk@48224


git-svn-id: http://core.svn.wordpress.org/trunk@47993 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-30 11:04:04 +00:00
gziolo
3f2e7804c4 Editor: Introduce WP_Block and WP_Block_List classes
Backports functionality added in Gutenberg in the following PRs:
- https://github.com/WordPress/gutenberg/pull/21467
- https://github.com/WordPress/gutenberg/pull/21925
It's a few ideas related to block rendering and the provided block value, which is particularly impactful for work around block context.

Props aduth, TimothyBJacobs, noisysocks, epiqueras, youknowriad, talldanwp, zebulan.
Fixes #49926.


Built from https://develop.svn.wordpress.org/trunk@48159


git-svn-id: http://core.svn.wordpress.org/trunk@47928 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-25 05:16:11 +00:00