Skip to:
Content

bbPress.org

Changeset 4881


Ignore:
Timestamp:
05/06/2013 02:38:53 AM (9 years ago)
Author:
johnjamesjacoby
Message:

In the BuddyPress Activity extension, move _update() methods from 'wp_insert_post' onto 'edit_post' action to prevent running them on topic/reply creation accidentally. Fixes bug causing hide_sitewide to incorrectly be set to true on some installations. Also some code clean-up and additional type-casting where appropriate. Fixes #2327 (trunk)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/extend/buddypress/activity.php

    r4836 r4881  
    104104
    105105        // The name of the BuddyPress component, used in activity streams
    106         $this->component = 'bbpress';
     106        $this->component    = 'bbpress';
    107107
    108108        // Forums
     
    138138
    139139        // Hook into topic and reply status changes
    140         add_action( 'wp_insert_post',                    array( $this, 'topic_update'              ), 10, 2 );
    141         add_action( 'wp_insert_post',                    array( $this, 'reply_update'              ), 10, 2 );
     140        add_action( 'edit_post',                         array( $this, 'topic_update'              ), 10, 2 );
     141        add_action( 'edit_post',                         array( $this, 'reply_update'              ), 10, 2 );
    142142
    143143        // Hook into topic and reply deletion
     
    164164     */
    165165    private function setup_filters() {
    166 
    167         /** Activity **********************************************************/
    168166
    169167        // Obey BuddyPress commenting rules
     
    211209     * @return type Activity ID if successful, false if not
    212210     */
    213     private function record_activity( $args = '' ) {
     211    private function record_activity( $args = array() ) {
    214212
    215213        // Default activity args
     
    247245
    248246        // Default activity args
    249         $defaults = array(
     247        $activity = bbp_parse_args( $args, array(
    250248            'item_id'           => false,
    251249            'component'         => $this->component,
     
    253251            'user_id'           => false,
    254252            'secondary_item_id' => false
    255         );
    256         $activity = bbp_parse_args( $args, $defaults, 'delete_activity' );
     253        ), 'delete_activity' );
    257254
    258255        // Delete the activity
     
    279276        // Get the activity stream item, bail if it doesn't exist
    280277        $existing = bp_activity_get_specific( array( 'activity_ids' => $activity_id, 'show_hidden' => true, 'spam' => 'all', ) );
    281         if ( empty( $existing['total'] ) || ( 1 != $existing['total'] ) )
     278        if ( empty( $existing['total'] ) || ( 1 !== (int) $existing['total'] ) )
    282279            return null;
    283280
     
    383380     * @return Bail early if topic is by anonymous user
    384381     */
    385     public function topic_create( $topic_id, $forum_id, $anonymous_data, $topic_author_id ) {
     382    public function topic_create( $topic_id = 0, $forum_id = 0, $anonymous_data = array(), $topic_author_id = 0 ) {
    386383
    387384        // Bail early if topic is by anonymous user
     
    394391
    395392        // Validate activity data
    396         $user_id  = $topic_author_id;
     393        $user_id  = (int) $topic_author_id;
    397394        $topic_id = bbp_get_topic_id( $topic_id );
    398395        $forum_id = bbp_get_forum_id( $forum_id );
     
    407404
    408405        // User link for topic author
    409         $user_link  = bbp_get_user_profile_link( $user_id  );
     406        $user_link = bbp_get_user_profile_link( $user_id  );
    410407
    411408        // Topic
     
    425422        $activity_content = apply_filters( 'bbp_activity_topic_create_excerpt', $topic_content                                     );
    426423
    427         // Compile the activity stream results
    428         $activity = array(
     424        // Compile and record the activity stream results
     425        $activity_id = $this->record_activity( array(
    429426            'id'                => $this->get_activity_id( $topic_id ),
    430427            'user_id'           => $user_id,
     
    437434            'recorded_time'     => get_post_time( 'Y-m-d H:i:s', true, $topic_id ),
    438435            'hide_sitewide'     => ! bbp_is_forum_public( $forum_id, false )
    439         );
    440 
    441         // Record the activity
    442         $activity_id = $this->record_activity( $activity );
     436        ) );
    443437
    444438        // Add the activity entry ID as a meta value to the topic
     
    454448     * @uses bp_activity_delete()
    455449     */
    456     public function topic_delete( $topic_id ) {
     450    public function topic_delete( $topic_id = 0 ) {
    457451
    458452        // Get activity ID, bail if it doesn't exist
     
    478472     * @return Bail early if not a topic, or topic is by anonymous user
    479473     */
    480     public function topic_update( $topic_id, $post ) {
     474    public function topic_update( $topic_id = 0, $post = null ) {
    481475
    482476        // Bail early if not a topic
    483         if ( get_post_type( $post ) != bbp_get_topic_post_type() )
     477        if ( get_post_type( $post ) !== bbp_get_topic_post_type() )
    484478            return;
    485479
     
    489483        if ( bbp_is_topic_anonymous( $topic_id ) )
    490484            return;
    491 
    492         $anonymous_data = array();
    493485
    494486        // Action based on new status
     
    499491            $topic_author_id = bbp_get_topic_author_id( $topic_id );
    500492
    501             $this->topic_create( $topic_id, $forum_id, $anonymous_data, $topic_author_id );
     493            $this->topic_create( $topic_id, $forum_id, array(), $topic_author_id );
    502494        } else {
    503495            $this->topic_delete( $topic_id );
     
    529521     * @return Bail early if topic is by anonywous user
    530522     */
    531     public function reply_create( $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author_id ) {
     523    public function reply_create( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = array(), $reply_author_id = 0 ) {
    532524
    533525        // Do not log activity of anonymous users
     
    540532
    541533        // Validate activity data
    542         $user_id  = $reply_author_id;
     534        $user_id  = (int) $reply_author_id;
    543535        $reply_id = bbp_get_reply_id( $reply_id );
    544536        $topic_id = bbp_get_topic_id( $topic_id );
     
    554546
    555547        // Setup links for activity stream
    556         $user_link  = bbp_get_user_profile_link( $user_id  );
     548        $user_link = bbp_get_user_profile_link( $user_id  );
    557549
    558550        // Reply
     
    575567        $activity_content = apply_filters( 'bbp_activity_reply_create_excerpt', $reply_content                                  );
    576568
    577         // Compile the activity stream results
    578         $activity = array(
     569        // Compile and record the activity stream results
     570        $activity_id = $this->record_activity( array(
    579571            'id'                => $this->get_activity_id( $reply_id ),
    580572            'user_id'           => $user_id,
     
    587579            'recorded_time'     => get_post_time( 'Y-m-d H:i:s', true, $reply_id ),
    588580            'hide_sitewide'     => ! bbp_is_forum_public( $forum_id, false )
    589         );
    590 
    591         // Record the activity
    592         $activity_id = $this->record_activity( $activity );
     581        ) );
    593582
    594583        // Add the activity entry ID as a meta value to the reply
     
    633622
    634623        // Bail early if not a reply
    635         if ( get_post_type( $post ) != bbp_get_reply_post_type() )
     624        if ( get_post_type( $post ) !== bbp_get_reply_post_type() )
    636625            return;
    637626
     
    641630        if ( bbp_is_reply_anonymous( $reply_id ) )
    642631            return;
    643 
    644         $anonymous_data = array();
    645632
    646633        // Action based on new status
     
    652639            $reply_author_id = bbp_get_reply_author_id( $reply_id );
    653640
    654             $this->reply_create( $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author_id );
     641            $this->reply_create( $reply_id, $topic_id, $forum_id, array(), $reply_author_id );
    655642        } else {
    656643            $this->reply_delete( $reply_id );
Note: See TracChangeset for help on using the changeset viewer.