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