<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[46174] trunk/src: Uploads: add helper functions for setting, getting, and deleting the temp upload reference used to the attachment_id when retrying to make image sub-sizes.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/46174">46174</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/46174","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>azaozz</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2019-09-19 01:25:14 +0000 (Thu, 19 Sep 2019)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Uploads: add helper functions for setting, getting, and deleting the temp upload reference used to the attachment_id when retrying to make image sub-sizes.

See <a href="https://core.trac.wordpress.org/ticket/47872">#47872</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcjs_enqueuesvendorpluploadhandlersjs">trunk/src/js/_enqueues/vendor/plupload/handlers.js</a></li>
<li><a href="#trunksrcjs_enqueuesvendorpluploadwppluploadjs">trunk/src/js/_enqueues/vendor/plupload/wp-plupload.js</a></li>
<li><a href="#trunksrcwpadminincludesajaxactionsphp">trunk/src/wp-admin/includes/ajax-actions.php</a></li>
<li><a href="#trunksrcwpadminincludesfilephp">trunk/src/wp-admin/includes/file.php</a></li>
<li><a href="#trunksrcwpadminincludesmediaphp">trunk/src/wp-admin/includes/media.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcjs_enqueuesvendorpluploadhandlersjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/js/_enqueues/vendor/plupload/handlers.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/js/_enqueues/vendor/plupload/handlers.js        2019-09-19 00:59:59 UTC (rev 46173)
+++ trunk/src/js/_enqueues/vendor/plupload/handlers.js  2019-09-19 01:25:14 UTC (rev 46174)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -450,7 +450,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                data: {
</span><span class="cx" style="display: block; padding: 0 10px">                                        action: 'media-create-image-subsizes',
</span><span class="cx" style="display: block; padding: 0 10px">                                        _wpnonce: _wpPluploadSettings.defaults.multipart_params._wpnonce,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        _wp_temp_image_ref: file.id,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 _wp_temp_upload_ref: file.id,
</ins><span class="cx" style="display: block; padding: 0 10px">                                         _wp_upload_failed_cleanup: true,
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px">                        });
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -478,7 +478,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        data: {
</span><span class="cx" style="display: block; padding: 0 10px">                                action: 'media-create-image-subsizes',
</span><span class="cx" style="display: block; padding: 0 10px">                                _wpnonce: wpUploaderInit.multipart_params._wpnonce,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                _wp_temp_image_ref: file.id,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         _wp_temp_upload_ref: file.id,
</ins><span class="cx" style="display: block; padding: 0 10px">                                 _legasy_support: 'true',
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px">                }).done( function( response ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -599,9 +599,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><span class="cx" style="display: block; padding: 0 10px">                uploader.bind( 'BeforeUpload', function( up, file ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( file.type && file.type.indexOf( 'image/' ) === 0 ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                up.settings.multipart_params._wp_temp_image_ref = file.id;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         up.settings.multipart_params._wp_temp_upload_ref = file.id;
</ins><span class="cx" style="display: block; padding: 0 10px">                         } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                up.settings.multipart_params._wp_temp_image_ref = '';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         up.settings.multipart_params._wp_temp_upload_ref = '';
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px">                } );
</span><span class="cx" style="display: block; padding: 0 10px">        };
</span></span></pre></div>
<a id="trunksrcjs_enqueuesvendorpluploadwppluploadjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/js/_enqueues/vendor/plupload/wp-plupload.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/js/_enqueues/vendor/plupload/wp-plupload.js     2019-09-19 00:59:59 UTC (rev 46173)
+++ trunk/src/js/_enqueues/vendor/plupload/wp-plupload.js       2019-09-19 01:25:14 UTC (rev 46174)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -138,7 +138,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        data: {
</span><span class="cx" style="display: block; padding: 0 10px">                                                action: 'media-create-image-subsizes',
</span><span class="cx" style="display: block; padding: 0 10px">                                                _wpnonce: _wpPluploadSettings.defaults.multipart_params._wpnonce,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                _wp_temp_image_ref: file.id,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         _wp_temp_upload_ref: file.id,
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 _wp_upload_failed_cleanup: true,
</span><span class="cx" style="display: block; padding: 0 10px">                                        }
</span><span class="cx" style="display: block; padding: 0 10px">                                });
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -161,7 +161,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                data: {
</span><span class="cx" style="display: block; padding: 0 10px">                                        action: 'media-create-image-subsizes',
</span><span class="cx" style="display: block; padding: 0 10px">                                        _wpnonce: _wpPluploadSettings.defaults.multipart_params._wpnonce,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        _wp_temp_image_ref: file.id, // Used to find the new attachment_id.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 _wp_temp_upload_ref: file.id, // Used to find the new attachment_id.
</ins><span class="cx" style="display: block; padding: 0 10px">                                 }
</span><span class="cx" style="display: block; padding: 0 10px">                        }).done( function( response ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                if ( response.success ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -324,9 +324,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><span class="cx" style="display: block; padding: 0 10px">                this.uploader.bind( 'BeforeUpload', function( up, file ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( file.type && file.type.indexOf( 'image/' ) === 0 ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                up.settings.multipart_params._wp_temp_image_ref = file.id;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         up.settings.multipart_params._wp_temp_upload_ref = file.id;
</ins><span class="cx" style="display: block; padding: 0 10px">                         } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                up.settings.multipart_params._wp_temp_image_ref = '';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         up.settings.multipart_params._wp_temp_upload_ref = '';
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px">                } );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunksrcwpadminincludesajaxactionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/ajax-actions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/ajax-actions.php      2019-09-19 00:59:59 UTC (rev 46173)
+++ trunk/src/wp-admin/includes/ajax-actions.php        2019-09-19 01:25:14 UTC (rev 46174)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2422,21 +2422,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">                wp_send_json_error( array( 'message' => __( 'Sorry, you are not allowed to upload files.' ) ) );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // Using Plupload `file.id` as ref.
-       if ( ! empty( $_POST['_wp_temp_image_ref'] ) ) {
-               $image_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $_POST['_wp_temp_image_ref'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $_POST['_wp_temp_upload_ref'] ) ) {
+               // Uploading of images usually fails while creating the sub-sizes, either because of a timeout or out of memory.
+               // At this point the file has been uploaded and an attachment post created, but because of the PHP fatal error
+               // the cliend doesn't know the attachment ID yet.
+               // To be able to find the new attachment_id in these cases we temporarily store an upload reference sent by the client
+               // in the original upload request. It is used to save a transient with the attachment_id as value.
+               // That reference currently is Plupload's `file.id` but can be any sufficiently random alpha-numeric string.
+               $attachment_id = _wp_get_upload_ref_attachment_id( $_POST['_wp_temp_upload_ref'] );
</ins><span class="cx" style="display: block; padding: 0 10px">         } else {
</span><span class="cx" style="display: block; padding: 0 10px">                wp_send_json_error( array( 'message' => __( 'Invalid file reference.' ) ) );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // Uploading of images usually fails while creating the sub-sizes, either because of a timeout or out of memory.
-       // At this point the file has been uploaded and an attachment post created, but because of the PHP fatal error
-       // the cliend doesn't know the attachment ID yet.
-       // To be able to find the new attachment_id in these cases we temporarily store an upload reference sent by the client
-       // in the original upload request. It is used to save a transient with the attachment_id as value.
-       // That reference currently is Plupload's `file.id` but can be any sufficiently random alpha-numeric string.
-       $attachment_id = get_transient( '_wp_temp_image_ref:' . $image_ref );
-
</del><span class="cx" style="display: block; padding: 0 10px">         if ( empty( $attachment_id ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                wp_send_json_error( array( 'message' => __( 'Upload failed. Please reload and try again.' ) ) );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2481,7 +2478,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        // At this point the image has been uploaded successfully.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        delete_transient( '_wp_temp_image_ref:' . $image_ref );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ _wp_clear_upload_ref( $_POST['_wp_temp_upload_ref'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        wp_send_json_success( $response );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpadminincludesfilephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/file.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/file.php      2019-09-19 00:59:59 UTC (rev 46173)
+++ trunk/src/wp-admin/includes/file.php        2019-09-19 01:25:14 UTC (rev 46174)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -978,8 +978,65 @@
</span><span class="cx" style="display: block; padding: 0 10px">        return _wp_handle_upload( $file, $overrides, $time, $action );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/**
+ * Temporarily stores the client upload reference in a transient.
+ *
+ * @since 5.3.0
+ * @access private
+ *
+ * @param string $upload_ref    The upload reference sent by the client.
+ * @param int    $attachment_id Attachment post ID.
+ * @return bool Whether the transient was set.
+ */
+function _wp_set_upload_ref( $upload_ref, $attachment_id ) {
+       $upload_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $upload_ref );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        if ( ! empty( $upload_ref ) ) {
+               return set_transient( '_wp_temp_image_ref:' . $upload_ref, $attachment_id, HOUR_IN_SECONDS );
+       }
+
+       return false;
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Get attachment post ID from an upload reference.
+ *
+ * @since 5.3.0
+ * @access private
+ *
+ * @param string $upload_ref    The upload reference sent by the client.
+ * @return int The attachemtn post ID. Zero if the upload reference has expired or doesn't exist.
+ */
+function _wp_get_upload_ref_attachment_id( $upload_ref ) {
+       $upload_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $upload_ref );
+
+       if ( ! empty( $upload_ref ) ) {
+               return (int) get_transient( '_wp_temp_image_ref:' . $upload_ref );
+       }
+
+       return 0;
+}
+
+/**
+ * Remove the transient that stores a temporary upload reference.
+ *
+ * @since 5.3.0
+ * @access private
+ *
+ * @param string $upload_ref    The upload reference sent by the client.
+ * @return bool Whether the transient was removed.
+ */
+function _wp_clear_upload_ref( $upload_ref ) {
+       $upload_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $upload_ref );
+
+       if ( ! empty( $upload_ref ) ) {
+               return delete_transient( '_wp_temp_image_ref:' . $upload_ref );
+       }
+
+       return false;
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px">  * Downloads a URL to a local temporary file using the WordPress HTTP API.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * Please note that the calling function must unlink() the file.
</span></span></pre></div>
<a id="trunksrcwpadminincludesmediaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/media.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/media.php     2019-09-19 00:59:59 UTC (rev 46173)
+++ trunk/src/wp-admin/includes/media.php       2019-09-19 01:25:14 UTC (rev 46174)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -308,13 +308,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">        $ext  = pathinfo( $name, PATHINFO_EXTENSION );
</span><span class="cx" style="display: block; padding: 0 10px">        $name = wp_basename( $name, ".$ext" );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        $url       = $file['url'];
-       $type      = $file['type'];
-       $file      = $file['file'];
-       $title     = sanitize_text_field( $name );
-       $content   = '';
-       $excerpt   = '';
-       $image_ref = false;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $url     = $file['url'];
+       $type    = $file['type'];
+       $file    = $file['file'];
+       $title   = sanitize_text_field( $name );
+       $content = '';
+       $excerpt = '';
+       $_ref    = false;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        if ( preg_match( '#^audio#', $type ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                $meta = wp_read_audio_metadata( $file );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -376,11 +376,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Use image exif/iptc data for title and caption defaults if possible.
</span><span class="cx" style="display: block; padding: 0 10px">        } elseif ( 0 === strpos( $type, 'image/' ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Image file reference passed by the uploader.
-               if ( ! empty( $_POST['_wp_temp_image_ref'] ) ) {
-                       $image_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $_POST['_wp_temp_image_ref'] );
-               }
-
</del><span class="cx" style="display: block; padding: 0 10px">                 $image_meta = wp_read_image_metadata( $file );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $image_meta ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -415,8 +410,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        if ( ! is_wp_error( $attachment_id ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                // If an image, keep the upload reference until all image sub-sizes are created.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( $image_ref ) {
-                       set_transient( '_wp_temp_image_ref:' . $image_ref, $attachment_id, HOUR_IN_SECONDS );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( ! empty( $_POST['_wp_temp_upload_ref'] ) && wp_attachment_is_image( $attachment_id ) ) {
+                       $_ref = _wp_set_upload_ref( $_POST['_wp_temp_upload_ref'], $attachment_id );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // The image sub-sizes are created during wp_generate_attachment_metadata().
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -425,8 +420,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // At this point the image is uploaded successfully even if there were specific errors or some sub-sizes were not created.
</span><span class="cx" style="display: block; padding: 0 10px">                // The transient is not needed any more.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( $image_ref ) {
-                       delete_transient( '_wp_temp_image_ref:' . $image_ref );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( $_ref ) {
+                       _wp_clear_upload_ref( $_POST['_wp_temp_upload_ref'] );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre>
</div>
</div>

</body>
</html>