*/ public array $post_types; /** * Post statuses to include when scanning and suggesting. * * @var array */ public array $post_statuses; /** * Post IDs to exclude from scanning and from appearing as suggestions. * * @var array */ public array $excluded_post_ids; /** * Category IDs whose posts are excluded from scanning and suggestions. * * @var array */ public array $excluded_category_ids; /** * Language code override for stemming. * * Empty string means auto-detect from WordPress locale. * * @var string */ public string $language; /** * Whether to show the suggestion metabox on the post editor. * * @var bool */ public bool $show_metabox; /** * @since 1.0.0 * * @param array $post_types Optional. Default `['post']`. * @param array $post_statuses Optional. Default `['publish']`. * @param array $excluded_post_ids Optional. Default []. * @param array $excluded_category_ids Optional. Default []. * @param string $language Optional. Default '' (auto-detect). * @param bool $show_metabox Optional. Default true. */ public function __construct( array $post_types = array( 'post' ), array $post_statuses = array( 'publish' ), array $excluded_post_ids = array(), array $excluded_category_ids = array(), string $language = '', bool $show_metabox = true ) { $this->post_types = array() !== $post_types ? $post_types : array( 'post' ); $this->post_statuses = array() !== $post_statuses ? $post_statuses : array( 'publish' ); $this->excluded_post_ids = $excluded_post_ids; $this->excluded_category_ids = $excluded_category_ids; $this->language = $language; $this->show_metabox = $show_metabox; } /** * Hydrates a DTO from a raw settings array. * * @since 1.0.0 * * @param array $data Raw settings data. * * @return self */ public static function from_array( array $data ): self { $post_types = isset( $data['post_types'] ) && is_array( $data['post_types'] ) ? array_values( array_filter( $data['post_types'], 'is_string' ) ) : array( 'post' ); $post_statuses = isset( $data['post_statuses'] ) && is_array( $data['post_statuses'] ) ? array_values( array_filter( $data['post_statuses'], 'is_string' ) ) : array( 'publish' ); $excluded_post_ids = isset( $data['excluded_post_ids'] ) && is_array( $data['excluded_post_ids'] ) ? array_values( array_map( 'intval', $data['excluded_post_ids'] ) ) : array(); $excluded_category_ids = isset( $data['excluded_category_ids'] ) && is_array( $data['excluded_category_ids'] ) ? array_values( array_map( 'intval', $data['excluded_category_ids'] ) ) : array(); return new self( $post_types, $post_statuses, $excluded_post_ids, $excluded_category_ids, (string) ( $data['language'] ?? '' ), (bool) ( $data['show_metabox'] ?? true ) ); } /** * Serialises the DTO to a plain array for storage. * * @since 1.0.0 * * @return array */ public function to_array(): array { return array( 'post_types' => $this->post_types, 'post_statuses' => $this->post_statuses, 'excluded_post_ids' => $this->excluded_post_ids, 'excluded_category_ids' => $this->excluded_category_ids, 'language' => $this->language, 'show_metabox' => $this->show_metabox, ); } }