Changeset 42343 for trunk/src/wp-includes/post-formats.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/post-formats.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post-formats.php
r42201 r42343 16 16 */ 17 17 function 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 } 23 25 24 26 $_format = get_the_terms( $post->ID, 'post_format' ); 25 27 26 if ( empty( $_format ) ) 27 return false; 28 if ( empty( $_format ) ) { 29 return false; 30 } 28 31 29 32 $format = reset( $_format ); 30 33 31 return str_replace( 'post-format-', '', $format->slug );34 return str_replace( 'post-format-', '', $format->slug ); 32 35 } 33 36 … … 65 68 $post = get_post( $post ); 66 69 67 if ( empty( $post ) ) 70 if ( empty( $post ) ) { 68 71 return new WP_Error( 'invalid_post', __( 'Invalid post.' ) ); 72 } 69 73 70 74 if ( ! empty( $format ) ) { 71 75 $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() ) ) { 73 77 $format = ''; 74 else78 } else { 75 79 $format = 'post-format-' . $format; 80 } 76 81 } 77 82 … … 89 94 $strings = array( 90 95 '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' ), 100 105 ); 101 106 return $strings; … … 124 129 function get_post_format_string( $slug ) { 125 130 $strings = get_post_format_strings(); 126 if ( ! $slug )131 if ( ! $slug ) { 127 132 return $strings['standard']; 128 else 129 return ( isset( $strings[$slug] ) ) ? $strings[$slug] : ''; 133 } else { 134 return ( isset( $strings[ $slug ] ) ) ? $strings[ $slug ] : ''; 135 } 130 136 } 131 137 … … 139 145 */ 140 146 function 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 } 144 151 return get_term_link( $term ); 145 152 } … … 155 162 */ 156 163 function _post_format_request( $qvs ) { 157 if ( ! isset( $qvs['post_format'] ) ) 164 if ( ! isset( $qvs['post_format'] ) ) { 158 165 return $qvs; 166 } 159 167 $slugs = get_post_format_slugs(); 160 if ( isset( $slugs[ $qvs['post_format'] ] ) ) 168 if ( isset( $slugs[ $qvs['post_format'] ] ) ) { 161 169 $qvs['post_format'] = 'post-format-' . $slugs[ $qvs['post_format'] ]; 170 } 162 171 $tax = get_taxonomy( 'post_format' ); 163 if ( ! is_admin() ) 172 if ( ! is_admin() ) { 164 173 $qvs['post_type'] = $tax->object_type; 174 } 165 175 return $qvs; 166 176 } … … 223 233 if ( isset( $args['fields'] ) && 'names' == $args['fields'] ) { 224 234 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 ) ); 226 236 } 227 237 } else { 228 238 foreach ( (array) $terms as $order => $term ) { 229 239 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 ) ); 231 241 } 232 242 } … … 248 258 foreach ( (array) $terms as $order => $term ) { 249 259 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 ) ); 251 261 } 252 262 }
Note: See TracChangeset
for help on using the changeset viewer.