\n";
}
}
-function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') {
-
- $html = get_image_tag($id, $alt, $title, $align, $size);
-
- $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : '';
+/**
+ * {@internal Missing Short Description}}
+ *
+ * @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, $caption, $title, $align, $url='', $rel = false, $size='medium', $alt = '') {
+
+ $html = get_image_tag($id, $alt, '', $align, $size);
+
+ $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;
}
-function image_add_caption( $html, $id, $alt, $title, $align, $url, $size ) {
+/**
+ * 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, $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 );
+
+ $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 );
+
+/**
+ * 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 2.5.0
+ *
+ * @param string $html
+ */
function media_send_to_editor($html) {
- ?>
+?>
- false);
- $file = wp_handle_upload($_FILES[$file_id], $overrides);
+/**
+ * This handles the file upload POST itself, creating the attachment post.
+ *
+ * @since 2.5.0
+ *
+ * @param string $file_id Index into the {@link $_FILES} array of the upload
+ * @param int $post_id The post ID the media is associated with
+ * @param array $post_data allows you to overwrite some of the attachment
+ * @param array $overrides allows you to override the {@link wp_handle_upload()} behavior
+ * @return int the ID of the attachment
+ */
+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) ) {
+ if ( substr( $post->post_date, 0, 4 ) > 0 )
+ $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'];
}
@@ -127,8 +293,12 @@ 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_parent);
+ $id = wp_insert_attachment($attachment, $file, $post_id);
if ( !is_wp_error($id) ) {
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
}
@@ -137,10 +307,27 @@ function media_handle_upload($file_id, $post_id, $post_data = array()) {
}
+/**
+ * This handles a sideloaded file in the same way as an uploaded file is handled by {@link media_handle_upload()}
+ *
+ * @since 2.6.0
+ *
+ * @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'] );
@@ -152,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(
@@ -169,87 +357,149 @@ function media_handle_sideload($file_array, $post_id, $desc = null, $post_data =
'post_content' => $content,
), $post_data );
- // Save the data
- $id = wp_insert_attachment($attachment, $file, $post_parent);
- if ( !is_wp_error($id) ) {
+ // 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) )
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
- return $url;
- }
+
return $id;
}
-
-// wrap iframe content (produced by $content_func) in a doctype, html head/body etc
-// any additional function args will be passed to content_func
+/**
+ * Adds the iframe to display content for the media upload page
+ *
+ * @since 2.5.0
+ *
+ * @param array $content_func
+ */
function wp_iframe($content_func /* ... */) {
+ _wp_admin_html_begin();
?>
-
- >
-
-
› —
->
+ class="wp-core-ui no-js">
+
+
-
-
-
-
-EOF;
- printf($context, $out);
+/**
+ * Adds the media button to the editor
+ *
+ * @since 2.5.0
+ *
+ * @param string $editor_id
+ */
+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 2.5.0
+ *
+ * @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']) )
@@ -259,8 +509,22 @@ function media_upload_form_handler() {
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'];
+ }
+
$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']);
@@ -269,24 +533,34 @@ 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']) )
- return media_send_to_editor('[gallery]');
+ if ( isset($_POST['insert-gallery']) || isset($_POST['update-gallery']) ) { ?>
+
+ $html";
}
+
$html = apply_filters('media_send_to_editor', $html, $send_id, $attachment);
return media_send_to_editor($html);
}
@@ -294,8 +568,19 @@ function media_upload_form_handler() {
return $errors;
}
-function media_upload_image() {
+/**
+ * {@internal Missing Short Description}}
+ *
+ * @since 2.5.0
+ *
+ * @return mixed
+ */
+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);
@@ -306,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);
}
@@ -333,53 +639,71 @@ function media_upload_image() {
return media_upload_gallery();
}
+ 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 );
}
+/**
+ * Download an image from the specified URL and attach it to a post.
+ *
+ * @since 2.6.0
+ *
+ * @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);
- $file_array['tmp_name'] = download_url($file);
- $desc = @$desc;
-
- $id = media_handle_sideload($file_array, $post_id, $desc);
- $src = $id;
+ 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;
+
+ // If error storing temporarily, unlink
+ if ( is_wp_error( $tmp ) ) {
+ @unlink($file_array['tmp_name']);
+ $file_array['tmp_name'] = '';
+ }
+ // 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;
}
}
-function media_upload_audio() {
- 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);
- }
+/**
+ * {@internal Missing Short Description}}
+ *
+ * @since 2.5.0
+ *
+ * @return unknown
+ */
+function media_upload_gallery() {
+ $errors = array();
if ( !empty($_POST) ) {
$return = media_upload_form_handler();
@@ -390,37 +714,19 @@ function media_upload_audio() {
$errors = $return;
}
- if ( isset($_POST['save']) ) {
- $errors['upload_notice'] = __('Saved.');
- return media_upload_gallery();
- }
-
- return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id );
+ wp_enqueue_script('admin-gallery');
+ return wp_iframe( 'media_upload_gallery_form', $errors );
}
-function media_upload_video() {
- 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);
- }
-
+/**
+ * {@internal Missing Short Description}}
+ *
+ * @since 2.5.0
+ *
+ * @return unknown
+ */
+function media_upload_library() {
+ $errors = array();
if ( !empty($_POST) ) {
$return = media_upload_form_handler();
@@ -430,158 +736,218 @@ function media_upload_video() {
$errors = $return;
}
- if ( isset($_POST['save']) ) {
- $errors['upload_notice'] = __('Saved.');
- return media_upload_gallery();
- }
-
- return wp_iframe( 'media_upload_type_form', 'video', $errors, $id );
+ return wp_iframe( 'media_upload_library_form', $errors );
}
-function media_upload_file() {
- 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;
+/**
+ * Retrieve HTML for the image alignment radio buttons with the specified one checked.
+ *
+ * @since 2.7.0
+ *
+ * @param object $post
+ * @param string $checked
+ * @return string
+ */
+function image_align_input_fields( $post, $checked = '' ) {
+
+ 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 ) {
+ $name = esc_attr($name);
+ $out[] = "";
}
+ return join("\n", $out);
+}
- if ( isset($_POST['save']) ) {
- $errors['upload_notice'] = __('Saved.');
- return media_upload_gallery();
- }
+/**
+ * Retrieve HTML for the size radio buttons with the specified one checked.
+ *
+ * @since 2.7.0
+ *
+ * @param object $post
+ * @param bool|string $check
+ * @return array
+ */
+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 = 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 => $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 ( $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 .= '
' . 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/' ) . '