WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/04/2012 04:29:28 PM (9 years ago)
Author:
ryan
Message:

Use get_post() instead of global $post.
Make the $post argument to get_post() optional, defaulting to the current post in The Loop.

Props nacin
see #21309

File:
1 edited

Legend:

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

    r21655 r21735  
    373373 * @link http://codex.wordpress.org/Function_Reference/get_post
    374374 *
    375  * @param int|object $post Post ID or post object.
     375 * @param int|object $post Post ID or post object. Optional, default is the current post from the loop.
    376376 * @param string $output Optional, default is Object. Either OBJECT, ARRAY_A, or ARRAY_N.
    377377 * @param string $filter Optional, default is raw.
    378378 * @return WP_Post|null WP_Post on success or null on failure
    379379 */
    380 function get_post( $post, $output = OBJECT, $filter = 'raw' ) {
     380function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) {
    381381    if ( empty( $post ) && isset( $GLOBALS['post'] ) )
    382382        $post = $GLOBALS['post'];
     
    946946 * @uses $post The Loop current post global
    947947 *
    948  * @param mixed $the_post Optional. Post object or post ID.
     948 * @param mixed $post Optional. Post object or post ID.
    949949 * @return bool|string post type or false on failure.
    950950 */
    951 function get_post_type( $the_post = false ) {
    952     global $post;
    953 
    954     if ( false === $the_post )
    955         $the_post = $post;
    956     elseif ( is_numeric($the_post) )
    957         $the_post = get_post($the_post);
    958 
    959     if ( is_object($the_post) )
    960         return $the_post->post_type;
     951function get_post_type( $post = null ) {
     952    if ( $post = get_post( $post ) )
     953        return $post->post_type;
    961954
    962955    return false;
Note: See TracChangeset for help on using the changeset viewer.