Make WordPress Core


Ignore:
Timestamp:
02/11/2015 03:59:06 AM (10 years ago)
Author:
SergeyBiryukov
Message:

Always pass back the custom classes get_post_class() was called with, even if the post was not found.

props F J Kaiser, Bueltge.
fixes #22271.

File:
1 edited

Legend:

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

    r31356 r31408  
    405405 */
    406406function get_post_class( $class = '', $post_id = null ) {
    407     $post = get_post($post_id);
     407    $post = get_post( $post_id );
    408408
    409409    $classes = array();
    410410
    411     if ( empty($post) )
     411    if ( $class ) {
     412        if ( ! is_array( $class ) ) {
     413            $class = preg_split( '#\s+#', $class );
     414        }
     415        $classes = array_map( 'esc_attr', $class );
     416    }
     417
     418    if ( ! $post ) {
    412419        return $classes;
     420    }
    413421
    414422    $classes[] = 'post-' . $post->ID;
     
    467475    }
    468476
    469     if ( !empty($class) ) {
    470         if ( !is_array( $class ) )
    471             $class = preg_split('#\s+#', $class);
    472         $classes = array_merge($classes, $class);
    473     }
    474 
    475     $classes = array_map('esc_attr', $classes);
     477    $classes = array_map( 'esc_attr', $classes );
    476478
    477479    /**
Note: See TracChangeset for help on using the changeset viewer.