array( 'labels' => array( 'name' => __( 'Organizers', 'gatherpress' ), 'singular_name' => __( 'Organizer', 'gatherpress' ), 'plural_name' => __( 'Organizers', 'gatherpress' ), ), 'field' => array( 'type' => 'autocomplete', 'options' => array( 'type' => 'user', 'label' => __( 'Select Organizers', 'gatherpress' ), ), ), ), ); /** * Filter the list of roles for GatherPress. * * This filter allows modification of the list of user roles used by GatherPress. * By default, GatherPress supports only the 'Organizers' role. * * @since 1.0.0 * * @param array $roles An array of user roles supported by GatherPress. * By default, it includes only the 'Organizers' role. * @return array The modified array of user roles. */ $roles = apply_filters( 'gatherpress_roles', $roles ); return array( 'roles' => array( 'name' => __( 'Roles', 'gatherpress' ), 'description' => __( 'Customize role labels to be more appropriate for events.', 'gatherpress' ), 'options' => $roles, ), ); } /** * Retrieve a list of user roles. * * This method returns an array of user roles defined for GatherPress. User roles * are used to customize role labels to be more appropriate for events. * * @since 1.0.0 * * @return array An array containing user roles and their corresponding settings. */ public function get_user_roles(): array { $sub_pages = Settings::get_instance()->get_sub_pages(); return (array) $sub_pages['leadership']['sections']['roles']['options']; } /** * Retrieve the role of a user. * * This method returns the role of a user identified by their User ID. * * @since 1.0.0 * * @param int $user_id User ID. * @return string The role of the user, or 'Member' if no matching role is found. */ public function get_user_role( int $user_id ): string { $leadership = get_option( Utility::prefix_key( 'leadership' ) ); $roles = $leadership['roles'] ?? array(); $default = __( 'Member', 'gatherpress' ); foreach ( $roles as $role => $users ) { foreach ( json_decode( $users ) as $user ) { if ( intval( $user->id ) === $user_id ) { $roles = $this->get_user_roles(); return $roles[ $role ]['labels']['singular_name'] ?? $default; } } } return $default; } }