WordPress.org

Make WordPress Core

Changeset 27209


Ignore:
Timestamp:
02/20/2014 05:49:30 PM (7 years ago)
Author:
wonderboymusic
Message:

Allow pseudo post types attachment:audio and attachment:video to get the media modal on Edit Media when they support featured images.

Introduces post_supports_thumbnails( $post ) and theme_supports_thumbnails( $post ) to cut down on duplicated code everytime this needs to be checked. There will be more cases forthcoming.

See #26631.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/edit-form-advanced.php

    r27036 r27209  
    2525$action = isset($action) ? $action : '';
    2626
    27 if ( post_type_supports($post_type, 'editor') || post_type_supports($post_type, 'thumbnail') ) {
     27$media_type = false;
     28if ( 'attachment' && $post_ID ) {
     29    $post = get_post( $post_ID );
     30    $media_type = post_supports_thumbnails( $post );
     31}
     32
     33if ( post_type_supports( $post_type, 'editor' ) || post_type_supports( $post_type, 'thumbnail' ) || $media_type ) {
    2834    add_thickbox();
    2935    wp_enqueue_media( array( 'post' => $post_ID ) );
  • trunk/src/wp-includes/media.php

    r27140 r27209  
    20132013        );
    20142014
    2015         if ( current_theme_supports( 'post-thumbnails', $post->post_type ) && post_type_supports( $post->post_type, 'thumbnail' ) ) {
     2015        if ( theme_supports_thumbnails( $post ) && post_supports_thumbnails( $post ) ) {
    20162016            $featured_image_id = get_post_meta( $post->ID, '_thumbnail_id', true );
    20172017            $settings['post']['featuredImageId'] = $featured_image_id ? $featured_image_id : -1;
     
    22412241 * If an attachment is missing its metadata, try to regenerate it
    22422242 *
     2243 * @since 3.9.0
     2244 *
    22432245 * @param post $attachment Post object.
    22442246 */
     
    22602262    }
    22612263}
     2264
     2265/**
     2266 * Determine if a post supports thumbnails based on the passed $post
     2267 *
     2268 * @since 3.9.0
     2269 *
     2270 * @param WP_Post $post
     2271 *
     2272 * @return boolean
     2273 */
     2274function post_supports_thumbnails( $post ) {
     2275    if ( 'attachment' === $post->post_type ) {
     2276        if ( 0 === strpos( $post->post_mime_type, 'audio' ) ) {
     2277            return post_type_supports( 'attachment:audio', 'thumbnail' );
     2278        } elseif ( 0 === strpos( $post->post_mime_type, 'video' ) ) {
     2279            return post_type_supports( 'attachment:video', 'thumbnail' );
     2280        }
     2281    }
     2282
     2283    return post_type_supports( $post->post_type, 'thumbnail' );
     2284}
     2285
     2286/**
     2287 * Determine if a theme supports thumbnails based on the passed $post
     2288 *
     2289 * @since 3.9.0
     2290 *
     2291 * @param WP_Post $post
     2292 *
     2293 * @return boolean
     2294 */
     2295function theme_supports_thumbnails( $post ) {
     2296    if ( 'attachment' === $post->post_type ) {
     2297        if ( 0 === strpos( $post->post_mime_type, 'audio' ) ) {
     2298            return current_theme_supports( 'post-thumbnails', 'attachment:audio' );
     2299        } elseif ( 0 === strpos( $post->post_mime_type, 'video' ) ) {
     2300            return current_theme_supports( 'post-thumbnails', 'attachment:video' );
     2301        }
     2302    }
     2303
     2304    return current_theme_supports( 'post-thumbnails', $post->post_type );
     2305}
Note: See TracChangeset for help on using the changeset viewer.