Yoast\WP\SEO\Builders
Indexable_Link_Builder::create_internal_link()
Creates an internal link.
Метод класса: Indexable_Link_Builder{}
Хуки из метода
Возвращает
SEO_Links
. The created link.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->create_internal_link( $url, $home_url, $indexable, $is_image, $image_id );
- $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 - $image_id(int)
- The ID of the internal image.
Код Indexable_Link_Builder::create_internal_link() Indexable Link Builder::create internal link Yoast 22.4
protected function create_internal_link( $url, $home_url, $indexable, $is_image = false, $image_id = 0 ) { $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 ) { $permalink = $this->build_permalink( $url, $home_url ); return $this->enhance_link_from_indexable( $model, $permalink ); } if ( $model->type === SEO_Links::TYPE_INTERNAL_IMAGE ) { $permalink = $this->build_permalink( $url, $home_url ); /** The `wpseo_force_creating_and_using_attachment_indexables` filter is documented in indexable-link-builder.php */ if ( ! $this->options_helper->get( 'disable-attachment' ) || \apply_filters( 'wpseo_force_creating_and_using_attachment_indexables', false ) ) { $model = $this->enhance_link_from_indexable( $model, $permalink ); } else { $target_post_id = ( $image_id !== 0 ) ? $image_id : WPSEO_Image_Utils::get_attachment_by_url( $permalink ); if ( ! empty( $target_post_id ) ) { $model->target_post_id = $target_post_id; } } if ( $model->target_post_id ) { $file = \get_attached_file( $model->target_post_id ); if ( $file ) { if ( \file_exists( $file ) ) { $model->size = \filesize( $file ); } else { $model->size = null; } [ , $width, $height ] = \wp_get_attachment_image_src( $model->target_post_id, 'full' ); $model->width = $width; $model->height = $height; } else { $model->width = 0; $model->height = 0; $model->size = 0; } } } return $model; }