Skip to content

Commit

Permalink
Don't require publish_post when manually adding cap
Browse files Browse the repository at this point in the history
  • Loading branch information
obenland committed Feb 3, 2025
1 parent 4b83d01 commit d31bb8b
Showing 1 changed file with 1 addition and 26 deletions.
27 changes: 1 addition & 26 deletions includes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public static function init() {
\add_action( 'load-comment.php', array( self::class, 'edit_comment' ) );
\add_action( 'load-post.php', array( self::class, 'edit_post' ) );
\add_action( 'load-edit.php', array( self::class, 'list_posts' ) );
\add_action( 'load-users.php', array( self::class, 'user_errors' ) );
\add_filter( 'page_row_actions', array( self::class, 'row_actions' ), 10, 2 );
\add_filter( 'post_row_actions', array( self::class, 'row_actions' ), 10, 2 );
\add_action( 'personal_options_update', array( self::class, 'save_user_settings' ) );
Expand Down Expand Up @@ -783,11 +782,7 @@ public static function handle_bulk_request( $sendback, $action, $users ) {
foreach ( $users as $user_id ) {
$user = new \WP_User( $user_id );
if ( 'add_activitypub_cap' === $action ) {
if ( \user_can( $user_id, 'publish_posts' ) ) {
$user->add_cap( 'activitypub' );
} else {
$sendback = \add_query_arg( 'update', 'activitypub_cap_error', $sendback );
}
$user->add_cap( 'activitypub' );
} elseif ( 'remove_activitypub_cap' === $action ) {
$user->remove_cap( 'activitypub' );
}
Expand All @@ -796,26 +791,6 @@ public static function handle_bulk_request( $sendback, $action, $users ) {
return $sendback;
}

/**
* Display an error message if the user has no publish_posts capability.
*/
public static function user_errors() {
if ( ! isset( $_GET['update'] ) || 'activitypub_cap_error' !== $_GET['update'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return;
}

// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$GLOBALS['errors'] = new \WP_Error( 'activitypub_cap_error', esc_html__( 'The user has to be able to publish posts to use ActivityPub.', 'activitypub' ) );

add_filter(
'wp_admin_notice_args',
function ( $args ) {
$args['paragraph_wrap'] = false;
return $args;
}
);
}

/**
* Add ActivityPub infos to the dashboard glance items.
*
Expand Down

0 comments on commit d31bb8b

Please sign in to comment.