Yoast\WP\SEO\Bulk_Editor\Infrastructure\Posts
Post_Meta_Posts_Collector::build_post
Builds a post from its ID.
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.
Метод класса: Post_Meta_Posts_Collector{}
Хуков нет.
Возвращает
Post. The post.
Использование
// private - только в коде основоного (родительского) класса $result = $this->build_post( $post_id, $editable, $scores_enabled, $content_type ): Post;
- $post_id(int) (обязательный)
- The post ID.
- $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.
- $content_type(строка) (обязательный)
- The post type of the collected page.
Код Post_Meta_Posts_Collector::build_post() Post Meta Posts Collector::build post Yoast 28.9
private function build_post( int $post_id, bool $editable, bool $scores_enabled, string $content_type ): Post {
$post = \get_post( $post_id );
$status = ( $post !== null ) ? (string) $post->post_status : '';
$post_type = ( $post !== null ) ? (string) $post->post_type : '';
$title = $this->get_normalized_title( $post_id );
$images = $this->get_post_images( $post_id, $content_type );
$context = $this->get_post_context( $post_id, $content_type );
if ( ! $editable ) {
return new Post( $post_id, $title, $status, '', '', '', '', '', '', false, [], '', '', '', '', $images, $context );
}
// Read each field's value once from its meta suffix, keyed by field param, so the values can be reused for
// the needs-improvement filter. Built from the suffix map to keep a single source of truth.
$fields = [];
foreach ( self::FIELD_META_SUFFIXES as $field => $suffix ) {
$fields[ $field ] = $this->get_meta( $post_id, $suffix );
}
$raw_seo_title = $fields['seo_title'];
$raw_meta_description = $fields['meta_description'];
$raw_social_title = $fields['social_title'];
$raw_social_description = $fields['social_description'];
// Resolve templates for needs-improvement scoring and as display fallbacks when the stored value is empty.
$fields['seo_title'] = $this->default_template_resolver->resolve_seo_title( $post_id, $post_type, $raw_seo_title );
$fields['meta_description'] = $this->default_template_resolver->resolve_meta_description( $post_id, $post_type, $raw_meta_description );
$fields['social_title'] = $this->default_template_resolver->resolve_social_title( $post_id, $post_type, $raw_social_title );
$fields['social_description'] = $this->default_template_resolver->resolve_social_description( $post_id, $post_type, $raw_social_description );
return new Post(
$post_id,
$title,
$status,
(string) \get_edit_post_link( $post_id, 'raw' ),
$this->get_meta( $post_id, 'focuskw' ),
$raw_seo_title,
$raw_meta_description,
$raw_social_title,
$raw_social_description,
true,
$this->build_needs_improvement( $post_id, $fields, $scores_enabled ),
( $raw_seo_title === '' ) ? $fields['seo_title'] : '',
( $raw_meta_description === '' ) ? $fields['meta_description'] : '',
( $raw_social_title === '' ) ? $fields['social_title'] : '',
( $raw_social_description === '' ) ? $fields['social_description'] : '',
$images,
$context,
);
}