Support » Plugin: Share Buttons by AddThis » AddThis Inserts duplicate meta items

  • Resolved Tyrel Kelsey


    Currently the addthis_post_metabox::save_post function adds a meta item every time the post_save action is run. The problem stems from this section of code lines 54 through 62 of addthis_post_metabox.php

    $custom_fields = get_post_custom($post_id);
    if (! isset ($custom_fields['addthis_exclude'][0])  )
        add_post_meta($post_id, 'addthis_exclude', 'true');
        update_post_meta($post_id, 'addthis_exclude', 'true' , $custom_fields['addthis_exclude'][0]  );

    From what I’ve found the problem is that when the new revision of the post that also triggers the save_post action has no meta so it triggers the add_post_meta section of the code which then uses wp_is_post_revision which returns the parent post id to have the meta applied to it and since add_post_meta doesn’t have the $unique parameter set as true it adds a duplicate meta value to the parent post.

    Since this meta key is supposed to be unique and only has one value I found that changing the code above to this code fixed the problem for me.

    if( ! update_post_meta($post_id, 'addthis_exclude', 'true' ) )
        add_post_meta( $post_id, 'addthis_exclude', 'true', true );

Viewing 1 replies (of 1 total)
  • @ninnypants: Thanks for the fix. We had a similar issue reported already and a slightly different fix is applied in the currently released version (3.0.3). I will review this fix as well apply it if necessary.

Viewing 1 replies (of 1 total)
  • The topic ‘AddThis Inserts duplicate meta items’ is closed to new replies.