Skip to content

Commit 1d58b15

Browse files
authored
Blocks: Cleanup after Interactivity moves (#1750)
1 parent 05fcefe commit 1d58b15

File tree

4 files changed

+24
-37
lines changed

4 files changed

+24
-37
lines changed

build/editor-plugin/plugin.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-components', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => '35eb7359fc61b0d65be6');
1+
<?php return array('dependencies' => array('react', 'wp-components', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => '1bd009e5ff8d85217279');

build/editor-plugin/plugin.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: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ public static function init() {
2121
// This is already being called on the init hook, so just add it.
2222
self::register_blocks();
2323

24-
\add_action( 'wp_head', array( self::class, 'inject_activitypub_options' ), 11 );
25-
\add_action( 'admin_print_scripts', array( self::class, 'inject_activitypub_options' ) );
2624
\add_action( 'load-post-new.php', array( self::class, 'handle_in_reply_to_get_param' ) );
2725
// Add editor plugin.
2826
\add_action( 'enqueue_block_editor_assets', array( self::class, 'enqueue_editor_assets' ) );
@@ -95,12 +93,24 @@ public static function register_postmeta() {
9593
* Enqueue the block editor assets.
9694
*/
9795
public static function enqueue_editor_assets() {
96+
$data = array(
97+
'namespace' => ACTIVITYPUB_REST_NAMESPACE,
98+
'defaultAvatarUrl' => ACTIVITYPUB_PLUGIN_URL . 'assets/img/mp.jpg',
99+
'enabled' => array(
100+
'site' => ! is_user_type_disabled( 'blog' ),
101+
'users' => ! is_user_type_disabled( 'user' ),
102+
),
103+
'maxImageAttachments' => \get_option( 'activitypub_max_image_attachments', ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS ),
104+
);
105+
wp_localize_script( 'wp-editor', '_activityPubOptions', $data );
106+
98107
// Check for our supported post types.
99108
$current_screen = \get_current_screen();
100109
$ap_post_types = \get_post_types_by_support( 'activitypub' );
101110
if ( ! $current_screen || ! in_array( $current_screen->post_type, $ap_post_types, true ) ) {
102111
return;
103112
}
113+
104114
$asset_data = include ACTIVITYPUB_PLUGIN_DIR . 'build/editor-plugin/plugin.asset.php';
105115
$plugin_url = plugins_url( 'build/editor-plugin/plugin.js', ACTIVITYPUB_PLUGIN_FILE );
106116
wp_enqueue_script( 'activitypub-block-editor', $plugin_url, $asset_data['dependencies'], $asset_data['version'], true );
@@ -121,42 +131,20 @@ public static function handle_in_reply_to_get_param() {
121131
wp_enqueue_script( 'activitypub-reply-intent', $plugin_url, $asset_data['dependencies'], $asset_data['version'], true );
122132
}
123133

124-
/**
125-
* Output ActivityPub options as a script tag.
126-
*/
127-
public static function inject_activitypub_options() {
128-
$data = array(
129-
'namespace' => ACTIVITYPUB_REST_NAMESPACE,
130-
'defaultAvatarUrl' => ACTIVITYPUB_PLUGIN_URL . 'assets/img/mp.jpg',
131-
'enabled' => array(
132-
'site' => ! is_user_type_disabled( 'blog' ),
133-
'users' => ! is_user_type_disabled( 'user' ),
134-
),
135-
'maxImageAttachments' => \get_option( 'activitypub_max_image_attachments', ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS ),
136-
);
137-
138-
printf(
139-
"\n<script>var _activityPubOptions = %s;</script>",
140-
wp_json_encode( $data )
141-
);
142-
}
143-
144134
/**
145135
* Register the blocks.
146136
*/
147137
public static function register_blocks() {
148-
\register_block_type_from_metadata( ACTIVITYPUB_PLUGIN_DIR . '/build/followers' );
149-
150138
\register_block_type_from_metadata( ACTIVITYPUB_PLUGIN_DIR . '/build/follow-me' );
139+
\register_block_type_from_metadata( ACTIVITYPUB_PLUGIN_DIR . '/build/followers' );
140+
\register_block_type_from_metadata( ACTIVITYPUB_PLUGIN_DIR . '/build/reactions' );
151141

152142
\register_block_type_from_metadata(
153143
ACTIVITYPUB_PLUGIN_DIR . '/build/reply',
154144
array(
155145
'render_callback' => array( self::class, 'render_reply_block' ),
156146
)
157147
);
158-
159-
\register_block_type_from_metadata( ACTIVITYPUB_PLUGIN_DIR . '/build/reactions' );
160148
}
161149

162150
/**

src/editor-plugin/plugin.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useEntityProp } from '@wordpress/core-data';
77
import { addQueryArgs } from '@wordpress/url';
88
import { __ } from '@wordpress/i18n';
99
import { SVG, Path } from '@wordpress/primitives';
10+
import { useOptions } from '../shared/use-options';
1011

1112
// Defining our own because it's too new in @wordpress/icons
1213
// https://github.com/WordPress/gutenberg/blob/trunk/packages/icons/src/library/not-allowed.js
@@ -27,8 +28,13 @@ const notAllowed = (
2728
*/
2829
const EditorPlugin = () => {
2930
const postType = useSelect( ( select ) => select( 'core/editor' ).getCurrentPostType(), [] );
30-
const [ meta, setMeta ] = useEntityProp( 'postType', postType, 'meta' );
31+
const [ meta, setMeta ] = useEntityProp( 'postType', postType || 'default', 'meta' );
3132

33+
// Don't show when editing sync blocks.
34+
if ( 'wp_block' === postType ) {
35+
return null;
36+
}
37+
const { maxImageAttachments = 4 } = useOptions();
3238
const labelStyling = {
3339
verticalAlign: 'middle',
3440
gap: '4px',
@@ -55,11 +61,6 @@ const EditorPlugin = () => {
5561
</Tooltip>
5662
);
5763

58-
// Don't show when editing sync blocks.
59-
if ( 'wp_block' === postType ) {
60-
return null;
61-
}
62-
6364
return (
6465
<PluginDocumentSettingPanel
6566
name="activitypub"
@@ -83,9 +84,7 @@ const EditorPlugin = () => {
8384

8485
<RangeControl
8586
label={ __( 'Maximum Image Attachments', 'activitypub' ) }
86-
value={
87-
meta?.activitypub_max_image_attachments ?? window._activityPubOptions?.maxImageAttachments ?? 4
88-
}
87+
value={ meta?.activitypub_max_image_attachments ?? maxImageAttachments }
8988
onChange={ ( value ) => {
9089
setMeta( { ...meta, activitypub_max_image_attachments: value } );
9190
} }

0 commit comments

Comments
 (0)