Opened 4 years ago

Last modified 3 years ago

#10545 new defect (bug)

_publish_post_hook (adding to postmeta existing hooks)

Reported by: butuzov Owned by:
Priority: normal Milestone: Future Release
Component: Optimization Version: 2.8.1
Severity: normal Keywords: has-patch, publish_post_hook, pings, postmeta
Cc:

Description

The problem that each time yuo press publish (assuming this is a save button) wp add to postmeta table new records even thay already exist now.

if ( get_option('default_pingback_flag') )
		$wpdb->insert( $wpdb->postmeta, $data + array( 'meta_key' => '_pingme' ) );
	$wpdb->insert( $wpdb->postmeta, $data + array( 'meta_key' => '_encloseme' ) );

shoud be (something like)

if ( get_option('default_pingback_flag') ){
		get_post_meta($post_id, '_pingme') ? update_post_meta($post_id, '_pingme', 1) : add_post_meta($post_id, '_pingme', 1);
		
	get_post_meta($post_id, '_encloseme') ? update_post_meta($post_id, '_encloseme', 1) : add_post_meta($post_id, '_encloseme', 1);

Attachments (1)

post.patch (903 bytes) - added by layotte 3 years ago.

Download all attachments as: .zip

Change History (6)

  • Milestone changed from 2.9 to 3.0

layotte3 years ago

  • Keywords has-patch added

Verified issue... published post, set post to draft, republished post... kept adding postmeta to DB.

created patch with suggested fix from butuzov and tested.

Now it acts like this:

  1. Publish Post
  2. Adds postmeta
  3. Set Post to Draft
  4. Removes postmeta
  5. Publish Post
  6. Adds postmeta

We shouldn't be removing postmeta on a status change.

Regarding the patch, no need to check get_post_meta before choosing between update_post_meta and add_post_meta. update will add if the key/value doesn't exist.

I imagine there's a reason for a direct query there.

I'm not really sure why it was removing the postmeta... something was somewhere.

Lew

  • Milestone changed from 3.0 to Future Release
Note: See TracTickets for help on using tickets.