Yoast\WP\SEO\Abilities\Infrastructure

Post_Identifier_Resolver::resolve_one │ public │ Yoast 1.0

Resolves the input to exactly one post indexable.

Used by operations that have to target a single, unambiguous post. Title keywords are deliberately not accepted here: they can match several posts, so only an exact identifier (post ID or permalink) is allowed.

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

Хуков нет.

Возвращает

Indexable|WP_Error. The matching indexable, or an error (missing or unknown identifier).

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

$Post_Identifier_Resolver = new Post_Identifier_Resolver();
$Post_Identifier_Resolver->resolve_one( $input );
$input(array<string, int|строка|true|false|null>) (обязательный)
The input containing one of 'post_id' or 'permalink'.

Код Post_Identifier_Resolver::resolve_one() Yoast 28.9

public function resolve_one( array $input ) {
	if ( $this->has( $input, 'post_id' ) ) {
		return $this->by_id( (int) $input['post_id'] );
	}

	if ( $this->has( $input, 'permalink' ) ) {
		return $this->by_permalink( (string) $input['permalink'] );
	}

	return new WP_Error(
		'yoast_seo_missing_identifier',
		\__( 'Provide a post_id or a permalink to identify the post.', 'wordpress-seo' ),
		[ 'status' => 400 ],
	);
}