Yoast\WP\SEO\Builders
Indexable_Link_Builder::build
Builds the links for a post.
Метод класса: Indexable_Link_Builder{}
Хуки из метода
Возвращает
SEO_Links[]. The created SEO links.
Использование
$Indexable_Link_Builder = new Indexable_Link_Builder(); $Indexable_Link_Builder->build( $indexable, $content );
- $indexable(Indexable) (обязательный)
- The indexable.
- $content(строка) (обязательный)
- The content. Expected to be unfiltered.
Код Indexable_Link_Builder::build() Indexable Link Builder::build Yoast 26.7
public function build( $indexable, $content ) {
if ( ! $this->indexable_helper->should_index_indexable( $indexable ) ) {
return [];
}
global $post;
if ( $indexable->object_type === 'post' ) {
$post_backup = $post;
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- To setup the post we need to do this explicitly.
$post = $this->post_helper->get_post( $indexable->object_id );
\setup_postdata( $post );
$content = \apply_filters( 'the_content', $content );
\wp_reset_postdata();
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- To setup the post we need to do this explicitly.
$post = $post_backup;
}
$content = \str_replace( ']]>', ']]>', $content );
$links = $this->gather_links( $content );
$images = $this->image_content_extractor->gather_images( $content );
if ( empty( $links ) && empty( $images ) ) {
$indexable->link_count = 0;
$this->update_related_indexables( $indexable, [] );
return [];
}
if ( ! empty( $images ) && ( $indexable->open_graph_image_source === 'first-content-image' || $indexable->twitter_image_source === 'first-content-image' ) ) {
$this->update_first_content_image( $indexable, $images );
}
$links = $this->create_links( $indexable, $links, $images );
$this->update_related_indexables( $indexable, $links );
$indexable->link_count = $this->get_internal_link_count( $links );
return $links;
}