render_block_core_latest_posts() Add filter for The block attributes#11195
render_block_core_latest_posts() Add filter for The block attributes#11195ghost wants to merge 2 commits intoWordPress:masterfrom
Conversation
|
Will this change be included in WP 5.0? |
|
Shouldn't this be covered by #11730? |
youknowriad
left a comment
There was a problem hiding this comment.
I think there's already a filter for the render_callback that is generic (across all blocks), I feel adding a specific filter like this is just a duplication.
|
see #11523 |
|
@youknowriad @swissspidy it's little different because |
|
It is different, but you can achieve the same use-cases, maybe it's a bit more difficult in some cases and a bit easier in others. |
|
@youknowriad I can filter $attributes array with 'render_block' filter but there no way to pass |
|
Can't you just regenerate the HTML output of the block the way you want? |
|
That sounds a bit hacky though, especially since the block HTML output could change. Why does the block even use |
|
I was wondering the same @swissspidy I never saw a report from users complaining that the results of Anyway, if it should use |
|
added https://core.trac.wordpress.org/ticket/45349 for adding filter inside |
|
@youknowriad @gziolo is it ok if I modify pull request and replace |
|
Probably easier to do that in a separate PR as it's a totally different approach. |
|
I'm closing this one in favor of #11730, which tries to do the same but for all blocks. This is example from the mentioned PR: add_filter( 'block_prepared_attributes', 'block_attributes_filter', 1, 10 );
function block_attributes_filter( $attributes, $block_type ) {
if ( $block_type->name === 'my-plugin/my-block' && isset( $attributes['data'] ) ) {
$original_post_id = apply_filters( 'wpml_object_id', get_the_ID(), get_post_type(), true, apply_filters( 'wpml_default_language', null) );
foreach ( $attributes['data'] as $name => $value ) {
$string_name = WPML_Gutenberg_Strings_In_Block::get_string_id($attributes['name'], $value);
$translated = apply_filters( 'wpml_translate_string',
$value,
$string_name,
array('kind' => 'Gutenberg', 'name' => $original_post_id) );
$attributes['data'][$name] = $translated;
}
}
return $attributes;
} |

Description
Add a filter so that plugins and themes can filter the block attributes.
Why is this needed.
Plugins may want to filter attributes in some situations. Eg. WPML will need to display posts in the current language only.
How has this been tested?
This has been tested with WPML using the following code example.
Types of changes
Add a new filter
Checklist: