[wp-trac] [WordPress Trac] #52995: Undefined `$post_ID` variable in `edit-form-blocks.php`

WordPress Trac noreply at wordpress.org
Thu Apr 8 03:43:10 UTC 2021


#52995: Undefined `$post_ID` variable in `edit-form-blocks.php`
--------------------------+------------------------------
 Reporter:  ravipatel     |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Editor        |     Version:  5.0
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:
--------------------------+------------------------------

Comment (by mukesh27):

 Hi there!

 I investigate more on this issue and found that `$post_ID` is not defined
 on the current file but it defines in their parent files.

 `edit-form-blocks.php` has two parent files.

 File
 [https://github.com/WordPress/WordPress/blob/7d65ff4f7ae3d7fd68fe6afa1725a9aa0bd78dbc
 /wp-admin/post-new.php#L67 post-new.php] define `$post_ID` like below.

 {{{
 $post    = get_default_post_to_edit( $post_type, true );
 $post_ID = $post->ID;
 }}}

 File
 [https://github.com/WordPress/WordPress/blob/7d65ff4f7ae3d7fd68fe6afa1725a9aa0bd78dbc
 /wp-admin/post.php#L28 post.php] define `$post_ID` like below.

 {{{
 if ( isset( $_GET['post'] ) && isset( $_POST['post_ID'] ) && (int)
 $_GET['post'] !== (int) $_POST['post_ID'] ) {
         wp_die( __( 'A post ID mismatch has been detected.' ), __( 'Sorry,
 you are not allowed to edit this item.' ), 400 );
 } elseif ( isset( $_GET['post'] ) ) {
         $post_id = (int) $_GET['post'];
 } elseif ( isset( $_POST['post_ID'] ) ) {
         $post_id = (int) $_POST['post_ID'];
 } else {
         $post_id = 0;
 }
 $post_ID = $post_id;
 }}}

 FYI both the variables give the same post ID value in my test.
 {{{
 echo $post_ID;
 echo $post->ID;
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52995#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list