Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r42201 r42343  
    1616 */
    1717function get_post_format( $post = null ) {
    18         if ( ! $post = get_post( $post ) )
    19                 return false;
    20 
    21         if ( ! post_type_supports( $post->post_type, 'post-formats' ) )
    22                 return false;
     18        if ( ! $post = get_post( $post ) ) {
     19                return false;
     20        }
     21
     22        if ( ! post_type_supports( $post->post_type, 'post-formats' ) ) {
     23                return false;
     24        }
    2325
    2426        $_format = get_the_terms( $post->ID, 'post_format' );
    2527
    26         if ( empty( $_format ) )
    27                 return false;
     28        if ( empty( $_format ) ) {
     29                return false;
     30        }
    2831
    2932        $format = reset( $_format );
    3033
    31         return str_replace('post-format-', '', $format->slug );
     34        return str_replace( 'post-format-', '', $format->slug );
    3235}
    3336
     
    6568        $post = get_post( $post );
    6669
    67         if ( empty( $post ) )
     70        if ( empty( $post ) ) {
    6871                return new WP_Error( 'invalid_post', __( 'Invalid post.' ) );
     72        }
    6973
    7074        if ( ! empty( $format ) ) {
    7175                $format = sanitize_key( $format );
    72                 if ( 'standard' === $format || ! in_array( $format, get_post_format_slugs() ) )
     76                if ( 'standard' === $format || ! in_array( $format, get_post_format_slugs() ) ) {
    7377                        $format = '';
    74                 else
     78                } else {
    7579                        $format = 'post-format-' . $format;
     80                }
    7681        }
    7782
     
    8994        $strings = array(
    9095                'standard' => _x( 'Standard', 'Post format' ), // Special case. any value that evals to false will be considered standard
    91                 'aside'    => _x( 'Aside',    'Post format' ),
    92                 'chat'     => _x( 'Chat',     'Post format' ),
    93                 'gallery'  => _x( 'Gallery',  'Post format' ),
    94                 'link'     => _x( 'Link',     'Post format' ),
    95                 'image'    => _x( 'Image',    'Post format' ),
    96                 'quote'    => _x( 'Quote',    'Post format' ),
    97                 'status'   => _x( 'Status',   'Post format' ),
    98                 'video'    => _x( 'Video',    'Post format' ),
    99                 'audio'    => _x( 'Audio',    'Post format' ),
     96                'aside'    => _x( 'Aside', 'Post format' ),
     97                'chat'     => _x( 'Chat', 'Post format' ),
     98                'gallery'  => _x( 'Gallery', 'Post format' ),
     99                'link'     => _x( 'Link', 'Post format' ),
     100                'image'    => _x( 'Image', 'Post format' ),
     101                'quote'    => _x( 'Quote', 'Post format' ),
     102                'status'   => _x( 'Status', 'Post format' ),
     103                'video'    => _x( 'Video', 'Post format' ),
     104                'audio'    => _x( 'Audio', 'Post format' ),
    100105        );
    101106        return $strings;
     
    124129function get_post_format_string( $slug ) {
    125130        $strings = get_post_format_strings();
    126         if ( !$slug )
     131        if ( ! $slug ) {
    127132                return $strings['standard'];
    128         else
    129                 return ( isset( $strings[$slug] ) ) ? $strings[$slug] : '';
     133        } else {
     134                return ( isset( $strings[ $slug ] ) ) ? $strings[ $slug ] : '';
     135        }
    130136}
    131137
     
    139145 */
    140146function get_post_format_link( $format ) {
    141         $term = get_term_by('slug', 'post-format-' . $format, 'post_format' );
    142         if ( ! $term || is_wp_error( $term ) )
    143                 return false;
     147        $term = get_term_by( 'slug', 'post-format-' . $format, 'post_format' );
     148        if ( ! $term || is_wp_error( $term ) ) {
     149                return false;
     150        }
    144151        return get_term_link( $term );
    145152}
     
    155162 */
    156163function _post_format_request( $qvs ) {
    157         if ( ! isset( $qvs['post_format'] ) )
     164        if ( ! isset( $qvs['post_format'] ) ) {
    158165                return $qvs;
     166        }
    159167        $slugs = get_post_format_slugs();
    160         if ( isset( $slugs[ $qvs['post_format'] ] ) )
     168        if ( isset( $slugs[ $qvs['post_format'] ] ) ) {
    161169                $qvs['post_format'] = 'post-format-' . $slugs[ $qvs['post_format'] ];
     170        }
    162171        $tax = get_taxonomy( 'post_format' );
    163         if ( ! is_admin() )
     172        if ( ! is_admin() ) {
    164173                $qvs['post_type'] = $tax->object_type;
     174        }
    165175        return $qvs;
    166176}
     
    223233                if ( isset( $args['fields'] ) && 'names' == $args['fields'] ) {
    224234                        foreach ( $terms as $order => $name ) {
    225                                 $terms[$order] = get_post_format_string( str_replace( 'post-format-', '', $name ) );
     235                                $terms[ $order ] = get_post_format_string( str_replace( 'post-format-', '', $name ) );
    226236                        }
    227237                } else {
    228238                        foreach ( (array) $terms as $order => $term ) {
    229239                                if ( isset( $term->taxonomy ) && 'post_format' == $term->taxonomy ) {
    230                                         $terms[$order]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) );
     240                                        $terms[ $order ]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) );
    231241                                }
    232242                        }
     
    248258        foreach ( (array) $terms as $order => $term ) {
    249259                if ( isset( $term->taxonomy ) && 'post_format' == $term->taxonomy ) {
    250                         $terms[$order]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) );
     260                        $terms[ $order ]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) );
    251261                }
    252262        }
Note: See TracChangeset for help on using the changeset viewer.