Yoast\WP\SEO\Abilities\Infrastructure

Post_Identifier_Resolver::by_permalink │ private │ Yoast 1.0

Resolves a post by its permalink.

Matches the permalink exactly against the indexable table; no WordPress URL resolution is performed, so the exact stored permalink must be provided.

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

Хуков нет.

Возвращает

Indexable|WP_Error. The matching indexable, or a not-found error.

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

// private - только в коде основоного (родительского) класса
$result = $this->by_permalink( $permalink );
$permalink(строка) (обязательный)
The permalink.

Код Post_Identifier_Resolver::by_permalink() Yoast 28.9

private function by_permalink( string $permalink ) {
	$indexable = $this->indexable_repository->find_by_permalink( $permalink );

	// A static front page shares its URL with the home-page indexable, which the lookup can return instead of the page itself.
	if ( $indexable && $indexable->object_type === 'home-page' ) {
		$front_page_id = $this->current_page_helper->get_front_page_id();

		if ( $front_page_id !== 0 ) {
			$indexable = $this->indexable_repository->find_by_id_and_type( $front_page_id, 'post', false );
		}
	}

	// The permalink lookup is not scoped by object type, so a term, author, or
	// archive URL can match too; only posts are valid targets here.
	if ( ! $indexable || $indexable->object_type !== 'post' ) {
		return $this->invalid_identifier( 'permalink' );
	}

	return $indexable;
}