/** * Filters the available tabs in the legacy (pre-3.5.0) media popup. * * @since 2.5.0 * * @param string[] $_default_tabs An array of media tabs. */ return apply_filters( 'media_upload_tabs', $_default_tabs ); }
/** * Adds the gallery tab back to the tabs array if post has image attachments. * * @since 2.5.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param array $tabs * @return array $tabs with gallery if post has image attachment */ function update_gallery_tab( $tabs ) { global $wpdb;
/** * Filters the image HTML markup to send to the editor when inserting an image. * * @since 2.5.0 * @since 5.6.0 The `$rel` parameter was added. * * @param string $html The image HTML markup to send. * @param int $id The attachment ID. * @param string $caption The image caption. * @param string $title The image title. * @param string $align The image alignment. * @param string $url The image source URL. * @param string|int[] $size Requested image size. Can be any registered image size name, or * an array of width and height values in pixels (in that order). * @param string $alt The image alternative, or alt, text. * @param string $rel The image rel attribute. */ $html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt, $rel );
return $html; }
/** * Adds image shortcode with caption to editor. * * @since 2.6.0 * * @param string $html The image HTML markup to send. * @param int $id Image attachment ID. * @param string $caption Image caption. * @param string $title Image title attribute (not used). * @param string $align Image CSS alignment property. * @param string $url Image source URL (not used). * @param string $size Image size (not used). * @param string $alt Image `alt` attribute (not used). * @return string The image HTML markup with caption shortcode. */ function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {
/** * Filters the caption text. * * Note: If the caption text is empty, the caption shortcode will not be appended * to the image HTML when inserted into the editor. * * Passing an empty value also prevents the {@see 'image_add_caption_shortcode'} * Filters from being evaluated at the end of image_add_caption(). * * @since 4.1.0 * * @param string $caption The original caption text. * @param int $id The attachment ID. */ $caption = apply_filters( 'image_add_caption_text', $caption, $id );
/** * Filters whether to disable captions. * * Prevents image captions from being appended to image HTML when inserted into the editor. * * @since 2.6.0 * * @param bool $bool Whether to disable appending captions. Returning true from the filter * will disable captions. Default empty string. */ if ( empty( $caption ) || apply_filters( 'disable_captions', '' ) ) { return $html; }
/** * Filters the image HTML markup including the caption shortcode. * * @since 2.6.0 * * @param string $shcode The image HTML markup with caption shortcode. * @param string $html The image HTML markup. */ return apply_filters( 'image_add_caption_shortcode', $shcode, $html ); }
/** * Private preg_replace callback used in image_add_caption(). * * @access private * @since 3.4.0 * * @param array $matches Single regex match. * @return string Cleaned up HTML for caption. */ function _cleanup_image_add_caption( $matches ) { // Remove any line breaks from inside the tags. return preg_replace( '/[\r\n\t]+/', ' ', $matches[0] ); }
/** * Saves a file submitted from a POST request and create an attachment post for it. * * @since 2.5.0 * * @param string $file_id Index of the `$_FILES` array that the file was sent. * @param int $post_id The post ID of a post to attach the media item to. Required, but can * be set to 0, creating a media item that has no relationship to a post. * @param array $post_data Optional. Overwrite some of the attachment. * @param array $overrides Optional. Override the wp_handle_upload() behavior. * @return int|WP_Error ID of the attachment or a WP_Error object on failure. */ function media_handle_upload( $file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false ) ) { $time = current_time( 'mysql' ); $post = get_post( $post_id );
if ( $post ) { // The post date doesn't usually matter for pages, so don't backdate this upload. if ( 'page' !== $post->post_type && substr( $post->post_date, 0, 4 ) > 0 ) { $time = $post->post_date; } }
// Use image exif/iptc data for title and caption defaults if possible. } elseif ( str_starts_with( $type, 'image/' ) ) { $image_meta = wp_read_image_metadata( $file );
// This should never be set as it would then overwrite an existing attachment. unset( $attachment['ID'] );
// Save the data. $attachment_id = wp_insert_attachment( $attachment, $file, $post_id, true );
if ( ! is_wp_error( $attachment_id ) ) { /* * Set a custom header with the attachment_id. * Used by the browser/client to resume creating image sub-sizes after a PHP fatal error. */ if ( ! headers_sent() ) { header( 'X-WP-Upload-Attachment-ID: ' . $attachment_id ); }
/* * The image sub-sizes are created during wp_generate_attachment_metadata(). * This is generally slow and may cause timeouts or out of memory errors. */ wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) ); }
return $attachment_id; }
/** * Handles a side-loaded file in the same way as an uploaded file is handled by media_handle_upload(). * * @since 2.6.0 * @since 5.3.0 The `$post_id` parameter was made optional. * * @param string[] $file_array Array that represents a `$_FILES` upload array. * @param int $post_id Optional. The post ID the media is associated with. * @param string $desc Optional. Description of the side-loaded file. Default null. * @param array $post_data Optional. Post data to override. Default empty array. * @return int|WP_Error The ID of the attachment or a WP_Error on failure. */ function media_handle_sideload( $file_array, $post_id = 0, $desc = null, $post_data = array() ) { $overrides = array( 'test_form' => false );
/** * Outputs the iframe to display the media upload page. * * @since 2.5.0 * @since 5.3.0 Formalized the existing and already documented `...$args` parameter * by adding it to the function signature. * * @global string $body_id * * @param callable $content_func Function that outputs the content. * @param mixed ...$args Optional additional parameters to pass to the callback function when it's called. */ function wp_iframe( $content_func, ...$args ) { global $body_id;
/** * Fires when admin styles enqueued for the legacy (pre-3.5.0) media upload popup are printed. * * @since 2.9.0 */ do_action( 'admin_print_styles-media-upload-popup' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
/** This action is documented in wp-admin/admin-header.php */ do_action( 'admin_print_styles' );
/** * Fires when admin scripts enqueued for the legacy (pre-3.5.0) media upload popup are printed. * * @since 2.9.0 */ do_action( 'admin_print_scripts-media-upload-popup' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
/** This action is documented in wp-admin/admin-header.php */ do_action( 'admin_print_scripts' );
/** * Fires when scripts enqueued for the admin header for the legacy (pre-3.5.0) * media upload popup are printed. * * @since 2.9.0 */ do_action( 'admin_head-media-upload-popup' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
/** This action is documented in wp-admin/admin-header.php */ do_action( 'admin_head' );
if ( is_string( $content_func ) ) { /** * Fires in the admin header for each specific form tab in the legacy * (pre-3.5.0) media upload popup. * * The dynamic portion of the hook name, `$content_func`, refers to the form * callback for the media upload type. * * @since 2.5.0 */ do_action( "admin_head_{$content_func}" ); }
/** * Filters the legacy (pre-3.5.0) media buttons. * * Use {@see 'media_buttons'} action instead. * * @since 2.5.0 * @deprecated 3.5.0 Use {@see 'media_buttons'} action instead. * * @param string $string Media buttons context. Default empty. */ $legacy_filter = apply_filters_deprecated( 'media_buttons_context', array( '' ), '3.5.0', 'media_buttons' );
if ( $legacy_filter ) { // #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag. if ( 0 === stripos( trim( $legacy_filter ), '</a>' ) ) { $legacy_filter .= '</a>'; } echo $legacy_filter; } }
/** * Retrieves the upload iframe source URL. * * @since 3.0.0 * * @global int $post_ID * * @param string $type Media type. * @param int $post_id Post ID. * @param string $tab Media upload tab. * @return string Upload iframe source URL. */ function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) { global $post_ID;
/** * Filters the upload iframe source URL for a specific media type. * * The dynamic portion of the hook name, `$type`, refers to the type * of media uploaded. * * Possible hook names include: * * - `image_upload_iframe_src` * - `media_upload_iframe_src` * * @since 3.0.0 * * @param string $upload_iframe_src The upload iframe source URL. */ $upload_iframe_src = apply_filters( "{$type}_upload_iframe_src", $upload_iframe_src );
/** * Handles form submissions for the legacy media uploader. * * @since 2.5.0 * * @return null|array|void Array of error messages keyed by attachment ID, null or void on success. */ function media_upload_form_handler() { check_admin_referer( 'media-form' );
/** * Filters the HTML markup for a media item sent to the editor. * * @since 2.5.0 * * @see wp_get_attachment_metadata() * * @param string $html HTML markup for a media item sent to the editor. * @param int $send_id The first key from the $_POST['send'] data. * @param array $attachment Array of attachment metadata. */ $html = apply_filters( 'media_send_to_editor', $html, $send_id, $attachment );
return media_send_to_editor( $html ); }
return $errors; }
/** * Handles the process of uploading media. * * @since 2.5.0 * * @return null|string */ function wp_media_upload_handler() { $errors = array(); $id = 0;
/** * Filters the URL sent to the editor for a specific media type. * * The dynamic portion of the hook name, `$type`, refers to the type * of media being sent. * * Possible hook names include: * * - `audio_send_to_editor_url` * - `file_send_to_editor_url` * - `video_send_to_editor_url` * * @since 3.3.0 * * @param string $html HTML markup sent to the editor. * @param string $src Media source URL. * @param string $title Media title. */ $html = apply_filters( "{$type}_send_to_editor_url", $html, sanitize_url( $src ), $title ); } else { $align = ''; $alt = esc_attr( wp_unslash( $_POST['alt'] ) );
/** * Downloads an image from the specified URL, saves it as an attachment, and optionally attaches it to a post. * * @since 2.6.0 * @since 4.2.0 Introduced the `$return_type` parameter. * @since 4.8.0 Introduced the 'id' option for the `$return_type` parameter. * @since 5.3.0 The `$post_id` parameter was made optional. * @since 5.4.0 The original URL of the attachment is stored in the `_source_url` * post meta value. * @since 5.8.0 Added 'webp' to the default list of allowed file extensions. * * @param string $file The URL of the image to download. * @param int $post_id Optional. The post ID the media is to be associated with. * @param string $desc Optional. Description of the image. * @param string $return_type Optional. Accepts 'html' (image tag html) or 'src' (URL), * or 'id' (attachment ID). Default 'html'. * @return string|int|WP_Error Populated HTML img tag, attachment ID, or attachment source * on success, WP_Error object otherwise. */ function media_sideload_image( $file, $post_id = 0, $desc = null, $return_type = 'html' ) { if ( ! empty( $file ) ) {
/** * Retrieves the legacy media uploader form in an iframe. * * @since 2.5.0 * * @return string|null */ function media_upload_gallery() { $errors = array();
/** * Retrieves the legacy media library form in an iframe. * * @since 2.5.0 * * @return string|null */ function media_upload_library() { $errors = array();
/** * Retrieves HTML for the image alignment radio buttons with the specified one checked. * * @since 2.7.0 * * @param WP_Post $post * @param string $checked * @return string */ function image_align_input_fields( $post, $checked = '' ) {
// Is this size selectable? $enabled = ( $downsize[3] || 'full' === $size ); $css_id = "image-size-{$size}-{$post->ID}";
// If this size is the default but that's not available, don't select it. if ( $size === $check ) { if ( $enabled ) { $checked = " checked='checked'"; } else { $check = ''; } } elseif ( ! $check && $enabled && 'thumbnail' !== $size ) { /* * If $check is not enabled, default to the first available size * that's bigger than a thumbnail. */ $check = $size; $checked = " checked='checked'"; }
// Only show the dimensions if that choice is available. if ( $enabled ) { $html .= " <label for='{$css_id}' class='help'>" . sprintf( '(%d × %d)', $downsize[1], $downsize[2] ) . '</label>'; } $html .= '</div>';
/** * Retrieves HTML for the Link URL buttons with the default link type as specified. * * @since 2.7.0 * * @param WP_Post $post * @param string $url_type * @return string */ function image_link_input_fields( $post, $url_type = '' ) {
/** * Outputs a textarea element for inputting an attachment caption. * * @since 3.4.0 * * @param WP_Post $edit_post Attachment WP_Post object. * @return string HTML markup for the textarea element. */ function wp_caption_input_textarea( $edit_post ) { // Post data is already escaped. $name = "attachments[{$edit_post->ID}][post_excerpt]";
/** * Retrieves the image attachment fields to edit form fields. * * @since 2.5.0 * * @param array $form_fields * @param object $post * @return array */ function image_attachment_fields_to_edit( $form_fields, $post ) { return $form_fields; }
/** * Retrieves the single non-image attachment fields to edit form fields. * * @since 2.5.0 * * @param array $form_fields An array of attachment form fields. * @param WP_Post $post The WP_Post attachment object. * @return array Filtered attachment form fields. */ function media_single_attachment_fields_to_edit( $form_fields, $post ) { unset( $form_fields['url'], $form_fields['align'], $form_fields['image-size'] ); return $form_fields; }
/** * Retrieves the post non-image attachment fields to edit form fields. * * @since 2.8.0 * * @param array $form_fields An array of attachment form fields. * @param WP_Post $post The WP_Post attachment object. * @return array Filtered attachment form fields. */ function media_post_single_attachment_fields_to_edit( $form_fields, $post ) { unset( $form_fields['image_url'] ); return $form_fields; }
/** * Retrieves the media element HTML to send to the editor. * * @since 2.5.0 * * @param string $html * @param int $attachment_id * @param array $attachment * @return string */ function image_media_send_to_editor( $html, $attachment_id, $attachment ) { $post = get_post( $attachment_id );
/* * Merge default fields with their errors, so any key passed with the error * (e.g. 'error', 'helps', 'value') will replace the default. * The recursive merge is easily traversed with array casting: * foreach ( (array) $things as $thing ) */ $form_fields = array_merge_recursive( $form_fields, (array) $errors );
// This was formerly in image_attachment_fields_to_edit(). if ( str_starts_with( $post->post_mime_type, 'image' ) ) { $alt = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
if ( empty( $alt ) ) { $alt = ''; }
$form_fields['post_title']['required'] = true;
$form_fields['image_alt'] = array( 'value' => $alt, 'label' => __( 'Alternative Text' ), 'helps' => __( 'Alt text for the image, e.g. “The Mona Lisa”' ), );
/** * Filters the attachment fields to edit. * * @since 2.5.0 * * @param array $form_fields An array of attachment form fields. * @param WP_Post $post The WP_Post attachment object. */ $form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post );
return $form_fields; }
/** * Retrieves HTML for media items of post gallery. * * The HTML markup retrieved will be created for the progress of SWF Upload * component. Will also create link for showing and hiding the form to modify * the image attachment. * * @since 2.5.0 * * @global WP_Query $wp_the_query WordPress Query object. * * @param int $post_id Post ID. * @param array $errors Errors for attachment, if any. * @return string HTML content for media items of post gallery. */ function get_media_items( $post_id, $errors ) { $attachments = array();
/** * Retrieves HTML form for modifying the image attachment. * * @since 2.5.0 * * @global string $redir_tab * * @param int $attachment_id Attachment ID for modification. * @param string|array $args Optional. Override defaults. * @return string HTML form for attachment. */ function get_media_item( $attachment_id, $args = null ) { global $redir_tab;
/** * Filters the arguments used to retrieve an image for the edit image form. * * @since 3.1.0 * * @see get_media_item * * @param array $parsed_args An array of arguments. */ $parsed_args = apply_filters( 'get_media_item_args', $parsed_args );
/* * Merge default fields with their errors, so any key passed with the error * (e.g. 'error', 'helps', 'value') will replace the default. * The recursive merge is easily traversed with array casting: * foreach ( (array) $things as $thing ) */ $form_fields = array_merge_recursive( $form_fields, (array) $args['errors'] );
/** This filter is documented in wp-admin/includes/media.php */ $form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post );
/** * Outputs the legacy media upload form. * * @since 2.5.0 * * @global string $type * @global string $tab * * @param array $errors */ function media_upload_form( $errors = null ) { global $type, $tab;
if ( ! _device_can_upload() ) { echo '<p>' . sprintf( /* translators: %s: https://apps.wordpress.org/ */ __( 'The web browser on your device cannot be used to upload files. You may be able to use the <a href="%s">native app for your device</a> instead.' ), 'https://apps.wordpress.org/' ) . '</p>'; return; }
if ( is_multisite() && ! is_upload_space_available() ) { /** * Fires when an upload will exceed the defined upload space quota for a network site. * * @since 3.5.0 */ do_action( 'upload_ui_over_quota' ); return; }
/** * Fires just before the legacy (pre-3.5.0) upload interface is loaded. * * @since 2.6.0 */ do_action( 'pre-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
/** * Filters the media upload post parameters. * * @since 3.1.0 As 'swfupload_post_params' * @since 3.3.0 * * @param array $post_params An array of media upload parameters used by Plupload. */ $post_params = apply_filters( 'upload_post_params', $post_params );
/* * Since 4.9 the `runtimes` setting is hardcoded in our version of Plupload to `html5,html4`, * and the `flash_swf_url` and `silverlight_xap_url` are not used. */ $plupload_init = array( 'browse_button' => 'plupload-browse-button', 'container' => 'plupload-upload-ui', 'drop_element' => 'drag-drop-area', 'file_data_name' => 'async-upload', 'url' => $upload_action_url, 'filters' => array( 'max_file_size' => $max_upload_size . 'b' ), 'multipart_params' => $post_params, );
/* * Currently only iOS Safari supports multiple files uploading, * but iOS 7.x has a bug that prevents uploading of videos when enabled. * See #29602. */ if ( wp_is_mobile() && str_contains( $_SERVER['HTTP_USER_AGENT'], 'OS 7_' ) && str_contains( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' ) ) { $plupload_init['multi_selection'] = false; }
/** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php */ $prevent_unsupported_uploads = apply_filters( 'wp_prevent_unsupported_mime_type_uploads', true, null );
if ( $prevent_unsupported_uploads ) { // Check if WebP images can be edited. if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) { $plupload_init['webp_upload_error'] = true; }
// Check if AVIF images can be edited. if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/avif' ) ) ) { $plupload_init['avif_upload_error'] = true; } }
/** * Filters the default Plupload settings. * * @since 3.3.0 * * @param array $plupload_init An array of default settings used by Plupload. */ $plupload_init = apply_filters( 'plupload_init', $plupload_init );
?> <script type="text/javascript"> <?php // Verify size is an int. If not return default value. $large_size_h = absint( get_option( 'large_size_h' ) );
if ( $page_links ) { echo "<div class='tablenav-pages'>$page_links</div>"; } ?>
<div class="alignleft actions"> <?php $months = $wpdb->get_results( "SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC" );
?> <p class="upload-flash-bypass"> <?php printf( /* translators: 1: URL to browser uploader, 2: Additional link attributes. */ __( 'You are using the multi-file uploader. Problems? Try the <a href="%1$s" %2$s>browser uploader</a> instead.' ), $browser_uploader, 'target="_blank"' ); ?> </p> <?php }
/** * Displays the browser's built-in uploader message. * * @since 2.6.0 */ function media_upload_html_bypass() { ?> <p class="upload-html-bypass hide-if-no-js"> <?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>.' ); ?> </p> <?php }
/** * Used to display a "After a file has been uploaded..." help message. * * @since 3.3.0 */ function media_upload_text_after() {}
?> <p class="hide-if-no-js"><label> <input name="image_resize" type="checkbox" id="image_resize" value="true"<?php echo $checked; ?> /> <?php /* translators: 1: Link start tag, 2: Link end tag, 3: Width, 4: Height. */ 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' ) );
?> </label></p> <?php }
/** * Displays the out of storage quota message in Multisite. * * @since 3.5.0 */ function multisite_over_quota_message() { echo '<p>' . sprintf( /* translators: %s: Allowed space allocation. */ __( 'Sorry, you have used your space allocation of %s. Please delete some files to upload more files.' ), size_format( get_space_allowed() * MB_IN_BYTES ) ) . '</p>'; }
/** * Displays the image and editor in the post editor * * @since 3.5.0 * * @param WP_Post $post A post object. */ function edit_form_image_editor( $post ) { $open = isset( $_GET['image-editor'] );
if ( $open ) { require_once ABSPATH . 'wp-admin/includes/image-edit.php'; }
/** * Fires when an attachment type can't be rendered in the edit form. * * @since 4.6.0 * * @param WP_Post $post A post object. */ do_action( 'wp_edit_form_attachment_display', $post );
printf( /* translators: 1: Link to tutorial, 2: Additional link attributes, 3: Accessibility text. */ __( '<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.' ), /* translators: Localized tutorial, if one exists. W3C Web Accessibility Initiative link has list of existing translations. */ esc_url( __( 'https://www.w3.org/WAI/tutorials/images/decision-tree/' ) ), 'target="_blank"', sprintf( '<span class="screen-reader-text"> %s</span>', /* translators: Hidden accessibility text. */ __( '(opens in a new tab)' ) ) );
/** * Filters the audio and video metadata fields to be shown in the publish meta box. * * The key for each item in the array should correspond to an attachment * metadata key, and the value should be the desired label. * * @since 3.7.0 * @since 4.9.0 Added the `$post` parameter. * * @param array $fields An array of the attachment metadata keys and labels. * @param WP_Post $post WP_Post object for the current attachment. */ $fields = apply_filters( 'media_submitbox_misc_sections', $fields, $post );
foreach ( $fields as $key => $label ) { if ( empty( $meta[ $key ] ) ) { continue; }
/** * Filters the audio attachment metadata fields to be shown in the publish meta box. * * The key for each item in the array should correspond to an attachment * metadata key, and the value should be the desired label. * * @since 3.7.0 * @since 4.9.0 Added the `$post` parameter. * * @param array $fields An array of the attachment metadata keys and labels. * @param WP_Post $post WP_Post object for the current attachment. */ $audio_fields = apply_filters( 'audio_submitbox_misc_sections', $fields, $post );
foreach ( $audio_fields as $key => $label ) { if ( empty( $meta['audio'][ $key ] ) ) { continue; }
$id3 = new getID3(); // Required to get the `created_timestamp` value. $id3->options_audiovideo_quicktime_ReturnAtomData = true; // phpcs:ignore WordPress.NamingConventions.ValidVariableName
/** * Filters the array of metadata retrieved from a video. * * In core, usually this selection is what is stored. * More complete data can be parsed from the `$data` parameter. * * @since 4.9.0 * * @param array $metadata Filtered video metadata. * @param string $file Path to video file. * @param string|null $file_format File format of video, as analyzed by getID3. * Null if unknown. * @param array $data Raw metadata from getID3. */ return apply_filters( 'wp_read_video_metadata', $metadata, $file, $file_format, $data ); }
/** * Retrieves metadata from an audio file's ID3 tags. * * @since 3.6.0 * * @param string $file Path to file. * @return array|false Returns array of metadata, if found. */ function wp_read_audio_metadata( $file ) { if ( ! file_exists( $file ) ) { return false; }
$id3 = new getID3(); // Required to get the `created_timestamp` value. $id3->options_audiovideo_quicktime_ReturnAtomData = true; // phpcs:ignore WordPress.NamingConventions.ValidVariableName
/** * Filters the array of metadata retrieved from an audio file. * * In core, usually this selection is what is stored. * More complete data can be parsed from the `$data` parameter. * * @since 6.1.0 * * @param array $metadata Filtered audio metadata. * @param string $file Path to audio file. * @param string|null $file_format File format of audio, as analyzed by getID3. * Null if unknown. * @param array $data Raw metadata from getID3. */ return apply_filters( 'wp_read_audio_metadata', $metadata, $file, $file_format, $data ); }
/** * Parses creation date from media metadata. * * The getID3 library doesn't have a standard method for getting creation dates, * so the location of this data can vary based on the MIME type. * * @since 4.9.0 * * @link https://github.com/JamesHeinrich/getID3/blob/master/structure.txt * * @param array $metadata The metadata returned by getID3::analyze(). * @return int|false A UNIX timestamp for the media's creation date if available * or a boolean FALSE if a timestamp could not be determined. */ function wp_get_media_creation_timestamp( $metadata ) { $creation_date = false;
if ( empty( $metadata['fileformat'] ) ) { return $creation_date; }
switch ( $metadata['fileformat'] ) { case 'asf': if ( isset( $metadata['asf']['file_properties_object']['creation_date_unix'] ) ) { $creation_date = (int) $metadata['asf']['file_properties_object']['creation_date_unix']; } break;
case 'matroska': case 'webm': if ( isset( $metadata['matroska']['comments']['creation_time'][0] ) ) { $creation_date = strtotime( $metadata['matroska']['comments']['creation_time'][0] ); } elseif ( isset( $metadata['matroska']['info'][0]['DateUTC_unix'] ) ) { $creation_date = (int) $metadata['matroska']['info'][0]['DateUTC_unix']; } break;
case 'quicktime': case 'mp4': if ( isset( $metadata['quicktime']['moov']['subatoms'][0]['creation_time_unix'] ) ) { $creation_date = (int) $metadata['quicktime']['moov']['subatoms'][0]['creation_time_unix']; } break; }
return $creation_date; }
/** * Encapsulates the logic for Attach/Detach actions. * * @since 4.2.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $parent_id Attachment parent ID. * @param string $action Optional. Attach/detach action. Accepts 'attach' or 'detach'. * Default 'attach'. */ function wp_media_attach_action( $parent_id, $action = 'attach' ) { global $wpdb;
if ( ! $parent_id ) { return; }
if ( ! current_user_can( 'edit_post', $parent_id ) ) { wp_die( __( 'Sorry, you are not allowed to edit this post.' ) ); }
if ( 'attach' === $action ) { $result = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ( $ids_string )", $parent_id ) ); } else { $result = $wpdb->query( "UPDATE $wpdb->posts SET post_parent = 0 WHERE post_type = 'attachment' AND ID IN ( $ids_string )" ); } }
if ( isset( $result ) ) { foreach ( $ids as $attachment_id ) { /** * Fires when media is attached or detached from a post. * * @since 5.5.0 * * @param string $action Attach/detach action. Accepts 'attach' or 'detach'. * @param int $attachment_id The attachment ID. * @param int $parent_id Attachment parent ID. */ do_action( 'wp_media_attach_action', $action, $attachment_id, $parent_id );