Make WordPress Core


Ignore:
Timestamp:
09/10/2008 10:47:03 PM (16 years ago)
Author:
ryan
Message:

Inline editing. First cut. Props Aaron Harp. see #6815

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/post.php

    r8732 r8857  
    1010 *
    1111 * @param bool $update Are we updating a pre-existing post?
     12 * @param post_data array Array of post data. Defaults to the contents of $_POST
    1213 * @return object|bool WP_Error on failure, true on success.
    1314 */
    14 function _wp_translate_postdata( $update = false ) {
     15function _wp_translate_postdata( $update = false, &$post_data = null ) {
     16
     17    if ( empty($post_data) )
     18        $post_data = &$_POST;
     19
    1520    if ( $update )
    16         $_POST['ID'] = (int) $_POST['post_ID'];
    17     $_POST['post_content'] = $_POST['content'];
    18     $_POST['post_excerpt'] = $_POST['excerpt'];
    19     $_POST['post_parent'] = isset($_POST['parent_id'])? $_POST['parent_id'] : '';
    20     if ( isset($_POST['trackback_url']) )
    21         $_POST['to_ping'] = $_POST['trackback_url'];
    22 
    23     if (!empty ( $_POST['post_author_override'] ) ) {
    24         $_POST['post_author'] = (int) $_POST['post_author_override'];
     21        $post_data['ID'] = (int) $post_data['post_ID'];
     22    $post_data['post_content'] = $post_data['content'];
     23    $post_data['post_excerpt'] = $post_data['excerpt'];
     24    $post_data['post_parent'] = isset($post_data['parent_id'])? $post_data['parent_id'] : '';
     25    if ( isset($post_data['trackback_url']) )
     26        $post_data['to_ping'] = $post_data['trackback_url'];
     27
     28    if (!empty ( $post_data['post_author_override'] ) ) {
     29        $post_data['post_author'] = (int) $post_data['post_author_override'];
    2530    } else {
    26         if (!empty ( $_POST['post_author'] ) ) {
    27             $_POST['post_author'] = (int) $_POST['post_author'];
     31        if (!empty ( $post_data['post_author'] ) ) {
     32            $post_data['post_author'] = (int) $post_data['post_author'];
    2833        } else {
    29             $_POST['post_author'] = (int) $_POST['user_ID'];
     34            $post_data['post_author'] = (int) $post_data['user_ID'];
    3035        }
    3136    }
    3237
    33     if ( isset($_POST['user_ID']) && ($_POST['post_author'] != $_POST['user_ID']) ) {
    34         if ( 'page' == $_POST['post_type'] ) {
     38    if ( isset($post_data['user_ID']) && ($post_data['post_author'] != $post_data['user_ID']) ) {
     39        if ( 'page' == $post_data['post_type'] ) {
    3540            if ( !current_user_can( 'edit_others_pages' ) ) {
    3641                return new WP_Error( 'edit_others_pages', $update ?
     
    5055
    5156    // What to do based on which button they pressed
    52     if ( isset($_POST['saveasdraft']) && '' != $_POST['saveasdraft'] )
    53         $_POST['post_status'] = 'draft';
    54     if ( isset($_POST['saveasprivate']) && '' != $_POST['saveasprivate'] )
    55         $_POST['post_status'] = 'private';
    56     if ( isset($_POST['publish']) && ( '' != $_POST['publish'] ) && ( $_POST['post_status'] != 'private' ) )
    57         $_POST['post_status'] = 'publish';
    58     if ( isset($_POST['advanced']) && '' != $_POST['advanced'] )
    59         $_POST['post_status'] = 'draft';
    60 
    61     $previous_status = get_post_field('post_status',  $_POST['ID']);
     57    if ( isset($post_data['saveasdraft']) && '' != $post_data['saveasdraft'] )
     58        $post_data['post_status'] = 'draft';
     59    if ( isset($post_data['saveasprivate']) && '' != $post_data['saveasprivate'] )
     60        $post_data['post_status'] = 'private';
     61    if ( isset($post_data['publish']) && ( '' != $post_data['publish'] ) && ( $post_data['post_status'] != 'private' ) )
     62        $post_data['post_status'] = 'publish';
     63    if ( isset($post_data['advanced']) && '' != $post_data['advanced'] )
     64        $post_data['post_status'] = 'draft';
     65
     66    $previous_status = get_post_field('post_status',  $post_data['ID']);
    6267
    6368    // Posts 'submitted for approval' present are submitted to $_POST the same as if they were being published.
    6469    // Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts.
    65     if ( 'page' == $_POST['post_type'] ) {
    66         if ( 'publish' == $_POST['post_status'] && !current_user_can( 'publish_pages' ) )
     70    if ( 'page' == $post_data['post_type'] ) {
     71        if ( 'publish' == $post_data['post_status'] && !current_user_can( 'publish_pages' ) )
    6772            if ( $previous_status != 'publish' OR !current_user_can( 'edit_published_pages') )
    68                 $_POST['post_status'] = 'pending';
     73                $post_data['post_status'] = 'pending';
    6974    } else {
    70         if ( isset($_POST['post_status']) && ('publish' == $_POST['post_status'] && !current_user_can( 'publish_posts' )) ) :
     75        if ( isset($post_data['post_status']) && ('publish' == $post_data['post_status'] && !current_user_can( 'publish_posts' )) ) :
    7176            // Stop attempts to publish new posts, but allow already published posts to be saved if appropriate.
    7277            if ( $previous_status != 'publish' OR !current_user_can( 'edit_published_posts') )
    73                 $_POST['post_status'] = 'pending';
     78                $post_data['post_status'] = 'pending';
    7479        endif;
    7580    }
    7681
    77     if (!isset( $_POST['comment_status'] ))
    78         $_POST['comment_status'] = 'closed';
    79 
    80     if (!isset( $_POST['ping_status'] ))
    81         $_POST['ping_status'] = 'closed';
     82    if (!isset( $post_data['comment_status'] ))
     83        $post_data['comment_status'] = 'closed';
     84
     85    if (!isset( $post_data['ping_status'] ))
     86        $post_data['ping_status'] = 'closed';
    8287
    8388    foreach ( array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) {
    84         if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) {
    85             $_POST['edit_date'] = '1';
     89        if ( !empty( $post_data['hidden_' . $timeunit] ) && $post_data['hidden_' . $timeunit] != $post_data[$timeunit] ) {
     90            $post_data['edit_date'] = '1';
    8691            break;
    8792        }
    8893    }
    8994
    90     if ( !empty( $_POST['edit_date'] ) ) {
    91         $aa = $_POST['aa'];
    92         $mm = $_POST['mm'];
    93         $jj = $_POST['jj'];
    94         $hh = $_POST['hh'];
    95         $mn = $_POST['mn'];
    96         $ss = $_POST['ss'];
     95    if ( !empty( $post_data['edit_date'] ) ) {
     96        $aa = $post_data['aa'];
     97        $mm = $post_data['mm'];
     98        $jj = $post_data['jj'];
     99        $hh = $post_data['hh'];
     100        $mn = $post_data['mn'];
     101        $ss = $post_data['ss'];
    97102        $aa = ($aa <= 0 ) ? date('Y') : $aa;
    98103        $mm = ($mm <= 0 ) ? date('n') : $mm;
     
    102107        $mn = ($mn > 59 ) ? $mn -60 : $mn;
    103108        $ss = ($ss > 59 ) ? $ss -60 : $ss;
    104         $_POST['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
    105         $_POST['post_date_gmt'] = get_gmt_from_date( $_POST['post_date'] );
     109        $post_data['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
     110        $post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );
    106111    }
    107112
     
    111116
    112117// Update an existing post with values provided in $_POST.
    113 function edit_post() {
    114 
    115     $post_ID = (int) $_POST['post_ID'];
    116 
    117     if ( 'page' == $_POST['post_type'] ) {
     118function edit_post( $post_data = null ) {
     119
     120    if ( empty($post_data) )
     121        $post_data = &$_POST;
     122
     123    $post_ID = (int) $post_data['post_ID'];
     124
     125    if ( 'page' == $post_data['post_type'] ) {
    118126        if ( !current_user_can( 'edit_page', $post_ID ) )
    119127            wp_die( __('You are not allowed to edit this page.' ));
     
    124132
    125133    // Autosave shouldn't save too soon after a real save
    126     if ( 'autosave' == $_POST['action'] ) {
     134    if ( 'autosave' == $post_data['action'] ) {
    127135        $post =& get_post( $post_ID );
    128136        $now = time();
     
    133141    }
    134142
    135     $translated = _wp_translate_postdata( true );
     143    $translated = _wp_translate_postdata( true, $post_data );
    136144    if ( is_wp_error($translated) )
    137145        wp_die( $translated->get_error_message() );
    138146
    139147    // Meta Stuff
    140     if ( isset($_POST['meta']) && $_POST['meta'] ) {
    141         foreach ( $_POST['meta'] as $key => $value )
     148    if ( isset($post_data['meta']) && $post_data['meta'] ) {
     149        foreach ( $post_data['meta'] as $key => $value )
    142150            update_meta( $key, $value['key'], $value['value'] );
    143151    }
    144152
    145     if ( isset($_POST['deletemeta']) && $_POST['deletemeta'] ) {
    146         foreach ( $_POST['deletemeta'] as $key => $value )
     153    if ( isset($post_data['deletemeta']) && $post_data['deletemeta'] ) {
     154        foreach ( $post_data['deletemeta'] as $key => $value )
    147155            delete_meta( $key );
    148156    }
     
    150158    add_meta( $post_ID );
    151159
    152     wp_update_post( $_POST );
     160    wp_update_post( $post_data );
    153161
    154162    // Reunite any orphaned attachments with their parent
     
    164172
    165173    if ( current_user_can( 'edit_others_posts' ) ) {
    166         if ( !empty($_POST['sticky']) )
     174        if ( !empty($post_data['sticky']) )
    167175            stick_post($post_ID);
    168176        else
Note: See TracChangeset for help on using the changeset viewer.