Make WordPress Core


Ignore:
Timestamp:
09/04/2012 04:29:28 PM (11 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-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( ' ', $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}
Note: See TracChangeset for help on using the changeset viewer.