WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Получай пассивный доход от сайта
функция не описана

Yoast\WP\SEO\Helpers

Image_Helper::get_attachment_by_url() public Yoast 1.0

Find an attachment ID for a given URL.

{} Это метод класса: Image_Helper{}

Хуков нет.

Возвращает

int. The found attachment ID, or 0 if none was found.

Использование

$Image_Helper = new Image_Helper();
$Image_Helper->get_attachment_by_url( $url );
$url(строка) (обязательный)
The URL to find the attachment for.

Код Image_Helper::get_attachment_by_url() Yoast 16.8

<?php
public function get_attachment_by_url( $url ) {
	// Strip out the size part of an image URL.
	$url = \preg_replace( '/(.*)-\d+x\d+\.(jpeg|jpg|png|gif)$/', '$1.$2', $url );

	// Don't try to do this for external URLs.
	if ( \strpos( $url, \get_site_url() ) !== 0 ) {
		return 0;
	}

	$indexable = $this->indexable_repository->find_by_permalink( $url );

	if ( $indexable && $indexable->object_type === 'post' && $indexable->object_sub_type === 'attachment' ) {
		return $indexable->object_id;
	}

	$post_id = WPSEO_Image_Utils::get_attachment_by_url( $url );

	if ( $post_id !== 0 ) {
		// Find the indexable, this triggers creating it so it can be found next time.
		$this->indexable_repository->find_by_id_and_type( $post_id, 'post' );
	}

	return $post_id;
}