[wp-trac] [WordPress Trac] #58763: Inconsistent add/get/update/delete_post_meta() functions leads to deleting post metadata.
WordPress Trac
noreply at wordpress.org
Tue May 13 17:37:31 UTC 2025
#58763: Inconsistent add/get/update/delete_post_meta() functions leads to deleting
post metadata.
-------------------------------------------------+-------------------------
Reporter: jsmoriss | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future
| Release
Component: General | Version:
Severity: major | Resolution:
Keywords: has-patch has-test-info has-unit- | Focuses:
tests early dev-feedback |
-------------------------------------------------+-------------------------
Changes (by SirLouen):
* keywords: has-patch needs-testing has-test-info has-unit-tests early =>
has-patch has-test-info has-unit-tests early dev-feedback
Comment:
== Test Report
=== Description
✅ This report validates that the indicated patch works as expected.
Patch tested: https://github.com/WordPress/wordpress-
develop/pull/5476.diff
=== Environment
- WordPress: 6.9-alpha-60093-src
- PHP: 8.2.28
- Server: nginx/1.27.5
- Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
- Browser: Chrome 136.0.0.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Five 1.2
- MU Plugins: None activated
- Plugins:
* Hello Dolly v2 1.7.2
* Test Reports 1.2.0
=== Bug Reproduction
1. We can use the
[https://core.trac.wordpress.org/ticket/58763?replyto=13#comment:6 code
here] (note that there is a slight mistake in the function name callback
of the `add_action`)
2. Create a post
3. Add a revision
4. 🐞 Check PHP logs to observe that the result, unexpectedly is empty
I've also created another version of the code to test this, but its pretty
much the same idea
=== Actual Results
1. ✅ Issue resolved with patch.
=== Additional Notes
Replying to [comment:13 audrasjb]:
> The aim was to commit it before beta 1. Looks like we let it slip to
beta 2…
>
> By the way, as unit tests are failing, it's probably better to handle
this ticket `early` in the 6.6 cycle.
I've been running full testing, and I can't really see any errors
I don't entirely understand why this patch has not been integrated
already. Both patch, unit tests and the overall testing framework seem
legit, and the problem is there. I think that this is ready to be shipped
✅
=== Supplemental Artifacts
My version of the code
{{{#!php
add_action('save_post', 'demo_post_meta_revision_issue', 10, 3);
function demo_post_meta_revision_issue($post_id, $post) {
$meta_key = '_demo_test_metadata';
error_log("--------------------------------");
if ('revision' === $post->post_type) {
$parent_id = wp_get_post_parent_id($post_id);
$log_message = " - Revision ID: $post_id (Parent Post ID:
$parent_id)\n";
error_log($log_message);
$meta_value = get_post_meta($post_id, $meta_key, true);
$log_message = " - Retrieved meta value for revision: " .
(empty($meta_value) ? '❌ Empty' : '✅ ' . $meta_value) . "\n";
error_log($log_message);
update_post_meta($post_id, $meta_key, $meta_value);
$updated_value = get_post_meta($parent_id, $meta_key, true);
$log_message = " - Updated meta value on parent post: " .
(empty($updated_value) ? '❌ Empty (Metadata erased)' : '✅ ' .
$updated_value) . "\n";
error_log($log_message);
} else {
if (empty(get_post_meta($post_id, $meta_key, true))) {
add_post_meta($post_id, $meta_key, 'Test Value');
$log_message = " - Post ID: $post_id - Added meta value:
Test Value\n";
error_log($log_message);
} else {
$meta_value = get_post_meta($post_id, $meta_key, true);
$log_message = " - Post ID: $post_id - Existing meta value:
$meta_value\n";
error_log($log_message);
}
}
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58763#comment:17>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list