WordPress.org

Make WordPress Core

Changeset 23740


Ignore:
Timestamp:
03/18/13 14:33:09 (2 years ago)
Author:
ryan
Message:

Bail early with correct WP_Error when an invalid post ID is passed to wp_insert_post() and wp_update_post().

Props simonwheatley
fixes #23474

File:
1 edited

Legend:

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

    r23722 r23740  
    26362636 
    26372637    // Are we updating or creating? 
     2638    $post_ID = 0; 
    26382639    $update = false; 
    2639     if ( !empty($ID) ) { 
     2640    if ( ! empty( $ID ) ) { 
    26402641        $update = true; 
     2642 
     2643        // Get the post ID and GUID 
     2644        $post_ID = $ID; 
     2645        $post_before = get_post( $post_ID ); 
     2646        if ( is_null( $post_before ) ) { 
     2647            if ( $wp_error ) 
     2648                return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) ); 
     2649            return 0; 
     2650        } 
     2651 
     2652        $guid = get_post_field( 'guid', $post_ID ); 
    26412653        $previous_status = get_post_field('post_status', $ID); 
    26422654    } else { 
     
    26732685    if ( empty($post_author) ) 
    26742686        $post_author = $user_ID; 
    2675  
    2676     $post_ID = 0; 
    2677  
    2678     // Get the post ID and GUID 
    2679     if ( $update ) { 
    2680         $post_ID = (int) $ID; 
    2681         $guid = get_post_field( 'guid', $post_ID ); 
    2682         $post_before = get_post($post_ID); 
    2683     } 
    26842687 
    26852688    // Don't allow contributors to set the post slug for pending review posts 
     
    28942897    // First, get all of the original fields 
    28952898    $post = get_post($postarr['ID'], ARRAY_A); 
     2899 
     2900    if ( is_null( $post ) ) { 
     2901        if ( $wp_error ) 
     2902            return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) ); 
     2903        return 0; 
     2904    } 
    28962905 
    28972906    // Escape data pulled from DB. 
Note: See TracChangeset for help on using the changeset viewer.