postmeta} WHERE meta_key = 'default_thumbnail_for'"; $results = $wpdb->get_results( $query ); if ( is_array( $results ) ) { foreach( $results as $result ) { $extensions = array_map( 'strtolower', array_map( 'trim', explode( ',', $result->meta_value ) ) ); foreach ( $extensions as $extension ) { self::$default_thumbnails[ $extension ] = absint( $result->post_id ); } } add_filter( 'mla_gallery_featured_image', 'MLADefaultFeaturedImage::mla_gallery_featured_image', 10, 4 ); } } /** * Map file extensions to thumbnail items * * @since 1.00 * * @var array ( extension => item_ID */ private static $default_thumbnails = array(); /** * Replace empty Featured Image tags with a default based on the item's file extension * * @since 1.00 * * @param array parameter_name => parameter_value pairs */ public static function mla_gallery_featured_image( $feature, $attachment, $size, $item_values ) { if ( ! empty( $feature ) ) { return $feature; } $extension = strtolower( pathinfo( $item_values['file'], PATHINFO_EXTENSION ) ); if ( isset( self::$default_thumbnails[ $extension ] ) ) { $feature = wp_get_attachment_image( self::$default_thumbnails[ $extension ], $size, false, array( 'class' => 'attachment-thumbnail' ) ); } return $feature; } // mla_gallery_featured_image } // Class MLADefaultFeaturedImage /* * Install the filters at an early opportunity */ add_action('init', 'MLADefaultFeaturedImage::initialize'); ?>