• Resolved SuperCougar

    (@supercougar)


    Hi,

    I tried adding a Custom Field to the media library with the following settings:
    Type: Custom Field
    Field: _wp_attached_file
    Field Type: Image
    Image Size: Thumbnail (150 x 150)

    I want to add this field because the default thumbnails are too small in list mode.

    The problem is that I get empty squares (with no images inside) in the media library.

    If I inspect the missing images, I get something like this:
    <img style="width:150px;height:150px" src="2021/12/image-name.jpg" alt="">

    Since it is a relative link, it links to:
    https://example.com/wp-admin/2021/12/image-name.jpg

    Of course, the link is incorrect, hence the missing image. It should be:
    https://example.com/wp-content/uploads/2021/12/image-name.jpg

    On the other hand, I have added a “Download” field just to test, and the links are OK. They are absolute URLs, not relative ones, like so:
    https://example.com/wp-content/uploads/2021/12/image-name.jpg

    So, there seems to be a bug due to relative URLs referring to “…/wp-admin/…” instead of “…/wp-content/uploads/…”.

    I have tried on several sites with different themes, and I get the same issue.

    I hope you can fix this.

    Thank you in advance for your help.

    • This topic was modified 2 years, 11 months ago by SuperCougar.
    • This topic was modified 2 years, 11 months ago by SuperCougar.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Stefan van den Dungen Gronovius

    (@dungengronovius)

    Thanks for your feedback.
    I understand what you mean, but this is not a bug in our software.
    Our Custom Field column is a one-fits-all solution that can create an image from an ID or absolute URL. This column is not aware of its context so it requires an absolute URL. In your example, the relative path is the uploads folder, but there is no way that our plugin knows that for the chosen custom field. I hope that makes sense since there is no way we can ‘fix’ this in our software.

    For the media library, you can better use the Image column that allows you to create an image for the attached file and even set the desired width.

    Thread Starter SuperCougar

    (@supercougar)

    Hi Stefan,

    Thank you for your reply, but I don’t understand.

    What do you mean by “column”? Do you mean Type?

    If so, I don’t see any “Image” type for Media.

    When I click “Add Column”, I need to choose a “Type”, and there is no “image” option available there.

    The only way I can get an image is by choosing “Custom Field”, then _wp_attached_file and then choose “Image” as “File type”.

    You say that there is no way for your plugin to know the URL for the chosen custom field. So, how does the plugin find the right URL for a “Download” field, which is exactly the same?

    Am I doing something wrong?

    Did you try on your side and add custom thumbnails to the media library? I mean did you try and reproduce my issue?

    If so, a screenshot or better a screencast would be welcome.

    Plugin Author Stefan van den Dungen Gronovius

    (@dungengronovius)

    Yes, I did indeed mean the column type field when adding a new column. But that said, I checked again and it seems that the Image column for Media is a Pro-only column. I believe this can perfectly be a free column though, so I moved it to the free version for the upcoming release. If you want the column right away, you can create a file Image.php in the folder: codepress-admin-columns/classes/Column/Media

    And put the following contents in that file:
    https://gist.github.com/DGStefan/94349635ff304ebaa9d33c57130ce1a4

    About the other questions. Yes, it is correct that the custom field column does not know where to look for relative paths. The download column is a custom and specifically written column by us to get the download link based on the ID and/or custom field. The Custom Field column is a one fits all solution for custom fields and does not know the context where it is called. That’s the main difference in writing a one-fits-all solution and a more specific approach of writing specific columns doing specific things ??

    Thread Starter SuperCougar

    (@supercougar)

    Hi Stefan,

    I have followed your instructions carefully, but the “Image” column doesn’t show up in the list (I have tried locally and online).
    I have deactivated and reactivated the plugin, but it didn’t help.

    Plugin Author Stefan van den Dungen Gronovius

    (@dungengronovius)

    Hmm strange, I don’t understand what placing the file with the contents of the snippet does not work. Don’t you have any feedback or errors on your website? In that case, I recommend waiting for the next release with the new column included in it. I can’t give a timeframe for the release though.

    Thread Starter SuperCougar

    (@supercougar)

    Hi Stefan,

    Maybe there is a slight glitch somewhere. Anyway, thank you for considering my message and integrating the image field in the next update. I can well wait until that update. I’ll let you know if it is OK. ??

    Do I need to remove the Image.php file?

    ==

    Meanwhile, I would like to go back to the custom field mentioned in my previous message. You may think that I insist a lot, but no, I just want to understand because I am a Cartesian person.

    I understand what you mean when you say that it does not know the context where it is called. What I can’t figure out is how to make it understand the context.
    You say that it requires an ID or absolute URL, but where can they be specified?
    Is it a pro-only feature?

    Otherwise, I don’t see the use of it if there is no way to make it work.

    Plugin Author Stefan van den Dungen Gronovius

    (@dungengronovius)

    You can remove the Image.php file, but it will also be back again next time you update the plugin, so not necessary required to do so.

    ==

    The custom field column will not work for your use case, since the value for the key you select is not compatible with our image logic. There is also no way to make it understand the context since this is such a global one-fits-all solution column.

    The only workaround is to alter the value of the Custom Field column with the following hook:
    https://github.com/codepress/admin-columns-hooks/blob/master/ac-export-value.php

    You probably want to set the field type setting to ‘Default’ and then take the value and wrap it in an image tag and set the width/height yourself. But that basically wring a custom column, which is exactly what we do to make some specific fields available in our plugin.

    My advice is to wait for the next update ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Custom Field (Image – _wp_attached_file): Images not showing up’ is closed to new replies.