Yoast\WP\SEO\Builders

Indexable_Post_Builder::has_public_posts()protectedYoast 1.0

Determines the value of has_public_posts.

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

Хуков нет.

Возвращает

true|false|null. Whether the attachment has a public parent, can be true, false and null. Null when it is not an attachment.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->has_public_posts( $indexable );
$indexable(Indexable) (обязательный)
The indexable.

Код Indexable_Post_Builder::has_public_posts() Yoast 22.4

protected function has_public_posts( $indexable ) {
	// Only attachments (and authors) have this value.
	if ( $indexable->object_sub_type !== 'attachment' ) {
		return null;
	}

	// The attachment should have a post parent.
	if ( empty( $indexable->post_parent ) ) {
		return false;
	}

	// The attachment should inherit the post status.
	if ( $indexable->post_status !== 'inherit' ) {
		return false;
	}

	// The post parent should be public.
	$post_parent_indexable = $this->indexable_repository->find_by_id_and_type( $indexable->post_parent, 'post' );
	if ( $post_parent_indexable !== false ) {
		return $post_parent_indexable->is_public;
	}

	return false;
}