11
11
/* @var array $attributes Block attributes. */
12
12
$ attributes = wp_parse_args ( $ attributes , array ( 'align ' => null ) );
13
13
14
- /* @var string $content Inner blocks content. */
14
+ /* @var \WP_Block $block Current block. */
15
+ $ block = $ block ?? '' ;
16
+
17
+ /* @var string $content Block content. */
18
+ $ content = $ content ?? '' ;
19
+
15
20
if ( empty ( $ content ) ) {
16
21
// Fallback for v1.0.0 blocks.
17
22
$ _title = $ attributes ['title ' ] ?? __ ( 'Fediverse Reactions ' , 'activitypub ' );
18
23
$ content = '<h6 class="wp-block-heading"> ' . esc_html ( $ _title ) . '</h6> ' ;
19
24
unset( $ attributes ['title ' ], $ attributes ['className ' ] );
25
+ } else {
26
+ $ content = implode ( PHP_EOL , wp_list_pluck ( $ block ->parsed_block ['innerBlocks ' ], 'innerHTML ' ) );
20
27
}
21
28
22
29
// Get the Post ID from attributes or use the current post.
@@ -71,6 +78,11 @@ function ( $comment ) {
71
78
);
72
79
}
73
80
81
+ if ( empty ( $ reactions ) ) {
82
+ echo '<!-- Reactions block: No reactions found. --> ' ;
83
+ return ;
84
+ }
85
+
74
86
// Set up the Interactivity API state.
75
87
wp_interactivity_state (
76
88
'activitypub/reactions ' ,
@@ -102,11 +114,10 @@ function ( $reaction ) use ( $attributes ) {
102
114
103
115
// Initialize the context for the block.
104
116
$ context = array (
105
- 'blockId ' => $ block_id ,
106
- 'hasReactions ' => ! empty ( $ reactions ),
107
- 'reactions ' => $ reactions ,
108
- 'postId ' => $ _post_id ,
109
- 'modal ' => array (
117
+ 'blockId ' => $ block_id ,
118
+ 'reactions ' => $ reactions ,
119
+ 'postId ' => $ _post_id ,
120
+ 'modal ' => array (
110
121
'isCompact ' => true ,
111
122
'isOpen ' => false ,
112
123
'items ' => array (),
@@ -116,11 +127,10 @@ function ( $reaction ) use ( $attributes ) {
116
127
// Add the block wrapper attributes.
117
128
$ wrapper_attributes = get_block_wrapper_attributes (
118
129
array (
119
- 'id ' => $ block_id ,
120
- 'data-wp-interactive ' => 'activitypub/reactions ' ,
121
- 'data-wp-context ' => wp_json_encode ( $ context , JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP ),
122
- 'data-wp-init ' => 'callbacks.initReactions ' ,
123
- 'data-wp-bind--hidden ' => '!context.hasReactions ' ,
130
+ 'id ' => $ block_id ,
131
+ 'data-wp-interactive ' => 'activitypub/reactions ' ,
132
+ 'data-wp-context ' => wp_json_encode ( $ context , JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP ),
133
+ 'data-wp-init ' => 'callbacks.initReactions ' ,
124
134
)
125
135
);
126
136
?>
0 commit comments