Skip to content

Commit 49f0883

Browse files
committed
Fix: Harden callbacks and fix permission fallback
1 parent 0590c7e commit 49f0883

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

src/wp-includes/abilities.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,14 @@ function wp_register_core_abilities(): void {
330330
'additionalProperties' => false,
331331
),
332332
'execute_callback' => static function ( $input = array() ) {
333+
$input = is_array( $input ) ? $input : array();
333334
$user = null;
334-
if ( ! empty( $input['id'] ) ) {
335+
336+
if ( isset( $input['id'] ) ) {
335337
$user = get_user_by( 'id', $input['id'] );
336-
} elseif ( ! empty( $input['username'] ) ) {
338+
} elseif ( isset( $input['username'] ) ) {
337339
$user = get_user_by( 'login', $input['username'] );
338-
} elseif ( ! empty( $input['email'] ) ) {
340+
} elseif ( isset( $input['email'] ) ) {
339341
$user = get_user_by( 'email', $input['email'] );
340342
}
341343

@@ -374,26 +376,23 @@ function wp_register_core_abilities(): void {
374376

375377
return $result;
376378
},
377-
'permission_callback' => static function ( $input = array() ) {
379+
'permission_callback' => static function ( $input = array() ): bool {
378380
if ( ! is_user_logged_in() ) {
379381
return false;
380382
}
381383

384+
$input = is_array( $input ) ? $input : array();
385+
382386
$target_user = null;
383-
if ( ! empty( $input['id'] ) ) {
387+
if ( isset( $input['id'] ) ) {
384388
$target_user = get_user_by( 'id', $input['id'] );
385-
} elseif ( ! empty( $input['username'] ) ) {
389+
} elseif ( isset( $input['username'] ) ) {
386390
$target_user = get_user_by( 'login', $input['username'] );
387-
} elseif ( ! empty( $input['email'] ) ) {
391+
} elseif ( isset( $input['email'] ) ) {
388392
$target_user = get_user_by( 'email', $input['email'] );
389393
}
390394

391-
if ( ! $target_user || is_wp_error( $target_user ) ) {
392-
return true;
393-
}
394-
395-
$current_user = wp_get_current_user();
396-
if ( (int) $target_user->ID === (int) $current_user->ID ) {
395+
if ( $target_user instanceof WP_User && get_current_user_id() === $target_user->ID ) {
397396
return true;
398397
}
399398

0 commit comments

Comments
 (0)