X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/7f1521bf193b382565eb753043c161f4cb3fcda7..refs/tags/wordpress-4.4:/wp-admin/includes/media.php diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index 75811962..9990b9fd 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -36,6 +36,8 @@ function media_upload_tabs() { * * @since 2.5.0 * + * @global wpdb $wpdb WordPress database abstraction object. + * * @param array $tabs * @return array $tabs with gallery if post has image attachment */ @@ -61,12 +63,13 @@ function update_gallery_tab($tabs) { return $tabs; } -add_filter('media_upload_tabs', 'update_gallery_tab'); /** - * {@internal Missing Short Description}} + * Outputs the legacy media upload tabs UI. * * @since 2.5.0 + * + * @global string $redir_tab */ function the_media_upload_tabs() { global $redir_tab; @@ -99,25 +102,30 @@ function the_media_upload_tabs() { } /** - * {@internal Missing Short Description}} + * Retrieves the image HTML to send to the editor. * * @since 2.5.0 * - * @param integer $id image attachment id - * @param string $caption image caption - * @param string $alt image alt attribute - * @param string $title image title attribute - * @param string $align image css alignment property - * @param string $url image src url - * @param string|bool $rel image rel attribute - * @param string $size image size (thumbnail, medium, large, full or added with add_image_size() ) - * @return string the html to insert into editor + * @param int $id Image attachment id. + * @param string $caption Image caption. + * @param string $title Image title attribute. + * @param string $align Image CSS alignment property. + * @param string $url Optional. Image src URL. Default empty. + * @param string $rel Optional. Image rel attribute. Default empty. + * @param string|array $size Optional. Image size. Accepts any valid image size, or an array of width + * and height values in pixels (in that order). Default 'medium'. + * @param string $alt Optional. Image alt attribute. Default empty. + * @return string The HTML output to insert into the editor. */ -function get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel = false, $size='medium', $alt = '') { +function get_image_send_to_editor( $id, $caption, $title, $align, $url = '', $rel = '', $size = 'medium', $alt = '' ) { $html = get_image_tag($id, $alt, '', $align, $size); - $rel = $rel ? ' rel="attachment wp-att-' . esc_attr($id).'"' : ''; + if ( ! $rel ) { + $rel = ' rel="attachment wp-att-' . esc_attr( $id ) . '"'; + } else { + $rel = ' rel="' . esc_attr( $rel ) . '"'; + } if ( $url ) $html = '$html"; @@ -127,14 +135,15 @@ function get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel = * * @since 2.5.0 * - * @param string $html The image HTML markup to send. - * @param int $id The attachment id. - * @param string $caption The image caption. - * @param string $title The image title. - * @param string $align The image alignment. - * @param string $url The image source URL. - * @param string $size The image size. - * @param string $alt The image alternative, or alt, text. + * @param string $html The image HTML markup to send. + * @param int $id The attachment id. + * @param string $caption The image caption. + * @param string $title The image title. + * @param string $align The image alignment. + * @param string $url The image source URL. + * @param string|array $size Size of image. Image size or array of width and height values + * (in that order). Default 'medium'. + * @param string $alt The image alternative, or alt, text. */ $html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt ); @@ -216,7 +225,6 @@ function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $ */ return apply_filters( 'image_add_caption_shortcode', $shcode, $html ); } -add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 ); /** * Private preg_replace callback used in image_add_caption() @@ -240,7 +248,7 @@ function media_send_to_editor($html) { ?> '; $id_attribute = $instance === 1 ? ' id="insert-media-button"' : ''; - printf( '%s', + printf( '', $id_attribute, esc_attr( $editor_id ), - esc_attr__( 'Add Media' ), $img . __( 'Add Media' ) ); /** @@ -569,7 +580,6 @@ function media_buttons($editor_id = 'content') { echo $legacy_filter; } } -add_action( 'media_buttons', 'media_buttons' ); /** * @@ -609,7 +619,7 @@ function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) { } /** - * {@internal Missing Short Description}} + * Handles form submissions for the legacy media uploader. * * @since 2.5.0 * @@ -652,8 +662,8 @@ function media_upload_form_handler() { * * @see wp_get_attachment_metadata() * - * @param WP_Post $post The WP_Post object. - * @param array $attachment An array of attachment metadata. + * @param array $post An array of post data. + * @param array $attachment An array of attachment metadata. */ $post = apply_filters( 'attachment_fields_to_save', $post, $attachment ); @@ -720,7 +730,7 @@ function media_upload_form_handler() { } /** - * {@internal Missing Short Description}} + * Handles the process of uploading media. * * @since 2.5.0 * @@ -801,7 +811,9 @@ function wp_media_upload_handler() { if ( isset( $_POST['save'] ) ) { $errors['upload_notice'] = __('Saved.'); - return media_upload_gallery(); + wp_enqueue_script( 'admin-gallery' ); + return wp_iframe( 'media_upload_gallery_form', $errors ); + } elseif ( ! empty( $_POST ) ) { $return = media_upload_form_handler(); @@ -822,20 +834,26 @@ function wp_media_upload_handler() { } /** - * Download an image from the specified URL and attach it to a post. + * Downloads an image from the specified URL and attaches it to a post. * * @since 2.6.0 + * @since 4.2.0 Introduced the `$return` parameter. * - * @param string $file The URL of the image to download - * @param int $post_id The post ID the media is to be associated with - * @param string $desc Optional. Description of the image - * @param string $return Optional. What to return: an image tag (default) or only the src. - * @return string|WP_Error Populated HTML img tag on success + * @param string $file The URL of the image to download. + * @param int $post_id The post ID the media is to be associated with. + * @param string $desc Optional. Description of the image. + * @param string $return Optional. Accepts 'html' (image tag html) or 'src' (URL). Default 'html'. + * @return string|WP_Error Populated HTML img tag on success, WP_Error object otherwise. */ function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) { if ( ! empty( $file ) ) { + // Set variables for storage, fix file filename for query strings. preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches ); + if ( ! $matches ) { + return new WP_Error( 'image_sideload_failed', __( 'Invalid image URL' ) ); + } + $file_array = array(); $file_array['name'] = basename( $matches[0] ); @@ -859,7 +877,7 @@ function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) $src = wp_get_attachment_url( $id ); } - // Finally check to make sure the file has been saved, then return the HTML. + // Finally, check to make sure the file has been saved, then return the HTML. if ( ! empty( $src ) ) { if ( $return === 'src' ) { return $src; @@ -874,7 +892,7 @@ function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) } /** - * {@internal Missing Short Description}} + * Retrieves the legacy media uploader form in an iframe. * * @since 2.5.0 * @@ -897,7 +915,7 @@ function media_upload_gallery() { } /** - * {@internal Missing Short Description}} + * Retrieves the legacy media library form in an iframe. * * @since 2.5.0 * @@ -1050,6 +1068,14 @@ function image_link_input_fields($post, $url_type = '') { "; } +/** + * Output a textarea element for inputting an attachment caption. + * + * @since 3.4.0 + * + * @param WP_Post $edit_post Attachment WP_Post object. + * @return string HTML markup for the textarea element. + */ function wp_caption_input_textarea($edit_post) { // Post data is already escaped. $name = "attachments[{$edit_post->ID}][post_excerpt]"; @@ -1058,7 +1084,7 @@ function wp_caption_input_textarea($edit_post) { } /** - * {@internal Missing Short Description}} + * Retrieves the image attachment fields to edit form fields. * * @since 2.5.0 * @@ -1071,7 +1097,7 @@ function image_attachment_fields_to_edit($form_fields, $post) { } /** - * {@internal Missing Short Description}} + * Retrieves the single non-image attachment fields to edit form fields. * * @since 2.5.0 * @@ -1085,7 +1111,7 @@ function media_single_attachment_fields_to_edit( $form_fields, $post ) { } /** - * {@internal Missing Short Description}} + * Retrieves the post non-image attachment fields to edito form fields. * * @since 2.8.0 * @@ -1123,10 +1149,8 @@ function image_attachment_fields_to_save( $post, $attachment ) { return $post; } -add_filter( 'attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2 ); - /** - * {@internal Missing Short Description}} + * Retrieves the media element HTML to send to the editor. * * @since 2.5.0 * @@ -1150,10 +1174,8 @@ function image_media_send_to_editor($html, $attachment_id, $attachment) { return $html; } -add_filter('media_send_to_editor', 'image_media_send_to_editor', 10, 3); - /** - * {@internal Missing Short Description}} + * Retrieves the attachment fields to edit form fields. * * @since 2.5.0 * @@ -1229,7 +1251,7 @@ function get_attachment_fields_to_edit($post, $errors = null) { } // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default - // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing ) + // The recursive merge is easily traversed with array casting: foreach ( (array) $things as $thing ) $form_fields = array_merge_recursive($form_fields, (array) $errors); // This was formerly in image_attachment_fields_to_edit(). @@ -1280,6 +1302,8 @@ function get_attachment_fields_to_edit($post, $errors = null) { * * @since 2.5.0 * + * @global WP_Query $wp_the_query + * * @param int $post_id Optional. Post ID. * @param array $errors Errors for attachment, if any. * @return string @@ -1314,6 +1338,8 @@ function get_media_items( $post_id, $errors ) { * * @since 2.5.0 * + * @global string $redir_tab + * * @param int $attachment_id Attachment ID for modification. * @param string|array $args Optional. Override defaults. * @return string HTML form for attachment. @@ -1352,7 +1378,8 @@ function get_media_item( $attachment_id, $args = null ) { $toggle_on = __( 'Show' ); $toggle_off = __( 'Hide' ); - $filename = esc_html( wp_basename( $post->guid ) ); + $file = get_attached_file( $post->ID ); + $filename = esc_html( wp_basename( $file ) ); $title = esc_attr( $post->post_title ); $post_mime_types = get_post_mime_types(); @@ -1457,7 +1484,9 @@ function get_media_item( $attachment_id, $args = null ) { $delete = "" . __( 'Delete Permanently' ) . ''; } elseif ( !MEDIA_TRASH ) { $delete = "" . __( 'Delete' ) . " -