Yoast\WP\SEO\Helpers
Url_Helper::get_link_type() public Yoast 1.0
Returns the link type.
{} Это метод класса: Url_Helper{}
Хуков нет.
Возвращает
Строку. The link type.
Использование
$Url_Helper = new Url_Helper(); $Url_Helper->get_link_type( $url, $home_url, $is_image );
- $url(массив) (обязательный)
- The URL, as parsed by wp_parse_url.
- $home_url(массив)
- The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url.
По умолчанию: null - $is_image(true/false)
- Whether or not the link is an image.
По умолчанию: false
Код Url_Helper::get_link_type() Url Helper::get link type Yoast 15.6.2
public function get_link_type( $url, $home_url = null, $is_image = false ) {
// If there is no scheme the link is always internal.
if ( empty( $url['scheme'] ) ) {
return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL;
}
// If there is a scheme but it's not https? then the link is always external.
if ( ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) {
return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL;
}
if ( \is_null( $home_url ) ) {
$home_url = \wp_parse_url( \home_url() );
}
// When the base host is equal to the host.
if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) {
return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL;
}
// There is no base path and thus all URLs of the same domain are internal.
if ( empty( $home_url['path'] ) ) {
return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL;
}
// When there is a path and it matches the start of the url.
if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) {
return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL;
}
return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL;
}