WordPress.org

Make WordPress Core

Ticket #16149: 16149.diff

File 16149.diff, 2.7 KB (added by nacin, 2 years ago)
  • wp-includes/post.php

     
    534534                        $format = 'post-format-' . $format; 
    535535        } 
    536536 
     537        if ( ! term_exists( 'post-format-standard', 'post_format' ) ) 
     538                wp_insert_term( 'post-format-standard', 'post_format' ); 
     539 
    537540        return wp_set_post_terms($post->ID, $format, 'post_format'); 
    538541} 
    539542 
     
    51445147} 
    51455148 
    51465149/** 
    5147  * Filters the request to allow for the format prefix. 
     5150 * Filters the request to allow for the format prefix and handles the standard post format query. 
    51485151 * 
    51495152 * @access private 
    51505153 * @since 3.1.0 
     
    51525155function _post_format_request( $qvs ) { 
    51535156        if ( ! isset( $qvs['post_format'] ) ) 
    51545157                return $qvs; 
    5155         $slugs = array_flip( get_post_format_slugs() ); 
    5156         if ( isset( $slugs[ $qvs['post_format'] ] ) ) 
    5157                 $qvs['post_format'] = 'post-format-' . $slugs[ $qvs['post_format'] ]; 
     5158        $by_raw_slug = get_post_format_slugs(); 
     5159        $by_translated_slug = array_flip( $by_raw_slug ); 
     5160        if ( isset( $by_translated_slug[ $qvs['post_format'] ] ) ) { 
     5161                if ( 'standard' == $by_translated_slug[ $qvs['post_format'] ] ) { 
     5162                        // If 'standard', then query every persistent format with a NOT IN instead. 
     5163                        unset( $qvs['post_format'] ); 
     5164                        $formats = array(); 
     5165                        $raw_slugs = array_diff( array_keys( $by_raw_slug ), array( 'standard' ) ); 
     5166                        foreach ( $raw_slugs as $format ) { 
     5167                                        $formats[] = 'post-format-' . $format; 
     5168                        } 
     5169                        if ( ! isset( $qvs['tax_query'] ) ) 
     5170                                $qvs['tax_query'] = array(); 
     5171                        $qvs['tax_query'][] = array( 'taxonomy' => 'post_format', 'terms' => $formats, 'field' => 'slug', 'operator' => 'NOT IN' ); 
     5172                        $qvs['tax_query']['relation'] = 'AND'; 
     5173                        // Repair the query flags and queried object. 
     5174                        add_action( 'parse_query', '_post_format_parse_query' ); 
     5175                } else { 
     5176                        $qvs['post_format'] = 'post-format-' . $by_translated_slug[ $qvs['post_format'] ]; 
     5177                } 
     5178        } 
     5179        // Only post types that support formats should be queried. 
     5180        // Especially important for the NOT IN 'standard' format query. 
     5181        $tax = get_taxonomy( 'post_format' ); 
     5182        $qvs['post_type'] = $tax->object_type; 
    51585183        return $qvs; 
    51595184} 
    51605185add_filter( 'request', '_post_format_request' ); 
    51615186 
    51625187/** 
     5188 * Filters the query object when the standard post format is requested. 
     5189 * 
     5190 * @access private 
     5191 * @since 3.1.0 
     5192 */ 
     5193function _post_format_parse_query( $query ) { 
     5194        $query->is_tax = $query->is_archive = true; 
     5195        $query->is_home = false; 
     5196        $query->queried_object = get_term_by( 'slug', 'post-format-standard', 'post_format' );  
     5197        $query->queried_object_id = $query->queried_object->term_id; 
     5198} 
     5199 
     5200/** 
    51635201 * Filters the post format term link to remove the format prefix. 
    51645202 * 
    51655203 * @access private