[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/js/ -> media-new-upload.js (summary)

Routes "Add New Media File" uploads through the client-side media pipeline. On wp-admin/media-new.php WordPress uploads via a raw plupload.Uploader (created by plupload-handlers) posting to async-upload.php. When the browser is cross-origin isolated and supports the client-side pipeline, this script intercepts the uploader's FilesAdded handler and hands files to wp.mediaUploadPipeline (media-upload-pipeline.js) instead: the original image is uploaded via the REST API and thumbnails are generated in the browser (wasm-vips), then sideloaded and finalized.

File Size: 339 lines (11 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 7 functions

  finishUpload()
  getParentPostId()
  getItem()
  renderError()
  renderProgress()
  handleFilesAdded()
  bindUploader()

Functions
Functions that are not part of a class:

finishUpload( up )   X-Ref
Marks one pipeline upload as finished, firing uploadComplete() when
nothing is left uploading.

The built-in UploadComplete binding never fires for pipeline uploads
because every file is removed from plupload before its queue starts.
Files plupload is still uploading (a batch's classic share, a HEIC
handed back) end with plupload's own UploadComplete instead.

param: {plupload.Uploader} up The plupload uploader.

getParentPostId()   X-Ref
Returns the post the screen attaches uploads to, or 0.

media-new.php validates `post_id` (the post must exist and be
editable by the user) before printing it into the form, whereas the
raw request value is what plupload carries in its multipart params.
async-upload.php re-validates that raw value and silently uploads
unattached; the REST API rejects it instead, so read the validated one.

return: {number} The parent post ID, or 0.

getItem( file )   X-Ref
Returns the screen's progress item for a plupload file.

param: {plupload.File} file The plupload file.
return: {HTMLElement|null} The item fileQueued() built, if it is still on the page.

renderError( file, message )   X-Ref
Renders a failed upload the way async-upload.php does for a
server-side failure: an error notice with a real Dismiss button
described by the notice, a screen reader announcement, and focus
returned to the browse button once dismissed.

param: {plupload.File} file    The plupload file that failed.
param: {string}        message The reason the upload failed.

renderProgress( file, percent )   X-Ref
Reflects pipeline progress onto the screen's progress bar for a file.

The bar is 200px wide at 100%, matching uploadProgress() in
plupload-handlers.

param: {plupload.File} file    The plupload file being uploaded.
param: {number}        percent Progress percentage.

handleFilesAdded( up, files )   X-Ref
Intercepts files added to the plupload uploader.

Builds the screen's progress items for the files the pipeline takes
(see wp.mediaUploadPipeline.routeBatch()). Returns undefined to leave
the whole batch to plupload's built-in handler.

param: {plupload.Uploader} up    The plupload uploader instance.
param: {plupload.File[]}   files Files added to the queue.
return: {boolean|undefined} False to suppress the built-in handler.

bindUploader( up )   X-Ref
Binds the interceptor to an uploader once it has initialized.

plupload sorts handlers by priority (descending) and a `false` return
breaks the chain, so priority 100 runs before and suppresses the
built-in FilesAdded and UploadComplete handlers.

param: {plupload.Uploader} up The uploader that initialized.



Generated : Tue Oct 20 08:20:34 2026 Cross-referenced by PHPXref