Make WordPress Core

Opened 14 years ago

Closed 9 years ago

Last modified 5 years ago

#10545 closed defect (bug) (worksforme)

_publish_post_hook (adding to postmeta existing hooks)

Reported by: butuzov's profile butuzov Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.8.1
Component: General Keywords: has-patch publish_post_hook pings postmeta
Focuses: 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 13 years ago.

Download all attachments as: .zip

Change History (8)

#1 @markjaquith
13 years ago

  • Milestone changed from 2.9 to 3.0

@layotte
13 years ago

#2 @layotte
13 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

#3 @nacin
13 years ago

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.

#4 @layotte
13 years ago

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

Lew

#5 @nacin
13 years ago

  • Milestone changed from 3.0 to Future Release

#6 @nacin
9 years ago

  • Component changed from Optimization to General
  • Keywords changed from has-patch, publish_post_hook, pings, postmeta to has-patch publish_post_hook pings postmeta
  • Milestone Future Release deleted
  • Resolution set to worksforme
  • Status changed from new to closed

This ticket was mentioned in Slack in #accessibility by afercia. View the logs.


5 years ago

Note: See TracTickets for help on using tickets.