@@ -55,6 +55,20 @@ public function check_cloudinary_version( $cloudinary_id, $attachment_id ) {
5555 */
5656 if ( ! empty ( $ meta ['cloudinary ' ] ) && empty ( $ public_id ) ) {
5757 $ cloudinary_id = $ this ->convert_cloudinary_version ( $ attachment_id );
58+ } elseif ( ! empty ( $ meta ['cloudinary ' ] ) ) {
59+ // Has public ID, but still has cloudinary, check pending status.
60+ $ is_pending = $ this ->media ->get_post_meta ( $ attachment_id , Sync::META_KEYS ['pending ' ], true );
61+ $ attempts = (int ) $ this ->media ->get_post_meta ( $ attachment_id , Sync::META_KEYS ['attempts ' ], true );
62+ if ( ( empty ( $ is_pending ) || $ is_pending < time () - 5 * 60 ) && 10 > $ attempts ) {
63+ // Timeout.
64+ $ this ->media ->update_post_meta ( $ attachment_id , Sync::META_KEYS ['attempts ' ], $ attempts + 1 );
65+
66+ // return proposed ID to allow front render.
67+ return $ this ->convert_cloudinary_version ( $ attachment_id );
68+ }
69+ $ cloudinary_id = $ public_id ;
70+ } else {
71+ $ cloudinary_id = $ public_id ;
5872 }
5973 }
6074
@@ -105,6 +119,8 @@ function ( $val ) use ( $media ) {
105119 $ public_id = strstr ( $ public_id , '. ' . $ path ['extension ' ], true );
106120 // Save public ID.
107121 $ this ->media ->update_post_meta ( $ attachment_id , Sync::META_KEYS ['public_id ' ], $ public_id );
122+ // Set download started data.
123+ $ this ->media ->update_post_meta ( $ attachment_id , Sync::META_KEYS ['pending ' ], time () );
108124
109125 // Setup a call for a background sync.
110126 $ params = array (
@@ -125,7 +141,7 @@ public function setup_hooks() {
125141 add_filter ( 'cloudinary_id ' , array ( $ this , 'check_cloudinary_version ' ), 9 , 2 ); // Priority 9, to take preference over prep_on_demand_upload.
126142
127143 // Add a redirection to the new plugin settings, from the old plugin.
128- if ( is_admin () ) {
144+ if ( is_admin () ) {
129145 add_action ( 'admin_menu ' , function () {
130146 global $ plugin_page ;
131147 if ( ! empty ( $ plugin_page ) && false !== strpos ( $ plugin_page , 'cloudinary-image-management-and-manipulation-in-the-cloud-cdn ' ) ) {
0 commit comments