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