Yoast\WP\SEO\Builders

Indexable_Post_Builder::build()publicYoast 1.0

Formats the data.

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

Хуков нет.

Возвращает

true|false|Indexable. The extended indexable. False when unable to build.

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

$Indexable_Post_Builder = new Indexable_Post_Builder();
$Indexable_Post_Builder->build( $post_id, $indexable );
$post_id(int) (обязательный)
The post ID to use.
$indexable(Indexable) (обязательный)
The indexable to format.

Код Indexable_Post_Builder::build() Yoast 22.4

public function build( $post_id, $indexable ) {
	if ( ! $this->post_helper->is_post_indexable( $post_id ) ) {
		throw Post_Not_Built_Exception::because_not_indexable( $post_id );
	}

	$post = $this->post_helper->get_post( $post_id );

	if ( $post === null ) {
		throw new Post_Not_Found_Exception();
	}

	if ( $this->should_exclude_post( $post ) ) {
		throw Post_Not_Built_Exception::because_post_type_excluded( $post_id );
	}

	$indexable->object_id       = $post_id;
	$indexable->object_type     = 'post';
	$indexable->object_sub_type = $post->post_type;
	$indexable->permalink       = $this->get_permalink( $post->post_type, $post_id );

	$indexable->primary_focus_keyword_score = $this->get_keyword_score(
		$this->meta->get_value( 'focuskw', $post_id ),
		(int) $this->meta->get_value( 'linkdex', $post_id )
	);

	$indexable->readability_score = (int) $this->meta->get_value( 'content_score', $post_id );

	$indexable->inclusive_language_score = (int) $this->meta->get_value( 'inclusive_language_score', $post_id );

	$indexable->is_cornerstone    = ( $this->meta->get_value( 'is_cornerstone', $post_id ) === '1' );
	$indexable->is_robots_noindex = $this->get_robots_noindex(
		(int) $this->meta->get_value( 'meta-robots-noindex', $post_id )
	);

	// Set additional meta-robots values.
	$indexable->is_robots_nofollow = ( $this->meta->get_value( 'meta-robots-nofollow', $post_id ) === '1' );
	$noindex_advanced              = $this->meta->get_value( 'meta-robots-adv', $post_id );
	$meta_robots                   = \explode( ',', $noindex_advanced );

	foreach ( $this->get_robots_options() as $meta_robots_option ) {
		$indexable->{'is_robots_' . $meta_robots_option} = \in_array( $meta_robots_option, $meta_robots, true ) ? 1 : null;
	}

	$this->reset_social_images( $indexable );

	foreach ( $this->get_indexable_lookup() as $meta_key => $indexable_key ) {
		$indexable->{$indexable_key} = $this->empty_string_to_null( $this->meta->get_value( $meta_key, $post_id ) );
	}

	if ( empty( $indexable->breadcrumb_title ) ) {
		$indexable->breadcrumb_title = \wp_strip_all_tags( \get_the_title( $post_id ), true );
	}

	$this->handle_social_images( $indexable );

	$indexable->author_id   = $post->post_author;
	$indexable->post_parent = $post->post_parent;

	$indexable->number_of_pages  = $this->get_number_of_pages_for_post( $post );
	$indexable->post_status      = $post->post_status;
	$indexable->is_protected     = $post->post_password !== '';
	$indexable->is_public        = $this->is_public( $indexable );
	$indexable->has_public_posts = $this->has_public_posts( $indexable );
	$indexable->blog_id          = \get_current_blog_id();

	$indexable->schema_page_type    = $this->empty_string_to_null( $this->meta->get_value( 'schema_page_type', $post_id ) );
	$indexable->schema_article_type = $this->empty_string_to_null( $this->meta->get_value( 'schema_article_type', $post_id ) );

	$indexable->object_last_modified = $post->post_modified_gmt;
	$indexable->object_published_at  = $post->post_date_gmt;

	$indexable->version = $this->version;

	return $indexable;
}