0

I am using the WP-File-Upload Plugin: https://wordpress.org/support/plugin/wp-file-upload

This plugin allows you to upload a file on the front end and have it "attach" to the post that the plugin is displayed on. The plug in works just as advertised and the video is indeed attached to the post when viewed in the media library.

I have included the WP Shortcode [video] on my post as well which defaults to the first attached video file if it exists. Prior to the user uploading a video (mp4 in my case), the video doesn't display as there is no attached video. Once I upload the video successfully, I have a small script that refreshes the page to display the now uploaded video. The page refreshes, but the video still does not display. I have to log into the site on the back end and open the post in the editor, the video shows up in the editor and then I have to hit "Update" for it to correctly show on the front end.

I have tried reloading the post numerous times on my own (F5) also forcing the cache to clear (CTRL+F5) and neither of these works. The only way to get the post to display the video is to "Update" it on the back end.

I believe I need to call the wp_update_post() function when the video successfully uploads, but the problem is when I do this, the post DOES NOT save.

This is the code snippet called upon a successful file upload.

if (!function_exists('wfu_after_file_upload_handler')) {
  function wfu_after_file_upload_handler($changable_data, $additional_data) {
    if ( $additional_data['upload_result'] == 'success' ) {  
       $this_post_id = get_the_ID();
       $my_post = array(
        'ID' => $this_post_id
        );
     wp_update_post( $my_post );                          
  }
$changable_data['js_script'] = 'setTimeout(function(){ location.reload(); }, 5000);';
 }
return $changable_data;
}
add_filter('wfu_after_file_upload', 'wfu_after_file_upload_handler', 10, 2);
}
0

I found the reason this was not working was because of a conflict with another plugin that was preventing the page from refreshing properly if the user was not logged in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.