[wp-trac] [WordPress Trac] #19826: Error behavior for deleting trashed posts is different for Bulk Delete versus Empty Trash
WordPress Trac
noreply at wordpress.org
Wed Dec 10 15:40:55 UTC 2025
#19826: Error behavior for deleting trashed posts is different for Bulk Delete
versus Empty Trash
-------------------------------------------------+-------------------------
Reporter: jpbellona | Owner:
| piontkowski
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: Future
| Release
Component: Posts, Post Types | Version: 3.1.2
Severity: minor | Resolution:
Keywords: has-patch needs-testing has-test- | Focuses:
info |
-------------------------------------------------+-------------------------
Comment (by sajib1223):
== Test Report
=== Description
This report validates whether the indicated patch works as expected.
Patch tested: REPLACE_WITH_PATCH_URL
=== Environment
- WordPress: 6.9
- PHP: 8.3.28
- Server: Apache/2.4.65 (Debian)
- Database: mysqli (Server: 10.6.24-MariaDB-ubu2204 / Client: mysqlnd
8.3.28)
- Browser: Firefox 145.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Five 1.4
- MU Plugins: None activated
- Plugins:
* Test Delete Behavior Plugin 1.1.0
* Test Reports 1.2.1
=== Actual Results
1. ✅ Issue resolved with patch.
=== Additional Notes
- Create a test plugin with this following code to create an author user,
and give the author user `edit_others_posts` capability to make Empty
Trash button available.
{{{
<?php
/*
* Plugin Name: Test Delete Behavior Plugin
* Plugin URI: https://shazzad.me
* Description: Creates subject CPT + test posts for admin/author, auto-
creates users if needed. Includes reset button.
* Version: 1.2.0
* Author: Shazzad Hossain Khan
* Author URI: https://shazzad.me
*/
if (! defined('ABSPATH')) {
exit;
}
add_action('init', function () {
$role = get_role('author');
if ($role) {
// Allow author to see Tools page actions
$role->add_cap('read'); // default
$role->add_cap('edit_posts'); // required
$role->add_cap('delete_posts'); // cleanup button
$role->add_cap('edit_others_posts'); // needed for
testing behavior
}
}, 20);
add_action('init', function () {
register_post_type('subject', [
'label' => 'Subjects',
'public' => false,
'show_ui' => true,
'supports' => ['title', 'editor', 'author'],
'capability_type' => 'post',
]);
});
add_action('admin_menu', function () {
add_management_page(
'Generate Test Posts',
'Generate Test Posts',
'edit_posts', // <-- author can access
'generate-test-posts',
't19826_generate_test_posts_admin_page'
);
});
function t19826_get_or_create_test_user($username, $role)
{
$user = get_user_by('login', $username);
if ($user) {
return $user->ID;
}
$user_id = wp_create_user($username, $username,
$username.'@example.com');
if (is_wp_error($user_id)) {
return 0;
}
$user_obj = new WP_User($user_id);
$user_obj->set_role($role);
return $user_id;
}
function t19826_generate_test_posts_admin_page()
{
// --- Generate Posts ---
if (isset($_POST['generate_posts']) &&
check_admin_referer('generate_posts_action')) {
// Create or get users
$admin_id = t19826_get_or_create_test_user('admin',
'administrator');
$author_id = t19826_get_or_create_test_user('author',
'author');
if (! $admin_id || ! $author_id) {
echo '<div class="notice notice-
error"><p><strong>Error creating test users.</strong></p></div>';
} else {
// Create 3 trashed posts for each user
foreach ([$admin_id, $author_id] as $uid) {
for ($i = 1; $i <= 3; $i++) {
wp_insert_post([
'post_title' => "Test
Subject by User {$uid} - {$i}",
'post_content' =>
"Generated for Trash permission testing.",
'post_status' => 'trash',
'post_type' =>
'subject',
'post_author' => $uid,
]);
}
}
echo '<div class="notice notice-
success"><p><strong>Test users verified and posts
generated.</strong></p></div>';
}
}
// --- Reset / Delete all subject posts ---
if (isset($_POST['reset_subjects']) &&
check_admin_referer('reset_subjects_action')) {
$posts = get_posts([
'post_type' => 'subject',
'post_status' => 'all',
'numberposts' => -1,
'fields' => 'ids',
]);
foreach ($posts as $pid) {
wp_delete_post($pid, true); // force delete
}
echo '<div class="notice notice-success"><p><strong>All
subject posts deleted/reset.</strong></p></div>';
}
?>
<div class="wrap">
<h1>Test Delete Behavior – Tools</h1>
<p>This tool allows generating and resetting test data for
testing delete behavior.</p>
<hr>
<h2>Generate Test Posts</h2>
<p>This will:</p>
<ul>
<li>Create users <strong>admin</strong> (password:
<code>admin</code>) and <strong>author</strong> (password:
<code>author</code>) if missing.
</li>
<li>Create 3 trashed <code>subject</code> posts
for each user.</li>
</ul>
<form method="post" style="margin-bottom:30px;">
<?php wp_nonce_field('generate_posts_action'); ?>
<input type="hidden" name="generate_posts"
value="1" />
<?php submit_button('Generate Posts Now'); ?>
</form>
<hr>
<h2>Reset / Delete All Subject Posts</h2>
<p>This will permanently delete all <code>subject</code>
posts (including trash).</p>
<form method="post">
<?php wp_nonce_field('reset_subjects_action'); ?>
<input type="hidden" name="reset_subjects"
value="1" />
<?php submit_button('Delete/Reset Subject Posts',
'delete'); ?>
</form>
</div>
<?php
}
}}}
=== Supplemental Artifacts
With patch:
https://www.awesomescreenshot.com/video/47323561?key=83612d1ef9c46d21bf965fd2aba0aacf
--
Ticket URL: <https://core.trac.wordpress.org/ticket/19826#comment:20>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list