Skip to content

Commit cdb231f

Browse files
authored
Add Command Palette integration for ActivityPub (#2315)
1 parent 29db902 commit cdb231f

File tree

13 files changed

+1855
-337
lines changed

13 files changed

+1855
-337
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: added
3+
4+
Add Command Palette integration for quick navigation to ActivityPub admin pages

build/command-palette/block.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "https://schemas.wp.org/trunk/block.json",
3+
"apiVersion": 3,
4+
"name": "activitypub/command-palette",
5+
"title": "ActivityPub Command Palette",
6+
"category": "widgets",
7+
"description": "Registers ActivityPub commands for the WordPress Command Palette.",
8+
"textdomain": "activitypub",
9+
"editorScript": "file:./plugin.js"
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php return array('dependencies' => array('react', 'react-jsx-runtime', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'e39de7b99dcb1cb7d308');

build/command-palette/plugin.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/class-post-types.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,15 @@ public static function register_extra_fields_post_types() {
433433
'show_in_rest' => true,
434434
'map_meta_cap' => true,
435435
'show_ui' => true,
436-
'supports' => array( 'title', 'editor', 'page-attributes' ),
436+
'supports' => array( 'title', 'editor', 'page-attributes', 'author' ),
437+
'capabilities' => array(
438+
'edit_others_posts' => 'do_not_allow', // Disallow editing others' Extra Fields (only own ones).
439+
),
437440
);
438441

439442
\register_post_type( Extra_Fields::USER_POST_TYPE, $extra_field_args );
443+
444+
unset( $extra_field_args['capabilities'] ); // Allow editing the Blog's Extra Fields.
440445
\register_post_type( Extra_Fields::BLOG_POST_TYPE, $extra_field_args );
441446

442447
/**

includes/wp-admin/class-admin.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,28 @@ public static function enqueue_scripts( $hook_suffix ) {
273273
false
274274
);
275275

276+
// Register and enqueue command palette integration.
277+
if ( user_can_activitypub( \get_current_user_id() ) || \current_user_can( 'manage_options' ) ) {
278+
$asset_data = include ACTIVITYPUB_PLUGIN_DIR . 'build/command-palette/plugin.asset.php';
279+
wp_enqueue_script(
280+
'activitypub-command-palette',
281+
plugins_url( 'build/command-palette/plugin.js', ACTIVITYPUB_PLUGIN_FILE ),
282+
$asset_data['dependencies'],
283+
$asset_data['version'],
284+
true
285+
);
286+
287+
wp_localize_script(
288+
'activitypub-command-palette',
289+
'activitypubCommandPalette',
290+
array(
291+
'followingEnabled' => '1' === \get_option( 'activitypub_following_ui', '0' ),
292+
'actorMode' => \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ),
293+
'canManageOptions' => \current_user_can( 'manage_options' ),
294+
)
295+
);
296+
}
297+
276298
if ( false !== strpos( $hook_suffix, 'activitypub' ) ) {
277299
wp_enqueue_style(
278300
'activitypub-admin-styles',
@@ -406,16 +428,6 @@ function ( $all_caps, $caps, $arg ) {
406428
* Add ActivityPub specific actions/filters to the post list view.
407429
*/
408430
public static function list_posts() {
409-
// Show only the user's extra fields.
410-
\add_action(
411-
'pre_get_posts',
412-
function ( $query ) {
413-
if ( $query->get( 'post_type' ) === 'ap_extrafield' ) {
414-
$query->set( 'author', get_current_user_id() );
415-
}
416-
}
417-
);
418-
419431
// Remove all views for the extra fields.
420432
$screen_id = get_current_screen()->id;
421433

0 commit comments

Comments
 (0)