Make WordPress Core

Changeset 5797


Ignore:
Timestamp:
07/12/2007 04:00:51 PM (17 years ago)
Author:
ryan
Message:

Fix variable name. Props bgracewood. fixes #4621

Location:
trunk/wp-includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/category-template.php

    r5726 r5797  
    340340
    341341    if ( 'DESC' == $order )
    342         $counts = array_reverse( $tag_counts, true );
     342        $counts = array_reverse( $counts, true );
    343343
    344344    $a = array();
  • trunk/wp-includes/default-filters.php

    r5783 r5797  
    185185add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 );
    186186add_action( 'shutdown', 'wp_ob_end_flush_all', 1);
     187add_action('publish_post', '_publish_post_hook', 5, 1);
     188add_action('future_post', '_future_post_hook', 5, 2);
     189add_action('future_page', '_future_post_hook', 5, 2);
     190add_action('save_post', '_save_post_hook', 5, 2);
     191add_action('transition_post_status', '_transition_post_status', 5, 3);
    187192
    188193?>
  • trunk/wp-includes/post.php

    r5796 r5797  
    140140function get_post_field( $field, $post, $context = 'display' ) {
    141141    $post = (int) $post;
    142     $post = get_term( $post );
     142    $post = get_post( $post );
    143143
    144144    if ( is_wp_error($post) )
     
    421421    $fields = array('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_date', 'post_date_gmt', 'post_parent', 'menu_order', 'post_mime_type');
    422422
    423     if ( 'raw' == $context )
    424         return $post;
    425 
    426423    $do_object = false;
    427424    if ( is_object($post) )
     
    442439    if ( in_array($field, $int_fields) )
    443440        $value = (int) $value;
     441
     442    if ( 'raw' == $context )
     443        return $value;
    444444
    445445    $prefixed = false;
     
    587587
    588588    $postarr = wp_parse_args($postarr, $defaults);
    589 
    590     if ( empty($postarr['no_filter']) )
    591         $postarr = sanitize_post($postarr, 'db');
     589    $postarr = sanitize_post($postarr, 'db');
    592590
    593591    // export array as variables
     
    598596    if ( !empty($ID) ) {
    599597        $update = true;
    600         $post = & get_post($ID);
    601         $previous_status = $post->post_status;
     598        $previous_status = get_post_field('post_status', $ID);
     599    } else {
     600        $previous_status = 'new';
    602601    }
    603602
     
    609608        $post_category = array(get_option('default_category'));
    610609    }
    611     $post_cat = $post_category[0];
    612610
    613611    if ( empty($post_author) )
     
    632630        $post_name = sanitize_title($post_name);
    633631    }
    634 
    635632
    636633    // If the post date is empty (due to having been new or a draft) and status is not 'draft', set date to now
     
    739736    if ( 'page' == $post_type ) {
    740737        clean_page_cache($post_ID);
    741         $wp_rewrite->flush_rules();
    742738    } else {
    743739        clean_post_cache($post_ID);
     
    748744        $wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post_ID) . "' WHERE ID = '$post_ID'");
    749745
    750     if ( $update) {
    751         if ($previous_status != 'publish' && $post_status == 'publish') {
    752             // Reset GUID if transitioning to publish.
    753             $wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post_ID) . "' WHERE ID = '$post_ID'");
    754             do_action('private_to_published', $post_ID);
    755         }
    756 
    757         do_action('edit_post', $post_ID);
    758     }
    759 
    760     if ($post_status == 'publish' && $post_type == 'post') {
    761         do_action('publish_post', $post_ID);
    762         if ( defined('XMLRPC_REQUEST') )
    763             do_action('xmlrpc_publish_post', $post_ID);
    764         if ( defined('APP_REQUEST') )
    765             do_action('app_publish_post', $post_ID);
    766 
    767         if ( !defined('WP_IMPORTING') ) {
    768             if ( $post_pingback )
    769                 $result = $wpdb->query("
    770                     INSERT INTO $wpdb->postmeta
    771                     (post_id,meta_key,meta_value)
    772                     VALUES ('$post_ID','_pingme','1')
    773                 ");
    774             $result = $wpdb->query("
    775                 INSERT INTO $wpdb->postmeta
    776                 (post_id,meta_key,meta_value)
    777                 VALUES ('$post_ID','_encloseme','1')
    778             ");
    779             wp_schedule_single_event(time(), 'do_pings');
    780         }
    781     } else if ($post_type == 'page') {
    782         if ( !empty($page_template) )
    783             if ( ! update_post_meta($post_ID, '_wp_page_template',  $page_template))
    784                 add_post_meta($post_ID, '_wp_page_template',  $page_template, true);
    785 
    786         if ( $post_status == 'publish' )
    787             do_action('publish_page', $post_ID);
    788     }
    789 
    790     // Always clears the hook in case the post status bounced from future to draft.
    791     wp_clear_scheduled_hook('publish_future_post', $post_ID);
    792 
    793     // Schedule publication.
    794     if ( 'future' == $post_status )
    795         wp_schedule_single_event(strtotime($post_date_gmt. ' GMT'), 'publish_future_post', array($post_ID));
    796 
    797     do_action('save_post', $post_ID);
    798     do_action('wp_insert_post', $post_ID);
     746    $post = get_post($post_ID);
     747    if ( !empty($page_template) )
     748        $post->page_template = $page_template;
     749
     750    wp_transition_post_status($post_status, $previous_status, $post);
     751
     752    if ( $update)
     753        do_action('edit_post', $post_ID, $post);
     754
     755    do_action('save_post', $post_ID, $post);
     756    do_action('wp_insert_post', $post_ID, $post);
    799757
    800758    return $post_ID;
     
    842800
    843801function wp_publish_post($post_id) {
     802    global $wpdb;
     803
    844804    $post = get_post($post_id);
    845805
     
    850810        return;
    851811
    852     return wp_update_post(array('post_status' => 'publish', 'ID' => $post_id, 'no_filter' => true));
     812    $wpdb->query( "UPDATE $wpdb->posts SET post_status = 'publish' WHERE ID = '$post_id'" );
     813
     814    $old_status = $post->post_status;
     815    $post->post_status = 'publish';
     816    wp_transition_post_status('publish', $old_status, $post);
     817
     818    do_action('edit_post', $post_id, $post);
     819    do_action('save_post', $post_id, $post);
     820    do_action('wp_insert_post', $post_id, $post);
    853821}
    854822
     
    887855    return wp_set_object_terms($post_ID, $post_categories, 'category');
    888856}   // wp_set_post_categories()
     857
     858function wp_transition_post_status($new_status, $old_status, $post) {
     859    if ( $new_status != $old_status ) {
     860        do_action('transition_post_status', $new_status, $old_status, $post);
     861        do_action("${old_status}_to_$new_status", $post);
     862    }
     863    do_action("${new_status}_$post->post_type", $post->ID, $post);
     864}
    889865
    890866//
     
    18441820}
    18451821
     1822//
     1823// Hooks
     1824//
     1825
     1826function _transition_post_status($new_status, $old_status, $post) {
     1827    global $wpdb;
     1828
     1829    if ( $old_status != 'publish' && $new_status == 'publish' ) {
     1830            // Reset GUID if transitioning to publish.
     1831            $wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post->ID) . "' WHERE ID = '$post->ID'");
     1832            do_action('private_to_published', $post->ID);  // Deprecated, use private_to_publish
     1833    }
     1834
     1835    // Always clears the hook in case the post status bounced from future to draft.
     1836    wp_clear_scheduled_hook('publish_future_post', $post->ID);
     1837}
     1838
     1839function _future_post_hook($post_id, $post) {
     1840    // Schedule publication.
     1841    wp_schedule_single_event(strtotime($post->post_date_gmt. ' GMT'), 'publish_future_post', array($post->ID));
     1842}
     1843
     1844function _publish_post_hook($post_id) {
     1845    global $wpdb;
     1846
     1847    if ( defined('XMLRPC_REQUEST') )
     1848        do_action('xmlrpc_publish_post', $post_id);
     1849    if ( defined('APP_REQUEST') )
     1850        do_action('app_publish_post', $post_id);
     1851
     1852    if ( defined('WP_IMPORTING') )
     1853        return;
     1854
     1855    $post = get_post($post_id);
     1856
     1857    if ( $post->post_pingback )
     1858        $result = $wpdb->query("
     1859            INSERT INTO $wpdb->postmeta
     1860            (post_id,meta_key,meta_value)
     1861            VALUES ('$post_id','_pingme','1')
     1862        ");
     1863    $result = $wpdb->query("
     1864        INSERT INTO $wpdb->postmeta
     1865        (post_id,meta_key,meta_value)
     1866        VALUES ('$post_id','_encloseme','1')
     1867    ");
     1868    wp_schedule_single_event(time(), 'do_pings');
     1869}
     1870
     1871function _save_post_hook($post_id, $post) {
     1872    if ( $post->post_type == 'page' ) {
     1873        if ( !empty($post->page_template) )
     1874            if ( ! update_post_meta($post_id, '_wp_page_template',  $post->page_template))
     1875                add_post_meta($post_id, '_wp_page_template',  $post->page_template, true);
     1876
     1877        clean_page_cache($post_id);
     1878        global $wp_rewrite;
     1879        $wp_rewrite->flush_rules();
     1880    } else {
     1881        clean_post_cache($post_id);
     1882    }
     1883}
     1884
    18461885?>
Note: See TracChangeset for help on using the changeset viewer.