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