Skip to:
Content

BuddyPress.org

Changeset 8191


Ignore:
Timestamp:
03/28/2014 11:01:08 PM (10 years ago)
Author:
r-a-y
Message:

Blogs: Tweak what happens when a post status is changed.

r8073 introduced bp_blogs_catch_transition_post_status() to determine
how blog posts are recorded in the activity stream. However, blog
post edits are not accounted for.

This commit:

  • Updates a blog post's activity item when a post is edited
  • Mirrors a blog post's comment status to activitymeta for use with bp_blogs_comments_open() (see r8189)
  • Removes the usage of bp_blogs_record_post() when a post has changed to an unpublished status. bp_blogs_record_post() already fires on the 'delete_post' action, so this isn't necessary. Instead, we remove the corresponding activity entry.

See #5333, #5130

File:
1 edited

Legend:

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

    r8190 r8191  
    360360 * @since BuddyPress (2.0.0)
    361361 *
     362 * @todo Support untrashing better
     363 *
    362364 * @param string $new_status New status for the post.
    363365 * @param string $old_status Old status for the post.
     
    366368function bp_blogs_catch_transition_post_status( $new_status, $old_status, $post ) {
    367369
    368     // Do nothing for edits
     370    // This is an edit
    369371    if ( $new_status === $old_status ) {
    370         return;
     372        if ( $new_status == 'publish' ) {
     373            bp_blogs_update_post( $post );
     374            return;
     375        }
    371376    }
    372377
    373378    // Publishing a previously unpublished post
    374379    if ( 'publish' === $new_status ) {
    375         return bp_blogs_record_post( $post->ID, $post );
     380        // Untrashing the post
     381        // Nothing here yet
     382        if ( 'trash' == $old_status ) {}
     383
     384        // Record the post
     385        bp_blogs_record_post( $post->ID, $post );
    376386
    377387    // Unpublishing a previously published post
    378388    } else if ( 'publish' === $old_status ) {
    379         return bp_blogs_remove_post( $post->ID );
     389        // Some form of pending status
     390        // Only remove the activity entry
     391        bp_blogs_delete_activity( array(
     392            'item_id'           => get_current_blog_id(),
     393            'secondary_item_id' => $post->ID,
     394            'component'         => buddypress()->blogs->id,
     395            'type'              => 'new_blog_post'
     396        ) );
    380397    }
    381398}
     
    472489
    473490    do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
     491}
     492
     493/**
     494 * Updates a blog post's corresponding activity entry during a post edit.
     495 *
     496 * @since BuddyPress (2.0.0)
     497 *
     498 * @see bp_blogs_catch_transition_post_status()
     499 *
     500 * @param WP_Post $post
     501 */
     502function bp_blogs_update_post( $post ) {
     503    if ( ! bp_is_active( 'activity' ) ) {
     504        return;
     505    }
     506
     507    $activity_id = bp_activity_get_activity_id( array(
     508        'component'         => buddypress()->blogs->id,
     509        'item_id'           => get_current_blog_id(),
     510        'secondary_item_id' => $post->ID,
     511        'type'              => 'new_blog_post',
     512     ) );
     513
     514    // activity ID doesn't exist, so stop!
     515    if ( empty( $activity_id ) ) {
     516        return;
     517    }
     518
     519    // update the activity entry
     520    $activity = new BP_Activity_Activity( $activity_id );
     521    $activity->content = $post->post_content;
     522    $activity->save();
     523
     524    // add post comment status to activity meta if closed
     525    if( 'closed' == $post->comment_status ) {
     526        bp_activity_update_meta( $activity_id, 'post_comment_status', $post->comment_status );
     527    } else {
     528        bp_activity_delete_meta( $activity_id, 'post_comment_status' );
     529    }
    474530}
    475531
Note: See TracChangeset for help on using the changeset viewer.