Yoast\WP\SEO\Repositories

Indexable_Repository::for_current_page()publicYoast 1.0

Attempts to find the indexable for the current WordPress page. Returns false if no indexable could be found. This may be the result of the indexable not existing or of being unable to determine what type of page the current page is.

Метод класса: Indexable_Repository{}

Хуков нет.

Возвращает

true|false|Indexable. The indexable. If no indexable is found returns an empty indexable. Returns false if there is a database error.

Использование

$Indexable_Repository = new Indexable_Repository();
$Indexable_Repository->for_current_page();

Код Indexable_Repository::for_current_page() Yoast 22.4

public function for_current_page() {
	$indexable = false;

	switch ( true ) {
		case $this->current_page->is_simple_page():
			$indexable = $this->find_by_id_and_type( $this->current_page->get_simple_page_id(), 'post' );
			break;
		case $this->current_page->is_home_static_page():
			$indexable = $this->find_by_id_and_type( $this->current_page->get_front_page_id(), 'post' );
			break;
		case $this->current_page->is_home_posts_page():
			$indexable = $this->find_for_home_page();
			break;
		case $this->current_page->is_term_archive():
			$indexable = $this->find_by_id_and_type( $this->current_page->get_term_id(), 'term' );
			break;
		case $this->current_page->is_date_archive():
			$indexable = $this->find_for_date_archive();
			break;
		case $this->current_page->is_search_result():
			$indexable = $this->find_for_system_page( 'search-result' );
			break;
		case $this->current_page->is_post_type_archive():
			$indexable = $this->find_for_post_type_archive( $this->current_page->get_queried_post_type() );
			break;
		case $this->current_page->is_author_archive():
			$indexable = $this->find_by_id_and_type( $this->current_page->get_author_id(), 'user' );
			break;
		case $this->current_page->is_404():
			$indexable = $this->find_for_system_page( '404' );
			break;
	}

	if ( $indexable === false ) {
		return $this->query()->create(
			[
				'object_type' => 'unknown',
				'post_status' => 'unindexed',
				'version'     => 1,
			]
		);
	}

	return $indexable;
}