Skip to:
Content

BuddyPress.org

Changeset 7577


Ignore:
Timestamp:
11/15/2013 09:31:46 PM (11 years ago)
Author:
boonebgorges
Message:

Publish blog posts to the activity stream based on transition_post_status

BP has historically had problems when posting certain kinds of blog posts to
the activity stream, such as improper bumping for post edits and incorrect
timestamps for scheduled posts. These problems stem from the fact that
bp_blogs_record_post has been hooked to the generic 'save_post'. Using
'transition_post_status' instead allows BP to prevent edit-bumps, while
allowing bp_blogs_record_post() to use post_date_gmt for activity timestamps
(thereby properly attributing scheduled posts).

See #3746, #2546.

Fixes #4090

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-blogs/bp-blogs-functions.php

    r7555 r7577  
    248248
    249249/**
     250 * Detect a change in post status, and initiate an activity update if necessary.
     251 *
     252 * Posts get new activity updates when (a) they are being published, and (b)
     253 * they have not already been published. This enables proper posting for
     254 * regular posts as well as scheduled posts, while preventing post bumping.
     255 *
     256 * See #4090, #3746, #2546 for background.
     257 *
     258 * @since BuddyPress (1.9.0)
     259 *
     260 * @param string $new_status New status for the post.
     261 * @param string $old_status Old status for the post.
     262 * @param object $post Post data.
     263 */
     264function bp_blogs_catch_published_post( $new_status, $old_status, $post ) {
     265
     266    // Only record published posts
     267    if ( 'publish' !== $new_status ) {
     268        return;
     269    }
     270
     271    // Don't record edits (publish -> publish)
     272    if ( 'publish' === $old_status ) {
     273        return;
     274    }
     275
     276    return bp_blogs_record_post( $post->ID, $post );
     277}
     278add_action( 'transition_post_status', 'bp_blogs_catch_published_post', 10, 3 );
     279
     280/**
    250281 * Record a new blog post in the BuddyPress activity stream.
    251282 *
     
    327358                'item_id'           => $blog_id,
    328359                'secondary_item_id' => $post_id,
    329                 'recorded_time'     => $post->post_modified_gmt
     360                'recorded_time'     => $post->post_date_gmt,
    330361            ));
    331362        }
     
    339370    do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
    340371}
    341 add_action( 'save_post', 'bp_blogs_record_post', 10, 2 );
    342372
    343373/**
Note: See TracChangeset for help on using the changeset viewer.