|null */ private $conditions = null; /** * Returns the condition for a type, or null when it isn't registered. * * @param string $type Condition type ID. * @return Condition|null */ public function get( string $type ): ?Condition { return $this->all()[ $type ] ?? null; } /** * All registered conditions, keyed by type, in the order they were registered. * * The list is built on first use, not when the plugin boots, so conditions * that Pro adds later through the filter are included. * * @return array */ public function all(): array { if ( null !== $this->conditions ) { return $this->conditions; } $this->conditions = array(); $free = array(); foreach ( array( new UserState(), new UserRole(), new PageType(), new ArchivePage(), new VisitorDevice() ) as $condition ) { $free[ $condition->type() ] = $condition; } /** * Filters the condition types that can be checked, keyed by type ID. * * @param array $conditions Condition objects keyed by type ID. * Values that aren't a Condition are ignored. */ $conditions = apply_filters( 'yangra_conditional_condition_types', $free ); foreach ( (array) $conditions as $type => $condition ) { if ( $condition instanceof Condition ) { $this->conditions[ (string) $type ] = $condition; } } return $this->conditions; } /** * Whether a type is one of the Pro condition types. * * @param string $type Condition type ID. * @return bool */ public function is_pro_type( string $type ): bool { return in_array( $type, self::PRO_TYPES, true ); } /** * Translated name of a Pro condition type, for "Requires Pro, skipped" warnings. * * @param string $type Pro condition type ID. * @return string The name, or the type ID if it isn't a Pro type. */ public function pro_type_label( string $type ): string { $labels = array( 'visitor_location' => __( 'Visitor location', 'yangra-conditional' ), 'visitor_language' => __( 'Visitor language', 'yangra-conditional' ), 'user_group' => __( 'User group', 'yangra-conditional' ), ); return $labels[ $type ] ?? $type; } }