Skip to content

Blocks: Cleanup after Interactivity moves #1750

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

Merged
merged 6 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion build/editor-plugin/plugin.asset.php
Original file line number Diff line number Diff line change
@@ -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');
<?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');
2 changes: 1 addition & 1 deletion build/editor-plugin/plugin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 14 additions & 26 deletions includes/class-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public static function init() {
// This is already being called on the init hook, so just add it.
self::register_blocks();

\add_action( 'wp_head', array( self::class, 'inject_activitypub_options' ), 11 );
\add_action( 'admin_print_scripts', array( self::class, 'inject_activitypub_options' ) );
\add_action( 'load-post-new.php', array( self::class, 'handle_in_reply_to_get_param' ) );
// Add editor plugin.
\add_action( 'enqueue_block_editor_assets', array( self::class, 'enqueue_editor_assets' ) );
Expand Down Expand Up @@ -95,12 +93,24 @@ public static function register_postmeta() {
* Enqueue the block editor assets.
*/
public static function enqueue_editor_assets() {
$data = array(
'namespace' => ACTIVITYPUB_REST_NAMESPACE,
'defaultAvatarUrl' => ACTIVITYPUB_PLUGIN_URL . 'assets/img/mp.jpg',
'enabled' => array(
'site' => ! is_user_type_disabled( 'blog' ),
'users' => ! is_user_type_disabled( 'user' ),
),
'maxImageAttachments' => \get_option( 'activitypub_max_image_attachments', ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS ),
);
wp_localize_script( 'wp-editor', '_activityPubOptions', $data );

// Check for our supported post types.
$current_screen = \get_current_screen();
$ap_post_types = \get_post_types_by_support( 'activitypub' );
if ( ! $current_screen || ! in_array( $current_screen->post_type, $ap_post_types, true ) ) {
return;
}

$asset_data = include ACTIVITYPUB_PLUGIN_DIR . 'build/editor-plugin/plugin.asset.php';
$plugin_url = plugins_url( 'build/editor-plugin/plugin.js', ACTIVITYPUB_PLUGIN_FILE );
wp_enqueue_script( 'activitypub-block-editor', $plugin_url, $asset_data['dependencies'], $asset_data['version'], true );
Expand All @@ -121,42 +131,20 @@ public static function handle_in_reply_to_get_param() {
wp_enqueue_script( 'activitypub-reply-intent', $plugin_url, $asset_data['dependencies'], $asset_data['version'], true );
}

/**
* Output ActivityPub options as a script tag.
*/
public static function inject_activitypub_options() {
$data = array(
'namespace' => ACTIVITYPUB_REST_NAMESPACE,
'defaultAvatarUrl' => ACTIVITYPUB_PLUGIN_URL . 'assets/img/mp.jpg',
'enabled' => array(
'site' => ! is_user_type_disabled( 'blog' ),
'users' => ! is_user_type_disabled( 'user' ),
),
'maxImageAttachments' => \get_option( 'activitypub_max_image_attachments', ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS ),
);

printf(
"\n<script>var _activityPubOptions = %s;</script>",
wp_json_encode( $data )
);
}

/**
* Register the blocks.
*/
public static function register_blocks() {
\register_block_type_from_metadata( ACTIVITYPUB_PLUGIN_DIR . '/build/followers' );

\register_block_type_from_metadata( ACTIVITYPUB_PLUGIN_DIR . '/build/follow-me' );
\register_block_type_from_metadata( ACTIVITYPUB_PLUGIN_DIR . '/build/followers' );
\register_block_type_from_metadata( ACTIVITYPUB_PLUGIN_DIR . '/build/reactions' );

\register_block_type_from_metadata(
ACTIVITYPUB_PLUGIN_DIR . '/build/reply',
array(
'render_callback' => array( self::class, 'render_reply_block' ),
)
);

\register_block_type_from_metadata( ACTIVITYPUB_PLUGIN_DIR . '/build/reactions' );
}

/**
Expand Down
17 changes: 8 additions & 9 deletions src/editor-plugin/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useEntityProp } from '@wordpress/core-data';
import { addQueryArgs } from '@wordpress/url';
import { __ } from '@wordpress/i18n';
import { SVG, Path } from '@wordpress/primitives';
import { useOptions } from '../shared/use-options';

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

// Don't show when editing sync blocks.
if ( 'wp_block' === postType ) {
return null;
}
const { maxImageAttachments = 4 } = useOptions();
const labelStyling = {
verticalAlign: 'middle',
gap: '4px',
Expand All @@ -55,11 +61,6 @@ const EditorPlugin = () => {
</Tooltip>
);

// Don't show when editing sync blocks.
if ( 'wp_block' === postType ) {
return null;
}

return (
<PluginDocumentSettingPanel
name="activitypub"
Expand All @@ -83,9 +84,7 @@ const EditorPlugin = () => {

<RangeControl
label={ __( 'Maximum Image Attachments', 'activitypub' ) }
value={
meta?.activitypub_max_image_attachments ?? window._activityPubOptions?.maxImageAttachments ?? 4
}
value={ meta?.activitypub_max_image_attachments ?? maxImageAttachments }
onChange={ ( value ) => {
setMeta( { ...meta, activitypub_max_image_attachments: value } );
} }
Expand Down
Loading