Make WordPress Core


Ignore:
Timestamp:
04/23/2014 10:04:03 PM (10 years ago)
Author:
johnbillion
Message:

Avoid an expensive attachment counting query on the post editing screen. See #27985, for trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r28106 r28191  
    22932293
    22942294/**
     2295 * Determine if at least one attachment of a particular mime-type has been uploaded
     2296 *
     2297 * @global wpdb $wpdb
     2298 *
     2299 * @since 3.9.1
     2300 *
     2301 * @param string $mime_type The mime-type string to check.
     2302 *
     2303 * @return int|null If exist, the post ID of the first found attachment.
     2304 */
     2305function wp_has_mime_type_attachments( $mime_type ) {
     2306    global $wpdb;
     2307    $sql = sprintf( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE '%s%%' LIMIT 1", like_escape( $mime_type ) );
     2308    return $wpdb->get_var( $sql );
     2309}
     2310
     2311/**
    22952312 * Get default post mime types
    22962313 *
Note: See TracChangeset for help on using the changeset viewer.