$columns Existing columns. * @return array */ public function replace_role_column( array $columns ): array { unset( $columns['role'] ); $columns['aiou_roles'] = __( 'Roles', 'all-in-one-utilities' ); return $columns; } /** * Render the "Roles" column content. * * @param string $output Existing column HTML (should be empty). * @param string $column Column name. * @param int $user_id User id. * @return string */ public function render_role_column( string $output, string $column, int $user_id ): string { if ( 'aiou_roles' !== $column ) { return $output; } $roles = Roles::for_user( $user_id ); if ( empty( $roles ) ) { return '' . esc_html__( 'None', 'all-in-one-utilities' ) . ''; } $links = array(); foreach ( $roles as $slug => $label ) { $links[] = sprintf( '%s', esc_url( add_query_arg( 'role', $slug, admin_url( 'users.php' ) ) ), esc_html( translate_user_role( $label ) ) ); } return implode( ', ', $links ); } /** * Render the roles checklist on the profile/add-new-user/edit-user screens. * * @param WP_User|string $user_or_type A WP_User on show/edit_user_profile, or a type string on user_new_form. * @return void */ public function render_checklist( $user_or_type ): void { if ( ! Roles::current_user_can_manage() ) { return; } $user = $user_or_type instanceof WP_User ? $user_or_type : null; wp_nonce_field( self::NONCE_ACTION, self::NONCE_FIELD ); $roles = Roles::editable(); $user_roles = $user ? array_keys( Roles::for_user( $user->ID ) ) : array(); ?>

roles_from_request(); if ( null === $roles || ! current_user_can( 'promote_user', $user_id ) ) { return; } Roles::update( $user_id, $roles ); } /** * Multisite: stash the submitted roles in signup meta (the user doesn't * exist yet at this point -- they're only in the `wp_signups` table * pending activation). * * Only `$meta` is used; the other six arguments WordPress passes to this * filter (domain, path, title, user, user_email, key) are accepted by * the hook registration (`add_filter( ..., 10, 7 )`) but not declared * here, since PHP simply drops extra arguments a callback doesn't * declare parameters for. * * @param array $meta Signup meta. * @return array */ public function store_roles_in_signup_meta( $meta ) { $roles = $this->roles_from_request(); if ( empty( $roles ) ) { return $meta; } $meta['aiou_user_roles'] = $roles; return $meta; } /** * Multisite: apply the roles stashed in signup meta once the user * actually activates and a real account exists. * * @param int $user_id The newly activated user's id. * @param string $password Password (unused). * @param array $meta Signup meta. * @return void */ public function apply_roles_after_activation( int $user_id, string $password, array $meta ): void { if ( ! empty( $meta['aiou_user_roles'] ) ) { Roles::update( $user_id, (array) $meta['aiou_user_roles'] ); } } }