Yoast\WP\SEO\Builders
Indexable_Link_Builder::create_internal_link() protected Yoast 1.0
Creates an internal link.
{} Это метод класса: Indexable_Link_Builder{}
Хуков нет.
Возвращает
SEO_Links. The created link.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->create_internal_link( $url, $home_url, $indexable, $is_image );
- $url(строка) (обязательный)
- The url of the link.
- $home_url(массив) (обязательный)
- The home url, as parsed by wp_parse_url.
- $indexable(Indexable) (обязательный)
- The indexable of the post containing the link.
- $is_image(true/false)
- Whether or not the link is an image.
По умолчанию: false
Код Indexable_Link_Builder::create_internal_link() Indexable Link Builder::create internal link Yoast 15.6.2
protected function create_internal_link( $url, $home_url, $indexable, $is_image = false ) {
$parsed_url = \wp_parse_url( $url );
$link_type = $this->url_helper->get_link_type( $parsed_url, $home_url, $is_image );
/**
* ORM representing a link in the SEO Links table.
*
* @var SEO_Links $model
*/
$model = $this->seo_links_repository->query()->create(
[
'url' => $url,
'type' => $link_type,
'indexable_id' => $indexable->id,
'post_id' => $indexable->object_id,
]
);
$model->parsed_url = $parsed_url;
if ( $model->type === SEO_Links::TYPE_INTERNAL || $model->type === SEO_Links::TYPE_INTERNAL_IMAGE ) {
$permalink = $this->get_permalink( $url, $home_url );
$target = $this->indexable_repository->find_by_permalink( $permalink );
if ( ! $target ) {
// If target indexable cannot be found, create one based on the post's post ID.
$post_id = $this->get_post_id( $model->type, $permalink );
if ( $post_id && $post_id !== 0 ) {
$target = $this->indexable_repository->find_by_id_and_type( $post_id, 'post' );
}
}
if ( ! $target ) {
return $model;
}
$model->target_indexable_id = $target->id;
if ( $target->object_type === 'post' ) {
$model->target_post_id = $target->object_id;
}
}
if ( $is_image && $model->target_post_id ) {
list( , $width, $height ) = \wp_get_attachment_image_src( $model->target_post_id, 'full' );
$model->width = $width;
$model->height = $height;
$model->size = \filesize( \get_attached_file( $model->target_post_id ) );
}
if ( $model->target_indexable_id ) {
$model->language = $target->language;
$model->region = $target->region;
}
return $model;
}