author | ymh <ymh.work@gmail.com> |
Tue, 27 Sep 2022 16:37:53 +0200 | |
changeset 19 | 3d72ae0968f4 |
parent 18 | be944660c56a |
child 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress Administration Media API. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
19 | 10 |
* Defines the default media upload tabs. |
0 | 11 |
* |
12 |
* @since 2.5.0 |
|
13 |
* |
|
16 | 14 |
* @return string[] Default tabs. |
0 | 15 |
*/ |
16 |
function media_upload_tabs() { |
|
17 |
$_default_tabs = array( |
|
16 | 18 |
'type' => __( 'From Computer' ), // Handler action suffix => tab text. |
9 | 19 |
'type_url' => __( 'From URL' ), |
20 |
'gallery' => __( 'Gallery' ), |
|
21 |
'library' => __( 'Media Library' ), |
|
0 | 22 |
); |
23 |
||
5 | 24 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
* Filters the available tabs in the legacy (pre-3.5.0) media popup. |
5 | 26 |
* |
27 |
* @since 2.5.0 |
|
28 |
* |
|
16 | 29 |
* @param string[] $_default_tabs An array of media tabs. |
5 | 30 |
*/ |
31 |
return apply_filters( 'media_upload_tabs', $_default_tabs ); |
|
0 | 32 |
} |
33 |
||
34 |
/** |
|
19 | 35 |
* Adds the gallery tab back to the tabs array if post has image attachments. |
0 | 36 |
* |
37 |
* @since 2.5.0 |
|
38 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
* |
0 | 41 |
* @param array $tabs |
42 |
* @return array $tabs with gallery if post has image attachment |
|
43 |
*/ |
|
9 | 44 |
function update_gallery_tab( $tabs ) { |
0 | 45 |
global $wpdb; |
46 |
||
9 | 47 |
if ( ! isset( $_REQUEST['post_id'] ) ) { |
48 |
unset( $tabs['gallery'] ); |
|
0 | 49 |
return $tabs; |
50 |
} |
|
51 |
||
18 | 52 |
$post_id = (int) $_REQUEST['post_id']; |
9 | 53 |
|
54 |
if ( $post_id ) { |
|
18 | 55 |
$attachments = (int) $wpdb->get_var( $wpdb->prepare( "SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id ) ); |
9 | 56 |
} |
57 |
||
58 |
if ( empty( $attachments ) ) { |
|
59 |
unset( $tabs['gallery'] ); |
|
0 | 60 |
return $tabs; |
61 |
} |
|
62 |
||
16 | 63 |
/* translators: %s: Number of attachments. */ |
9 | 64 |
$tabs['gallery'] = sprintf( __( 'Gallery (%s)' ), "<span id='attachments-count'>$attachments</span>" ); |
0 | 65 |
|
66 |
return $tabs; |
|
67 |
} |
|
68 |
||
69 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
* Outputs the legacy media upload tabs UI. |
0 | 71 |
* |
72 |
* @since 2.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
* @global string $redir_tab |
0 | 75 |
*/ |
76 |
function the_media_upload_tabs() { |
|
77 |
global $redir_tab; |
|
9 | 78 |
$tabs = media_upload_tabs(); |
0 | 79 |
$default = 'type'; |
80 |
||
9 | 81 |
if ( ! empty( $tabs ) ) { |
0 | 82 |
echo "<ul id='sidemenu'>\n"; |
16 | 83 |
|
9 | 84 |
if ( isset( $redir_tab ) && array_key_exists( $redir_tab, $tabs ) ) { |
0 | 85 |
$current = $redir_tab; |
9 | 86 |
} elseif ( isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $tabs ) ) { |
0 | 87 |
$current = $_GET['tab']; |
5 | 88 |
} else { |
89 |
/** This filter is documented in wp-admin/media-upload.php */ |
|
90 |
$current = apply_filters( 'media_upload_default_tab', $default ); |
|
91 |
} |
|
0 | 92 |
|
93 |
foreach ( $tabs as $callback => $text ) { |
|
94 |
$class = ''; |
|
95 |
||
9 | 96 |
if ( $current == $callback ) { |
0 | 97 |
$class = " class='current'"; |
9 | 98 |
} |
99 |
||
100 |
$href = add_query_arg( |
|
101 |
array( |
|
102 |
'tab' => $callback, |
|
103 |
's' => false, |
|
104 |
'paged' => false, |
|
105 |
'post_mime_type' => false, |
|
106 |
'm' => false, |
|
107 |
) |
|
108 |
); |
|
109 |
$link = "<a href='" . esc_url( $href ) . "'$class>$text</a>"; |
|
110 |
echo "\t<li id='" . esc_attr( "tab-$callback" ) . "'>$link</li>\n"; |
|
0 | 111 |
} |
16 | 112 |
|
0 | 113 |
echo "</ul>\n"; |
114 |
} |
|
115 |
} |
|
116 |
||
117 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
118 |
* Retrieves the image HTML to send to the editor. |
0 | 119 |
* |
120 |
* @since 2.5.0 |
|
121 |
* |
|
16 | 122 |
* @param int $id Image attachment ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
123 |
* @param string $caption Image caption. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
124 |
* @param string $title Image title attribute. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
* @param string $align Image CSS alignment property. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
* @param string $url Optional. Image src URL. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
127 |
* @param bool|string $rel Optional. Value for rel attribute or whether to add a default value. Default false. |
18 | 128 |
* @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array of |
129 |
* width and height values in pixels (in that order). Default 'medium'. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
* @param string $alt Optional. Image alt attribute. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
* @return string The HTML output to insert into the editor. |
0 | 132 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
function get_image_send_to_editor( $id, $caption, $title, $align, $url = '', $rel = false, $size = 'medium', $alt = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
$html = get_image_tag( $id, $alt, '', $align, $size ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
if ( $rel ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
if ( is_string( $rel ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
139 |
$rel = ' rel="' . esc_attr( $rel ) . '"'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
} else { |
18 | 141 |
$rel = ' rel="attachment wp-att-' . (int) $id . '"'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
144 |
$rel = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
145 |
} |
0 | 146 |
|
9 | 147 |
if ( $url ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
148 |
$html = '<a href="' . esc_attr( $url ) . '"' . $rel . '>' . $html . '</a>'; |
9 | 149 |
} |
0 | 150 |
|
5 | 151 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
152 |
* Filters the image HTML markup to send to the editor when inserting an image. |
5 | 153 |
* |
154 |
* @since 2.5.0 |
|
18 | 155 |
* @since 5.6.0 The `$rel` parameter was added. |
5 | 156 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
* @param string $html The image HTML markup to send. |
16 | 158 |
* @param int $id The attachment ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
159 |
* @param string $caption The image caption. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
160 |
* @param string $title The image title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
161 |
* @param string $align The image alignment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
162 |
* @param string $url The image source URL. |
18 | 163 |
* @param string|int[] $size Requested image size. Can be any registered image size name, or |
164 |
* an array of width and height values in pixels (in that order). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
165 |
* @param string $alt The image alternative, or alt, text. |
18 | 166 |
* @param string $rel The image rel attribute. |
5 | 167 |
*/ |
18 | 168 |
$html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt, $rel ); |
0 | 169 |
|
170 |
return $html; |
|
171 |
} |
|
172 |
||
173 |
/** |
|
16 | 174 |
* Adds image shortcode with caption to editor. |
0 | 175 |
* |
176 |
* @since 2.6.0 |
|
177 |
* |
|
9 | 178 |
* @param string $html The image HTML markup to send. |
18 | 179 |
* @param int $id Image attachment ID. |
9 | 180 |
* @param string $caption Image caption. |
181 |
* @param string $title Image title attribute (not used). |
|
182 |
* @param string $align Image CSS alignment property. |
|
183 |
* @param string $url Image source URL (not used). |
|
18 | 184 |
* @param string $size Image size (not used). |
9 | 185 |
* @param string $alt Image `alt` attribute (not used). |
186 |
* @return string The image HTML markup with caption shortcode. |
|
0 | 187 |
*/ |
188 |
function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) { |
|
189 |
||
5 | 190 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
* Filters the caption text. |
5 | 192 |
* |
193 |
* Note: If the caption text is empty, the caption shortcode will not be appended |
|
194 |
* to the image HTML when inserted into the editor. |
|
195 |
* |
|
196 |
* Passing an empty value also prevents the {@see 'image_add_caption_shortcode'} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
197 |
* Filters from being evaluated at the end of image_add_caption(). |
5 | 198 |
* |
199 |
* @since 4.1.0 |
|
200 |
* |
|
201 |
* @param string $caption The original caption text. |
|
202 |
* @param int $id The attachment ID. |
|
203 |
*/ |
|
204 |
$caption = apply_filters( 'image_add_caption_text', $caption, $id ); |
|
205 |
||
206 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
207 |
* Filters whether to disable captions. |
5 | 208 |
* |
209 |
* Prevents image captions from being appended to image HTML when inserted into the editor. |
|
210 |
* |
|
211 |
* @since 2.6.0 |
|
212 |
* |
|
16 | 213 |
* @param bool $bool Whether to disable appending captions. Returning true from the filter |
5 | 214 |
* will disable captions. Default empty string. |
215 |
*/ |
|
9 | 216 |
if ( empty( $caption ) || apply_filters( 'disable_captions', '' ) ) { |
0 | 217 |
return $html; |
9 | 218 |
} |
0 | 219 |
|
220 |
$id = ( 0 < (int) $id ) ? 'attachment_' . $id : ''; |
|
221 |
||
9 | 222 |
if ( ! preg_match( '/width=["\']([0-9]+)/', $html, $matches ) ) { |
0 | 223 |
return $html; |
9 | 224 |
} |
0 | 225 |
|
226 |
$width = $matches[1]; |
|
227 |
||
9 | 228 |
$caption = str_replace( array( "\r\n", "\r" ), "\n", $caption ); |
0 | 229 |
$caption = preg_replace_callback( '/<[a-zA-Z0-9]+(?: [^<>]+>)*/', '_cleanup_image_add_caption', $caption ); |
5 | 230 |
|
16 | 231 |
// Convert any remaining line breaks to <br />. |
0 | 232 |
$caption = preg_replace( '/[ \n\t]*\n[ \t]*/', '<br />', $caption ); |
233 |
||
234 |
$html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html ); |
|
9 | 235 |
if ( empty( $align ) ) { |
0 | 236 |
$align = 'none'; |
9 | 237 |
} |
238 |
||
239 |
$shcode = '[caption id="' . $id . '" align="align' . $align . '" width="' . $width . '"]' . $html . ' ' . $caption . '[/caption]'; |
|
0 | 240 |
|
5 | 241 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
242 |
* Filters the image HTML markup including the caption shortcode. |
5 | 243 |
* |
244 |
* @since 2.6.0 |
|
245 |
* |
|
246 |
* @param string $shcode The image HTML markup with caption shortcode. |
|
247 |
* @param string $html The image HTML markup. |
|
248 |
*/ |
|
0 | 249 |
return apply_filters( 'image_add_caption_shortcode', $shcode, $html ); |
250 |
} |
|
251 |
||
252 |
/** |
|
16 | 253 |
* Private preg_replace callback used in image_add_caption(). |
0 | 254 |
* |
255 |
* @access private |
|
256 |
* @since 3.4.0 |
|
257 |
*/ |
|
258 |
function _cleanup_image_add_caption( $matches ) { |
|
5 | 259 |
// Remove any line breaks from inside the tags. |
0 | 260 |
return preg_replace( '/[\r\n\t]+/', ' ', $matches[0] ); |
261 |
} |
|
262 |
||
263 |
/** |
|
16 | 264 |
* Adds image HTML to editor. |
0 | 265 |
* |
266 |
* @since 2.5.0 |
|
267 |
* |
|
268 |
* @param string $html |
|
269 |
*/ |
|
9 | 270 |
function media_send_to_editor( $html ) { |
271 |
?> |
|
16 | 272 |
<script type="text/javascript"> |
273 |
var win = window.dialogArguments || opener || parent || top; |
|
274 |
win.send_to_editor( <?php echo wp_json_encode( $html ); ?> ); |
|
275 |
</script> |
|
9 | 276 |
<?php |
0 | 277 |
exit; |
278 |
} |
|
279 |
||
280 |
/** |
|
16 | 281 |
* Saves a file submitted from a POST request and create an attachment post for it. |
0 | 282 |
* |
283 |
* @since 2.5.0 |
|
284 |
* |
|
19 | 285 |
* @param string $file_id Index of the `$_FILES` array that the file was sent. |
5 | 286 |
* @param int $post_id The post ID of a post to attach the media item to. Required, but can |
287 |
* be set to 0, creating a media item that has no relationship to a post. |
|
16 | 288 |
* @param array $post_data Optional. Overwrite some of the attachment. |
289 |
* @param array $overrides Optional. Override the wp_handle_upload() behavior. |
|
5 | 290 |
* @return int|WP_Error ID of the attachment or a WP_Error object on failure. |
0 | 291 |
*/ |
9 | 292 |
function media_handle_upload( $file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false ) ) { |
293 |
$time = current_time( 'mysql' ); |
|
16 | 294 |
$post = get_post( $post_id ); |
295 |
||
296 |
if ( $post ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
297 |
// The post date doesn't usually matter for pages, so don't backdate this upload. |
9 | 298 |
if ( 'page' !== $post->post_type && substr( $post->post_date, 0, 4 ) > 0 ) { |
0 | 299 |
$time = $post->post_date; |
9 | 300 |
} |
0 | 301 |
} |
302 |
||
9 | 303 |
$file = wp_handle_upload( $_FILES[ $file_id ], $overrides, $time ); |
304 |
||
305 |
if ( isset( $file['error'] ) ) { |
|
0 | 306 |
return new WP_Error( 'upload_error', $file['error'] ); |
9 | 307 |
} |
308 |
||
309 |
$name = $_FILES[ $file_id ]['name']; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
310 |
$ext = pathinfo( $name, PATHINFO_EXTENSION ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
311 |
$name = wp_basename( $name, ".$ext" ); |
0 | 312 |
|
9 | 313 |
$url = $file['url']; |
314 |
$type = $file['type']; |
|
315 |
$file = $file['file']; |
|
316 |
$title = sanitize_text_field( $name ); |
|
0 | 317 |
$content = ''; |
5 | 318 |
$excerpt = ''; |
0 | 319 |
|
320 |
if ( preg_match( '#^audio#', $type ) ) { |
|
321 |
$meta = wp_read_audio_metadata( $file ); |
|
322 |
||
5 | 323 |
if ( ! empty( $meta['title'] ) ) { |
0 | 324 |
$title = $meta['title']; |
5 | 325 |
} |
0 | 326 |
|
327 |
if ( ! empty( $title ) ) { |
|
328 |
||
329 |
if ( ! empty( $meta['album'] ) && ! empty( $meta['artist'] ) ) { |
|
16 | 330 |
/* translators: 1: Audio track title, 2: Album title, 3: Artist name. */ |
0 | 331 |
$content .= sprintf( __( '"%1$s" from %2$s by %3$s.' ), $title, $meta['album'], $meta['artist'] ); |
5 | 332 |
} elseif ( ! empty( $meta['album'] ) ) { |
16 | 333 |
/* translators: 1: Audio track title, 2: Album title. */ |
0 | 334 |
$content .= sprintf( __( '"%1$s" from %2$s.' ), $title, $meta['album'] ); |
5 | 335 |
} elseif ( ! empty( $meta['artist'] ) ) { |
16 | 336 |
/* translators: 1: Audio track title, 2: Artist name. */ |
0 | 337 |
$content .= sprintf( __( '"%1$s" by %2$s.' ), $title, $meta['artist'] ); |
338 |
} else { |
|
16 | 339 |
/* translators: %s: Audio track title. */ |
0 | 340 |
$content .= sprintf( __( '"%s".' ), $title ); |
341 |
} |
|
5 | 342 |
} elseif ( ! empty( $meta['album'] ) ) { |
0 | 343 |
|
344 |
if ( ! empty( $meta['artist'] ) ) { |
|
16 | 345 |
/* translators: 1: Audio album title, 2: Artist name. */ |
0 | 346 |
$content .= sprintf( __( '%1$s by %2$s.' ), $meta['album'], $meta['artist'] ); |
347 |
} else { |
|
348 |
$content .= $meta['album'] . '.'; |
|
349 |
} |
|
5 | 350 |
} elseif ( ! empty( $meta['artist'] ) ) { |
0 | 351 |
|
352 |
$content .= $meta['artist'] . '.'; |
|
353 |
||
354 |
} |
|
355 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
356 |
if ( ! empty( $meta['year'] ) ) { |
16 | 357 |
/* translators: Audio file track information. %d: Year of audio track release. */ |
0 | 358 |
$content .= ' ' . sprintf( __( 'Released: %d.' ), $meta['year'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
359 |
} |
0 | 360 |
|
361 |
if ( ! empty( $meta['track_number'] ) ) { |
|
362 |
$track_number = explode( '/', $meta['track_number'] ); |
|
16 | 363 |
|
19 | 364 |
if ( is_numeric( $track_number[0] ) ) { |
365 |
if ( isset( $track_number[1] ) && is_numeric( $track_number[1] ) ) { |
|
366 |
$content .= ' ' . sprintf( |
|
367 |
/* translators: Audio file track information. 1: Audio track number, 2: Total audio tracks. */ |
|
368 |
__( 'Track %1$s of %2$s.' ), |
|
369 |
number_format_i18n( $track_number[0] ), |
|
370 |
number_format_i18n( $track_number[1] ) |
|
371 |
); |
|
372 |
} else { |
|
373 |
$content .= ' ' . sprintf( |
|
374 |
/* translators: Audio file track information. %s: Audio track number. */ |
|
375 |
__( 'Track %s.' ), |
|
376 |
number_format_i18n( $track_number[0] ) |
|
377 |
); |
|
378 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
379 |
} |
0 | 380 |
} |
381 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
if ( ! empty( $meta['genre'] ) ) { |
16 | 383 |
/* translators: Audio file genre information. %s: Audio genre name. */ |
0 | 384 |
$content .= ' ' . sprintf( __( 'Genre: %s.' ), $meta['genre'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
} |
0 | 386 |
|
9 | 387 |
// Use image exif/iptc data for title and caption defaults if possible. |
16 | 388 |
} elseif ( 0 === strpos( $type, 'image/' ) ) { |
389 |
$image_meta = wp_read_image_metadata( $file ); |
|
390 |
||
391 |
if ( $image_meta ) { |
|
392 |
if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) { |
|
393 |
$title = $image_meta['title']; |
|
394 |
} |
|
395 |
||
396 |
if ( trim( $image_meta['caption'] ) ) { |
|
397 |
$excerpt = $image_meta['caption']; |
|
398 |
} |
|
5 | 399 |
} |
0 | 400 |
} |
401 |
||
16 | 402 |
// Construct the attachment array. |
9 | 403 |
$attachment = array_merge( |
404 |
array( |
|
405 |
'post_mime_type' => $type, |
|
406 |
'guid' => $url, |
|
407 |
'post_parent' => $post_id, |
|
408 |
'post_title' => $title, |
|
409 |
'post_content' => $content, |
|
410 |
'post_excerpt' => $excerpt, |
|
411 |
), |
|
412 |
$post_data |
|
413 |
); |
|
0 | 414 |
|
415 |
// This should never be set as it would then overwrite an existing attachment. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
unset( $attachment['ID'] ); |
0 | 417 |
|
16 | 418 |
// Save the data. |
419 |
$attachment_id = wp_insert_attachment( $attachment, $file, $post_id, true ); |
|
420 |
||
421 |
if ( ! is_wp_error( $attachment_id ) ) { |
|
422 |
// Set a custom header with the attachment_id. |
|
423 |
// Used by the browser/client to resume creating image sub-sizes after a PHP fatal error. |
|
424 |
if ( ! headers_sent() ) { |
|
425 |
header( 'X-WP-Upload-Attachment-ID: ' . $attachment_id ); |
|
426 |
} |
|
427 |
||
428 |
// The image sub-sizes are created during wp_generate_attachment_metadata(). |
|
429 |
// This is generally slow and may cause timeouts or out of memory errors. |
|
430 |
wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) ); |
|
0 | 431 |
} |
432 |
||
16 | 433 |
return $attachment_id; |
0 | 434 |
} |
435 |
||
436 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
* Handles a side-loaded file in the same way as an uploaded file is handled by media_handle_upload(). |
0 | 438 |
* |
439 |
* @since 2.6.0 |
|
16 | 440 |
* @since 5.3.0 The `$post_id` parameter was made optional. |
0 | 441 |
* |
18 | 442 |
* @param string[] $file_array Array that represents a `$_FILES` upload array. |
443 |
* @param int $post_id Optional. The post ID the media is associated with. |
|
444 |
* @param string $desc Optional. Description of the side-loaded file. Default null. |
|
445 |
* @param array $post_data Optional. Post data to override. Default empty array. |
|
16 | 446 |
* @return int|WP_Error The ID of the attachment or a WP_Error on failure. |
0 | 447 |
*/ |
16 | 448 |
function media_handle_sideload( $file_array, $post_id = 0, $desc = null, $post_data = array() ) { |
9 | 449 |
$overrides = array( 'test_form' => false ); |
0 | 450 |
|
18 | 451 |
if ( isset( $post_data['post_date'] ) && substr( $post_data['post_date'], 0, 4 ) > 0 ) { |
452 |
$time = $post_data['post_date']; |
|
453 |
} else { |
|
454 |
$post = get_post( $post_id ); |
|
455 |
if ( $post && substr( $post->post_date, 0, 4 ) > 0 ) { |
|
0 | 456 |
$time = $post->post_date; |
18 | 457 |
} else { |
458 |
$time = current_time( 'mysql' ); |
|
9 | 459 |
} |
0 | 460 |
} |
461 |
||
462 |
$file = wp_handle_sideload( $file_array, $overrides, $time ); |
|
16 | 463 |
|
9 | 464 |
if ( isset( $file['error'] ) ) { |
0 | 465 |
return new WP_Error( 'upload_error', $file['error'] ); |
9 | 466 |
} |
467 |
||
468 |
$url = $file['url']; |
|
469 |
$type = $file['type']; |
|
470 |
$file = $file['file']; |
|
471 |
$title = preg_replace( '/\.[^.]+$/', '', wp_basename( $file ) ); |
|
0 | 472 |
$content = ''; |
473 |
||
5 | 474 |
// Use image exif/iptc data for title and caption defaults if possible. |
16 | 475 |
$image_meta = wp_read_image_metadata( $file ); |
476 |
||
477 |
if ( $image_meta ) { |
|
9 | 478 |
if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) { |
0 | 479 |
$title = $image_meta['title']; |
9 | 480 |
} |
16 | 481 |
|
9 | 482 |
if ( trim( $image_meta['caption'] ) ) { |
0 | 483 |
$content = $image_meta['caption']; |
9 | 484 |
} |
0 | 485 |
} |
486 |
||
9 | 487 |
if ( isset( $desc ) ) { |
0 | 488 |
$title = $desc; |
9 | 489 |
} |
0 | 490 |
|
5 | 491 |
// Construct the attachment array. |
9 | 492 |
$attachment = array_merge( |
493 |
array( |
|
494 |
'post_mime_type' => $type, |
|
495 |
'guid' => $url, |
|
496 |
'post_parent' => $post_id, |
|
497 |
'post_title' => $title, |
|
498 |
'post_content' => $content, |
|
499 |
), |
|
500 |
$post_data |
|
501 |
); |
|
0 | 502 |
|
503 |
// This should never be set as it would then overwrite an existing attachment. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
504 |
unset( $attachment['ID'] ); |
0 | 505 |
|
16 | 506 |
// Save the attachment metadata. |
507 |
$attachment_id = wp_insert_attachment( $attachment, $file, $post_id, true ); |
|
508 |
||
509 |
if ( ! is_wp_error( $attachment_id ) ) { |
|
510 |
wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) ); |
|
9 | 511 |
} |
0 | 512 |
|
16 | 513 |
return $attachment_id; |
0 | 514 |
} |
515 |
||
516 |
/** |
|
16 | 517 |
* Outputs the iframe to display the media upload page. |
0 | 518 |
* |
519 |
* @since 2.5.0 |
|
16 | 520 |
* @since 5.3.0 Formalized the existing and already documented `...$args` parameter |
521 |
* by adding it to the function signature. |
|
0 | 522 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
* @global int $body_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
524 |
* |
16 | 525 |
* @param callable $content_func Function that outputs the content. |
526 |
* @param mixed ...$args Optional additional parameters to pass to the callback function when it's called. |
|
0 | 527 |
*/ |
16 | 528 |
function wp_iframe( $content_func, ...$args ) { |
0 | 529 |
_wp_admin_html_begin(); |
9 | 530 |
?> |
16 | 531 |
<title><?php bloginfo( 'name' ); ?> › <?php _e( 'Uploads' ); ?> — <?php _e( 'WordPress' ); ?></title> |
9 | 532 |
<?php |
533 |
||
534 |
wp_enqueue_style( 'colors' ); |
|
16 | 535 |
// Check callback name for 'media'. |
536 |
if ( |
|
537 |
( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) ) || |
|
538 |
( ! is_array( $content_func ) && 0 === strpos( $content_func, 'media' ) ) |
|
539 |
) { |
|
9 | 540 |
wp_enqueue_style( 'deprecated-media' ); |
541 |
} |
|
16 | 542 |
|
9 | 543 |
?> |
16 | 544 |
<script type="text/javascript"> |
19 | 545 |
addLoadEvent = function(func){if(typeof jQuery!=='undefined')jQuery(function(){func();});else if(typeof wpOnload!=='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}; |
18 | 546 |
var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup', |
16 | 547 |
isRtl = <?php echo (int) is_rtl(); ?>; |
548 |
</script> |
|
9 | 549 |
<?php |
5 | 550 |
/** This action is documented in wp-admin/admin-header.php */ |
551 |
do_action( 'admin_enqueue_scripts', 'media-upload-popup' ); |
|
552 |
||
553 |
/** |
|
554 |
* Fires when admin styles enqueued for the legacy (pre-3.5.0) media upload popup are printed. |
|
555 |
* |
|
556 |
* @since 2.9.0 |
|
557 |
*/ |
|
16 | 558 |
do_action( 'admin_print_styles-media-upload-popup' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
5 | 559 |
|
560 |
/** This action is documented in wp-admin/admin-header.php */ |
|
561 |
do_action( 'admin_print_styles' ); |
|
562 |
||
563 |
/** |
|
564 |
* Fires when admin scripts enqueued for the legacy (pre-3.5.0) media upload popup are printed. |
|
565 |
* |
|
566 |
* @since 2.9.0 |
|
567 |
*/ |
|
16 | 568 |
do_action( 'admin_print_scripts-media-upload-popup' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
5 | 569 |
|
570 |
/** This action is documented in wp-admin/admin-header.php */ |
|
571 |
do_action( 'admin_print_scripts' ); |
|
572 |
||
573 |
/** |
|
574 |
* Fires when scripts enqueued for the admin header for the legacy (pre-3.5.0) |
|
575 |
* media upload popup are printed. |
|
576 |
* |
|
577 |
* @since 2.9.0 |
|
578 |
*/ |
|
16 | 579 |
do_action( 'admin_head-media-upload-popup' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
5 | 580 |
|
581 |
/** This action is documented in wp-admin/admin-header.php */ |
|
582 |
do_action( 'admin_head' ); |
|
583 |
||
9 | 584 |
if ( is_string( $content_func ) ) { |
585 |
/** |
|
586 |
* Fires in the admin header for each specific form tab in the legacy |
|
587 |
* (pre-3.5.0) media upload popup. |
|
588 |
* |
|
19 | 589 |
* The dynamic portion of the hook name, `$content_func`, refers to the form |
590 |
* callback for the media upload type. |
|
9 | 591 |
* |
592 |
* @since 2.5.0 |
|
593 |
*/ |
|
594 |
do_action( "admin_head_{$content_func}" ); |
|
595 |
} |
|
596 |
||
597 |
$body_id_attr = ''; |
|
16 | 598 |
|
9 | 599 |
if ( isset( $GLOBALS['body_id'] ) ) { |
600 |
$body_id_attr = ' id="' . $GLOBALS['body_id'] . '"'; |
|
601 |
} |
|
16 | 602 |
|
9 | 603 |
?> |
16 | 604 |
</head> |
605 |
<body<?php echo $body_id_attr; ?> class="wp-core-ui no-js"> |
|
606 |
<script type="text/javascript"> |
|
607 |
document.body.className = document.body.className.replace('no-js', 'js'); |
|
608 |
</script> |
|
9 | 609 |
<?php |
16 | 610 |
|
9 | 611 |
call_user_func_array( $content_func, $args ); |
0 | 612 |
|
5 | 613 |
/** This action is documented in wp-admin/admin-footer.php */ |
614 |
do_action( 'admin_print_footer_scripts' ); |
|
16 | 615 |
|
9 | 616 |
?> |
18 | 617 |
<script type="text/javascript">if(typeof wpOnload==='function')wpOnload();</script> |
16 | 618 |
</body> |
619 |
</html> |
|
9 | 620 |
<?php |
0 | 621 |
} |
622 |
||
623 |
/** |
|
19 | 624 |
* Adds the media button to the editor. |
0 | 625 |
* |
626 |
* @since 2.5.0 |
|
627 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
628 |
* @global int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
629 |
* |
0 | 630 |
* @param string $editor_id |
631 |
*/ |
|
9 | 632 |
function media_buttons( $editor_id = 'content' ) { |
5 | 633 |
static $instance = 0; |
634 |
$instance++; |
|
635 |
||
0 | 636 |
$post = get_post(); |
16 | 637 |
|
9 | 638 |
if ( ! $post && ! empty( $GLOBALS['post_ID'] ) ) { |
0 | 639 |
$post = $GLOBALS['post_ID']; |
9 | 640 |
} |
641 |
||
16 | 642 |
wp_enqueue_media( array( 'post' => $post ) ); |
0 | 643 |
|
644 |
$img = '<span class="wp-media-buttons-icon"></span> '; |
|
645 |
||
16 | 646 |
$id_attribute = 1 === $instance ? ' id="insert-media-button"' : ''; |
647 |
||
9 | 648 |
printf( |
649 |
'<button type="button"%s class="button insert-media add_media" data-editor="%s">%s</button>', |
|
5 | 650 |
$id_attribute, |
651 |
esc_attr( $editor_id ), |
|
652 |
$img . __( 'Add Media' ) |
|
653 |
); |
|
16 | 654 |
|
5 | 655 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
656 |
* Filters the legacy (pre-3.5.0) media buttons. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
657 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
658 |
* Use {@see 'media_buttons'} action instead. |
5 | 659 |
* |
660 |
* @since 2.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
661 |
* @deprecated 3.5.0 Use {@see 'media_buttons'} action instead. |
5 | 662 |
* |
663 |
* @param string $string Media buttons context. Default empty. |
|
664 |
*/ |
|
16 | 665 |
$legacy_filter = apply_filters_deprecated( 'media_buttons_context', array( '' ), '3.5.0', 'media_buttons' ); |
0 | 666 |
|
667 |
if ( $legacy_filter ) { |
|
668 |
// #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag. |
|
9 | 669 |
if ( 0 === stripos( trim( $legacy_filter ), '</a>' ) ) { |
0 | 670 |
$legacy_filter .= '</a>'; |
9 | 671 |
} |
0 | 672 |
echo $legacy_filter; |
673 |
} |
|
674 |
} |
|
675 |
||
5 | 676 |
/** |
677 |
* @global int $post_ID |
|
678 |
* @param string $type |
|
16 | 679 |
* @param int $post_id |
5 | 680 |
* @param string $tab |
681 |
* @return string |
|
682 |
*/ |
|
0 | 683 |
function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) { |
684 |
global $post_ID; |
|
685 |
||
9 | 686 |
if ( empty( $post_id ) ) { |
0 | 687 |
$post_id = $post_ID; |
9 | 688 |
} |
689 |
||
690 |
$upload_iframe_src = add_query_arg( 'post_id', (int) $post_id, admin_url( 'media-upload.php' ) ); |
|
691 |
||
16 | 692 |
if ( $type && 'media' !== $type ) { |
9 | 693 |
$upload_iframe_src = add_query_arg( 'type', $type, $upload_iframe_src ); |
694 |
} |
|
695 |
||
696 |
if ( ! empty( $tab ) ) { |
|
697 |
$upload_iframe_src = add_query_arg( 'tab', $tab, $upload_iframe_src ); |
|
698 |
} |
|
0 | 699 |
|
5 | 700 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
701 |
* Filters the upload iframe source URL for a specific media type. |
5 | 702 |
* |
703 |
* The dynamic portion of the hook name, `$type`, refers to the type |
|
704 |
* of media uploaded. |
|
705 |
* |
|
18 | 706 |
* Possible hook names include: |
707 |
* |
|
708 |
* - `image_upload_iframe_src` |
|
709 |
* - `media_upload_iframe_src` |
|
710 |
* |
|
5 | 711 |
* @since 3.0.0 |
712 |
* |
|
18 | 713 |
* @param string $upload_iframe_src The upload iframe source URL. |
5 | 714 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
715 |
$upload_iframe_src = apply_filters( "{$type}_upload_iframe_src", $upload_iframe_src ); |
0 | 716 |
|
9 | 717 |
return add_query_arg( 'TB_iframe', true, $upload_iframe_src ); |
0 | 718 |
} |
719 |
||
720 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
721 |
* Handles form submissions for the legacy media uploader. |
0 | 722 |
* |
723 |
* @since 2.5.0 |
|
724 |
* |
|
19 | 725 |
* @return null|array|void Array of error messages keyed by attachment ID, null or void on success. |
0 | 726 |
*/ |
727 |
function media_upload_form_handler() { |
|
9 | 728 |
check_admin_referer( 'media-form' ); |
0 | 729 |
|
730 |
$errors = null; |
|
731 |
||
9 | 732 |
if ( isset( $_POST['send'] ) ) { |
733 |
$keys = array_keys( $_POST['send'] ); |
|
5 | 734 |
$send_id = (int) reset( $keys ); |
0 | 735 |
} |
736 |
||
9 | 737 |
if ( ! empty( $_POST['attachments'] ) ) { |
738 |
foreach ( $_POST['attachments'] as $attachment_id => $attachment ) { |
|
16 | 739 |
$post = get_post( $attachment_id, ARRAY_A ); |
740 |
$_post = $post; |
|
9 | 741 |
|
742 |
if ( ! current_user_can( 'edit_post', $attachment_id ) ) { |
|
743 |
continue; |
|
744 |
} |
|
745 |
||
746 |
if ( isset( $attachment['post_content'] ) ) { |
|
747 |
$post['post_content'] = $attachment['post_content']; |
|
748 |
} |
|
16 | 749 |
|
9 | 750 |
if ( isset( $attachment['post_title'] ) ) { |
751 |
$post['post_title'] = $attachment['post_title']; |
|
752 |
} |
|
16 | 753 |
|
9 | 754 |
if ( isset( $attachment['post_excerpt'] ) ) { |
755 |
$post['post_excerpt'] = $attachment['post_excerpt']; |
|
756 |
} |
|
16 | 757 |
|
9 | 758 |
if ( isset( $attachment['menu_order'] ) ) { |
759 |
$post['menu_order'] = $attachment['menu_order']; |
|
760 |
} |
|
761 |
||
762 |
if ( isset( $send_id ) && $attachment_id == $send_id ) { |
|
763 |
if ( isset( $attachment['post_parent'] ) ) { |
|
764 |
$post['post_parent'] = $attachment['post_parent']; |
|
765 |
} |
|
766 |
} |
|
767 |
||
768 |
/** |
|
769 |
* Filters the attachment fields to be saved. |
|
770 |
* |
|
771 |
* @since 2.5.0 |
|
772 |
* |
|
773 |
* @see wp_get_attachment_metadata() |
|
774 |
* |
|
775 |
* @param array $post An array of post data. |
|
776 |
* @param array $attachment An array of attachment metadata. |
|
777 |
*/ |
|
778 |
$post = apply_filters( 'attachment_fields_to_save', $post, $attachment ); |
|
779 |
||
780 |
if ( isset( $attachment['image_alt'] ) ) { |
|
781 |
$image_alt = wp_unslash( $attachment['image_alt'] ); |
|
16 | 782 |
|
783 |
if ( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) !== $image_alt ) { |
|
9 | 784 |
$image_alt = wp_strip_all_tags( $image_alt, true ); |
785 |
||
16 | 786 |
// update_post_meta() expects slashed. |
9 | 787 |
update_post_meta( $attachment_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) ); |
788 |
} |
|
789 |
} |
|
790 |
||
791 |
if ( isset( $post['errors'] ) ) { |
|
792 |
$errors[ $attachment_id ] = $post['errors']; |
|
793 |
unset( $post['errors'] ); |
|
794 |
} |
|
795 |
||
796 |
if ( $post != $_post ) { |
|
797 |
wp_update_post( $post ); |
|
798 |
} |
|
799 |
||
800 |
foreach ( get_attachment_taxonomies( $post ) as $t ) { |
|
801 |
if ( isset( $attachment[ $t ] ) ) { |
|
802 |
wp_set_object_terms( $attachment_id, array_map( 'trim', preg_split( '/,+/', $attachment[ $t ] ) ), $t, false ); |
|
803 |
} |
|
0 | 804 |
} |
805 |
} |
|
806 |
} |
|
807 |
||
9 | 808 |
if ( isset( $_POST['insert-gallery'] ) || isset( $_POST['update-gallery'] ) ) { |
809 |
?> |
|
0 | 810 |
<script type="text/javascript"> |
811 |
var win = window.dialogArguments || opener || parent || top; |
|
812 |
win.tb_remove(); |
|
813 |
</script> |
|
814 |
<?php |
|
16 | 815 |
|
0 | 816 |
exit; |
817 |
} |
|
818 |
||
9 | 819 |
if ( isset( $send_id ) ) { |
820 |
$attachment = wp_unslash( $_POST['attachments'][ $send_id ] ); |
|
16 | 821 |
$html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : ''; |
822 |
||
9 | 823 |
if ( ! empty( $attachment['url'] ) ) { |
0 | 824 |
$rel = ''; |
16 | 825 |
|
9 | 826 |
if ( strpos( $attachment['url'], 'attachment_id' ) || get_attachment_link( $send_id ) == $attachment['url'] ) { |
827 |
$rel = " rel='attachment wp-att-" . esc_attr( $send_id ) . "'"; |
|
828 |
} |
|
16 | 829 |
|
0 | 830 |
$html = "<a href='{$attachment['url']}'$rel>$html</a>"; |
831 |
} |
|
832 |
||
5 | 833 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
834 |
* Filters the HTML markup for a media item sent to the editor. |
5 | 835 |
* |
836 |
* @since 2.5.0 |
|
837 |
* |
|
838 |
* @see wp_get_attachment_metadata() |
|
839 |
* |
|
840 |
* @param string $html HTML markup for a media item sent to the editor. |
|
841 |
* @param int $send_id The first key from the $_POST['send'] data. |
|
842 |
* @param array $attachment Array of attachment metadata. |
|
843 |
*/ |
|
844 |
$html = apply_filters( 'media_send_to_editor', $html, $send_id, $attachment ); |
|
16 | 845 |
|
9 | 846 |
return media_send_to_editor( $html ); |
0 | 847 |
} |
848 |
||
849 |
return $errors; |
|
850 |
} |
|
851 |
||
852 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
853 |
* Handles the process of uploading media. |
0 | 854 |
* |
855 |
* @since 2.5.0 |
|
856 |
* |
|
5 | 857 |
* @return null|string |
0 | 858 |
*/ |
859 |
function wp_media_upload_handler() { |
|
860 |
$errors = array(); |
|
9 | 861 |
$id = 0; |
862 |
||
863 |
if ( isset( $_POST['html-upload'] ) && ! empty( $_FILES ) ) { |
|
864 |
check_admin_referer( 'media-form' ); |
|
16 | 865 |
// Upload File button was clicked. |
9 | 866 |
$id = media_handle_upload( 'async-upload', $_REQUEST['post_id'] ); |
867 |
unset( $_FILES ); |
|
16 | 868 |
|
9 | 869 |
if ( is_wp_error( $id ) ) { |
0 | 870 |
$errors['upload_error'] = $id; |
9 | 871 |
$id = false; |
0 | 872 |
} |
873 |
} |
|
874 |
||
9 | 875 |
if ( ! empty( $_POST['insertonlybutton'] ) ) { |
0 | 876 |
$src = $_POST['src']; |
16 | 877 |
|
9 | 878 |
if ( ! empty( $src ) && ! strpos( $src, '://' ) ) { |
0 | 879 |
$src = "http://$src"; |
9 | 880 |
} |
0 | 881 |
|
16 | 882 |
if ( isset( $_POST['media_type'] ) && 'image' !== $_POST['media_type'] ) { |
0 | 883 |
$title = esc_html( wp_unslash( $_POST['title'] ) ); |
9 | 884 |
if ( empty( $title ) ) { |
885 |
$title = esc_html( wp_basename( $src ) ); |
|
886 |
} |
|
887 |
||
888 |
if ( $title && $src ) { |
|
889 |
$html = "<a href='" . esc_url( $src ) . "'>$title</a>"; |
|
890 |
} |
|
0 | 891 |
|
892 |
$type = 'file'; |
|
16 | 893 |
$ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ); |
894 |
||
895 |
if ( $ext ) { |
|
896 |
$ext_type = wp_ext2type( $ext ); |
|
897 |
if ( 'audio' === $ext_type || 'video' === $ext_type ) { |
|
0 | 898 |
$type = $ext_type; |
16 | 899 |
} |
9 | 900 |
} |
0 | 901 |
|
5 | 902 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
903 |
* Filters the URL sent to the editor for a specific media type. |
5 | 904 |
* |
905 |
* The dynamic portion of the hook name, `$type`, refers to the type |
|
906 |
* of media being sent. |
|
907 |
* |
|
18 | 908 |
* Possible hook names include: |
909 |
* |
|
910 |
* - `audio_send_to_editor_url` |
|
911 |
* - `file_send_to_editor_url` |
|
912 |
* - `video_send_to_editor_url` |
|
913 |
* |
|
5 | 914 |
* @since 3.3.0 |
915 |
* |
|
916 |
* @param string $html HTML markup sent to the editor. |
|
917 |
* @param string $src Media source URL. |
|
918 |
* @param string $title Media title. |
|
919 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
920 |
$html = apply_filters( "{$type}_send_to_editor_url", $html, esc_url_raw( $src ), $title ); |
0 | 921 |
} else { |
922 |
$align = ''; |
|
9 | 923 |
$alt = esc_attr( wp_unslash( $_POST['alt'] ) ); |
16 | 924 |
|
9 | 925 |
if ( isset( $_POST['align'] ) ) { |
0 | 926 |
$align = esc_attr( wp_unslash( $_POST['align'] ) ); |
927 |
$class = " class='align$align'"; |
|
928 |
} |
|
16 | 929 |
|
9 | 930 |
if ( ! empty( $src ) ) { |
931 |
$html = "<img src='" . esc_url( $src ) . "' alt='$alt'$class />"; |
|
932 |
} |
|
0 | 933 |
|
5 | 934 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
935 |
* Filters the image URL sent to the editor. |
5 | 936 |
* |
937 |
* @since 2.8.0 |
|
938 |
* |
|
939 |
* @param string $html HTML markup sent to the editor for an image. |
|
940 |
* @param string $src Image source URL. |
|
941 |
* @param string $alt Image alternate, or alt, text. |
|
942 |
* @param string $align The image alignment. Default 'alignnone'. Possible values include |
|
943 |
* 'alignleft', 'aligncenter', 'alignright', 'alignnone'. |
|
944 |
*/ |
|
0 | 945 |
$html = apply_filters( 'image_send_to_editor_url', $html, esc_url_raw( $src ), $alt, $align ); |
946 |
} |
|
947 |
||
9 | 948 |
return media_send_to_editor( $html ); |
0 | 949 |
} |
950 |
||
5 | 951 |
if ( isset( $_POST['save'] ) ) { |
9 | 952 |
$errors['upload_notice'] = __( 'Saved.' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
953 |
wp_enqueue_script( 'admin-gallery' ); |
16 | 954 |
|
9 | 955 |
return wp_iframe( 'media_upload_gallery_form', $errors ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
956 |
|
5 | 957 |
} elseif ( ! empty( $_POST ) ) { |
0 | 958 |
$return = media_upload_form_handler(); |
959 |
||
9 | 960 |
if ( is_string( $return ) ) { |
0 | 961 |
return $return; |
9 | 962 |
} |
16 | 963 |
|
9 | 964 |
if ( is_array( $return ) ) { |
0 | 965 |
$errors = $return; |
9 | 966 |
} |
0 | 967 |
} |
968 |
||
16 | 969 |
if ( isset( $_GET['tab'] ) && 'type_url' === $_GET['tab'] ) { |
0 | 970 |
$type = 'image'; |
16 | 971 |
|
972 |
if ( isset( $_GET['type'] ) && in_array( $_GET['type'], array( 'video', 'audio', 'file' ), true ) ) { |
|
0 | 973 |
$type = $_GET['type']; |
9 | 974 |
} |
16 | 975 |
|
0 | 976 |
return wp_iframe( 'media_upload_type_url_form', $type, $errors, $id ); |
977 |
} |
|
978 |
||
979 |
return wp_iframe( 'media_upload_type_form', 'image', $errors, $id ); |
|
980 |
} |
|
981 |
||
982 |
/** |
|
18 | 983 |
* Downloads an image from the specified URL, saves it as an attachment, and optionally attaches it to a post. |
0 | 984 |
* |
985 |
* @since 2.6.0 |
|
19 | 986 |
* @since 4.2.0 Introduced the `$return_type` parameter. |
987 |
* @since 4.8.0 Introduced the 'id' option for the `$return_type` parameter. |
|
16 | 988 |
* @since 5.3.0 The `$post_id` parameter was made optional. |
989 |
* @since 5.4.0 The original URL of the attachment is stored in the `_source_url` |
|
990 |
* post meta value. |
|
0 | 991 |
* |
19 | 992 |
* @param string $file The URL of the image to download. |
993 |
* @param int $post_id Optional. The post ID the media is to be associated with. |
|
994 |
* @param string $desc Optional. Description of the image. |
|
995 |
* @param string $return_type Optional. Accepts 'html' (image tag html) or 'src' (URL), |
|
996 |
* or 'id' (attachment ID). Default 'html'. |
|
18 | 997 |
* @return string|int|WP_Error Populated HTML img tag, attachment ID, or attachment source |
998 |
* on success, WP_Error object otherwise. |
|
0 | 999 |
*/ |
19 | 1000 |
function media_sideload_image( $file, $post_id = 0, $desc = null, $return_type = 'html' ) { |
5 | 1001 |
if ( ! empty( $file ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1002 |
|
18 | 1003 |
$allowed_extensions = array( 'jpg', 'jpeg', 'jpe', 'png', 'gif', 'webp' ); |
1004 |
||
1005 |
/** |
|
1006 |
* Filters the list of allowed file extensions when sideloading an image from a URL. |
|
1007 |
* |
|
1008 |
* The default allowed extensions are: |
|
1009 |
* |
|
1010 |
* - `jpg` |
|
1011 |
* - `jpeg` |
|
1012 |
* - `jpe` |
|
1013 |
* - `png` |
|
1014 |
* - `gif` |
|
1015 |
* |
|
1016 |
* @since 5.6.0 |
|
1017 |
* |
|
1018 |
* @param string[] $allowed_extensions Array of allowed file extensions. |
|
1019 |
* @param string $file The URL of the image to download. |
|
1020 |
*/ |
|
1021 |
$allowed_extensions = apply_filters( 'image_sideload_extensions', $allowed_extensions, $file ); |
|
1022 |
$allowed_extensions = array_map( 'preg_quote', $allowed_extensions ); |
|
1023 |
||
5 | 1024 |
// Set variables for storage, fix file filename for query strings. |
18 | 1025 |
preg_match( '/[^\?]+\.(' . implode( '|', $allowed_extensions ) . ')\b/i', $file, $matches ); |
16 | 1026 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1027 |
if ( ! $matches ) { |
16 | 1028 |
return new WP_Error( 'image_sideload_failed', __( 'Invalid image URL.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1029 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1030 |
|
9 | 1031 |
$file_array = array(); |
1032 |
$file_array['name'] = wp_basename( $matches[0] ); |
|
5 | 1033 |
|
1034 |
// Download file to temp location. |
|
1035 |
$file_array['tmp_name'] = download_url( $file ); |
|
1036 |
||
1037 |
// If error storing temporarily, return the error. |
|
1038 |
if ( is_wp_error( $file_array['tmp_name'] ) ) { |
|
1039 |
return $file_array['tmp_name']; |
|
0 | 1040 |
} |
1041 |
||
5 | 1042 |
// Do the validation and storage stuff. |
0 | 1043 |
$id = media_handle_sideload( $file_array, $post_id, $desc ); |
5 | 1044 |
|
1045 |
// If error storing permanently, unlink. |
|
1046 |
if ( is_wp_error( $id ) ) { |
|
1047 |
@unlink( $file_array['tmp_name'] ); |
|
0 | 1048 |
return $id; |
16 | 1049 |
} |
1050 |
||
1051 |
// Store the original attachment source in meta. |
|
1052 |
add_post_meta( $id, '_source_url', $file ); |
|
1053 |
||
1054 |
// If attachment ID was requested, return it. |
|
19 | 1055 |
if ( 'id' === $return_type ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1056 |
return $id; |
0 | 1057 |
} |
1058 |
||
1059 |
$src = wp_get_attachment_url( $id ); |
|
1060 |
} |
|
1061 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1062 |
// Finally, check to make sure the file has been saved, then return the HTML. |
5 | 1063 |
if ( ! empty( $src ) ) { |
19 | 1064 |
if ( 'src' === $return_type ) { |
5 | 1065 |
return $src; |
1066 |
} |
|
1067 |
||
9 | 1068 |
$alt = isset( $desc ) ? esc_attr( $desc ) : ''; |
0 | 1069 |
$html = "<img src='$src' alt='$alt' />"; |
16 | 1070 |
|
0 | 1071 |
return $html; |
5 | 1072 |
} else { |
1073 |
return new WP_Error( 'image_sideload_failed' ); |
|
0 | 1074 |
} |
1075 |
} |
|
1076 |
||
1077 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1078 |
* Retrieves the legacy media uploader form in an iframe. |
0 | 1079 |
* |
1080 |
* @since 2.5.0 |
|
1081 |
* |
|
5 | 1082 |
* @return string|null |
0 | 1083 |
*/ |
1084 |
function media_upload_gallery() { |
|
1085 |
$errors = array(); |
|
1086 |
||
9 | 1087 |
if ( ! empty( $_POST ) ) { |
0 | 1088 |
$return = media_upload_form_handler(); |
1089 |
||
9 | 1090 |
if ( is_string( $return ) ) { |
0 | 1091 |
return $return; |
9 | 1092 |
} |
16 | 1093 |
|
9 | 1094 |
if ( is_array( $return ) ) { |
0 | 1095 |
$errors = $return; |
9 | 1096 |
} |
0 | 1097 |
} |
1098 |
||
9 | 1099 |
wp_enqueue_script( 'admin-gallery' ); |
0 | 1100 |
return wp_iframe( 'media_upload_gallery_form', $errors ); |
1101 |
} |
|
1102 |
||
1103 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1104 |
* Retrieves the legacy media library form in an iframe. |
0 | 1105 |
* |
1106 |
* @since 2.5.0 |
|
1107 |
* |
|
5 | 1108 |
* @return string|null |
0 | 1109 |
*/ |
1110 |
function media_upload_library() { |
|
1111 |
$errors = array(); |
|
16 | 1112 |
|
9 | 1113 |
if ( ! empty( $_POST ) ) { |
0 | 1114 |
$return = media_upload_form_handler(); |
1115 |
||
9 | 1116 |
if ( is_string( $return ) ) { |
0 | 1117 |
return $return; |
9 | 1118 |
} |
1119 |
if ( is_array( $return ) ) { |
|
0 | 1120 |
$errors = $return; |
9 | 1121 |
} |
0 | 1122 |
} |
1123 |
||
1124 |
return wp_iframe( 'media_upload_library_form', $errors ); |
|
1125 |
} |
|
1126 |
||
1127 |
/** |
|
19 | 1128 |
* Retrieves HTML for the image alignment radio buttons with the specified one checked. |
0 | 1129 |
* |
1130 |
* @since 2.7.0 |
|
1131 |
* |
|
5 | 1132 |
* @param WP_Post $post |
16 | 1133 |
* @param string $checked |
0 | 1134 |
* @return string |
1135 |
*/ |
|
1136 |
function image_align_input_fields( $post, $checked = '' ) { |
|
1137 |
||
9 | 1138 |
if ( empty( $checked ) ) { |
1139 |
$checked = get_user_setting( 'align', 'none' ); |
|
1140 |
} |
|
1141 |
||
1142 |
$alignments = array( |
|
1143 |
'none' => __( 'None' ), |
|
1144 |
'left' => __( 'Left' ), |
|
1145 |
'center' => __( 'Center' ), |
|
1146 |
'right' => __( 'Right' ), |
|
1147 |
); |
|
16 | 1148 |
|
9 | 1149 |
if ( ! array_key_exists( (string) $checked, $alignments ) ) { |
0 | 1150 |
$checked = 'none'; |
9 | 1151 |
} |
0 | 1152 |
|
1153 |
$out = array(); |
|
16 | 1154 |
|
0 | 1155 |
foreach ( $alignments as $name => $label ) { |
9 | 1156 |
$name = esc_attr( $name ); |
1157 |
$out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'" . |
|
1158 |
( $checked == $name ? " checked='checked'" : '' ) . |
|
0 | 1159 |
" /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>$label</label>"; |
1160 |
} |
|
16 | 1161 |
|
18 | 1162 |
return implode( "\n", $out ); |
0 | 1163 |
} |
1164 |
||
1165 |
/** |
|
19 | 1166 |
* Retrieves HTML for the size radio buttons with the specified one checked. |
0 | 1167 |
* |
1168 |
* @since 2.7.0 |
|
1169 |
* |
|
16 | 1170 |
* @param WP_Post $post |
0 | 1171 |
* @param bool|string $check |
1172 |
* @return array |
|
1173 |
*/ |
|
1174 |
function image_size_input_fields( $post, $check = '' ) { |
|
5 | 1175 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1176 |
* Filters the names and labels of the default image sizes. |
5 | 1177 |
* |
1178 |
* @since 3.3.0 |
|
1179 |
* |
|
16 | 1180 |
* @param string[] $size_names Array of image size labels keyed by their name. Default values |
1181 |
* include 'Thumbnail', 'Medium', 'Large', and 'Full Size'. |
|
5 | 1182 |
*/ |
9 | 1183 |
$size_names = apply_filters( |
1184 |
'image_size_names_choose', |
|
1185 |
array( |
|
1186 |
'thumbnail' => __( 'Thumbnail' ), |
|
1187 |
'medium' => __( 'Medium' ), |
|
1188 |
'large' => __( 'Large' ), |
|
1189 |
'full' => __( 'Full Size' ), |
|
1190 |
) |
|
1191 |
); |
|
5 | 1192 |
|
1193 |
if ( empty( $check ) ) { |
|
9 | 1194 |
$check = get_user_setting( 'imgsize', 'medium' ); |
5 | 1195 |
} |
16 | 1196 |
|
5 | 1197 |
$out = array(); |
1198 |
||
1199 |
foreach ( $size_names as $size => $label ) { |
|
1200 |
$downsize = image_downsize( $post->ID, $size ); |
|
9 | 1201 |
$checked = ''; |
5 | 1202 |
|
1203 |
// Is this size selectable? |
|
16 | 1204 |
$enabled = ( $downsize[3] || 'full' === $size ); |
9 | 1205 |
$css_id = "image-size-{$size}-{$post->ID}"; |
5 | 1206 |
|
1207 |
// If this size is the default but that's not available, don't select it. |
|
1208 |
if ( $size == $check ) { |
|
1209 |
if ( $enabled ) { |
|
0 | 1210 |
$checked = " checked='checked'"; |
5 | 1211 |
} else { |
1212 |
$check = ''; |
|
0 | 1213 |
} |
16 | 1214 |
} elseif ( ! $check && $enabled && 'thumbnail' !== $size ) { |
5 | 1215 |
/* |
1216 |
* If $check is not enabled, default to the first available size |
|
1217 |
* that's bigger than a thumbnail. |
|
1218 |
*/ |
|
9 | 1219 |
$check = $size; |
5 | 1220 |
$checked = " checked='checked'"; |
0 | 1221 |
} |
1222 |
||
5 | 1223 |
$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 />"; |
1224 |
||
1225 |
$html .= "<label for='{$css_id}'>$label</label>"; |
|
1226 |
||
1227 |
// Only show the dimensions if that choice is available. |
|
1228 |
if ( $enabled ) { |
|
9 | 1229 |
$html .= " <label for='{$css_id}' class='help'>" . sprintf( '(%d × %d)', $downsize[1], $downsize[2] ) . '</label>'; |
5 | 1230 |
} |
1231 |
$html .= '</div>'; |
|
1232 |
||
1233 |
$out[] = $html; |
|
1234 |
} |
|
1235 |
||
1236 |
return array( |
|
1237 |
'label' => __( 'Size' ), |
|
1238 |
'input' => 'html', |
|
18 | 1239 |
'html' => implode( "\n", $out ), |
5 | 1240 |
); |
0 | 1241 |
} |
1242 |
||
1243 |
/** |
|
19 | 1244 |
* Retrieves HTML for the Link URL buttons with the default link type as specified. |
0 | 1245 |
* |
1246 |
* @since 2.7.0 |
|
1247 |
* |
|
5 | 1248 |
* @param WP_Post $post |
16 | 1249 |
* @param string $url_type |
0 | 1250 |
* @return string |
1251 |
*/ |
|
9 | 1252 |
function image_link_input_fields( $post, $url_type = '' ) { |
1253 |
||
1254 |
$file = wp_get_attachment_url( $post->ID ); |
|
1255 |
$link = get_attachment_link( $post->ID ); |
|
1256 |
||
1257 |
if ( empty( $url_type ) ) { |
|
1258 |
$url_type = get_user_setting( 'urlbutton', 'post' ); |
|
1259 |
} |
|
0 | 1260 |
|
1261 |
$url = ''; |
|
16 | 1262 |
|
1263 |
if ( 'file' === $url_type ) { |
|
0 | 1264 |
$url = $file; |
16 | 1265 |
} elseif ( 'post' === $url_type ) { |
0 | 1266 |
$url = $link; |
9 | 1267 |
} |
0 | 1268 |
|
1269 |
return " |
|
9 | 1270 |
<input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr( $url ) . "' /><br /> |
1271 |
<button type='button' class='button urlnone' data-link-url=''>" . __( 'None' ) . "</button> |
|
1272 |
<button type='button' class='button urlfile' data-link-url='" . esc_attr( $file ) . "'>" . __( 'File URL' ) . "</button> |
|
1273 |
<button type='button' class='button urlpost' data-link-url='" . esc_attr( $link ) . "'>" . __( 'Attachment Post URL' ) . '</button> |
|
1274 |
'; |
|
0 | 1275 |
} |
1276 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1277 |
/** |
19 | 1278 |
* Outputs a textarea element for inputting an attachment caption. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1279 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1280 |
* @since 3.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1281 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1282 |
* @param WP_Post $edit_post Attachment WP_Post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1283 |
* @return string HTML markup for the textarea element. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1284 |
*/ |
9 | 1285 |
function wp_caption_input_textarea( $edit_post ) { |
5 | 1286 |
// Post data is already escaped. |
0 | 1287 |
$name = "attachments[{$edit_post->ID}][post_excerpt]"; |
1288 |
||
1289 |
return '<textarea name="' . $name . '" id="' . $name . '">' . $edit_post->post_excerpt . '</textarea>'; |
|
1290 |
} |
|
1291 |
||
1292 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1293 |
* Retrieves the image attachment fields to edit form fields. |
0 | 1294 |
* |
1295 |
* @since 2.5.0 |
|
1296 |
* |
|
16 | 1297 |
* @param array $form_fields |
0 | 1298 |
* @param object $post |
1299 |
* @return array |
|
1300 |
*/ |
|
9 | 1301 |
function image_attachment_fields_to_edit( $form_fields, $post ) { |
0 | 1302 |
return $form_fields; |
1303 |
} |
|
1304 |
||
1305 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1306 |
* Retrieves the single non-image attachment fields to edit form fields. |
0 | 1307 |
* |
1308 |
* @since 2.5.0 |
|
1309 |
* |
|
5 | 1310 |
* @param array $form_fields An array of attachment form fields. |
1311 |
* @param WP_Post $post The WP_Post attachment object. |
|
1312 |
* @return array Filtered attachment form fields. |
|
0 | 1313 |
*/ |
1314 |
function media_single_attachment_fields_to_edit( $form_fields, $post ) { |
|
9 | 1315 |
unset( $form_fields['url'], $form_fields['align'], $form_fields['image-size'] ); |
0 | 1316 |
return $form_fields; |
1317 |
} |
|
1318 |
||
1319 |
/** |
|
16 | 1320 |
* Retrieves the post non-image attachment fields to edit form fields. |
0 | 1321 |
* |
1322 |
* @since 2.8.0 |
|
1323 |
* |
|
5 | 1324 |
* @param array $form_fields An array of attachment form fields. |
1325 |
* @param WP_Post $post The WP_Post attachment object. |
|
1326 |
* @return array Filtered attachment form fields. |
|
0 | 1327 |
*/ |
1328 |
function media_post_single_attachment_fields_to_edit( $form_fields, $post ) { |
|
9 | 1329 |
unset( $form_fields['image_url'] ); |
0 | 1330 |
return $form_fields; |
1331 |
} |
|
1332 |
||
1333 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1334 |
* Retrieves the media element HTML to send to the editor. |
0 | 1335 |
* |
1336 |
* @since 2.5.0 |
|
1337 |
* |
|
16 | 1338 |
* @param string $html |
18 | 1339 |
* @param int $attachment_id |
16 | 1340 |
* @param array $attachment |
5 | 1341 |
* @return string |
0 | 1342 |
*/ |
9 | 1343 |
function image_media_send_to_editor( $html, $attachment_id, $attachment ) { |
1344 |
$post = get_post( $attachment_id ); |
|
16 | 1345 |
|
1346 |
if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) { |
|
9 | 1347 |
$url = $attachment['url']; |
1348 |
$align = ! empty( $attachment['align'] ) ? $attachment['align'] : 'none'; |
|
1349 |
$size = ! empty( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium'; |
|
1350 |
$alt = ! empty( $attachment['image_alt'] ) ? $attachment['image_alt'] : ''; |
|
16 | 1351 |
$rel = ( strpos( $url, 'attachment_id' ) || get_attachment_link( $attachment_id ) === $url ); |
9 | 1352 |
|
1353 |
return get_image_send_to_editor( $attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt ); |
|
0 | 1354 |
} |
1355 |
||
1356 |
return $html; |
|
1357 |
} |
|
1358 |
||
1359 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1360 |
* Retrieves the attachment fields to edit form fields. |
0 | 1361 |
* |
1362 |
* @since 2.5.0 |
|
1363 |
* |
|
5 | 1364 |
* @param WP_Post $post |
16 | 1365 |
* @param array $errors |
0 | 1366 |
* @return array |
1367 |
*/ |
|
9 | 1368 |
function get_attachment_fields_to_edit( $post, $errors = null ) { |
1369 |
if ( is_int( $post ) ) { |
|
1370 |
$post = get_post( $post ); |
|
1371 |
} |
|
16 | 1372 |
|
9 | 1373 |
if ( is_array( $post ) ) { |
0 | 1374 |
$post = new WP_Post( (object) $post ); |
9 | 1375 |
} |
1376 |
||
1377 |
$image_url = wp_get_attachment_url( $post->ID ); |
|
1378 |
||
1379 |
$edit_post = sanitize_post( $post, 'edit' ); |
|
0 | 1380 |
|
1381 |
$form_fields = array( |
|
1382 |
'post_title' => array( |
|
9 | 1383 |
'label' => __( 'Title' ), |
1384 |
'value' => $edit_post->post_title, |
|
0 | 1385 |
), |
9 | 1386 |
'image_alt' => array(), |
0 | 1387 |
'post_excerpt' => array( |
9 | 1388 |
'label' => __( 'Caption' ), |
1389 |
'input' => 'html', |
|
1390 |
'html' => wp_caption_input_textarea( $edit_post ), |
|
0 | 1391 |
), |
1392 |
'post_content' => array( |
|
9 | 1393 |
'label' => __( 'Description' ), |
1394 |
'value' => $edit_post->post_content, |
|
1395 |
'input' => 'textarea', |
|
0 | 1396 |
), |
1397 |
'url' => array( |
|
9 | 1398 |
'label' => __( 'Link URL' ), |
1399 |
'input' => 'html', |
|
1400 |
'html' => image_link_input_fields( $post, get_option( 'image_default_link_type' ) ), |
|
1401 |
'helps' => __( 'Enter a link URL or click above for presets.' ), |
|
0 | 1402 |
), |
1403 |
'menu_order' => array( |
|
9 | 1404 |
'label' => __( 'Order' ), |
1405 |
'value' => $edit_post->menu_order, |
|
0 | 1406 |
), |
9 | 1407 |
'image_url' => array( |
1408 |
'label' => __( 'File URL' ), |
|
1409 |
'input' => 'html', |
|
1410 |
'html' => "<input type='text' class='text urlfield' readonly='readonly' name='attachments[$post->ID][url]' value='" . esc_attr( $image_url ) . "' /><br />", |
|
1411 |
'value' => wp_get_attachment_url( $post->ID ), |
|
1412 |
'helps' => __( 'Location of the uploaded file.' ), |
|
1413 |
), |
|
0 | 1414 |
); |
1415 |
||
9 | 1416 |
foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) { |
1417 |
$t = (array) get_taxonomy( $taxonomy ); |
|
16 | 1418 |
|
9 | 1419 |
if ( ! $t['public'] || ! $t['show_ui'] ) { |
0 | 1420 |
continue; |
9 | 1421 |
} |
16 | 1422 |
|
9 | 1423 |
if ( empty( $t['label'] ) ) { |
0 | 1424 |
$t['label'] = $taxonomy; |
9 | 1425 |
} |
16 | 1426 |
|
9 | 1427 |
if ( empty( $t['args'] ) ) { |
0 | 1428 |
$t['args'] = array(); |
9 | 1429 |
} |
1430 |
||
1431 |
$terms = get_object_term_cache( $post->ID, $taxonomy ); |
|
16 | 1432 |
|
9 | 1433 |
if ( false === $terms ) { |
1434 |
$terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] ); |
|
1435 |
} |
|
0 | 1436 |
|
1437 |
$values = array(); |
|
1438 |
||
9 | 1439 |
foreach ( $terms as $term ) { |
0 | 1440 |
$values[] = $term->slug; |
9 | 1441 |
} |
16 | 1442 |
|
18 | 1443 |
$t['value'] = implode( ', ', $values ); |
9 | 1444 |
|
1445 |
$form_fields[ $taxonomy ] = $t; |
|
0 | 1446 |
} |
1447 |
||
16 | 1448 |
/* |
1449 |
* Merge default fields with their errors, so any key passed with the error |
|
1450 |
* (e.g. 'error', 'helps', 'value') will replace the default. |
|
1451 |
* The recursive merge is easily traversed with array casting: |
|
1452 |
* foreach ( (array) $things as $thing ) |
|
1453 |
*/ |
|
9 | 1454 |
$form_fields = array_merge_recursive( $form_fields, (array) $errors ); |
0 | 1455 |
|
1456 |
// This was formerly in image_attachment_fields_to_edit(). |
|
16 | 1457 |
if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) { |
9 | 1458 |
$alt = get_post_meta( $post->ID, '_wp_attachment_image_alt', true ); |
16 | 1459 |
|
9 | 1460 |
if ( empty( $alt ) ) { |
0 | 1461 |
$alt = ''; |
9 | 1462 |
} |
0 | 1463 |
|
1464 |
$form_fields['post_title']['required'] = true; |
|
1465 |
||
1466 |
$form_fields['image_alt'] = array( |
|
1467 |
'value' => $alt, |
|
9 | 1468 |
'label' => __( 'Alternative Text' ), |
1469 |
'helps' => __( 'Alt text for the image, e.g. “The Mona Lisa”' ), |
|
0 | 1470 |
); |
1471 |
||
1472 |
$form_fields['align'] = array( |
|
9 | 1473 |
'label' => __( 'Alignment' ), |
0 | 1474 |
'input' => 'html', |
9 | 1475 |
'html' => image_align_input_fields( $post, get_option( 'image_default_align' ) ), |
0 | 1476 |
); |
1477 |
||
9 | 1478 |
$form_fields['image-size'] = image_size_input_fields( $post, get_option( 'image_default_size', 'medium' ) ); |
0 | 1479 |
|
1480 |
} else { |
|
1481 |
unset( $form_fields['image_alt'] ); |
|
1482 |
} |
|
1483 |
||
5 | 1484 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1485 |
* Filters the attachment fields to edit. |
5 | 1486 |
* |
1487 |
* @since 2.5.0 |
|
1488 |
* |
|
1489 |
* @param array $form_fields An array of attachment form fields. |
|
1490 |
* @param WP_Post $post The WP_Post attachment object. |
|
1491 |
*/ |
|
1492 |
$form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post ); |
|
0 | 1493 |
|
1494 |
return $form_fields; |
|
1495 |
} |
|
1496 |
||
1497 |
/** |
|
19 | 1498 |
* Retrieves HTML for media items of post gallery. |
0 | 1499 |
* |
1500 |
* The HTML markup retrieved will be created for the progress of SWF Upload |
|
1501 |
* component. Will also create link for showing and hiding the form to modify |
|
1502 |
* the image attachment. |
|
1503 |
* |
|
1504 |
* @since 2.5.0 |
|
1505 |
* |
|
16 | 1506 |
* @global WP_Query $wp_the_query WordPress Query object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1507 |
* |
19 | 1508 |
* @param int $post_id Post ID. |
16 | 1509 |
* @param array $errors Errors for attachment, if any. |
19 | 1510 |
* @return string HTML content for media items of post gallery. |
0 | 1511 |
*/ |
1512 |
function get_media_items( $post_id, $errors ) { |
|
1513 |
$attachments = array(); |
|
16 | 1514 |
|
0 | 1515 |
if ( $post_id ) { |
9 | 1516 |
$post = get_post( $post_id ); |
16 | 1517 |
|
1518 |
if ( $post && 'attachment' === $post->post_type ) { |
|
9 | 1519 |
$attachments = array( $post->ID => $post ); |
1520 |
} else { |
|
1521 |
$attachments = get_children( |
|
1522 |
array( |
|
1523 |
'post_parent' => $post_id, |
|
1524 |
'post_type' => 'attachment', |
|
1525 |
'orderby' => 'menu_order ASC, ID', |
|
1526 |
'order' => 'DESC', |
|
1527 |
) |
|
1528 |
); |
|
1529 |
} |
|
0 | 1530 |
} else { |
9 | 1531 |
if ( is_array( $GLOBALS['wp_the_query']->posts ) ) { |
1532 |
foreach ( $GLOBALS['wp_the_query']->posts as $attachment ) { |
|
1533 |
$attachments[ $attachment->ID ] = $attachment; |
|
1534 |
} |
|
1535 |
} |
|
0 | 1536 |
} |
1537 |
||
1538 |
$output = ''; |
|
1539 |
foreach ( (array) $attachments as $id => $attachment ) { |
|
16 | 1540 |
if ( 'trash' === $attachment->post_status ) { |
0 | 1541 |
continue; |
9 | 1542 |
} |
16 | 1543 |
|
1544 |
$item = get_media_item( $id, array( 'errors' => isset( $errors[ $id ] ) ? $errors[ $id ] : null ) ); |
|
1545 |
||
1546 |
if ( $item ) { |
|
0 | 1547 |
$output .= "\n<div id='media-item-$id' class='media-item child-of-$attachment->post_parent preloaded'><div class='progress hidden'><div class='bar'></div></div><div id='media-upload-error-$id' class='hidden'></div><div class='filename hidden'></div>$item\n</div>"; |
9 | 1548 |
} |
0 | 1549 |
} |
1550 |
||
1551 |
return $output; |
|
1552 |
} |
|
1553 |
||
1554 |
/** |
|
19 | 1555 |
* Retrieves HTML form for modifying the image attachment. |
0 | 1556 |
* |
1557 |
* @since 2.5.0 |
|
1558 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1559 |
* @global string $redir_tab |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1560 |
* |
16 | 1561 |
* @param int $attachment_id Attachment ID for modification. |
1562 |
* @param string|array $args Optional. Override defaults. |
|
0 | 1563 |
* @return string HTML form for attachment. |
1564 |
*/ |
|
1565 |
function get_media_item( $attachment_id, $args = null ) { |
|
1566 |
global $redir_tab; |
|
1567 |
||
16 | 1568 |
$thumb_url = false; |
18 | 1569 |
$attachment_id = (int) $attachment_id; |
16 | 1570 |
|
1571 |
if ( $attachment_id ) { |
|
1572 |
$thumb_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail', true ); |
|
1573 |
||
1574 |
if ( $thumb_url ) { |
|
1575 |
$thumb_url = $thumb_url[0]; |
|
1576 |
} |
|
9 | 1577 |
} |
1578 |
||
1579 |
$post = get_post( $attachment_id ); |
|
1580 |
$current_post_id = ! empty( $_GET['post_id'] ) ? (int) $_GET['post_id'] : 0; |
|
0 | 1581 |
|
5 | 1582 |
$default_args = array( |
9 | 1583 |
'errors' => null, |
1584 |
'send' => $current_post_id ? post_type_supports( get_post_type( $current_post_id ), 'editor' ) : true, |
|
1585 |
'delete' => true, |
|
1586 |
'toggle' => true, |
|
1587 |
'show_title' => true, |
|
5 | 1588 |
); |
16 | 1589 |
|
1590 |
$parsed_args = wp_parse_args( $args, $default_args ); |
|
5 | 1591 |
|
1592 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1593 |
* Filters the arguments used to retrieve an image for the edit image form. |
5 | 1594 |
* |
1595 |
* @since 3.1.0 |
|
1596 |
* |
|
1597 |
* @see get_media_item |
|
1598 |
* |
|
16 | 1599 |
* @param array $parsed_args An array of arguments. |
5 | 1600 |
*/ |
16 | 1601 |
$parsed_args = apply_filters( 'get_media_item_args', $parsed_args ); |
0 | 1602 |
|
1603 |
$toggle_on = __( 'Show' ); |
|
1604 |
$toggle_off = __( 'Hide' ); |
|
1605 |
||
9 | 1606 |
$file = get_attached_file( $post->ID ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1607 |
$filename = esc_html( wp_basename( $file ) ); |
9 | 1608 |
$title = esc_attr( $post->post_title ); |
0 | 1609 |
|
1610 |
$post_mime_types = get_post_mime_types(); |
|
9 | 1611 |
$keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) ); |
1612 |
$type = reset( $keys ); |
|
1613 |
$type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />"; |
|
0 | 1614 |
|
16 | 1615 |
$form_fields = get_attachment_fields_to_edit( $post, $parsed_args['errors'] ); |
1616 |
||
1617 |
if ( $parsed_args['toggle'] ) { |
|
1618 |
$class = empty( $parsed_args['errors'] ) ? 'startclosed' : 'startopen'; |
|
0 | 1619 |
$toggle_links = " |
16 | 1620 |
<a class='toggle describe-toggle-on' href='#'>$toggle_on</a> |
1621 |
<a class='toggle describe-toggle-off' href='#'>$toggle_off</a>"; |
|
0 | 1622 |
} else { |
9 | 1623 |
$class = ''; |
0 | 1624 |
$toggle_links = ''; |
1625 |
} |
|
1626 |
||
16 | 1627 |
$display_title = ( ! empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case. |
1628 |
$display_title = $parsed_args['show_title'] ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60, '…' ) . '</span></div>' : ''; |
|
1629 |
||
1630 |
$gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' === $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' === $redir_tab ) ); |
|
9 | 1631 |
$order = ''; |
0 | 1632 |
|
1633 |
foreach ( $form_fields as $key => $val ) { |
|
16 | 1634 |
if ( 'menu_order' === $key ) { |
9 | 1635 |
if ( $gallery ) { |
1636 |
$order = "<div class='menu_order'> <input class='menu_order_input' type='text' id='attachments[$attachment_id][menu_order]' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' /></div>"; |
|
1637 |
} else { |
|
0 | 1638 |
$order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' />"; |
9 | 1639 |
} |
0 | 1640 |
|
1641 |
unset( $form_fields['menu_order'] ); |
|
1642 |
break; |
|
1643 |
} |
|
1644 |
} |
|
1645 |
||
1646 |
$media_dims = ''; |
|
9 | 1647 |
$meta = wp_get_attachment_metadata( $post->ID ); |
16 | 1648 |
|
9 | 1649 |
if ( isset( $meta['width'], $meta['height'] ) ) { |
0 | 1650 |
$media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> "; |
9 | 1651 |
} |
5 | 1652 |
|
1653 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1654 |
* Filters the media metadata. |
5 | 1655 |
* |
1656 |
* @since 2.5.0 |
|
1657 |
* |
|
1658 |
* @param string $media_dims The HTML markup containing the media dimensions. |
|
1659 |
* @param WP_Post $post The WP_Post attachment object. |
|
1660 |
*/ |
|
0 | 1661 |
$media_dims = apply_filters( 'media_meta', $media_dims, $post ); |
1662 |
||
1663 |
$image_edit_button = ''; |
|
16 | 1664 |
|
0 | 1665 |
if ( wp_attachment_is_image( $post->ID ) && wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { |
9 | 1666 |
$nonce = wp_create_nonce( "image_editor-$post->ID" ); |
0 | 1667 |
$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>"; |
1668 |
} |
|
1669 |
||
1670 |
$attachment_url = get_permalink( $attachment_id ); |
|
1671 |
||
1672 |
$item = " |
|
16 | 1673 |
$type_html |
1674 |
$toggle_links |
|
1675 |
$order |
|
1676 |
$display_title |
|
1677 |
<table class='slidetoggle describe $class'> |
|
1678 |
<thead class='media-item-info' id='media-head-$post->ID'> |
|
1679 |
<tr> |
|
0 | 1680 |
<td class='A1B1' id='thumbnail-head-$post->ID'> |
1681 |
<p><a href='$attachment_url' target='_blank'><img class='thumbnail' src='$thumb_url' alt='' /></a></p> |
|
1682 |
<p>$image_edit_button</p> |
|
1683 |
</td> |
|
1684 |
<td> |
|
9 | 1685 |
<p><strong>" . __( 'File name:' ) . "</strong> $filename</p> |
1686 |
<p><strong>" . __( 'File type:' ) . "</strong> $post->post_mime_type</p> |
|
1687 |
<p><strong>" . __( 'Upload date:' ) . '</strong> ' . mysql2date( __( 'F j, Y' ), $post->post_date ) . '</p>'; |
|
16 | 1688 |
|
9 | 1689 |
if ( ! empty( $media_dims ) ) { |
1690 |
$item .= '<p><strong>' . __( 'Dimensions:' ) . "</strong> $media_dims</p>\n"; |
|
1691 |
} |
|
0 | 1692 |
|
16 | 1693 |
$item .= "</td></tr>\n"; |
0 | 1694 |
|
1695 |
$item .= " |
|
1696 |
</thead> |
|
1697 |
<tbody> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1698 |
<tr><td colspan='2' class='imgedit-response' id='imgedit-response-$post->ID'></td></tr>\n |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1699 |
<tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-$post->ID'></td></tr>\n |
16 | 1700 |
<tr><td colspan='2'><p class='media-types media-types-required-info'>" . |
1701 |
/* translators: %s: Asterisk symbol (*). */ |
|
1702 |
sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) . |
|
1703 |
"</p></td></tr>\n"; |
|
0 | 1704 |
|
1705 |
$defaults = array( |
|
1706 |
'input' => 'text', |
|
1707 |
'required' => false, |
|
1708 |
'value' => '', |
|
1709 |
'extra_rows' => array(), |
|
1710 |
); |
|
1711 |
||
16 | 1712 |
if ( $parsed_args['send'] ) { |
1713 |
$parsed_args['send'] = get_submit_button( __( 'Insert into Post' ), '', "send[$attachment_id]", false ); |
|
5 | 1714 |
} |
1715 |
||
16 | 1716 |
$delete = empty( $parsed_args['delete'] ) ? '' : $parsed_args['delete']; |
0 | 1717 |
if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) { |
9 | 1718 |
if ( ! EMPTY_TRASH_DAYS ) { |
0 | 1719 |
$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>'; |
9 | 1720 |
} elseif ( ! MEDIA_TRASH ) { |
0 | 1721 |
$delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a> |
9 | 1722 |
<div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'>" . |
16 | 1723 |
/* translators: %s: File name. */ |
9 | 1724 |
'<p>' . sprintf( __( 'You are about to delete %s.' ), '<strong>' . $filename . '</strong>' ) . "</p> |
1725 |
<a href='" . wp_nonce_url( "post.php?action=delete&post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='button'>" . __( 'Continue' ) . "</a> |
|
1726 |
<a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . '</a> |
|
1727 |
</div>'; |
|
0 | 1728 |
} else { |
1729 |
$delete = "<a href='" . wp_nonce_url( "post.php?action=trash&post=$attachment_id", 'trash-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Move to Trash' ) . "</a> |
|
9 | 1730 |
<a href='" . wp_nonce_url( "post.php?action=untrash&post=$attachment_id", 'untrash-post_' . $attachment_id ) . "' id='undo[$attachment_id]' class='undo hidden'>" . __( 'Undo' ) . '</a>'; |
0 | 1731 |
} |
1732 |
} else { |
|
1733 |
$delete = ''; |
|
1734 |
} |
|
1735 |
||
9 | 1736 |
$thumbnail = ''; |
0 | 1737 |
$calling_post_id = 0; |
16 | 1738 |
|
5 | 1739 |
if ( isset( $_GET['post_id'] ) ) { |
0 | 1740 |
$calling_post_id = absint( $_GET['post_id'] ); |
16 | 1741 |
} elseif ( isset( $_POST ) && count( $_POST ) ) {// Like for async-upload where $_GET['post_id'] isn't set. |
0 | 1742 |
$calling_post_id = $post->post_parent; |
5 | 1743 |
} |
16 | 1744 |
|
1745 |
if ( 'image' === $type && $calling_post_id |
|
1746 |
&& current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) ) |
|
1747 |
&& post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) |
|
1748 |
&& get_post_thumbnail_id( $calling_post_id ) != $attachment_id |
|
1749 |
) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1750 |
|
9 | 1751 |
$calling_post = get_post( $calling_post_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1752 |
$calling_post_type_object = get_post_type_object( $calling_post->post_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1753 |
|
0 | 1754 |
$ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" ); |
9 | 1755 |
$thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;'>" . esc_html( $calling_post_type_object->labels->use_featured_image ) . '</a>'; |
0 | 1756 |
} |
1757 |
||
16 | 1758 |
if ( ( $parsed_args['send'] || $thumbnail || $delete ) && ! isset( $form_fields['buttons'] ) ) { |
1759 |
$form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>" . $parsed_args['send'] . " $thumbnail $delete</td></tr>\n" ); |
|
5 | 1760 |
} |
16 | 1761 |
|
0 | 1762 |
$hidden_fields = array(); |
1763 |
||
1764 |
foreach ( $form_fields as $id => $field ) { |
|
16 | 1765 |
if ( '_' === $id[0] ) { |
0 | 1766 |
continue; |
9 | 1767 |
} |
1768 |
||
1769 |
if ( ! empty( $field['tr'] ) ) { |
|
0 | 1770 |
$item .= $field['tr']; |
1771 |
continue; |
|
1772 |
} |
|
1773 |
||
1774 |
$field = array_merge( $defaults, $field ); |
|
9 | 1775 |
$name = "attachments[$attachment_id][$id]"; |
0 | 1776 |
|
16 | 1777 |
if ( 'hidden' === $field['input'] ) { |
9 | 1778 |
$hidden_fields[ $name ] = $field['value']; |
0 | 1779 |
continue; |
1780 |
} |
|
1781 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1782 |
$required = $field['required'] ? '<span class="required">*</span>' : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1783 |
$required_attr = $field['required'] ? ' required' : ''; |
9 | 1784 |
$class = $id; |
1785 |
$class .= $field['required'] ? ' form-required' : ''; |
|
0 | 1786 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1787 |
$item .= "\t\t<tr class='$class'>\n\t\t\t<th scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}{$required}</span><br class='clear' /></label></th>\n\t\t\t<td class='field'>"; |
16 | 1788 |
|
9 | 1789 |
if ( ! empty( $field[ $field['input'] ] ) ) { |
0 | 1790 |
$item .= $field[ $field['input'] ]; |
16 | 1791 |
} elseif ( 'textarea' === $field['input'] ) { |
1792 |
if ( 'post_content' === $id && user_can_richedit() ) { |
|
5 | 1793 |
// Sanitize_post() skips the post_content when user_can_richedit. |
0 | 1794 |
$field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES ); |
1795 |
} |
|
5 | 1796 |
// Post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit(). |
9 | 1797 |
$item .= "<textarea id='$name' name='$name'{$required_attr}>" . $field['value'] . '</textarea>'; |
0 | 1798 |
} else { |
9 | 1799 |
$item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "'{$required_attr} />"; |
0 | 1800 |
} |
16 | 1801 |
|
9 | 1802 |
if ( ! empty( $field['helps'] ) ) { |
18 | 1803 |
$item .= "<p class='help'>" . implode( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>'; |
9 | 1804 |
} |
0 | 1805 |
$item .= "</td>\n\t\t</tr>\n"; |
1806 |
||
1807 |
$extra_rows = array(); |
|
1808 |
||
9 | 1809 |
if ( ! empty( $field['errors'] ) ) { |
1810 |
foreach ( array_unique( (array) $field['errors'] ) as $error ) { |
|
0 | 1811 |
$extra_rows['error'][] = $error; |
9 | 1812 |
} |
1813 |
} |
|
1814 |
||
1815 |
if ( ! empty( $field['extra_rows'] ) ) { |
|
1816 |
foreach ( $field['extra_rows'] as $class => $rows ) { |
|
1817 |
foreach ( (array) $rows as $html ) { |
|
1818 |
$extra_rows[ $class ][] = $html; |
|
1819 |
} |
|
1820 |
} |
|
1821 |
} |
|
1822 |
||
1823 |
foreach ( $extra_rows as $class => $rows ) { |
|
1824 |
foreach ( $rows as $html ) { |
|
0 | 1825 |
$item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n"; |
9 | 1826 |
} |
1827 |
} |
|
0 | 1828 |
} |
1829 |
||
9 | 1830 |
if ( ! empty( $form_fields['_final'] ) ) { |
0 | 1831 |
$item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n"; |
9 | 1832 |
} |
16 | 1833 |
|
0 | 1834 |
$item .= "\t</tbody>\n"; |
1835 |
$item .= "\t</table>\n"; |
|
1836 |
||
9 | 1837 |
foreach ( $hidden_fields as $name => $value ) { |
0 | 1838 |
$item .= "\t<input type='hidden' name='$name' id='$name' value='" . esc_attr( $value ) . "' />\n"; |
9 | 1839 |
} |
0 | 1840 |
|
1841 |
if ( $post->post_parent < 1 && isset( $_REQUEST['post_id'] ) ) { |
|
9 | 1842 |
$parent = (int) $_REQUEST['post_id']; |
0 | 1843 |
$parent_name = "attachments[$attachment_id][post_parent]"; |
9 | 1844 |
$item .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='$parent' />\n"; |
0 | 1845 |
} |
1846 |
||
1847 |
return $item; |
|
1848 |
} |
|
1849 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1850 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1851 |
* @since 3.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1852 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1853 |
* @param int $attachment_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1854 |
* @param array $args |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1855 |
* @return array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1856 |
*/ |
0 | 1857 |
function get_compat_media_markup( $attachment_id, $args = null ) { |
1858 |
$post = get_post( $attachment_id ); |
|
1859 |
||
1860 |
$default_args = array( |
|
9 | 1861 |
'errors' => null, |
0 | 1862 |
'in_modal' => false, |
1863 |
); |
|
1864 |
||
1865 |
$user_can_edit = current_user_can( 'edit_post', $attachment_id ); |
|
1866 |
||
1867 |
$args = wp_parse_args( $args, $default_args ); |
|
5 | 1868 |
|
1869 |
/** This filter is documented in wp-admin/includes/media.php */ |
|
0 | 1870 |
$args = apply_filters( 'get_media_item_args', $args ); |
1871 |
||
1872 |
$form_fields = array(); |
|
1873 |
||
1874 |
if ( $args['in_modal'] ) { |
|
9 | 1875 |
foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) { |
1876 |
$t = (array) get_taxonomy( $taxonomy ); |
|
16 | 1877 |
|
9 | 1878 |
if ( ! $t['public'] || ! $t['show_ui'] ) { |
0 | 1879 |
continue; |
9 | 1880 |
} |
16 | 1881 |
|
9 | 1882 |
if ( empty( $t['label'] ) ) { |
0 | 1883 |
$t['label'] = $taxonomy; |
9 | 1884 |
} |
16 | 1885 |
|
9 | 1886 |
if ( empty( $t['args'] ) ) { |
0 | 1887 |
$t['args'] = array(); |
9 | 1888 |
} |
1889 |
||
1890 |
$terms = get_object_term_cache( $post->ID, $taxonomy ); |
|
16 | 1891 |
|
9 | 1892 |
if ( false === $terms ) { |
1893 |
$terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] ); |
|
1894 |
} |
|
0 | 1895 |
|
1896 |
$values = array(); |
|
1897 |
||
9 | 1898 |
foreach ( $terms as $term ) { |
0 | 1899 |
$values[] = $term->slug; |
9 | 1900 |
} |
16 | 1901 |
|
18 | 1902 |
$t['value'] = implode( ', ', $values ); |
0 | 1903 |
$t['taxonomy'] = true; |
1904 |
||
9 | 1905 |
$form_fields[ $taxonomy ] = $t; |
0 | 1906 |
} |
1907 |
} |
|
1908 |
||
16 | 1909 |
/* |
1910 |
* Merge default fields with their errors, so any key passed with the error |
|
1911 |
* (e.g. 'error', 'helps', 'value') will replace the default. |
|
1912 |
* The recursive merge is easily traversed with array casting: |
|
1913 |
* foreach ( (array) $things as $thing ) |
|
1914 |
*/ |
|
9 | 1915 |
$form_fields = array_merge_recursive( $form_fields, (array) $args['errors'] ); |
0 | 1916 |
|
5 | 1917 |
/** This filter is documented in wp-admin/includes/media.php */ |
0 | 1918 |
$form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post ); |
1919 |
||
9 | 1920 |
unset( |
1921 |
$form_fields['image-size'], |
|
1922 |
$form_fields['align'], |
|
1923 |
$form_fields['image_alt'], |
|
1924 |
$form_fields['post_title'], |
|
1925 |
$form_fields['post_excerpt'], |
|
1926 |
$form_fields['post_content'], |
|
1927 |
$form_fields['url'], |
|
1928 |
$form_fields['menu_order'], |
|
1929 |
$form_fields['image_url'] |
|
1930 |
); |
|
0 | 1931 |
|
5 | 1932 |
/** This filter is documented in wp-admin/includes/media.php */ |
0 | 1933 |
$media_meta = apply_filters( 'media_meta', '', $post ); |
1934 |
||
1935 |
$defaults = array( |
|
1936 |
'input' => 'text', |
|
5 | 1937 |
'required' => false, |
1938 |
'value' => '', |
|
1939 |
'extra_rows' => array(), |
|
1940 |
'show_in_edit' => true, |
|
1941 |
'show_in_modal' => true, |
|
0 | 1942 |
); |
1943 |
||
1944 |
$hidden_fields = array(); |
|
1945 |
||
1946 |
$item = ''; |
|
16 | 1947 |
|
0 | 1948 |
foreach ( $form_fields as $id => $field ) { |
16 | 1949 |
if ( '_' === $id[0] ) { |
0 | 1950 |
continue; |
9 | 1951 |
} |
1952 |
||
1953 |
$name = "attachments[$attachment_id][$id]"; |
|
0 | 1954 |
$id_attr = "attachments-$attachment_id-$id"; |
1955 |
||
9 | 1956 |
if ( ! empty( $field['tr'] ) ) { |
0 | 1957 |
$item .= $field['tr']; |
1958 |
continue; |
|
1959 |
} |
|
1960 |
||
1961 |
$field = array_merge( $defaults, $field ); |
|
1962 |
||
9 | 1963 |
if ( ( ! $field['show_in_edit'] && ! $args['in_modal'] ) || ( ! $field['show_in_modal'] && $args['in_modal'] ) ) { |
0 | 1964 |
continue; |
9 | 1965 |
} |
0 | 1966 |
|
16 | 1967 |
if ( 'hidden' === $field['input'] ) { |
9 | 1968 |
$hidden_fields[ $name ] = $field['value']; |
0 | 1969 |
continue; |
1970 |
} |
|
1971 |
||
1972 |
$readonly = ! $user_can_edit && ! empty( $field['taxonomy'] ) ? " readonly='readonly' " : ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1973 |
$required = $field['required'] ? '<span class="required">*</span>' : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1974 |
$required_attr = $field['required'] ? ' required' : ''; |
9 | 1975 |
$class = 'compat-field-' . $id; |
1976 |
$class .= $field['required'] ? ' form-required' : ''; |
|
0 | 1977 |
|
1978 |
$item .= "\t\t<tr class='$class'>"; |
|
5 | 1979 |
$item .= "\t\t\t<th scope='row' class='label'><label for='$id_attr'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label>"; |
0 | 1980 |
$item .= "</th>\n\t\t\t<td class='field'>"; |
1981 |
||
9 | 1982 |
if ( ! empty( $field[ $field['input'] ] ) ) { |
0 | 1983 |
$item .= $field[ $field['input'] ]; |
16 | 1984 |
} elseif ( 'textarea' === $field['input'] ) { |
1985 |
if ( 'post_content' === $id && user_can_richedit() ) { |
|
5 | 1986 |
// sanitize_post() skips the post_content when user_can_richedit. |
0 | 1987 |
$field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES ); |
1988 |
} |
|
9 | 1989 |
$item .= "<textarea id='$id_attr' name='$name'{$required_attr}>" . $field['value'] . '</textarea>'; |
0 | 1990 |
} else { |
9 | 1991 |
$item .= "<input type='text' class='text' id='$id_attr' name='$name' value='" . esc_attr( $field['value'] ) . "' $readonly{$required_attr} />"; |
0 | 1992 |
} |
16 | 1993 |
|
9 | 1994 |
if ( ! empty( $field['helps'] ) ) { |
18 | 1995 |
$item .= "<p class='help'>" . implode( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>'; |
9 | 1996 |
} |
16 | 1997 |
|
0 | 1998 |
$item .= "</td>\n\t\t</tr>\n"; |
1999 |
||
2000 |
$extra_rows = array(); |
|
2001 |
||
9 | 2002 |
if ( ! empty( $field['errors'] ) ) { |
2003 |
foreach ( array_unique( (array) $field['errors'] ) as $error ) { |
|
0 | 2004 |
$extra_rows['error'][] = $error; |
9 | 2005 |
} |
2006 |
} |
|
2007 |
||
2008 |
if ( ! empty( $field['extra_rows'] ) ) { |
|
2009 |
foreach ( $field['extra_rows'] as $class => $rows ) { |
|
2010 |
foreach ( (array) $rows as $html ) { |
|
2011 |
$extra_rows[ $class ][] = $html; |
|
2012 |
} |
|
2013 |
} |
|
2014 |
} |
|
2015 |
||
2016 |
foreach ( $extra_rows as $class => $rows ) { |
|
2017 |
foreach ( $rows as $html ) { |
|
0 | 2018 |
$item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n"; |
9 | 2019 |
} |
2020 |
} |
|
0 | 2021 |
} |
2022 |
||
9 | 2023 |
if ( ! empty( $form_fields['_final'] ) ) { |
0 | 2024 |
$item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n"; |
9 | 2025 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2026 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2027 |
if ( $item ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2028 |
$item = '<p class="media-types media-types-required-info">' . |
16 | 2029 |
/* translators: %s: Asterisk symbol (*). */ |
2030 |
sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) . |
|
2031 |
'</p>' . |
|
2032 |
'<table class="compat-attachment-fields">' . $item . '</table>'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2033 |
} |
0 | 2034 |
|
2035 |
foreach ( $hidden_fields as $hidden_field => $value ) { |
|
2036 |
$item .= '<input type="hidden" name="' . esc_attr( $hidden_field ) . '" value="' . esc_attr( $value ) . '" />' . "\n"; |
|
2037 |
} |
|
2038 |
||
9 | 2039 |
if ( $item ) { |
0 | 2040 |
$item = '<input type="hidden" name="attachments[' . $attachment_id . '][menu_order]" value="' . esc_attr( $post->menu_order ) . '" />' . $item; |
9 | 2041 |
} |
0 | 2042 |
|
2043 |
return array( |
|
9 | 2044 |
'item' => $item, |
2045 |
'meta' => $media_meta, |
|
0 | 2046 |
); |
2047 |
} |
|
2048 |
||
2049 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2050 |
* Outputs the legacy media upload header. |
0 | 2051 |
* |
2052 |
* @since 2.5.0 |
|
2053 |
*/ |
|
2054 |
function media_upload_header() { |
|
18 | 2055 |
$post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2056 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2057 |
echo '<script type="text/javascript">post_id = ' . $post_id . ';</script>'; |
16 | 2058 |
|
0 | 2059 |
if ( empty( $_GET['chromeless'] ) ) { |
2060 |
echo '<div id="media-upload-header">'; |
|
2061 |
the_media_upload_tabs(); |
|
2062 |
echo '</div>'; |
|
2063 |
} |
|
2064 |
} |
|
2065 |
||
2066 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2067 |
* Outputs the legacy media upload form. |
0 | 2068 |
* |
2069 |
* @since 2.5.0 |
|
2070 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2071 |
* @global string $type |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2072 |
* @global string $tab |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2073 |
* @global bool $is_IE |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2074 |
* @global bool $is_opera |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2075 |
* |
5 | 2076 |
* @param array $errors |
0 | 2077 |
*/ |
2078 |
function media_upload_form( $errors = null ) { |
|
2079 |
global $type, $tab, $is_IE, $is_opera; |
|
2080 |
||
2081 |
if ( ! _device_can_upload() ) { |
|
16 | 2082 |
echo '<p>' . sprintf( |
2083 |
/* translators: %s: https://apps.wordpress.org/ */ |
|
2084 |
__( '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.' ), |
|
2085 |
'https://apps.wordpress.org/' |
|
2086 |
) . '</p>'; |
|
0 | 2087 |
return; |
2088 |
} |
|
2089 |
||
9 | 2090 |
$upload_action_url = admin_url( 'async-upload.php' ); |
18 | 2091 |
$post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0; |
9 | 2092 |
$_type = isset( $type ) ? $type : ''; |
2093 |
$_tab = isset( $tab ) ? $tab : ''; |
|
0 | 2094 |
|
5 | 2095 |
$max_upload_size = wp_max_upload_size(); |
2096 |
if ( ! $max_upload_size ) { |
|
2097 |
$max_upload_size = 0; |
|
0 | 2098 |
} |
16 | 2099 |
|
9 | 2100 |
?> |
16 | 2101 |
<div id="media-upload-notice"> |
9 | 2102 |
<?php |
2103 |
||
2104 |
if ( isset( $errors['upload_notice'] ) ) { |
|
0 | 2105 |
echo $errors['upload_notice']; |
9 | 2106 |
} |
2107 |
||
2108 |
?> |
|
16 | 2109 |
</div> |
2110 |
<div id="media-upload-error"> |
|
9 | 2111 |
<?php |
2112 |
||
2113 |
if ( isset( $errors['upload_error'] ) && is_wp_error( $errors['upload_error'] ) ) { |
|
0 | 2114 |
echo $errors['upload_error']->get_error_message(); |
9 | 2115 |
} |
2116 |
||
2117 |
?> |
|
16 | 2118 |
</div> |
9 | 2119 |
<?php |
16 | 2120 |
|
9 | 2121 |
if ( is_multisite() && ! is_upload_space_available() ) { |
2122 |
/** |
|
2123 |
* Fires when an upload will exceed the defined upload space quota for a network site. |
|
2124 |
* |
|
2125 |
* @since 3.5.0 |
|
2126 |
*/ |
|
2127 |
do_action( 'upload_ui_over_quota' ); |
|
2128 |
return; |
|
2129 |
} |
|
2130 |
||
5 | 2131 |
/** |
9 | 2132 |
* Fires just before the legacy (pre-3.5.0) upload interface is loaded. |
5 | 2133 |
* |
9 | 2134 |
* @since 2.6.0 |
5 | 2135 |
*/ |
16 | 2136 |
do_action( 'pre-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
9 | 2137 |
|
2138 |
$post_params = array( |
|
2139 |
'post_id' => $post_id, |
|
2140 |
'_wpnonce' => wp_create_nonce( 'media-form' ), |
|
2141 |
'type' => $_type, |
|
2142 |
'tab' => $_tab, |
|
2143 |
'short' => '1', |
|
2144 |
); |
|
2145 |
||
2146 |
/** |
|
2147 |
* Filters the media upload post parameters. |
|
2148 |
* |
|
2149 |
* @since 3.1.0 As 'swfupload_post_params' |
|
2150 |
* @since 3.3.0 |
|
2151 |
* |
|
2152 |
* @param array $post_params An array of media upload parameters used by Plupload. |
|
2153 |
*/ |
|
2154 |
$post_params = apply_filters( 'upload_post_params', $post_params ); |
|
2155 |
||
2156 |
/* |
|
2157 |
* Since 4.9 the `runtimes` setting is hardcoded in our version of Plupload to `html5,html4`, |
|
2158 |
* and the `flash_swf_url` and `silverlight_xap_url` are not used. |
|
2159 |
*/ |
|
2160 |
$plupload_init = array( |
|
2161 |
'browse_button' => 'plupload-browse-button', |
|
2162 |
'container' => 'plupload-upload-ui', |
|
2163 |
'drop_element' => 'drag-drop-area', |
|
2164 |
'file_data_name' => 'async-upload', |
|
2165 |
'url' => $upload_action_url, |
|
16 | 2166 |
'filters' => array( 'max_file_size' => $max_upload_size . 'b' ), |
9 | 2167 |
'multipart_params' => $post_params, |
2168 |
); |
|
2169 |
||
16 | 2170 |
/* |
2171 |
* Currently only iOS Safari supports multiple files uploading, |
|
2172 |
* but iOS 7.x has a bug that prevents uploading of videos when enabled. |
|
2173 |
* See #29602. |
|
2174 |
*/ |
|
2175 |
if ( |
|
2176 |
wp_is_mobile() && |
|
2177 |
strpos( $_SERVER['HTTP_USER_AGENT'], 'OS 7_' ) !== false && |
|
2178 |
strpos( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' ) !== false |
|
2179 |
) { |
|
9 | 2180 |
$plupload_init['multi_selection'] = false; |
2181 |
} |
|
2182 |
||
18 | 2183 |
// Check if WebP images can be edited. |
2184 |
if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) { |
|
2185 |
$plupload_init['webp_upload_error'] = true; |
|
2186 |
} |
|
2187 |
||
9 | 2188 |
/** |
2189 |
* Filters the default Plupload settings. |
|
2190 |
* |
|
2191 |
* @since 3.3.0 |
|
2192 |
* |
|
2193 |
* @param array $plupload_init An array of default settings used by Plupload. |
|
2194 |
*/ |
|
2195 |
$plupload_init = apply_filters( 'plupload_init', $plupload_init ); |
|
2196 |
||
2197 |
?> |
|
16 | 2198 |
<script type="text/javascript"> |
9 | 2199 |
<?php |
2200 |
// Verify size is an int. If not return default value. |
|
2201 |
$large_size_h = absint( get_option( 'large_size_h' ) ); |
|
16 | 2202 |
|
9 | 2203 |
if ( ! $large_size_h ) { |
2204 |
$large_size_h = 1024; |
|
2205 |
} |
|
16 | 2206 |
|
9 | 2207 |
$large_size_w = absint( get_option( 'large_size_w' ) ); |
16 | 2208 |
|
9 | 2209 |
if ( ! $large_size_w ) { |
2210 |
$large_size_w = 1024; |
|
2211 |
} |
|
16 | 2212 |
|
9 | 2213 |
?> |
16 | 2214 |
var resize_height = <?php echo $large_size_h; ?>, resize_width = <?php echo $large_size_w; ?>, |
2215 |
wpUploaderInit = <?php echo wp_json_encode( $plupload_init ); ?>; |
|
2216 |
</script> |
|
2217 |
||
2218 |
<div id="plupload-upload-ui" class="hide-if-no-js"> |
|
9 | 2219 |
<?php |
2220 |
/** |
|
2221 |
* Fires before the upload interface loads. |
|
2222 |
* |
|
2223 |
* @since 2.6.0 As 'pre-flash-upload-ui' |
|
2224 |
* @since 3.3.0 |
|
2225 |
*/ |
|
16 | 2226 |
do_action( 'pre-plupload-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
2227 |
||
9 | 2228 |
?> |
16 | 2229 |
<div id="drag-drop-area"> |
2230 |
<div class="drag-drop-inside"> |
|
2231 |
<p class="drag-drop-info"><?php _e( 'Drop files to upload' ); ?></p> |
|
2232 |
<p><?php _ex( 'or', 'Uploader: Drop files here - or - Select Files' ); ?></p> |
|
2233 |
<p class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e( 'Select Files' ); ?>" class="button" /></p> |
|
2234 |
</div> |
|
0 | 2235 |
</div> |
9 | 2236 |
<?php |
2237 |
/** |
|
2238 |
* Fires after the upload interface loads. |
|
2239 |
* |
|
2240 |
* @since 2.6.0 As 'post-flash-upload-ui' |
|
2241 |
* @since 3.3.0 |
|
2242 |
*/ |
|
16 | 2243 |
do_action( 'post-plupload-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
9 | 2244 |
?> |
16 | 2245 |
</div> |
2246 |
||
2247 |
<div id="html-upload-ui" class="hide-if-js"> |
|
5 | 2248 |
<?php |
2249 |
/** |
|
2250 |
* Fires before the upload button in the media upload interface. |
|
2251 |
* |
|
2252 |
* @since 2.6.0 |
|
2253 |
*/ |
|
16 | 2254 |
do_action( 'pre-html-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
2255 |
||
5 | 2256 |
?> |
0 | 2257 |
<p id="async-upload-wrap"> |
9 | 2258 |
<label class="screen-reader-text" for="async-upload"><?php _e( 'Upload' ); ?></label> |
0 | 2259 |
<input type="file" name="async-upload" id="async-upload" /> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2260 |
<?php submit_button( __( 'Upload' ), 'primary', 'html-upload', false ); ?> |
9 | 2261 |
<a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e( 'Cancel' ); ?></a> |
0 | 2262 |
</p> |
2263 |
<div class="clear"></div> |
|
9 | 2264 |
<?php |
2265 |
/** |
|
2266 |
* Fires after the upload button in the media upload interface. |
|
2267 |
* |
|
2268 |
* @since 2.6.0 |
|
2269 |
*/ |
|
16 | 2270 |
do_action( 'post-html-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
2271 |
||
9 | 2272 |
?> |
16 | 2273 |
</div> |
2274 |
||
2275 |
<p class="max-upload-size"> |
|
2276 |
<?php |
|
2277 |
/* translators: %s: Maximum allowed file size. */ |
|
2278 |
printf( __( 'Maximum upload file size: %s.' ), esc_html( size_format( $max_upload_size ) ) ); |
|
2279 |
?> |
|
2280 |
</p> |
|
9 | 2281 |
<?php |
5 | 2282 |
|
2283 |
/** |
|
2284 |
* Fires on the post upload UI screen. |
|
2285 |
* |
|
2286 |
* Legacy (pre-3.5.0) media workflow hook. |
|
2287 |
* |
|
2288 |
* @since 2.6.0 |
|
2289 |
*/ |
|
16 | 2290 |
do_action( 'post-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
0 | 2291 |
} |
2292 |
||
2293 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2294 |
* Outputs the legacy media upload form for a given media type. |
0 | 2295 |
* |
2296 |
* @since 2.5.0 |
|
2297 |
* |
|
18 | 2298 |
* @param string $type |
2299 |
* @param array $errors |
|
2300 |
* @param int|WP_Error $id |
|
0 | 2301 |
*/ |
9 | 2302 |
function media_upload_type_form( $type = 'file', $errors = null, $id = null ) { |
0 | 2303 |
|
2304 |
media_upload_header(); |
|
2305 |
||
18 | 2306 |
$post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0; |
9 | 2307 |
|
2308 |
$form_action_url = admin_url( "media-upload.php?type=$type&tab=type&post_id=$post_id" ); |
|
5 | 2309 |
|
2310 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2311 |
* Filters the media upload form action URL. |
5 | 2312 |
* |
2313 |
* @since 2.6.0 |
|
2314 |
* |
|
2315 |
* @param string $form_action_url The media upload form action URL. |
|
2316 |
* @param string $type The type of media. Default 'file'. |
|
2317 |
*/ |
|
2318 |
$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type ); |
|
9 | 2319 |
$form_class = 'media-upload-form type-form validate'; |
2320 |
||
2321 |
if ( get_user_setting( 'uploader' ) ) { |
|
0 | 2322 |
$form_class .= ' html-uploader'; |
9 | 2323 |
} |
16 | 2324 |
|
9 | 2325 |
?> |
16 | 2326 |
<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form"> |
2327 |
<?php submit_button( '', 'hidden', 'save', false ); ?> |
|
2328 |
<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
|
2329 |
<?php wp_nonce_field( 'media-form' ); ?> |
|
2330 |
||
2331 |
<h3 class="media-title"><?php _e( 'Add media files from your computer' ); ?></h3> |
|
9 | 2332 |
|
2333 |
<?php media_upload_form( $errors ); ?> |
|
0 | 2334 |
|
16 | 2335 |
<script type="text/javascript"> |
2336 |
jQuery(function($){ |
|
2337 |
var preloaded = $(".media-item.preloaded"); |
|
2338 |
if ( preloaded.length > 0 ) { |
|
2339 |
preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
|
2340 |
} |
|
2341 |
updateMediaForm(); |
|
2342 |
}); |
|
2343 |
</script> |
|
2344 |
<div id="media-items"> |
|
9 | 2345 |
<?php |
2346 |
||
2347 |
if ( $id ) { |
|
2348 |
if ( ! is_wp_error( $id ) ) { |
|
2349 |
add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 ); |
|
2350 |
echo get_media_items( $id, $errors ); |
|
2351 |
} else { |
|
2352 |
echo '<div id="media-upload-error">' . esc_html( $id->get_error_message() ) . '</div></div>'; |
|
2353 |
exit; |
|
2354 |
} |
|
0 | 2355 |
} |
16 | 2356 |
|
9 | 2357 |
?> |
16 | 2358 |
</div> |
2359 |
||
2360 |
<p class="savebutton ml-submit"> |
|
2361 |
<?php submit_button( __( 'Save all changes' ), '', 'save', false ); ?> |
|
2362 |
</p> |
|
2363 |
</form> |
|
9 | 2364 |
<?php |
0 | 2365 |
} |
2366 |
||
2367 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2368 |
* Outputs the legacy media upload form for external media. |
0 | 2369 |
* |
2370 |
* @since 2.7.0 |
|
2371 |
* |
|
16 | 2372 |
* @param string $type |
2373 |
* @param object $errors |
|
18 | 2374 |
* @param int $id |
0 | 2375 |
*/ |
9 | 2376 |
function media_upload_type_url_form( $type = null, $errors = null, $id = null ) { |
2377 |
if ( null === $type ) { |
|
0 | 2378 |
$type = 'image'; |
9 | 2379 |
} |
0 | 2380 |
|
2381 |
media_upload_header(); |
|
2382 |
||
18 | 2383 |
$post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0; |
0 | 2384 |
|
9 | 2385 |
$form_action_url = admin_url( "media-upload.php?type=$type&tab=type&post_id=$post_id" ); |
5 | 2386 |
/** This filter is documented in wp-admin/includes/media.php */ |
2387 |
$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type ); |
|
9 | 2388 |
$form_class = 'media-upload-form type-form validate'; |
2389 |
||
2390 |
if ( get_user_setting( 'uploader' ) ) { |
|
0 | 2391 |
$form_class .= ' html-uploader'; |
9 | 2392 |
} |
16 | 2393 |
|
9 | 2394 |
?> |
16 | 2395 |
<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form"> |
2396 |
<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
|
2397 |
<?php wp_nonce_field( 'media-form' ); ?> |
|
2398 |
||
2399 |
<h3 class="media-title"><?php _e( 'Insert media from another website' ); ?></h3> |
|
2400 |
||
2401 |
<script type="text/javascript"> |
|
2402 |
var addExtImage = { |
|
0 | 2403 |
|
2404 |
width : '', |
|
2405 |
height : '', |
|
2406 |
align : 'alignnone', |
|
2407 |
||
2408 |
insert : function() { |
|
2409 |
var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = ''; |
|
2410 |
||
16 | 2411 |
if ( '' === f.src.value || '' === t.width ) |
0 | 2412 |
return false; |
2413 |
||
2414 |
if ( f.alt.value ) |
|
2415 |
alt = f.alt.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); |
|
2416 |
||
16 | 2417 |
<?php |
2418 |
/** This filter is documented in wp-admin/includes/media.php */ |
|
2419 |
if ( ! apply_filters( 'disable_captions', '' ) ) { |
|
2420 |
?> |
|
2421 |
if ( f.caption.value ) { |
|
2422 |
caption = f.caption.value.replace(/\r\n|\r/g, '\n'); |
|
2423 |
caption = caption.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){ |
|
2424 |
return a.replace(/[\r\n\t]+/, ' '); |
|
2425 |
}); |
|
2426 |
||
2427 |
caption = caption.replace(/\s*\n\s*/g, '<br />'); |
|
2428 |
} |
|
2429 |
<?php |
|
2430 |
} |
|
2431 |
||
5 | 2432 |
?> |
0 | 2433 |
cls = caption ? '' : ' class="'+t.align+'"'; |
2434 |
||
2435 |
html = '<img alt="'+alt+'" src="'+f.src.value+'"'+cls+' width="'+t.width+'" height="'+t.height+'" />'; |
|
2436 |
||
2437 |
if ( f.url.value ) { |
|
2438 |
url = f.url.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); |
|
2439 |
html = '<a href="'+url+'">'+html+'</a>'; |
|
2440 |
} |
|
2441 |
||
2442 |
if ( caption ) |
|
2443 |
html = '[caption id="" align="'+t.align+'" width="'+t.width+'"]'+html+caption+'[/caption]'; |
|
2444 |
||
2445 |
var win = window.dialogArguments || opener || parent || top; |
|
2446 |
win.send_to_editor(html); |
|
2447 |
return false; |
|
2448 |
}, |
|
2449 |
||
2450 |
resetImageData : function() { |
|
2451 |
var t = addExtImage; |
|
2452 |
||
2453 |
t.width = t.height = ''; |
|
2454 |
document.getElementById('go_button').style.color = '#bbb'; |
|
2455 |
if ( ! document.forms[0].src.value ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2456 |
document.getElementById('status_img').innerHTML = ''; |
0 | 2457 |
else document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/no.png' ) ); ?>" alt="" />'; |
2458 |
}, |
|
2459 |
||
2460 |
updateImageData : function() { |
|
2461 |
var t = addExtImage; |
|
2462 |
||
2463 |
t.width = t.preloadImg.width; |
|
2464 |
t.height = t.preloadImg.height; |
|
2465 |
document.getElementById('go_button').style.color = '#333'; |
|
2466 |
document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/yes.png' ) ); ?>" alt="" />'; |
|
2467 |
}, |
|
2468 |
||
2469 |
getImageData : function() { |
|
2470 |
if ( jQuery('table.describe').hasClass('not-image') ) |
|
2471 |
return; |
|
2472 |
||
2473 |
var t = addExtImage, src = document.forms[0].src.value; |
|
2474 |
||
2475 |
if ( ! src ) { |
|
2476 |
t.resetImageData(); |
|
2477 |
return false; |
|
2478 |
} |
|
2479 |
||
5 | 2480 |
document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/spinner-2x.gif' ) ); ?>" alt="" width="16" height="16" />'; |
0 | 2481 |
t.preloadImg = new Image(); |
2482 |
t.preloadImg.onload = t.updateImageData; |
|
2483 |
t.preloadImg.onerror = t.resetImageData; |
|
2484 |
t.preloadImg.src = src; |
|
2485 |
} |
|
16 | 2486 |
}; |
2487 |
||
19 | 2488 |
jQuery( function($) { |
16 | 2489 |
$('.media-types input').click( function() { |
2490 |
$('table.describe').toggleClass('not-image', $('#not-image').prop('checked') ); |
|
2491 |
}); |
|
19 | 2492 |
} ); |
16 | 2493 |
</script> |
2494 |
||
2495 |
<div id="media-items"> |
|
2496 |
<div class="media-item media-blank"> |
|
9 | 2497 |
<?php |
2498 |
/** |
|
2499 |
* Filters the insert media from URL form HTML. |
|
2500 |
* |
|
2501 |
* @since 3.3.0 |
|
2502 |
* |
|
2503 |
* @param string $form_html The insert from URL form HTML. |
|
2504 |
*/ |
|
2505 |
echo apply_filters( 'type_url_form_media', wp_media_insert_url_form( $type ) ); |
|
16 | 2506 |
|
9 | 2507 |
?> |
16 | 2508 |
</div> |
2509 |
</div> |
|
2510 |
</form> |
|
9 | 2511 |
<?php |
0 | 2512 |
} |
2513 |
||
2514 |
/** |
|
19 | 2515 |
* Adds gallery form to upload iframe. |
0 | 2516 |
* |
2517 |
* @since 2.5.0 |
|
2518 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2519 |
* @global string $redir_tab |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2520 |
* @global string $type |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2521 |
* @global string $tab |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2522 |
* |
0 | 2523 |
* @param array $errors |
2524 |
*/ |
|
9 | 2525 |
function media_upload_gallery_form( $errors ) { |
0 | 2526 |
global $redir_tab, $type; |
2527 |
||
2528 |
$redir_tab = 'gallery'; |
|
2529 |
media_upload_header(); |
|
2530 |
||
18 | 2531 |
$post_id = (int) $_REQUEST['post_id']; |
9 | 2532 |
$form_action_url = admin_url( "media-upload.php?type=$type&tab=gallery&post_id=$post_id" ); |
5 | 2533 |
/** This filter is documented in wp-admin/includes/media.php */ |
2534 |
$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type ); |
|
9 | 2535 |
$form_class = 'media-upload-form validate'; |
2536 |
||
2537 |
if ( get_user_setting( 'uploader' ) ) { |
|
0 | 2538 |
$form_class .= ' html-uploader'; |
9 | 2539 |
} |
16 | 2540 |
|
9 | 2541 |
?> |
16 | 2542 |
<script type="text/javascript"> |
2543 |
jQuery(function($){ |
|
2544 |
var preloaded = $(".media-item.preloaded"); |
|
2545 |
if ( preloaded.length > 0 ) { |
|
2546 |
preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
|
2547 |
updateMediaForm(); |
|
2548 |
} |
|
2549 |
}); |
|
2550 |
</script> |
|
2551 |
<div id="sort-buttons" class="hide-if-no-js"> |
|
2552 |
<span> |
|
2553 |
<?php _e( 'All Tabs:' ); ?> |
|
2554 |
<a href="#" id="showall"><?php _e( 'Show' ); ?></a> |
|
2555 |
<a href="#" id="hideall" style="display:none;"><?php _e( 'Hide' ); ?></a> |
|
2556 |
</span> |
|
2557 |
<?php _e( 'Sort Order:' ); ?> |
|
2558 |
<a href="#" id="asc"><?php _e( 'Ascending' ); ?></a> | |
|
2559 |
<a href="#" id="desc"><?php _e( 'Descending' ); ?></a> | |
|
2560 |
<a href="#" id="clear"><?php _ex( 'Clear', 'verb' ); ?></a> |
|
2561 |
</div> |
|
2562 |
<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="gallery-form"> |
|
2563 |
<?php wp_nonce_field( 'media-form' ); ?> |
|
2564 |
<table class="widefat"> |
|
2565 |
<thead><tr> |
|
2566 |
<th><?php _e( 'Media' ); ?></th> |
|
2567 |
<th class="order-head"><?php _e( 'Order' ); ?></th> |
|
2568 |
<th class="actions-head"><?php _e( 'Actions' ); ?></th> |
|
2569 |
</tr></thead> |
|
2570 |
</table> |
|
2571 |
<div id="media-items"> |
|
2572 |
<?php add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 ); ?> |
|
2573 |
<?php echo get_media_items( $post_id, $errors ); ?> |
|
2574 |
</div> |
|
2575 |
||
2576 |
<p class="ml-submit"> |
|
2577 |
<?php |
|
2578 |
submit_button( |
|
2579 |
__( 'Save all changes' ), |
|
2580 |
'savebutton', |
|
2581 |
'save', |
|
2582 |
false, |
|
2583 |
array( |
|
2584 |
'id' => 'save-all', |
|
2585 |
'style' => 'display: none;', |
|
2586 |
) |
|
2587 |
); |
|
2588 |
?> |
|
2589 |
<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
|
2590 |
<input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" /> |
|
2591 |
<input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" /> |
|
2592 |
</p> |
|
2593 |
||
2594 |
<div id="gallery-settings" style="display:none;"> |
|
2595 |
<div class="title"><?php _e( 'Gallery Settings' ); ?></div> |
|
2596 |
<table id="basic" class="describe"><tbody> |
|
2597 |
<tr> |
|
2598 |
<th scope="row" class="label"> |
|
2599 |
<label> |
|
2600 |
<span class="alignleft"><?php _e( 'Link thumbnails to:' ); ?></span> |
|
2601 |
</label> |
|
2602 |
</th> |
|
2603 |
<td class="field"> |
|
2604 |
<input type="radio" name="linkto" id="linkto-file" value="file" /> |
|
2605 |
<label for="linkto-file" class="radio"><?php _e( 'Image File' ); ?></label> |
|
2606 |
||
2607 |
<input type="radio" checked="checked" name="linkto" id="linkto-post" value="post" /> |
|
2608 |
<label for="linkto-post" class="radio"><?php _e( 'Attachment Page' ); ?></label> |
|
2609 |
</td> |
|
2610 |
</tr> |
|
2611 |
||
2612 |
<tr> |
|
2613 |
<th scope="row" class="label"> |
|
2614 |
<label> |
|
2615 |
<span class="alignleft"><?php _e( 'Order images by:' ); ?></span> |
|
2616 |
</label> |
|
2617 |
</th> |
|
2618 |
<td class="field"> |
|
2619 |
<select id="orderby" name="orderby"> |
|
2620 |
<option value="menu_order" selected="selected"><?php _e( 'Menu order' ); ?></option> |
|
2621 |
<option value="title"><?php _e( 'Title' ); ?></option> |
|
2622 |
<option value="post_date"><?php _e( 'Date/Time' ); ?></option> |
|
2623 |
<option value="rand"><?php _e( 'Random' ); ?></option> |
|
2624 |
</select> |
|
2625 |
</td> |
|
2626 |
</tr> |
|
2627 |
||
2628 |
<tr> |
|
2629 |
<th scope="row" class="label"> |
|
2630 |
<label> |
|
2631 |
<span class="alignleft"><?php _e( 'Order:' ); ?></span> |
|
2632 |
</label> |
|
2633 |
</th> |
|
2634 |
<td class="field"> |
|
2635 |
<input type="radio" checked="checked" name="order" id="order-asc" value="asc" /> |
|
2636 |
<label for="order-asc" class="radio"><?php _e( 'Ascending' ); ?></label> |
|
2637 |
||
2638 |
<input type="radio" name="order" id="order-desc" value="desc" /> |
|
2639 |
<label for="order-desc" class="radio"><?php _e( 'Descending' ); ?></label> |
|
2640 |
</td> |
|
2641 |
</tr> |
|
2642 |
||
2643 |
<tr> |
|
2644 |
<th scope="row" class="label"> |
|
2645 |
<label> |
|
2646 |
<span class="alignleft"><?php _e( 'Gallery columns:' ); ?></span> |
|
2647 |
</label> |
|
2648 |
</th> |
|
2649 |
<td class="field"> |
|
2650 |
<select id="columns" name="columns"> |
|
2651 |
<option value="1">1</option> |
|
2652 |
<option value="2">2</option> |
|
2653 |
<option value="3" selected="selected">3</option> |
|
2654 |
<option value="4">4</option> |
|
2655 |
<option value="5">5</option> |
|
2656 |
<option value="6">6</option> |
|
2657 |
<option value="7">7</option> |
|
2658 |
<option value="8">8</option> |
|
2659 |
<option value="9">9</option> |
|
2660 |
</select> |
|
2661 |
</td> |
|
2662 |
</tr> |
|
2663 |
</tbody></table> |
|
2664 |
||
2665 |
<p class="ml-submit"> |
|
2666 |
<input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="insert-gallery" id="insert-gallery" value="<?php esc_attr_e( 'Insert gallery' ); ?>" /> |
|
2667 |
<input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="update-gallery" id="update-gallery" value="<?php esc_attr_e( 'Update gallery settings' ); ?>" /> |
|
2668 |
</p> |
|
2669 |
</div> |
|
2670 |
</form> |
|
9 | 2671 |
<?php |
0 | 2672 |
} |
2673 |
||
2674 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2675 |
* Outputs the legacy media upload form for the media library. |
0 | 2676 |
* |
2677 |
* @since 2.5.0 |
|
2678 |
* |
|
16 | 2679 |
* @global wpdb $wpdb WordPress database abstraction object. |
2680 |
* @global WP_Query $wp_query WordPress Query object. |
|
2681 |
* @global WP_Locale $wp_locale WordPress date and time locale object. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2682 |
* @global string $type |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2683 |
* @global string $tab |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2684 |
* @global array $post_mime_types |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2685 |
* |
0 | 2686 |
* @param array $errors |
2687 |
*/ |
|
9 | 2688 |
function media_upload_library_form( $errors ) { |
0 | 2689 |
global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types; |
2690 |
||
2691 |
media_upload_header(); |
|
2692 |
||
18 | 2693 |
$post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0; |
0 | 2694 |
|
9 | 2695 |
$form_action_url = admin_url( "media-upload.php?type=$type&tab=library&post_id=$post_id" ); |
5 | 2696 |
/** This filter is documented in wp-admin/includes/media.php */ |
2697 |
$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type ); |
|
9 | 2698 |
$form_class = 'media-upload-form validate'; |
2699 |
||
2700 |
if ( get_user_setting( 'uploader' ) ) { |
|
0 | 2701 |
$form_class .= ' html-uploader'; |
9 | 2702 |
} |
2703 |
||
2704 |
$q = $_GET; |
|
5 | 2705 |
$q['posts_per_page'] = 10; |
18 | 2706 |
$q['paged'] = isset( $q['paged'] ) ? (int) $q['paged'] : 0; |
5 | 2707 |
if ( $q['paged'] < 1 ) { |
2708 |
$q['paged'] = 1; |
|
2709 |
} |
|
2710 |
$q['offset'] = ( $q['paged'] - 1 ) * 10; |
|
2711 |
if ( $q['offset'] < 1 ) { |
|
2712 |
$q['offset'] = 0; |
|
2713 |
} |
|
2714 |
||
2715 |
list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query( $q ); |
|
0 | 2716 |
|
9 | 2717 |
?> |
16 | 2718 |
<form id="filter" method="get"> |
2719 |
<input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" /> |
|
2720 |
<input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" /> |
|
2721 |
<input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" /> |
|
2722 |
<input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" /> |
|
2723 |
<input type="hidden" name="context" value="<?php echo isset( $_GET['context'] ) ? esc_attr( $_GET['context'] ) : ''; ?>" /> |
|
2724 |
||
2725 |
<p id="media-search" class="search-box"> |
|
2726 |
<label class="screen-reader-text" for="media-search-input"><?php _e( 'Search Media' ); ?>:</label> |
|
2727 |
<input type="search" id="media-search-input" name="s" value="<?php the_search_query(); ?>" /> |
|
2728 |
<?php submit_button( __( 'Search Media' ), '', '', false ); ?> |
|
2729 |
</p> |
|
2730 |
||
2731 |
<ul class="subsubsub"> |
|
2732 |
<?php |
|
2733 |
$type_links = array(); |
|
2734 |
$_num_posts = (array) wp_count_attachments(); |
|
2735 |
$matches = wp_match_mime_types( array_keys( $post_mime_types ), array_keys( $_num_posts ) ); |
|
2736 |
foreach ( $matches as $_type => $reals ) { |
|
2737 |
foreach ( $reals as $real ) { |
|
2738 |
if ( isset( $num_posts[ $_type ] ) ) { |
|
2739 |
$num_posts[ $_type ] += $_num_posts[ $real ]; |
|
2740 |
} else { |
|
2741 |
$num_posts[ $_type ] = $_num_posts[ $real ]; |
|
2742 |
} |
|
9 | 2743 |
} |
2744 |
} |
|
16 | 2745 |
// If available type specified by media button clicked, filter by that type. |
2746 |
if ( empty( $_GET['post_mime_type'] ) && ! empty( $num_posts[ $type ] ) ) { |
|
2747 |
$_GET['post_mime_type'] = $type; |
|
2748 |
list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); |
|
9 | 2749 |
} |
16 | 2750 |
if ( empty( $_GET['post_mime_type'] ) || 'all' === $_GET['post_mime_type'] ) { |
9 | 2751 |
$class = ' class="current"'; |
16 | 2752 |
} else { |
2753 |
$class = ''; |
|
9 | 2754 |
} |
2755 |
$type_links[] = '<li><a href="' . esc_url( |
|
2756 |
add_query_arg( |
|
2757 |
array( |
|
16 | 2758 |
'post_mime_type' => 'all', |
9 | 2759 |
'paged' => false, |
16 | 2760 |
'm' => false, |
9 | 2761 |
) |
2762 |
) |
|
16 | 2763 |
) . '"' . $class . '>' . __( 'All Types' ) . '</a>'; |
2764 |
foreach ( $post_mime_types as $mime_type => $label ) { |
|
2765 |
$class = ''; |
|
2766 |
||
2767 |
if ( ! wp_match_mime_types( $mime_type, $avail_post_mime_types ) ) { |
|
9 | 2768 |
continue; |
2769 |
} |
|
16 | 2770 |
|
2771 |
if ( isset( $_GET['post_mime_type'] ) && wp_match_mime_types( $mime_type, $_GET['post_mime_type'] ) ) { |
|
2772 |
$class = ' class="current"'; |
|
9 | 2773 |
} |
2774 |
||
16 | 2775 |
$type_links[] = '<li><a href="' . esc_url( |
2776 |
add_query_arg( |
|
2777 |
array( |
|
2778 |
'post_mime_type' => $mime_type, |
|
2779 |
'paged' => false, |
|
2780 |
) |
|
2781 |
) |
|
2782 |
) . '"' . $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>'; |
|
2783 |
} |
|
2784 |
/** |
|
2785 |
* Filters the media upload mime type list items. |
|
2786 |
* |
|
2787 |
* Returned values should begin with an `<li>` tag. |
|
2788 |
* |
|
2789 |
* @since 3.1.0 |
|
2790 |
* |
|
2791 |
* @param string[] $type_links An array of list items containing mime type link HTML. |
|
2792 |
*/ |
|
2793 |
echo implode( ' | </li>', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '</li>'; |
|
2794 |
unset( $type_links ); |
|
2795 |
?> |
|
2796 |
</ul> |
|
2797 |
||
2798 |
<div class="tablenav"> |
|
2799 |
||
2800 |
<?php |
|
2801 |
$page_links = paginate_links( |
|
2802 |
array( |
|
2803 |
'base' => add_query_arg( 'paged', '%#%' ), |
|
2804 |
'format' => '', |
|
2805 |
'prev_text' => __( '«' ), |
|
2806 |
'next_text' => __( '»' ), |
|
2807 |
'total' => ceil( $wp_query->found_posts / 10 ), |
|
2808 |
'current' => $q['paged'], |
|
2809 |
) |
|
2810 |
); |
|
2811 |
||
2812 |
if ( $page_links ) { |
|
2813 |
echo "<div class='tablenav-pages'>$page_links</div>"; |
|
9 | 2814 |
} |
2815 |
?> |
|
16 | 2816 |
|
2817 |
<div class="alignleft actions"> |
|
2818 |
<?php |
|
2819 |
||
2820 |
$arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC"; |
|
2821 |
||
2822 |
$arc_result = $wpdb->get_results( $arc_query ); |
|
2823 |
||
2824 |
$month_count = count( $arc_result ); |
|
2825 |
$selected_month = isset( $_GET['m'] ) ? $_GET['m'] : 0; |
|
2826 |
||
2827 |
if ( $month_count && ! ( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { |
|
2828 |
?> |
|
2829 |
<select name='m'> |
|
2830 |
<option<?php selected( $selected_month, 0 ); ?> value='0'><?php _e( 'All dates' ); ?></option> |
|
2831 |
<?php |
|
2832 |
||
2833 |
foreach ( $arc_result as $arc_row ) { |
|
2834 |
if ( 0 == $arc_row->yyear ) { |
|
2835 |
continue; |
|
2836 |
} |
|
2837 |
||
2838 |
$arc_row->mmonth = zeroise( $arc_row->mmonth, 2 ); |
|
2839 |
||
2840 |
if ( $arc_row->yyear . $arc_row->mmonth == $selected_month ) { |
|
2841 |
$default = ' selected="selected"'; |
|
2842 |
} else { |
|
2843 |
$default = ''; |
|
2844 |
} |
|
2845 |
||
2846 |
echo "<option$default value='" . esc_attr( $arc_row->yyear . $arc_row->mmonth ) . "'>"; |
|
2847 |
echo esc_html( $wp_locale->get_month( $arc_row->mmonth ) . " $arc_row->yyear" ); |
|
2848 |
echo "</option>\n"; |
|
2849 |
} |
|
2850 |
||
2851 |
?> |
|
2852 |
</select> |
|
2853 |
<?php } ?> |
|
2854 |
||
2855 |
<?php submit_button( __( 'Filter »' ), '', 'post-query-submit', false ); ?> |
|
2856 |
||
2857 |
</div> |
|
2858 |
||
2859 |
<br class="clear" /> |
|
2860 |
</div> |
|
2861 |
</form> |
|
2862 |
||
2863 |
<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="library-form"> |
|
9 | 2864 |
<?php wp_nonce_field( 'media-form' ); ?> |
16 | 2865 |
|
2866 |
<script type="text/javascript"> |
|
2867 |
jQuery(function($){ |
|
2868 |
var preloaded = $(".media-item.preloaded"); |
|
2869 |
if ( preloaded.length > 0 ) { |
|
2870 |
preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
|
2871 |
updateMediaForm(); |
|
2872 |
} |
|
2873 |
}); |
|
2874 |
</script> |
|
2875 |
||
2876 |
<div id="media-items"> |
|
2877 |
<?php add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 ); ?> |
|
2878 |
<?php echo get_media_items( null, $errors ); ?> |
|
2879 |
</div> |
|
2880 |
<p class="ml-submit"> |
|
2881 |
<?php submit_button( __( 'Save all changes' ), 'savebutton', 'save', false ); ?> |
|
2882 |
<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
|
2883 |
</p> |
|
2884 |
</form> |
|
9 | 2885 |
<?php |
0 | 2886 |
} |
2887 |
||
2888 |
/** |
|
19 | 2889 |
* Creates the form for external url. |
0 | 2890 |
* |
2891 |
* @since 2.7.0 |
|
2892 |
* |
|
2893 |
* @param string $default_view |
|
19 | 2894 |
* @return string HTML content of the form. |
0 | 2895 |
*/ |
2896 |
function wp_media_insert_url_form( $default_view = 'image' ) { |
|
5 | 2897 |
/** This filter is documented in wp-admin/includes/media.php */ |
2898 |
if ( ! apply_filters( 'disable_captions', '' ) ) { |
|
0 | 2899 |
$caption = ' |
2900 |
<tr class="image-only"> |
|
5 | 2901 |
<th scope="row" class="label"> |
9 | 2902 |
<label for="caption"><span class="alignleft">' . __( 'Image Caption' ) . '</span></label> |
0 | 2903 |
</th> |
2904 |
<td class="field"><textarea id="caption" name="caption"></textarea></td> |
|
16 | 2905 |
</tr>'; |
0 | 2906 |
} else { |
2907 |
$caption = ''; |
|
2908 |
} |
|
2909 |
||
9 | 2910 |
$default_align = get_option( 'image_default_align' ); |
16 | 2911 |
|
9 | 2912 |
if ( empty( $default_align ) ) { |
0 | 2913 |
$default_align = 'none'; |
9 | 2914 |
} |
0 | 2915 |
|
16 | 2916 |
if ( 'image' === $default_view ) { |
9 | 2917 |
$view = 'image-only'; |
0 | 2918 |
$table_class = ''; |
2919 |
} else { |
|
16 | 2920 |
$view = 'not-image'; |
2921 |
$table_class = $view; |
|
0 | 2922 |
} |
2923 |
||
2924 |
return ' |
|
2925 |
<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> |
|
16 | 2926 |
<p class="media-types media-types-required-info">' . |
2927 |
/* translators: %s: Asterisk symbol (*). */ |
|
2928 |
sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) . |
|
2929 |
'</p> |
|
0 | 2930 |
<table class="describe ' . $table_class . '"><tbody> |
2931 |
<tr> |
|
5 | 2932 |
<th scope="row" class="label" style="width:130px;"> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2933 |
<label for="src"><span class="alignleft">' . __( 'URL' ) . '</span> <span class="required">*</span></label> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2934 |
<span class="alignright" id="status_img"></span> |
0 | 2935 |
</th> |
9 | 2936 |
<td class="field"><input id="src" name="src" value="" type="text" required onblur="addExtImage.getImageData()" /></td> |
0 | 2937 |
</tr> |
2938 |
||
2939 |
<tr> |
|
5 | 2940 |
<th scope="row" class="label"> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2941 |
<label for="title"><span class="alignleft">' . __( 'Title' ) . '</span> <span class="required">*</span></label> |
0 | 2942 |
</th> |
9 | 2943 |
<td class="field"><input id="title" name="title" value="" type="text" required /></td> |
0 | 2944 |
</tr> |
2945 |
||
9 | 2946 |
<tr class="not-image"><td></td><td><p class="help">' . __( 'Link text, e.g. “Ransom Demands (PDF)”' ) . '</p></td></tr> |
0 | 2947 |
|
2948 |
<tr class="image-only"> |
|
5 | 2949 |
<th scope="row" class="label"> |
9 | 2950 |
<label for="alt"><span class="alignleft">' . __( 'Alternative Text' ) . '</span></label> |
0 | 2951 |
</th> |
9 | 2952 |
<td class="field"><input id="alt" name="alt" value="" type="text" required /> |
2953 |
<p class="help">' . __( 'Alt text for the image, e.g. “The Mona Lisa”' ) . '</p></td> |
|
0 | 2954 |
</tr> |
2955 |
' . $caption . ' |
|
2956 |
<tr class="align image-only"> |
|
9 | 2957 |
<th scope="row" class="label"><p><label for="align">' . __( 'Alignment' ) . '</label></p></th> |
0 | 2958 |
<td class="field"> |
16 | 2959 |
<input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ( 'none' === $default_align ? ' checked="checked"' : '' ) . ' /> |
9 | 2960 |
<label for="align-none" class="align image-align-none-label">' . __( 'None' ) . '</label> |
16 | 2961 |
<input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ( 'left' === $default_align ? ' checked="checked"' : '' ) . ' /> |
9 | 2962 |
<label for="align-left" class="align image-align-left-label">' . __( 'Left' ) . '</label> |
16 | 2963 |
<input name="align" id="align-center" value="center" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ( 'center' === $default_align ? ' checked="checked"' : '' ) . ' /> |
9 | 2964 |
<label for="align-center" class="align image-align-center-label">' . __( 'Center' ) . '</label> |
16 | 2965 |
<input name="align" id="align-right" value="right" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ( 'right' === $default_align ? ' checked="checked"' : '' ) . ' /> |
9 | 2966 |
<label for="align-right" class="align image-align-right-label">' . __( 'Right' ) . '</label> |
0 | 2967 |
</td> |
2968 |
</tr> |
|
2969 |
||
2970 |
<tr class="image-only"> |
|
5 | 2971 |
<th scope="row" class="label"> |
9 | 2972 |
<label for="url"><span class="alignleft">' . __( 'Link Image To:' ) . '</span></label> |
0 | 2973 |
</th> |
2974 |
<td class="field"><input id="url" name="url" value="" type="text" /><br /> |
|
2975 |
||
9 | 2976 |
<button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __( 'None' ) . '</button> |
2977 |
<button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __( 'Link to image' ) . '</button> |
|
2978 |
<p class="help">' . __( 'Enter a link URL or click above for presets.' ) . '</p></td> |
|
0 | 2979 |
</tr> |
2980 |
<tr class="image-only"> |
|
2981 |
<td></td> |
|
2982 |
<td> |
|
9 | 2983 |
<input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__( 'Insert into Post' ) . '" /> |
0 | 2984 |
</td> |
2985 |
</tr> |
|
2986 |
<tr class="not-image"> |
|
2987 |
<td></td> |
|
2988 |
<td> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2989 |
' . get_submit_button( __( 'Insert into Post' ), '', 'insertonlybutton', false ) . ' |
0 | 2990 |
</td> |
2991 |
</tr> |
|
16 | 2992 |
</tbody></table>'; |
0 | 2993 |
} |
2994 |
||
2995 |
/** |
|
2996 |
* Displays the multi-file uploader message. |
|
2997 |
* |
|
2998 |
* @since 2.6.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2999 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3000 |
* @global int $post_ID |
0 | 3001 |
*/ |
3002 |
function media_upload_flash_bypass() { |
|
3003 |
$browser_uploader = admin_url( 'media-new.php?browser-uploader' ); |
|
3004 |
||
16 | 3005 |
$post = get_post(); |
3006 |
if ( $post ) { |
|
18 | 3007 |
$browser_uploader .= '&post_id=' . (int) $post->ID; |
9 | 3008 |
} elseif ( ! empty( $GLOBALS['post_ID'] ) ) { |
18 | 3009 |
$browser_uploader .= '&post_id=' . (int) $GLOBALS['post_ID']; |
9 | 3010 |
} |
0 | 3011 |
|
3012 |
?> |
|
3013 |
<p class="upload-flash-bypass"> |
|
16 | 3014 |
<?php |
3015 |
printf( |
|
3016 |
/* translators: 1: URL to browser uploader, 2: Additional link attributes. */ |
|
3017 |
__( 'You are using the multi-file uploader. Problems? Try the <a href="%1$s" %2$s>browser uploader</a> instead.' ), |
|
3018 |
$browser_uploader, |
|
3019 |
'target="_blank"' |
|
3020 |
); |
|
3021 |
?> |
|
0 | 3022 |
</p> |
3023 |
<?php |
|
3024 |
} |
|
3025 |
||
3026 |
/** |
|
3027 |
* Displays the browser's built-in uploader message. |
|
3028 |
* |
|
3029 |
* @since 2.6.0 |
|
3030 |
*/ |
|
3031 |
function media_upload_html_bypass() { |
|
3032 |
?> |
|
3033 |
<p class="upload-html-bypass hide-if-no-js"> |
|
9 | 3034 |
<?php _e( 'You are using the browser’s built-in file uploader. The WordPress uploader includes multiple file selection and drag and drop capability. <a href="#">Switch to the multi-file uploader</a>.' ); ?> |
0 | 3035 |
</p> |
3036 |
<?php |
|
3037 |
} |
|
3038 |
||
3039 |
/** |
|
3040 |
* Used to display a "After a file has been uploaded..." help message. |
|
3041 |
* |
|
3042 |
* @since 3.3.0 |
|
3043 |
*/ |
|
3044 |
function media_upload_text_after() {} |
|
3045 |
||
3046 |
/** |
|
3047 |
* Displays the checkbox to scale images. |
|
3048 |
* |
|
3049 |
* @since 3.3.0 |
|
3050 |
*/ |
|
3051 |
function media_upload_max_image_resize() { |
|
9 | 3052 |
$checked = get_user_setting( 'upload_resize' ) ? ' checked="true"' : ''; |
16 | 3053 |
$a = ''; |
3054 |
$end = ''; |
|
0 | 3055 |
|
3056 |
if ( current_user_can( 'manage_options' ) ) { |
|
9 | 3057 |
$a = '<a href="' . esc_url( admin_url( 'options-media.php' ) ) . '" target="_blank">'; |
0 | 3058 |
$end = '</a>'; |
3059 |
} |
|
16 | 3060 |
|
9 | 3061 |
?> |
16 | 3062 |
<p class="hide-if-no-js"><label> |
3063 |
<input name="image_resize" type="checkbox" id="image_resize" value="true"<?php echo $checked; ?> /> |
|
9 | 3064 |
<?php |
16 | 3065 |
/* translators: 1: Link start tag, 2: Link end tag, 3: Width, 4: Height. */ |
0 | 3066 |
printf( __( 'Scale images to match the large size selected in %1$simage options%2$s (%3$d × %4$d).' ), $a, $end, (int) get_option( 'large_size_w', '1024' ), (int) get_option( 'large_size_h', '1024' ) ); |
16 | 3067 |
|
9 | 3068 |
?> |
16 | 3069 |
</label></p> |
9 | 3070 |
<?php |
0 | 3071 |
} |
3072 |
||
3073 |
/** |
|
3074 |
* Displays the out of storage quota message in Multisite. |
|
3075 |
* |
|
3076 |
* @since 3.5.0 |
|
3077 |
*/ |
|
3078 |
function multisite_over_quota_message() { |
|
9 | 3079 |
echo '<p>' . sprintf( |
16 | 3080 |
/* translators: %s: Allowed space allocation. */ |
9 | 3081 |
__( 'Sorry, you have used your space allocation of %s. Please delete some files to upload more files.' ), |
3082 |
size_format( get_space_allowed() * MB_IN_BYTES ) |
|
3083 |
) . '</p>'; |
|
0 | 3084 |
} |
3085 |
||
3086 |
/** |
|
3087 |
* Displays the image and editor in the post editor |
|
3088 |
* |
|
3089 |
* @since 3.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3090 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3091 |
* @param WP_Post $post A post object. |
0 | 3092 |
*/ |
3093 |
function edit_form_image_editor( $post ) { |
|
3094 |
$open = isset( $_GET['image-editor'] ); |
|
16 | 3095 |
|
9 | 3096 |
if ( $open ) { |
0 | 3097 |
require_once ABSPATH . 'wp-admin/includes/image-edit.php'; |
9 | 3098 |
} |
0 | 3099 |
|
16 | 3100 |
$thumb_url = false; |
18 | 3101 |
$attachment_id = (int) $post->ID; |
16 | 3102 |
|
3103 |
if ( $attachment_id ) { |
|
0 | 3104 |
$thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 450 ), true ); |
9 | 3105 |
} |
0 | 3106 |
|
3107 |
$alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true ); |
|
3108 |
||
9 | 3109 |
$att_url = wp_get_attachment_url( $post->ID ); |
3110 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3111 |
<div class="wp_attachment_holder wp-clearfix"> |
0 | 3112 |
<?php |
16 | 3113 |
|
0 | 3114 |
if ( wp_attachment_is_image( $post->ID ) ) : |
3115 |
$image_edit_button = ''; |
|
3116 |
if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { |
|
9 | 3117 |
$nonce = wp_create_nonce( "image_editor-$post->ID" ); |
0 | 3118 |
$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>"; |
3119 |
} |
|
9 | 3120 |
|
16 | 3121 |
$open_style = ''; |
3122 |
$not_open_style = ''; |
|
3123 |
||
9 | 3124 |
if ( $open ) { |
3125 |
$open_style = ' style="display:none"'; |
|
3126 |
} else { |
|
3127 |
$not_open_style = ' style="display:none"'; |
|
3128 |
} |
|
16 | 3129 |
|
9 | 3130 |
?> |
0 | 3131 |
<div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div> |
3132 |
||
9 | 3133 |
<div<?php echo $open_style; ?> class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>"> |
0 | 3134 |
<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> |
3135 |
<p><?php echo $image_edit_button; ?></p> |
|
3136 |
</div> |
|
9 | 3137 |
<div<?php echo $not_open_style; ?> class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"> |
16 | 3138 |
<?php |
3139 |
||
3140 |
if ( $open ) { |
|
3141 |
wp_image_editor( $attachment_id ); |
|
3142 |
} |
|
3143 |
||
3144 |
?> |
|
0 | 3145 |
</div> |
9 | 3146 |
<?php |
3147 |
elseif ( $attachment_id && wp_attachment_is( 'audio', $post ) ) : |
|
5 | 3148 |
|
3149 |
wp_maybe_generate_attachment_metadata( $post ); |
|
0 | 3150 |
|
3151 |
echo wp_audio_shortcode( array( 'src' => $att_url ) ); |
|
3152 |
||
9 | 3153 |
elseif ( $attachment_id && wp_attachment_is( 'video', $post ) ) : |
5 | 3154 |
|
3155 |
wp_maybe_generate_attachment_metadata( $post ); |
|
0 | 3156 |
|
3157 |
$meta = wp_get_attachment_metadata( $attachment_id ); |
|
9 | 3158 |
$w = ! empty( $meta['width'] ) ? min( $meta['width'], 640 ) : 0; |
3159 |
$h = ! empty( $meta['height'] ) ? $meta['height'] : 0; |
|
16 | 3160 |
|
5 | 3161 |
if ( $h && $w < $meta['width'] ) { |
0 | 3162 |
$h = round( ( $meta['height'] * $w ) / $meta['width'] ); |
5 | 3163 |
} |
0 | 3164 |
|
3165 |
$attr = array( 'src' => $att_url ); |
|
16 | 3166 |
|
5 | 3167 |
if ( ! empty( $w ) && ! empty( $h ) ) { |
9 | 3168 |
$attr['width'] = $w; |
0 | 3169 |
$attr['height'] = $h; |
5 | 3170 |
} |
3171 |
||
3172 |
$thumb_id = get_post_thumbnail_id( $attachment_id ); |
|
16 | 3173 |
|
5 | 3174 |
if ( ! empty( $thumb_id ) ) { |
3175 |
$attr['poster'] = wp_get_attachment_url( $thumb_id ); |
|
3176 |
} |
|
0 | 3177 |
|
3178 |
echo wp_video_shortcode( $attr ); |
|
3179 |
||
9 | 3180 |
elseif ( isset( $thumb_url[0] ) ) : |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3181 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3182 |
<div class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3183 |
<p id="thumbnail-head-<?php echo $attachment_id; ?>"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3184 |
<img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" /> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3185 |
</p> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3186 |
</div> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3187 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3188 |
|
9 | 3189 |
else : |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3190 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3191 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3192 |
* Fires when an attachment type can't be rendered in the edit form. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3193 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3194 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3195 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3196 |
* @param WP_Post $post A post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3197 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3198 |
do_action( 'wp_edit_form_attachment_display', $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3199 |
|
9 | 3200 |
endif; |
16 | 3201 |
|
9 | 3202 |
?> |
0 | 3203 |
</div> |
3204 |
<div class="wp_attachment_details edit-form-section"> |
|
9 | 3205 |
<?php if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) : ?> |
3206 |
<p class="attachment-alt-text"> |
|
3207 |
<label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br /> |
|
3208 |
<input type="text" class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" aria-describedby="alt-text-description" value="<?php echo esc_attr( $alt_text ); ?>" /> |
|
3209 |
</p> |
|
3210 |
<p class="attachment-alt-text-description" id="alt-text-description"> |
|
16 | 3211 |
<?php |
3212 |
||
3213 |
printf( |
|
3214 |
/* translators: 1: Link to tutorial, 2: Additional link attributes, 3: Accessibility text. */ |
|
19 | 3215 |
__( '<a href="%1$s" %2$s>Learn how to describe the purpose of the image%3$s</a>. Leave empty if the image is purely decorative.' ), |
16 | 3216 |
esc_url( 'https://www.w3.org/WAI/tutorials/images/decision-tree' ), |
18 | 3217 |
'target="_blank" rel="noopener"', |
16 | 3218 |
sprintf( |
3219 |
'<span class="screen-reader-text"> %s</span>', |
|
3220 |
/* translators: Accessibility text. */ |
|
3221 |
__( '(opens in a new tab)' ) |
|
3222 |
) |
|
3223 |
); |
|
3224 |
||
3225 |
?> |
|
9 | 3226 |
</p> |
3227 |
<?php endif; ?> |
|
3228 |
||
0 | 3229 |
<p> |
3230 |
<label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br /> |
|
3231 |
<textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea> |
|
3232 |
</p> |
|
3233 |
||
3234 |
<?php |
|
16 | 3235 |
|
3236 |
$quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' ); |
|
3237 |
$editor_args = array( |
|
3238 |
'textarea_name' => 'content', |
|
3239 |
'textarea_rows' => 5, |
|
3240 |
'media_buttons' => false, |
|
3241 |
'tinymce' => false, |
|
3242 |
'quicktags' => $quicktags_settings, |
|
3243 |
); |
|
3244 |
||
0 | 3245 |
?> |
3246 |
||
16 | 3247 |
<label for="attachment_content" class="attachment-content-description"><strong><?php _e( 'Description' ); ?></strong> |
3248 |
<?php |
|
3249 |
||
3250 |
if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) { |
|
3251 |
echo ': ' . __( 'Displayed on attachment pages.' ); |
|
3252 |
} |
|
3253 |
||
3254 |
?> |
|
9 | 3255 |
</label> |
16 | 3256 |
<?php wp_editor( format_to_edit( $post->post_content ), 'attachment_content', $editor_args ); ?> |
0 | 3257 |
|
3258 |
</div> |
|
3259 |
<?php |
|
16 | 3260 |
|
0 | 3261 |
$extras = get_compat_media_markup( $post->ID ); |
3262 |
echo $extras['item']; |
|
3263 |
echo '<input type="hidden" id="image-edit-context" value="edit-attachment" />' . "\n"; |
|
3264 |
} |
|
3265 |
||
3266 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3267 |
* Displays non-editable attachment metadata in the publish meta box. |
0 | 3268 |
* |
3269 |
* @since 3.5.0 |
|
3270 |
*/ |
|
3271 |
function attachment_submitbox_metadata() { |
|
16 | 3272 |
$post = get_post(); |
3273 |
$attachment_id = $post->ID; |
|
3274 |
||
3275 |
$file = get_attached_file( $attachment_id ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3276 |
$filename = esc_html( wp_basename( $file ) ); |
0 | 3277 |
|
3278 |
$media_dims = ''; |
|
16 | 3279 |
$meta = wp_get_attachment_metadata( $attachment_id ); |
3280 |
||
9 | 3281 |
if ( isset( $meta['width'], $meta['height'] ) ) { |
16 | 3282 |
$media_dims .= "<span id='media-dims-$attachment_id'>{$meta['width']} × {$meta['height']}</span> "; |
9 | 3283 |
} |
5 | 3284 |
/** This filter is documented in wp-admin/includes/media.php */ |
0 | 3285 |
$media_dims = apply_filters( 'media_meta', $media_dims, $post ); |
3286 |
||
16 | 3287 |
$att_url = wp_get_attachment_url( $attachment_id ); |
3288 |
||
18 | 3289 |
$author = new WP_User( $post->post_author ); |
3290 |
||
3291 |
$uploaded_by_name = __( '(no author)' ); |
|
3292 |
$uploaded_by_link = ''; |
|
3293 |
||
3294 |
if ( $author->exists() ) { |
|
3295 |
$uploaded_by_name = $author->display_name ? $author->display_name : $author->nickname; |
|
3296 |
$uploaded_by_link = get_edit_user_link( $author->ID ); |
|
3297 |
} |
|
9 | 3298 |
?> |
18 | 3299 |
<div class="misc-pub-section misc-pub-uploadedby"> |
3300 |
<?php if ( $uploaded_by_link ) { ?> |
|
3301 |
<?php _e( 'Uploaded by:' ); ?> <a href="<?php echo $uploaded_by_link; ?>"><strong><?php echo $uploaded_by_name; ?></strong></a> |
|
3302 |
<?php } else { ?> |
|
3303 |
<?php _e( 'Uploaded by:' ); ?> <strong><?php echo $uploaded_by_name; ?></strong> |
|
3304 |
<?php } ?> |
|
3305 |
</div> |
|
3306 |
||
3307 |
<?php |
|
3308 |
if ( $post->post_parent ) { |
|
3309 |
$post_parent = get_post( $post->post_parent ); |
|
3310 |
if ( $post_parent ) { |
|
3311 |
$uploaded_to_title = $post_parent->post_title ? $post_parent->post_title : __( '(no title)' ); |
|
3312 |
$uploaded_to_link = get_edit_post_link( $post->post_parent, 'raw' ); |
|
3313 |
?> |
|
3314 |
<div class="misc-pub-section misc-pub-uploadedto"> |
|
3315 |
<?php if ( $uploaded_to_link ) { ?> |
|
3316 |
<?php _e( 'Uploaded to:' ); ?> <a href="<?php echo $uploaded_to_link; ?>"><strong><?php echo $uploaded_to_title; ?></strong></a> |
|
3317 |
<?php } else { ?> |
|
3318 |
<?php _e( 'Uploaded to:' ); ?> <strong><?php echo $uploaded_to_title; ?></strong> |
|
3319 |
<?php } ?> |
|
3320 |
</div> |
|
3321 |
<?php |
|
3322 |
} |
|
3323 |
} |
|
3324 |
?> |
|
3325 |
||
0 | 3326 |
<div class="misc-pub-section misc-pub-attachment"> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3327 |
<label for="attachment_url"><?php _e( 'File URL:' ); ?></label> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3328 |
<input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" id="attachment_url" value="<?php echo esc_attr( $att_url ); ?>" /> |
16 | 3329 |
<span class="copy-to-clipboard-container"> |
18 | 3330 |
<button type="button" class="button copy-attachment-url edit-media" data-clipboard-target="#attachment_url"><?php _e( 'Copy URL to clipboard' ); ?></button> |
16 | 3331 |
<span class="success hidden" aria-hidden="true"><?php _e( 'Copied!' ); ?></span> |
3332 |
</span> |
|
0 | 3333 |
</div> |
3334 |
<div class="misc-pub-section misc-pub-filename"> |
|
3335 |
<?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong> |
|
3336 |
</div> |
|
3337 |
<div class="misc-pub-section misc-pub-filetype"> |
|
16 | 3338 |
<?php _e( 'File type:' ); ?> |
3339 |
<strong> |
|
3340 |
<?php |
|
3341 |
||
3342 |
if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) { |
|
3343 |
echo esc_html( strtoupper( $matches[1] ) ); |
|
3344 |
list( $mime_type ) = explode( '/', $post->post_mime_type ); |
|
3345 |
if ( 'image' !== $mime_type && ! empty( $meta['mime_type'] ) ) { |
|
3346 |
if ( "$mime_type/" . strtolower( $matches[1] ) !== $meta['mime_type'] ) { |
|
3347 |
echo ' (' . $meta['mime_type'] . ')'; |
|
3348 |
} |
|
3349 |
} |
|
3350 |
} else { |
|
3351 |
echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) ); |
|
3352 |
} |
|
3353 |
||
3354 |
?> |
|
9 | 3355 |
</strong> |
0 | 3356 |
</div> |
3357 |
||
3358 |
<?php |
|
16 | 3359 |
|
3360 |
$file_size = false; |
|
0 | 3361 |
|
9 | 3362 |
if ( isset( $meta['filesize'] ) ) { |
3363 |
$file_size = $meta['filesize']; |
|
3364 |
} elseif ( file_exists( $file ) ) { |
|
19 | 3365 |
$file_size = wp_filesize( $file ); |
9 | 3366 |
} |
3367 |
||
16 | 3368 |
if ( ! empty( $file_size ) ) { |
9 | 3369 |
?> |
16 | 3370 |
<div class="misc-pub-section misc-pub-filesize"> |
3371 |
<?php _e( 'File size:' ); ?> <strong><?php echo size_format( $file_size ); ?></strong> |
|
3372 |
</div> |
|
3373 |
<?php |
|
3374 |
} |
|
0 | 3375 |
|
5 | 3376 |
if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3377 |
$fields = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3378 |
'length_formatted' => __( 'Length:' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3379 |
'bitrate' => __( 'Bitrate:' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3380 |
); |
0 | 3381 |
|
3382 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3383 |
* Filters the audio and video metadata fields to be shown in the publish meta box. |
0 | 3384 |
* |
3385 |
* The key for each item in the array should correspond to an attachment |
|
3386 |
* metadata key, and the value should be the desired label. |
|
3387 |
* |
|
5 | 3388 |
* @since 3.7.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3389 |
* @since 4.9.0 Added the `$post` parameter. |
0 | 3390 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3391 |
* @param array $fields An array of the attachment metadata keys and labels. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3392 |
* @param WP_Post $post WP_Post object for the current attachment. |
0 | 3393 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3394 |
$fields = apply_filters( 'media_submitbox_misc_sections', $fields, $post ); |
0 | 3395 |
|
5 | 3396 |
foreach ( $fields as $key => $label ) { |
3397 |
if ( empty( $meta[ $key ] ) ) { |
|
3398 |
continue; |
|
3399 |
} |
|
16 | 3400 |
|
9 | 3401 |
?> |
16 | 3402 |
<div class="misc-pub-section misc-pub-mime-meta misc-pub-<?php echo sanitize_html_class( $key ); ?>"> |
3403 |
<?php echo $label; ?> |
|
3404 |
<strong> |
|
3405 |
<?php |
|
3406 |
||
3407 |
switch ( $key ) { |
|
3408 |
case 'bitrate': |
|
3409 |
echo round( $meta['bitrate'] / 1000 ) . 'kb/s'; |
|
3410 |
if ( ! empty( $meta['bitrate_mode'] ) ) { |
|
3411 |
echo ' ' . strtoupper( esc_html( $meta['bitrate_mode'] ) ); |
|
5 | 3412 |
} |
16 | 3413 |
break; |
3414 |
default: |
|
3415 |
echo esc_html( $meta[ $key ] ); |
|
3416 |
break; |
|
3417 |
} |
|
3418 |
||
3419 |
?> |
|
3420 |
</strong> |
|
3421 |
</div> |
|
9 | 3422 |
<?php |
5 | 3423 |
} |
0 | 3424 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3425 |
$fields = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3426 |
'dataformat' => __( 'Audio Format:' ), |
9 | 3427 |
'codec' => __( 'Audio Codec:' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3428 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3429 |
|
0 | 3430 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3431 |
* Filters the audio attachment metadata fields to be shown in the publish meta box. |
0 | 3432 |
* |
3433 |
* The key for each item in the array should correspond to an attachment |
|
3434 |
* metadata key, and the value should be the desired label. |
|
3435 |
* |
|
5 | 3436 |
* @since 3.7.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3437 |
* @since 4.9.0 Added the `$post` parameter. |
0 | 3438 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3439 |
* @param array $fields An array of the attachment metadata keys and labels. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3440 |
* @param WP_Post $post WP_Post object for the current attachment. |
0 | 3441 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3442 |
$audio_fields = apply_filters( 'audio_submitbox_misc_sections', $fields, $post ); |
0 | 3443 |
|
5 | 3444 |
foreach ( $audio_fields as $key => $label ) { |
3445 |
if ( empty( $meta['audio'][ $key ] ) ) { |
|
3446 |
continue; |
|
3447 |
} |
|
16 | 3448 |
|
9 | 3449 |
?> |
16 | 3450 |
<div class="misc-pub-section misc-pub-audio misc-pub-<?php echo sanitize_html_class( $key ); ?>"> |
3451 |
<?php echo $label; ?> <strong><?php echo esc_html( $meta['audio'][ $key ] ); ?></strong> |
|
3452 |
</div> |
|
9 | 3453 |
<?php |
5 | 3454 |
} |
3455 |
} |
|
0 | 3456 |
|
16 | 3457 |
if ( $media_dims ) { |
9 | 3458 |
?> |
16 | 3459 |
<div class="misc-pub-section misc-pub-dimensions"> |
3460 |
<?php _e( 'Dimensions:' ); ?> <strong><?php echo $media_dims; ?></strong> |
|
3461 |
</div> |
|
9 | 3462 |
<?php |
16 | 3463 |
} |
3464 |
||
3465 |
if ( ! empty( $meta['original_image'] ) ) { |
|
3466 |
?> |
|
3467 |
<div class="misc-pub-section misc-pub-original-image"> |
|
3468 |
<?php _e( 'Original image:' ); ?> |
|
3469 |
<a href="<?php echo esc_url( wp_get_original_image_url( $attachment_id ) ); ?>"> |
|
3470 |
<?php echo esc_html( wp_basename( wp_get_original_image_path( $attachment_id ) ) ); ?> |
|
3471 |
</a> |
|
3472 |
</div> |
|
3473 |
<?php |
|
3474 |
} |
|
0 | 3475 |
} |
3476 |
||
3477 |
/** |
|
19 | 3478 |
* Parses ID3v2, ID3v1, and getID3 comments to extract usable data. |
0 | 3479 |
* |
3480 |
* @since 3.6.0 |
|
3481 |
* |
|
19 | 3482 |
* @param array $metadata An existing array with data. |
3483 |
* @param array $data Data supplied by ID3 tags. |
|
0 | 3484 |
*/ |
3485 |
function wp_add_id3_tag_data( &$metadata, $data ) { |
|
3486 |
foreach ( array( 'id3v2', 'id3v1' ) as $version ) { |
|
9 | 3487 |
if ( ! empty( $data[ $version ]['comments'] ) ) { |
3488 |
foreach ( $data[ $version ]['comments'] as $key => $list ) { |
|
5 | 3489 |
if ( 'length' !== $key && ! empty( $list ) ) { |
9 | 3490 |
$metadata[ $key ] = wp_kses_post( reset( $list ) ); |
5 | 3491 |
// Fix bug in byte stream analysis. |
9 | 3492 |
if ( 'terms_of_use' === $key && 0 === strpos( $metadata[ $key ], 'yright notice.' ) ) { |
3493 |
$metadata[ $key ] = 'Cop' . $metadata[ $key ]; |
|
3494 |
} |
|
0 | 3495 |
} |
3496 |
} |
|
3497 |
break; |
|
3498 |
} |
|
3499 |
} |
|
3500 |
||
3501 |
if ( ! empty( $data['id3v2']['APIC'] ) ) { |
|
9 | 3502 |
$image = reset( $data['id3v2']['APIC'] ); |
0 | 3503 |
if ( ! empty( $image['data'] ) ) { |
3504 |
$metadata['image'] = array( |
|
9 | 3505 |
'data' => $image['data'], |
3506 |
'mime' => $image['image_mime'], |
|
3507 |
'width' => $image['image_width'], |
|
3508 |
'height' => $image['image_height'], |
|
0 | 3509 |
); |
3510 |
} |
|
3511 |
} elseif ( ! empty( $data['comments']['picture'] ) ) { |
|
3512 |
$image = reset( $data['comments']['picture'] ); |
|
3513 |
if ( ! empty( $image['data'] ) ) { |
|
3514 |
$metadata['image'] = array( |
|
3515 |
'data' => $image['data'], |
|
9 | 3516 |
'mime' => $image['image_mime'], |
0 | 3517 |
); |
3518 |
} |
|
3519 |
} |
|
3520 |
} |
|
3521 |
||
3522 |
/** |
|
19 | 3523 |
* Retrieves metadata from a video file's ID3 tags. |
0 | 3524 |
* |
3525 |
* @since 3.6.0 |
|
3526 |
* |
|
3527 |
* @param string $file Path to file. |
|
18 | 3528 |
* @return array|false Returns array of metadata, if found. |
0 | 3529 |
*/ |
3530 |
function wp_read_video_metadata( $file ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3531 |
if ( ! file_exists( $file ) ) { |
0 | 3532 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3533 |
} |
0 | 3534 |
|
3535 |
$metadata = array(); |
|
3536 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3537 |
if ( ! defined( 'GETID3_TEMP_DIR' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3538 |
define( 'GETID3_TEMP_DIR', get_temp_dir() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3539 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3540 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3541 |
if ( ! class_exists( 'getID3', false ) ) { |
16 | 3542 |
require ABSPATH . WPINC . '/ID3/getid3.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3543 |
} |
16 | 3544 |
|
19 | 3545 |
$id3 = new getID3(); |
3546 |
// Required to get the `created_timestamp` value. |
|
3547 |
$id3->options_audiovideo_quicktime_ReturnAtomData = true; // phpcs:ignore WordPress.NamingConventions.ValidVariableName |
|
3548 |
||
0 | 3549 |
$data = $id3->analyze( $file ); |
3550 |
||
9 | 3551 |
if ( isset( $data['video']['lossless'] ) ) { |
0 | 3552 |
$metadata['lossless'] = $data['video']['lossless']; |
9 | 3553 |
} |
16 | 3554 |
|
9 | 3555 |
if ( ! empty( $data['video']['bitrate'] ) ) { |
0 | 3556 |
$metadata['bitrate'] = (int) $data['video']['bitrate']; |
9 | 3557 |
} |
16 | 3558 |
|
9 | 3559 |
if ( ! empty( $data['video']['bitrate_mode'] ) ) { |
0 | 3560 |
$metadata['bitrate_mode'] = $data['video']['bitrate_mode']; |
9 | 3561 |
} |
16 | 3562 |
|
9 | 3563 |
if ( ! empty( $data['filesize'] ) ) { |
0 | 3564 |
$metadata['filesize'] = (int) $data['filesize']; |
9 | 3565 |
} |
16 | 3566 |
|
9 | 3567 |
if ( ! empty( $data['mime_type'] ) ) { |
0 | 3568 |
$metadata['mime_type'] = $data['mime_type']; |
9 | 3569 |
} |
16 | 3570 |
|
9 | 3571 |
if ( ! empty( $data['playtime_seconds'] ) ) { |
5 | 3572 |
$metadata['length'] = (int) round( $data['playtime_seconds'] ); |
9 | 3573 |
} |
16 | 3574 |
|
9 | 3575 |
if ( ! empty( $data['playtime_string'] ) ) { |
0 | 3576 |
$metadata['length_formatted'] = $data['playtime_string']; |
9 | 3577 |
} |
16 | 3578 |
|
9 | 3579 |
if ( ! empty( $data['video']['resolution_x'] ) ) { |
0 | 3580 |
$metadata['width'] = (int) $data['video']['resolution_x']; |
9 | 3581 |
} |
16 | 3582 |
|
9 | 3583 |
if ( ! empty( $data['video']['resolution_y'] ) ) { |
0 | 3584 |
$metadata['height'] = (int) $data['video']['resolution_y']; |
9 | 3585 |
} |
16 | 3586 |
|
9 | 3587 |
if ( ! empty( $data['fileformat'] ) ) { |
0 | 3588 |
$metadata['fileformat'] = $data['fileformat']; |
9 | 3589 |
} |
16 | 3590 |
|
9 | 3591 |
if ( ! empty( $data['video']['dataformat'] ) ) { |
0 | 3592 |
$metadata['dataformat'] = $data['video']['dataformat']; |
9 | 3593 |
} |
16 | 3594 |
|
9 | 3595 |
if ( ! empty( $data['video']['encoder'] ) ) { |
0 | 3596 |
$metadata['encoder'] = $data['video']['encoder']; |
9 | 3597 |
} |
16 | 3598 |
|
9 | 3599 |
if ( ! empty( $data['video']['codec'] ) ) { |
0 | 3600 |
$metadata['codec'] = $data['video']['codec']; |
9 | 3601 |
} |
0 | 3602 |
|
3603 |
if ( ! empty( $data['audio'] ) ) { |
|
3604 |
unset( $data['audio']['streams'] ); |
|
3605 |
$metadata['audio'] = $data['audio']; |
|
3606 |
} |
|
3607 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3608 |
if ( empty( $metadata['created_timestamp'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3609 |
$created_timestamp = wp_get_media_creation_timestamp( $data ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3610 |
|
16 | 3611 |
if ( false !== $created_timestamp ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3612 |
$metadata['created_timestamp'] = $created_timestamp; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3613 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3614 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3615 |
|
0 | 3616 |
wp_add_id3_tag_data( $metadata, $data ); |
3617 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3618 |
$file_format = isset( $metadata['fileformat'] ) ? $metadata['fileformat'] : null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3619 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3620 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3621 |
* Filters the array of metadata retrieved from a video. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3622 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3623 |
* In core, usually this selection is what is stored. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3624 |
* More complete data can be parsed from the `$data` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3625 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3626 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3627 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3628 |
* @param array $metadata Filtered Video metadata. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3629 |
* @param string $file Path to video file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3630 |
* @param string $file_format File format of video, as analyzed by getID3. |
19 | 3631 |
* @param array $data Raw metadata from getID3. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3632 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3633 |
return apply_filters( 'wp_read_video_metadata', $metadata, $file, $file_format, $data ); |
0 | 3634 |
} |
3635 |
||
3636 |
/** |
|
19 | 3637 |
* Retrieves metadata from an audio file's ID3 tags. |
0 | 3638 |
* |
3639 |
* @since 3.6.0 |
|
3640 |
* |
|
3641 |
* @param string $file Path to file. |
|
18 | 3642 |
* @return array|false Returns array of metadata, if found. |
0 | 3643 |
*/ |
3644 |
function wp_read_audio_metadata( $file ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3645 |
if ( ! file_exists( $file ) ) { |
0 | 3646 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3647 |
} |
16 | 3648 |
|
0 | 3649 |
$metadata = array(); |
3650 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3651 |
if ( ! defined( 'GETID3_TEMP_DIR' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3652 |
define( 'GETID3_TEMP_DIR', get_temp_dir() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3653 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3654 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3655 |
if ( ! class_exists( 'getID3', false ) ) { |
16 | 3656 |
require ABSPATH . WPINC . '/ID3/getid3.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3657 |
} |
16 | 3658 |
|
19 | 3659 |
$id3 = new getID3(); |
3660 |
// Required to get the `created_timestamp` value. |
|
3661 |
$id3->options_audiovideo_quicktime_ReturnAtomData = true; // phpcs:ignore WordPress.NamingConventions.ValidVariableName |
|
3662 |
||
0 | 3663 |
$data = $id3->analyze( $file ); |
3664 |
||
3665 |
if ( ! empty( $data['audio'] ) ) { |
|
3666 |
unset( $data['audio']['streams'] ); |
|
3667 |
$metadata = $data['audio']; |
|
3668 |
} |
|
3669 |
||
9 | 3670 |
if ( ! empty( $data['fileformat'] ) ) { |
0 | 3671 |
$metadata['fileformat'] = $data['fileformat']; |
9 | 3672 |
} |
16 | 3673 |
|
9 | 3674 |
if ( ! empty( $data['filesize'] ) ) { |
0 | 3675 |
$metadata['filesize'] = (int) $data['filesize']; |
9 | 3676 |
} |
16 | 3677 |
|
9 | 3678 |
if ( ! empty( $data['mime_type'] ) ) { |
0 | 3679 |
$metadata['mime_type'] = $data['mime_type']; |
9 | 3680 |
} |
16 | 3681 |
|
9 | 3682 |
if ( ! empty( $data['playtime_seconds'] ) ) { |
5 | 3683 |
$metadata['length'] = (int) round( $data['playtime_seconds'] ); |
9 | 3684 |
} |
16 | 3685 |
|
9 | 3686 |
if ( ! empty( $data['playtime_string'] ) ) { |
0 | 3687 |
$metadata['length_formatted'] = $data['playtime_string']; |
9 | 3688 |
} |
3689 |
||
3690 |
if ( empty( $metadata['created_timestamp'] ) ) { |
|
3691 |
$created_timestamp = wp_get_media_creation_timestamp( $data ); |
|
3692 |
||
3693 |
if ( false !== $created_timestamp ) { |
|
3694 |
$metadata['created_timestamp'] = $created_timestamp; |
|
3695 |
} |
|
3696 |
} |
|
0 | 3697 |
|
3698 |
wp_add_id3_tag_data( $metadata, $data ); |
|
3699 |
||
3700 |
return $metadata; |
|
3701 |
} |
|
5 | 3702 |
|
3703 |
/** |
|
19 | 3704 |
* Parses creation date from media metadata. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3705 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3706 |
* The getID3 library doesn't have a standard method for getting creation dates, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3707 |
* so the location of this data can vary based on the MIME type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3708 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3709 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3710 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3711 |
* @link https://github.com/JamesHeinrich/getID3/blob/master/structure.txt |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3712 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3713 |
* @param array $metadata The metadata returned by getID3::analyze(). |
18 | 3714 |
* @return int|false A UNIX timestamp for the media's creation date if available |
3715 |
* or a boolean FALSE if a timestamp could not be determined. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3716 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3717 |
function wp_get_media_creation_timestamp( $metadata ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3718 |
$creation_date = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3719 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3720 |
if ( empty( $metadata['fileformat'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3721 |
return $creation_date; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3722 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3723 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3724 |
switch ( $metadata['fileformat'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3725 |
case 'asf': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3726 |
if ( isset( $metadata['asf']['file_properties_object']['creation_date_unix'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3727 |
$creation_date = (int) $metadata['asf']['file_properties_object']['creation_date_unix']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3728 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3729 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3730 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3731 |
case 'matroska': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3732 |
case 'webm': |
19 | 3733 |
if ( isset( $metadata['matroska']['comments']['creation_time'][0] ) ) { |
3734 |
$creation_date = strtotime( $metadata['matroska']['comments']['creation_time'][0] ); |
|
3735 |
} elseif ( isset( $metadata['matroska']['info'][0]['DateUTC_unix'] ) ) { |
|
3736 |
$creation_date = (int) $metadata['matroska']['info'][0]['DateUTC_unix']; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3737 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3738 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3739 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3740 |
case 'quicktime': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3741 |
case 'mp4': |
19 | 3742 |
if ( isset( $metadata['quicktime']['moov']['subatoms'][0]['creation_time_unix'] ) ) { |
3743 |
$creation_date = (int) $metadata['quicktime']['moov']['subatoms'][0]['creation_time_unix']; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3744 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3745 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3746 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3747 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3748 |
return $creation_date; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3749 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3750 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3751 |
/** |
16 | 3752 |
* Encapsulates the logic for Attach/Detach actions. |
5 | 3753 |
* |
3754 |
* @since 4.2.0 |
|
3755 |
* |
|
3756 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
3757 |
* |
|
3758 |
* @param int $parent_id Attachment parent ID. |
|
3759 |
* @param string $action Optional. Attach/detach action. Accepts 'attach' or 'detach'. |
|
3760 |
* Default 'attach'. |
|
3761 |
*/ |
|
3762 |
function wp_media_attach_action( $parent_id, $action = 'attach' ) { |
|
3763 |
global $wpdb; |
|
3764 |
||
3765 |
if ( ! $parent_id ) { |
|
3766 |
return; |
|
3767 |
} |
|
3768 |
||
3769 |
if ( ! current_user_can( 'edit_post', $parent_id ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3770 |
wp_die( __( 'Sorry, you are not allowed to edit this post.' ) ); |
5 | 3771 |
} |
16 | 3772 |
|
5 | 3773 |
$ids = array(); |
16 | 3774 |
|
3775 |
foreach ( (array) $_REQUEST['media'] as $attachment_id ) { |
|
3776 |
$attachment_id = (int) $attachment_id; |
|
3777 |
||
3778 |
if ( ! current_user_can( 'edit_post', $attachment_id ) ) { |
|
5 | 3779 |
continue; |
3780 |
} |
|
3781 |
||
16 | 3782 |
$ids[] = $attachment_id; |
5 | 3783 |
} |
3784 |
||
3785 |
if ( ! empty( $ids ) ) { |
|
3786 |
$ids_string = implode( ',', $ids ); |
|
16 | 3787 |
|
5 | 3788 |
if ( 'attach' === $action ) { |
3789 |
$result = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ( $ids_string )", $parent_id ) ); |
|
3790 |
} else { |
|
3791 |
$result = $wpdb->query( "UPDATE $wpdb->posts SET post_parent = 0 WHERE post_type = 'attachment' AND ID IN ( $ids_string )" ); |
|
3792 |
} |
|
3793 |
} |
|
3794 |
||
3795 |
if ( isset( $result ) ) { |
|
16 | 3796 |
foreach ( $ids as $attachment_id ) { |
3797 |
/** |
|
3798 |
* Fires when media is attached or detached from a post. |
|
3799 |
* |
|
3800 |
* @since 5.5.0 |
|
3801 |
* |
|
3802 |
* @param string $action Attach/detach action. Accepts 'attach' or 'detach'. |
|
3803 |
* @param int $attachment_id The attachment ID. |
|
3804 |
* @param int $parent_id Attachment parent ID. |
|
3805 |
*/ |
|
3806 |
do_action( 'wp_media_attach_action', $action, $attachment_id, $parent_id ); |
|
3807 |
||
3808 |
clean_attachment_cache( $attachment_id ); |
|
3809 |
} |
|
3810 |
||
5 | 3811 |
$location = 'upload.php'; |
16 | 3812 |
$referer = wp_get_referer(); |
3813 |
||
3814 |
if ( $referer ) { |
|
5 | 3815 |
if ( false !== strpos( $referer, 'upload.php' ) ) { |
3816 |
$location = remove_query_arg( array( 'attached', 'detach' ), $referer ); |
|
3817 |
} |
|
3818 |
} |
|
3819 |
||
9 | 3820 |
$key = 'attach' === $action ? 'attached' : 'detach'; |
5 | 3821 |
$location = add_query_arg( array( $key => $result ), $location ); |
16 | 3822 |
|
5 | 3823 |
wp_redirect( $location ); |
3824 |
exit; |
|
3825 |
} |
|
3826 |
} |