options_helper = $options_helper; $this->indexable_helper = $indexable_helper; $this->indexable_repository = $indexable_repository; $this->meta = $meta; } /** * The post method to get all relevant content type entries * * @return array> The posts that are relevant for the LLMs.txt. */ public function get_posts(): array { $posts = []; $pages = [ 'about_us_page', 'contact_page', 'terms_page', 'privacy_policy_page', 'shop_page', ]; foreach ( $pages as $page ) { $page_id = $this->options_helper->get( $page ); if ( ! empty( $page_id ) ) { $post = $this->get_content_type_entry( $page_id ); if ( $post !== null ) { $posts[] = $post; } else { $this->options_helper->set( $page, 0 ); } } } $other_pages = $this->options_helper->get( 'other_included_pages' ); $filtered_pages = []; if ( ! empty( $other_pages ) ) { foreach ( $other_pages as $page_id ) { $post = $this->get_content_type_entry( $page_id ); if ( $post !== null ) { $posts[] = $post; $filtered_pages[] = $page_id; } } if ( \count( $filtered_pages ) !== \count( $other_pages ) ) { $this->options_helper->set( 'other_included_pages', $filtered_pages ); } } return $posts; } /** * Gets the content entries. * * @param int $page_id The id of the page. * * @return Content_Type_Entry The content type entry. */ public function get_content_type_entry( int $page_id ): ?Content_Type_Entry { if ( $this->indexable_helper->should_index_indexables() ) { $post = $this->get_content_type_entry_for_indexable( $page_id ); } else { $post = $this->get_content_type_entry_wp_query( $page_id ); } return $post; } /** * Gets the content entries with WP query. * * @param int $page_id The id of the page. * * @return Content_Type_Entry The content type entry. */ public function get_content_type_entry_wp_query( int $page_id ): ?Content_Type_Entry { $page = \get_post( $page_id ); if ( $page !== null && $page->post_password === '' && $page->post_status === 'publish' ) { return Content_Type_Entry::from_post( $page, \get_permalink( $page->ID ) ); } return null; } /** * Gets the content entries with indexables. * * @param int $page_id The id of the page. * * @return Content_Type_Entry The content type entry. */ public function get_content_type_entry_for_indexable( int $page_id ): ?Content_Type_Entry { $indexable = $this->indexable_repository->find_by_id_and_type( $page_id, 'post' ); if ( $indexable && ( $indexable->is_public === null || $indexable->is_public ) ) { $indexable_meta = $this->meta->for_indexable( $indexable ); if ( $indexable_meta->post instanceof WP_Post ) { return Content_Type_Entry::from_meta( $indexable_meta ); } } return null; } }