Make WordPress Core

Opened 9 years ago

Last modified 6 years ago

#37441 new defect (bug)

get_default_post_to_edit() function is broken

Reported by: tfrommen's profile tfrommen Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: administration Cc:

Description

The get_default_post_to_edit() function contains the following code (formatted for the sake of better readability) in case a new post should be inserted to the database:

<?php
$post_id = wp_insert_post( array(
    'post_title' => __( 'Auto Draft' ),
    'post_type' => $post_type,
    'post_status' => 'auto-draft',
) );
$post = get_post( $post_id );

Later in the function, we just work with the $post object.

The problem is, there are se-ve-ral rea-sons under which wp_insert_post() returns 0. In such a case, get_post(), in turn, will return null, which is neither a WP_Post object nor an object at all.

Then, setting a property on this null post will automatically create a new stdClass, resulting in the $post object only having the three explicitly set properties post_content, post_title and post_excerpt.

If you want to see how this affects WordPress, just put $post = null; before wp-admin/includes/post.php:L631.

Change History (0)

Note: See TracTickets for help on using tickets.