*/ public function operator_labels(): array { return array( 'is' => __( 'Is', 'blocksieve' ), 'is_not' => __( 'Is not', 'blocksieve' ), 'between' => __( 'Between', 'blocksieve' ), 'not_between' => __( 'Not between', 'blocksieve' ), 'in' => __( 'In', 'blocksieve' ), 'not_in' => __( 'Not in', 'blocksieve' ), 'contains' => __( 'Contains', 'blocksieve' ), 'not_contains' => __( 'Does not contain', 'blocksieve' ), 'exists' => __( 'Exists', 'blocksieve' ), 'not_exists' => __( 'Does not exist', 'blocksieve' ), ); } /** * Returns the label for a single operator, falling back to its identifier. * * @param string $operator Operator identifier. * @return string */ public function operator_label( string $operator ): string { $labels = $this->operator_labels(); return $labels[ $operator ] ?? ucfirst( $operator ); } /** * Builds operator option pairs for the given operator identifiers. * * @param string[] $operators Operator identifiers. * @return array */ public function operator_options( array $operators ): array { $out = array(); foreach ( $operators as $operator ) { $out[] = array( 'value' => (string) $operator, 'label' => $this->operator_label( (string) $operator ), ); } return $out; } /** * All registered roles as option pairs. * * Reads `wp_roles()` rather than `get_editable_roles()`: the latter lives in * wp-admin/includes and is undefined during REST requests, and it would also * hide roles the current editor cannot assign (which they may still target). * * @return array */ public function role_options(): array { $out = array(); foreach ( wp_roles()->roles as $slug => $data ) { $out[] = array( 'value' => (string) $slug, 'label' => translate_user_role( (string) ( $data['name'] ?? $slug ) ), ); } return $out; } /** * Public post types as option pairs. * * @return array */ public function post_type_options(): array { $out = array(); foreach ( get_post_types( array( 'public' => true ), 'objects' ) as $type ) { $out[] = array( 'value' => (string) $type->name, 'label' => (string) $type->labels->name, ); } return $out; } /** * Weekday option pairs (Mon = 1 … Sun = 7). * * @return array */ public function weekday_options(): array { $labels = array( 1 => __( 'Monday', 'blocksieve' ), 2 => __( 'Tuesday', 'blocksieve' ), 3 => __( 'Wednesday', 'blocksieve' ), 4 => __( 'Thursday', 'blocksieve' ), 5 => __( 'Friday', 'blocksieve' ), 6 => __( 'Saturday', 'blocksieve' ), 7 => __( 'Sunday', 'blocksieve' ), ); $out = array(); foreach ( $labels as $value => $label ) { $out[] = array( 'value' => $value, 'label' => $label, ); } return $out; } /** * Page-view (archive) option pairs matching the Archive condition enum. * * @return array */ public function archive_type_options(): array { $pairs = array( 'home' => __( 'Blog posts index', 'blocksieve' ), 'front_page' => __( 'Front page', 'blocksieve' ), 'archive' => __( 'Any archive', 'blocksieve' ), 'category' => __( 'Category archive', 'blocksieve' ), 'tag' => __( 'Tag archive', 'blocksieve' ), 'taxonomy' => __( 'Taxonomy archive', 'blocksieve' ), 'date' => __( 'Date archive', 'blocksieve' ), 'author' => __( 'Author archive', 'blocksieve' ), 'post_type' => __( 'Post type archive', 'blocksieve' ), 'search' => __( 'Search results', 'blocksieve' ), '404' => __( '404 (not found)', 'blocksieve' ), 'single' => __( 'Single post, page or other single item', 'blocksieve' ), ); $out = array(); foreach ( $pairs as $value => $label ) { $out[] = array( // Cast: PHP turns the numeric-string key '404' into int 404. 'value' => (string) $value, 'label' => $label, ); } return $out; } /** * Device option pairs. * * @return array */ public function device_options(): array { return array( array( 'value' => 'desktop', 'label' => __( 'Desktop', 'blocksieve' ), ), array( 'value' => 'tablet', 'label' => __( 'Tablet', 'blocksieve' ), ), array( 'value' => 'mobile', 'label' => __( 'Mobile', 'blocksieve' ), ), ); } /** * Returns the slugs of all public post types. * * @return string[] */ public function public_post_types(): array { return array_values( get_post_types( array( 'public' => true ), 'names' ) ); } /** * Flattens option pairs into a value → label map. * * @param array $options Option pairs. * @return array */ public function to_map( array $options ): array { $map = array(); foreach ( $options as $option ) { $map[ (string) $option['value'] ] = (string) $option['label']; } return $map; } }