Opened 18 months ago
Last modified 4 months ago
#61716 new defect (bug)
Fatal error: Uncaught ArgumentCountError in get_delete_post_link() when _edit_link is site-editor.php?postType=%s&postId=%s&canvas=edit
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Permalinks | Keywords: | has-screenshots has-patch |
| Focuses: | Cc: |
Description
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.
Attachments (1)
Change History (3)
This ticket was mentioned in PR #9952 on WordPress/wordpress-develop by @debarghyabanerjee.
4 months ago
#2
- Keywords has-patch added
Trac Ticket: Core-61716
## Problem
get_delete_post_link()assumes _edit_link contains only a single placeholder (e.g. post.php?post=%d).
Gutenberg post types such as wp_template and wp_template_part define _edit_link with multiple placeholders (e.g. site-editor.php?postType=%s&postId=%s&canvas=edit).
- This mismatch causes sprintf() to throw an ArgumentCountError when generating delete links.
## Solution
- Update
get_delete_post_link()to dynamically count placeholders in _edit_link and adjust the arguments passed tovsprintf().
- This ensures compatibility with both classic and Gutenberg CPTs, prevents fatal errors, and future-proofs the function against additional placeholders.
Screenshot of the Fatal error on Template Parts ( wp_template_part ) showing the stack trace