\n";
}
@@ -88,74 +92,91 @@ function the_media_upload_tabs() {
/**
* {@internal Missing Short Description}}
*
- * @since unknown
- *
- * @param unknown_type $id
- * @param unknown_type $alt
- * @param unknown_type $title
- * @param unknown_type $align
- * @param unknown_type $url
- * @param unknown_type $rel
- * @param unknown_type $size
- * @return unknown
+ * @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
*/
-function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') {
+function get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel = false, $size='medium', $alt = '') {
- $htmlalt = ( empty($alt) ) ? $title : $alt;
+ $html = get_image_tag($id, $alt, '', $align, $size);
- $html = get_image_tag($id, $htmlalt, $title, $align, $size);
-
- $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : '';
+ $rel = $rel ? ' rel="attachment wp-att-' . esc_attr($id).'"' : '';
if ( $url )
- $html = '$html";
+ $html = '$html";
- $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url, $size );
+ $html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt );
return $html;
}
/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- *
- * @param unknown_type $html
- * @param unknown_type $id
- * @param unknown_type $alt
- * @param unknown_type $title
- * @param unknown_type $align
- * @param unknown_type $url
- * @param unknown_type $size
- * @return unknown
+ * Adds image shortcode with caption to editor
+ *
+ * @since 2.6.0
+ *
+ * @param string $html
+ * @param integer $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 $size image size (thumbnail, medium, large, full or added with add_image_size() )
+ * @return string
*/
-function image_add_caption( $html, $id, $alt, $title, $align, $url, $size ) {
+function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {
+
+ if ( empty($caption) || apply_filters( 'disable_captions', '' ) )
+ return $html;
- if ( empty($alt) || apply_filters( 'disable_captions', '' ) ) return $html;
$id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
- preg_match( '/width="([0-9]+)/', $html, $matches );
- if ( ! isset($matches[1]) ) return $html;
+ if ( ! preg_match( '/width=["\']([0-9]+)/', $html, $matches ) )
+ return $html;
+
$width = $matches[1];
- $html = preg_replace( '/align[^\s\'"]+\s?/', '', $html );
- if ( empty($align) ) $align = 'none';
+ $caption = str_replace( array("\r\n", "\r"), "\n", $caption);
+ $caption = preg_replace_callback( '/<[a-zA-Z0-9]+(?: [^<>]+>)*/', '_cleanup_image_add_caption', $caption );
+ // convert any remaining line breaks to
+ $caption = preg_replace( '/[ \n\t]*\n[ \t]*/', ' ', $caption );
- $alt = ! empty($alt) ? addslashes($alt) : '';
+ $html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html );
+ if ( empty($align) )
+ $align = 'none';
- $shcode = '[caption id="' . $id . '" align="align' . $align
- . '" width="' . $width . '" caption="' . $alt . '"]' . $html . '[/caption]';
+ $shcode = '[caption id="' . $id . '" align="align' . $align . '" width="' . $width . '"]' . $html . ' ' . $caption . '[/caption]';
return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
}
-add_filter( 'image_send_to_editor', 'image_add_caption', 20, 7 );
+add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 );
/**
- * {@internal Missing Short Description}}
+ * Private preg_replace callback used in image_add_caption()
+ *
+ * @access private
+ * @since 3.4.0
+ */
+function _cleanup_image_add_caption( $matches ) {
+ // remove any line breaks from inside the tags
+ return preg_replace( '/[\r\n\t]+/', ' ', $matches[0] );
+}
+
+/**
+ * Adds image html to editor
*
- * @since unknown
+ * @since 2.5.0
*
- * @param unknown_type $html
+ * @param string $html
*/
function media_send_to_editor($html) {
?>
@@ -165,24 +186,22 @@ var win = window.dialogArguments || opener || parent || top;
win.send_to_editor('');
/* ]]> */
- false);
+function media_handle_upload($file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false )) {
$time = current_time('mysql');
if ( $post = get_post($post_id) ) {
@@ -190,22 +209,78 @@ function media_handle_upload($file_id, $post_id, $post_data = array()) {
$time = $post->post_date;
}
+ $name = $_FILES[$file_id]['name'];
$file = wp_handle_upload($_FILES[$file_id], $overrides, $time);
if ( isset($file['error']) )
return new WP_Error( 'upload_error', $file['error'] );
+ $name_parts = pathinfo($name);
+ $name = trim( substr( $name, 0, -(1 + strlen($name_parts['extension'])) ) );
+
$url = $file['url'];
$type = $file['type'];
$file = $file['file'];
- $title = preg_replace('/\.[^.]+$/', '', basename($file));
+ $title = $name;
$content = '';
+ if ( preg_match( '#^audio#', $type ) ) {
+ $meta = wp_read_audio_metadata( $file );
+
+ if ( ! empty( $meta['title'] ) )
+ $title = $meta['title'];
+
+ $content = '';
+
+ if ( ! empty( $title ) ) {
+
+ if ( ! empty( $meta['album'] ) && ! empty( $meta['artist'] ) ) {
+ /* translators: 1: audio track title, 2: album title, 3: artist name */
+ $content .= sprintf( __( '"%1$s" from %2$s by %3$s.' ), $title, $meta['album'], $meta['artist'] );
+ } else if ( ! empty( $meta['album'] ) ) {
+ /* translators: 1: audio track title, 2: album title */
+ $content .= sprintf( __( '"%1$s" from %2$s.' ), $title, $meta['album'] );
+ } else if ( ! empty( $meta['artist'] ) ) {
+ /* translators: 1: audio track title, 2: artist name */
+ $content .= sprintf( __( '"%1$s" by %2$s.' ), $title, $meta['artist'] );
+ } else {
+ $content .= sprintf( __( '"%s".' ), $title );
+ }
+
+ } else if ( ! empty( $meta['album'] ) ) {
+
+ if ( ! empty( $meta['artist'] ) ) {
+ /* translators: 1: audio album title, 2: artist name */
+ $content .= sprintf( __( '%1$s by %2$s.' ), $meta['album'], $meta['artist'] );
+ } else {
+ $content .= $meta['album'] . '.';
+ }
+
+ } else if ( ! empty( $meta['artist'] ) ) {
+
+ $content .= $meta['artist'] . '.';
+
+ }
+
+ if ( ! empty( $meta['year'] ) )
+ $content .= ' ' . sprintf( __( 'Released: %d.' ), $meta['year'] );
+
+ if ( ! empty( $meta['track_number'] ) ) {
+ $track_number = explode( '/', $meta['track_number'] );
+ if ( isset( $track_number[1] ) )
+ $content .= ' ' . sprintf( __( 'Track %1$s of %2$s.' ), number_format_i18n( $track_number[0] ), number_format_i18n( $track_number[1] ) );
+ else
+ $content .= ' ' . sprintf( __( 'Track %1$s.' ), number_format_i18n( $track_number[0] ) );
+ }
+
+ if ( ! empty( $meta['genre'] ) )
+ $content .= ' ' . sprintf( __( 'Genre: %s.' ), $meta['genre'] );
+
// use image exif/iptc data for title and caption defaults if possible
- if ( $image_meta = @wp_read_image_metadata($file) ) {
- if ( trim($image_meta['title']) )
+ } elseif ( $image_meta = @wp_read_image_metadata( $file ) ) {
+ if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) )
$title = $image_meta['title'];
- if ( trim($image_meta['caption']) )
+ if ( trim( $image_meta['caption'] ) )
$content = $image_meta['caption'];
}
@@ -218,6 +293,10 @@ function media_handle_upload($file_id, $post_id, $post_data = array()) {
'post_content' => $content,
), $post_data );
+ // This should never be set as it would then overwrite an existing attachment.
+ if ( isset( $attachment['ID'] ) )
+ unset( $attachment['ID'] );
+
// Save the data
$id = wp_insert_attachment($attachment, $file, $post_id);
if ( !is_wp_error($id) ) {
@@ -229,20 +308,26 @@ function media_handle_upload($file_id, $post_id, $post_data = array()) {
}
/**
- * {@internal Missing Short Description}}
+ * This handles a sideloaded file in the same way as an uploaded file is handled by {@link media_handle_upload()}
*
- * @since unknown
+ * @since 2.6.0
*
- * @param unknown_type $file_array
- * @param unknown_type $post_id
- * @param unknown_type $desc
- * @param unknown_type $post_data
- * @return unknown
+ * @param array $file_array Array similar to a {@link $_FILES} upload array
+ * @param int $post_id The post ID the media is associated with
+ * @param string $desc Description of the sideloaded file
+ * @param array $post_data allows you to overwrite some of the attachment
+ * @return int|object The ID of the attachment or a WP_Error on failure
*/
function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
$overrides = array('test_form'=>false);
- $file = wp_handle_sideload($file_array, $overrides);
+ $time = current_time( 'mysql' );
+ if ( $post = get_post( $post_id ) ) {
+ if ( substr( $post->post_date, 0, 4 ) > 0 )
+ $time = $post->post_date;
+ }
+
+ $file = wp_handle_sideload( $file_array, $overrides, $time );
if ( isset($file['error']) )
return new WP_Error( 'upload_error', $file['error'] );
@@ -254,13 +339,14 @@ function media_handle_sideload($file_array, $post_id, $desc = null, $post_data =
// use image exif/iptc data for title and caption defaults if possible
if ( $image_meta = @wp_read_image_metadata($file) ) {
- if ( trim($image_meta['title']) )
+ if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) )
$title = $image_meta['title'];
- if ( trim($image_meta['caption']) )
+ if ( trim( $image_meta['caption'] ) )
$content = $image_meta['caption'];
}
- $title = @$desc;
+ if ( isset( $desc ) )
+ $title = $desc;
// Construct the attachment array
$attachment = array_merge( array(
@@ -271,111 +357,149 @@ function media_handle_sideload($file_array, $post_id, $desc = null, $post_data =
'post_content' => $content,
), $post_data );
- // Save the data
+ // This should never be set as it would then overwrite an existing attachment.
+ if ( isset( $attachment['ID'] ) )
+ unset( $attachment['ID'] );
+
+ // Save the attachment metadata
$id = wp_insert_attachment($attachment, $file, $post_id);
- if ( !is_wp_error($id) ) {
+ if ( !is_wp_error($id) )
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
- return $url;
- }
+
return $id;
}
/**
- * {@internal Missing Short Description}}
+ * Adds the iframe to display content for the media upload page
*
- * Wrap iframe content (produced by $content_func) in a doctype, html head/body
- * etc any additional function args will be passed to content_func.
+ * @since 2.5.0
*
- * @since unknown
- *
- * @param unknown_type $content_func
+ * @param array $content_func
*/
function wp_iframe($content_func /* ... */) {
+ _wp_admin_html_begin();
?>
-
- >
-
-
› —
->
+ class="wp-core-ui no-js">
+
+
-
-
-
-
-EOF;
- printf($context, $out);
+function media_buttons($editor_id = 'content') {
+ $post = get_post();
+ if ( ! $post && ! empty( $GLOBALS['post_ID'] ) )
+ $post = $GLOBALS['post_ID'];
+
+ wp_enqueue_media( array(
+ 'post' => $post
+ ) );
+
+ $img = ' ';
+
+ echo '' . $img . __( 'Add Media' ) . '';
+
+ // Don't use this filter. Want to add a button? Use the media_buttons action.
+ $legacy_filter = apply_filters('media_buttons_context', ''); // deprecated
+
+ if ( $legacy_filter ) {
+ // #WP22559. Close if a plugin started by closing to open their own tag.
+ if ( 0 === stripos( trim( $legacy_filter ), '' ) )
+ $legacy_filter .= '';
+ echo $legacy_filter;
+ }
}
add_action( 'media_buttons', 'media_buttons' );
-add_action('media_upload_media', 'media_upload_handler');
+
+function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) {
+ global $post_ID;
+
+ if ( empty( $post_id ) )
+ $post_id = $post_ID;
+
+ $upload_iframe_src = add_query_arg( 'post_id', (int) $post_id, admin_url('media-upload.php') );
+
+ if ( $type && 'media' != $type )
+ $upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src);
+
+ if ( ! empty( $tab ) )
+ $upload_iframe_src = add_query_arg('tab', $tab, $upload_iframe_src);
+
+ $upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src);
+
+ return add_query_arg('TB_iframe', true, $upload_iframe_src);
+}
/**
* {@internal Missing Short Description}}
*
- * @since unknown
+ * @since 2.5.0
*
- * @return unknown
+ * @return mixed void|object WP_Error on failure
*/
function media_upload_form_handler() {
check_admin_referer('media-form');
+ $errors = null;
+
if ( isset($_POST['send']) ) {
$keys = array_keys($_POST['send']);
$send_id = (int) array_shift($keys);
}
-
+
if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) {
$post = $_post = get_post($attachment_id, ARRAY_A);
+
+ if ( !current_user_can( 'edit_post', $attachment_id ) )
+ continue;
+
if ( isset($attachment['post_content']) )
$post['post_content'] = $attachment['post_content'];
if ( isset($attachment['post_title']) )
@@ -384,6 +508,7 @@ function media_upload_form_handler() {
$post['post_excerpt'] = $attachment['post_excerpt'];
if ( isset($attachment['menu_order']) )
$post['menu_order'] = $attachment['menu_order'];
+
if ( isset($send_id) && $attachment_id == $send_id ) {
if ( isset($attachment['post_parent']) )
$post['post_parent'] = $attachment['post_parent'];
@@ -391,6 +516,15 @@ function media_upload_form_handler() {
$post = apply_filters('attachment_fields_to_save', $post, $attachment);
+ if ( isset($attachment['image_alt']) ) {
+ $image_alt = wp_unslash( $attachment['image_alt'] );
+ if ( $image_alt != get_post_meta($attachment_id, '_wp_attachment_image_alt', true) ) {
+ $image_alt = wp_strip_all_tags( $image_alt, true );
+ // update_meta expects slashed
+ update_post_meta( $attachment_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
+ }
+ }
+
if ( isset($post['errors']) ) {
$errors[$attachment_id] = $post['errors'];
unset($post['errors']);
@@ -399,9 +533,10 @@ function media_upload_form_handler() {
if ( $post != $_post )
wp_update_post($post);
- foreach ( get_attachment_taxonomies($post) as $t )
+ foreach ( get_attachment_taxonomies($post) as $t ) {
if ( isset($attachment[$t]) )
wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false);
+ }
}
if ( isset($_POST['insert-gallery']) || isset($_POST['update-gallery']) ) { ?>
@@ -416,13 +551,16 @@ function media_upload_form_handler() {
}
if ( isset($send_id) ) {
- $attachment = stripslashes_deep( $_POST['attachments'][$send_id] );
- $html = $attachment['post_title'];
+ $attachment = wp_unslash( $_POST['attachments'][$send_id] );
+
+ $html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
if ( !empty($attachment['url']) ) {
- if ( strpos($attachment['url'], 'attachment_id') || false !== strpos($attachment['url'], get_permalink($_POST['post_id'])) )
- $rel = " rel='attachment wp-att-".attribute_escape($send_id)."'";
+ $rel = '';
+ if ( strpos($attachment['url'], 'attachment_id') || get_attachment_link($send_id) == $attachment['url'] )
+ $rel = " rel='attachment wp-att-" . esc_attr($send_id) . "'";
$html = "$html";
}
+
$html = apply_filters('media_send_to_editor', $html, $send_id, $attachment);
return media_send_to_editor($html);
}
@@ -433,15 +571,16 @@ function media_upload_form_handler() {
/**
* {@internal Missing Short Description}}
*
- * @since unknown
+ * @since 2.5.0
*
- * @return unknown
+ * @return mixed
*/
-function media_upload_image() {
+function wp_media_upload_handler() {
$errors = array();
$id = 0;
if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
+ check_admin_referer('media-form');
// Upload File button was clicked
$id = media_handle_upload('async-upload', $_REQUEST['post_id']);
unset($_FILES);
@@ -452,16 +591,37 @@ function media_upload_image() {
}
if ( !empty($_POST['insertonlybutton']) ) {
- $src = $_POST['insertonly']['src'];
+ $src = $_POST['src'];
if ( !empty($src) && !strpos($src, '://') )
$src = "http://$src";
- $alt = attribute_escape($_POST['insertonly']['alt']);
- if ( isset($_POST['insertonly']['align']) ) {
- $align = attribute_escape($_POST['insertonly']['align']);
- $class = " class='align$align'";
+
+ if ( isset( $_POST['media_type'] ) && 'image' != $_POST['media_type'] ) {
+ $title = esc_html( wp_unslash( $_POST['title'] ) );
+ if ( empty( $title ) )
+ $title = esc_html( basename( $src ) );
+
+ if ( $title && $src )
+ $html = "$title";
+
+ $type = 'file';
+ if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) )
+ && ( 'audio' == $ext_type || 'video' == $ext_type ) )
+ $type = $ext_type;
+
+ $html = apply_filters( $type . '_send_to_editor_url', $html, esc_url_raw( $src ), $title );
+ } else {
+ $align = '';
+ $alt = esc_attr( wp_unslash( $_POST['alt'] ) );
+ if ( isset($_POST['align']) ) {
+ $align = esc_attr( wp_unslash( $_POST['align'] ) );
+ $class = " class='align$align'";
+ }
+ if ( !empty($src) )
+ $html = "";
+
+ $html = apply_filters( 'image_send_to_editor_url', $html, esc_url_raw( $src ), $alt, $align );
}
- if ( !empty($src) )
- $html = "";
+
return media_send_to_editor($html);
}
@@ -479,45 +639,57 @@ function media_upload_image() {
return media_upload_gallery();
}
- if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
- return wp_iframe( 'media_upload_type_url_form', 'image', $errors, $id );
+ if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) {
+ $type = 'image';
+ if ( isset( $_GET['type'] ) && in_array( $_GET['type'], array( 'video', 'audio', 'file' ) ) )
+ $type = $_GET['type'];
+ return wp_iframe( 'media_upload_type_url_form', $type, $errors, $id );
+ }
return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
}
/**
- * {@internal Missing Short Description}}
+ * Download an image from the specified URL and attach it to a post.
*
- * @since unknown
+ * @since 2.6.0
*
- * @param unknown_type $file
- * @param unknown_type $post_id
- * @param unknown_type $desc
- * @return unknown
+ * @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
+ * @return string|WP_Error Populated HTML img tag on success
*/
function media_sideload_image($file, $post_id, $desc = null) {
- if (!empty($file) ) {
- $file_array['name'] = basename($file);
- $tmp = download_url($file);
+ if ( ! empty($file) ) {
+ // Download file to temp location
+ $tmp = download_url( $file );
+
+ // Set variables for storage
+ // fix file filename for query strings
+ preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
+ $file_array['name'] = basename($matches[0]);
$file_array['tmp_name'] = $tmp;
- $desc = @$desc;
- if ( is_wp_error($tmp) ) {
+ // If error storing temporarily, unlink
+ if ( is_wp_error( $tmp ) ) {
@unlink($file_array['tmp_name']);
$file_array['tmp_name'] = '';
}
- $id = media_handle_sideload($file_array, $post_id, $desc);
- $src = $id;
-
+ // do the validation and storage stuff
+ $id = media_handle_sideload( $file_array, $post_id, $desc );
+ // If error storing permanently, unlink
if ( is_wp_error($id) ) {
@unlink($file_array['tmp_name']);
return $id;
}
+
+ $src = wp_get_attachment_url( $id );
}
- if ( !empty($src) ) {
- $alt = @$desc;
+ // Finally check to make sure the file has been saved, then return the html
+ if ( ! empty($src) ) {
+ $alt = isset($desc) ? esc_attr($desc) : '';
$html = "";
return $html;
}
@@ -526,166 +698,7 @@ function media_sideload_image($file, $post_id, $desc = null) {
/**
* {@internal Missing Short Description}}
*
- * @since unknown
- *
- * @return unknown
- */
-function media_upload_audio() {
- $errors = array();
- $id = 0;
-
- if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
- // Upload File button was clicked
- $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
- unset($_FILES);
- if ( is_wp_error($id) ) {
- $errors['upload_error'] = $id;
- $id = false;
- }
- }
-
- if ( !empty($_POST['insertonlybutton']) ) {
- $href = $_POST['insertonly']['href'];
- if ( !empty($href) && !strpos($href, '://') )
- $href = "http://$href";
- $title = attribute_escape($_POST['insertonly']['title']);
- if ( empty($title) )
- $title = basename($href);
- if ( !empty($title) && !empty($href) )
- $html = "$title";
- return media_send_to_editor($html);
- }
-
- if ( !empty($_POST) ) {
- $return = media_upload_form_handler();
-
- if ( is_string($return) )
- return $return;
- if ( is_array($return) )
- $errors = $return;
- }
-
- if ( isset($_POST['save']) ) {
- $errors['upload_notice'] = __('Saved.');
- return media_upload_gallery();
- }
-
- if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
- return wp_iframe( 'media_upload_type_url_form', 'audio', $errors, $id );
-
- return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id );
-}
-
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- *
- * @return unknown
- */
-function media_upload_video() {
- $errors = array();
- $id = 0;
-
- if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
- // Upload File button was clicked
- $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
- unset($_FILES);
- if ( is_wp_error($id) ) {
- $errors['upload_error'] = $id;
- $id = false;
- }
- }
-
- if ( !empty($_POST['insertonlybutton']) ) {
- $href = $_POST['insertonly']['href'];
- if ( !empty($href) && !strpos($href, '://') )
- $href = "http://$href";
- $title = attribute_escape($_POST['insertonly']['title']);
- if ( empty($title) )
- $title = basename($href);
- if ( !empty($title) && !empty($href) )
- $html = "$title";
- return media_send_to_editor($html);
- }
-
- if ( !empty($_POST) ) {
- $return = media_upload_form_handler();
-
- if ( is_string($return) )
- return $return;
- if ( is_array($return) )
- $errors = $return;
- }
-
- if ( isset($_POST['save']) ) {
- $errors['upload_notice'] = __('Saved.');
- return media_upload_gallery();
- }
-
- if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
- return wp_iframe( 'media_upload_type_url_form', 'video', $errors, $id );
-
- return wp_iframe( 'media_upload_type_form', 'video', $errors, $id );
-}
-
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
- *
- * @return unknown
- */
-function media_upload_file() {
- $errors = array();
- $id = 0;
-
- if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
- // Upload File button was clicked
- $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
- unset($_FILES);
- if ( is_wp_error($id) ) {
- $errors['upload_error'] = $id;
- $id = false;
- }
- }
-
- if ( !empty($_POST['insertonlybutton']) ) {
- $href = $_POST['insertonly']['href'];
- if ( !empty($href) && !strpos($href, '://') )
- $href = "http://$href";
- $title = attribute_escape($_POST['insertonly']['title']);
- if ( empty($title) )
- $title = basename($href);
- if ( !empty($title) && !empty($href) )
- $html = "$title";
- return media_send_to_editor($html);
- }
-
- if ( !empty($_POST) ) {
- $return = media_upload_form_handler();
-
- if ( is_string($return) )
- return $return;
- if ( is_array($return) )
- $errors = $return;
- }
-
- if ( isset($_POST['save']) ) {
- $errors['upload_notice'] = __('Saved.');
- return media_upload_gallery();
- }
-
- if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
- return wp_iframe( 'media_upload_type_url_form', 'file', $errors, $id );
-
- return wp_iframe( 'media_upload_type_form', 'file', $errors, $id );
-}
-
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
+ * @since 2.5.0
*
* @return unknown
*/
@@ -708,7 +721,7 @@ function media_upload_gallery() {
/**
* {@internal Missing Short Description}}
*
- * @since unknown
+ * @since 2.5.0
*
* @return unknown
*/
@@ -729,24 +742,27 @@ function media_upload_library() {
/**
* Retrieve HTML for the image alignment radio buttons with the specified one checked.
*
- * @since unknown
+ * @since 2.7.0
*
- * @param unknown_type $post
- * @param unknown_type $checked
- * @return unknown
+ * @param object $post
+ * @param string $checked
+ * @return string
*/
-function image_align_input_fields($post, $checked='') {
+function image_align_input_fields( $post, $checked = '' ) {
- $alignments = array('none' => 'None', 'left' => 'Left', 'center' => 'Center', 'right' => 'Right');
- if ( !array_key_exists($checked, $alignments) )
+ if ( empty($checked) )
+ $checked = get_user_setting('align', 'none');
+
+ $alignments = array('none' => __('None'), 'left' => __('Left'), 'center' => __('Center'), 'right' => __('Right'));
+ if ( !array_key_exists( (string) $checked, $alignments ) )
$checked = 'none';
$out = array();
- foreach ($alignments as $name => $label) {
-
+ foreach ( $alignments as $name => $label ) {
+ $name = esc_attr($name);
$out[] = "";
+ " />";
}
return join("\n", $out);
}
@@ -754,36 +770,45 @@ function image_align_input_fields($post, $checked='') {
/**
* Retrieve HTML for the size radio buttons with the specified one checked.
*
- * @since unknown
+ * @since 2.7.0
*
- * @param unknown_type $post
- * @param unknown_type $checked
- * @return unknown
+ * @param object $post
+ * @param bool|string $check
+ * @return array
*/
-function image_size_input_fields($post, $checked='') {
+function image_size_input_fields( $post, $check = '' ) {
// get a list of the actual pixel dimensions of each possible intermediate version of this image
- $size_names = array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full size'));
+ $size_names = apply_filters( 'image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')) );
+
+ if ( empty($check) )
+ $check = get_user_setting('imgsize', 'medium');
- foreach ( $size_names as $size => $name) {
+ foreach ( $size_names as $size => $label ) {
$downsize = image_downsize($post->ID, $size);
+ $checked = '';
// is this size selectable?
$enabled = ( $downsize[3] || 'full' == $size );
$css_id = "image-size-{$size}-{$post->ID}";
// if this size is the default but that's not available, don't select it
- if ( $checked && !$enabled )
- $checked = '';
- // if $checked was not specified, default to the first available size that's bigger than a thumbnail
- if ( !$checked && $enabled && 'thumbnail' != $size )
- $checked = $size;
-
- $html = "
ID][image-size]' id='{$css_id}' value='{$size}'".( $checked == $size ? " checked='checked'" : '') ." />";
-
- $html .= "";
+ if ( $size == $check ) {
+ if ( $enabled )
+ $checked = " checked='checked'";
+ else
+ $check = '';
+ } elseif ( !$check && $enabled && 'thumbnail' != $size ) {
+ // if $check is not enabled, default to the first available size that's bigger than a thumbnail
+ $check = $size;
+ $checked = " checked='checked'";
+ }
+
+ $html = "
ID][image-size]' id='{$css_id}' value='{$size}'$checked />";
+
+ $html .= "";
// only show the dimensions if that choice is available
if ( $enabled )
- $html .= " ";
+ $html .= " ";
$html .= '
' . sprintf( __('The web browser on your device cannot be used to upload files. You may be able to use the native app for your device instead.'), 'http://wordpress.org/mobile/' ) . '
+ post_mime_type ) ):
+
+ /**
+ * Audio and video metadata fields to be shown in the publish meta box.
+ *
+ * The key for each item in the array should correspond to an attachment
+ * metadata key, and the value should be the desired label.
+ *
+ * @since 3.7.0
+ *
+ * @param array $fields {
+ * An array of the attachment metadata keys and labels.
+ *
+ * @type string 'mime_type' Label to be shown before the field mime_type.
+ * @type string 'year' Label to be shown before the field year.
+ * @type string 'genre' Label to be shown before the field genre.
+ * @type string 'length_formatted' Label to be shown before the field length_formatted.
+ * }
+ */
+ $fields = apply_filters( 'media_submitbox_misc_sections', array(
+ 'mime_type' => __( 'Mime-type:' ),
+ 'year' => __( 'Year:' ),
+ 'genre' => __( 'Genre:' ),
+ 'length_formatted' => __( 'Length:' ),
+ ) );
+
+ foreach ( $fields as $key => $label ):
+ if ( ! empty( $meta[$key] ) ) : ?>
+