Commit Graph

32 Commits

Author SHA1 Message Date
gziolo
c0ed2c6f06 Editor: Merge uses_context defined by block bindings sources with block types
Adds logic that fixes the limitation for souces by allowing merging the `uses_context` defined by block bindings sources into supported block types. Each source defines the context it needs and it is added to the block types that are using the block bindings API.

Fixes #60525.
Props santosguillamot, gziolo, czapla, thekt12.



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


git-svn-id: http://core.svn.wordpress.org/trunk@57142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-02-16 12:55:11 +00:00
youknowriad
21e68fe56e Editor: Expand Block Bindings for button block.
Add block bindings support for the linkTarget and rel button block attributes.
This allows using custom fiends or pattern overrides for these attributes.

Props glendaviesnz.
Fixes #60481.
Built from https://develop.svn.wordpress.org/trunk@57576


git-svn-id: http://core.svn.wordpress.org/trunk@57077 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-02-09 15:10:13 +00:00
gziolo
66badc5b0d Editor: Add wakeup magic method to the block bindings registry
See #60282.
Follow-up [57373].
Props dmsnell, mukesh27, gziolo.


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


git-svn-id: http://core.svn.wordpress.org/trunk@57076 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-02-09 10:54:11 +00:00
gziolo
9cd17860ba Editor: Refactor block binding processing and attribute computation
Refactors the processing of block bindings into steps:
- Gets the value for each "bound" attribute from the respective source.
- Returns the computer attributes with values from the sources.
- The computed attributes get injected into block's content.
- The `render_callback` gets the updated list of attributes and processeded block content.

Fixes #60282.
Props czapla, gziolo, andraganescu, santosguillamot.


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


git-svn-id: http://core.svn.wordpress.org/trunk@57075 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-02-09 10:40:15 +00:00
gziolo
f31040bcdb Editor: Add viewScriptModule handling to block.json metadata
Syncing changes from the Gutenberg plugin: https://github.com/WordPress/gutenberg/pull/57437.

Scripts and styles can be registered for blocks via `block.json` metadata. There is now a Modules API, but was no way to register or associate module assets with blocks via `block.json`.

Fixes #60233.
Props jonsurrell, gziolo, cbravobernal, luisherranz, youknowriad.


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


git-svn-id: http://core.svn.wordpress.org/trunk@57066 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-02-08 10:41:13 +00:00
gziolo
b19e148a07 Editor: Introduce WP_Block_Bindings_Source class
Abstracts the block bindings source array into a well-defined object.

Fixes #60447.
See #60282.
Follow-up [57373].
Props czapla, santosguillamot, gziolo.


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


git-svn-id: http://core.svn.wordpress.org/trunk@57063 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-02-08 08:57:07 +00:00
gziolo
b89d86bde8 Editor: Avoid double escaping on value passed for attribute in HTML tag processor
Fix for the Block Bindings processing.
See https://github.com/WordPress/wordpress-develop/pull/5888#discussion_r1476793062.

Props: czapla, dmsnell, gziolo.


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


git-svn-id: http://core.svn.wordpress.org/trunk@57062 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-02-08 08:42:07 +00:00
gziolo
742e8aae9c Editor: Refactor the way block bindings sources are handled
It fixes the coding style issues reported. It goes further and improves the code quality it other places where the logic for block bindings was added.

Follow-up for [57514].
Props: gziolo, mukesh27, youknowriad, santosguillamot.
See #60282.


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


git-svn-id: http://core.svn.wordpress.org/trunk@57027 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-02-02 20:24:12 +00:00
youknowriad
a2786a3785 Editor: Add the Block Bindings API.
This introduces the Block Bindings API for WordPress.

The API allows developers to connects block attributes to different sources. In this PR, two such sources are included: "post meta" and "pattern". Attributes connected to sources can have their HTML replaced by values coming from the source in a way defined by the binding.

Props czapla, lgladdy, gziolo, sc0ttkclark, swissspidy, artemiosans, kevin940726, fabiankaegy, santosguillamot, talldanwp, wildworks.
Fixes #60282.
Built from https://develop.svn.wordpress.org/trunk@57514


git-svn-id: http://core.svn.wordpress.org/trunk@57015 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-02-01 12:54:15 +00:00
gziolo
9eea02e31b Editor: Add viewStyle property to block.json for frontend-only block styles
Related issue in Gutenberg: https://github.com/WordPress/gutenberg/issues/54491.

For block scripts there was already `script`, `viewScript` and `editorScript`. For block styles there was only `style` and `editorStyle`. This brings the parity.

Props gaambo.
Fixes #59673. 


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


git-svn-id: http://core.svn.wordpress.org/trunk@56994 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-31 09:11:17 +00:00
Sergey Biryukov
b80ce60f70 Coding Standards: Use pre-increment/decrement for stand-alone statements.
Note: This is enforced by WPCS 3.0.0:

1. There should be no space between an increment/decrement operator and the variable it applies to.
2. Pre-increment/decrement should be favoured over post-increment/decrement for stand-alone statements. “Pre” will in/decrement and then return, “post” will return and then in/decrement. Using the “pre” version is slightly more performant and can prevent future bugs when code gets moved around.

References:
* [https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#increment-decrement-operators WordPress PHP Coding Standards: Increment/decrement operators]
* [https://github.com/WordPress/WordPress-Coding-Standards/pull/2130 WPCS: PR #2130 Core: add sniffs to check formatting of increment/decrement operators]

Props jrf.
See #59161, #58831.
Built from https://develop.svn.wordpress.org/trunk@56549


git-svn-id: http://core.svn.wordpress.org/trunk@56061 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-09-09 09:28:26 +00:00
Sergey Biryukov
9a49b70239 Coding Standards: Remove superfluous blank lines at the end of various classes.
Note: This is enforced by WPCS 3.0.0.

Follow-up to [56536].

Props jrf.
See #59161, #58831.
Built from https://develop.svn.wordpress.org/trunk@56547


git-svn-id: http://core.svn.wordpress.org/trunk@56059 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-09-08 09:32:23 +00:00
audrasjb
349e9ac8d4 Docs: Improve various globals documentation, as per documentation standards.
Props upadalavipul, mukesh27, krupalpanchal, jigar-bhanushali.
See #57069, #56792.

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


git-svn-id: http://core.svn.wordpress.org/trunk@54419 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-11-23 21:30:13 +00:00
davidbaumwald
a68841201d Editor: Ensure block script is enqueued, regardless of ronder_callback.
Follow-up to [54155].

Props aristath, cbravobernal.
See #56408.
Built from https://develop.svn.wordpress.org/trunk@54367


git-svn-id: http://core.svn.wordpress.org/trunk@53926 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-10-03 14:41:14 +00:00
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