[wp-trac] [WordPress Trac] #61716: Fatal error: Uncaught ArgumentCountError in get_delete_post_link() when _edit_link is site-editor.php?postType=%s&postId=%s&canvas=edit

WordPress Trac noreply at wordpress.org
Sat Jul 20 11:28:55 UTC 2024


#61716: Fatal error: Uncaught ArgumentCountError in get_delete_post_link() when
_edit_link is site-editor.php?postType=%s&postId=%s&canvas=edit
-------------------------------+-----------------------------
 Reporter:  bobbingwide        |      Owner:  (none)
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:
 Severity:  normal             |   Keywords:  has-screenshots
  Focuses:                     |
-------------------------------+-----------------------------
 Background

 I while ago, before WordPress 6.3, I wrote plugin called gbcptedit (
 Gutenberg Custom Post Type Edit ) which enables me to see the posts for
 the CPTs that were introduced by Gutenberg into WordPress. I used this
 plugin to help debug / problem determination of several problems where the
 site editor was not working as expected.

 I recently noticed a Fatal error while attempting to view template parts.

 Analysis of the problem indicates that this is a problem within the
 `get_delete_post_link()`. The function assumes that the format of the
 `_edit_link` property for the post_object is `post.php?post=%d`, so it
 only passes the post ID to the sprintf

 The failing line is

 {{{
 $delete_link = add_query_arg( 'action', $action, admin_url( sprintf(
 $post_type_object->_edit_link, $post->ID ) ) );
 }}}

 When the `_edit_link` is
 `site-editor.php?postType=%s&postId=%s&canvas=edit`
 then sprintf expects 3 parameters; the second for the postType attribute
 and the third for the postId.

 The Docblock for the function states

 Can be used within the WordPress loop or outside of it, with any post
 type.


 This comment is no longer true.
 In my opinion the code needs to be corrected rather than the comment.

 Note: I was not using get_delete_post_link directly. It's called during
 WP_List_Table->display.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/61716>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list