Don't use the global anymore. Fixes #11624

git-svn-id: http://svn.automattic.com/wordpress/trunk@15549 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
scribu 2010-08-28 11:57:28 +00:00
parent bc0c1bb3f0
commit 950901ca92
5 changed files with 27 additions and 42 deletions

View File

@ -545,11 +545,10 @@ function comments_link( $deprecated = '', $deprecated_2 = '' ) {
* @return int The number of comments a post has
*/
function get_comments_number( $post_id = 0 ) {
global $id;
$post_id = (int) $post_id;
if ( !$post_id )
$post_id = (int) $id;
$post_id = get_the_ID();
$post_id = absint($post_id);
$post = get_post($post_id);
if ( ! isset($post->comment_count) )
@ -564,7 +563,6 @@ function get_comments_number( $post_id = 0 ) {
* Display the language string for the number of comments the current post has.
*
* @since 0.71
* @uses $id
* @uses apply_filters() Calls the 'comments_number' hook on the output and number of comments respectively.
*
* @param string $zero Text for no comments
@ -573,12 +571,10 @@ function get_comments_number( $post_id = 0 ) {
* @param string $deprecated Not used.
*/
function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
global $id;
if ( !empty( $deprecated ) )
_deprecated_argument( __FUNCTION__, '1.3' );
$number = get_comments_number($id);
$number = get_comments_number(get_the_ID());
if ( $number > 1 )
$output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments') : $more);
@ -703,16 +699,14 @@ function comment_type($commenttxt = false, $trackbacktxt = false, $pingbacktxt =
*
* @since 1.5.0
* @uses apply_filters() Calls 'trackback_url' on the resulting trackback URL
* @uses $id
*
* @return string The trackback URL after being filtered
*/
function get_trackback_url() {
global $id;
if ( '' != get_option('permalink_structure') ) {
$tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback');
} else {
$tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . $id;
$tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . get_the_ID();
}
return apply_filters('trackback_url', $tb_url);
}
@ -844,7 +838,6 @@ function wp_comment_form_unfiltered_html_nonce() {
* @since 1.5.0
* @global array $comment List of comment objects for the current post
* @uses $wpdb
* @uses $id
* @uses $post
* @uses $withcomments Will not try to get the comments if the post has none.
*
@ -961,7 +954,6 @@ function comments_popup_script($width=400, $height=400, $file='') {
* lists of posts
*
* @since 0.71
* @uses $id
* @uses $wpcommentspopupfile
* @uses $wpcommentsjavascript
* @uses $post
@ -974,7 +966,9 @@ function comments_popup_script($width=400, $height=400, $file='') {
* @return null Returns null on single posts and pages.
*/
function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
global $id, $wpcommentspopupfile, $wpcommentsjavascript;
global $wpcommentspopupfile, $wpcommentsjavascript;
$id = get_the_ID();
if ( false === $zero ) $zero = __( 'No Comments' );
if ( false === $one ) $one = __( '1 Comment' );
@ -1168,7 +1162,7 @@ function cancel_comment_reply_link($text = '') {
* @return string Hidden input HTML for replying to comments
*/
function get_comment_id_fields() {
global $id;
$id = get_the_ID();
$replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
$result = "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n";

View File

@ -462,10 +462,10 @@ function get_feed_link($feed = '') {
* @return string
*/
function get_post_comments_feed_link($post_id = '', $feed = '') {
global $id;
if ( !$post_id )
$post_id = get_the_ID();
if ( empty($post_id) )
$post_id = (int) $id;
$post_id = absint($post_id);
if ( empty($feed) )
$feed = get_default_feed();

View File

@ -12,24 +12,22 @@
* Display the ID of the current item in the WordPress Loop.
*
* @since 0.71
* @uses $id
*/
function the_ID() {
global $id;
echo $id;
echo get_the_ID();
}
/**
* Retrieve the ID of the current item in the WordPress Loop.
*
* @since 2.1.0
* @uses $id
* @uses $post
*
* @return unknown
* @return int
*/
function get_the_ID() {
global $id;
return $id;
global $post;
return $post->ID;
}
/**
@ -181,7 +179,7 @@ function the_content($more_link_text = null, $stripteaser = 0) {
* @return string
*/
function get_the_content($more_link_text = null, $stripteaser = 0) {
global $id, $post, $more, $page, $pages, $multipage, $preview;
global $post, $more, $page, $pages, $multipage, $preview;
if ( null === $more_link_text )
$more_link_text = __( '(more...)' );
@ -216,10 +214,10 @@ function get_the_content($more_link_text = null, $stripteaser = 0) {
$output .= $teaser;
if ( count($content) > 1 ) {
if ( $more ) {
$output .= '<span id="more-' . $id . '"></span>' . $content[1];
$output .= '<span id="more-' . $post->ID . '"></span>' . $content[1];
} else {
if ( ! empty($more_link_text) )
$output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-$id\" class=\"more-link\">$more_link_text</a>", $more_link_text );
$output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
$output = force_balance_tags($output);
}

View File

@ -18,8 +18,7 @@
* @return bool Whether post has an image attached.
*/
function has_post_thumbnail( $post_id = NULL ) {
global $id;
$post_id = ( NULL === $post_id ) ? $id : $post_id;
$post_id = ( NULL === $post_id ) ? get_the_ID() : $post_id;
return !! get_post_thumbnail_id( $post_id );
}
@ -32,8 +31,7 @@ function has_post_thumbnail( $post_id = NULL ) {
* @return int
*/
function get_post_thumbnail_id( $post_id = NULL ) {
global $id;
$post_id = ( NULL === $post_id ) ? $id : $post_id;
$post_id = ( NULL === $post_id ) ? get_the_ID() : $post_id;
return get_post_meta( $post_id, '_thumbnail_id', true );
}
@ -59,8 +57,7 @@ function the_post_thumbnail( $size = 'post-thumbnail', $attr = '' ) {
* @param string|array $attr Optional. Query string or array of attributes.
*/
function get_the_post_thumbnail( $post_id = NULL, $size = 'post-thumbnail', $attr = '' ) {
global $id;
$post_id = ( NULL === $post_id ) ? $id : $post_id;
$post_id = ( NULL === $post_id ) ? get_the_ID() : $post_id;
$post_thumbnail_id = get_post_thumbnail_id( $post_id );
$size = apply_filters( 'post_thumbnail_size', $size );
if ( $post_thumbnail_id ) {
@ -73,4 +70,4 @@ function get_the_post_thumbnail( $post_id = NULL, $size = 'post-thumbnail', $att
return apply_filters( 'post_thumbnail_html', $html, $post_id, $post_thumbnail_id, $size, $attr );
}
?>
?>

View File

@ -1268,10 +1268,8 @@ function delete_post_meta_by_key($post_meta_key) {
* @return array
*/
function get_post_custom($post_id = 0) {
global $id;
if ( !$post_id )
$post_id = (int) $id;
$post_id = get_the_ID();
$post_id = (int) $post_id;
@ -1336,13 +1334,11 @@ function get_post_custom_values( $key = '', $post_id = 0 ) {
* @return bool Whether post is sticky.
*/
function is_sticky($post_id = null) {
global $id;
if ( !$post_id )
$post_id = get_the_ID();
$post_id = absint($post_id);
if ( !$post_id )
$post_id = absint($id);
$stickies = get_option('sticky_posts');
if ( !is_array($stickies) )