66 $tabs = media_upload_tabs(); |
73 $tabs = media_upload_tabs(); |
67 $default = 'type'; |
74 $default = 'type'; |
68 |
75 |
69 if ( !empty($tabs) ) { |
76 if ( !empty($tabs) ) { |
70 echo "<ul id='sidemenu'>\n"; |
77 echo "<ul id='sidemenu'>\n"; |
71 if ( isset($redir_tab) && array_key_exists($redir_tab, $tabs) ) |
78 if ( isset($redir_tab) && array_key_exists($redir_tab, $tabs) ) { |
72 $current = $redir_tab; |
79 $current = $redir_tab; |
73 elseif ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) ) |
80 } elseif ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) ) { |
74 $current = $_GET['tab']; |
81 $current = $_GET['tab']; |
75 else |
82 } else { |
76 $current = apply_filters('media_upload_default_tab', $default); |
83 /** This filter is documented in wp-admin/media-upload.php */ |
|
84 $current = apply_filters( 'media_upload_default_tab', $default ); |
|
85 } |
77 |
86 |
78 foreach ( $tabs as $callback => $text ) { |
87 foreach ( $tabs as $callback => $text ) { |
79 $class = ''; |
88 $class = ''; |
80 |
89 |
81 if ( $current == $callback ) |
90 if ( $current == $callback ) |
111 $rel = $rel ? ' rel="attachment wp-att-' . esc_attr($id).'"' : ''; |
120 $rel = $rel ? ' rel="attachment wp-att-' . esc_attr($id).'"' : ''; |
112 |
121 |
113 if ( $url ) |
122 if ( $url ) |
114 $html = '<a href="' . esc_attr($url) . "\"$rel>$html</a>"; |
123 $html = '<a href="' . esc_attr($url) . "\"$rel>$html</a>"; |
115 |
124 |
|
125 /** |
|
126 * Filter the image HTML markup to send to the editor. |
|
127 * |
|
128 * @since 2.5.0 |
|
129 * |
|
130 * @param string $html The image HTML markup to send. |
|
131 * @param int $id The attachment id. |
|
132 * @param string $caption The image caption. |
|
133 * @param string $title The image title. |
|
134 * @param string $align The image alignment. |
|
135 * @param string $url The image source URL. |
|
136 * @param string $size The image size. |
|
137 * @param string $alt The image alternative, or alt, text. |
|
138 */ |
116 $html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt ); |
139 $html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt ); |
117 |
140 |
118 return $html; |
141 return $html; |
119 } |
142 } |
120 |
143 |
133 * @param string $size image size (thumbnail, medium, large, full or added with add_image_size() ) |
156 * @param string $size image size (thumbnail, medium, large, full or added with add_image_size() ) |
134 * @return string |
157 * @return string |
135 */ |
158 */ |
136 function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) { |
159 function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) { |
137 |
160 |
|
161 /** |
|
162 * Filter the caption text. |
|
163 * |
|
164 * Note: If the caption text is empty, the caption shortcode will not be appended |
|
165 * to the image HTML when inserted into the editor. |
|
166 * |
|
167 * Passing an empty value also prevents the {@see 'image_add_caption_shortcode'} |
|
168 * filter from being evaluated at the end of {@see image_add_caption()}. |
|
169 * |
|
170 * @since 4.1.0 |
|
171 * |
|
172 * @param string $caption The original caption text. |
|
173 * @param int $id The attachment ID. |
|
174 */ |
|
175 $caption = apply_filters( 'image_add_caption_text', $caption, $id ); |
|
176 |
|
177 /** |
|
178 * Filter whether to disable captions. |
|
179 * |
|
180 * Prevents image captions from being appended to image HTML when inserted into the editor. |
|
181 * |
|
182 * @since 2.6.0 |
|
183 * |
|
184 * @param bool $bool Whether to disable appending captions. Returning true to the filter |
|
185 * will disable captions. Default empty string. |
|
186 */ |
138 if ( empty($caption) || apply_filters( 'disable_captions', '' ) ) |
187 if ( empty($caption) || apply_filters( 'disable_captions', '' ) ) |
139 return $html; |
188 return $html; |
140 |
189 |
141 $id = ( 0 < (int) $id ) ? 'attachment_' . $id : ''; |
190 $id = ( 0 < (int) $id ) ? 'attachment_' . $id : ''; |
142 |
191 |
145 |
194 |
146 $width = $matches[1]; |
195 $width = $matches[1]; |
147 |
196 |
148 $caption = str_replace( array("\r\n", "\r"), "\n", $caption); |
197 $caption = str_replace( array("\r\n", "\r"), "\n", $caption); |
149 $caption = preg_replace_callback( '/<[a-zA-Z0-9]+(?: [^<>]+>)*/', '_cleanup_image_add_caption', $caption ); |
198 $caption = preg_replace_callback( '/<[a-zA-Z0-9]+(?: [^<>]+>)*/', '_cleanup_image_add_caption', $caption ); |
150 // convert any remaining line breaks to <br> |
199 |
|
200 // Convert any remaining line breaks to <br>. |
151 $caption = preg_replace( '/[ \n\t]*\n[ \t]*/', '<br />', $caption ); |
201 $caption = preg_replace( '/[ \n\t]*\n[ \t]*/', '<br />', $caption ); |
152 |
202 |
153 $html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html ); |
203 $html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html ); |
154 if ( empty($align) ) |
204 if ( empty($align) ) |
155 $align = 'none'; |
205 $align = 'none'; |
156 |
206 |
157 $shcode = '[caption id="' . $id . '" align="align' . $align . '" width="' . $width . '"]' . $html . ' ' . $caption . '[/caption]'; |
207 $shcode = '[caption id="' . $id . '" align="align' . $align . '" width="' . $width . '"]' . $html . ' ' . $caption . '[/caption]'; |
158 |
208 |
|
209 /** |
|
210 * Filter the image HTML markup including the caption shortcode. |
|
211 * |
|
212 * @since 2.6.0 |
|
213 * |
|
214 * @param string $shcode The image HTML markup with caption shortcode. |
|
215 * @param string $html The image HTML markup. |
|
216 */ |
159 return apply_filters( 'image_add_caption_shortcode', $shcode, $html ); |
217 return apply_filters( 'image_add_caption_shortcode', $shcode, $html ); |
160 } |
218 } |
161 add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 ); |
219 add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 ); |
162 |
220 |
163 /** |
221 /** |
179 * @param string $html |
237 * @param string $html |
180 */ |
238 */ |
181 function media_send_to_editor($html) { |
239 function media_send_to_editor($html) { |
182 ?> |
240 ?> |
183 <script type="text/javascript"> |
241 <script type="text/javascript"> |
184 /* <![CDATA[ */ |
|
185 var win = window.dialogArguments || opener || parent || top; |
242 var win = window.dialogArguments || opener || parent || top; |
186 win.send_to_editor('<?php echo addslashes($html); ?>'); |
243 win.send_to_editor('<?php echo addslashes($html); ?>'); |
187 /* ]]> */ |
|
188 </script> |
244 </script> |
189 <?php |
245 <?php |
190 exit; |
246 exit; |
191 } |
247 } |
192 |
248 |
193 /** |
249 /** |
194 * This handles the file upload POST itself, creating the attachment post. |
250 * Save a file submitted from a POST request and create an attachment post for it. |
195 * |
251 * |
196 * @since 2.5.0 |
252 * @since 2.5.0 |
197 * |
253 * |
198 * @param string $file_id Index into the {@link $_FILES} array of the upload |
254 * @param string $file_id Index of the {@link $_FILES} array that the file was sent. Required. |
199 * @param int $post_id The post ID the media is associated with |
255 * @param int $post_id The post ID of a post to attach the media item to. Required, but can |
200 * @param array $post_data allows you to overwrite some of the attachment |
256 * be set to 0, creating a media item that has no relationship to a post. |
201 * @param array $overrides allows you to override the {@link wp_handle_upload()} behavior |
257 * @param array $post_data Overwrite some of the attachment. Optional. |
202 * @return int the ID of the attachment |
258 * @param array $overrides Override the {@link wp_handle_upload()} behavior. Optional. |
|
259 * @return int|WP_Error ID of the attachment or a WP_Error object on failure. |
203 */ |
260 */ |
204 function media_handle_upload($file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false )) { |
261 function media_handle_upload($file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false )) { |
205 |
262 |
206 $time = current_time('mysql'); |
263 $time = current_time('mysql'); |
207 if ( $post = get_post($post_id) ) { |
264 if ( $post = get_post($post_id) ) { |
221 $url = $file['url']; |
278 $url = $file['url']; |
222 $type = $file['type']; |
279 $type = $file['type']; |
223 $file = $file['file']; |
280 $file = $file['file']; |
224 $title = $name; |
281 $title = $name; |
225 $content = ''; |
282 $content = ''; |
|
283 $excerpt = ''; |
226 |
284 |
227 if ( preg_match( '#^audio#', $type ) ) { |
285 if ( preg_match( '#^audio#', $type ) ) { |
228 $meta = wp_read_audio_metadata( $file ); |
286 $meta = wp_read_audio_metadata( $file ); |
229 |
287 |
230 if ( ! empty( $meta['title'] ) ) |
288 if ( ! empty( $meta['title'] ) ) { |
231 $title = $meta['title']; |
289 $title = $meta['title']; |
232 |
290 } |
233 $content = ''; |
|
234 |
291 |
235 if ( ! empty( $title ) ) { |
292 if ( ! empty( $title ) ) { |
236 |
293 |
237 if ( ! empty( $meta['album'] ) && ! empty( $meta['artist'] ) ) { |
294 if ( ! empty( $meta['album'] ) && ! empty( $meta['artist'] ) ) { |
238 /* translators: 1: audio track title, 2: album title, 3: artist name */ |
295 /* translators: 1: audio track title, 2: album title, 3: artist name */ |
239 $content .= sprintf( __( '"%1$s" from %2$s by %3$s.' ), $title, $meta['album'], $meta['artist'] ); |
296 $content .= sprintf( __( '"%1$s" from %2$s by %3$s.' ), $title, $meta['album'], $meta['artist'] ); |
240 } else if ( ! empty( $meta['album'] ) ) { |
297 } elseif ( ! empty( $meta['album'] ) ) { |
241 /* translators: 1: audio track title, 2: album title */ |
298 /* translators: 1: audio track title, 2: album title */ |
242 $content .= sprintf( __( '"%1$s" from %2$s.' ), $title, $meta['album'] ); |
299 $content .= sprintf( __( '"%1$s" from %2$s.' ), $title, $meta['album'] ); |
243 } else if ( ! empty( $meta['artist'] ) ) { |
300 } elseif ( ! empty( $meta['artist'] ) ) { |
244 /* translators: 1: audio track title, 2: artist name */ |
301 /* translators: 1: audio track title, 2: artist name */ |
245 $content .= sprintf( __( '"%1$s" by %2$s.' ), $title, $meta['artist'] ); |
302 $content .= sprintf( __( '"%1$s" by %2$s.' ), $title, $meta['artist'] ); |
246 } else { |
303 } else { |
247 $content .= sprintf( __( '"%s".' ), $title ); |
304 $content .= sprintf( __( '"%s".' ), $title ); |
248 } |
305 } |
249 |
306 |
250 } else if ( ! empty( $meta['album'] ) ) { |
307 } elseif ( ! empty( $meta['album'] ) ) { |
251 |
308 |
252 if ( ! empty( $meta['artist'] ) ) { |
309 if ( ! empty( $meta['artist'] ) ) { |
253 /* translators: 1: audio album title, 2: artist name */ |
310 /* translators: 1: audio album title, 2: artist name */ |
254 $content .= sprintf( __( '%1$s by %2$s.' ), $meta['album'], $meta['artist'] ); |
311 $content .= sprintf( __( '%1$s by %2$s.' ), $meta['album'], $meta['artist'] ); |
255 } else { |
312 } else { |
256 $content .= $meta['album'] . '.'; |
313 $content .= $meta['album'] . '.'; |
257 } |
314 } |
258 |
315 |
259 } else if ( ! empty( $meta['artist'] ) ) { |
316 } elseif ( ! empty( $meta['artist'] ) ) { |
260 |
317 |
261 $content .= $meta['artist'] . '.'; |
318 $content .= $meta['artist'] . '.'; |
262 |
319 |
263 } |
320 } |
264 |
321 |
274 } |
331 } |
275 |
332 |
276 if ( ! empty( $meta['genre'] ) ) |
333 if ( ! empty( $meta['genre'] ) ) |
277 $content .= ' ' . sprintf( __( 'Genre: %s.' ), $meta['genre'] ); |
334 $content .= ' ' . sprintf( __( 'Genre: %s.' ), $meta['genre'] ); |
278 |
335 |
279 // use image exif/iptc data for title and caption defaults if possible |
336 // Use image exif/iptc data for title and caption defaults if possible. |
280 } elseif ( $image_meta = @wp_read_image_metadata( $file ) ) { |
337 } elseif ( 0 === strpos( $type, 'image/' ) && $image_meta = @wp_read_image_metadata( $file ) ) { |
281 if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) |
338 if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) { |
282 $title = $image_meta['title']; |
339 $title = $image_meta['title']; |
283 if ( trim( $image_meta['caption'] ) ) |
340 } |
284 $content = $image_meta['caption']; |
341 |
|
342 if ( trim( $image_meta['caption'] ) ) { |
|
343 $excerpt = $image_meta['caption']; |
|
344 } |
285 } |
345 } |
286 |
346 |
287 // Construct the attachment array |
347 // Construct the attachment array |
288 $attachment = array_merge( array( |
348 $attachment = array_merge( array( |
289 'post_mime_type' => $type, |
349 'post_mime_type' => $type, |
290 'guid' => $url, |
350 'guid' => $url, |
291 'post_parent' => $post_id, |
351 'post_parent' => $post_id, |
292 'post_title' => $title, |
352 'post_title' => $title, |
293 'post_content' => $content, |
353 'post_content' => $content, |
|
354 'post_excerpt' => $excerpt, |
294 ), $post_data ); |
355 ), $post_data ); |
295 |
356 |
296 // This should never be set as it would then overwrite an existing attachment. |
357 // This should never be set as it would then overwrite an existing attachment. |
297 if ( isset( $attachment['ID'] ) ) |
358 if ( isset( $attachment['ID'] ) ) |
298 unset( $attachment['ID'] ); |
359 unset( $attachment['ID'] ); |
335 $type = $file['type']; |
396 $type = $file['type']; |
336 $file = $file['file']; |
397 $file = $file['file']; |
337 $title = preg_replace('/\.[^.]+$/', '', basename($file)); |
398 $title = preg_replace('/\.[^.]+$/', '', basename($file)); |
338 $content = ''; |
399 $content = ''; |
339 |
400 |
340 // use image exif/iptc data for title and caption defaults if possible |
401 // Use image exif/iptc data for title and caption defaults if possible. |
341 if ( $image_meta = @wp_read_image_metadata($file) ) { |
402 if ( $image_meta = @wp_read_image_metadata($file) ) { |
342 if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) |
403 if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) |
343 $title = $image_meta['title']; |
404 $title = $image_meta['title']; |
344 if ( trim( $image_meta['caption'] ) ) |
405 if ( trim( $image_meta['caption'] ) ) |
345 $content = $image_meta['caption']; |
406 $content = $image_meta['caption']; |
346 } |
407 } |
347 |
408 |
348 if ( isset( $desc ) ) |
409 if ( isset( $desc ) ) |
349 $title = $desc; |
410 $title = $desc; |
350 |
411 |
351 // Construct the attachment array |
412 // Construct the attachment array. |
352 $attachment = array_merge( array( |
413 $attachment = array_merge( array( |
353 'post_mime_type' => $type, |
414 'post_mime_type' => $type, |
354 'guid' => $url, |
415 'guid' => $url, |
355 'post_parent' => $post_id, |
416 'post_parent' => $post_id, |
356 'post_title' => $title, |
417 'post_title' => $title, |
388 || ( ! is_array( $content_func ) && 0 === strpos( $content_func, 'media' ) ) ) |
449 || ( ! is_array( $content_func ) && 0 === strpos( $content_func, 'media' ) ) ) |
389 wp_enqueue_style( 'media' ); |
450 wp_enqueue_style( 'media' ); |
390 wp_enqueue_style( 'ie' ); |
451 wp_enqueue_style( 'ie' ); |
391 ?> |
452 ?> |
392 <script type="text/javascript"> |
453 <script type="text/javascript"> |
393 //<![CDATA[ |
|
394 addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}; |
454 addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}; |
395 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup', |
455 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup', |
396 isRtl = <?php echo (int) is_rtl(); ?>; |
456 isRtl = <?php echo (int) is_rtl(); ?>; |
397 //]]> |
|
398 </script> |
457 </script> |
399 <?php |
458 <?php |
400 do_action('admin_enqueue_scripts', 'media-upload-popup'); |
459 /** This action is documented in wp-admin/admin-header.php */ |
401 do_action('admin_print_styles-media-upload-popup'); |
460 do_action( 'admin_enqueue_scripts', 'media-upload-popup' ); |
402 do_action('admin_print_styles'); |
461 |
403 do_action('admin_print_scripts-media-upload-popup'); |
462 /** |
404 do_action('admin_print_scripts'); |
463 * Fires when admin styles enqueued for the legacy (pre-3.5.0) media upload popup are printed. |
405 do_action('admin_head-media-upload-popup'); |
464 * |
406 do_action('admin_head'); |
465 * @since 2.9.0 |
407 |
466 */ |
408 if ( is_string($content_func) ) |
467 do_action( 'admin_print_styles-media-upload-popup' ); |
|
468 |
|
469 /** This action is documented in wp-admin/admin-header.php */ |
|
470 do_action( 'admin_print_styles' ); |
|
471 |
|
472 /** |
|
473 * Fires when admin scripts enqueued for the legacy (pre-3.5.0) media upload popup are printed. |
|
474 * |
|
475 * @since 2.9.0 |
|
476 */ |
|
477 do_action( 'admin_print_scripts-media-upload-popup' ); |
|
478 |
|
479 /** This action is documented in wp-admin/admin-header.php */ |
|
480 do_action( 'admin_print_scripts' ); |
|
481 |
|
482 /** |
|
483 * Fires when scripts enqueued for the admin header for the legacy (pre-3.5.0) |
|
484 * media upload popup are printed. |
|
485 * |
|
486 * @since 2.9.0 |
|
487 */ |
|
488 do_action( 'admin_head-media-upload-popup' ); |
|
489 |
|
490 /** This action is documented in wp-admin/admin-header.php */ |
|
491 do_action( 'admin_head' ); |
|
492 |
|
493 if ( is_string( $content_func ) ) { |
|
494 /** |
|
495 * Fires in the admin header for each specific form tab in the legacy |
|
496 * (pre-3.5.0) media upload popup. |
|
497 * |
|
498 * The dynamic portion of the hook, `$content_func`, refers to the form |
|
499 * callback for the media upload type. Possible values include |
|
500 * 'media_upload_type_form', 'media_upload_type_url_form', and |
|
501 * 'media_upload_library_form'. |
|
502 * |
|
503 * @since 2.5.0 |
|
504 */ |
409 do_action( "admin_head_{$content_func}" ); |
505 do_action( "admin_head_{$content_func}" ); |
|
506 } |
410 ?> |
507 ?> |
411 </head> |
508 </head> |
412 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="wp-core-ui no-js"> |
509 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="wp-core-ui no-js"> |
413 <script type="text/javascript"> |
510 <script type="text/javascript"> |
414 document.body.className = document.body.className.replace('no-js', 'js'); |
511 document.body.className = document.body.className.replace('no-js', 'js'); |
432 * @since 2.5.0 |
530 * @since 2.5.0 |
433 * |
531 * |
434 * @param string $editor_id |
532 * @param string $editor_id |
435 */ |
533 */ |
436 function media_buttons($editor_id = 'content') { |
534 function media_buttons($editor_id = 'content') { |
|
535 static $instance = 0; |
|
536 $instance++; |
|
537 |
437 $post = get_post(); |
538 $post = get_post(); |
438 if ( ! $post && ! empty( $GLOBALS['post_ID'] ) ) |
539 if ( ! $post && ! empty( $GLOBALS['post_ID'] ) ) |
439 $post = $GLOBALS['post_ID']; |
540 $post = $GLOBALS['post_ID']; |
440 |
541 |
441 wp_enqueue_media( array( |
542 wp_enqueue_media( array( |
442 'post' => $post |
543 'post' => $post |
443 ) ); |
544 ) ); |
444 |
545 |
445 $img = '<span class="wp-media-buttons-icon"></span> '; |
546 $img = '<span class="wp-media-buttons-icon"></span> '; |
446 |
547 |
447 echo '<a href="#" id="insert-media-button" class="button insert-media add_media" data-editor="' . esc_attr( $editor_id ) . '" title="' . esc_attr__( 'Add Media' ) . '">' . $img . __( 'Add Media' ) . '</a>'; |
548 $id_attribute = $instance === 1 ? ' id="insert-media-button"' : ''; |
448 |
549 printf( '<a href="#"%s class="button insert-media add_media" data-editor="%s" title="%s">%s</a>', |
449 // Don't use this filter. Want to add a button? Use the media_buttons action. |
550 $id_attribute, |
450 $legacy_filter = apply_filters('media_buttons_context', ''); // deprecated |
551 esc_attr( $editor_id ), |
|
552 esc_attr__( 'Add Media' ), |
|
553 $img . __( 'Add Media' ) |
|
554 ); |
|
555 /** |
|
556 * Filter the legacy (pre-3.5.0) media buttons. |
|
557 * |
|
558 * @since 2.5.0 |
|
559 * @deprecated 3.5.0 Use 'media_buttons' action instead. |
|
560 * |
|
561 * @param string $string Media buttons context. Default empty. |
|
562 */ |
|
563 $legacy_filter = apply_filters( 'media_buttons_context', '' ); |
451 |
564 |
452 if ( $legacy_filter ) { |
565 if ( $legacy_filter ) { |
453 // #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag. |
566 // #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag. |
454 if ( 0 === stripos( trim( $legacy_filter ), '</a>' ) ) |
567 if ( 0 === stripos( trim( $legacy_filter ), '</a>' ) ) |
455 $legacy_filter .= '</a>'; |
568 $legacy_filter .= '</a>'; |
456 echo $legacy_filter; |
569 echo $legacy_filter; |
457 } |
570 } |
458 } |
571 } |
459 add_action( 'media_buttons', 'media_buttons' ); |
572 add_action( 'media_buttons', 'media_buttons' ); |
460 |
573 |
|
574 /** |
|
575 * |
|
576 * @global int $post_ID |
|
577 * @param string $type |
|
578 * @param int $post_id |
|
579 * @param string $tab |
|
580 * @return string |
|
581 */ |
461 function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) { |
582 function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) { |
462 global $post_ID; |
583 global $post_ID; |
463 |
584 |
464 if ( empty( $post_id ) ) |
585 if ( empty( $post_id ) ) |
465 $post_id = $post_ID; |
586 $post_id = $post_ID; |
470 $upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src); |
591 $upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src); |
471 |
592 |
472 if ( ! empty( $tab ) ) |
593 if ( ! empty( $tab ) ) |
473 $upload_iframe_src = add_query_arg('tab', $tab, $upload_iframe_src); |
594 $upload_iframe_src = add_query_arg('tab', $tab, $upload_iframe_src); |
474 |
595 |
475 $upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src); |
596 /** |
|
597 * Filter the upload iframe source URL for a specific media type. |
|
598 * |
|
599 * The dynamic portion of the hook name, `$type`, refers to the type |
|
600 * of media uploaded. |
|
601 * |
|
602 * @since 3.0.0 |
|
603 * |
|
604 * @param string $upload_iframe_src The upload iframe source URL by type. |
|
605 */ |
|
606 $upload_iframe_src = apply_filters( $type . '_upload_iframe_src', $upload_iframe_src ); |
476 |
607 |
477 return add_query_arg('TB_iframe', true, $upload_iframe_src); |
608 return add_query_arg('TB_iframe', true, $upload_iframe_src); |
478 } |
609 } |
479 |
610 |
480 /** |
611 /** |
512 if ( isset($send_id) && $attachment_id == $send_id ) { |
643 if ( isset($send_id) && $attachment_id == $send_id ) { |
513 if ( isset($attachment['post_parent']) ) |
644 if ( isset($attachment['post_parent']) ) |
514 $post['post_parent'] = $attachment['post_parent']; |
645 $post['post_parent'] = $attachment['post_parent']; |
515 } |
646 } |
516 |
647 |
517 $post = apply_filters('attachment_fields_to_save', $post, $attachment); |
648 /** |
|
649 * Filter the attachment fields to be saved. |
|
650 * |
|
651 * @since 2.5.0 |
|
652 * |
|
653 * @see wp_get_attachment_metadata() |
|
654 * |
|
655 * @param WP_Post $post The WP_Post object. |
|
656 * @param array $attachment An array of attachment metadata. |
|
657 */ |
|
658 $post = apply_filters( 'attachment_fields_to_save', $post, $attachment ); |
518 |
659 |
519 if ( isset($attachment['image_alt']) ) { |
660 if ( isset($attachment['image_alt']) ) { |
520 $image_alt = wp_unslash( $attachment['image_alt'] ); |
661 $image_alt = wp_unslash( $attachment['image_alt'] ); |
521 if ( $image_alt != get_post_meta($attachment_id, '_wp_attachment_image_alt', true) ) { |
662 if ( $image_alt != get_post_meta($attachment_id, '_wp_attachment_image_alt', true) ) { |
522 $image_alt = wp_strip_all_tags( $image_alt, true ); |
663 $image_alt = wp_strip_all_tags( $image_alt, true ); |
523 // update_meta expects slashed |
664 |
|
665 // Update_meta expects slashed. |
524 update_post_meta( $attachment_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) ); |
666 update_post_meta( $attachment_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) ); |
525 } |
667 } |
526 } |
668 } |
527 |
669 |
528 if ( isset($post['errors']) ) { |
670 if ( isset($post['errors']) ) { |
559 if ( strpos($attachment['url'], 'attachment_id') || get_attachment_link($send_id) == $attachment['url'] ) |
699 if ( strpos($attachment['url'], 'attachment_id') || get_attachment_link($send_id) == $attachment['url'] ) |
560 $rel = " rel='attachment wp-att-" . esc_attr($send_id) . "'"; |
700 $rel = " rel='attachment wp-att-" . esc_attr($send_id) . "'"; |
561 $html = "<a href='{$attachment['url']}'$rel>$html</a>"; |
701 $html = "<a href='{$attachment['url']}'$rel>$html</a>"; |
562 } |
702 } |
563 |
703 |
564 $html = apply_filters('media_send_to_editor', $html, $send_id, $attachment); |
704 /** |
|
705 * Filter the HTML markup for a media item sent to the editor. |
|
706 * |
|
707 * @since 2.5.0 |
|
708 * |
|
709 * @see wp_get_attachment_metadata() |
|
710 * |
|
711 * @param string $html HTML markup for a media item sent to the editor. |
|
712 * @param int $send_id The first key from the $_POST['send'] data. |
|
713 * @param array $attachment Array of attachment metadata. |
|
714 */ |
|
715 $html = apply_filters( 'media_send_to_editor', $html, $send_id, $attachment ); |
565 return media_send_to_editor($html); |
716 return media_send_to_editor($html); |
566 } |
717 } |
567 |
718 |
568 return $errors; |
719 return $errors; |
569 } |
720 } |
606 $type = 'file'; |
757 $type = 'file'; |
607 if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) ) |
758 if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) ) |
608 && ( 'audio' == $ext_type || 'video' == $ext_type ) ) |
759 && ( 'audio' == $ext_type || 'video' == $ext_type ) ) |
609 $type = $ext_type; |
760 $type = $ext_type; |
610 |
761 |
|
762 /** |
|
763 * Filter the URL sent to the editor for a specific media type. |
|
764 * |
|
765 * The dynamic portion of the hook name, `$type`, refers to the type |
|
766 * of media being sent. |
|
767 * |
|
768 * @since 3.3.0 |
|
769 * |
|
770 * @param string $html HTML markup sent to the editor. |
|
771 * @param string $src Media source URL. |
|
772 * @param string $title Media title. |
|
773 */ |
611 $html = apply_filters( $type . '_send_to_editor_url', $html, esc_url_raw( $src ), $title ); |
774 $html = apply_filters( $type . '_send_to_editor_url', $html, esc_url_raw( $src ), $title ); |
612 } else { |
775 } else { |
613 $align = ''; |
776 $align = ''; |
614 $alt = esc_attr( wp_unslash( $_POST['alt'] ) ); |
777 $alt = esc_attr( wp_unslash( $_POST['alt'] ) ); |
615 if ( isset($_POST['align']) ) { |
778 if ( isset($_POST['align']) ) { |
617 $class = " class='align$align'"; |
780 $class = " class='align$align'"; |
618 } |
781 } |
619 if ( !empty($src) ) |
782 if ( !empty($src) ) |
620 $html = "<img src='" . esc_url($src) . "' alt='$alt'$class />"; |
783 $html = "<img src='" . esc_url($src) . "' alt='$alt'$class />"; |
621 |
784 |
|
785 /** |
|
786 * Filter the image URL sent to the editor. |
|
787 * |
|
788 * @since 2.8.0 |
|
789 * |
|
790 * @param string $html HTML markup sent to the editor for an image. |
|
791 * @param string $src Image source URL. |
|
792 * @param string $alt Image alternate, or alt, text. |
|
793 * @param string $align The image alignment. Default 'alignnone'. Possible values include |
|
794 * 'alignleft', 'aligncenter', 'alignright', 'alignnone'. |
|
795 */ |
622 $html = apply_filters( 'image_send_to_editor_url', $html, esc_url_raw( $src ), $alt, $align ); |
796 $html = apply_filters( 'image_send_to_editor_url', $html, esc_url_raw( $src ), $alt, $align ); |
623 } |
797 } |
624 |
798 |
625 return media_send_to_editor($html); |
799 return media_send_to_editor($html); |
626 } |
800 } |
627 |
801 |
628 if ( !empty($_POST) ) { |
802 if ( isset( $_POST['save'] ) ) { |
|
803 $errors['upload_notice'] = __('Saved.'); |
|
804 return media_upload_gallery(); |
|
805 } elseif ( ! empty( $_POST ) ) { |
629 $return = media_upload_form_handler(); |
806 $return = media_upload_form_handler(); |
630 |
807 |
631 if ( is_string($return) ) |
808 if ( is_string($return) ) |
632 return $return; |
809 return $return; |
633 if ( is_array($return) ) |
810 if ( is_array($return) ) |
634 $errors = $return; |
811 $errors = $return; |
635 } |
|
636 |
|
637 if ( isset($_POST['save']) ) { |
|
638 $errors['upload_notice'] = __('Saved.'); |
|
639 return media_upload_gallery(); |
|
640 } |
812 } |
641 |
813 |
642 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) { |
814 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) { |
643 $type = 'image'; |
815 $type = 'image'; |
644 if ( isset( $_GET['type'] ) && in_array( $_GET['type'], array( 'video', 'audio', 'file' ) ) ) |
816 if ( isset( $_GET['type'] ) && in_array( $_GET['type'], array( 'video', 'audio', 'file' ) ) ) |
655 * @since 2.6.0 |
827 * @since 2.6.0 |
656 * |
828 * |
657 * @param string $file The URL of the image to download |
829 * @param string $file The URL of the image to download |
658 * @param int $post_id The post ID the media is to be associated with |
830 * @param int $post_id The post ID the media is to be associated with |
659 * @param string $desc Optional. Description of the image |
831 * @param string $desc Optional. Description of the image |
|
832 * @param string $return Optional. What to return: an image tag (default) or only the src. |
660 * @return string|WP_Error Populated HTML img tag on success |
833 * @return string|WP_Error Populated HTML img tag on success |
661 */ |
834 */ |
662 function media_sideload_image($file, $post_id, $desc = null) { |
835 function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) { |
663 if ( ! empty($file) ) { |
836 if ( ! empty( $file ) ) { |
664 // Download file to temp location |
837 // Set variables for storage, fix file filename for query strings. |
665 $tmp = download_url( $file ); |
|
666 |
|
667 // Set variables for storage |
|
668 // fix file filename for query strings |
|
669 preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches ); |
838 preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches ); |
670 $file_array['name'] = basename($matches[0]); |
839 $file_array = array(); |
671 $file_array['tmp_name'] = $tmp; |
840 $file_array['name'] = basename( $matches[0] ); |
672 |
841 |
673 // If error storing temporarily, unlink |
842 // Download file to temp location. |
674 if ( is_wp_error( $tmp ) ) { |
843 $file_array['tmp_name'] = download_url( $file ); |
675 @unlink($file_array['tmp_name']); |
844 |
676 $file_array['tmp_name'] = ''; |
845 // If error storing temporarily, return the error. |
677 } |
846 if ( is_wp_error( $file_array['tmp_name'] ) ) { |
678 |
847 return $file_array['tmp_name']; |
679 // do the validation and storage stuff |
848 } |
|
849 |
|
850 // Do the validation and storage stuff. |
680 $id = media_handle_sideload( $file_array, $post_id, $desc ); |
851 $id = media_handle_sideload( $file_array, $post_id, $desc ); |
681 // If error storing permanently, unlink |
852 |
682 if ( is_wp_error($id) ) { |
853 // If error storing permanently, unlink. |
683 @unlink($file_array['tmp_name']); |
854 if ( is_wp_error( $id ) ) { |
|
855 @unlink( $file_array['tmp_name'] ); |
684 return $id; |
856 return $id; |
685 } |
857 } |
686 |
858 |
687 $src = wp_get_attachment_url( $id ); |
859 $src = wp_get_attachment_url( $id ); |
688 } |
860 } |
689 |
861 |
690 // Finally check to make sure the file has been saved, then return the html |
862 // Finally check to make sure the file has been saved, then return the HTML. |
691 if ( ! empty($src) ) { |
863 if ( ! empty( $src ) ) { |
692 $alt = isset($desc) ? esc_attr($desc) : ''; |
864 if ( $return === 'src' ) { |
|
865 return $src; |
|
866 } |
|
867 |
|
868 $alt = isset( $desc ) ? esc_attr( $desc ) : ''; |
693 $html = "<img src='$src' alt='$alt' />"; |
869 $html = "<img src='$src' alt='$alt' />"; |
694 return $html; |
870 return $html; |
|
871 } else { |
|
872 return new WP_Error( 'image_sideload_failed' ); |
695 } |
873 } |
696 } |
874 } |
697 |
875 |
698 /** |
876 /** |
699 * {@internal Missing Short Description}} |
877 * {@internal Missing Short Description}} |
700 * |
878 * |
701 * @since 2.5.0 |
879 * @since 2.5.0 |
702 * |
880 * |
703 * @return unknown |
881 * @return string|null |
704 */ |
882 */ |
705 function media_upload_gallery() { |
883 function media_upload_gallery() { |
706 $errors = array(); |
884 $errors = array(); |
707 |
885 |
708 if ( !empty($_POST) ) { |
886 if ( !empty($_POST) ) { |
759 |
937 |
760 $out = array(); |
938 $out = array(); |
761 foreach ( $alignments as $name => $label ) { |
939 foreach ( $alignments as $name => $label ) { |
762 $name = esc_attr($name); |
940 $name = esc_attr($name); |
763 $out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'". |
941 $out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'". |
764 ( $checked == $name ? " checked='checked'" : "" ) . |
942 ( $checked == $name ? " checked='checked'" : "" ) . |
765 " /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>$label</label>"; |
943 " /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>$label</label>"; |
766 } |
944 } |
767 return join("\n", $out); |
945 return join("\n", $out); |
768 } |
946 } |
769 |
947 |
770 /** |
948 /** |
771 * Retrieve HTML for the size radio buttons with the specified one checked. |
949 * Retrieve HTML for the size radio buttons with the specified one checked. |
772 * |
950 * |
773 * @since 2.7.0 |
951 * @since 2.7.0 |
774 * |
952 * |
775 * @param object $post |
953 * @param WP_Post $post |
776 * @param bool|string $check |
954 * @param bool|string $check |
777 * @return array |
955 * @return array |
778 */ |
956 */ |
779 function image_size_input_fields( $post, $check = '' ) { |
957 function image_size_input_fields( $post, $check = '' ) { |
780 |
958 /** |
781 // get a list of the actual pixel dimensions of each possible intermediate version of this image |
959 * Filter the names and labels of the default image sizes. |
782 $size_names = apply_filters( 'image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')) ); |
960 * |
783 |
961 * @since 3.3.0 |
784 if ( empty($check) ) |
962 * |
785 $check = get_user_setting('imgsize', 'medium'); |
963 * @param array $size_names Array of image sizes and their names. Default values |
786 |
964 * include 'Thumbnail', 'Medium', 'Large', 'Full Size'. |
787 foreach ( $size_names as $size => $label ) { |
965 */ |
788 $downsize = image_downsize($post->ID, $size); |
966 $size_names = apply_filters( 'image_size_names_choose', array( |
789 $checked = ''; |
967 'thumbnail' => __( 'Thumbnail' ), |
790 |
968 'medium' => __( 'Medium' ), |
791 // is this size selectable? |
969 'large' => __( 'Large' ), |
792 $enabled = ( $downsize[3] || 'full' == $size ); |
970 'full' => __( 'Full Size' ) |
793 $css_id = "image-size-{$size}-{$post->ID}"; |
971 ) ); |
794 // if this size is the default but that's not available, don't select it |
972 |
795 if ( $size == $check ) { |
973 if ( empty( $check ) ) { |
796 if ( $enabled ) |
974 $check = get_user_setting('imgsize', 'medium'); |
797 $checked = " checked='checked'"; |
975 } |
798 else |
976 $out = array(); |
799 $check = ''; |
977 |
800 } elseif ( !$check && $enabled && 'thumbnail' != $size ) { |
978 foreach ( $size_names as $size => $label ) { |
801 // if $check is not enabled, default to the first available size that's bigger than a thumbnail |
979 $downsize = image_downsize( $post->ID, $size ); |
802 $check = $size; |
980 $checked = ''; |
|
981 |
|
982 // Is this size selectable? |
|
983 $enabled = ( $downsize[3] || 'full' == $size ); |
|
984 $css_id = "image-size-{$size}-{$post->ID}"; |
|
985 |
|
986 // If this size is the default but that's not available, don't select it. |
|
987 if ( $size == $check ) { |
|
988 if ( $enabled ) { |
803 $checked = " checked='checked'"; |
989 $checked = " checked='checked'"; |
|
990 } else { |
|
991 $check = ''; |
804 } |
992 } |
805 |
993 } elseif ( ! $check && $enabled && 'thumbnail' != $size ) { |
806 $html = "<div class='image-size-item'><input type='radio' " . disabled( $enabled, false, false ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />"; |
994 /* |
807 |
995 * If $check is not enabled, default to the first available size |
808 $html .= "<label for='{$css_id}'>$label</label>"; |
996 * that's bigger than a thumbnail. |
809 // only show the dimensions if that choice is available |
997 */ |
810 if ( $enabled ) |
998 $check = $size; |
811 $html .= " <label for='{$css_id}' class='help'>" . sprintf( "(%d × %d)", $downsize[1], $downsize[2] ). "</label>"; |
999 $checked = " checked='checked'"; |
812 |
1000 } |
813 $html .= '</div>'; |
1001 |
814 |
1002 $html = "<div class='image-size-item'><input type='radio' " . disabled( $enabled, false, false ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />"; |
815 $out[] = $html; |
1003 |
816 } |
1004 $html .= "<label for='{$css_id}'>$label</label>"; |
817 |
1005 |
818 return array( |
1006 // Only show the dimensions if that choice is available. |
819 'label' => __('Size'), |
1007 if ( $enabled ) { |
820 'input' => 'html', |
1008 $html .= " <label for='{$css_id}' class='help'>" . sprintf( "(%d × %d)", $downsize[1], $downsize[2] ). "</label>"; |
821 'html' => join("\n", $out), |
1009 } |
822 ); |
1010 $html .= '</div>'; |
|
1011 |
|
1012 $out[] = $html; |
|
1013 } |
|
1014 |
|
1015 return array( |
|
1016 'label' => __( 'Size' ), |
|
1017 'input' => 'html', |
|
1018 'html' => join( "\n", $out ), |
|
1019 ); |
823 } |
1020 } |
824 |
1021 |
825 /** |
1022 /** |
826 * Retrieve HTML for the Link URL buttons with the default link type as specified. |
1023 * Retrieve HTML for the Link URL buttons with the default link type as specified. |
827 * |
1024 * |
828 * @since 2.7.0 |
1025 * @since 2.7.0 |
829 * |
1026 * |
830 * @param object $post |
1027 * @param WP_Post $post |
831 * @param string $url_type |
1028 * @param string $url_type |
832 * @return string |
1029 * @return string |
833 */ |
1030 */ |
834 function image_link_input_fields($post, $url_type = '') { |
1031 function image_link_input_fields($post, $url_type = '') { |
835 |
1032 |
908 * Illustrates the use of the attachment_fields_to_save filter |
1105 * Illustrates the use of the attachment_fields_to_save filter |
909 * which can be used to add default values to any field before saving to DB. |
1106 * which can be used to add default values to any field before saving to DB. |
910 * |
1107 * |
911 * @since 2.5.0 |
1108 * @since 2.5.0 |
912 * |
1109 * |
913 * @param object $post |
1110 * @param array $post The WP_Post attachment object converted to an array. |
914 * @param array $attachment {@internal $attachment not used}} |
1111 * @param array $attachment An array of attachment metadata. |
915 * @return array |
1112 * @return array Filtered attachment post object. |
916 */ |
1113 */ |
917 function image_attachment_fields_to_save( $post, $attachment ) { |
1114 function image_attachment_fields_to_save( $post, $attachment ) { |
918 if ( substr( $post['post_mime_type'], 0, 5 ) == 'image' ) { |
1115 if ( substr( $post['post_mime_type'], 0, 5 ) == 'image' ) { |
919 if ( strlen( trim( $post['post_title'] ) ) == 0 ) { |
1116 if ( strlen( trim( $post['post_title'] ) ) == 0 ) { |
920 $attachment_url = ( isset( $post['attachment_url'] ) ) ? $post['attachment_url'] : $post['guid']; |
1117 $attachment_url = ( isset( $post['attachment_url'] ) ) ? $post['attachment_url'] : $post['guid']; |
1122 $thumb_url = false; |
1327 $thumb_url = false; |
1123 |
1328 |
1124 $post = get_post( $attachment_id ); |
1329 $post = get_post( $attachment_id ); |
1125 $current_post_id = !empty( $_GET['post_id'] ) ? (int) $_GET['post_id'] : 0; |
1330 $current_post_id = !empty( $_GET['post_id'] ) ? (int) $_GET['post_id'] : 0; |
1126 |
1331 |
1127 $default_args = array( 'errors' => null, 'send' => $current_post_id ? post_type_supports( get_post_type( $current_post_id ), 'editor' ) : true, 'delete' => true, 'toggle' => true, 'show_title' => true ); |
1332 $default_args = array( |
|
1333 'errors' => null, |
|
1334 'send' => $current_post_id ? post_type_supports( get_post_type( $current_post_id ), 'editor' ) : true, |
|
1335 'delete' => true, |
|
1336 'toggle' => true, |
|
1337 'show_title' => true |
|
1338 ); |
1128 $args = wp_parse_args( $args, $default_args ); |
1339 $args = wp_parse_args( $args, $default_args ); |
1129 $args = apply_filters( 'get_media_item_args', $args ); |
1340 |
1130 extract( $args, EXTR_SKIP ); |
1341 /** |
|
1342 * Filter the arguments used to retrieve an image for the edit image form. |
|
1343 * |
|
1344 * @since 3.1.0 |
|
1345 * |
|
1346 * @see get_media_item |
|
1347 * |
|
1348 * @param array $args An array of arguments. |
|
1349 */ |
|
1350 $r = apply_filters( 'get_media_item_args', $args ); |
1131 |
1351 |
1132 $toggle_on = __( 'Show' ); |
1352 $toggle_on = __( 'Show' ); |
1133 $toggle_off = __( 'Hide' ); |
1353 $toggle_off = __( 'Hide' ); |
1134 |
1354 |
1135 $filename = esc_html( wp_basename( $post->guid ) ); |
1355 $filename = esc_html( wp_basename( $post->guid ) ); |
1136 $title = esc_attr( $post->post_title ); |
1356 $title = esc_attr( $post->post_title ); |
1137 |
1357 |
1138 if ( $_tags = get_the_tags( $attachment_id ) ) { |
|
1139 foreach ( $_tags as $tag ) |
|
1140 $tags[] = $tag->name; |
|
1141 $tags = esc_attr( join( ', ', $tags ) ); |
|
1142 } |
|
1143 |
|
1144 $post_mime_types = get_post_mime_types(); |
1358 $post_mime_types = get_post_mime_types(); |
1145 $keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) ); |
1359 $keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) ); |
1146 $type = array_shift( $keys ); |
1360 $type = reset( $keys ); |
1147 $type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />"; |
1361 $type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />"; |
1148 |
1362 |
1149 $form_fields = get_attachment_fields_to_edit( $post, $errors ); |
1363 $form_fields = get_attachment_fields_to_edit( $post, $r['errors'] ); |
1150 |
1364 |
1151 if ( $toggle ) { |
1365 if ( $r['toggle'] ) { |
1152 $class = empty( $errors ) ? 'startclosed' : 'startopen'; |
1366 $class = empty( $r['errors'] ) ? 'startclosed' : 'startopen'; |
1153 $toggle_links = " |
1367 $toggle_links = " |
1154 <a class='toggle describe-toggle-on' href='#'>$toggle_on</a> |
1368 <a class='toggle describe-toggle-on' href='#'>$toggle_on</a> |
1155 <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>"; |
1369 <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>"; |
1156 } else { |
1370 } else { |
1157 $class = ''; |
1371 $class = ''; |
1158 $toggle_links = ''; |
1372 $toggle_links = ''; |
1159 } |
1373 } |
1160 |
1374 |
1161 $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case |
1375 $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case |
1162 $display_title = $show_title ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60, '…' ) . "</span></div>" : ''; |
1376 $display_title = $r['show_title'] ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60, '…' ) . "</span></div>" : ''; |
1163 |
1377 |
1164 $gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' == $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' == $redir_tab ) ); |
1378 $gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' == $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' == $redir_tab ) ); |
1165 $order = ''; |
1379 $order = ''; |
1166 |
1380 |
1167 foreach ( $form_fields as $key => $val ) { |
1381 foreach ( $form_fields as $key => $val ) { |
1178 |
1392 |
1179 $media_dims = ''; |
1393 $media_dims = ''; |
1180 $meta = wp_get_attachment_metadata( $post->ID ); |
1394 $meta = wp_get_attachment_metadata( $post->ID ); |
1181 if ( isset( $meta['width'], $meta['height'] ) ) |
1395 if ( isset( $meta['width'], $meta['height'] ) ) |
1182 $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> "; |
1396 $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> "; |
|
1397 |
|
1398 /** |
|
1399 * Filter the media metadata. |
|
1400 * |
|
1401 * @since 2.5.0 |
|
1402 * |
|
1403 * @param string $media_dims The HTML markup containing the media dimensions. |
|
1404 * @param WP_Post $post The WP_Post attachment object. |
|
1405 */ |
1183 $media_dims = apply_filters( 'media_meta', $media_dims, $post ); |
1406 $media_dims = apply_filters( 'media_meta', $media_dims, $post ); |
1184 |
1407 |
1185 $image_edit_button = ''; |
1408 $image_edit_button = ''; |
1186 if ( wp_attachment_is_image( $post->ID ) && wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { |
1409 if ( wp_attachment_is_image( $post->ID ) && wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { |
1187 $nonce = wp_create_nonce( "image_editor-$post->ID" ); |
1410 $nonce = wp_create_nonce( "image_editor-$post->ID" ); |
1222 'required' => false, |
1445 'required' => false, |
1223 'value' => '', |
1446 'value' => '', |
1224 'extra_rows' => array(), |
1447 'extra_rows' => array(), |
1225 ); |
1448 ); |
1226 |
1449 |
1227 if ( $send ) |
1450 if ( $r['send'] ) { |
1228 $send = get_submit_button( __( 'Insert into Post' ), 'button', "send[$attachment_id]", false ); |
1451 $r['send'] = get_submit_button( __( 'Insert into Post' ), 'button', "send[$attachment_id]", false ); |
|
1452 } |
|
1453 |
|
1454 $delete = empty( $r['delete'] ) ? '' : $r['delete']; |
1229 if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) { |
1455 if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) { |
1230 if ( !EMPTY_TRASH_DAYS ) { |
1456 if ( !EMPTY_TRASH_DAYS ) { |
1231 $delete = "<a href='" . wp_nonce_url( "post.php?action=delete&post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete-permanently'>" . __( 'Delete Permanently' ) . '</a>'; |
1457 $delete = "<a href='" . wp_nonce_url( "post.php?action=delete&post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete-permanently'>" . __( 'Delete Permanently' ) . '</a>'; |
1232 } elseif ( !MEDIA_TRASH ) { |
1458 } elseif ( !MEDIA_TRASH ) { |
1233 $delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a> |
1459 $delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a> |
1243 $delete = ''; |
1469 $delete = ''; |
1244 } |
1470 } |
1245 |
1471 |
1246 $thumbnail = ''; |
1472 $thumbnail = ''; |
1247 $calling_post_id = 0; |
1473 $calling_post_id = 0; |
1248 if ( isset( $_GET['post_id'] ) ) |
1474 if ( isset( $_GET['post_id'] ) ) { |
1249 $calling_post_id = absint( $_GET['post_id'] ); |
1475 $calling_post_id = absint( $_GET['post_id'] ); |
1250 elseif ( isset( $_POST ) && count( $_POST ) ) // Like for async-upload where $_GET['post_id'] isn't set |
1476 } elseif ( isset( $_POST ) && count( $_POST ) ) {// Like for async-upload where $_GET['post_id'] isn't set |
1251 $calling_post_id = $post->post_parent; |
1477 $calling_post_id = $post->post_parent; |
|
1478 } |
1252 if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) ) |
1479 if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) ) |
1253 && post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) { |
1480 && post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) { |
1254 $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" ); |
1481 $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" ); |
1255 $thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;'>" . esc_html__( "Use as featured image" ) . "</a>"; |
1482 $thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;'>" . esc_html__( "Use as featured image" ) . "</a>"; |
1256 } |
1483 } |
1257 |
1484 |
1258 if ( ( $send || $thumbnail || $delete ) && !isset( $form_fields['buttons'] ) ) |
1485 if ( ( $r['send'] || $thumbnail || $delete ) && !isset( $form_fields['buttons'] ) ) { |
1259 $form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $thumbnail $delete</td></tr>\n" ); |
1486 $form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>" . $r['send'] . " $thumbnail $delete</td></tr>\n" ); |
1260 |
1487 } |
1261 $hidden_fields = array(); |
1488 $hidden_fields = array(); |
1262 |
1489 |
1263 foreach ( $form_fields as $id => $field ) { |
1490 foreach ( $form_fields as $id => $field ) { |
1264 if ( $id[0] == '_' ) |
1491 if ( $id[0] == '_' ) |
1265 continue; |
1492 continue; |
1280 $required = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : ''; |
1507 $required = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : ''; |
1281 $aria_required = $field['required'] ? " aria-required='true' " : ''; |
1508 $aria_required = $field['required'] ? " aria-required='true' " : ''; |
1282 $class = $id; |
1509 $class = $id; |
1283 $class .= $field['required'] ? ' form-required' : ''; |
1510 $class .= $field['required'] ? ' form-required' : ''; |
1284 |
1511 |
1285 $item .= "\t\t<tr class='$class'>\n\t\t\t<th valign='top' scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label></th>\n\t\t\t<td class='field'>"; |
1512 $item .= "\t\t<tr class='$class'>\n\t\t\t<th scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label></th>\n\t\t\t<td class='field'>"; |
1286 if ( !empty( $field[ $field['input'] ] ) ) |
1513 if ( !empty( $field[ $field['input'] ] ) ) |
1287 $item .= $field[ $field['input'] ]; |
1514 $item .= $field[ $field['input'] ]; |
1288 elseif ( $field['input'] == 'textarea' ) { |
1515 elseif ( $field['input'] == 'textarea' ) { |
1289 if ( 'post_content' == $id && user_can_richedit() ) { |
1516 if ( 'post_content' == $id && user_can_richedit() ) { |
1290 // sanitize_post() skips the post_content when user_can_richedit |
1517 // Sanitize_post() skips the post_content when user_can_richedit. |
1291 $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES ); |
1518 $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES ); |
1292 } |
1519 } |
1293 // post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit() |
1520 // Post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit(). |
1294 $item .= "<textarea id='$name' name='$name' $aria_required>" . $field['value'] . '</textarea>'; |
1521 $item .= "<textarea id='$name' name='$name' $aria_required>" . $field['value'] . '</textarea>'; |
1295 } else { |
1522 } else { |
1296 $item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "' $aria_required />"; |
1523 $item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "' $aria_required />"; |
1297 } |
1524 } |
1298 if ( !empty( $field['helps'] ) ) |
1525 if ( !empty( $field['helps'] ) ) |
1374 |
1603 |
1375 // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default |
1604 // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default |
1376 // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing ) |
1605 // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing ) |
1377 $form_fields = array_merge_recursive($form_fields, (array) $args['errors'] ); |
1606 $form_fields = array_merge_recursive($form_fields, (array) $args['errors'] ); |
1378 |
1607 |
|
1608 /** This filter is documented in wp-admin/includes/media.php */ |
1379 $form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post ); |
1609 $form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post ); |
1380 |
1610 |
1381 unset( $form_fields['image-size'], $form_fields['align'], $form_fields['image_alt'], |
1611 unset( $form_fields['image-size'], $form_fields['align'], $form_fields['image_alt'], |
1382 $form_fields['post_title'], $form_fields['post_excerpt'], $form_fields['post_content'], |
1612 $form_fields['post_title'], $form_fields['post_excerpt'], $form_fields['post_content'], |
1383 $form_fields['url'], $form_fields['menu_order'], $form_fields['image_url'] ); |
1613 $form_fields['url'], $form_fields['menu_order'], $form_fields['image_url'] ); |
1384 |
1614 |
|
1615 /** This filter is documented in wp-admin/includes/media.php */ |
1385 $media_meta = apply_filters( 'media_meta', '', $post ); |
1616 $media_meta = apply_filters( 'media_meta', '', $post ); |
1386 |
1617 |
1387 $defaults = array( |
1618 $defaults = array( |
1388 'input' => 'text', |
1619 'input' => 'text', |
1389 'required' => false, |
1620 'required' => false, |
1390 'value' => '', |
1621 'value' => '', |
1391 'extra_rows' => array(), |
1622 'extra_rows' => array(), |
1392 'show_in_edit' => true, |
1623 'show_in_edit' => true, |
1393 'show_in_modal' => true, |
1624 'show_in_modal' => true, |
1394 ); |
1625 ); |
1395 |
1626 |
1396 $hidden_fields = array(); |
1627 $hidden_fields = array(); |
1397 |
1628 |
1398 $item = ''; |
1629 $item = ''; |
1423 $aria_required = $field['required'] ? " aria-required='true' " : ''; |
1654 $aria_required = $field['required'] ? " aria-required='true' " : ''; |
1424 $class = 'compat-field-' . $id; |
1655 $class = 'compat-field-' . $id; |
1425 $class .= $field['required'] ? ' form-required' : ''; |
1656 $class .= $field['required'] ? ' form-required' : ''; |
1426 |
1657 |
1427 $item .= "\t\t<tr class='$class'>"; |
1658 $item .= "\t\t<tr class='$class'>"; |
1428 $item .= "\t\t\t<th valign='top' scope='row' class='label'><label for='$id_attr'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label>"; |
1659 $item .= "\t\t\t<th scope='row' class='label'><label for='$id_attr'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label>"; |
1429 $item .= "</th>\n\t\t\t<td class='field'>"; |
1660 $item .= "</th>\n\t\t\t<td class='field'>"; |
1430 |
1661 |
1431 if ( !empty( $field[ $field['input'] ] ) ) |
1662 if ( !empty( $field[ $field['input'] ] ) ) |
1432 $item .= $field[ $field['input'] ]; |
1663 $item .= $field[ $field['input'] ]; |
1433 elseif ( $field['input'] == 'textarea' ) { |
1664 elseif ( $field['input'] == 'textarea' ) { |
1434 if ( 'post_content' == $id && user_can_richedit() ) { |
1665 if ( 'post_content' == $id && user_can_richedit() ) { |
1435 // sanitize_post() skips the post_content when user_can_richedit |
1666 // sanitize_post() skips the post_content when user_can_richedit. |
1436 $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES ); |
1667 $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES ); |
1437 } |
1668 } |
1438 $item .= "<textarea id='$id_attr' name='$name' $aria_required>" . $field['value'] . '</textarea>'; |
1669 $item .= "<textarea id='$id_attr' name='$name' $aria_required>" . $field['value'] . '</textarea>'; |
1439 } else { |
1670 } else { |
1440 $item .= "<input type='text' class='text' id='$id_attr' name='$name' value='" . esc_attr( $field['value'] ) . "' $readonly $aria_required />"; |
1671 $item .= "<input type='text' class='text' id='$id_attr' name='$name' value='" . esc_attr( $field['value'] ) . "' $readonly $aria_required />"; |
1495 /** |
1726 /** |
1496 * {@internal Missing Short Description}} |
1727 * {@internal Missing Short Description}} |
1497 * |
1728 * |
1498 * @since 2.5.0 |
1729 * @since 2.5.0 |
1499 * |
1730 * |
1500 * @param unknown_type $errors |
1731 * @param array $errors |
1501 */ |
1732 */ |
1502 function media_upload_form( $errors = null ) { |
1733 function media_upload_form( $errors = null ) { |
1503 global $type, $tab, $is_IE, $is_opera; |
1734 global $type, $tab, $is_IE, $is_opera; |
1504 |
1735 |
1505 if ( ! _device_can_upload() ) { |
1736 if ( ! _device_can_upload() ) { |
1506 echo '<p>' . sprintf( __('The web browser on your device cannot be used to upload files. You may be able to use the <a href="%s">native app for your device</a> instead.'), 'http://wordpress.org/mobile/' ) . '</p>'; |
1737 echo '<p>' . sprintf( __('The web browser on your device cannot be used to upload files. You may be able to use the <a href="%s">native app for your device</a> instead.'), 'https://apps.wordpress.org/' ) . '</p>'; |
1507 return; |
1738 return; |
1508 } |
1739 } |
1509 |
1740 |
1510 $upload_action_url = admin_url('async-upload.php'); |
1741 $upload_action_url = admin_url('async-upload.php'); |
1511 $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0; |
1742 $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0; |
1512 $_type = isset($type) ? $type : ''; |
1743 $_type = isset($type) ? $type : ''; |
1513 $_tab = isset($tab) ? $tab : ''; |
1744 $_tab = isset($tab) ? $tab : ''; |
1514 |
1745 |
1515 $upload_size_unit = $max_upload_size = wp_max_upload_size(); |
1746 $max_upload_size = wp_max_upload_size(); |
1516 $sizes = array( 'KB', 'MB', 'GB' ); |
1747 if ( ! $max_upload_size ) { |
1517 |
1748 $max_upload_size = 0; |
1518 for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { |
|
1519 $upload_size_unit /= 1024; |
|
1520 } |
|
1521 |
|
1522 if ( $u < 0 ) { |
|
1523 $upload_size_unit = 0; |
|
1524 $u = 0; |
|
1525 } else { |
|
1526 $upload_size_unit = (int) $upload_size_unit; |
|
1527 } |
1749 } |
1528 ?> |
1750 ?> |
1529 |
1751 |
1530 <div id="media-upload-notice"><?php |
1752 <div id="media-upload-notice"><?php |
1531 |
1753 |
1539 echo $errors['upload_error']->get_error_message(); |
1761 echo $errors['upload_error']->get_error_message(); |
1540 |
1762 |
1541 ?></div> |
1763 ?></div> |
1542 <?php |
1764 <?php |
1543 if ( is_multisite() && !is_upload_space_available() ) { |
1765 if ( is_multisite() && !is_upload_space_available() ) { |
|
1766 /** |
|
1767 * Fires when an upload will exceed the defined upload space quota for a network site. |
|
1768 * |
|
1769 * @since 3.5.0 |
|
1770 */ |
1544 do_action( 'upload_ui_over_quota' ); |
1771 do_action( 'upload_ui_over_quota' ); |
1545 return; |
1772 return; |
1546 } |
1773 } |
1547 |
1774 |
1548 do_action('pre-upload-ui'); |
1775 /** |
|
1776 * Fires just before the legacy (pre-3.5.0) upload interface is loaded. |
|
1777 * |
|
1778 * @since 2.6.0 |
|
1779 */ |
|
1780 do_action( 'pre-upload-ui' ); |
1549 |
1781 |
1550 $post_params = array( |
1782 $post_params = array( |
1551 "post_id" => $post_id, |
1783 "post_id" => $post_id, |
1552 "_wpnonce" => wp_create_nonce('media-form'), |
1784 "_wpnonce" => wp_create_nonce('media-form'), |
1553 "type" => $_type, |
1785 "type" => $_type, |
1554 "tab" => $_tab, |
1786 "tab" => $_tab, |
1555 "short" => "1", |
1787 "short" => "1", |
1556 ); |
1788 ); |
1557 |
1789 |
1558 $post_params = apply_filters( 'upload_post_params', $post_params ); // hook change! old name: 'swfupload_post_params' |
1790 /** |
|
1791 * Filter the media upload post parameters. |
|
1792 * |
|
1793 * @since 3.1.0 As 'swfupload_post_params' |
|
1794 * @since 3.3.0 |
|
1795 * |
|
1796 * @param array $post_params An array of media upload parameters used by Plupload. |
|
1797 */ |
|
1798 $post_params = apply_filters( 'upload_post_params', $post_params ); |
1559 |
1799 |
1560 $plupload_init = array( |
1800 $plupload_init = array( |
1561 'runtimes' => 'html5,silverlight,flash,html4', |
1801 'runtimes' => 'html5,flash,silverlight,html4', |
1562 'browse_button' => 'plupload-browse-button', |
1802 'browse_button' => 'plupload-browse-button', |
1563 'container' => 'plupload-upload-ui', |
1803 'container' => 'plupload-upload-ui', |
1564 'drop_element' => 'drag-drop-area', |
1804 'drop_element' => 'drag-drop-area', |
1565 'file_data_name' => 'async-upload', |
1805 'file_data_name' => 'async-upload', |
1566 'multiple_queues' => true, |
1806 'url' => $upload_action_url, |
1567 'max_file_size' => $max_upload_size . 'b', |
1807 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ), |
1568 'url' => $upload_action_url, |
1808 'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ), |
1569 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'), |
1809 'filters' => array( |
1570 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'), |
1810 'max_file_size' => $max_upload_size . 'b', |
1571 'filters' => array( array('title' => __( 'Allowed Files' ), 'extensions' => '*') ), |
1811 ), |
1572 'multipart' => true, |
1812 'multipart_params' => $post_params, |
1573 'urlstream_upload' => true, |
|
1574 'multipart_params' => $post_params |
|
1575 ); |
1813 ); |
1576 |
1814 |
1577 // Multi-file uploading doesn't currently work in iOS Safari, |
1815 // Currently only iOS Safari supports multiple files uploading but iOS 7.x has a bug that prevents uploading of videos |
1578 // single-file allows the built-in camera to be used as source for images |
1816 // when enabled. See #29602. |
1579 if ( wp_is_mobile() ) |
1817 if ( wp_is_mobile() && strpos( $_SERVER['HTTP_USER_AGENT'], 'OS 7_' ) !== false && |
|
1818 strpos( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' ) !== false ) { |
|
1819 |
1580 $plupload_init['multi_selection'] = false; |
1820 $plupload_init['multi_selection'] = false; |
1581 |
1821 } |
|
1822 |
|
1823 /** |
|
1824 * Filter the default Plupload settings. |
|
1825 * |
|
1826 * @since 3.3.0 |
|
1827 * |
|
1828 * @param array $plupload_init An array of default settings used by Plupload. |
|
1829 */ |
1582 $plupload_init = apply_filters( 'plupload_init', $plupload_init ); |
1830 $plupload_init = apply_filters( 'plupload_init', $plupload_init ); |
1583 |
1831 |
1584 ?> |
1832 ?> |
1585 |
1833 |
1586 <script type="text/javascript"> |
1834 <script type="text/javascript"> |
1592 $large_size_w = absint( get_option('large_size_w') ); |
1840 $large_size_w = absint( get_option('large_size_w') ); |
1593 if( !$large_size_w ) |
1841 if( !$large_size_w ) |
1594 $large_size_w = 1024; |
1842 $large_size_w = 1024; |
1595 ?> |
1843 ?> |
1596 var resize_height = <?php echo $large_size_h; ?>, resize_width = <?php echo $large_size_w; ?>, |
1844 var resize_height = <?php echo $large_size_h; ?>, resize_width = <?php echo $large_size_w; ?>, |
1597 wpUploaderInit = <?php echo json_encode($plupload_init); ?>; |
1845 wpUploaderInit = <?php echo wp_json_encode( $plupload_init ); ?>; |
1598 </script> |
1846 </script> |
1599 |
1847 |
1600 <div id="plupload-upload-ui" class="hide-if-no-js"> |
1848 <div id="plupload-upload-ui" class="hide-if-no-js"> |
1601 <?php do_action('pre-plupload-upload-ui'); // hook change, old name: 'pre-flash-upload-ui' ?> |
1849 <?php |
|
1850 /** |
|
1851 * Fires before the upload interface loads. |
|
1852 * |
|
1853 * @since 2.6.0 As 'pre-flash-upload-ui' |
|
1854 * @since 3.3.0 |
|
1855 */ |
|
1856 do_action( 'pre-plupload-upload-ui' ); ?> |
1602 <div id="drag-drop-area"> |
1857 <div id="drag-drop-area"> |
1603 <div class="drag-drop-inside"> |
1858 <div class="drag-drop-inside"> |
1604 <p class="drag-drop-info"><?php _e('Drop files here'); ?></p> |
1859 <p class="drag-drop-info"><?php _e('Drop files here'); ?></p> |
1605 <p><?php _ex('or', 'Uploader: Drop files here - or - Select Files'); ?></p> |
1860 <p><?php _ex('or', 'Uploader: Drop files here - or - Select Files'); ?></p> |
1606 <p class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e('Select Files'); ?>" class="button" /></p> |
1861 <p class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e('Select Files'); ?>" class="button" /></p> |
1607 </div> |
1862 </div> |
1608 </div> |
1863 </div> |
1609 <?php do_action('post-plupload-upload-ui'); // hook change, old name: 'post-flash-upload-ui' ?> |
1864 <?php |
|
1865 /** |
|
1866 * Fires after the upload interface loads. |
|
1867 * |
|
1868 * @since 2.6.0 As 'post-flash-upload-ui' |
|
1869 * @since 3.3.0 |
|
1870 */ |
|
1871 do_action( 'post-plupload-upload-ui' ); ?> |
1610 </div> |
1872 </div> |
1611 |
1873 |
1612 <div id="html-upload-ui" class="hide-if-js"> |
1874 <div id="html-upload-ui" class="hide-if-js"> |
1613 <?php do_action('pre-html-upload-ui'); ?> |
1875 <?php |
|
1876 /** |
|
1877 * Fires before the upload button in the media upload interface. |
|
1878 * |
|
1879 * @since 2.6.0 |
|
1880 */ |
|
1881 do_action( 'pre-html-upload-ui' ); |
|
1882 ?> |
1614 <p id="async-upload-wrap"> |
1883 <p id="async-upload-wrap"> |
1615 <label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label> |
1884 <label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label> |
1616 <input type="file" name="async-upload" id="async-upload" /> |
1885 <input type="file" name="async-upload" id="async-upload" /> |
1617 <?php submit_button( __( 'Upload' ), 'button', 'html-upload', false ); ?> |
1886 <?php submit_button( __( 'Upload' ), 'button', 'html-upload', false ); ?> |
1618 <a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e('Cancel'); ?></a> |
1887 <a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e('Cancel'); ?></a> |
1619 </p> |
1888 </p> |
1620 <div class="clear"></div> |
1889 <div class="clear"></div> |
1621 <?php do_action('post-html-upload-ui'); ?> |
1890 <?php |
|
1891 /** |
|
1892 * Fires after the upload button in the media upload interface. |
|
1893 * |
|
1894 * @since 2.6.0 |
|
1895 */ |
|
1896 do_action( 'post-html-upload-ui' ); |
|
1897 ?> |
1622 </div> |
1898 </div> |
1623 |
1899 |
1624 <span class="max-upload-size"><?php printf( __( 'Maximum upload file size: %d%s.' ), esc_html($upload_size_unit), esc_html($sizes[$u]) ); ?></span> |
1900 <p class="max-upload-size"><?php printf( __( 'Maximum upload file size: %s.' ), esc_html( size_format( $max_upload_size ) ) ); ?></p> |
1625 <?php |
1901 <?php |
1626 if ( ($is_IE || $is_opera) && $max_upload_size > 100 * 1024 * 1024 ) { ?> |
1902 |
1627 <span class="big-file-warning"><?php _e('Your browser has some limitations uploading large files with the multi-file uploader. Please use the browser uploader for files over 100MB.'); ?></span> |
1903 /** |
1628 <?php } |
1904 * Fires on the post upload UI screen. |
1629 |
1905 * |
1630 do_action('post-upload-ui'); |
1906 * Legacy (pre-3.5.0) media workflow hook. |
|
1907 * |
|
1908 * @since 2.6.0 |
|
1909 */ |
|
1910 do_action( 'post-upload-ui' ); |
1631 } |
1911 } |
1632 |
1912 |
1633 /** |
1913 /** |
1634 * {@internal Missing Short Description}} |
1914 * {@internal Missing Short Description}} |
1635 * |
1915 * |
1644 media_upload_header(); |
1924 media_upload_header(); |
1645 |
1925 |
1646 $post_id = isset( $_REQUEST['post_id'] )? intval( $_REQUEST['post_id'] ) : 0; |
1926 $post_id = isset( $_REQUEST['post_id'] )? intval( $_REQUEST['post_id'] ) : 0; |
1647 |
1927 |
1648 $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id"); |
1928 $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id"); |
1649 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type); |
1929 |
|
1930 /** |
|
1931 * Filter the media upload form action URL. |
|
1932 * |
|
1933 * @since 2.6.0 |
|
1934 * |
|
1935 * @param string $form_action_url The media upload form action URL. |
|
1936 * @param string $type The type of media. Default 'file'. |
|
1937 */ |
|
1938 $form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type ); |
1650 $form_class = 'media-upload-form type-form validate'; |
1939 $form_class = 'media-upload-form type-form validate'; |
1651 |
1940 |
1652 if ( get_user_setting('uploader') ) |
1941 if ( get_user_setting('uploader') ) |
1653 $form_class .= ' html-uploader'; |
1942 $form_class .= ' html-uploader'; |
1654 ?> |
1943 ?> |
1739 return false; |
2026 return false; |
1740 |
2027 |
1741 if ( f.alt.value ) |
2028 if ( f.alt.value ) |
1742 alt = f.alt.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); |
2029 alt = f.alt.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); |
1743 |
2030 |
1744 <?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?> |
2031 <?php |
|
2032 /** This filter is documented in wp-admin/includes/media.php */ |
|
2033 if ( ! apply_filters( 'disable_captions', '' ) ) { |
|
2034 ?> |
1745 if ( f.caption.value ) { |
2035 if ( f.caption.value ) { |
1746 caption = f.caption.value.replace(/\r\n|\r/g, '\n'); |
2036 caption = f.caption.value.replace(/\r\n|\r/g, '\n'); |
1747 caption = caption.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){ |
2037 caption = caption.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){ |
1748 return a.replace(/[\r\n\t]+/, ' '); |
2038 return a.replace(/[\r\n\t]+/, ' '); |
1749 }); |
2039 }); |
1797 if ( ! src ) { |
2087 if ( ! src ) { |
1798 t.resetImageData(); |
2088 t.resetImageData(); |
1799 return false; |
2089 return false; |
1800 } |
2090 } |
1801 |
2091 |
1802 document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" width="16" />'; |
2092 document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/spinner-2x.gif' ) ); ?>" alt="" width="16" height="16" />'; |
1803 t.preloadImg = new Image(); |
2093 t.preloadImg = new Image(); |
1804 t.preloadImg.onload = t.updateImageData; |
2094 t.preloadImg.onload = t.updateImageData; |
1805 t.preloadImg.onerror = t.resetImageData; |
2095 t.preloadImg.onerror = t.resetImageData; |
1806 t.preloadImg.src = src; |
2096 t.preloadImg.src = src; |
1807 } |
2097 } |
1808 } |
2098 }; |
1809 |
2099 |
1810 jQuery(document).ready( function($) { |
2100 jQuery(document).ready( function($) { |
1811 $('.media-types input').click( function() { |
2101 $('.media-types input').click( function() { |
1812 $('table.describe').toggleClass('not-image', $('#not-image').prop('checked') ); |
2102 $('table.describe').toggleClass('not-image', $('#not-image').prop('checked') ); |
1813 }); |
2103 }); |
1814 }); |
2104 }); |
1815 |
|
1816 //]]> |
|
1817 </script> |
2105 </script> |
1818 |
2106 |
1819 <div id="media-items"> |
2107 <div id="media-items"> |
1820 <div class="media-item media-blank"> |
2108 <div class="media-item media-blank"> |
1821 <?php echo apply_filters( 'type_url_form_media', wp_media_insert_url_form( $type ) ); ?> |
2109 <?php |
|
2110 /** |
|
2111 * Filter the insert media from URL form HTML. |
|
2112 * |
|
2113 * @since 3.3.0 |
|
2114 * |
|
2115 * @param string $form_html The insert from URL form HTML. |
|
2116 */ |
|
2117 echo apply_filters( 'type_url_form_media', wp_media_insert_url_form( $type ) ); |
|
2118 ?> |
1822 </div> |
2119 </div> |
1823 </div> |
2120 </div> |
1824 </form> |
2121 </form> |
1825 <?php |
2122 <?php |
1826 } |
2123 } |
1838 $redir_tab = 'gallery'; |
2135 $redir_tab = 'gallery'; |
1839 media_upload_header(); |
2136 media_upload_header(); |
1840 |
2137 |
1841 $post_id = intval($_REQUEST['post_id']); |
2138 $post_id = intval($_REQUEST['post_id']); |
1842 $form_action_url = admin_url("media-upload.php?type=$type&tab=gallery&post_id=$post_id"); |
2139 $form_action_url = admin_url("media-upload.php?type=$type&tab=gallery&post_id=$post_id"); |
1843 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type); |
2140 /** This filter is documented in wp-admin/includes/media.php */ |
|
2141 $form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type ); |
1844 $form_class = 'media-upload-form validate'; |
2142 $form_class = 'media-upload-form validate'; |
1845 |
2143 |
1846 if ( get_user_setting('uploader') ) |
2144 if ( get_user_setting('uploader') ) |
1847 $form_class .= ' html-uploader'; |
2145 $form_class .= ' html-uploader'; |
1848 ?> |
2146 ?> |
1849 |
2147 |
1850 <script type="text/javascript"> |
2148 <script type="text/javascript"> |
1851 <!-- |
|
1852 jQuery(function($){ |
2149 jQuery(function($){ |
1853 var preloaded = $(".media-item.preloaded"); |
2150 var preloaded = $(".media-item.preloaded"); |
1854 if ( preloaded.length > 0 ) { |
2151 if ( preloaded.length > 0 ) { |
1855 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
2152 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
1856 updateMediaForm(); |
2153 updateMediaForm(); |
1857 } |
2154 } |
1858 }); |
2155 }); |
1859 --> |
|
1860 </script> |
2156 </script> |
1861 <div id="sort-buttons" class="hide-if-no-js"> |
2157 <div id="sort-buttons" class="hide-if-no-js"> |
1862 <span> |
2158 <span> |
1863 <?php _e('All Tabs:'); ?> |
2159 <?php _e('All Tabs:'); ?> |
1864 <a href="#" id="showall"><?php _e('Show'); ?></a> |
2160 <a href="#" id="showall"><?php _e('Show'); ?></a> |
1984 media_upload_header(); |
2280 media_upload_header(); |
1985 |
2281 |
1986 $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0; |
2282 $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0; |
1987 |
2283 |
1988 $form_action_url = admin_url("media-upload.php?type=$type&tab=library&post_id=$post_id"); |
2284 $form_action_url = admin_url("media-upload.php?type=$type&tab=library&post_id=$post_id"); |
1989 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type); |
2285 /** This filter is documented in wp-admin/includes/media.php */ |
|
2286 $form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type ); |
1990 $form_class = 'media-upload-form validate'; |
2287 $form_class = 'media-upload-form validate'; |
1991 |
2288 |
1992 if ( get_user_setting('uploader') ) |
2289 if ( get_user_setting('uploader') ) |
1993 $form_class .= ' html-uploader'; |
2290 $form_class .= ' html-uploader'; |
1994 |
2291 |
1995 $_GET['paged'] = isset( $_GET['paged'] ) ? intval($_GET['paged']) : 0; |
2292 $q = $_GET; |
1996 if ( $_GET['paged'] < 1 ) |
2293 $q['posts_per_page'] = 10; |
1997 $_GET['paged'] = 1; |
2294 $q['paged'] = isset( $q['paged'] ) ? intval( $q['paged'] ) : 0; |
1998 $start = ( $_GET['paged'] - 1 ) * 10; |
2295 if ( $q['paged'] < 1 ) { |
1999 if ( $start < 1 ) |
2296 $q['paged'] = 1; |
2000 $start = 0; |
2297 } |
2001 add_filter( 'post_limits', create_function( '$a', "return 'LIMIT $start, 10';" ) ); |
2298 $q['offset'] = ( $q['paged'] - 1 ) * 10; |
2002 |
2299 if ( $q['offset'] < 1 ) { |
2003 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); |
2300 $q['offset'] = 0; |
|
2301 } |
|
2302 |
|
2303 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query( $q ); |
2004 |
2304 |
2005 ?> |
2305 ?> |
2006 |
2306 |
2007 <form id="filter" action="" method="get"> |
2307 <form id="filter" method="get"> |
2008 <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" /> |
2308 <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" /> |
2009 <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" /> |
2309 <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" /> |
2010 <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" /> |
2310 <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" /> |
2011 <input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" /> |
2311 <input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" /> |
2012 <input type="hidden" name="context" value="<?php echo isset( $_GET['context'] ) ? esc_attr( $_GET['context'] ) : ''; ?>" /> |
2312 <input type="hidden" name="context" value="<?php echo isset( $_GET['context'] ) ? esc_attr( $_GET['context'] ) : ''; ?>" /> |
2035 } |
2335 } |
2036 if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' ) |
2336 if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' ) |
2037 $class = ' class="current"'; |
2337 $class = ' class="current"'; |
2038 else |
2338 else |
2039 $class = ''; |
2339 $class = ''; |
2040 $type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false))) . "'$class>".__('All Types')."</a>"; |
2340 $type_links[] = '<li><a href="' . esc_url(add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false))) . '"' . $class . '>' . __('All Types') . '</a>'; |
2041 foreach ( $post_mime_types as $mime_type => $label ) { |
2341 foreach ( $post_mime_types as $mime_type => $label ) { |
2042 $class = ''; |
2342 $class = ''; |
2043 |
2343 |
2044 if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) ) |
2344 if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) ) |
2045 continue; |
2345 continue; |
2046 |
2346 |
2047 if ( isset($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) ) |
2347 if ( isset($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) ) |
2048 $class = ' class="current"'; |
2348 $class = ' class="current"'; |
2049 |
2349 |
2050 $type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false))) . "'$class>" . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), "<span id='$mime_type-counter'>" . number_format_i18n( $num_posts[$mime_type] ) . '</span>') . '</a>'; |
2350 $type_links[] = '<li><a href="' . esc_url(add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false))) . '"' . $class . '>' . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), '<span id="' . $mime_type . '-counter">' . number_format_i18n( $num_posts[$mime_type] ) . '</span>') . '</a>'; |
2051 } |
2351 } |
|
2352 /** |
|
2353 * Filter the media upload mime type list items. |
|
2354 * |
|
2355 * Returned values should begin with an `<li>` tag. |
|
2356 * |
|
2357 * @since 3.1.0 |
|
2358 * |
|
2359 * @param array $type_links An array of list items containing mime type link HTML. |
|
2360 */ |
2052 echo implode(' | </li>', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '</li>'; |
2361 echo implode(' | </li>', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '</li>'; |
2053 unset($type_links); |
2362 unset($type_links); |
2054 ?> |
2363 ?> |
2055 </ul> |
2364 </ul> |
2056 |
2365 |
2174 |
2484 |
2175 return ' |
2485 return ' |
2176 <p class="media-types"><label><input type="radio" name="media_type" value="image" id="image-only"' . checked( 'image-only', $view, false ) . ' /> ' . __( 'Image' ) . '</label> <label><input type="radio" name="media_type" value="generic" id="not-image"' . checked( 'not-image', $view, false ) . ' /> ' . __( 'Audio, Video, or Other File' ) . '</label></p> |
2486 <p class="media-types"><label><input type="radio" name="media_type" value="image" id="image-only"' . checked( 'image-only', $view, false ) . ' /> ' . __( 'Image' ) . '</label> <label><input type="radio" name="media_type" value="generic" id="not-image"' . checked( 'not-image', $view, false ) . ' /> ' . __( 'Audio, Video, or Other File' ) . '</label></p> |
2177 <table class="describe ' . $table_class . '"><tbody> |
2487 <table class="describe ' . $table_class . '"><tbody> |
2178 <tr> |
2488 <tr> |
2179 <th valign="top" scope="row" class="label" style="width:130px;"> |
2489 <th scope="row" class="label" style="width:130px;"> |
2180 <label for="src"><span class="alignleft">' . __('URL') . '</span></label> |
2490 <label for="src"><span class="alignleft">' . __('URL') . '</span></label> |
2181 <span class="alignright"><abbr id="status_img" title="required" class="required">*</abbr></span> |
2491 <span class="alignright"><abbr id="status_img" title="required" class="required">*</abbr></span> |
2182 </th> |
2492 </th> |
2183 <td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()" /></td> |
2493 <td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()" /></td> |
2184 </tr> |
2494 </tr> |
2185 |
2495 |
2186 <tr> |
2496 <tr> |
2187 <th valign="top" scope="row" class="label"> |
2497 <th scope="row" class="label"> |
2188 <label for="title"><span class="alignleft">' . __('Title') . '</span></label> |
2498 <label for="title"><span class="alignleft">' . __('Title') . '</span></label> |
2189 <span class="alignright"><abbr title="required" class="required">*</abbr></span> |
2499 <span class="alignright"><abbr title="required" class="required">*</abbr></span> |
2190 </th> |
2500 </th> |
2191 <td class="field"><input id="title" name="title" value="" type="text" aria-required="true" /></td> |
2501 <td class="field"><input id="title" name="title" value="" type="text" aria-required="true" /></td> |
2192 </tr> |
2502 </tr> |
2193 |
2503 |
2194 <tr class="not-image"><td></td><td><p class="help">' . __('Link text, e.g. “Ransom Demands (PDF)”') . '</p></td></tr> |
2504 <tr class="not-image"><td></td><td><p class="help">' . __('Link text, e.g. “Ransom Demands (PDF)”') . '</p></td></tr> |
2195 |
2505 |
2196 <tr class="image-only"> |
2506 <tr class="image-only"> |
2197 <th valign="top" scope="row" class="label"> |
2507 <th scope="row" class="label"> |
2198 <label for="alt"><span class="alignleft">' . __('Alternative Text') . '</span></label> |
2508 <label for="alt"><span class="alignleft">' . __('Alternative Text') . '</span></label> |
2199 </th> |
2509 </th> |
2200 <td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" /> |
2510 <td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" /> |
2201 <p class="help">' . __('Alt text for the image, e.g. “The Mona Lisa”') . '</p></td> |
2511 <p class="help">' . __('Alt text for the image, e.g. “The Mona Lisa”') . '</p></td> |
2202 </tr> |
2512 </tr> |
2203 ' . $caption . ' |
2513 ' . $caption . ' |
2204 <tr class="align image-only"> |
2514 <tr class="align image-only"> |
2205 <th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th> |
2515 <th scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th> |
2206 <td class="field"> |
2516 <td class="field"> |
2207 <input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'none' ? ' checked="checked"' : '').' /> |
2517 <input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'none' ? ' checked="checked"' : '').' /> |
2208 <label for="align-none" class="align image-align-none-label">' . __('None') . '</label> |
2518 <label for="align-none" class="align image-align-none-label">' . __('None') . '</label> |
2209 <input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'left' ? ' checked="checked"' : '').' /> |
2519 <input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'left' ? ' checked="checked"' : '').' /> |
2210 <label for="align-left" class="align image-align-left-label">' . __('Left') . '</label> |
2520 <label for="align-left" class="align image-align-left-label">' . __('Left') . '</label> |
2342 $image_edit_button = ''; |
2650 $image_edit_button = ''; |
2343 if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { |
2651 if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { |
2344 $nonce = wp_create_nonce( "image_editor-$post->ID" ); |
2652 $nonce = wp_create_nonce( "image_editor-$post->ID" ); |
2345 $image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>"; |
2653 $image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>"; |
2346 } |
2654 } |
2347 ?> |
2655 ?> |
2348 |
2656 |
2349 <div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div> |
2657 <div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div> |
2350 |
2658 |
2351 <div<?php if ( $open ) echo ' style="display:none"'; ?> class="wp_attachment_image" id="media-head-<?php echo $attachment_id; ?>"> |
2659 <div<?php if ( $open ) echo ' style="display:none"'; ?> class="wp_attachment_image" id="media-head-<?php echo $attachment_id; ?>"> |
2352 <p id="thumbnail-head-<?php echo $attachment_id; ?>"><img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" /></p> |
2660 <p id="thumbnail-head-<?php echo $attachment_id; ?>"><img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" /></p> |
2354 </div> |
2662 </div> |
2355 <div<?php if ( ! $open ) echo ' style="display:none"'; ?> class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"> |
2663 <div<?php if ( ! $open ) echo ' style="display:none"'; ?> class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"> |
2356 <?php if ( $open ) wp_image_editor( $attachment_id ); ?> |
2664 <?php if ( $open ) wp_image_editor( $attachment_id ); ?> |
2357 </div> |
2665 </div> |
2358 <?php |
2666 <?php |
2359 elseif ( $attachment_id && 0 === strpos( $post->post_mime_type, 'audio/' ) ): |
2667 elseif ( $attachment_id && wp_attachment_is( 'audio', $post ) ): |
|
2668 |
|
2669 wp_maybe_generate_attachment_metadata( $post ); |
2360 |
2670 |
2361 echo wp_audio_shortcode( array( 'src' => $att_url ) ); |
2671 echo wp_audio_shortcode( array( 'src' => $att_url ) ); |
2362 |
2672 |
2363 elseif ( $attachment_id && 0 === strpos( $post->post_mime_type, 'video/' ) ): |
2673 elseif ( $attachment_id && wp_attachment_is( 'video', $post ) ): |
|
2674 |
|
2675 wp_maybe_generate_attachment_metadata( $post ); |
2364 |
2676 |
2365 $meta = wp_get_attachment_metadata( $attachment_id ); |
2677 $meta = wp_get_attachment_metadata( $attachment_id ); |
2366 $w = ! empty( $meta['width'] ) ? min( $meta['width'], 600 ) : 0; |
2678 $w = ! empty( $meta['width'] ) ? min( $meta['width'], 640 ) : 0; |
2367 $h = 0; |
2679 $h = ! empty( $meta['height'] ) ? $meta['height'] : 0; |
2368 if ( ! empty( $meta['height'] ) ) |
2680 if ( $h && $w < $meta['width'] ) { |
2369 $h = $meta['height']; |
|
2370 if ( $h && $w < $meta['width'] ) |
|
2371 $h = round( ( $meta['height'] * $w ) / $meta['width'] ); |
2681 $h = round( ( $meta['height'] * $w ) / $meta['width'] ); |
|
2682 } |
2372 |
2683 |
2373 $attr = array( 'src' => $att_url ); |
2684 $attr = array( 'src' => $att_url ); |
2374 |
2685 if ( ! empty( $w ) && ! empty( $h ) ) { |
2375 if ( ! empty( $meta['width' ] ) ) |
|
2376 $attr['width'] = $w; |
2686 $attr['width'] = $w; |
2377 |
|
2378 if ( ! empty( $meta['height'] ) ) |
|
2379 $attr['height'] = $h; |
2687 $attr['height'] = $h; |
|
2688 } |
|
2689 |
|
2690 $thumb_id = get_post_thumbnail_id( $attachment_id ); |
|
2691 if ( ! empty( $thumb_id ) ) { |
|
2692 $attr['poster'] = wp_get_attachment_url( $thumb_id ); |
|
2693 } |
2380 |
2694 |
2381 echo wp_video_shortcode( $attr ); |
2695 echo wp_video_shortcode( $attr ); |
2382 |
2696 |
2383 endif; ?> |
2697 endif; ?> |
2384 </div> |
2698 </div> |
2385 <div class="wp_attachment_details edit-form-section"> |
2699 <div class="wp_attachment_details edit-form-section"> |
2386 <p> |
2700 <p> |
2387 <label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br /> |
2701 <label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br /> |
2388 <textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea> |
2702 <textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea> |
2389 </p> |
2703 </p> |
|
2704 |
2390 |
2705 |
2391 <?php if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) : ?> |
2706 <?php if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) : ?> |
2392 <p> |
2707 <p> |
2393 <label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br /> |
2708 <label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br /> |
2394 <input type="text" class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" value="<?php echo esc_attr( $alt_text ); ?>" /> |
2709 <input type="text" class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" value="<?php echo esc_attr( $alt_text ); ?>" /> |
2441 <div class="misc-pub-section misc-pub-filename"> |
2760 <div class="misc-pub-section misc-pub-filename"> |
2442 <?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong> |
2761 <?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong> |
2443 </div> |
2762 </div> |
2444 <div class="misc-pub-section misc-pub-filetype"> |
2763 <div class="misc-pub-section misc-pub-filetype"> |
2445 <?php _e( 'File type:' ); ?> <strong><?php |
2764 <?php _e( 'File type:' ); ?> <strong><?php |
2446 if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) |
2765 if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) { |
2447 echo esc_html( strtoupper( $matches[1] ) ); |
2766 echo esc_html( strtoupper( $matches[1] ) ); |
2448 else |
2767 list( $mime_type ) = explode( '/', $post->post_mime_type ); |
|
2768 if ( $mime_type !== 'image' && ! empty( $meta['mime_type'] ) ) { |
|
2769 if ( $meta['mime_type'] !== "$mime_type/" . strtolower( $matches[1] ) ) { |
|
2770 echo ' (' . $meta['mime_type'] . ')'; |
|
2771 } |
|
2772 } |
|
2773 } else { |
2449 echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) ); |
2774 echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) ); |
|
2775 } |
2450 ?></strong> |
2776 ?></strong> |
2451 </div> |
2777 </div> |
2452 |
2778 |
2453 <?php |
2779 <?php |
2454 $file = get_attached_file( $post->ID ); |
2780 $file = get_attached_file( $post->ID ); |
2464 <?php _e( 'File size:' ); ?> <strong><?php echo size_format( $file_size ); ?></strong> |
2790 <?php _e( 'File size:' ); ?> <strong><?php echo size_format( $file_size ); ?></strong> |
2465 </div> |
2791 </div> |
2466 <?php |
2792 <?php |
2467 endif; |
2793 endif; |
2468 |
2794 |
2469 if ( preg_match( '#^(audio|video)#', $post->post_mime_type ) ): |
2795 if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) { |
2470 |
2796 |
2471 /** |
2797 /** |
2472 * Audio and video metadata fields to be shown in the publish meta box. |
2798 * Filter the audio and video metadata fields to be shown in the publish meta box. |
2473 * |
2799 * |
2474 * The key for each item in the array should correspond to an attachment |
2800 * The key for each item in the array should correspond to an attachment |
2475 * metadata key, and the value should be the desired label. |
2801 * metadata key, and the value should be the desired label. |
2476 * |
2802 * |
2477 * @since 3.7.0 |
2803 * @since 3.7.0 |
2478 * |
2804 * |
2479 * @param array $fields { |
2805 * @param array $fields An array of the attachment metadata keys and labels. |
2480 * An array of the attachment metadata keys and labels. |
|
2481 * |
|
2482 * @type string 'mime_type' Label to be shown before the field mime_type. |
|
2483 * @type string 'year' Label to be shown before the field year. |
|
2484 * @type string 'genre' Label to be shown before the field genre. |
|
2485 * @type string 'length_formatted' Label to be shown before the field length_formatted. |
|
2486 * } |
|
2487 */ |
2806 */ |
2488 $fields = apply_filters( 'media_submitbox_misc_sections', array( |
2807 $fields = apply_filters( 'media_submitbox_misc_sections', array( |
2489 'mime_type' => __( 'Mime-type:' ), |
|
2490 'year' => __( 'Year:' ), |
|
2491 'genre' => __( 'Genre:' ), |
|
2492 'length_formatted' => __( 'Length:' ), |
2808 'length_formatted' => __( 'Length:' ), |
|
2809 'bitrate' => __( 'Bitrate:' ), |
2493 ) ); |
2810 ) ); |
2494 |
2811 |
2495 foreach ( $fields as $key => $label ): |
2812 foreach ( $fields as $key => $label ) { |
2496 if ( ! empty( $meta[$key] ) ) : ?> |
2813 if ( empty( $meta[ $key ] ) ) { |
|
2814 continue; |
|
2815 } |
|
2816 ?> |
2497 <div class="misc-pub-section misc-pub-mime-meta misc-pub-<?php echo sanitize_html_class( $key ); ?>"> |
2817 <div class="misc-pub-section misc-pub-mime-meta misc-pub-<?php echo sanitize_html_class( $key ); ?>"> |
2498 <?php echo $label ?> <strong><?php echo esc_html( $meta[$key] ); ?></strong> |
2818 <?php echo $label ?> <strong><?php |
2499 </div> |
2819 switch ( $key ) { |
2500 <?php |
2820 case 'bitrate' : |
2501 endif; |
2821 echo round( $meta['bitrate'] / 1000 ) . 'kb/s'; |
2502 endforeach; |
2822 if ( ! empty( $meta['bitrate_mode'] ) ) { |
2503 |
2823 echo ' ' . strtoupper( esc_html( $meta['bitrate_mode'] ) ); |
2504 if ( ! empty( $meta['bitrate'] ) ) : ?> |
2824 } |
2505 <div class="misc-pub-section misc-pub-bitrate"> |
2825 break; |
2506 <?php _e( 'Bitrate:' ); ?> <strong><?php |
2826 default: |
2507 echo round( $meta['bitrate'] / 1000 ), 'kb/s'; |
2827 echo esc_html( $meta[ $key ] ); |
2508 |
2828 break; |
2509 if ( ! empty( $meta['bitrate_mode'] ) ) |
2829 } |
2510 echo ' ', strtoupper( $meta['bitrate_mode'] ); |
|
2511 |
|
2512 ?></strong> |
2830 ?></strong> |
2513 </div> |
2831 </div> |
2514 <?php |
2832 <?php |
2515 endif; |
2833 } |
2516 |
2834 |
2517 /** |
2835 /** |
2518 * Audio attachment metadata fields to be shown in the publish meta box. |
2836 * Filter the audio attachment metadata fields to be shown in the publish meta box. |
2519 * |
2837 * |
2520 * The key for each item in the array should correspond to an attachment |
2838 * The key for each item in the array should correspond to an attachment |
2521 * metadata key, and the value should be the desired label. |
2839 * metadata key, and the value should be the desired label. |
2522 * |
2840 * |
2523 * @since 3.7.0 |
2841 * @since 3.7.0 |
2524 * |
2842 * |
2525 * @param array $fields { |
2843 * @param array $fields An array of the attachment metadata keys and labels. |
2526 * An array of the attachment metadata keys and labels. |
|
2527 * |
|
2528 * @type string 'dataformat' Label to be shown before the field dataformat. |
|
2529 * @type string 'codec' Label to be shown before the field codec. |
|
2530 * } |
|
2531 */ |
2844 */ |
2532 $audio_fields = apply_filters( 'audio_submitbox_misc_sections', array( |
2845 $audio_fields = apply_filters( 'audio_submitbox_misc_sections', array( |
2533 'dataformat' => __( 'Audio Format:' ), |
2846 'dataformat' => __( 'Audio Format:' ), |
2534 'codec' => __( 'Audio Codec:' ) |
2847 'codec' => __( 'Audio Codec:' ) |
2535 ) ); |
2848 ) ); |
2536 |
2849 |
2537 foreach ( $audio_fields as $key => $label ): |
2850 foreach ( $audio_fields as $key => $label ) { |
2538 if ( ! empty( $meta['audio'][$key] ) ) : ?> |
2851 if ( empty( $meta['audio'][ $key ] ) ) { |
|
2852 continue; |
|
2853 } |
|
2854 ?> |
2539 <div class="misc-pub-section misc-pub-audio misc-pub-<?php echo sanitize_html_class( $key ); ?>"> |
2855 <div class="misc-pub-section misc-pub-audio misc-pub-<?php echo sanitize_html_class( $key ); ?>"> |
2540 <?php echo $label; ?> <strong><?php echo esc_html( $meta['audio'][$key] ); ?></strong> |
2856 <?php echo $label; ?> <strong><?php echo esc_html( $meta['audio'][$key] ); ?></strong> |
2541 </div> |
2857 </div> |
2542 <?php |
2858 <?php |
2543 endif; |
2859 } |
2544 endforeach; |
2860 |
2545 |
2861 } |
2546 endif; |
|
2547 |
2862 |
2548 if ( $media_dims ) : ?> |
2863 if ( $media_dims ) : ?> |
2549 <div class="misc-pub-section misc-pub-dimensions"> |
2864 <div class="misc-pub-section misc-pub-dimensions"> |
2550 <?php _e( 'Dimensions:' ); ?> <strong><?php echo $media_dims; ?></strong> |
2865 <?php _e( 'Dimensions:' ); ?> <strong><?php echo $media_dims; ?></strong> |
2551 </div> |
2866 </div> |
2578 */ |
2893 */ |
2579 function wp_add_id3_tag_data( &$metadata, $data ) { |
2894 function wp_add_id3_tag_data( &$metadata, $data ) { |
2580 foreach ( array( 'id3v2', 'id3v1' ) as $version ) { |
2895 foreach ( array( 'id3v2', 'id3v1' ) as $version ) { |
2581 if ( ! empty( $data[$version]['comments'] ) ) { |
2896 if ( ! empty( $data[$version]['comments'] ) ) { |
2582 foreach ( $data[$version]['comments'] as $key => $list ) { |
2897 foreach ( $data[$version]['comments'] as $key => $list ) { |
2583 if ( ! empty( $list ) ) { |
2898 if ( 'length' !== $key && ! empty( $list ) ) { |
2584 $metadata[$key] = reset( $list ); |
2899 $metadata[$key] = reset( $list ); |
2585 // fix bug in byte stream analysis |
2900 // Fix bug in byte stream analysis. |
2586 if ( 'terms_of_use' === $key && 0 === strpos( $metadata[$key], 'yright notice.' ) ) |
2901 if ( 'terms_of_use' === $key && 0 === strpos( $metadata[$key], 'yright notice.' ) ) |
2587 $metadata[$key] = 'Cop' . $metadata[$key]; |
2902 $metadata[$key] = 'Cop' . $metadata[$key]; |
2588 } |
2903 } |
2589 } |
2904 } |
2590 break; |
2905 break; |
2640 if ( ! empty( $data['filesize'] ) ) |
2955 if ( ! empty( $data['filesize'] ) ) |
2641 $metadata['filesize'] = (int) $data['filesize']; |
2956 $metadata['filesize'] = (int) $data['filesize']; |
2642 if ( ! empty( $data['mime_type'] ) ) |
2957 if ( ! empty( $data['mime_type'] ) ) |
2643 $metadata['mime_type'] = $data['mime_type']; |
2958 $metadata['mime_type'] = $data['mime_type']; |
2644 if ( ! empty( $data['playtime_seconds'] ) ) |
2959 if ( ! empty( $data['playtime_seconds'] ) ) |
2645 $metadata['length'] = (int) ceil( $data['playtime_seconds'] ); |
2960 $metadata['length'] = (int) round( $data['playtime_seconds'] ); |
2646 if ( ! empty( $data['playtime_string'] ) ) |
2961 if ( ! empty( $data['playtime_string'] ) ) |
2647 $metadata['length_formatted'] = $data['playtime_string']; |
2962 $metadata['length_formatted'] = $data['playtime_string']; |
2648 if ( ! empty( $data['video']['resolution_x'] ) ) |
2963 if ( ! empty( $data['video']['resolution_x'] ) ) |
2649 $metadata['width'] = (int) $data['video']['resolution_x']; |
2964 $metadata['width'] = (int) $data['video']['resolution_x']; |
2650 if ( ! empty( $data['video']['resolution_y'] ) ) |
2965 if ( ! empty( $data['video']['resolution_y'] ) ) |
2696 if ( ! empty( $data['filesize'] ) ) |
3011 if ( ! empty( $data['filesize'] ) ) |
2697 $metadata['filesize'] = (int) $data['filesize']; |
3012 $metadata['filesize'] = (int) $data['filesize']; |
2698 if ( ! empty( $data['mime_type'] ) ) |
3013 if ( ! empty( $data['mime_type'] ) ) |
2699 $metadata['mime_type'] = $data['mime_type']; |
3014 $metadata['mime_type'] = $data['mime_type']; |
2700 if ( ! empty( $data['playtime_seconds'] ) ) |
3015 if ( ! empty( $data['playtime_seconds'] ) ) |
2701 $metadata['length'] = (int) ceil( $data['playtime_seconds'] ); |
3016 $metadata['length'] = (int) round( $data['playtime_seconds'] ); |
2702 if ( ! empty( $data['playtime_string'] ) ) |
3017 if ( ! empty( $data['playtime_string'] ) ) |
2703 $metadata['length_formatted'] = $data['playtime_string']; |
3018 $metadata['length_formatted'] = $data['playtime_string']; |
2704 |
3019 |
2705 wp_add_id3_tag_data( $metadata, $data ); |
3020 wp_add_id3_tag_data( $metadata, $data ); |
2706 |
3021 |
2707 return $metadata; |
3022 return $metadata; |
2708 } |
3023 } |
|
3024 |
|
3025 /** |
|
3026 * Encapsulate logic for Attach/Detach actions |
|
3027 * |
|
3028 * @since 4.2.0 |
|
3029 * |
|
3030 * @global wpdb $wpdb WordPress database abstraction object. |
|
3031 * |
|
3032 * @param int $parent_id Attachment parent ID. |
|
3033 * @param string $action Optional. Attach/detach action. Accepts 'attach' or 'detach'. |
|
3034 * Default 'attach'. |
|
3035 */ |
|
3036 function wp_media_attach_action( $parent_id, $action = 'attach' ) { |
|
3037 global $wpdb; |
|
3038 |
|
3039 if ( ! $parent_id ) { |
|
3040 return; |
|
3041 } |
|
3042 |
|
3043 if ( ! current_user_can( 'edit_post', $parent_id ) ) { |
|
3044 wp_die( __( 'You are not allowed to edit this post.' ) ); |
|
3045 } |
|
3046 $ids = array(); |
|
3047 foreach ( (array) $_REQUEST['media'] as $att_id ) { |
|
3048 $att_id = (int) $att_id; |
|
3049 |
|
3050 if ( ! current_user_can( 'edit_post', $att_id ) ) { |
|
3051 continue; |
|
3052 } |
|
3053 |
|
3054 $ids[] = $att_id; |
|
3055 } |
|
3056 |
|
3057 if ( ! empty( $ids ) ) { |
|
3058 $ids_string = implode( ',', $ids ); |
|
3059 if ( 'attach' === $action ) { |
|
3060 $result = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ( $ids_string )", $parent_id ) ); |
|
3061 } else { |
|
3062 $result = $wpdb->query( "UPDATE $wpdb->posts SET post_parent = 0 WHERE post_type = 'attachment' AND ID IN ( $ids_string )" ); |
|
3063 } |
|
3064 |
|
3065 foreach ( $ids as $att_id ) { |
|
3066 clean_attachment_cache( $att_id ); |
|
3067 } |
|
3068 } |
|
3069 |
|
3070 if ( isset( $result ) ) { |
|
3071 $location = 'upload.php'; |
|
3072 if ( $referer = wp_get_referer() ) { |
|
3073 if ( false !== strpos( $referer, 'upload.php' ) ) { |
|
3074 $location = remove_query_arg( array( 'attached', 'detach' ), $referer ); |
|
3075 } |
|
3076 } |
|
3077 |
|
3078 $key = 'attach' === $action ? 'attached' : 'detach'; |
|
3079 $location = add_query_arg( array( $key => $result ), $location ); |
|
3080 wp_redirect( $location ); |
|
3081 exit; |
|
3082 } |
|
3083 } |