Skip to content

Commit 5f5def1

Browse files
author
Marco Pereirinha
committed
Fix the cache logic to get attachment ID from URl
1 parent eb5e749 commit 5f5def1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

php/class-utils.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -923,14 +923,17 @@ public static function get_registered_sizes( $attachment_id = null ) {
923923
* @return int
924924
*/
925925
public static function attachment_url_to_postid( $url ) {
926-
$attachment_id = 0;
926+
$key = "postid_{$url}";
927+
927928
if ( function_exists( 'wpcom_vip_attachment_url_to_postid' ) ) {
928929
$attachment_id = wpcom_vip_attachment_url_to_postid( $url );
930+
} else {
931+
$attachment_id = wp_cache_get( $key, 'cloudinary' );
929932
}
930933

931-
if ( 0 === $attachment_id && empty( wp_cache_get( "postid_{$url}", 'cloudinary' ) ) ) {
934+
if ( empty( $attachment_id ) ) {
932935
$attachment_id = attachment_url_to_postid( $url ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.attachment_url_to_postid_attachment_url_to_postid
933-
wp_cache_set( "postid_{$url}", $attachment_id, 'cloudinary' );
936+
wp_cache_set( $key, $attachment_id, 'cloudinary' );
934937
}
935938

936939
return $attachment_id;

0 commit comments

Comments
 (0)