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