0 ? $existing : get_current_user_id(); RuntimeDebugger::add_server_error_log_entry( sprintf( 'AdPresso: refused to assign %s to user #%d (more rights than the current user).', $data['post_type'], $author ) ); return $data; } /** * Blocks edit_post/delete_post on entities whose author outranks the user. * * @param array $caps Primitive capabilities required. * @param string $cap Meta capability being checked. * @param int $user_id User being checked. * @param array $args Additional arguments, [0] is the post ID. */ public function deny_editing_items_of_more_privileged_authors( array $caps, string $cap, int $user_id, array $args ): array { if ( ! in_array( $cap, [ 'edit_post', 'delete_post' ], true ) || empty( $args[0] ) ) { return $caps; } $post = get_post( (int) $args[0] ); if ( ! $post || ! self::is_guarded_post_type( $post->post_type ) ) { return $caps; } $author_id = (int) $post->post_author; if ( $author_id === $user_id || ! get_userdata( $author_id ) ) { return $caps; } return self::outranks( $author_id, $user_id ) ? [ 'do_not_allow' ] : $caps; } /** * Super admins outrank everyone on multisite; otherwise unfiltered_html decides. * * @param int $user_id The user in question. * @param int $other_id The user to compare against. */ private static function outranks( int $user_id, int $other_id ): bool { if ( is_multisite() && is_super_admin( $user_id ) && ! is_super_admin( $other_id ) ) { return true; } return Util::user_can_unfiltered_html( $user_id ) && ! Util::user_can_unfiltered_html( $other_id ); } }