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

WPSEO_Image_Utils::attachment_url_to_postid() protected Yoast 1.0

Implements the attachment_url_to_postid with use of WP Cache.

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

Хуков нет.

Возвращает

Число. The Post ID belonging to the attachment, 0 if not found.

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

$result = WPSEO_Image_Utils::attachment_url_to_postid( $url );
$url(строка) (обязательный)
The attachment URL for which we want to know the Post ID.

Код WPSEO_Image_Utils::attachment_url_to_postid() Yoast 16.2

<?php
protected static function attachment_url_to_postid( $url ) {
	$cache_key = sprintf( 'yoast_attachment_url_post_id_%s', md5( $url ) );

	// Set the ID based on the hashed URL in the cache.
	$id = wp_cache_get( $cache_key );

	if ( $id === 'not_found' ) {
		return 0;
	}

	// ID is found in cache, return.
	if ( $id !== false ) {
		return $id;
	}

	// Note: We use the WP COM version if we can, see above.
	$id = attachment_url_to_postid( $url );

	if ( empty( $id ) ) {
		wp_cache_set( $cache_key, 'not_found', '', ( 12 * HOUR_IN_SECONDS + wp_rand( 0, ( 4 * HOUR_IN_SECONDS ) ) ) );
		return 0;
	}

	// We have the Post ID, but it's not in the cache yet. We do that here and return.
	wp_cache_set( $cache_key, $id, '', ( 24 * HOUR_IN_SECONDS + wp_rand( 0, ( 12 * HOUR_IN_SECONDS ) ) ) );
	return $id;
}