*/ private const EVENT_TYPE_WORDS = [ 'offline' => 'offline', 'in-person' => 'offline', 'in person' => 'offline', 'in_person' => 'offline', 'inperson' => 'offline', 'physical' => 'offline', 'venue' => 'offline', 'onsite' => 'offline', 'on-site' => 'offline', 'on site' => 'offline', 'online' => 'online', 'virtual' => 'online', 'remote' => 'online', 'hybrid' => 'hybrid', ]; /** * Turn the assistant's word for an event type into Eventin's value. * * @param string|null $event_type Word from the assistant. * @return string|null One of offline, online, hybrid, or null when the word * is not recognised. */ protected static function normalize_event_type( ?string $event_type ): ?string { if ( null === $event_type ) { return null; } $key = strtolower( trim( $event_type ) ); return self::EVENT_TYPE_WORDS[ $key ] ?? null; } /** * Guard against Eventin being inactive or the user lacking capabilities. * * The user must hold at least one of the given capabilities. * Returns an error array on failure, null on success. * * @param string $capability Required capability slug. * @param string ...$extra_capabilities Additional capability slugs (user must hold any one). * @return array|null */ protected function guard( string $capability, string ...$extra_capabilities ): ?array { if ( ! class_exists( 'Wpeventin' ) ) { return [ 'error' => 'Eventin plugin is not active.' ]; } $all_capabilities = array_merge( [ $capability ], $extra_capabilities ); foreach ( $all_capabilities as $cap ) { if ( current_user_can( $cap ) ) { return null; } } return [ 'error' => 'You do not have permission to manage Eventin data.' ]; } }