Automattic / WP-Job-Manager

Manage job listings from the WordPress admin panel, and allow users to post jobs directly to your site.
https://wpjobmanager.com
GNU General Public License v3.0
895 stars 366 forks source link

Featured Images disappear when you edit a listing if you use a CDN that hosts external images #2056

Open dave3322 opened 3 years ago

dave3322 commented 3 years ago

If you are using a CDN to host external images, the featured image or images originally added to the listing disappears.

The issue is when you want to edit the submission. If you click 'save' all seems fine, when you go to the front end and refresh the featured image disappears. I have tried with with two different CDN plugins

I think this issue is slightly different from wpjm rejecting external images on submission. This is wpjm rejecting external images on edit without displaying an error.

To replicate,

  1. Download any CDN external image plug that changes the URL of your images so they are sourced from the CDN URL. I used 'WP Offload Media Lite' and also used 'Leopard - Wordpress offload media.

  2. Turn all unecessary plugins off only the plugins that work with wpjobmanager'

  3. Ensure you are running the latest version of wordpress 5.5.1

  4. Create a listing with a featured image and submit

  5. Go to front end and check. Featured image is there and if you inspect the URL of the image, it points to the CDN URL.

  6. Now go back and click edit the listing, and just save, you don't necessarily have to make any changes, but click save again.

  7. Now go back to the listing. Featured image disappears.

WordPress Environment

jom commented 3 years ago

Hi Dave! This is closely related to #576 (which is Jetpack's CDN). Keeping it open for now just to make sure our solution for that issue also fixes this issue.

dave3322 commented 3 years ago

Ok Thanbks - that issue [#576] has been open since 2016 though?

dave3322 commented 3 years ago

Considering there are about 4 different issues raised around this topic that have been open for up to 4 years my question / challenge to automattic developers is as follows.

  1. What have automattic done to extensively test the cdn externa image hosting compatibility of this plugin?
  2. What mainstream cdn plugins have you tested this with?
  3. In addition to asking people to explain the problem, isnt it best for someone at automattic to review the cdn external image hosting compatibility as a specific exercise and do some thorough testing?

Sorry to be direct, just wondering, as when i read the different issues raised, the contributors are always challenging the issue owner to explain the issue. which i understand. but considering the issue raised is around the same topic and has been raised a few times and is close to 4 years old, i would have thought one of the developers would look into this a bit as well as continue to challenge issue openers to explain the issue.

just my thoughts

Dave

dave3322 commented 3 years ago

Still no solution?

tripflex commented 3 years ago

You can see my response in #1523

https://github.com/Automattic/WP-Job-Manager/issues/1523#issuecomment-693419838

dave3322 commented 3 years ago

@tripflex

Thanks for looking at this much appreciated. I am not a developer so I wont try and talk like one. but i do understand the basics when it comes to writing code and building a website and how things interlink. I believe the summary of what you are saying is that all the offload plugins have to do the work not wordpress or wpjm. I spoke to the plugin developers and they all said this is an issue with wpjm not their plugin. Especially around just the featured image.

Now lets us take two scenarios for showing images 1) an image gallery 2) the featured image

the image gallery works well with these cdn plugins (i.e insert a new gallery on the same page where the featured image disappears on edit). try and create a gallery with any cdn plugin. when you create the images they show on the front end, when you edit the gallery the images still show on the front end. and all urls are pointing to the cdn. This is with wpjm, wordpress and the existing infrastructure. This is their argument that the issue is not with all images on wpjm but the issue is exclusively on the featured image disappearing on edit.

featured image This does not work with the cdn and image disappears on edit.

suggested solution Can you look at the way the codeing, meta and all the developer type stuff you talked about and try and mirror the same codeding architecture that exits for the gallery images and do the same for the featured image?

Summary: if the gallery images work well with cdn, and the featured image dosent, then i can only conclude that this is an issue on the core codeing architecture and should not be fixed at plugin level.

Please let me know your thoughts

dave3322 commented 3 years ago

FYI 22 September 2020 - This is still an issue (WPJM featured image disappears on edit with using a cdn to host external images)

renatho commented 3 years ago

Hey @dave3322!

Since you're using it only for featured images, I think I have a solution for you. Could you try adding this snippet to your site, and confirm if it works properly?

I tested in a fresh env, using a similar setup to yours and it worked for me.

renatho commented 3 years ago

Sorry, I forgot the snippet:

add_filter( 'submit_job_form_fields_get_job_data',
    function( $fields, $job ) {
        if ( has_post_thumbnail( $job->ID ) ) {
            $fields['company']['company_logo']['value'] = get_post_thumbnail_id( $job->ID );
        }

        return $fields;
    },
    10,
    2
);
wgicio commented 10 months ago

I came into this problem yesterday. Solution was to modify the output html buffer with str_replace to rewrite the CDN urls on the job listings form page back to the original urls so the hidden inputs for the existing media are not modified when the form is resubmitted