WordPress.org

Make WordPress Core

Changeset 21735


Ignore:
Timestamp:
09/04/2012 04:29:28 PM (8 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

Location:
trunk
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-comments-list-table.php

    r21323 r21735  
    303303
    304304    function single_row( $a_comment ) {
    305         global $post, $comment;
     305        global $comment;
     306        $post = get_post();
    306307
    307308        $comment = $a_comment;
     
    326327
    327328    function column_comment( $comment ) {
    328         global $post, $comment_status;
     329        global $comment_status;
     330        $post = get_post();
    329331
    330332        $user_can = $this->user_can;
     
    480482
    481483    function column_response( $comment ) {
    482         global $post;
     484        $post = get_post();
    483485
    484486        if ( isset( $this->pending_count[$post->ID] ) ) {
  • trunk/wp-admin/includes/class-wp-media-list-table.php

    r21504 r21735  
    157157
    158158    function display_rows() {
    159         global $post, $id;
     159        $post = get_post();
     160        $id = $post->ID;
    160161
    161162        add_filter( 'the_title','esc_html' );
  • trunk/wp-admin/includes/class-wp-posts-list-table.php

    r21597 r21735  
    317317
    318318    function _display_rows( $posts, $level = 0 ) {
    319         global $post, $mode;
     319        global $mode;
    320320
    321321        // Create array of post IDs.
     
    459459    }
    460460
    461     function single_row( $a_post, $level = 0 ) {
    462         global $post, $mode;
     461    function single_row( $post, $level = 0 ) {
     462        global $mode;
    463463        static $alternate;
    464464
    465         $global_post = $post;
    466         $post = $a_post;
     465        $global_post = get_post();
     466        $GLOBALS['post'] = $post;
    467467        setup_postdata( $post );
    468468
     
    530530                else {
    531531                    $attributes = 'class="post-title page-title column-title"' . $style;
    532                    
     532
    533533                    $pad = str_repeat( '— ', $level );
    534534?>
     
    685685        </tr>
    686686    <?php
    687         $post = $global_post;
     687        $GLOBALS['post'] = $global_post;
    688688    }
    689689
  • trunk/wp-admin/includes/export.php

    r19859 r21735  
    280280     */
    281281    function wxr_post_taxonomy() {
    282         global $post;
     282        $post = get_post();
    283283
    284284        $taxonomies = get_object_taxonomies( $post->post_type );
  • trunk/wp-admin/includes/meta-boxes.php

    r21688 r21735  
    467467 * @param object $post
    468468 */
    469 function post_comment_meta_box($post) {
    470     global $wpdb, $post_ID;
     469function post_comment_meta_box( $post ) {
     470    global $wpdb;
    471471
    472472    wp_nonce_field( 'get-comments', 'add_comment_nonce', false );
    473473    ?>
    474     <p class="hide-if-no-js" id="add-new-comment"><a href="#commentstatusdiv" onclick="commentReply.addcomment(<?php echo $post_ID; ?>);return false;"><?php _e('Add comment'); ?></a></p>
     474    <p class="hide-if-no-js" id="add-new-comment"><a href="#commentstatusdiv" onclick="commentReply.addcomment(<?php echo $post->ID; ?>);return false;"><?php _e('Add comment'); ?></a></p>
    475475    <?php
    476476
    477     $total = get_comments( array( 'post_id' => $post_ID, 'number' => 1, 'count' => true ) );
     477    $total = get_comments( array( 'post_id' => $post->ID, 'number' => 1, 'count' => true ) );
    478478    $wp_list_table = _get_list_table('WP_Post_Comments_List_Table');
    479479    $wp_list_table->display( true );
     
    911911 * @since 2.9.0
    912912 */
    913 function post_thumbnail_meta_box() {
    914     global $post;
     913function post_thumbnail_meta_box( $post ) {
    915914    $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true );
    916915    echo _wp_post_thumbnail_html( $thumbnail_id );
  • trunk/wp-admin/includes/post.php

    r21651 r21735  
    11221122 *
    11231123 * @param int $thumbnail_id ID of the attachment used for thumbnail
    1124  * @param int $post_id ID of the post associated with the thumbnail, defaults to global $post_ID
     1124 * @param mixed $post The post ID or object associated with the thumbnail, defaults to global $post.
    11251125 * @return string html
    11261126 */
    1127 function _wp_post_thumbnail_html( $thumbnail_id = null, $post_id = null ) {
    1128     global $content_width, $_wp_additional_image_sizes, $post_ID;
    1129 
    1130     if ( empty( $post_id ) )
    1131         $post_id = $post_ID;
    1132 
    1133     $upload_iframe_src = esc_url( get_upload_iframe_src('image', $post_id) );
     1127function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) {
     1128    global $content_width, $_wp_additional_image_sizes;
     1129
     1130    $post = get_post( $post );
     1131
     1132    $upload_iframe_src = esc_url( get_upload_iframe_src('image', $post->ID ) );
    11341133    $set_thumbnail_link = '<p class="hide-if-no-js"><a title="' . esc_attr__( 'Set featured image' ) . '" href="%s" id="set-post-thumbnail" class="thickbox">%s</a></p>';
    11351134    $content = sprintf( $set_thumbnail_link, $upload_iframe_src, esc_html__( 'Set featured image' ) );
     
    11431142            $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'post-thumbnail' );
    11441143        if ( !empty( $thumbnail_html ) ) {
    1145             $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$post_id" );
     1144            $ajax_nonce = wp_create_nonce( 'set_post_thumbnail-' . $post->ID );
    11461145            $content = sprintf( $set_thumbnail_link, $upload_iframe_src, $thumbnail_html );
    11471146            $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail(\'' . $ajax_nonce . '\');return false;">' . esc_html__( 'Remove featured image' ) . '</a></p>';
     
    11501149    }
    11511150
    1152     return apply_filters( 'admin_post_thumbnail_html', $content, $post_id );
     1151    return apply_filters( 'admin_post_thumbnail_html', $content, $post->ID );
    11531152}
    11541153
     
    12081207 */
    12091208function _admin_notice_post_locked() {
    1210     global $post;
    1211 
     1209    $post = get_post();
    12121210    $lock = explode( ':', get_post_meta( $post->ID, '_edit_lock', true ) );
    12131211    $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true );
  • trunk/wp-admin/includes/template.php

    r21659 r21735  
    167167 */
    168168function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
    169     global $post_ID;
    170 
    171     if ( $post_ID )
    172         $checked_terms = wp_get_object_terms($post_ID, $taxonomy, array('fields'=>'ids'));
     169    $post = get_post();
     170    if ( $post->ID )
     171        $checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields'=>'ids'));
    173172    else
    174173        $checked_terms = array();
     
    576575 */
    577576function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
    578     global $wp_locale, $post, $comment;
     577    global $wp_locale, $comment;
     578    $post = get_post();
    579579
    580580    if ( $for_post )
     
    671671 */
    672672function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
    673     global $wpdb, $post_ID;
     673    global $wpdb;
     674    $post = get_post();
    674675    $items = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' ORDER BY menu_order", $parent) );
    675676
     
    677678        foreach ( $items as $item ) {
    678679            // A page cannot be its own parent.
    679             if (!empty ( $post_ID ) ) {
    680                 if ( $item->ID == $post_ID ) {
    681                     continue;
    682                 }
    683             }
     680            if ( $post->ID && $item->ID == $post->ID )
     681                continue;
     682
    684683            $pad = str_repeat( '&nbsp;', $level * 3 );
    685684            if ( $item->ID == $default)
     
    13461345 */
    13471346function the_post_password() {
    1348     global $post;
    1349     if ( isset( $post->post_password ) ) echo esc_attr( $post->post_password );
     1347    $post = get_post();
     1348    if ( isset( $post->post_password ) )
     1349        echo esc_attr( $post->post_password );
    13501350}
    13511351
     
    13571357 *
    13581358 * @since 2.7.0
    1359  * @param int $post_id The post id. If not supplied the global $post is used.
     1359 * @param mixed $post Post id or object. If not supplied the global $post is used.
    13601360 * @return string The post title if set
    13611361 */
    1362 function _draft_or_post_title( $post_id = 0 ) {
    1363     $title = get_the_title($post_id);
    1364     if ( empty($title) )
    1365         $title = __('(no title)');
     1362function _draft_or_post_title( $post = 0 ) {
     1363    $title = get_the_title( $post );
     1364    if ( empty( $title ) )
     1365        $title = __( '(no title)' );
    13661366    return $title;
    13671367}
  • trunk/wp-includes/admin-bar.php

    r21549 r21735  
    420420 */
    421421function wp_admin_bar_edit_menu( $wp_admin_bar ) {
    422     global $post, $tag, $wp_the_query;
     422    global $tag, $wp_the_query;
    423423
    424424    if ( is_admin() ) {
    425425        $current_screen = get_current_screen();
     426        $post = get_post();
    426427
    427428        if ( 'post' == $current_screen->base
     
    620621
    621622    $title = '<span class="ab-icon"></span><span class="ab-label">' . number_format_i18n( $update_data['counts']['total'] ) . '</span>';
    622     $title .= '<span class="screen-reader-text">' . $update_data['title'] . '</span>'; 
     623    $title .= '<span class="screen-reader-text">' . $update_data['title'] . '</span>';
    623624
    624625    $wp_admin_bar->add_menu( array(
  • trunk/wp-includes/author-template.php

    r20615 r21735  
    7070 */
    7171function get_the_modified_author() {
    72     global $post;
    73     if ( $last_id = get_post_meta($post->ID, '_edit_last', true) ) {
     72    if ( $last_id = get_post_meta( get_post()->ID, '_edit_last', true) ) {
    7473        $last_user = get_userdata($last_id);
    7574        return apply_filters('the_modified_author', $last_user->display_name);
     
    165164 */
    166165function get_the_author_posts() {
    167     global $post;
    168     return count_user_posts($post->post_author);
     166    return count_user_posts( get_post()->post_author );
    169167}
    170168
  • trunk/wp-includes/category-template.php

    r20675 r21735  
    10551055 * @since 2.5.0
    10561056 *
    1057  * @param int $id Post ID.
     1057 * @param mixed $post Post ID or object.
    10581058 * @param string $taxonomy Taxonomy name.
    10591059 * @return array|bool False on failure. Array of term objects on success.
    10601060 */
    1061 function get_the_terms( $id, $taxonomy ) {
    1062     global $post;
    1063 
    1064     $id = (int) $id;
    1065 
    1066     if ( !$id ) {
    1067         if ( empty( $post->ID ) )
    1068             return false;
    1069         else
    1070             $id = (int) $post->ID;
    1071     }
    1072 
    1073     $terms = get_object_term_cache( $id, $taxonomy );
     1061function get_the_terms( $post, $taxonomy ) {
     1062    if ( ! $post = get_post( $post ) )
     1063        return false;
     1064
     1065    $terms = get_object_term_cache( $post->ID, $taxonomy );
    10741066    if ( false === $terms ) {
    1075         $terms = wp_get_object_terms( $id, $taxonomy );
    1076         wp_cache_add($id, $terms, $taxonomy . '_relationships');
    1077     }
    1078 
    1079     $terms = apply_filters( 'get_the_terms', $terms, $id, $taxonomy );
     1067        $terms = wp_get_object_terms( $post->ID, $taxonomy );
     1068        wp_cache_add($post->ID, $terms, $taxonomy . '_relationships');
     1069    }
     1070
     1071    $terms = apply_filters( 'get_the_terms', $terms, $post->ID, $taxonomy );
    10801072
    10811073    if ( empty( $terms ) )
  • trunk/wp-includes/class-wp-atom-server.php

    r21651 r21735  
    847847     * @return string
    848848     */
    849     function get_entry_url($postID = null) {
     849    function get_entry_url( $postID = null ) {
    850850        if (!isset($postID)) {
    851             global $post;
    852             $postID = (int) $post->ID;
     851            $postID = (int) get_post()->ID;
    853852        }
    854853
     
    879878    function get_media_url($postID = null) {
    880879        if (!isset($postID)) {
    881             global $post;
    882             $postID = (int) $post->ID;
     880            $postID = (int) get_post()->ID;
    883881        }
    884882
  • trunk/wp-includes/class-wp-editor.php

    r21664 r21735  
    127127
    128128    public static function editor_settings($editor_id, $set) {
    129         global $editor_styles, $post;
     129        global $editor_styles;
    130130        $first_run = false;
    131131
     
    371371            $body_class = $editor_id;
    372372
    373             if ( isset($post) )
    374                 $body_class .= " post-type-$post->post_type";
     373            if ( $post = get_post() )
     374                $body_class .= ' post-type-' . $post->post_type;
    375375
    376376            if ( !empty($set['tinymce']['body_class']) ) {
     
    613613
    614614    public static function wp_fullscreen_html() {
    615         global $content_width, $post;
     615        global $content_width;
     616        $post = get_post();
    616617
    617618        $width = isset($content_width) && 800 > $content_width ? $content_width : 800;
  • trunk/wp-includes/comment-template.php

    r21364 r21735  
    811811 */
    812812function wp_comment_form_unfiltered_html_nonce() {
    813     global $post;
    814 
    815     $post_id = 0;
    816     if ( !empty($post) )
    817         $post_id = $post->ID;
     813    $post = get_post();
     814    $post_id = $post ? $post->ID : 0;
    818815
    819816    if ( current_user_can( 'unfiltered_html' ) ) {
  • trunk/wp-includes/deprecated.php

    r21651 r21735  
    5858 */
    5959function start_wp() {
    60     global $wp_query, $post;
     60    global $wp_query;
    6161
    6262    _deprecated_function( __FUNCTION__, '1.5', __('new WordPress Loop') );
     
    6565    $wp_query->next_post();
    6666
    67     setup_postdata($post);
     67    setup_postdata( get_post() );
    6868}
    6969
  • trunk/wp-includes/general-template.php

    r21610 r21735  
    13121312 */
    13131313function the_date_xml() {
    1314     global $post;
    1315     echo mysql2date('Y-m-d', $post->post_date, false);
     1314    echo mysql2date( 'Y-m-d', get_post()->post_date, false );
    13161315}
    13171316
     
    13681367 */
    13691368function get_the_date( $d = '' ) {
    1370     global $post;
     1369    $post = get_post();
    13711370    $the_date = '';
    13721371
     
    15291528 */
    15301529function the_weekday() {
    1531     global $wp_locale, $post;
    1532     $the_weekday = $wp_locale->get_weekday(mysql2date('w', $post->post_date, false));
     1530    global $wp_locale;
     1531    $the_weekday = $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
    15331532    $the_weekday = apply_filters('the_weekday', $the_weekday);
    15341533    echo $the_weekday;
     
    15471546 */
    15481547function the_weekday_date($before='',$after='') {
    1549     global $wp_locale, $post, $day, $previousweekday;
     1548    global $wp_locale, $day, $previousweekday;
    15501549    $the_weekday_date = '';
    15511550    if ( $currentday != $previousweekday ) {
    15521551        $the_weekday_date .= $before;
    1553         $the_weekday_date .= $wp_locale->get_weekday(mysql2date('w', $post->post_date, false));
     1552        $the_weekday_date .= $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
    15541553        $the_weekday_date .= $after;
    15551554        $previousweekday = $currentday;
  • trunk/wp-includes/link-template.php

    r21734 r21735  
    5555 * @param string $mode Permalink mode can be either 'title', 'id', or default, which is 'id'.
    5656 */
    57 function permalink_anchor($mode = 'id') {
    58     global $post;
    59     switch ( strtolower($mode) ) {
     57function permalink_anchor( $mode = 'id' ) {
     58    $post = get_post();
     59    switch ( strtolower( $mode ) ) {
    6060        case 'title':
    61             $title = sanitize_title($post->post_title) . '-' . $post->ID;
     61            $title = sanitize_title( $post->post_title ) . '-' . $post->ID;
    6262            echo '<a id="'.$title.'"></a>';
    6363            break;
     
    7878 * @return string
    7979 */
    80 function get_permalink($id = 0, $leavename = false) {
     80function get_permalink( $id = 0, $leavename = false ) {
    8181    $rewritecode = array(
    8282        '%year%',
     
    233233 * @since 1.5.0
    234234 *
    235  * @param int $id Optional. Post ID.
     235 * @param mixed $post Optional. Post ID or object.
    236236 * @param bool $leavename Optional, defaults to false. Whether to keep page name.
    237237 * @param bool $sample Optional, defaults to false. Is it a sample permalink.
    238238 * @return string
    239239 */
    240 function get_page_link( $id = false, $leavename = false, $sample = false ) {
    241     global $post;
    242 
    243     $id = (int) $id;
    244     if ( !$id )
    245         $id = (int) $post->ID;
    246 
    247     if ( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') )
     240function get_page_link( $post = false, $leavename = false, $sample = false ) {
     241    $post = get_post( $post );
     242
     243    if ( 'page' == get_option( 'show_on_front' ) && $post->ID == get_option( 'page_on_front' ) )
    248244        $link = home_url('/');
    249245    else
    250         $link = _get_page_link( $id , $leavename, $sample );
    251 
    252     return apply_filters('page_link', $link, $id, $sample);
     246        $link = _get_page_link( $post, $leavename, $sample );
     247
     248    return apply_filters( 'page_link', $link, $post->ID, $sample );
    253249}
    254250
     
    261257 * @access private
    262258 *
    263  * @param int $id Optional. Post ID.
     259 * @param mixed $post Optional. Post ID or object.
    264260 * @param bool $leavename Optional. Leave name.
    265261 * @param bool $sample Optional. Sample permalink.
    266262 * @return string
    267263 */
    268 function _get_page_link( $id = false, $leavename = false, $sample = false ) {
     264function _get_page_link( $post = false, $leavename = false, $sample = false ) {
    269265    global $wp_rewrite;
    270266
    271     $post = get_post( $id );
     267    $post = get_post( $post );
    272268
    273269    $draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
     
    277273    if ( !empty($link) && ( ( isset($post->post_status) && !$draft_or_pending ) || $sample ) ) {
    278274        if ( ! $leavename ) {
    279             $link = str_replace('%pagename%', get_page_uri($id), $link);
     275            $link = str_replace('%pagename%', get_page_uri( $post ), $link);
    280276        }
    281277
     
    283279        $link = user_trailingslashit($link, 'page');
    284280    } else {
    285         $link = home_url("?page_id=$id");
    286     }
    287 
    288     return apply_filters( '_get_page_link', $link, $id );
     281        $link = home_url( '?page_id=' . $post->ID );
     282    }
     283
     284    return apply_filters( '_get_page_link', $link, $post->ID );
    289285}
    290286
     
    296292 * @since 2.0.0
    297293 *
    298  * @param int $id Optional. Post ID.
    299  * @return string
    300  */
    301 function get_attachment_link($id = false) {
    302     global $post, $wp_rewrite;
     294 * @param mixed $post Optional. Post ID or object.
     295 * @return string
     296 */
     297function get_attachment_link( $post = null ) {
     298    global $wp_rewrite;
    303299
    304300    $link = false;
    305301
    306     if ( ! $id)
    307         $id = (int) $post->ID;
    308 
    309     $object = get_post($id);
    310     if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) && ($object->post_parent != $id) ) {
    311         $parent = get_post($object->post_parent);
     302    $post = get_post( $post );
     303
     304    if ( $wp_rewrite->using_permalinks() && ( $post->post_parent > 0 ) && ( $post->post_parent != $post->ID ) ) {
     305        $parent = get_post($post->post_parent);
    312306        if ( 'page' == $parent->post_type )
    313             $parentlink = _get_page_link( $object->post_parent ); // Ignores page_on_front
     307            $parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front
    314308        else
    315             $parentlink = get_permalink( $object->post_parent );
    316 
    317         if ( is_numeric($object->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') )
    318             $name = 'attachment/' . $object->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker
     309            $parentlink = get_permalink( $post->post_parent );
     310
     311        if ( is_numeric($post->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') )
     312            $name = 'attachment/' . $post->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker
    319313        else
    320             $name = $object->post_name;
     314            $name = $post->post_name;
    321315
    322316        if ( strpos($parentlink, '?') === false )
     
    325319
    326320    if ( ! $link )
    327         $link = home_url( "/?attachment_id=$id" );
    328 
    329     return apply_filters('attachment_link', $link, $id);
     321        $link = home_url( '/?attachment_id=' . $post->ID );
     322
     323    return apply_filters( 'attachment_link', $link, $post->ID );
    330324}
    331325
     
    896890 */
    897891function get_edit_post_link( $id = 0, $context = 'display' ) {
    898     if ( !$post = get_post( $id ) )
     892    if ( ! $post = get_post( $id ) )
    899893        return;
    900894
     
    11231117 */
    11241118function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $previous = true ) {
    1125     global $post, $wpdb;
    1126 
    1127     if ( empty( $post ) )
     1119    global $wpdb;
     1120
     1121    if ( ! $post = get_post() )
    11281122        return null;
    11291123
     
    12081202 */
    12091203function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) {
    1210     if ( $previous && is_attachment() && is_object( $GLOBALS['post'] ) )
    1211         $post = get_post($GLOBALS['post']->post_parent);
     1204    if ( $previous && is_attachment() && $post = get_post() )
     1205        $post = get_post( $post->post_parent );
    12121206    else
    1213         $post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);
     1207        $post = get_adjacent_post( $in_same_cat, $excluded_categories, $previous );
    12141208
    12151209    if ( empty($post) )
     
    13001294 */
    13011295function get_boundary_post( $in_same_cat = false, $excluded_categories = '', $start = true ) {
    1302     global $post;
    1303 
    1304     if ( empty($post) || ! is_single() || is_attachment() )
     1296    $post = get_post();
     1297    if ( ! $post || ! is_single() || is_attachment() )
    13051298        return null;
    13061299
     
    13741367function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) {
    13751368    if ( $previous && is_attachment() )
    1376         $post = get_post($GLOBALS['post']->post_parent);
     1369        $post = get_post( get_post()->post_parent );
    13771370    else
    13781371        $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
     
    16811674 */
    16821675function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) {
    1683     global $post, $wp_rewrite;
     1676    global $wp_rewrite;
    16841677
    16851678    $pagenum = (int) $pagenum;
    16861679
    1687     $result = get_permalink( $post->ID );
     1680    $result = get_permalink();
    16881681
    16891682    if ( 'newest' == get_option('default_comments_page') ) {
     
    24132406 */
    24142407function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) {
    2415     global $post;
    2416 
    24172408    if ( empty( $text ) )
    24182409        $text = __('This is the short link.');
     
    24212412        $title = the_title_attribute( array( 'echo' => false ) );
    24222413
    2423     $shortlink = wp_get_shortlink( $post->ID );
     2414    $shortlink = wp_get_shortlink();
    24242415
    24252416    if ( !empty( $shortlink ) ) {
  • trunk/wp-includes/media.php

    r21691 r21735  
    776776 */
    777777function gallery_shortcode($attr) {
    778     global $post;
     778    $post = get_post();
    779779
    780780    static $instance = 0;
     
    929929 */
    930930function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false) {
    931     global $post;
    932     $post = get_post($post);
    933     $attachments = array_values(get_children( array('post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') ));
     931    $post = get_post();
     932    $attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) );
    934933
    935934    foreach ( $attachments as $k => $attachment )
     
    11031102     */
    11041103    function maybe_run_ajax_cache() {
    1105         global $post_ID;
    1106 
    1107         if ( empty($post_ID) || empty($_GET['message']) || 1 != $_GET['message'] )
     1104        $post = get_post();
     1105
     1106        if ( ! $post || empty($_GET['message']) || 1 != $_GET['message'] )
    11081107            return;
    11091108
     
    11121111/* <![CDATA[ */
    11131112    jQuery(document).ready(function($){
    1114         $.get("<?php echo admin_url( 'admin-ajax.php?action=oembed-cache&post=' . $post_ID, 'relative' ); ?>");
     1113        $.get("<?php echo admin_url( 'admin-ajax.php?action=oembed-cache&post=' . $post->ID, 'relative' ); ?>");
    11151114    });
    11161115/* ]]> */
     
    11681167     */
    11691168    function shortcode( $attr, $url = '' ) {
    1170         global $post;
    1171 
    1172         if ( empty($url) )
     1169        $post = get_post();
     1170
     1171        if ( empty( $url ) )
    11731172            return '';
    11741173
     
    11911190        }
    11921191
    1193         $post_ID = ( !empty($post->ID) ) ? $post->ID : null;
    1194         if ( !empty($this->post_ID) ) // Potentially set by WP_Embed::cache_oembed()
     1192        $post_ID = ( ! empty( $post->ID ) ) ? $post->ID : null;
     1193        if ( ! empty( $this->post_ID ) ) // Potentially set by WP_Embed::cache_oembed()
    11951194            $post_ID = $this->post_ID;
    11961195
     
    12071206                    return $this->maybe_make_link( $url );
    12081207
    1209                 if ( !empty($cache) )
     1208                if ( ! empty( $cache ) )
    12101209                    return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $post_ID );
    12111210            }
  • trunk/wp-includes/post-template.php

    r21597 r21735  
    2727 */
    2828function get_the_ID() {
    29     global $post;
    30     return $post->ID;
     29    return get_post()->ID;
    3130}
    3231
     
    9897 * @since 0.71
    9998 *
    100  * @param int $id Optional. Post ID.
     99 * @param mixed $post Optional. Post ID or object.
    101100 * @return string
    102101 */
    103 function get_the_title( $id = 0 ) {
    104     $post = get_post($id);
    105 
    106     $title = isset($post->post_title) ? $post->post_title : '';
    107     $id = isset($post->ID) ? $post->ID : (int) $id;
    108 
    109     if ( !is_admin() ) {
    110         if ( !empty($post->post_password) ) {
    111             $protected_title_format = apply_filters('protected_title_format', __('Protected: %s'));
    112             $title = sprintf($protected_title_format, $title);
    113         } else if ( isset($post->post_status) && 'private' == $post->post_status ) {
    114             $private_title_format = apply_filters('private_title_format', __('Private: %s'));
    115             $title = sprintf($private_title_format, $title);
     102function get_the_title( $post = 0 ) {
     103    $post = get_post( $post );
     104
     105    $title = isset( $post->post_title ) ? $post->post_title : '';
     106    $id = isset( $post->ID ) ? $post->ID : 0;
     107
     108    if ( ! is_admin() ) {
     109        if ( ! empty( $post->post_password ) ) {
     110            $protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ) );
     111            $title = sprintf( $protected_title_format, $title );
     112        } else if ( isset( $post->post_status ) && 'private' == $post->post_status ) {
     113            $private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ) );
     114            $title = sprintf( $private_title_format, $title );
    116115        }
    117116    }
     117
    118118    return apply_filters( 'the_title', $title, $id );
    119119}
     
    178178 * @return string
    179179 */
    180 function get_the_content($more_link_text = null, $stripteaser = false) {
    181     global $post, $more, $page, $pages, $multipage, $preview;
     180function get_the_content( $more_link_text = null, $stripteaser = false ) {
     181    global $more, $page, $pages, $multipage, $preview;
     182
     183    $post = get_post();
    182184
    183185    if ( null === $more_link_text )
     
    188190
    189191    // If post password required and it doesn't match the cookie.
    190     if ( post_password_required($post) )
     192    if ( post_password_required() )
    191193        return get_the_password_form();
    192194
     
    260262        _deprecated_argument( __FUNCTION__, '2.3' );
    261263
    262     global $post;
    263     if ( post_password_required($post) ) {
     264    if ( post_password_required() ) {
    264265        return __( 'There is no excerpt because this is a protected post.' );
    265266    }
     
    677678 */
    678679function _wp_link_page( $i ) {
    679     global $post, $wp_rewrite;
     680    global $wp_rewrite;
     681    $post = get_post();
    680682
    681683    if ( 1 == $i ) {
     
    11721174 */
    11731175function prepend_attachment($content) {
    1174     global $post;
     1176    $post = get_post();
    11751177
    11761178    if ( empty($post->post_type) || $post->post_type != 'attachment' )
     
    11991201 */
    12001202function get_the_password_form() {
    1201     global $post;
     1203    $post = get_post();
    12021204    $label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );
    12031205    $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
  • 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.