Skip to content

Commit 9d235ff

Browse files
authored
Reactions: Fix fallback for blocks with default title (#1705)
1 parent dce490f commit 9d235ff

File tree

7 files changed

+26
-10
lines changed

7 files changed

+26
-10
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Fixed a bug where Reaction blocks without modified titles did not get displayed correctly.

build/reactions/block.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "https://schemas.wp.org/trunk/block.json",
33
"name": "activitypub/reactions",
44
"apiVersion": 2,
5-
"version": "1.0.0",
5+
"version": "2.0.0",
66
"title": "Fediverse Reactions",
77
"category": "widgets",
88
"icon": "heart",

build/reactions/index.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '13c017000d37a3025875');
1+
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '3a159dbba14b00d4163c');

build/reactions/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/class-blocks.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,21 @@ public static function render_post_reactions_block( $attrs, $content ) {
186186
}
187187

188188
$args = array( 'data-attrs' => wp_json_encode( $attrs ) );
189-
if ( isset( $attrs['title'] ) ) {
190-
$args['class'] = 'activitypub-reactions-block';
189+
if ( empty( $content ) ) {
190+
if ( isset( $attrs['title'] ) ) {
191+
$content = '<div class="activitypub-reactions"><div class="activitypub-reactions-block" ' . \get_block_wrapper_attributes( $args ) . '></div></div>';
192+
} else {
193+
$has_comments = \get_comments(
194+
array(
195+
'post_id' => $attrs['postId'],
196+
'fields' => 'ids',
197+
'type' => Comment::get_comment_type_slugs(),
198+
)
199+
);
200+
if ( $has_comments ) {
201+
$content = '<div class="activitypub-reactions"><h6>' . \__( 'Fediverse Reactions', 'activitypub' ) . '</h6><div class="activitypub-reactions-block" ' . \get_block_wrapper_attributes( $args ) . '></div></div>';
202+
}
203+
}
191204
}
192205

193206
return sprintf(

src/reactions/block.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "https://schemas.wp.org/trunk/block.json",
33
"name": "activitypub/reactions",
44
"apiVersion": 2,
5-
"version": "1.0.0",
5+
"version": "2.0.0",
66
"title": "Fediverse Reactions",
77
"category": "widgets",
88
"icon": "heart",

src/reactions/edit.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,13 @@ export default function Edit( { attributes, __unstableLayoutClassNames } ) {
155155
],
156156
];
157157

158-
const ALLOWED_BLOCKS = [ 'core/heading' ];
159-
160158
return (
161159
<div { ...blockProps }>
162160
<InnerBlocks
163161
template={ TEMPLATE }
164-
allowedBlocks={ ALLOWED_BLOCKS }
165-
templateLock={ false }
162+
allowedBlocks={ [ 'core/heading' ] }
163+
templateLock={ 'all' }
164+
renderAppender={ false }
166165
/>
167166
<Reactions reactions={ dummyReactions } />
168167
</div>

0 commit comments

Comments
 (0)