Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/06/2014 09:02:22 PM (11 years ago)
Author:
boonebgorges
Message:

Improved management of new_blog_post activity items at transition_post_status

Introduces bp_blogs_catch_transition_post_status(). This function, which
replaces bp_blogs_catch_published_post(), performs a similar task - determining
when a new blog post has been published, and recording the post in the activity
stream - but adds a corrolary for unpublishing that deletes the activity item.

Unit tests and deprecated function are included.

See #5333

Props henry.wright for an initial patch

File:
1 edited

Legend:

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

    r8042 r8073  
    260260 * See #4090, #3746, #2546 for background.
    261261 *
    262  * @since BuddyPress (1.9.0)
     262 * @since BuddyPress (2.0.0)
    263263 *
    264264 * @param string $new_status New status for the post.
     
    266266 * @param object $post Post data.
    267267 */
    268 function bp_blogs_catch_published_post( $new_status, $old_status, $post ) {
    269 
    270     // Only record published posts
    271     if ( 'publish' !== $new_status ) {
     268function bp_blogs_catch_transition_post_status( $new_status, $old_status, $post ) {
     269
     270    // Do nothing for edits
     271    if ( $new_status === $old_status ) {
    272272        return;
    273273    }
    274274
    275     // Don't record edits (publish -> publish)
    276     if ( 'publish' === $old_status ) {
    277         return;
    278     }
    279 
    280     return bp_blogs_record_post( $post->ID, $post );
    281 }
    282 add_action( 'transition_post_status', 'bp_blogs_catch_published_post', 10, 3 );
     275    // Publishing a previously unpublished post
     276    if ( 'publish' === $new_status ) {
     277        return bp_blogs_record_post( $post->ID, $post );
     278
     279    // Unpublishing a previously published post
     280    } else if ( 'publish' === $old_status ) {
     281        return bp_blogs_remove_post( $post->ID );
     282    }
     283}
     284add_action( 'transition_post_status', 'bp_blogs_catch_transition_post_status', 10, 3 );
    283285
    284286/**
Note: See TracChangeset for help on using the changeset viewer.