Ticket #21309: 21309.10.diff

File 21309.10.diff, 32.3 KB (added by nacin, 9 months ago)

Eliminates most direct calls to $post, by making get_post() take an *optional* $post argument.

  • wp-includes/admin-bar.php

     
    419419 * @since 3.1.0 
    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 
    428429                        && 'add' != $current_screen->action 
     
    619620                return; 
    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( 
    625626                'id'    => 'updates', 
  • wp-includes/class-wp-atom-server.php

     
    846846         * @param int $postID Post ID. 
    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 
    855854                $url = $this->app_base . $this->ENTRY_PATH . "/$postID"; 
     
    878877         */ 
    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 
    885883                $url = $this->app_base . $this->MEDIA_SINGLE_PATH ."/file/$postID"; 
  • wp-includes/post-template.php

     
    2626 * @return int 
    2727 */ 
    2828function get_the_ID() { 
    29         global $post; 
    30         return $post->ID; 
     29        return get_post()->ID; 
    3130} 
    3231 
    3332/** 
     
    9796 * 
    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); 
     102function get_the_title( $post = 0 ) { 
     103        $post = get_post( $post ); 
    105104 
    106105        $title = isset($post->post_title) ? $post->post_title : ''; 
    107106        $id = isset($post->ID) ? $post->ID : (int) $id; 
     
    178177 * @return string 
    179178 */ 
    180179function get_the_content($more_link_text = null, $stripteaser = false) { 
    181         global $post, $more, $page, $pages, $multipage, $preview; 
     180        global $more, $page, $pages, $multipage, $preview; 
    182181 
     182        $post = get_post(); 
     183 
    183184        if ( null === $more_link_text ) 
    184185                $more_link_text = __( '(more...)' ); 
    185186 
     
    187188        $hasTeaser = false; 
    188189 
    189190        // If post password required and it doesn't match the cookie. 
    190         if ( post_password_required($post) ) 
     191        if ( post_password_required() ) 
    191192                return get_the_password_form(); 
    192193 
    193194        if ( $page > count($pages) ) // if the requested page doesn't exist 
     
    259260        if ( !empty( $deprecated ) ) 
    260261                _deprecated_argument( __FUNCTION__, '2.3' ); 
    261262 
    262         global $post; 
    263         if ( post_password_required($post) ) { 
     263        if ( post_password_required() ) { 
    264264                return __( 'There is no excerpt because this is a protected post.' ); 
    265265        } 
    266266 
     
    676676 * @return string Link. 
    677677 */ 
    678678function _wp_link_page( $i ) { 
    679         global $post, $wp_rewrite; 
     679        global $wp_rewrite; 
     680        $post = get_post(); 
    680681 
    681682        if ( 1 == $i ) { 
    682683                $url = get_permalink(); 
     
    11711172 * @return string 
    11721173 */ 
    11731174function prepend_attachment($content) { 
    1174         global $post; 
     1175        $post = get_post(); 
    11751176 
    11761177        if ( empty($post->post_type) || $post->post_type != 'attachment' ) 
    11771178                return $content; 
     
    11981199 * @return string HTML content for password form for password protected post. 
    11991200 */ 
    12001201function get_the_password_form() { 
    1201         global $post; 
     1202        $post = get_post(); 
    12021203        $label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID ); 
    12031204        $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post"> 
    12041205        <p>' . __("This post is password protected. To view it please enter your password below:") . '</p> 
  • wp-includes/post.php

     
    372372 * @uses $wpdb 
    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']; 
    383383 
     
    914914 * 
    915915 * @uses $post The Loop current post global 
    916916 * 
    917  * @param mixed $the_post Optional. Post object or post ID. 
     917 * @param mixed $post Optional. Post object or post ID. 
    918918 * @return bool|string post type or false on failure. 
    919919 */ 
    920 function get_post_type( $the_post = false ) { 
    921         global $post; 
     920function get_post_type( $post = null ) { 
     921        if ( $post = get_post( $post ) ) 
     922                return $post->post_type; 
    922923 
    923         if ( false === $the_post ) 
    924                 $the_post = $post; 
    925         elseif ( is_numeric($the_post) ) 
    926                 $the_post = get_post($the_post); 
    927  
    928         if ( is_object($the_post) ) 
    929                 return $the_post->post_type; 
    930  
    931924        return false; 
    932925} 
    933926 
     
    11521145                        $args->rewrite['with_front'] = true; 
    11531146                if ( ! isset( $args->rewrite['pages'] ) ) 
    11541147                        $args->rewrite['pages'] = true; 
    1155                 if ( ! isset( $args->rewrite['feeds'] ) || ! $args->has_archive ) 
     1148                if ( ! isset( $args->rewrite['feeds'] ) && isset( $args->has_archive ) ) 
    11561149                        $args->rewrite['feeds'] = (bool) $args->has_archive; 
    11571150                if ( ! isset( $args->rewrite['ep_mask'] ) ) { 
    11581151                        if ( isset( $args->permalink_epmask ) ) 
     
    11661159                else 
    11671160                        add_rewrite_tag("%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name="); 
    11681161 
    1169                 if ( $args->has_archive ) { 
    1170                         $archive_slug = $args->has_archive === true ? $args->rewrite['slug'] : $args->has_archive; 
    1171                         if ( $args->rewrite['with_front'] ) 
    1172                                 $archive_slug = substr( $wp_rewrite->front, 1 ) . $archive_slug; 
    1173                         else 
    1174                                 $archive_slug = $wp_rewrite->root . $archive_slug; 
     1162                $archive_slug = is_string( $args->has_archive ) && $args->has_archive ? $args->has_archive : $args->rewrite['slug']; 
     1163                if ( $args->rewrite['with_front'] ) 
     1164                        $archive_slug = substr( $wp_rewrite->front, 1 ) . $archive_slug; 
     1165                else 
     1166                        $archive_slug = $wp_rewrite->root . $archive_slug; 
    11751167 
     1168                // Feed support can be added even without an archive. 
     1169                if ( $args->rewrite['feeds'] && $wp_rewrite->feeds ) { 
     1170                        $feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')'; 
     1171                        add_rewrite_rule( "{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' ); 
     1172                        add_rewrite_rule( "{$archive_slug}/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' ); 
     1173                } 
     1174 
     1175                if ( $args->has_archive ) { 
    11761176                        add_rewrite_rule( "{$archive_slug}/?$", "index.php?post_type=$post_type", 'top' ); 
    1177                         if ( $args->rewrite['feeds'] && $wp_rewrite->feeds ) { 
    1178                                 $feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')'; 
    1179                                 add_rewrite_rule( "{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' ); 
    1180                                 add_rewrite_rule( "{$archive_slug}/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' ); 
    1181                         } 
    11821177                        if ( $args->rewrite['pages'] ) 
    11831178                                add_rewrite_rule( "{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=$post_type" . '&paged=$matches[1]', 'top' ); 
    11841179                } 
  • wp-includes/comment-template.php

     
    810810 * @uses $post Gets the ID of the current post for the token 
    811811 */ 
    812812function wp_comment_form_unfiltered_html_nonce() { 
    813         global $post; 
     813        $post = get_post(); 
     814        $post_id = $post ? $post->ID : 0; 
    814815 
    815         $post_id = 0; 
    816         if ( !empty($post) ) 
    817                 $post_id = $post->ID; 
    818  
    819816        if ( current_user_can( 'unfiltered_html' ) ) { 
    820817                wp_nonce_field( 'unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment_disabled', false ); 
    821818                echo "<script>(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();</script>\n"; 
  • wp-includes/media.php

     
    775775 * @return string HTML content to display gallery. 
    776776 */ 
    777777function gallery_shortcode($attr) { 
    778         global $post; 
     778        $post = get_post(); 
    779779 
    780780        static $instance = 0; 
    781781        $instance++; 
     
    928928 * @param bool $prev Optional. Default is true to display previous link, false for next. 
    929929 */ 
    930930function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false) { 
    931         global $post; 
    932         $post = get_post($post); 
     931        $post = get_post(); 
    933932        $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 ) 
     
    11021101         * an AJAX request that will call WP_Embed::cache_oembed(). 
    11031102         */ 
    11041103        function maybe_run_ajax_cache() { 
    1105                 global $post_ID; 
     1104                $post = get_post(); 
    11061105 
    1107                 if ( empty($post_ID) || empty($_GET['message']) || 1 != $_GET['message'] ) 
     1106                if ( ! $post || empty($_GET['message']) || 1 != $_GET['message'] ) 
    11081107                        return; 
    11091108 
    11101109?> 
    11111110<script type="text/javascript"> 
    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/* ]]> */ 
    11171116</script> 
     
    11671166         * @return string The embed HTML on success, otherwise the original URL. 
    11681167         */ 
    11691168        function shortcode( $attr, $url = '' ) { 
    1170                 global $post; 
     1169                $post = get_post(); 
    11711170 
    11721171                if ( empty($url) ) 
    11731172                        return ''; 
  • wp-includes/link-template.php

     
    5555 * @param string $mode Permalink mode can be either 'title', 'id', or default, which is 'id'. 
    5656 */ 
    5757function permalink_anchor($mode = 'id') { 
    58         global $post; 
     58        $post = get_post(); 
    5959        switch ( strtolower($mode) ) { 
    6060                case 'title': 
    6161                        $title = sanitize_title($post->post_title) . '-' . $post->ID; 
     
    232232 * 
    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; 
     240function get_page_link( $post = false, $leavename = false, $sample = false ) { 
     241        $post = get_post( $post ); 
    242242 
    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') ) 
     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 ); 
     246                $link = _get_page_link( $post, $leavename, $sample ); 
    251247 
    252         return apply_filters('page_link', $link, $id, $sample); 
     248        return apply_filters( 'page_link', $link, $post->ID, $sample ); 
    253249} 
    254250 
    255251/** 
     
    260256 * @since 2.1.0 
    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' ) ); 
    274270 
     
    276272 
    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 
    282278                $link = home_url($link); 
    283279                $link = user_trailingslashit($link, 'page'); 
    284280        } else { 
    285                 $link = home_url("?page_id=$id"); 
     281                $link = home_url( '?page_id=' . $post->ID ); 
    286282        } 
    287283 
    288         return apply_filters( '_get_page_link', $link, $id ); 
     284        return apply_filters( '_get_page_link', $link, $post->ID ); 
    289285} 
    290286 
    291287/** 
     
    295291 * 
    296292 * @since 2.0.0 
    297293 * 
    298  * @param int $id Optional. Post ID. 
     294 * @param mixed $post Optional. Post ID or object. 
    299295 * @return string 
    300296 */ 
    301 function get_attachment_link($id = false) { 
    302         global $post, $wp_rewrite; 
     297function get_attachment_link( $post = null ) { 
     298        global $wp_rewrite; 
    303299 
    304300        $link = false; 
    305301 
    306         if ( ! $id) 
    307                 $id = (int) $post->ID; 
     302        $post = get_post( $post ); 
    308303 
    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); 
     304        if ( $wp_rewrite->using_permalinks() && ($post->post_parent > 0) && ($post->post_parent != $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 ); 
     309                        $parentlink = get_permalink( $post->post_parent ); 
    316310 
    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 
     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 ) 
    323317                        $link = user_trailingslashit( trailingslashit($parentlink) . $name ); 
     
    11221116 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. 
    11231117 */ 
    11241118function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $previous = true ) { 
    1125         global $post, $wpdb; 
     1119        global $wpdb; 
    11261120 
    1127         if ( empty( $post ) ) 
     1121        if ( ! $post = get_post() ) 
    11281122                return null; 
    11291123 
    11301124        $current_post_date = $post->post_date; 
     
    12001194 * @return string 
    12011195 */ 
    12021196function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) { 
    1203         if ( $previous && is_attachment() && is_object( $GLOBALS['post'] ) ) 
    1204                 $post = get_post($GLOBALS['post']->post_parent); 
     1197        if ( $previous && is_attachment() && $post = get_post() ) 
     1198                $post = get_post( $post->post_parent ); 
    12051199        else 
    1206                 $post = get_adjacent_post($in_same_cat,$excluded_categories,$previous); 
     1200                $post = get_adjacent_post( $in_same_cat, $excluded_categories, $previous ); 
    12071201 
    12081202        if ( empty($post) ) 
    12091203                return; 
     
    12921286 * @return object 
    12931287 */ 
    12941288function get_boundary_post( $in_same_cat = false, $excluded_categories = '', $start = true ) { 
    1295         global $post; 
    1296  
    1297         if ( empty($post) || ! is_single() || is_attachment() ) 
     1289        $post = get_post(); 
     1290        if ( ! $post || ! is_single() || is_attachment() ) 
    12981291                return null; 
    12991292 
    13001293        $cat_array = array(); 
     
    13661359 */ 
    13671360function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) { 
    13681361        if ( $previous && is_attachment() ) 
    1369                 $post = get_post($GLOBALS['post']->post_parent); 
     1362                $post = get_post( get_post()->post_parent ); 
    13701363        else 
    13711364                $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous); 
    13721365 
     
    16731666 * @return string 
    16741667 */ 
    16751668function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) { 
    1676         global $post, $wp_rewrite; 
     1669        global $wp_rewrite; 
    16771670 
    16781671        $pagenum = (int) $pagenum; 
    16791672 
    1680         $result = get_permalink( $post->ID ); 
     1673        $result = get_permalink(); 
    16811674 
    16821675        if ( 'newest' == get_option('default_comments_page') ) { 
    16831676                if ( $pagenum != $max_page ) { 
     
    24382431 * @param string $after Optional HTML to display after the link. 
    24392432 */ 
    24402433function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) { 
    2441         global $post; 
    2442  
    24432434        if ( empty( $text ) ) 
    24442435                $text = __('This is the short link.'); 
    24452436 
    24462437        if ( empty( $title ) ) 
    24472438                $title = the_title_attribute( array( 'echo' => false ) ); 
    24482439 
    2449         $shortlink = wp_get_shortlink( $post->ID ); 
     2440        $shortlink = wp_get_shortlink(); 
    24502441 
    24512442        if ( !empty( $shortlink ) ) { 
    24522443                $link = '<a rel="shortlink" href="' . esc_url( $shortlink ) . '" title="' . $title . '">' . $text . '</a>'; 
  • wp-includes/author-template.php

     
    6969 * @return string The author's display name. 
    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); 
    7675        } 
     
    164163 * @return int The number of posts by the author. 
    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 
    171169/** 
  • wp-includes/general-template.php

     
    13111311 * @since 1.0.0 
    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 
    13181317/** 
     
    13671366 * @return string|null Null if displaying, string if retrieving. 
    13681367 */ 
    13691368function get_the_date( $d = '' ) { 
    1370         global $post; 
     1369        $post = get_post(); 
    13711370        $the_date = ''; 
    13721371 
    13731372        if ( '' == $d ) 
     
    15281527 * @uses $post 
    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; 
    15351534} 
     
    15461545 * @param string $after Optional Output after the date. 
    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; 
    15561555        } 
  • wp-includes/deprecated.php

     
    5757 * @deprecated Use The Loop - {@link http://codex.wordpress.org/The_Loop Use new WordPress Loop} 
    5858 */ 
    5959function start_wp() { 
    60         global $wp_query, $post; 
     60        global $wp_query; 
    6161 
    6262        _deprecated_function( __FUNCTION__, '1.5', __('new WordPress Loop') ); 
    6363 
    6464        // Since the old style loop is being used, advance the query iterator here. 
    6565        $wp_query->next_post(); 
    6666 
    67         setup_postdata($post); 
     67        setup_postdata( get_post() ); 
    6868} 
    6969 
    7070/** 
  • wp-includes/class-wp-editor.php

     
    126126        } 
    127127 
    128128        public static function editor_settings($editor_id, $set) { 
    129                 global $editor_styles, $post; 
     129                global $editor_styles; 
    130130                $first_run = false; 
    131131 
    132132                if ( empty(self::$first_init) ) { 
     
    370370 
    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']) ) { 
    377377                                $body_class .= ' ' . $set['tinymce']['body_class']; 
     
    612612        } 
    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; 
    618619                $width = $width + 22; // compensate for the padding and border 
  • wp-includes/category-template.php

     
    10541054 * 
    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; 
     1061function get_the_terms( $post, $taxonomy ) { 
     1062        if ( ! $post = get_post( $post ) ) 
     1063                return false; 
    10631064 
    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 ); 
     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'); 
     1067                $terms = wp_get_object_terms( $post->ID, $taxonomy ); 
     1068                wp_cache_add($post->ID, $terms, $taxonomy . '_relationships'); 
    10771069        } 
    10781070 
    1079         $terms = apply_filters( 'get_the_terms', $terms, $id, $taxonomy ); 
     1071        $terms = apply_filters( 'get_the_terms', $terms, $post->ID, $taxonomy ); 
    10801072 
    10811073        if ( empty( $terms ) ) 
    10821074                return false; 
  • wp-admin/includes/class-wp-posts-list-table.php

     
    316316        } 
    317317 
    318318        function _display_rows( $posts, $level = 0 ) { 
    319                 global $post, $mode; 
     319                global $mode; 
     320                $post = get_post(); 
    320321 
    321322                // Create array of post IDs. 
    322323                $post_ids = array(); 
     
    458459                unset( $children_pages[$parent] ); //required in order to keep track of orphans 
    459460        } 
    460461 
    461         function single_row( $a_post, $level = 0 ) { 
    462                 global $post, $mode; 
     462        function single_row( $post, $level = 0 ) { 
     463                global $mode; 
    463464                static $alternate; 
    464465 
    465                 $global_post = $post; 
    466                 $post = $a_post; 
     466                $global_post = get_post(); 
     467                $GLOBALS['post'] = $post; 
    467468                setup_postdata( $post ); 
    468469 
    469470                $edit_link = get_edit_post_link( $post->ID ); 
     
    529530                                } 
    530531                                else { 
    531532                                        $attributes = 'class="post-title page-title column-title"' . $style; 
    532                                          
     533 
    533534                                        $pad = str_repeat( '&#8212; ', $level ); 
    534535?> 
    535536                        <td <?php echo $attributes ?>><strong><?php if ( $can_edit_post && $post->post_status != 'trash' ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ); ?>"><?php echo $pad; echo $title ?></a><?php } else { echo $pad; echo $title; }; _post_states( $post ); ?></strong> 
     
    684685        ?> 
    685686                </tr> 
    686687        <?php 
    687                 $post = $global_post; 
     688                $GLOBALS['post'] = $global_post; 
    688689        } 
    689690 
    690691        /** 
  • wp-admin/includes/class-wp-media-list-table.php

     
    156156        } 
    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' ); 
    162163                $alt = ''; 
  • wp-admin/includes/post.php

     
    928928/** 
    929929 * Executes a query for attachments. An array of WP_Query arguments 
    930930 * can be passed in, which will override the arguments set by this function. 
    931  *  
     931 * 
    932932 * @since 2.5.0 
    933933 * @uses apply_filters() Calls 'upload_per_page' on posts_per_page argument 
    934934 * 
     
    11391139 * @since 2.9.0 
    11401140 * 
    11411141 * @param int $thumbnail_id ID of the attachment used for thumbnail 
    1142  * @param int $post_id ID of the post associated with the thumbnail, defaults to global $post_ID 
     1142 * @param mixed $post The post ID or object associated with the thumbnail, defaults to global $post. 
    11431143 * @return string html 
    11441144 */ 
    1145 function _wp_post_thumbnail_html( $thumbnail_id = null, $post_id = null ) { 
    1146         global $content_width, $_wp_additional_image_sizes, $post_ID; 
     1145function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) { 
     1146        global $content_width, $_wp_additional_image_sizes; 
    11471147 
    1148         if ( empty( $post_id ) ) 
    1149                 $post_id = $post_ID; 
     1148        $post = get_post( $post ); 
    11501149 
    1151         $upload_iframe_src = esc_url( get_upload_iframe_src('image', $post_id) ); 
     1150        $upload_iframe_src = esc_url( get_upload_iframe_src('image', $post->ID ) ); 
    11521151        $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>'; 
    11531152        $content = sprintf( $set_thumbnail_link, $upload_iframe_src, esc_html__( 'Set featured image' ) ); 
    11541153 
     
    11601159                else 
    11611160                        $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'post-thumbnail' ); 
    11621161                if ( !empty( $thumbnail_html ) ) { 
    1163                         $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$post_id" ); 
     1162                        $ajax_nonce = wp_create_nonce( 'set_post_thumbnail-' . $post->ID ); 
    11641163                        $content = sprintf( $set_thumbnail_link, $upload_iframe_src, $thumbnail_html ); 
    11651164                        $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>'; 
    11661165                } 
    11671166                $content_width = $old_content_width; 
    11681167        } 
    11691168 
    1170         return apply_filters( 'admin_post_thumbnail_html', $content, $post_id ); 
     1169        return apply_filters( 'admin_post_thumbnail_html', $content, $post->ID ); 
    11711170} 
    11721171 
    11731172/** 
     
    12251224 * @return none 
    12261225 */ 
    12271226function _admin_notice_post_locked() { 
    1228         global $post; 
    1229  
     1227        $post = get_post(); 
    12301228        $lock = explode( ':', get_post_meta( $post->ID, '_edit_lock', true ) ); 
    12311229        $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true ); 
    12321230        $last_user = get_userdata( $user ); 
  • wp-admin/includes/meta-boxes.php

     
    469469 * @param object $post 
    470470 */ 
    471471function post_comment_meta_box($post) { 
    472         global $wpdb, $post_ID; 
     472        global $wpdb; 
    473473 
    474474        wp_nonce_field( 'get-comments', 'add_comment_nonce', false ); 
    475475        ?> 
    476476        <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> 
    477477        <?php 
    478478 
    479         $total = get_comments( array( 'post_id' => $post_ID, 'number' => 1, 'count' => true ) ); 
     479        $total = get_comments( array( 'post_id' => $post->ID, 'number' => 1, 'count' => true ) ); 
    480480        $wp_list_table = _get_list_table('WP_Post_Comments_List_Table'); 
    481481        $wp_list_table->display( true ); 
    482482 
     
    912912 * 
    913913 * @since 2.9.0 
    914914 */ 
    915 function post_thumbnail_meta_box() { 
    916         global $post; 
     915function post_thumbnail_meta_box( $post ) { 
    917916        $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true ); 
    918917        echo _wp_post_thumbnail_html( $thumbnail_id ); 
    919918} 
  • wp-admin/includes/class-wp-comments-list-table.php

     
    302302        } 
    303303 
    304304        function single_row( $a_comment ) { 
    305                 global $post, $comment; 
     305                global $comment; 
     306                $post = get_post(); 
    306307 
    307308                $comment = $a_comment; 
    308309                $the_comment_class = join( ' ', get_comment_class( wp_get_comment_status( $comment->comment_ID ) ) ); 
     
    325326        } 
    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; 
    331333 
     
    479481        } 
    480482 
    481483        function column_response( $comment ) { 
    482                 global $post; 
     484                $post = get_post(); 
    483485 
    484486                if ( isset( $this->pending_count[$post->ID] ) ) { 
    485487                        $pending_comments = $this->pending_count[$post->ID]; 
  • wp-admin/includes/template.php

     
    166166 * @return array List of popular term IDs. 
    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(); 
    175174 
     
    575574 * @param unknown_type $multi 
    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 ) 
    581581                $edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) ); 
     
    670670 * @return unknown 
    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 
    676677        if ( $items ) { 
    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) 
    686685                                $current = ' selected="selected"'; 
     
    13451344 * @since 2.7.0 
    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 
    13521352/** 
     
    13561356 * returned. 
    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); 
     1362function _draft_or_post_title( $post = 0 ) { 
     1363        $title = get_the_title( $post ); 
    13641364        if ( empty($title) ) 
    13651365                $title = __('(no title)'); 
    13661366        return $title; 
  • wp-admin/includes/export.php

     
    279279         * @since 2.3.0 
    280280         */ 
    281281        function wxr_post_taxonomy() { 
    282                 global $post; 
     282                $post = get_post(); 
    283283 
    284284                $taxonomies = get_object_taxonomies( $post->post_type ); 
    285285                if ( empty( $taxonomies ) )