Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the Block Bindings API #5888

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
8720e12
Add the Block Bindings API
michalczaplinski Jan 17, 2024
8891169
Add tests
artemiomorales Jan 17, 2024
eac5b22
Move tests to different directory
artemiomorales Jan 17, 2024
39e52ed
Fix bug wherein block content was erased
artemiomorales Jan 17, 2024
82e70ff
Update comment format for consistency
artemiomorales Jan 17, 2024
6486471
Move process_block_bindings_function to class-wp-block
michalczaplinski Jan 17, 2024
048330e
WordPress capitalization dangit
michalczaplinski Jan 17, 2024
4a4b825
PHPDoc formatting
michalczaplinski Jan 18, 2024
9a662e4
Add a better PHPDoc
michalczaplinski Jan 18, 2024
c92b6ac
Add a new unit test covering the _process_block_bindings() function
michalczaplinski Jan 18, 2024
abb56fb
More fixes for formatting, capitalization and PHPDocs
michalczaplinski Jan 18, 2024
e8b1195
Add @since to block-bindings.php
michalczaplinski Jan 18, 2024
cc6c2c2
Add version and since tags to class and methods
michalczaplinski Jan 18, 2024
206b6b7
Add a comment on the block class
michalczaplinski Jan 18, 2024
dc8377a
Update assertions in WP_Block_Bindings_Test class
michalczaplinski Jan 18, 2024
751a459
Update block binding registration function comment
michalczaplinski Jan 18, 2024
423bb66
Change the signature of `wp_block_bindings_register_source` & WP_Bloc…
michalczaplinski Jan 23, 2024
d1b0d2e
Add type hints for `register_source()` & `replace_html()`
michalczaplinski Jan 23, 2024
9f2274d
Add the missing array keys
michalczaplinski Jan 23, 2024
02f0ea3
Apply https://github.com/WordPress/gutenberg/pull/58055/
michalczaplinski Jan 23, 2024
9303e02
Make processing of bindings private to the class
artemiomorales Jan 25, 2024
30f4ed7
Update class name and method names
artemiomorales Jan 25, 2024
940fb82
Remove the `wp_block_bindings()` function and create a static get_ins…
michalczaplinski Jan 25, 2024
dbda027
Rename `register_block_bindings_source()` to `register()`
michalczaplinski Jan 25, 2024
34d9dd7
Move the process_block_bindings & replace_html methods to the WP_bloc…
michalczaplinski Jan 25, 2024
74bfae7
Rename WP_Block_Bindings to WP_Block_Bindings_Registry in missing places
michalczaplinski Jan 25, 2024
013535e
Rename class-wp-block-bindings.php to class-wp-block-bindings-registr…
michalczaplinski Jan 25, 2024
89e9833
Rename $source_args to $source_properties to align with other similar…
michalczaplinski Jan 25, 2024
0c931e0
Add `is_registered()` & `get_registered()`
michalczaplinski Jan 25, 2024
7b1ebe2
Register block bindings on 'init' action hook
michalczaplinski Jan 25, 2024
b0c300f
Merge branch 'trunk' into feature/block-bindings-api
michalczaplinski Jan 25, 2024
e0b3883
Fix incorrect loading of block bindings class
artemiomorales Jan 26, 2024
2900bf5
Add validation to prevent sources from being registered twice
artemiomorales Jan 26, 2024
26da23e
Add 'core' namespace to built-in sources
artemiomorales Jan 26, 2024
29213d8
Fix incorrect reading of sources
artemiomorales Jan 26, 2024
4c3d892
Rename 'apply' to 'get_value_callback'
artemiomorales Jan 26, 2024
06a3930
Fix incorrect reading of registered sources
artemiomorales Jan 26, 2024
f53121d
Ensure unauthorized users don't read post meta
artemiomorales Jan 26, 2024
5b8eb4a
Fix PHPCS errors
artemiomorales Jan 26, 2024
45a96f8
Rename sources using naming pattern for block types
artemiomorales Jan 26, 2024
08ddb0a
Add context to translation
artemiomorales Jan 26, 2024
3a16941
Update comments and revise to use proper array annotation
artemiomorales Jan 26, 2024
1729f65
Update callback comment with return type details; fix PHPCS
artemiomorales Jan 26, 2024
9ea2c9a
Code quality improvements for the Block Bindings Registry
gziolo Jan 29, 2024
fd090ab
Ensure that code comments fit into the line length limit
gziolo Jan 29, 2024
6ea69cd
Updates to the test
michalczaplinski Jan 25, 2024
15dea88
Merge branch 'trunk' into feature/block-bindings-api
michalczaplinski Jan 29, 2024
5893867
Remove the files already committed in #5965 and #5966.
michalczaplinski Jan 29, 2024
d10b165
Update block bindings function call in class-wp-block.php
michalczaplinski Jan 29, 2024
c324e65
Add set_up to block-bindings tests
michalczaplinski Jan 29, 2024
a0d550a
Refactor block bindings tests
michalczaplinski Jan 29, 2024
3f242d3
Fix block bindings registration unit test and test setup
michalczaplinski Jan 29, 2024
d202e5d
Move tests to block-bindings directory
michalczaplinski Jan 30, 2024
2a20dee
Remove unnecessary attributes from the test
michalczaplinski Jan 30, 2024
2b4cf33
Incorporate PHP changes from https://github.com/WordPress/gutenberg/p…
michalczaplinski Jan 30, 2024
8604e82
Fix binding source arguments in WP_Block class
michalczaplinski Jan 30, 2024
65a7c09
Test passing arguments to the source
michalczaplinski Jan 30, 2024
1ceef1b
Undo the changes in register.php
michalczaplinski Jan 30, 2024
3d97457
Merge branch 'trunk' into feature/block-bindings-api
michalczaplinski Jan 30, 2024
5f397aa
Update the docstring for `process_block_bindings`
michalczaplinski Jan 30, 2024
f2a611b
Update source_name parameter documentation in block-bindings.php and …
michalczaplinski Jan 30, 2024
a1e1bac
Refactor post_meta_source_callback function to use is_post_publicly_v…
michalczaplinski Jan 30, 2024
26571a7
Remove unnecessary condition for unregistering block bindings sources
michalczaplinski Jan 30, 2024
d189f50
Fix access control logic in post_meta_source_callback function
michalczaplinski Jan 30, 2024
d7201ce
Optimize call to post_password_required()
artemiomorales Jan 30, 2024
69ed754
Update pattern source label and PHPDoc string.
michalczaplinski Jan 31, 2024
951ca16
Merge branch 'trunk' into feature/block-bindings-api
michalczaplinski Jan 31, 2024
f10a4fe
Update block bindings source labels
michalczaplinski Jan 31, 2024
0bec833
Wrap the block binding registrations with 'init' actions
michalczaplinski Feb 1, 2024
3134faa
Use $this->block_type directly in replace_html method
michalczaplinski Feb 1, 2024
9491be3
Mark functions passed to init actions in block binding sources as pri…
michalczaplinski Feb 1, 2024
c95b92f
Prefix block binding function names with `_` to mark as private
michalczaplinski Feb 1, 2024
3619e18
Update the function names again
michalczaplinski Feb 1, 2024
c8232ac
Prevent pattern and post meta sources from registering in unit tests
michalczaplinski Feb 1, 2024
871cedc
Use `call_user_func_array` to call the source binding callback in WP_…
michalczaplinski Feb 1, 2024
604f7a2
Validate that `$block['attrs']['metadata']['bindings']` is an array i…
michalczaplinski Feb 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/wp-includes/block-bindings/sources/pattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ function pattern_source_callback( $source_attrs, $block_instance, $attribute_nam
return _wp_array_get( $block_instance->context, array( 'pattern/overrides', $block_id, $attribute_name ), null );
}

register_block_bindings_source(
'core/pattern-overrides',
array(
'label' => _x( 'Pattern Overrides', 'block bindings source' ),
'get_value_callback' => 'pattern_source_callback',
)
);
function register_block_bindings_pattern_overrides_source() {
michalczaplinski marked this conversation as resolved.
Show resolved Hide resolved
register_block_bindings_source(
'core/pattern-overrides',
array(
'label' => _x( 'Pattern Overrides', 'block bindings source' ),
'get_value_callback' => 'pattern_source_callback',
)
);
}

add_action( 'init', 'register_block_bindings_pattern_overrides_source' );
18 changes: 11 additions & 7 deletions src/wp-includes/block-bindings/sources/post-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ function post_meta_source_callback( $source_attrs ) {
return get_post_meta( $post_id, $source_attrs['key'], true );
}

register_block_bindings_source(
'core/post-meta',
array(
'label' => _x( 'Post Meta', 'block bindings source' ),
'get_value_callback' => 'post_meta_source_callback',
)
);
function gutenberg_register_block_bindings_post_meta_source() {
register_block_bindings_source(
'core/post-meta',
array(
'label' => _x( 'Post Meta', 'block bindings source' ),
'get_value_callback' => 'post_meta_source_callback',
)
);
}

add_action( 'init', 'gutenberg_register_block_bindings_post_meta_source' );