Image lock error – "Cannot find attachment ID"

Hi everyone,

I am having an issue with locking photos. In my post editor, when I select a photo and bring up the on-screen menu to lock it, before I even insert a value or attempt to update, it has the following text: “Can not find attachment id. Cannot lock.”

Screen Shot 2020-05-23 at 1.11.57 AM

When I do insert an amount and hit update, the message changes to “Pledge level for the image was updated! The value you posted may be same with the value already set!” even though I changed the value from (blank) to 5.

I have turned the feature on and saved my permalinks a time or two to ensure that’s not the reason.

I have re-uploaded the file to my Gallery to ensure it’s not an error with the version I have uploaded or anything.

I have also gone directly to the image in my Gallery. There I choose the tier I want to be able to see it from the drop down menu and hit update and after a moment of loading, it resets the tier to “Everyone.”

What am I doing wrong?

Is there any plugin at your site that modifies image library or the way it works? That notification should appear when the plugin is not able to determine an image’s attachment id from WP library. Do you use a CDN or something similar?

I don’t have any plugins that would affect my WP library… in fact I have very few plugins at all. Would an image’s extention or size matter? Its position in a post (i.e. what page?). I’m trying any combination of variables I can imagine as to why some save and remain locked while others don’t.

Then some remain locked? Can you check the images in media library and see if there is any difference in between those which remain locked and which dont?

This is a massive problem, it happens to me as well. All my plans are ruined now because I can’t lock images on my new blog.

I do not use any CDN besides CF (which has and should have nothing to do with the plugin), and all I am using is LSCACHE because it’s my own hosting and I have LS Enterprise.

Trying to debug there is not much I can see unless I dive deep into the plugin…

In my case it might be caused by the Image Optimization from LSCACHE and due to the fact that I have the replace images with WebP enabled. (not sure, haven’t seen your code yet)

But if I check the code in the posts:

<!-- wp:image {"id":25,"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="IMAGE_URL" alt="" class="wp-image-25"/></figure>
<!-- /wp:image -->

It looks good to me.

I’ve tracked down the issue, it’s coming from:

/wp-content/plugins/patreon-connect/classes/patreon_protect.php:

$attachment_id = attachment_url_to_postid( $attachment_url );
// attachment_url_to_postid returns 0 if it cant find the attachment post id
    		
if ( $attachment_id == 0 ) {
    			
    	// Couldnt determine attachment post id. Try to get id from thumbnail
    	$attachment_id = Patreon_Protect::getAttachmentIDfromThumbnailURL( $attachment_url );
    			
    	if( $attachment_id == 0 ) {
    		$message = 'Can not find attachment id.  Cannot lock.';
    	}
}

attachment_url_to_postid should not ever fail since it’s from WordPress, but your own function fails as well Patreon_Protect::getAttachmentIDfromThumbnailURL( $attachment_url ).

I`m still tracking down why this is happening.

UPDATE:

I found the cause, attachment_url_to_postid fails when the url passed is NOT the exact filename.

For example, in my case it’s sending:

pw_image_source:

https://MY_BLOG/wp-content/uploads/2020/05/Thinking-of-getting-a-cat-1024x512.png

When testing the function it was always returning 0:

echo 'TEST: ' . attachment_url_to_postid( 'https://MY_BLOG/wp-content/uploads/2020/05/Thinking-of-getting-a-cat-1024x512.png' );
die();

However when I removed the “size” from the filename:

echo 'TEST: ' . attachment_url_to_postid( 'https://MY_BLOG/wp-content/uploads/2020/05/Thinking-of-getting-a-cat.png' );
die();

I has correctly returned to me the attachement id. Now all that’s left is to figure out what to do I guess :slight_smile:

UPDATE 2:

Using the above “temporary” solution, if you set the image size to Full Size in Gutenberg the lock image does not return anymore errors.

However… the image is not actually “locked”. Checkout the generated HTML:

<img data-lazyloaded="1" src="https://MY_BLOG/wp-content/uploads/2020/05/Thinking-of-getting-a-cat-1024x512.png.webp" 
data-src="https://MY_BLOG/wp-content/uploads/2020/05/Thinking-of-getting-a-cat-1024x512.png.webp" 
alt="" 
data-patreon-flow-url="aHR0cHM6Ly9tZWNhbmlrLmRldi9wYXRyZW9uLWZsb3cvP3BhdHJlb24tdW5sb2NrLXBvc3Q9MTg3JnBhdHJlb24tdW5sb2NrLWltYWdlPTE5Mg==" 
class="patreon-locked-image wp-image-192 litespeed-loaded" 
data-srcset="https://MY_BLOG/wp-content/uploads/2020/05/Thinking-of-getting-a-cat-1024x512.png.webp 1024w, https://MY_BLOG/wp-content/uploads/2020/05/Thinking-of-getting-a-cat-300x150.png.webp 300w, https://MY_BLOG/wp-content/uploads/2020/05/Thinking-of-getting-a-cat-768x384.png.webp 768w, https://MY_BLOG/wp-content/uploads/2020/05/Thinking-of-getting-a-cat.png.webp 1200w" 
data-sizes="(max-width: 1024px) 100vw, 1024px" 
sizes="(max-width: 1024px) 100vw, 1024px" 
srcset="https://MY_BLOG/wp-content/uploads/2020/05/Thinking-of-getting-a-cat-1024x512.png.webp 1024w, https://MY_BLOG/wp-content/uploads/2020/05/Thinking-of-getting-a-cat-300x150.png.webp 300w, https://MY_BLOG/wp-content/uploads/2020/05/Thinking-of-getting-a-cat-768x384.png.webp 768w, https://MY_BLOG/wp-content/uploads/2020/05/Thinking-of-getting-a-cat.png.webp 1200w" 
data-was-processed="true">

Notice that the Patreon stuff is there though. The image is visible and we can see again the annoying “size” in the filename.

At this point I don’t know whether it’s the function I mentioned from WP, or the fact that I`m using LSCACHE and it serves .webp.

Please advice, I leave it in your hands from here.

What happens if you disable LSCACHE and image replacement?

You don’t need to disable the plugin totally, I’ve tested with just disabling Webp replacement and it does work. However it looks very ugly, and non clickable at all: https://prnt.sc/sowdzo (is this how it’s supposed to show?)

So the end problem is the extension, I guess. I can provide a hosting package if needed to test and fix.

That image placeholder looks ery low resolution. That’s not how it is suppose to look.

Thats more proper.

GDlib or something may not be working correctly in your installation/server.

Clicking only works when the image is inside a post or page, because JS code to make the image clickable is necessary. When viewed directly making it clickable is not practical.

Indeed that looks much better. However I`m not sure what I could be missing, my hosting is running for more than 5 years now, with hundreds of forums etc. With that being said, imagick, etc is present.

Perhaps add some logs for this or a debug mode ?

Regarding the clicking, the image is inside a post and you can click it but the “hand” icon is not showing at all on the button. Basically the user cannot know it’s clickable.

What can be done with all the above ? The most important one is locking…

Do you want a hosting package to debug and fix all this ?

Regarding the clicking, the image is inside a post and you can click it but the “hand” icon is not showing at all on the button. Basically the user cannot know it’s clickable.

This indicates to one or more functions that are used by image feature failing. GD lib must be installed for PHP for this to work. You may check this with your web host.

I`m a bit dissapointed…

This indicates to one or more functions that are used by image feature failing. GD lib must be installed for PHP for this to work. You may check this with your web host.

Are you reading anything that I am saying ? This is my web host…

Last question, are you going to fix the lock feature or not ? So I know what to do, because this seems like a waste of time and effort.

This indicates to one or more functions that are used by image feature failing. GD lib must be installed for PHP for this to work. You may check this with your web host.

For the sake of sanity, I’ve just checked and both GD and Imagick are there. I`m using PHP 7.4.

So to list the problems, in my case anyway:

  • Image locking does not work when using LSCACHE and replacing images with their Webp versions (nobody will let go of speed for this)
  • Image locking looks horrible when using LSCACHE image optimization (it looses quality)

When can we expect a fix ?

Replacement of the image by 3rd party optimizers or CDNs is something which cannot be handled without extensive custom coding.

For the quality issue - not only there is no other user reporting this quality issue, but also this issue is not reproducible in a standard test installation using a standard cPanel hosting account. There is no quality loss in the generated placeholder image - as you see in the one which was referenced before.

Since this issue is specific to your installation, this must be investigated by you or your developer. If you wish, i can provide you a disposable cPanel account to experiment and test this issue and compare it to your web hosting setup.

So, OP here… just wondering – is there anything I can do?

I certainly don’t know any custom coding. I’m just trying to lock a few select images on a blog. I have very few plug-ins; no customizations; I haven’t altered or added any coding. I’m like, create-a-website 101, hosting a WP blog on Bluehost. I can’t figure out why some images lock and some don’t. I have tried different file extensions, re-saving, etc. It just appears to work haphazardly.

How do I get support with this?

This may be due to many factors, ranging from your host’s setup affecting something or one of your plugins interfering with things on occasion.

I can provide you with a disposable reference hosting account with WP installed so you can check if your images will work without issues there. You can install PW there, connect it to your Patreon, enable image locking, upload the same images that you have issues with the other installation to this disposable one. If the images work without issues in the test account or the opposite, then that may provide a clue.

If you want to give it a try, let me know so ill arrange an account and send via DM.