Skip to:
Content

BuddyPress.org

Ticket #5130: 5130.02.patch

File 5130.02.patch, 28.7 KB (added by r-a-y, 12 years ago)
  • bp-activity/bp-activity-functions.php

     
    15071507         * You may want to hook into this filter if you want to override this function and
    15081508         * handle the deletion of child comments differently. Make sure you return false.
    15091509         */
    1510         if ( !apply_filters( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id ) )
    1511                 return false;
     1510        if ( ! apply_filters( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id ) ) {
     1511                return true;
     1512        }
    15121513
    15131514        // Delete any children of this comment.
    15141515        bp_activity_delete_children( $activity_id, $comment_id );
  • bp-activity/bp-activity-template.php

     
    29722972        }
    29732973
    29742974/**
     2975 * Recurse through all activity comments and return the activity comment IDs.
     2976 *
     2977 * @since BuddyPress (2.0.0)
     2978 *
     2979 * @param array $activity Array of activities generated from {@link bp_activity_get()}.
     2980 * @return array
     2981 */
     2982function bp_activity_recurse_comments_activity_ids( $activity = array(), $activity_ids = array() ) {
     2983        if ( is_array( $activity ) && ! empty( $activity['activities'] ) ) {
     2984                $activity = $activity['activities'][0];
     2985        }
     2986
     2987        if ( ! empty( $activity->children ) ) {
     2988                foreach ($activity->children as $child ) {
     2989                        $activity_ids[] = $child->id;
     2990
     2991                        if( ! empty( $child->children ) ) {
     2992                                $activity_ids = bp_activity_recurse_comments_activity_ids( $child, $activity_ids );
     2993                        }
     2994                }
     2995        }
     2996
     2997        return $activity_ids;
     2998}
     2999
     3000/**
    29753001 * Output the mentionname for the displayed user.
    29763002 *
    29773003 * @since BuddyPress (1.9.0)
  • bp-blogs/bp-blogs-activity.php

     
    345345                'secondary_item_id' => $secondary_item_id
    346346        ) );
    347347}
     348
     349/**
     350 * Syncs activity comments and posts them back as blog comments.
     351 *
     352 * Note: This is only a one-way sync - activity comments -> blog comment.
     353 *
     354 * For blog post -> activity comment, see {@link bp_blogs_record_comment()}.
     355 *
     356 * @since BuddyPress (2.0.0)
     357 *
     358 * @param int $comment_id The activity ID for the posted activity comment.
     359 * @param array $params Parameters for the activity comment.
     360 * @param object Parameters of the parent activity item (in this case, the blog post).
     361 */
     362function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_activity ) {
     363        // if parent activity isn't a blog post, stop now!
     364        if ( $parent_activity->type != 'new_blog_post' ) {
     365                return;
     366        }
     367
     368        // if activity comments are disabled for blog posts, stop now!
     369        if ( bp_disable_blogforum_comments() ) {
     370                return;
     371        }
     372
     373        // get userdata
     374        if ( $params['user_id'] == bp_loggedin_user_id() ) {
     375                $user = buddypress()->loggedin_user->userdata;
     376        } else {
     377                $user = bp_core_get_core_userdata( $params['user_id'] );
     378        }
     379
     380        // see if a parent WP comment ID exists
     381        if ( ! empty( $params['parent_id'] ) ) {
     382                $comment_parent = bp_activity_get_meta( $params['parent_id'], 'bp_blogs_post_comment_id' );
     383        } else {
     384                $comment_parent = 0;
     385        }
     386
     387        // comment args
     388        $args = array(
     389                'comment_post_ID'      => $parent_activity->secondary_item_id,
     390                'comment_author'       => bp_core_get_user_displayname( $params['user_id'] ),
     391                'comment_author_email' => $user->user_email,
     392                'comment_author_url'   => bp_core_get_user_domain( $params['user_id'], $user->user_nicename, $user->user_login ),
     393                'comment_content'      => $params['content'],
     394                'comment_type'         => '', // could be interesting to add 'buddypress' here...
     395                'comment_parent'       => (int) $comment_parent,
     396                'user_id'              => $params['user_id'],
     397
     398                // commenting these out for now
     399                //'comment_author_IP'    => '127.0.0.1',
     400                //'comment_agent'        => '',
     401
     402                'comment_approved'     => 1
     403        );
     404
     405        // prevent separate activity entry being made
     406        remove_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
     407
     408        // handle multisite
     409        switch_to_blog( $parent_activity->item_id );
     410
     411        // handle timestamps for the WP comment after we've switched to the blog
     412        $args['comment_date']     = current_time( 'mysql' );
     413        $args['comment_date_gmt'] = current_time( 'mysql', 1 );
     414
     415        // post the comment
     416        $post_comment_id = wp_insert_comment( $args );
     417
     418        // add meta to comment
     419        add_comment_meta( $post_comment_id, 'bp_activity_comment_id', $comment_id );
     420
     421        // add meta to activity comment
     422        bp_activity_update_meta( $comment_id, 'bp_blogs_post_comment_id', $post_comment_id );
     423
     424        // resave activity comment with WP comment permalink
     425        //
     426        // in bp_blogs_activity_comment_permalink(), we change activity comment
     427        // permalinks to use the post comment link
     428        //
     429        // @todo since this is done after AJAX posting, the activity comment permalink
     430        //       doesn't change on the frontend until the next page refresh.
     431        $resave_activity = new BP_Activity_Activity( $comment_id );
     432        $resave_activity->primary_link = get_comment_link( $post_comment_id );
     433        $resave_activity->save();
     434
     435        // multisite again!
     436        restore_current_blog();
     437
     438        // add the comment hook back
     439        add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
     440
     441        do_action( 'bp_blogs_sync_add_from_activity_comment', $comment_id, $args, $parent_activity, $user );
     442}
     443
     444/**
     445 * Deletes the blog comment when the associated activity comment is deleted.
     446 *
     447 * Note: This is hooked on the 'bp_activity_delete_comment_pre' filter instead
     448 * of the 'bp_activity_delete_comment' action because we need to fetch the
     449 * activity comment children before they are deleted.
     450 *
     451 * @since BuddyPress (2.0.0)
     452 *
     453 * @param bool $retval
     454 * @param int $parent_activity_id The parent activity ID for the activity comment.
     455 * @param int $activity_id The activity ID for the pending deleted activity comment.
     456 */
     457function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_id, $activity_id ) {
     458        // check if parent activity is a blog post
     459        $parent_activity = new BP_Activity_Activity( $parent_activity_id );
     460        if ( 'new_blog_post' != $parent_activity->type ) {
     461                return $retval;
     462        }
     463
     464        // fetch the activity comments for the activity item
     465        $activity = bp_activity_get( array(
     466                'in'               => $activity_id,
     467                'display_comments' => 'stream',
     468        ) );
     469
     470        // get all activity comment IDs for the pending deleted item
     471        $activity_ids   = bp_activity_recurse_comments_activity_ids( $activity );
     472        $activity_ids[] = $activity_id;
     473
     474        // handle multisite
     475        // switch to the blog where the comment was made
     476        switch_to_blog( $parent_activity->item_id );
     477
     478        // remove associated blog comments
     479        bp_blogs_remove_associated_blog_comments( $activity_ids );
     480
     481        // multisite again!
     482        restore_current_blog();
     483
     484        // rebuild activity comment tree
     485        // emulate bp_activity_delete_comment()
     486        BP_Activity_Activity::rebuild_activity_comment_tree( $parent_activity_id );
     487
     488        // we're overriding the default bp_activity_delete_comment() functionality
     489        // so we need to return false
     490        return false;
     491}
     492
     493/**
     494 * Utility function to set up some variables for use in the activity loop.
     495 *
     496 * Grabs the blog's comment depth and the post's open comment status options
     497 * for later use in the activity and activity comment loops.
     498 *
     499 * This is to prevent having to requery these items later on.
     500 *
     501 * @since BuddyPress (2.0.0)
     502 *
     503 * @see bp_blogs_disable_activity_commenting()
     504 * @see bp_blogs_setup_comment_loop_globals_on_ajax()
     505 *
     506 * @param array $r {
     507 *     @type int $blog_id The blog ID to check.
     508 *     @type int $post_id The post ID to check.
     509 *     @type string $type The activity type to check.
     510 * }
     511 */
     512function bp_blogs_setup_activity_loop_globals( $r = array() ) {
     513        if ( empty( $r['blog_id'] ) || empty( $r['post_id'] ) || empty( $r['type'] ) ) {
     514                return;
     515        }
     516
     517        // parent not a blog post? stop now!
     518        if ( 'new_blog_post' !== $r['type'] ) {
     519                return;
     520        }
     521
     522        // BP's 'comments_open' filter trumps all!
     523        // so we have to remove it temporarily
     524        remove_filter( 'comments_open', 'bp_comments_open', 10, 2 );
     525
     526        // handle multisite
     527        switch_to_blog( $r['blog_id'] );
     528
     529        // check if the WP post allows comments
     530        // this also checks if comments should be closed based on age if enabled
     531        $allow_comments = comments_open( $r['post_id'] );
     532
     533        // check the comment thread depth for the blog
     534        $thread_depth = (int) get_option( 'thread_comments' );
     535        if ( ! empty( $thread_depth ) ) {
     536                $thread_depth = get_option( 'thread_comments_depth' );
     537        } else {
     538                $thread_depth = 1;
     539        }
     540
     541        restore_current_blog();
     542
     543        // reinstate BP's comment filter
     544        add_filter( 'comments_open', 'bp_comments_open', 10, 2 );
     545
     546        // initialize a local object so we won't have to query this again in the
     547        // comment loop
     548        if ( empty( buddypress()->blogs->allow_comments ) ) {
     549                buddypress()->blogs->allow_comments = array();
     550        }
     551        if ( empty( buddypress()->blogs->thread_depth ) ) {
     552                buddypress()->blogs->thread_depth   = array();
     553        }
     554
     555        // cache comment settings in the buddypress() singleton to reference later in
     556        // the activity comment loop
     557        // @see bp_blogs_disable_activity_replies()
     558        //
     559        // thread_depth is keyed by activity ID instead of blog ID because when we're
     560        // in a comment loop, we don't have access to the blog ID...
     561        // should probably object cache these values instead...
     562        buddypress()->blogs->allow_comments[bp_get_activity_id()] = $allow_comments;
     563        buddypress()->blogs->thread_depth[bp_get_activity_id()]   = $thread_depth;
     564}
     565
     566/**
     567 * Set up some globals used in the activity comment loop when AJAX is used.
     568 *
     569 * @since BuddyPress (2.0.0)
     570 *
     571 * @see bp_blogs_setup_activity_loop_globals()
     572 */
     573function bp_blogs_setup_comment_loop_globals_on_ajax() {
     574        // not AJAX? stop now!
     575        if ( ! defined( 'DOING_AJAX' ) ) {
     576                return;
     577        }
     578        if ( false === (bool) constant( 'DOING_AJAX' ) ) {
     579                return;
     580        }
     581
     582        // get the parent activity item
     583        $comment         = bp_activity_current_comment();
     584        $parent_activity = new BP_Activity_Activity( $comment->item_id );
     585
     586        // setup the globals
     587        bp_blogs_setup_activity_loop_globals( array(
     588                'blog_id' => $parent_activity->item_id,
     589                'post_id' => $parent_activity->secondary_item_id,
     590                'type'    => $parent_activity->type,
     591        ) );
     592}
     593add_action( 'bp_before_activity_comment', 'bp_blogs_setup_comment_loop_globals_on_ajax' );
     594
     595/**
     596 * Disable activity commenting for blog posts based on certain criteria.
     597 *
     598 * If activity commenting is enabled for blog posts, we still need to disable
     599 * commenting if:
     600 *  - comments are disabled for the WP blog post from the admin dashboard
     601 *  - the WP blog post is supposed to be automatically closed from comments
     602 *    based on a certain age
     603 *  - the activity entry is a 'new_blog_comment' type
     604 *
     605 * @since BuddyPress (2.0.0)
     606 *
     607 * @param bool $retval Is activity commenting enabled for this activity entry?
     608 * @return bool
     609 */
     610function bp_blogs_disable_activity_commenting( $retval ) {
     611        // if activity commenting is disabled, return current value
     612        if ( bp_disable_blogforum_comments() ) {
     613                return $retval;
     614        }
     615
     616        // activity commenting is enabled for blog posts
     617        switch ( bp_get_activity_action_name() ) {
     618
     619                // we still have to disable activity commenting for 'new_blog_comment' items
     620                // commenting should only be done on the parent 'new_blog_post' item
     621                case 'new_blog_comment' :
     622                        $retval = false;
     623
     624                        break;
     625
     626                // check if commenting is disabled for the WP blog post
     627                // we should extrapolate this and automate this for plugins... or not
     628                case 'new_blog_post' :
     629
     630                        // setup some globals we'll need to reference later
     631                        bp_blogs_setup_activity_loop_globals( array(
     632                                'blog_id' => bp_get_activity_item_id(),
     633                                'post_id' => bp_get_activity_secondary_item_id(),
     634                                'type'    => bp_get_activity_action_name(),
     635                        ) );
     636
     637                        // if comments are closed for the WP blog post, we should disable
     638                        // activity comments for this activity entry
     639                        if ( empty( buddypress()->blogs->allow_comments[bp_get_activity_id()] ) ) {
     640                                $retval = false;
     641                        }
     642
     643                        break;
     644        }
     645
     646        return $retval;
     647}
     648add_filter( 'bp_activity_can_comment', 'bp_blogs_disable_activity_commenting' );
     649
     650/**
     651 * Disables replying to activity comments if the corresponding WP blog post no
     652 * longer accepts comments.
     653 *
     654 * This check uses a locally-cached value set in {@link bp_blogs_disable_activity_commenting()}
     655 * via {@link bp_blogs_setup_activity_loop_globals()}.
     656 *
     657 * @since BuddyPress (2.0.0)
     658 *
     659 * @param bool $retval Are replies allowed for this activity reply?
     660 * @param object $comment The activity comment object
     661 * @return bool
     662 */
     663function bp_blogs_disable_activity_replies( $retval, $comment ) {
     664        // check comment depth and disable if depth is too large
     665        if ( isset( buddypress()->blogs->thread_depth[$comment->item_id] ) ){
     666                if ( $comment->mptt_left > buddypress()->blogs->thread_depth[$comment->item_id] ) {
     667                        $retval = false;
     668                }
     669        }
     670
     671        // check if we should disable activity replies based on the parent activity
     672        if ( isset( buddypress()->blogs->allow_comments[$comment->item_id] ) ){
     673                // the blog post has closed off commenting, so we should disable all activity
     674                // comments under the parent 'new_blog_post' activity entry
     675                if ( empty( buddypress()->blogs->allow_comments[$comment->item_id] ) ) {
     676                        $retval = false;
     677                }
     678        }
     679
     680        return $retval;
     681}
     682add_filter( 'bp_activity_can_comment_reply', 'bp_blogs_disable_activity_replies', 10, 2 );
     683
     684/**
     685 * Changes activity comment permalinks to use the blog comment permalink
     686 * instead of the activity permalink.
     687 *
     688 * This is only done if activity commenting is allowed and whether the parent
     689 * activity item is a 'new_blog_post' entry.
     690 *
     691 * @since BuddyPress (2.0.0)
     692 *
     693 * @param string $retval The activity comment permalink
     694 * @return string
     695 */
     696function bp_blogs_activity_comment_permalink( $retval ) {
     697        global $activities_template;
     698
     699        if ( isset( buddypress()->blogs->allow_comments[$activities_template->activity->current_comment->item_id] ) ){
     700                $retval = $activities_template->activity->current_comment->primary_link;
     701        }
     702
     703        return $retval;
     704}
     705add_filter( 'bp_get_activity_comment_permalink', 'bp_blogs_activity_comment_permalink' );
  • bp-blogs/bp-blogs-functions.php

     
    441441                $post_permalink = get_permalink( $recorded_comment->comment_post_ID );
    442442                $comment_link   = get_comment_link( $recorded_comment->comment_ID );
    443443
    444                 // Prepare to record in activity streams
    445                 if ( is_multisite() )
    446                         $activity_action = sprintf( __( '%1$s commented on the post, %2$s, on the site %3$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' );
    447                 else
    448                         $activity_action = sprintf( __( '%1$s commented on the post, %2$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' );
     444                // Setup activity args
     445                $args = array();
     446
     447                $args['user_id']       = $user_id;
     448                $args['content']       = apply_filters_ref_array( 'bp_blogs_activity_new_comment_content', array( $recorded_comment->comment_content, &$recorded_comment, $comment_link ) );
     449                $args['primary_link']  = apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link,     &$recorded_comment ) );
     450                $args['recorded_time'] = $recorded_comment->comment_date_gmt;
     451
     452                if ( is_multisite() ) {
     453                        $args['action'] = sprintf( __( '%1$s commented on the post, %2$s, on the site %3$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' );
     454                } else {
     455                        $args['action'] = sprintf( __( '%1$s commented on the post, %2$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' );
     456                }
     457
     458                // Setup some different activity args depending if activity commenting is
     459                // enabled or not
     460
     461                // if cannot comment, record separate activity entry
     462                // this is the old way of doing things
     463                if ( bp_disable_blogforum_comments() ) {
     464                        $args['type']              = 'new_blog_comment';
     465                        $args['item_id']           = $blog_id;
     466                        $args['secondary_item_id'] = $comment_id;
     467
     468                        // record the activity entry
     469                        bp_blogs_record_activity( $args );
     470
     471                // record comment as BP activity comment under the parent 'new_blog_post'
     472                // activity item
     473                } else {
     474                        // find the parent 'new_blog_post' activity entry
     475                        $parent_activity_id = bp_activity_get_activity_id( array(
     476                                'user_id'           => $user_id,
     477                                'component'         => 'blogs',
     478                                'type'              => 'new_blog_post',
     479                                'item_id'           => $blog_id,
     480                                'secondary_item_id' => $recorded_comment->comment_post_ID
     481                        ) );
     482
     483                        // we found the parent activity entry
     484                        // so let's go ahead and reconfigure some activity args
     485                        if ( ! empty( $parent_activity_id ) ) {
     486                                // set the 'item_id' with the parent activity entry ID
     487                                $args['item_id'] = $parent_activity_id;
     488
     489                                // now see if the WP parent comment has a BP activity ID
     490                                $comment_parent = 0;
     491                                if ( ! empty( $recorded_comment->comment_parent ) ) {
     492                                        $comment_parent = get_comment_meta( $recorded_comment->comment_parent, 'bp_activity_comment_id', true );
     493                                }
    449494
    450                 $activity_content       = $recorded_comment->comment_content;
     495                                // WP parent comment does not have a BP activity ID
     496                                // so set to 'new_blog_post' activity ID
     497                                if ( empty( $comment_parent ) ) {
     498                                        $comment_parent = $parent_activity_id;
     499                                }
    451500
    452                 // Record in activity streams
    453                 bp_blogs_record_activity( array(
    454                         'user_id'           => $user_id,
    455                         'content'           => apply_filters_ref_array( 'bp_blogs_activity_new_comment_content',      array( $activity_content, &$recorded_comment, $comment_link ) ),
    456                         'primary_link'      => apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link,     &$recorded_comment                ) ),
    457                         'type'              => 'new_blog_comment',
    458                         'item_id'           => $blog_id,
    459                         'secondary_item_id' => $comment_id,
    460                         'recorded_time'     => $recorded_comment->comment_date_gmt
    461                 ) );
     501                                $args['secondary_item_id'] = $comment_parent;
     502                                $args['component']         = 'activity';
     503                                $args['type']              = 'activity_comment';
     504
     505                        // could not find corresponding parent activity entry
     506                        // so wipe out $args array
     507                        } else {
     508                                $args = array();
     509                        }
     510
     511                        // Record in activity streams
     512                        if ( ! empty( $args ) ) {
     513                                // @todo should we use bp_activity_new_comment()? that function will also send
     514                                // an email to people in the activity comment thread
     515                                //
     516                                // what if a site already has some comment email notification plugin setup?
     517                                // this is why I decided to go with bp_activity_add() to avoid any conflict
     518                                // with existing comment email notification plugins
     519                                $comment_activity_id = bp_activity_add( $args );
     520
     521                                // add meta to activity comment
     522                                bp_activity_update_meta( $comment_activity_id, 'bp_blogs_post_comment_id', $comment_id );
     523
     524                                // add meta to comment
     525                                add_comment_meta( $comment_id, 'bp_activity_comment_id', $comment_activity_id );
     526                        }
     527                }
    462528
    463529                // Update the blogs last active date
    464530                bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
     
    632698function bp_blogs_remove_comment( $comment_id ) {
    633699        global $wpdb;
    634700
    635         // Delete activity stream item
    636         bp_blogs_delete_activity( array( 'item_id' => $wpdb->blogid, 'secondary_item_id' => $comment_id, 'type' => 'new_blog_comment' ) );
     701        // activity comments are disabled for blog posts
     702        // which means that individual activity items exist for blog comments
     703        if ( bp_disable_blogforum_comments() ) {
     704                // Delete the individual activity stream item
     705                bp_blogs_delete_activity( array(
     706                        'item_id'           => $wpdb->blogid,
     707                        'secondary_item_id' => $comment_id,
     708                        'type'              => 'new_blog_comment'
     709                ) );
     710
     711        // activity comments are enabled for blog posts
     712        // remove the associated activity item
     713        } else {
     714                // get associated activity ID from comment meta
     715                $activity_id = get_comment_meta( $comment_id, 'bp_activity_comment_id', true );
     716
     717                // delete the associated activity comment
     718                //
     719                // also removes child post comments and associated activity comments
     720                if ( ! empty( $activity_id ) && bp_is_active( 'activity' ) ) {
     721                        // fetch the activity comments for the activity item
     722                        $activity = bp_activity_get( array(
     723                                'in'               => $activity_id,
     724                                'display_comments' => 'stream',
     725                        ) );
     726               
     727                        // get all activity comment IDs for the pending deleted item
     728                        if ( ! empty( $activity['activities'] ) ) {
     729                                $activity_ids   = bp_activity_recurse_comments_activity_ids( $activity );
     730                                $activity_ids[] = $activity_id;
     731
     732                                // delete activity items
     733                                foreach ( $activity_ids as $activity_id ) {
     734                                        bp_activity_delete( array(
     735                                                'id' => $activity_id
     736                                        ) );
     737                                }
     738
     739                                // remove associated blog comments
     740                                bp_blogs_remove_associated_blog_comments( $activity_ids );
     741
     742                                // rebuild activity comment tree
     743                                BP_Activity_Activity::rebuild_activity_comment_tree( $activity['activities'][0]->item_id );
     744                        }
     745                }
     746        }
    637747
    638748        do_action( 'bp_blogs_remove_comment', $wpdb->blogid, $comment_id, bp_loggedin_user_id() );
    639749}
    640750add_action( 'delete_comment', 'bp_blogs_remove_comment' );
    641751
    642752/**
     753 * Removes blog comments that are associated with activity comments.
     754 *
     755 * @since BuddyPress (2.0.0)
     756 *
     757 * @see bp_blogs_remove_comment()
     758 * @see bp_blogs_sync_delete_from_activity_comment()
     759 *
     760 * @param array $activity_ids The activity IDs to check association with blog
     761 *              comments.
     762 */
     763function bp_blogs_remove_associated_blog_comments( $activity_ids = array() ) {
     764        // query args
     765        $query_args = array(
     766                'meta_query' => array(
     767                        array(
     768                                'key'     => 'bp_activity_comment_id',
     769                                'value'   => implode( ',', (array) $activity_ids ),
     770                                'compare' => 'IN',
     771                        )
     772                )
     773        );
     774
     775        // get comment
     776        $comment_query = new WP_Comment_Query;
     777        $comments = $comment_query->query( $query_args );
     778
     779        // found the corresponding comments
     780        // let's delete them!
     781        foreach ( $comments as $comment ) {
     782                // we force delete the comment, since activity items are deleted immediately
     783                wp_delete_comment( $comment->comment_ID, true );
     784        }
     785}
     786
     787/**
    643788 * When a blog comment status transition occurs, update the relevant activity's status.
    644789 *
    645790 * @since BuddyPress (1.6.0)
  • bp-blogs/bp-blogs-loader.php

     
    7373
    7474                // Setup the globals
    7575                parent::setup_globals( $args );
     76
     77                // Activity comment post callback
     78                $this->activity_comment_post_callback = apply_filters( 'bp_blogs_activity_comment_post_callback', array(
     79                        'add'    => 'bp_blogs_sync_add_from_activity_comment',
     80                        'delete' => 'bp_blogs_sync_delete_from_activity_comment'
     81                ) );
    7682        }
    7783
    7884        /**
  • bp-core/bp-core-component.php

     
    8585        public $notification_callback = '';
    8686
    8787        /**
     88         * Callback to do something whenever an activity comment is saved or deleted.
     89         *
     90         * @since BuddyPress (2.0.0)
     91         *
     92         * @var array
     93         */
     94        public $activity_comment_post_callback = '';
     95
     96        /**
    8897         * WordPress Toolbar links.
    8998         *
    9099         * @var array $admin_menu
     
    336345        public function setup_actions() {
    337346
    338347                // Setup globals
    339                 add_action( 'bp_setup_globals',          array( $this, 'setup_globals'          ), 10 );
     348                add_action( 'bp_setup_globals',          array( $this, 'setup_globals'          ),         10 );
    340349
    341350                // Include required files. Called early to ensure that BP core
    342351                // components are loaded before plugins that hook their loader functions
    343352                // to bp_include with the default priority of 10. This is for backwards
    344353                // compatibility; henceforth, plugins should register themselves by
    345354                // extending this base class.
    346                 add_action( 'bp_include',                array( $this, 'includes'               ), 8 );
     355                add_action( 'bp_include',                array( $this, 'includes'               ),         8 );
    347356
    348357                // Setup navigation
    349                 add_action( 'bp_setup_nav',              array( $this, 'setup_nav'              ), 10 );
     358                add_action( 'bp_setup_nav',              array( $this, 'setup_nav'              ),         10 );
    350359
    351360                // Setup WP Toolbar menus
    352                 add_action( 'bp_setup_admin_bar',        array( $this, 'setup_admin_bar'        ), $this->adminbar_myaccount_order );
     361                add_action( 'bp_setup_admin_bar',        array( $this, 'setup_admin_bar'        ),         $this->adminbar_myaccount_order );
    353362
    354363                // Setup component title
    355                 add_action( 'bp_setup_title',            array( $this, 'setup_title'            ), 10 );
     364                add_action( 'bp_setup_title',            array( $this, 'setup_title'            ),         10 );
    356365
    357366                // Register post types
    358                 add_action( 'bp_register_post_types',    array( $this, 'register_post_types'    ), 10 );
     367                add_action( 'bp_register_post_types',    array( $this, 'register_post_types'    ),         10 );
    359368
    360369                // Register taxonomies
    361                 add_action( 'bp_register_taxonomies',    array( $this, 'register_taxonomies'    ), 10 );
     370                add_action( 'bp_register_taxonomies',    array( $this, 'register_taxonomies'    ),         10 );
    362371
    363372                // Add the rewrite tags
    364                 add_action( 'bp_add_rewrite_tags',       array( $this, 'add_rewrite_tags'       ), 10 );
     373                add_action( 'bp_add_rewrite_tags',       array( $this, 'add_rewrite_tags'       ),         10 );
    365374
    366375                // Add the rewrite rules
    367                 add_action( 'bp_add_rewrite_rules',      array( $this, 'add_rewrite_rules'      ), 10 );
     376                add_action( 'bp_add_rewrite_rules',      array( $this, 'add_rewrite_rules'      ),         10 );
    368377
    369378                // Add the permalink structure
    370                 add_action( 'bp_add_permastructs',       array( $this, 'add_permastructs'       ), 10 );
     379                add_action( 'bp_add_permastructs',       array( $this, 'add_permastructs'       ),         10 );
    371380
    372381                // Allow components to parse the main query
    373                 add_action( 'bp_parse_query',            array( $this, 'parse_query'            ), 10 );
     382                add_action( 'bp_parse_query',            array( $this, 'parse_query'            ),         10 );
    374383
    375384                // Generate rewrite rules
    376                 add_action( 'bp_generate_rewrite_rules', array( $this, 'generate_rewrite_rules' ), 10 );
     385                add_action( 'bp_generate_rewrite_rules', array( $this, 'generate_rewrite_rules' ),         10 );
     386
     387                // Activity comment callback setup
     388                add_action( 'bp_setup_globals',          array( $this, 'activity_comment_post_callback' ), 10 );
    377389
    378390                // Additional actions can be attached here
    379391                do_action( 'bp_' . $this->id . '_setup_actions' );
     
    602614        public function generate_rewrite_rules() {
    603615                do_action( 'bp_' . $this->id . '_generate_rewrite_rules' );
    604616        }
     617
     618        /**
     619         * Setup activity comment post callback.
     620         *
     621         * If a component has the 'activity_comment_post_callback' property set,
     622         * automatically setup the hooks to be used.
     623         *
     624         * @since BuddyPress (2.0.0
     625         */
     626        public function activity_comment_post_callback() {
     627                // if activity component is not active or callback is not an array, stop now!
     628                if ( ! bp_is_active( 'activity' ) || ! is_array( $this->activity_comment_post_callback ) ) {
     629                        return;
     630                }
     631
     632                $callback = $this->activity_comment_post_callback;
     633
     634                // Activity comment addition callback
     635                if ( ! empty( $callback['add'] ) && is_callable( $callback['add'] ) ) {
     636                        add_action( 'bp_activity_comment_posted', $callback['add'],    10, 3 );
     637                }
     638
     639                // Activity comment deletion callback
     640                if ( ! empty( $callback['delete'] ) && is_callable( $callback['delete'] ) ) {
     641                        add_filter( 'bp_activity_delete_comment_pre', $callback['delete'], 10, 3 );
     642                }
     643
     644        }
    605645}
    606646endif; // BP_Component
  • bp-core/bp-core-options.php

     
    226226 * @return mixed The value for the option.
    227227 */
    228228function bp_get_option( $option_name, $default = '' ) {
    229         $value = get_blog_option( bp_get_root_blog_id(), $option_name, $default );
     229        // check buddypress()->site_options array first
     230        if ( isset( buddypress()->site_options[$option_name] ) ) {
     231                $value = buddypress()->site_options[$option_name];
     232
     233        // query for the option if not available
     234        } else {
     235                $value = get_blog_option( bp_get_root_blog_id(), $option_name, $default );
     236        }
    230237
    231238        return apply_filters( 'bp_get_option', $value );
    232239}