Make WordPress Core


Ignore:
Timestamp:
09/02/2025 04:48:32 PM (13 months ago)
Author:
SergeyBiryukov
Message:

Posts, Post Types: Check the result of creating a draft in get_default_post_to_edit().

As wp_insert_post() can return an error for various reasons, this commit ensures that this scenario is properly handled and an error message is displayed.

Follow-up to [12987].

Props rishabhwp, tfrommen, SirLouen, siliconforks, SergeyBiryukov.
Fixes #37441.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/includesPost.php

    r58360 r60701  
    533533
    534534                $this->assertSame( 1, $action->get_call_count() );
     535        }
     536
     537        /**
     538         * Tests that get_default_post_to_edit() calls wp_die() if wp_insert_post() returns a WP_Error.
     539         *
     540         * @ticket 37441
     541         *
     542         * @covers ::get_default_post_to_edit
     543         */
     544        public function test_get_default_post_to_edit_with_wp_insert_post_error() {
     545                add_filter( 'wp_insert_post_empty_content', '__return_true' );
     546
     547                $this->expectException( 'WPDieException' );
     548                get_default_post_to_edit( 'post', true );
    535549        }
    536550
Note: See TracChangeset for help on using the changeset viewer.