>> $groups_data */ public static function from_array( array $groups_data ): RuleSet { $groups = array(); foreach ( $groups_data as $group_data ) { $rules = array(); foreach ( (array) $group_data as $rule_data ) { $rule = self::build_rule( (array) $rule_data ); if ( null !== $rule ) { $rules[] = $rule; } } $groups[] = new RuleGroup( $rules ); } return new RuleSet( $groups ); } /** * @param array $rule_data */ private static function build_rule( array $rule_data ): ?RuleInterface { $type = isset( $rule_data['type'] ) ? (string) $rule_data['type'] : ''; $value = isset( $rule_data['value'] ) ? (string) $rule_data['value'] : ''; if ( 'page_template' === $type && '' !== $value ) { return new PageTemplateRule( $value ); } if ( 'conditional_tag' === $type && '' !== $value && in_array( $value, wp_list_pluck( ConditionalTags::all(), 'tag' ), true ) ) { return new ConditionalTagRule( $value ); } /** * Filters/extends rule-type resolution for custom location rules * (e.g. archive, taxonomy, or PHP-condition rules). * * @param RuleInterface|null $rule * @param string $type * @param string $value */ $rule = apply_filters( 'acez_seo_location_rule', null, $type, $value ); return $rule instanceof RuleInterface ? $rule : null; } }