Yoast\WP\SEO\Bulk_Editor\Infrastructure\Posts
Indexable_Posts_Collector::build_post
Builds a post from an indexable.
The SEO data and edit link of a post the current user cannot edit are withheld, so the post is shown in the list but stays locked and does not expose its metadata.
Метод класса: Indexable_Posts_Collector{}
Хуков нет.
Возвращает
Post. The post.
Использование
// private - только в коде основоного (родительского) класса $result = $this->build_post( $indexable, $editable, $scores_enabled ): Post;
- $indexable(Indexable) (обязательный)
- The indexable.
- $editable(true|false) (обязательный)
- Whether the current user may edit the post.
- $scores_enabled(true|false) (обязательный)
- Whether the per-field scores may back the needs-improvement verdict.
Код Indexable_Posts_Collector::build_post() Indexable Posts Collector::build post Yoast 28.9
private function build_post( Indexable $indexable, bool $editable, bool $scores_enabled ): Post {
$object_id = (int) $indexable->object_id;
$post_type = (string) $indexable->object_sub_type;
$title = $this->get_normalized_title( $object_id );
$images = $this->get_post_images( $object_id, $post_type );
$context = $this->get_post_context( $object_id, $post_type );
if ( ! $editable ) {
return new Post( $object_id, $title, (string) $indexable->post_status, '', '', '', '', '', '', false, [], '', '', '', '', $images, $context );
}
$raw_seo_title = (string) $indexable->title;
$raw_meta_description = (string) $indexable->description;
$raw_social_title = (string) $indexable->open_graph_title;
$raw_social_description = (string) $indexable->open_graph_description;
// Resolver results are used for needs-improvement scoring and as display fallbacks when the stored value is empty.
$resolved_values = [
'seo_title' => $this->default_template_resolver->resolve_seo_title( $object_id, $post_type, $raw_seo_title ),
'meta_description' => $this->default_template_resolver->resolve_meta_description( $object_id, $post_type, $raw_meta_description ),
'social_title' => $this->default_template_resolver->resolve_social_title( $object_id, $post_type, $raw_social_title ),
'social_description' => $this->default_template_resolver->resolve_social_description( $object_id, $post_type, $raw_social_description ),
];
return new Post(
$object_id,
$title,
(string) $indexable->post_status,
(string) \get_edit_post_link( $object_id, 'raw' ),
(string) $indexable->primary_focus_keyword,
$raw_seo_title,
$raw_meta_description,
$raw_social_title,
$raw_social_description,
true,
$this->build_needs_improvement( $indexable, $scores_enabled, $resolved_values ),
( $raw_seo_title === '' ) ? $resolved_values['seo_title'] : '',
( $raw_meta_description === '' ) ? $resolved_values['meta_description'] : '',
( $raw_social_title === '' ) ? $resolved_values['social_title'] : '',
( $raw_social_description === '' ) ? $resolved_values['social_description'] : '',
$images,
$context,
);
}