Ticket #6482: 6482.01.patch
File 6482.01.patch, 78.0 KB (added by , 9 years ago) |
---|
-
src/bp-activity/bp-activity-actions.php
diff --git src/bp-activity/bp-activity-actions.php src/bp-activity/bp-activity-actions.php index 2b8b244..15f4a64 100644
function bp_activity_catch_transition_post_type_status( $new_status, $old_status 833 833 } 834 834 } 835 835 add_action( 'transition_post_status', 'bp_activity_catch_transition_post_type_status', 10, 3 ); 836 837 /** 838 * When a blog comment status transition occurs, update the relevant activity's status. 839 * 840 * @since BuddyPress (2.4.0) 841 * 842 * @param string $new_status New comment status. 843 * @param string $old_status Previous comment status. 844 * @param object $comment Comment data. 845 */ 846 function bp_activity_transition_post_type_comment_status( $new_status, $old_status, $comment ) { 847 $post_type = get_post_type( $comment->comment_post_ID ); 848 if ( ! $post_type ) { 849 return; 850 } 851 852 // Get the post type tracking args. 853 $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type ); 854 855 // Bail if the activity action does not exist 856 if ( empty( $activity_post_object->comments_tracking->action_id ) ) { 857 return false; 858 859 // Set the $activity_comment_object 860 } else { 861 $activity_comment_object = $activity_post_object->comments_tracking; 862 } 863 864 /** 865 * Activity currently doesn't have any concept of a trash, or an unapproved/approved state. 866 * 867 * If a blog comment transitions to a "delete" or "hold" status, delete the activity item. 868 * If a blog comment transitions to trashed, or spammed, mark the activity as spam. 869 * If a blog comment transitions to approved (and the activity exists), mark the activity as ham. 870 * If a blog comment transitions to unapproved (and the activity exists), mark the activity as spam. 871 * Otherwise, record the comment into the activity stream. 872 */ 873 874 // This clause handles delete/hold. 875 if ( in_array( $new_status, array( 'delete', 'hold' ) ) ) { 876 return bp_activity_post_type_remove_comment( $comment->comment_ID, $activity_post_object ); 877 878 // These clauses handle trash, spam, and un-spams. 879 } elseif ( in_array( $new_status, array( 'trash', 'spam', 'unapproved' ) ) ) { 880 $action = 'spam_activity'; 881 } elseif ( 'approved' == $new_status ) { 882 $action = 'ham_activity'; 883 } 884 885 // Get the activity 886 if ( bp_disable_blogforum_comments() ) { 887 $activity_id = bp_activity_get_activity_id( array( 888 'component' => $activity_comment_object->component_id, 889 'item_id' => get_current_blog_id(), 890 'secondary_item_id' => $comment->comment_ID, 891 'type' => $activity_comment_object->action_id, 892 ) ); 893 } else { 894 $activity_id = get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true ); 895 } 896 897 // Check activity item exists 898 if ( empty( $activity_id ) ) { 899 // If no activity exists, but the comment has been approved, record it into the activity table. 900 if ( 'approved' == $new_status ) { 901 return bp_activity_post_type_comment( $comment->comment_ID, true, $activity_post_object ); 902 } 903 904 return; 905 } 906 907 // Create an activity object 908 $activity = new BP_Activity_Activity( $activity_id ); 909 if ( empty( $activity->component ) ) { 910 return; 911 } 912 913 // Spam/ham the activity if it's not already in that state 914 if ( 'spam_activity' === $action && ! $activity->is_spam ) { 915 bp_activity_mark_as_spam( $activity ); 916 } elseif ( 'ham_activity' == $action) { 917 bp_activity_mark_as_ham( $activity ); 918 } 919 920 // Add "new_post_type_comment" to the whitelisted activity types, so that the activity's Akismet history is generated 921 $post_type_comment_action = $activity_comment_object->action_id; 922 $comment_akismet_history = create_function( '$t', '$t[] = $post_type_comment_action; return $t;' ); 923 add_filter( 'bp_akismet_get_activity_types', $comment_akismet_history ); 924 925 // Save the updated activity 926 $activity->save(); 927 928 // Remove the "new_blog_comment" activity type whitelist so we don't break anything 929 remove_filter( 'bp_akismet_get_activity_types', $comment_akismet_history ); 930 } 931 add_action( 'transition_comment_status', 'bp_activity_transition_post_type_comment_status', 10, 3 ); -
src/bp-activity/bp-activity-functions.php
diff --git src/bp-activity/bp-activity-functions.php src/bp-activity/bp-activity-functions.php index 57e42e7..5ab301f 100644
function bp_activity_set_post_type_tracking_args( $post_type = '', $args = array 425 425 return false; 426 426 } 427 427 428 $activity_labels = array( 429 /* Post labels */ 430 'bp_activity_admin_filter', 431 'bp_activity_front_filter', 432 'bp_activity_new_post', 433 'bp_activity_new_post_ms', 434 /* Comment labels */ 435 'bp_activity_comments_admin_filter', 436 'bp_activity_comments_front_filter', 437 'bp_activity_new_comment', 438 'bp_activity_new_comment_ms' 439 ); 440 428 441 // Labels are loaded into the post type object. 429 foreach ( array( 'bp_activity_admin_filter', 'bp_activity_front_filter', 'bp_activity_new_post', 'bp_activity_new_post_ms' )as $label_type ) {442 foreach ( $activity_labels as $label_type ) { 430 443 if ( ! empty( $args[ $label_type ] ) ) { 431 444 $wp_post_types[ $post_type ]->labels->{$label_type} = $args[ $label_type ]; 432 445 unset( $args[ $post_type ] ); … … function bp_activity_get_post_type_tracking_args( $post_type ) { 453 466 return false; 454 467 } 455 468 456 $post_type_object = get_post_type_object( $post_type ); 469 $post_type_object = get_post_type_object( $post_type ); 470 $post_type_support_comments = post_type_supports( $post_type, 'comments' ); 457 471 458 472 $post_type_activity = array( 459 'component_id' => buddypress()->activity->id, 460 'action_id' => 'new_' . $post_type, 461 'format_callback' => 'bp_activity_format_activity_action_custom_post_type_post', 462 'front_filter' => $post_type_object->labels->name, 463 'contexts' => array( 'activity' ), 464 'position' => 0, 465 'singular' => strtolower( $post_type_object->labels->singular_name ), 466 'activity_comment' => ! post_type_supports( $post_type, 'comments' ), 473 'component_id' => buddypress()->activity->id, 474 'action_id' => 'new_' . $post_type, 475 'format_callback' => 'bp_activity_format_activity_action_custom_post_type_post', 476 'front_filter' => $post_type_object->labels->name, 477 'contexts' => array( 'activity' ), 478 'position' => 0, 479 'singular' => strtolower( $post_type_object->labels->singular_name ), 480 'activity_comment' => ! $post_type_support_comments, 481 'comment_action_id' => false, 482 'comment_format_callback' => 'bp_activity_format_activity_action_custom_post_type_comment', 467 483 ); 468 484 469 485 if ( ! empty( $post_type_object->bp_activity ) ) { … … function bp_activity_get_post_type_tracking_args( $post_type ) { 496 512 $post_type_activity->new_post_type_action_ms = $post_type_object->labels->bp_activity_new_post_ms; 497 513 } 498 514 515 // If the post type supports comments and has a comment action id, build the comments tracking args 516 if ( $post_type_support_comments && ! empty( $post_type_activity->comment_action_id ) ) { 517 // Init a new container for the activity action for comments 518 $post_type_activity->comments_tracking = new stdClass(); 519 520 // Build the activity action for comments 521 $post_type_activity->comments_tracking->component_id = $post_type_activity->component_id; 522 $post_type_activity->comments_tracking->action_id = $post_type_activity->comment_action_id; 523 524 // Try to get the comments admin filter from the post type labels. 525 if ( ! empty( $post_type_object->labels->bp_activity_comments_admin_filter ) ) { 526 $post_type_activity->comments_tracking->admin_filter = $post_type_object->labels->bp_activity_comments_admin_filter; 527 528 // Fall back to a generic name. 529 } else { 530 $post_type_activity->comments_tracking->admin_filter = _x( 'New item comment posted', 'Post Type generic comments activity admin filter', 'buddypress' ); 531 } 532 533 $post_type_activity->comments_tracking->format_callback = $post_type_activity->comment_format_callback; 534 535 // Check for the comments front filter in the post type labels. 536 if ( ! empty( $post_type_object->labels->bp_activity_comments_front_filter ) ) { 537 $post_type_activity->comments_tracking->front_filter = $post_type_object->labels->bp_activity_comments_front_filter; 538 539 // Fall back to a generic name. 540 } else { 541 $post_type_activity->comments_tracking->front_filter = sprintf( __( '%s comments', 'buddypress' ), $post_type_object->labels->singular_name ); 542 } 543 544 $post_type_activity->comments_tracking->contexts = $post_type_activity->contexts; 545 $post_type_activity->comments_tracking->position = (int) $post_type_activity->position + 1; 546 547 // Try to get the action for new post type comment action on non-multisite installations. 548 if ( ! empty( $post_type_object->labels->bp_activity_new_comment ) ) { 549 $post_type_activity->comments_tracking->new_post_type_comment_action = $post_type_object->labels->bp_activity_new_comment; 550 } 551 552 // Try to get the action for new post type comment action on multisite installations. 553 if ( ! empty( $post_type_object->labels->bp_activity_new_comment_ms ) ) { 554 $post_type_activity->comments_tracking->new_post_type_comment_action_ms = $post_type_object->labels->bp_activity_new_comment_ms; 555 } 556 } 557 499 558 /** 500 559 * Filters tracking arguments for a specific post type. 501 560 * … … function bp_activity_get_post_types_tracking_args() { 524 583 $track_post_type = bp_activity_get_post_type_tracking_args( $post_type ); 525 584 526 585 if ( ! empty( $track_post_type ) ) { 586 // Set the post type comments tracking args 587 if ( ! empty( $track_post_type->comments_tracking->action_id ) ) { 588 // Used to check support for comment tracking by activity action (new_post_type_comment) 589 $track_post_type->comments_tracking->comments_tracking = true; 590 591 $post_types_tracking_args[ $track_post_type->comments_tracking->action_id ] = $track_post_type->comments_tracking; 592 593 // Used to check support for comment tracking by activity action (new_post_type) 594 $track_post_type->comments_tracking = true; 595 } 596 527 597 $post_types_tracking_args[ $track_post_type->action_id ] = $track_post_type; 528 598 } 529 599 … … function bp_activity_get_post_types_tracking_args() { 541 611 } 542 612 543 613 /** 614 * Helper function to check if the activity action is about a "parent" post type activity 615 * supporting comments tracking 616 * 617 * @since BuddyPress (2.4.0) 618 * 619 * @param string $action_id the activity action to check 620 * @return bool true if it's a parent post type activity supporting comments 621 * false otherwise 622 */ 623 function bp_activity_action_is_post_tracking_action( $action_id ) { 624 if ( empty( $action_id ) ) { 625 return false; 626 } 627 628 $bp = buddypress(); 629 630 $retval = bp_activity_action_supports_comments_tracking( $action_id ); 631 632 if ( empty( $retval ) ) { 633 return $retval; 634 } 635 636 return ! empty( $bp->activity->track[ $action_id ]->comment_action_id ); 637 } 638 639 /** 640 * Helper function to check if the activity action is supporting comments tracking 641 * 642 * @since BuddyPress (2.4.0) 643 * 644 * @param string $action_id the activity action to check 645 * @return bool true activity action supports comments tracking 646 * false otherwise 647 */ 648 function bp_activity_action_supports_comments_tracking( $action_id ) { 649 if ( empty( $action_id ) ) { 650 return false; 651 } 652 653 $bp = buddypress(); 654 655 // Set the activity track global if not set yet 656 if ( empty( $bp->activity->track ) ) { 657 $bp->activity->track = bp_activity_get_post_types_tracking_args(); 658 } 659 660 return ! empty( $bp->activity->track[ $action_id ]->comments_tracking ); 661 } 662 663 /** 664 * Helper function to get the parent action out of a post type comment action 665 * 666 * eg: new_blog_comment > new_blog_post 667 * 668 * @since BuddyPress (2.4.0) 669 * 670 * @param string $action_id the activity action to check 671 * @return array|object $parent_action the parent action post type tracking args 672 * empty array if not found 673 */ 674 function bp_activity_get_parent_post_type_action( $comment_action_id ) { 675 if ( empty( $comment_action_id ) ) { 676 return false; 677 } 678 679 $bp = buddypress(); 680 681 // Set the activity track global if not set yet 682 if ( empty( $bp->activity->track ) ) { 683 $bp->activity->track = bp_activity_get_post_types_tracking_args(); 684 } 685 686 $parent_action = wp_list_filter( $bp->activity->track, array( 'comment_action_id' => $comment_action_id ) ); 687 688 return reset( $parent_action ); 689 } 690 691 /** 544 692 * Get all components' activity actions, sorted by their position attribute. 545 693 * 546 694 * @since BuddyPress (2.2.0) … … function bp_activity_format_activity_action_custom_post_type_post( $action, $act 1418 1566 return apply_filters( 'bp_activity_custom_post_type_post_action', $action, $activity ); 1419 1567 } 1420 1568 1569 /** 1570 * Format activity action strings for custom post types comments. 1571 * 1572 * @since BuddyPress (2.4.0) 1573 * 1574 * @param string $action Static activity action. 1575 * @param object $activity Activity data object. 1576 * 1577 * @return string 1578 */ 1579 function bp_activity_format_activity_action_custom_post_type_comment( $action, $activity ) { 1580 $bp = buddypress(); 1581 1582 // Fetch all the tracked post types once. 1583 if ( empty( $bp->activity->track ) ) { 1584 $bp->activity->track = bp_activity_get_post_types_tracking_args(); 1585 } 1586 1587 if ( empty( $activity->type ) || empty( $bp->activity->track[ $activity->type ] ) ) { 1588 return $action; 1589 } 1590 1591 $user_link = bp_core_get_userlink( $activity->user_id ); 1592 1593 if ( is_multisite() ) { 1594 $blog_link = '<a href="' . esc_url( get_home_url( $activity->item_id ) ) . '">' . get_blog_option( $activity->item_id, 'blogname' ) . '</a>'; 1595 1596 if ( ! empty( $bp->activity->track[ $activity->type ]->new_post_type_comment_action_ms ) ) { 1597 $action = sprintf( $bp->activity->track[ $activity->type ]->new_post_type_comment_action_ms, $user_link, $activity->primary_link, $blog_link ); 1598 } else { 1599 $action = sprintf( _x( '%1$s commented on the <a href="%2$s">item</a>, on the site %3$s', 'Activity Custom Post Type comment action', 'buddypress' ), $user_link, $activity->primary_link, $blog_link ); 1600 } 1601 } else { 1602 if ( ! empty( $bp->activity->track[ $activity->type ]->new_post_type_comment_action ) ) { 1603 $action = sprintf( $bp->activity->track[ $activity->type ]->new_post_type_comment_action, $user_link, $activity->primary_link ); 1604 } else { 1605 $action = sprintf( _x( '%1$s commented on the <a href="%2$s">item</a>', 'Activity Custom Post Type post comment action', 'buddypress' ), $user_link, $activity->primary_link ); 1606 } 1607 } 1608 1609 /** 1610 * Filters the formatted custom post type activity comment action string. 1611 * 1612 * @since BuddyPress (2.4.0) 1613 * 1614 * @param string $action Activity action string value. 1615 * @param BP_Activity_Activity $activity Activity item object. 1616 */ 1617 return apply_filters( 'bp_activity_custom_post_type_comment_action', $action, $activity ); 1618 } 1619 1421 1620 /****************************************************************************** 1422 1621 * Business functions are where all the magic happens in BuddyPress. They will 1423 1622 * handle the actual saving or manipulation of information. Usually they will … … function bp_activity_post_type_update( $post = null ) { 2006 2205 * 2007 2206 * @since BuddyPress (2.2.0) 2008 2207 * 2009 * @param WP_Post $post Post object. 2010 * @param BP_Activity_Activity $activity Activity object. 2208 * @param WP_Post $post Post object. 2209 * @param BP_Activity_Activity $activity Activity object. 2210 * @param object $activity_post_object the post type tracking args object 2011 2211 */ 2012 do_action( 'bp_activity_post_type_updated', $post, $activity );2212 do_action( 'bp_activity_post_type_updated', $post, $activity, $activity_post_object ); 2013 2213 2014 2214 return $updated; 2015 2215 } … … function bp_activity_post_type_unpublish( $post_id = 0, $post = null ) { 2066 2266 } 2067 2267 2068 2268 /** 2269 * Create an activity item for a newly posted post type comment. 2270 * 2271 * @since BuddyPress (2.4.0) 2272 * 2273 * @param int $comment_id ID of the comment. 2274 * @param bool $is_approved Whether the comment is approved or not. 2275 * @param object $activity_post_object the post type tracking args object. 2276 * 2277 * @return int|bool The ID of the activity on success. False on error. 2278 */ 2279 function bp_activity_post_type_comment( $comment_id = 0, $is_approved = true, $activity_post_object = null ) { 2280 // Get the users comment 2281 $post_type_comment = get_comment( $comment_id ); 2282 2283 // Don't record activity if the comment hasn't been approved 2284 if ( empty( $is_approved ) ) { 2285 return false; 2286 } 2287 2288 // Don't record activity if no email address has been included 2289 if ( empty( $post_type_comment->comment_author_email ) ) { 2290 return false; 2291 } 2292 2293 // Don't record activity if the comment has already been marked as spam 2294 if ( 'spam' === $is_approved ) { 2295 return false; 2296 } 2297 2298 // Get the user by the comment author email. 2299 $user = get_user_by( 'email', $post_type_comment->comment_author_email ); 2300 2301 // If user isn't registered, don't record activity 2302 if ( empty( $user ) ) { 2303 return false; 2304 } 2305 2306 // Get the user_id 2307 $user_id = (int) $user->ID; 2308 2309 // Get blog and post data 2310 $blog_id = get_current_blog_id(); 2311 2312 // Get the post 2313 $post_type_comment->post = get_post( $post_type_comment->comment_post_ID ); 2314 2315 if ( ! is_a( $post_type_comment->post, 'WP_Post' ) ) { 2316 return false; 2317 } 2318 2319 /** 2320 * Filters whether to publish activities about the comment regarding the post status 2321 * 2322 * @since BuddyPress (2.4.0) 2323 * 2324 * @param bool true to bail, false otherwise. 2325 */ 2326 $is_post_status_not_allowed = (bool) apply_filters( 'bp_activity_post_type_is_post_status_allowed', 'publish' !== $post_type_comment->post->post_status || ! empty( $post_type_comment->post->post_password ) ); 2327 2328 // If this is a password protected post, or not a public post don't record the comment 2329 if ( $is_post_status_not_allowed ) { 2330 return false; 2331 } 2332 2333 // Set post type 2334 $post_type = $post_type_comment->post->post_type; 2335 2336 if ( empty( $activity_post_object ) ) { 2337 // Get the post type tracking args. 2338 $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type ); 2339 2340 // Bail if the activity action does not exist 2341 if ( empty( $activity_post_object->comments_tracking->action_id ) ) { 2342 return false; 2343 } 2344 } 2345 2346 // Set the $activity_comment_object 2347 $activity_comment_object = $activity_post_object->comments_tracking; 2348 2349 /** 2350 * Filters whether or not to post the activity about the comment. 2351 * 2352 * This is a variable filter, dependent on the post type, 2353 * that lets components or plugins bail early if needed. 2354 * 2355 * @since BuddyPress (2.4.0) 2356 * 2357 * @param bool $value Whether or not to continue. 2358 * @param int $blog_id ID of the current site. 2359 * @param int $post_id ID of the current post being commented. 2360 * @param int $user_id ID of the current user. 2361 * @param int $comment_id ID of the current comment being posted. 2362 */ 2363 if ( false === apply_filters( "bp_activity_{$post_type}_pre_comment", true, $blog_id, $post_type_comment->post->ID, $user_id, $comment_id ) ) { 2364 return false; 2365 } 2366 2367 // Is this an update ? 2368 $activity_id = bp_activity_get_activity_id( array( 2369 'user_id' => $user_id, 2370 'component' => $activity_comment_object->component_id, 2371 'type' => $activity_comment_object->action_id, 2372 'item_id' => $blog_id, 2373 'secondary_item_id' => $comment_id, 2374 ) ); 2375 2376 // Record this in activity streams. 2377 $comment_link = get_comment_link( $post_type_comment->comment_ID ); 2378 2379 // Backward compatibility filters for the 'blogs' component. 2380 if ( 'blogs' == $activity_comment_object->component_id ) { 2381 $activity_content = apply_filters_ref_array( 'bp_blogs_activity_new_comment_content', array( $post_type_comment->comment_content, &$post_type_comment, $comment_link ) ); 2382 $activity_primary_link = apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link, &$post_type_comment ) ); 2383 } else { 2384 $activity_content = $post_type_comment->comment_content; 2385 $activity_primary_link = $comment_link; 2386 } 2387 2388 $activity_args = array( 2389 'id' => $activity_id, 2390 'user_id' => $user_id, 2391 'content' => $activity_content, 2392 'primary_link' => $activity_primary_link, 2393 'component' => $activity_comment_object->component_id, 2394 'recorded_time' => $post_type_comment->comment_date_gmt, 2395 ); 2396 2397 if ( bp_disable_blogforum_comments() ) { 2398 $blog_url = get_home_url( $blog_id ); 2399 $post_url = add_query_arg( 2400 'p', 2401 $post_type_comment->post->ID, 2402 trailingslashit( $blog_url ) 2403 ); 2404 2405 $activity_args['type'] = $activity_comment_object->action_id; 2406 $activity_args['item_id'] = $blog_id; 2407 $activity_args['secondary_item_id'] = $post_type_comment->comment_ID; 2408 2409 if ( ! empty( $activity_args['content'] ) ) { 2410 // Create the excerpt. 2411 $activity_summary = bp_activity_create_summary( $activity_args['content'], $activity_args ); 2412 2413 // Backward compatibility filter for blog comments. 2414 if ( 'blogs' == $activity_post_object->component_id ) { 2415 $activity_args['content'] = apply_filters( 'bp_blogs_record_activity_content', $activity_summary, $activity_args['content'], $activity_args, $post_type ); 2416 } else { 2417 $activity_args['content'] = $activity_summary; 2418 } 2419 } 2420 2421 // Set up the action by using the format functions. 2422 $action_args = array_merge( $activity_args, array( 2423 'post_title' => $post_type_comment->post->post_title, 2424 'post_url' => $post_url, 2425 'blog_url' => $blog_url, 2426 'blog_name' => get_blog_option( $blog_id, 'blogname' ), 2427 ) ); 2428 2429 $activity_args['action'] = call_user_func_array( $activity_comment_object->format_callback, array( '', (object) $action_args ) ); 2430 2431 // Make sure the action is set. 2432 if ( empty( $activity_args['action'] ) ) { 2433 return; 2434 } else { 2435 // Backward compatibility filter for the blogs component. 2436 if ( 'blogs' === $activity_post_object->component_id ) { 2437 $activity_args['action'] = apply_filters( 'bp_blogs_record_activity_action', $activity_args['action'] ); 2438 } 2439 } 2440 2441 $activity_id = bp_activity_add( $activity_args ); 2442 } 2443 2444 /** 2445 * Fires after the publishing of an activity item for a newly published post type post. 2446 * 2447 * @since BuddyPress (2.4.0) 2448 * 2449 * @param int $activity_id ID of the newly published activity item. 2450 * @param WP_Comment $post_type_comment Comment object. 2451 * @param array $activity_args Array of activity arguments. 2452 * @param object $activity_post_object the post type tracking args object. 2453 */ 2454 do_action_ref_array( 'bp_activity_post_type_comment', array( &$activity_id, $post_type_comment, $activity_args, $activity_post_object ) ); 2455 2456 return $activity_id; 2457 } 2458 add_action( 'comment_post', 'bp_activity_post_type_comment', 10, 2 ); 2459 add_action( 'edit_comment', 'bp_activity_post_type_comment', 10 ); 2460 2461 /** 2462 * Remove an activity item when a comment about a post type is deleted. 2463 * 2464 * @since BuddyPress (2.4.0) 2465 * 2466 * @param int $comment_id ID of the comment. 2467 * @param object $activity_post_object the post type tracking args object. 2468 * 2469 * @return bool True on success. False on error. 2470 */ 2471 function bp_activity_post_type_remove_comment( $comment_id = 0, $activity_post_object = null ) { 2472 if ( empty( $activity_post_object ) ) { 2473 $comment = get_comment( $comment_id ); 2474 if ( ! $comment ) { 2475 return; 2476 } 2477 2478 $post_type = get_post_type( $comment->comment_post_ID ); 2479 if ( ! $post_type ) { 2480 return; 2481 } 2482 2483 // Get the post type tracking args. 2484 $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type ); 2485 2486 // Bail if the activity action does not exist 2487 if ( empty( $activity_post_object->comments_tracking->action_id ) ) { 2488 return false; 2489 } 2490 } 2491 2492 // Set the $activity_comment_object 2493 $activity_comment_object = $activity_post_object->comments_tracking; 2494 2495 $deleted = false; 2496 2497 if ( bp_disable_blogforum_comments() ) { 2498 $deleted = bp_activity_delete_by_item_id( array( 2499 'item_id' => get_current_blog_id(), 2500 'secondary_item_id' => $comment_id, 2501 'component' => $activity_comment_object->component_id, 2502 'type' => $activity_comment_object->action_id, 2503 'user_id' => false, 2504 ) ); 2505 } 2506 2507 /** 2508 * Fires after the unpublishing for the custom post type. 2509 * 2510 * @since BuddyPress (2.4.0) 2511 * 2512 * @param bool $deleted true if the activity was deleted false otherwise 2513 * @param WP_Comment $comment Comment object. 2514 * @param object $activity_post_object the post type tracking args object. 2515 */ 2516 do_action( 'bp_activity_post_type_remove_comment', $deleted, $comment_id, $activity_post_object ); 2517 2518 return $deleted; 2519 } 2520 add_action( 'delete_comment', 'bp_activity_post_type_remove_comment', 10, 1 ); 2521 2522 /** 2069 2523 * Add an activity comment. 2070 2524 * 2071 2525 * @since BuddyPress (1.2.0) … … function bp_activity_post_type_unpublish( $post_id = 0, $post = null ) { 2078 2532 * @uses do_action() To call the 'bp_activity_comment_posted' hook. 2079 2533 * 2080 2534 * @param array|string $args { 2081 * @type int $id Optional. Pass an ID to update an existing comment. 2082 * @type string $content The content of the comment. 2083 * @type int $user_id Optional. The ID of the user making the comment. 2084 * Defaults to the ID of the logged-in user. 2085 * @type int $activity_id The ID of the "root" activity item, ie the oldest 2086 * ancestor of the comment. 2087 * @type int $parent_id Optional. The ID of the parent activity item, ie the item to 2088 * which the comment is an immediate reply. If not provided, 2089 * this value defaults to the $activity_id. 2535 * @type int $id Optional. Pass an ID to update an existing comment. 2536 * @type string $content The content of the comment. 2537 * @type int $user_id Optional. The ID of the user making the comment. 2538 * Defaults to the ID of the logged-in user. 2539 * @type int $activity_id The ID of the "root" activity item, ie the oldest 2540 * ancestor of the comment. 2541 * @type int $parent_id Optional. The ID of the parent activity item, ie the item to 2542 * which the comment is an immediate reply. If not provided, 2543 * this value defaults to the $activity_id. 2544 * @type bool $skip_notification Optional. false to send a comment notification, false otherwise 2545 * Defaults to false 2090 2546 * } 2091 2547 * @return int|bool The ID of the comment on success, otherwise false. 2092 2548 */ … … function bp_activity_new_comment( $args = '' ) { 2100 2556 } 2101 2557 2102 2558 $r = wp_parse_args( $args, array( 2103 'id' => false, 2104 'content' => false, 2105 'user_id' => bp_loggedin_user_id(), 2106 'activity_id' => false, // ID of the root activity item 2107 'parent_id' => false // ID of a parent comment (optional) 2559 'id' => false, 2560 'content' => false, 2561 'user_id' => bp_loggedin_user_id(), 2562 'activity_id' => false, // ID of the root activity item 2563 'parent_id' => false, // ID of a parent comment (optional), 2564 'skip_notification' => false, 2108 2565 ) ); 2109 2566 2110 2567 // Bail if missing necessary data … … function bp_activity_new_comment( $args = '' ) { 2169 2626 } 2170 2627 wp_cache_delete( $activity_id, 'bp_activity' ); 2171 2628 2172 /** 2173 * Fires near the end of an activity comment posting, before the returning of the comment ID. 2174 * 2175 * @since BuddyPress (1.2.0) 2176 * 2177 * @param int $comment_id ID of the newly posted activity comment. 2178 * @param array $r Array of parsed comment arguments. 2179 * @param int $activity ID of the activity item being commented on. 2180 */ 2181 do_action( 'bp_activity_comment_posted', $comment_id, $r, $activity ); 2629 if ( empty( $r[ 'skip_notification' ] ) ) { 2630 /** 2631 * Fires near the end of an activity comment posting, before the returning of the comment ID. 2632 * Sends a notification to the user @see bp_activity_new_comment_notification_helper() 2633 * 2634 * @since BuddyPress (1.2.0) 2635 * 2636 * @param int $comment_id ID of the newly posted activity comment. 2637 * @param array $r Array of parsed comment arguments. 2638 * @param int $activity ID of the activity item being commented on. 2639 */ 2640 do_action( 'bp_activity_comment_posted', $comment_id, $r, $activity ); 2641 } else { 2642 /** 2643 * Fires near the end of an activity comment posting, before the returning of the comment ID. 2644 * without sending a notification to the user 2645 * 2646 * @since BuddyPress (2.4.0) 2647 * 2648 * @param int $comment_id ID of the newly posted activity comment. 2649 * @param array $r Array of parsed comment arguments. 2650 * @param int $activity ID of the activity item being commented on. 2651 */ 2652 do_action( 'bp_activity_comment_posted_notification_skipped', $comment_id, $r, $activity ); 2653 } 2182 2654 2183 2655 if ( empty( $comment_id ) ) { 2184 2656 $errors->add( 'comment_failed', $feedback ); … … function bp_activity_delete( $args = '' ) { 2451 2923 * @return bool True on success, false on failure. 2452 2924 */ 2453 2925 function bp_activity_delete_comment( $activity_id, $comment_id ) { 2926 $deleted = false; 2454 2927 2455 2928 /** 2456 2929 * Filters whether BuddyPress should delete an activity comment or not. … … function bp_activity_delete_comment( $activity_id, $comment_id ) { 2464 2937 * @param int $activity_id ID of the root activity item being deleted. 2465 2938 * @param int $comment_id ID of the comment being deleted. 2466 2939 */ 2467 if ( ! apply_filters ( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id) ) {2468 return false;2940 if ( ! apply_filters_ref_array( 'bp_activity_delete_comment_pre', array( true, $activity_id, $comment_id, &$deleted ) ) ) { 2941 return $deleted; 2469 2942 } 2470 2943 2471 2944 // Delete any children of this comment. … … function bp_activity_delete_comment( $activity_id, $comment_id ) { 2474 2947 // Delete the actual comment 2475 2948 if ( ! bp_activity_delete( array( 'id' => $comment_id, 'type' => 'activity_comment' ) ) ) { 2476 2949 return false; 2950 } else { 2951 $deleted = true; 2477 2952 } 2478 2953 2479 2954 // Purge comment cache for the root activity update … … function bp_activity_delete_comment( $activity_id, $comment_id ) { 2492 2967 */ 2493 2968 do_action( 'bp_activity_delete_comment', $activity_id, $comment_id ); 2494 2969 2495 return true;2970 return $deleted; 2496 2971 } 2497 2972 2498 2973 /** -
src/bp-blogs/bp-blogs-activity.php
diff --git src/bp-blogs/bp-blogs-activity.php src/bp-blogs/bp-blogs-activity.php index c29e56b..c2b8354 100644
function bp_blogs_register_activity_actions() { 37 37 ); 38 38 } 39 39 40 // Only add the comment type if the 'post' post type is trackable41 if ( post_type_supports( 'post', 'buddypress-activity' ) ) {42 bp_activity_set_action(43 $bp->blogs->id,44 'new_blog_comment',45 __( 'New post comment posted', 'buddypress' ),46 'bp_blogs_format_activity_action_new_blog_comment',47 __( 'Comments', 'buddypress' ),48 array( 'activity', 'member' ),49 1050 );51 }52 53 40 /** 54 41 * Fires after the registry of the default blog component activity actions. 55 42 * … … function bp_blogs_format_activity_action_new_blog_post( $action, $activity ) { 215 202 * @param obj $activity Activity data object. 216 203 */ 217 204 function bp_blogs_format_activity_action_new_blog_comment( $action, $activity ) { 218 $blog_url = bp_blogs_get_blogmeta( $activity->item_id, 'url' ); 219 $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' ); 205 /** 206 * When the comment is published we are faking an activity object 207 * to which we add 4 properties : 208 * - the post url 209 * - the post title 210 * - the blog url 211 * - the blog name 212 * This is done to build the 'post link' part of the activity 213 * action string. 214 * NB: in this case the activity has not yet been created. 215 */ 216 217 $blog_url = false; 218 219 // Try to get the blog url from the activity object 220 if ( isset( $activity->blog_url ) ) { 221 $blog_url = $activity->blog_url; 222 } else { 223 $blog_url = bp_blogs_get_blogmeta( $activity->item_id, 'url' ); 224 } 225 226 $blog_name = false; 227 228 // Try to get the blog name from the activity object 229 if ( isset( $activity->blog_name ) ) { 230 $blog_name = $activity->blog_name; 231 } else { 232 $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' ); 233 } 220 234 221 235 if ( empty( $blog_url ) || empty( $blog_name ) ) { 222 236 $blog_url = get_home_url( $activity->item_id ); … … function bp_blogs_format_activity_action_new_blog_comment( $action, $activity ) 226 240 bp_blogs_update_blogmeta( $activity->item_id, 'name', $blog_name ); 227 241 } 228 242 229 $post_url = bp_activity_get_meta( $activity->id, 'post_url' ); 230 $post_title = bp_activity_get_meta( $activity->id, 'post_title' ); 243 $post_url = false; 244 245 // Try to get the post url from the activity object 246 if ( isset( $activity->post_url ) ) { 247 $post_url = $activity->post_url; 248 249 /** 250 * The post_url property is not set, we need to build the url 251 * thanks to the post id which is also saved as the secondary 252 * item id property of the activity object. 253 */ 254 } elseif ( ! empty( $activity->id ) ) { 255 $post_url = bp_activity_get_meta( $activity->id, 'post_url' ); 256 } 257 258 $post_title = false; 259 260 // Should be the case when the comment has just been published 261 if ( isset( $activity->post_title ) ) { 262 $post_title = $activity->post_title; 263 264 // If activity already exists try to get the post title from activity meta 265 } elseif ( ! empty( $activity->id ) ) { 266 $post_title = bp_activity_get_meta( $activity->id, 'post_title' ); 267 } 231 268 232 269 // Should only be empty at the time of post creation 233 270 if ( empty( $post_url ) || empty( $post_title ) ) { … … function bp_blogs_comments_open( $activity ) { 518 555 * 519 556 * Note: This is only a one-way sync - activity comments -> blog comment. 520 557 * 521 * For blog post -> activity comment, see {@link bp_ blogs_record_comment()}.558 * For blog post -> activity comment, see {@link bp_activity_post_type_comment()}. 522 559 * 523 560 * @since BuddyPress (2.0.0) 524 561 * … … function bp_blogs_comments_open( $activity ) { 527 564 * @param object Parameters of the parent activity item (in this case, the blog post). 528 565 */ 529 566 function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_activity ) { 530 // if parent activity isn't a blog post, stop now!531 if ( $parent_activity->type != 'new_blog_post') {567 // if parent activity isn't a post type having the buddypress-activity support, stop now! 568 if ( ! bp_activity_action_supports_comments_tracking( $parent_activity->type ) ) { 532 569 return; 533 570 } 534 571 … … function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_ 561 598 'comment_type' => '', // could be interesting to add 'buddypress' here... 562 599 'comment_parent' => (int) $comment_parent, 563 600 'user_id' => $params['user_id'], 564 565 // commenting these out for now566 //'comment_author_IP' => '127.0.0.1',567 //'comment_agent' => '',568 569 601 'comment_approved' => 1 570 602 ); 571 603 572 604 // prevent separate activity entry being made 573 remove_action( 'comment_post', 'bp_ blogs_record_comment', 10, 2 );605 remove_action( 'comment_post', 'bp_activity_post_type_comment', 10, 2 ); 574 606 575 607 // handle multisite 576 608 switch_to_blog( $parent_activity->item_id ); … … function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_ 587 619 588 620 // add meta to activity comment 589 621 bp_activity_update_meta( $comment_id, 'bp_blogs_post_comment_id', $post_comment_id ); 622 bp_activity_update_meta( $comment_id, 'bp_parent_action', $parent_activity->type ); 590 623 591 624 // resave activity comment with WP comment permalink 592 625 // … … function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_ 603 636 restore_current_blog(); 604 637 605 638 // add the comment hook back 606 add_action( 'comment_post', 'bp_ blogs_record_comment', 10, 2 );639 add_action( 'comment_post', 'bp_activity_post_type_comment', 10, 2 ); 607 640 608 641 /** 609 642 * Fires after activity comments have been synced and posted as blog comments. … … add_action( 'bp_activity_comment_posted', 'bp_blogs_sync_add_from_activity_comme 629 662 * @since BuddyPress (2.0.0) 630 663 * 631 664 * @param bool $retval 632 * @param int $parent_activity_id The parent activity ID for the activity comment. 633 * @param int $activity_id The activity ID for the pending deleted activity comment. 665 * @param int $parent_activity_id The parent activity ID for the activity comment. 666 * @param int $activity_id The activity ID for the pending deleted activity comment. 667 * @param bool $deleted whether the comment was deleted or not 634 668 */ 635 function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_id, $activity_id ) {669 function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_id, $activity_id, &$deleted ) { 636 670 // check if parent activity is a blog post 637 671 $parent_activity = new BP_Activity_Activity( $parent_activity_id ); 638 if ( 'new_blog_post' != $parent_activity->type ) { 672 673 // if parent activity isn't a post type having the buddypress-activity support, stop now! 674 if ( ! bp_activity_action_supports_comments_tracking( $parent_activity->type ) ) { 639 675 return $retval; 640 676 } 641 677 … … function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_i 643 679 $activity = bp_activity_get( array( 644 680 'in' => $activity_id, 645 681 'display_comments' => 'stream', 682 'spam' => 'all', 646 683 ) ); 647 684 648 685 // get all activity comment IDs for the pending deleted item … … function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_i 663 700 // emulate bp_activity_delete_comment() 664 701 BP_Activity_Activity::rebuild_activity_comment_tree( $parent_activity_id ); 665 702 703 // Avoid the error message although the comments were successfully deleted 704 $deleted = true; 705 666 706 // we're overriding the default bp_activity_delete_comment() functionality 667 707 // so we need to return false 668 708 return false; 669 709 } 670 add_filter( 'bp_activity_delete_comment_pre', 'bp_blogs_sync_delete_from_activity_comment', 10, 3);710 add_filter( 'bp_activity_delete_comment_pre', 'bp_blogs_sync_delete_from_activity_comment', 10, 4 ); 671 711 672 712 /** 673 713 * Updates the blog comment when the associated activity comment is edited. … … function bp_blogs_sync_activity_edit_to_post_comment( BP_Activity_Activity $acti 701 741 // fetch parent activity item 702 742 $parent_activity = new BP_Activity_Activity( $activity->item_id ); 703 743 704 // sanity check705 if ( 'new_blog_post' !== $parent_activity->type) {744 // if parent activity isn't a post type having the buddypress-activity support for comments, stop now! 745 if ( ! bp_activity_action_supports_comments_tracking( $parent_activity->type ) ) { 706 746 return; 707 747 } 708 748 … … add_action( 'trashed_post_comments', 'bp_blogs_remove_activity_meta_for_trashed_ 766 806 * @return array $args 767 807 */ 768 808 function bp_blogs_new_blog_comment_query_backpat( $args ) { 769 // Bail if this is not a 'new_blog_comment' query 770 if ( 'new_blog_comment' !== $args['action'] ) { 809 global $wpdb; 810 $bp = buddypress(); 811 812 // if activity comments are disabled for blog posts, stop now! 813 if ( bp_disable_blogforum_comments() ) { 771 814 return $args; 772 815 } 773 816 774 // display_comments=stream is required to show new-style 775 // 'activity_comment' items inline 776 $args['display_comments'] = 'stream'; 817 // Get the parent action 818 $parent_action = bp_activity_get_parent_post_type_action( $args['action'] ); 777 819 778 // For the remaining clauses, we filter the SQL query directly 779 add_filter( 'bp_activity_paged_activities_sql', '_bp_blogs_new_blog_comment_query_backpat_filter' ); 780 add_filter( 'bp_activity_total_activities_sql', '_bp_blogs_new_blog_comment_query_backpat_filter' ); 820 // Bail if this is not a 'new_blog_comment' query 821 if ( empty( $parent_action ) ) { 822 return $args; 823 } 781 824 782 // Return the original arguments 783 return $args; 784 } 785 add_filter( 'bp_after_has_activities_parse_args', 'bp_blogs_new_blog_comment_query_backpat' ); 825 // Build the filter_query 826 $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT activity_id FROM {$bp->activity->table_name_meta} WHERE meta_key = 'bp_parent_action' AND meta_value = %s", $parent_action->action_id ) ); 827 828 // Init the filter query 829 $filter_query = array(); 830 831 if ( 'null' === $args['scope'] ) { 832 $args['scope'] = ''; 833 } elseif ( 'just-me' === $args['scope'] ) { 834 $filter_query = array( 835 'relation' => 'AND', 836 array( 837 'column' => 'user_id', 838 'value' => bp_displayed_user_id(), 839 ), 840 ); 841 $args['scope'] = ''; 842 } 786 843 787 /** 788 * Filter activity SQL to include new- and old-style 'new_blog_comment' activity items. 789 * 790 * @since BuddyPress (2.1.0) 791 * 792 * @access private 793 * @see bp_blogs_new_blog_comment_query_backpat() 794 * 795 * @param string $query SQL query as assembled in BP_Activity_Activity::get(). 796 * @return string $query Modified SQL query. 797 */ 798 function _bp_blogs_new_blog_comment_query_backpat_filter( $query ) { 799 $bp = buddypress(); 844 $filter_query[] = array( 845 'relation' => 'OR', 846 array( 847 'column' => 'type', 848 'value' => $args['action'], 849 ), 850 array( 851 'column' => 'id', 852 'value' => $activity_ids, 853 'compare' => 'IN' 854 ), 855 ); 800 856 801 // The query passed to the filter is for old-style 'new_blog_comment' 802 // items. We include new-style 'activity_comment' items by running a 803 // subquery inside of a large OR clause. 804 $activity_comment_subquery = "SELECT a.id FROM {$bp->activity->table_name} a INNER JOIN {$bp->activity->table_name_meta} am ON (a.id = am.activity_id) WHERE am.meta_key = 'bp_blogs_post_comment_id' AND a.type = 'activity_comment'"; 857 // Set the filter_query arg 858 $args['filter_query'] = $filter_query; 805 859 806 // WHERE ( [original WHERE clauses] OR a.id IN (activity_comment subquery) )807 $ query = preg_replace( '|WHERE (.*?) ORDER|', 'WHERE ( ( $1 ) OR ( a.id IN ( ' . $activity_comment_subquery . ' ) ) ) ORDER', $query );860 // Display 'activity_comment' items inline, but make sure to avoid duplicate content. 861 $args['display_comments'] = 'stream'; 808 862 809 // Don't run this on future queries 810 remove_filter( current_filter(), '_bp_blogs_new_blog_comment_query_backpat_filter' ); 863 // reset the action 864 $args['action'] = ''; 865 $args['type'] = ''; 811 866 812 return $query; 867 // Return the original arguments 868 return $args; 813 869 } 870 add_filter( 'bp_after_has_activities_parse_args', 'bp_blogs_new_blog_comment_query_backpat' ); 814 871 815 872 /** 816 873 * Utility function to set up some variables for use in the activity loop. … … function bp_blogs_setup_activity_loop_globals( $activity ) { 832 889 return; 833 890 } 834 891 835 // parent not a blog post? stop now!836 if ( 'new_blog_post' !== $activity->type) {892 // parent not a post post type action ? stop now! 893 if ( ! bp_activity_action_is_post_tracking_action( $activity->type ) ) { 837 894 return; 838 895 } 839 896 … … function bp_blogs_disable_activity_commenting( $retval ) { 915 972 return $retval; 916 973 } 917 974 918 // activity commenting is enabled for blog posts 919 switch ( bp_get_activity_action_name() ) { 920 921 // we still have to disable activity commenting for 'new_blog_comment' items 922 // commenting should only be done on the parent 'new_blog_post' item 923 case 'new_blog_comment' : 924 $retval = false; 975 $action = bp_get_activity_action_name(); 925 976 926 break; 927 928 // check if commenting is disabled for the WP blog post 929 // we should extrapolate this and automate this for plugins... or not 930 case 'new_blog_post' : 977 // It's a post type action supporting comment tracking 978 if ( bp_activity_action_supports_comments_tracking( $action ) ) { 979 // it's a "post" action 980 if ( bp_activity_action_is_post_tracking_action( $action ) ) { 931 981 global $activities_template; 932 982 933 983 // setup some globals we'll need to reference later 934 984 bp_blogs_setup_activity_loop_globals( $activities_template->activity ); 935 985 936 // if comments are closed for the WP blog post , we should disable986 // if comments are closed for the WP blog post type, we should disable 937 987 // activity comments for this activity entry 938 988 if ( empty( buddypress()->blogs->allow_comments[bp_get_activity_id()] ) ) { 939 989 $retval = false; 940 990 } 941 942 break; 991 // It's a "comment" action 992 } else { 993 $retval = false; 994 } 943 995 } 944 996 945 997 return $retval; … … function bp_blogs_activity_comment_single_action( $retval, $activity ) { 1057 1109 return $retval; 1058 1110 } 1059 1111 1112 $bp = buddypress(); 1060 1113 $blog_comment_id = bp_activity_get_meta( $activity->id, 'bp_blogs_post_comment_id' ); 1061 1114 1062 1115 if ( ! empty( $blog_comment_id ) ) { … … function bp_blogs_activity_comment_single_action( $retval, $activity ) { 1072 1125 // override 'secondary_item_id' to use comment ID 1073 1126 $object->secondary_item_id = $blog_comment_id; 1074 1127 1075 // now format the activity action using the 'new_blog_comment' action callback 1076 $retval = bp_blogs_format_activity_action_new_blog_comment( '', $object ); 1128 // Set the activity track global if not set yet 1129 if ( empty( $bp->activity->track ) ) { 1130 $bp->activity->track = bp_activity_get_post_types_tracking_args(); 1131 } 1132 1133 // Use the fallback of the action 1134 if ( ! empty( $bp->activity->track[ $parent_blog_post_activity->type ]->comment_action_id ) ) { 1135 $object->type = $bp->activity->track[ $parent_blog_post_activity->type ]->comment_action_id; 1136 1137 // now format the activity action using the 'new_blog_comment' action callback 1138 $retval = call_user_func_array( $bp->activity->track[ $object->type ]->format_callback, array( '', $object ) ); 1139 } 1077 1140 } 1078 1141 1079 1142 return $retval; -
src/bp-blogs/bp-blogs-filters.php
diff --git src/bp-blogs/bp-blogs-filters.php src/bp-blogs/bp-blogs-filters.php index 2b96a34..f841cdb 100644
function bp_blogs_comments_clauses_select_by_id( $retval ) { 62 62 } 63 63 64 64 /** 65 * Check whether the current post can be published.65 * Check whether the current activity about a post or a comment can be published. 66 66 * 67 67 * Abstracted from the deprecated `bp_blogs_record_post()`. 68 68 * … … function bp_blogs_post_pre_publish( $return = true, $blog_id = 0, $post_id = 0, 122 122 return $return; 123 123 } 124 124 add_filter( 'bp_activity_post_pre_publish', 'bp_blogs_post_pre_publish', 10, 4 ); 125 add_filter( 'bp_activity_post_pre_comment', 'bp_blogs_post_pre_publish', 10, 4 ); -
src/bp-blogs/bp-blogs-functions.php
diff --git src/bp-blogs/bp-blogs-functions.php src/bp-blogs/bp-blogs-functions.php index c45590a..7f765e2 100644
add_action( 'bp_activity_post_type_published', 'bp_blogs_publish_post_activity_m 467 467 * 468 468 * @since BuddyPress (2.2.0) 469 469 * 470 * @param WP_Post $post Post object. 471 * @param BP_Activity_Activity $activity Activity object. 470 * @param WP_Post $post Post object. 471 * @param BP_Activity_Activity $activity Activity object. 472 * @param object $activity_post_object the post type tracking args object 472 473 */ 473 function bp_blogs_update_post_activity_meta( $post, $activity ) {474 if ( empty( $activity->id ) || 'post' != $post->post_type) {474 function bp_blogs_update_post_activity_meta( $post, $activity, $activity_post_object ) { 475 if ( empty( $activity->id ) || empty( $activity_post_object->action_id ) ) { 475 476 return; 476 477 } 477 478 … … function bp_blogs_update_post_activity_meta( $post, $activity ) { 480 481 if ( $post->post_title !== $existing_title ) { 481 482 bp_activity_update_meta( $activity->id, 'post_title', $post->post_title ); 482 483 483 // Now update activity meta for post comments... sigh. 484 add_filter( 'comments_clauses', 'bp_blogs_comments_clauses_select_by_id' ); 485 $comments = get_comments( array( 'post_id' => $post->ID ) ); 486 remove_filter( 'comments_clauses', 'bp_blogs_comments_clauses_select_by_id' ); 487 488 if ( ! empty( $comments ) ) { 489 $activity_ids = array(); 490 $comment_ids = wp_list_pluck( $comments, 'comment_ID' ); 491 492 // Set up activity args. 493 $args = array( 494 'update_meta_cache' => false, 495 'show_hidden' => true, 496 'per_page' => 99999, 497 ); 498 499 // Query for old-style "new_blog_comment" activity items. 500 $args['filter'] = array( 501 'object' => buddypress()->blogs->id, 502 'action' => 'new_blog_comment', 503 'secondary_id' => implode( ',', $comment_ids ), 504 ); 505 506 $activities = bp_activity_get( $args ); 507 if ( ! empty( $activities['activities'] ) ) { 508 $activity_ids = (array) wp_list_pluck( $activities['activities'], 'id' ); 509 } 510 511 // Query for activity comments connected to a blog post. 512 unset( $args['filter'] ); 513 $args['meta_query'] = array( array( 514 'key' => 'bp_blogs_post_comment_id', 515 'value' => $comment_ids, 516 'compare' => 'IN', 517 ) ); 518 $args['type'] = 'activity_comment'; 519 $args['display_comments'] = 'stream'; 484 if ( ! empty( $activity_post_object->comments_tracking->action_id ) ) { 485 // Now update activity meta for post comments... sigh. 486 add_filter( 'comments_clauses', 'bp_blogs_comments_clauses_select_by_id' ); 487 $comments = get_comments( array( 'post_id' => $post->ID ) ); 488 remove_filter( 'comments_clauses', 'bp_blogs_comments_clauses_select_by_id' ); 489 490 if ( ! empty( $comments ) ) { 491 $activity_ids = array(); 492 $comment_ids = wp_list_pluck( $comments, 'comment_ID' ); 493 494 // Set up activity args. 495 $args = array( 496 'update_meta_cache' => false, 497 'show_hidden' => true, 498 'per_page' => 99999, 499 ); 500 501 // Query for old-style "new_blog_comment" activity items. 502 $args['filter'] = array( 503 'object' => $activity_post_object->comments_tracking->component_id, 504 'action' => $activity_post_object->comments_tracking->action_id, 505 'secondary_id' => implode( ',', $comment_ids ), 506 ); 507 508 $activities = bp_activity_get( $args ); 509 if ( ! empty( $activities['activities'] ) ) { 510 $activity_ids = (array) wp_list_pluck( $activities['activities'], 'id' ); 511 } 520 512 521 $activities = bp_activity_get( $args ); 522 if ( ! empty( $activities['activities'] ) ) { 523 $activity_ids = array_merge( $activity_ids, (array) wp_list_pluck( $activities['activities'], 'id' ) ); 524 } 513 // Query for activity comments connected to a blog post. 514 unset( $args['filter'] ); 515 $args['meta_query'] = array( array( 516 'key' => 'bp_blogs_post_comment_id', 517 'value' => $comment_ids, 518 'compare' => 'IN', 519 ) ); 520 $args['type'] = 'activity_comment'; 521 $args['display_comments'] = 'stream'; 522 523 $activities = bp_activity_get( $args ); 524 if ( ! empty( $activities['activities'] ) ) { 525 $activity_ids = array_merge( $activity_ids, (array) wp_list_pluck( $activities['activities'], 'id' ) ); 526 } 525 527 526 // Update activity meta for all found activity items. 527 if ( ! empty( $activity_ids ) ) { 528 foreach ( $activity_ids as $aid ) { 529 bp_activity_update_meta( $aid, 'post_title', $post->post_title ); 528 // Update activity meta for all found activity items. 529 if ( ! empty( $activity_ids ) ) { 530 foreach ( $activity_ids as $aid ) { 531 bp_activity_update_meta( $aid, 'post_title', $post->post_title ); 532 } 530 533 } 531 }532 534 533 unset( $activities, $activity_ids, $comment_ids, $comments ); 535 unset( $activities, $activity_ids, $comment_ids, $comments ); 536 } 534 537 } 535 538 } 536 539 … … function bp_blogs_update_post_activity_meta( $post, $activity ) { 541 544 bp_activity_delete_meta( $activity->id, 'post_comment_status' ); 542 545 } 543 546 } 544 add_action( 'bp_activity_post_type_updated', 'bp_blogs_update_post_activity_meta', 10, 2);547 add_action( 'bp_activity_post_type_updated', 'bp_blogs_update_post_activity_meta', 10, 3 ); 545 548 546 549 /** 547 * Record a new blog comment in the BuddyPress activity stream.550 * Update Activity and blogs meta and eventually sync comment with activity comment 548 551 * 549 * Only posts the item if blog is public and post is not password-protected.552 * @since BuddyPress (2.4.0) 550 553 * 551 * @param int $comment_id ID of the comment being recorded. 552 * @param bool|string $is_approved Optional. The $is_approved value passed to 553 * the 'comment_post' action. Default: true. 554 * @return bool|object Returns false on failure, the comment object on success. 554 * @param int|bool $activity_id ID of recorded activity, or false if sync is active. 555 * @param WP_Comment $comment the comment object 556 * @param array $activity_args Array of activity arguments. 557 * @param object $activity_post_object the post type tracking args object. 558 * @return int|bool Returns false if no activity, the activity id otherwise. 555 559 */ 556 function bp_blogs_record_comment( $comment_id, $is_approved = true ) { 557 // bail if activity component is not active 558 if ( ! bp_is_active( 'activity' ) ) { 559 return; 560 } 561 562 // Get the users comment 563 $recorded_comment = get_comment( $comment_id ); 564 565 // Don't record activity if the comment hasn't been approved 566 if ( empty( $is_approved ) ) 567 return false; 568 569 // Don't record activity if no email address has been included 570 if ( empty( $recorded_comment->comment_author_email ) ) 571 return false; 572 573 // Don't record activity if the comment has already been marked as spam 574 if ( 'spam' === $is_approved ) 575 return false; 576 577 // Get the user by the comment author email. 578 $user = get_user_by( 'email', $recorded_comment->comment_author_email ); 579 580 // If user isn't registered, don't record activity 581 if ( empty( $user ) ) 560 function bp_blogs_comment_sync_activity_comment( &$activity_id, $comment = null, $activity_args = array(), $activity_post_object = null ) { 561 if ( empty( $activity_args ) || empty( $comment->post->ID ) || empty( $activity_post_object->comment_action_id ) ) { 582 562 return false; 563 } 583 564 584 // Get the user_id 585 $user_id = (int) $user->ID; 586 587 // Get blog and post data 565 // Set the current blog id. 588 566 $blog_id = get_current_blog_id(); 589 567 590 // If blog is not trackable, do not record the activity. 591 if ( ! bp_blogs_is_blog_trackable( $blog_id, $user_id ) ) 592 return false; 593 594 $recorded_comment->post = get_post( $recorded_comment->comment_post_ID ); 595 596 if ( empty( $recorded_comment->post ) || is_wp_error( $recorded_comment->post ) ) 597 return false; 598 599 // If this is a password protected post, don't record the comment 600 if ( !empty( $recorded_comment->post->post_password ) ) 601 return false; 602 603 // Don't record activity if the comment's associated post isn't a WordPress Post 604 if ( !in_array( $recorded_comment->post->post_type, apply_filters( 'bp_blogs_record_comment_post_types', array( 'post' ) ) ) ) 605 return false; 606 607 $is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) ); 608 609 // If blog is public allow activity to be posted 610 if ( $is_blog_public ) { 611 612 // Get activity related links 613 $post_permalink = get_permalink( $recorded_comment->comment_post_ID ); 614 $comment_link = get_comment_link( $recorded_comment->comment_ID ); 615 616 // Setup activity args 617 $args = array(); 618 619 $args['user_id'] = $user_id; 620 $args['content'] = apply_filters_ref_array( 'bp_blogs_activity_new_comment_content', array( $recorded_comment->comment_content, &$recorded_comment, $comment_link ) ); 621 $args['primary_link'] = apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link, &$recorded_comment ) ); 622 $args['recorded_time'] = $recorded_comment->comment_date_gmt; 623 624 // Setup some different activity args depending if activity commenting is 625 // enabled or not 626 627 // if cannot comment, record separate activity entry 628 // this is the old way of doing things 629 if ( bp_disable_blogforum_comments() ) { 630 $args['type'] = 'new_blog_comment'; 631 $args['item_id'] = $blog_id; 632 $args['secondary_item_id'] = $comment_id; 633 634 // record the activity entry 635 $activity_id = bp_blogs_record_activity( $args ); 568 // These activity metadatas are used to build the new_blog_comment action string 569 if ( ! empty( $activity_id ) && ! empty( $activity_args['item_id'] ) && 'new_blog_comment' === $activity_post_object->comment_action_id ) { 570 // add some post info in activity meta 571 bp_activity_update_meta( $activity_id, 'post_title', $comment->post->post_title ); 572 bp_activity_update_meta( $activity_id, 'post_url', esc_url_raw( add_query_arg( 'p', $comment->post->ID, home_url( '/' ) ) ) ); 573 } 636 574 637 // add some post info in activity meta 638 bp_activity_update_meta( $activity_id, 'post_title', $recorded_comment->post->post_title ); 639 bp_activity_update_meta( $activity_id, 'post_url', add_query_arg( 'p', $recorded_comment->post->ID, home_url( '/' ) ) ); 575 // Sync comment - activity comment 576 if ( ! bp_disable_blogforum_comments() ) { 640 577 641 // record comment as BP activity comment under the parent 'new_blog_post' 642 // activity item 643 } else { 644 // this is a comment edit 645 // check to see if corresponding activity entry already exists 646 if ( ! empty( $_REQUEST['action'] ) ) { 647 $existing_activity_id = get_comment_meta( $comment_id, 'bp_activity_comment_id', true ); 578 if ( ! empty( $_REQUEST['action'] ) ) { 579 $existing_activity_id = get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true ); 648 580 649 if ( ! empty( $existing_activity_id ) ) { 650 $args['id'] = $existing_activity_id; 651 } 581 if ( ! empty( $existing_activity_id ) ) { 582 $activity_args['id'] = $existing_activity_id; 652 583 } 584 } 653 585 654 // find the parent 'new_blog_post' activity entry 586 if ( empty( $activity_post_object ) ) { 587 $activity_post_object = bp_activity_get_post_type_tracking_args( $comment->post->post_type ); 588 } 589 590 if ( isset( $activity_post_object->action_id ) && isset( $activity_post_object->component_id ) ) { 591 // find the parent 'new_post_type' activity entry 655 592 $parent_activity_id = bp_activity_get_activity_id( array( 656 'component' => 'blogs',657 'type' => 'new_blog_post',593 'component' => $activity_post_object->component_id, 594 'type' => $activity_post_object->action_id, 658 595 'item_id' => $blog_id, 659 'secondary_item_id' => $ recorded_comment->comment_post_ID596 'secondary_item_id' => $comment->comment_post_ID 660 597 ) ); 598 } 661 599 662 663 664 665 // set the 'item_id' withthe parent activity entry ID666 $args['item_id'] = $parent_activity_id;600 // we found the parent activity entry 601 // so let's go ahead and reconfigure some activity args 602 if ( ! empty( $parent_activity_id ) ) { 603 // set the parent activity entry ID 604 $activity_args['activity_id'] = $parent_activity_id; 667 605 668 669 670 if ( ! empty( $recorded_comment->comment_parent ) ) {671 $comment_parent = get_comment_meta( $recorded_comment->comment_parent, 'bp_activity_comment_id', true );672 606 // now see if the WP parent comment has a BP activity ID 607 $comment_parent = 0; 608 if ( ! empty( $comment->comment_parent ) ) { 609 $comment_parent = get_comment_meta( $comment->comment_parent, 'bp_activity_comment_id', true ); 610 } 673 611 674 675 // so set to 'new_blog_post'activity ID676 677 678 612 // WP parent comment does not have a BP activity ID 613 // so set to 'new_' . post_type activity ID 614 if ( empty( $comment_parent ) ) { 615 $comment_parent = $parent_activity_id; 616 } 679 617 680 $args['secondary_item_id'] = $comment_parent; 681 $args['component'] = 'activity'; 682 $args['type'] = 'activity_comment'; 618 $activity_args['parent_id'] = $comment_parent; 619 $activity_args['skip_notification'] = true; 683 620 684 685 686 687 $args = array();688 621 // could not find corresponding parent activity entry 622 // so wipe out $args array 623 } else { 624 $activity_args = array(); 625 } 689 626 690 // Record in activity streams 691 if ( ! empty( $args ) ) { 692 // @todo should we use bp_activity_new_comment()? that function will also send 693 // an email to people in the activity comment thread 694 // 695 // what if a site already has some comment email notification plugin setup? 696 // this is why I decided to go with bp_activity_add() to avoid any conflict 697 // with existing comment email notification plugins 698 $comment_activity_id = bp_activity_add( $args ); 699 700 if ( empty( $args['id'] ) ) { 701 // add meta to activity comment 702 bp_activity_update_meta( $comment_activity_id, 'bp_blogs_post_comment_id', $comment_id ); 703 bp_activity_update_meta( $comment_activity_id, 'post_title', $recorded_comment->post->post_title ); 704 bp_activity_update_meta( $comment_activity_id, 'post_url', add_query_arg( 'p', $recorded_comment->post->ID, home_url( '/' ) ) ); 705 706 // add meta to comment 707 add_comment_meta( $comment_id, 'bp_activity_comment_id', $comment_activity_id ); 627 // Record in activity streams 628 if ( ! empty( $activity_args ) ) { 629 $activity_id = bp_activity_new_comment( $activity_args ); 630 631 if ( empty( $activity_args['id'] ) ) { 632 // The activity metadata to inform about the corresponding comment ID 633 bp_activity_update_meta( $activity_id, 'bp_blogs_post_comment_id', $comment->comment_ID ); 634 635 /** 636 * The activity metadata to inform about the "parent" action 637 * eg: the "parent" action for new_blog_comment is new_blog_post 638 * 639 * This is used to make sure filtering the activities using the new_{post_type}_comment action 640 * will fetch all new_{post_type}_comment activities & activity_comment activities belonging to 641 * the new_{post_type} parent activity 642 */ 643 bp_activity_update_meta( $activity_id, 'bp_parent_action', $activity_post_object->action_id ); 644 645 // The comment metadata to inform about the corresponding activity ID 646 add_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', $activity_id ); 647 648 // These activity metadatas are used to build the new_blog_comment action string 649 if ( 'new_blog_comment' === $activity_post_object->comment_action_id ) { 650 bp_activity_update_meta( $activity_id, 'post_title', $comment->post->post_title ); 651 bp_activity_update_meta( $activity_id, 'post_url', esc_url_raw( add_query_arg( 'p', $comment->post->ID, home_url( '/' ) ) ) ); 708 652 } 709 653 } 710 654 } 711 712 // Update the blogs last active date713 bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );714 655 } 715 656 716 return $recorded_comment; 657 // Update the blogs last active date 658 bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() ); 659 660 return $activity_id; 717 661 } 718 add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 ); 719 add_action( 'edit_comment', 'bp_blogs_record_comment', 10 ); 662 add_action( 'bp_activity_post_type_comment', 'bp_blogs_comment_sync_activity_comment', 10, 4 ); 720 663 721 664 /** 722 665 * Record a user's association with a blog. … … add_action( 'delete_post', 'bp_blogs_remove_post' ); 974 917 * 975 918 * @param int $comment_id ID of the comment to be removed. 976 919 */ 977 function bp_blogs_remove_ comment( $comment_id) {920 function bp_blogs_remove_synced_comment( $deleted, $comment_id, $activity_post_object ) { 978 921 global $wpdb; 979 922 980 923 // activity comments are disabled for blog posts 981 // which means that individual activity items exist for blog comments982 924 if ( bp_disable_blogforum_comments() ) { 983 // Delete the individual activity stream item 984 bp_blogs_delete_activity( array( 985 'item_id' => $wpdb->blogid, 986 'secondary_item_id' => $comment_id, 987 'type' => 'new_blog_comment' 988 ) ); 925 return; 926 } 989 927 990 // activity comments are enabled for blog posts 991 // remove the associated activity item 992 } else { 993 // get associated activity ID from comment meta 994 $activity_id = get_comment_meta( $comment_id, 'bp_activity_comment_id', true ); 995 996 // delete the associated activity comment 997 // 998 // also removes child post comments and associated activity comments 999 if ( ! empty( $activity_id ) && bp_is_active( 'activity' ) ) { 1000 // fetch the activity comments for the activity item 1001 $activity = bp_activity_get( array( 1002 'in' => $activity_id, 1003 'display_comments' => 'stream', 1004 ) ); 928 // get associated activity ID from comment meta 929 $activity_id = get_comment_meta( $comment_id, 'bp_activity_comment_id', true ); 930 931 // delete the associated activity comment 932 // 933 // also removes child post comments and associated activity comments 934 if ( ! empty( $activity_id ) ) { 935 // fetch the activity comments for the activity item 936 $activity = bp_activity_get( array( 937 'in' => $activity_id, 938 'display_comments' => 'stream', 939 'spam' => 'all', 940 ) ); 1005 941 1006 1007 1008 1009 942 // get all activity comment IDs for the pending deleted item 943 if ( ! empty( $activity['activities'] ) ) { 944 $activity_ids = bp_activity_recurse_comments_activity_ids( $activity ); 945 $activity_ids[] = $activity_id; 1010 946 1011 1012 1013 1014 1015 1016 947 // delete activity items 948 foreach ( $activity_ids as $activity_id ) { 949 bp_activity_delete( array( 950 'id' => $activity_id 951 ) ); 952 } 1017 953 1018 1019 954 // remove associated blog comments 955 bp_blogs_remove_associated_blog_comments( $activity_ids ); 1020 956 1021 // rebuild activity comment tree 1022 BP_Activity_Activity::rebuild_activity_comment_tree( $activity['activities'][0]->item_id ); 1023 } 957 // rebuild activity comment tree 958 BP_Activity_Activity::rebuild_activity_comment_tree( $activity['activities'][0]->item_id ); 1024 959 } 1025 960 } 1026 961 … … function bp_blogs_remove_comment( $comment_id ) { 1035 970 */ 1036 971 do_action( 'bp_blogs_remove_comment', $wpdb->blogid, $comment_id, bp_loggedin_user_id() ); 1037 972 } 1038 add_action( ' delete_comment', 'bp_blogs_remove_comment');973 add_action( 'bp_activity_post_type_remove_comment', 'bp_blogs_remove_synced_comment', 10, 3 ); 1039 974 1040 975 /** 1041 976 * Removes blog comments that are associated with activity comments. 1042 977 * 1043 978 * @since BuddyPress (2.0.0) 1044 979 * 1045 * @see bp_blogs_remove_ comment()980 * @see bp_blogs_remove_synced_comment() 1046 981 * @see bp_blogs_sync_delete_from_activity_comment() 1047 982 * 1048 983 * @param array $activity_ids The activity IDs to check association with blog … … function bp_blogs_remove_associated_blog_comments( $activity_ids = array(), $for 1079 1014 } 1080 1015 1081 1016 /** 1082 * When a blog comment status transition occurs, update the relevant activity's status.1083 *1084 * @since BuddyPress (1.6.0)1085 *1086 * @param string $new_status New comment status.1087 * @param string $old_status Previous comment status.1088 * @param object $comment Comment data.1089 */1090 function bp_blogs_transition_activity_status( $new_status, $old_status, $comment ) {1091 1092 // Check the Activity component is active1093 if ( ! bp_is_active( 'activity' ) )1094 return;1095 1096 /**1097 * Activity currently doesn't have any concept of a trash, or an unapproved/approved state.1098 *1099 * If a blog comment transitions to a "delete" or "hold" status, delete the activity item.1100 * If a blog comment transitions to trashed, or spammed, mark the activity as spam.1101 * If a blog comment transitions to approved (and the activity exists), mark the activity as ham.1102 * If a blog comment transitions to unapproved (and the activity exists), mark the activity as spam.1103 * Otherwise, record the comment into the activity stream.1104 */1105 1106 // This clause was moved in from bp_blogs_remove_comment() in BuddyPress 1.6. It handles delete/hold.1107 if ( in_array( $new_status, array( 'delete', 'hold' ) ) ) {1108 return bp_blogs_remove_comment( $comment->comment_ID );1109 1110 // These clauses handle trash, spam, and un-spams.1111 } elseif ( in_array( $new_status, array( 'trash', 'spam', 'unapproved' ) ) ) {1112 $action = 'spam_activity';1113 } elseif ( 'approved' == $new_status ) {1114 $action = 'ham_activity';1115 }1116 1117 // Get the activity1118 if ( bp_disable_blogforum_comments() ) {1119 $activity_id = bp_activity_get_activity_id( array(1120 'component' => buddypress()->blogs->id,1121 'item_id' => get_current_blog_id(),1122 'secondary_item_id' => $comment->comment_ID,1123 'type' => 'new_blog_comment'1124 ) );1125 } else {1126 $activity_id = get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true );1127 }1128 1129 // Check activity item exists1130 if ( empty( $activity_id ) ) {1131 // If no activity exists, but the comment has been approved, record it into the activity table.1132 if ( 'approved' == $new_status ) {1133 return bp_blogs_record_comment( $comment->comment_ID, true );1134 }1135 1136 return;1137 }1138 1139 // Create an activity object1140 $activity = new BP_Activity_Activity( $activity_id );1141 if ( empty( $activity->component ) )1142 return;1143 1144 // Spam/ham the activity if it's not already in that state1145 if ( 'spam_activity' == $action && ! $activity->is_spam ) {1146 bp_activity_mark_as_spam( $activity );1147 } elseif ( 'ham_activity' == $action) {1148 bp_activity_mark_as_ham( $activity );1149 }1150 1151 // Add "new_blog_comment" to the whitelisted activity types, so that the activity's Akismet history is generated1152 $comment_akismet_history = create_function( '$t', '$t[] = "new_blog_comment"; return $t;' );1153 add_filter( 'bp_akismet_get_activity_types', $comment_akismet_history );1154 1155 // Save the updated activity1156 $activity->save();1157 1158 // Remove the "new_blog_comment" activity type whitelist so we don't break anything1159 remove_filter( 'bp_akismet_get_activity_types', $comment_akismet_history );1160 }1161 add_action( 'transition_comment_status', 'bp_blogs_transition_activity_status', 10, 3 );1162 1163 /**1164 1017 * Get the total number of blogs being tracked by BuddyPress. 1165 1018 * 1166 1019 * @return int $count Total blog count. -
src/bp-blogs/bp-blogs-loader.php
diff --git src/bp-blogs/bp-blogs-loader.php src/bp-blogs/bp-blogs-loader.php index 2e36870..7995349 100644
class BP_Blogs_Component extends BP_Component { 327 327 $params->contexts = array( 'activity', 'member' ); 328 328 $params->position = 5; 329 329 330 if ( post_type_supports( $post_type, 'comments' ) ) { 331 $params->comment_action_id = 'new_blog_comment'; 332 333 /** 334 * Filters the post types to track for the Blogs component. 335 * 336 * @since BuddyPress (1.5.0) 337 * @deprecated BuddyPress (2.3.0) 338 * 339 * Make sure plugins still using 'bp_blogs_record_comment_post_types' 340 * to track comment about their post types will generate new_blog_comment activities 341 * See https://buddypress.trac.wordpress.org/ticket/6306 342 * 343 * @param array $value Array of post types to track. 344 */ 345 $comment_post_types = apply_filters( 'bp_blogs_record_comment_post_types', array( 'post' ) ); 346 $comment_post_types_array = array_flip( $comment_post_types ); 347 348 if ( isset( $comment_post_types_array[ $post_type ] ) ) { 349 $params->comments_tracking = new stdClass(); 350 $params->comments_tracking->component_id = $this->id; 351 $params->comments_tracking->action_id = 'new_blog_comment'; 352 $params->comments_tracking->admin_filter = __( 'New post comment posted', 'buddypress' ); 353 $params->comments_tracking->format_callback = 'bp_blogs_format_activity_action_new_blog_comment'; 354 $params->comments_tracking->front_filter = __( 'Comments', 'buddypress' ); 355 $params->comments_tracking->contexts = array( 'activity', 'member' ); 356 $params->comments_tracking->position = 10; 357 } 358 } 359 330 360 return $params; 331 361 } 332 362 } -
src/bp-core/deprecated/1.6.php
diff --git src/bp-core/deprecated/1.6.php src/bp-core/deprecated/1.6.php index 8b5a5f0..995080c 100644
function bp_core_is_user_spammer( $user_id = 0 ) { 85 85 86 86 /** 87 87 * @deprecated BuddyPress (1.6) 88 * @deprecated No longer used; see bp_ blogs_transition_activity_status()88 * @deprecated No longer used; see bp_activity_transition_post_type_comment_status() 89 89 */ 90 90 function bp_blogs_manage_comment( $comment_id, $comment_status ) { 91 91 _deprecated_function( __FUNCTION__, '1.6', 'No longer used' ); -
src/bp-core/deprecated/2.4.php
diff --git src/bp-core/deprecated/2.4.php src/bp-core/deprecated/2.4.php index e69de29..1667615 100644
1 <?php 2 /** 3 * Deprecated functions. 4 * 5 * @deprecated 2.4.0 6 */ 7 8 // Exit if accessed directly. 9 defined( 'ABSPATH' ) || exit; 10 11 /** 12 * Record a new blog comment in the BuddyPress activity stream. 13 * 14 * Only posts the item if blog is public and post is not password-protected. 15 * 16 * @deprecated BuddyPress (2.4.0) 17 * 18 * @param int $comment_id ID of the comment being recorded. 19 * @param bool|string $is_approved Optional. The $is_approved value passed to 20 * the 'comment_post' action. Default: true. 21 * @return bool|object Returns false on failure, the comment object on success. 22 */ 23 function bp_blogs_record_comment( $comment_id, $is_approved = true ) { 24 _deprecated_function( __FUNCTION__, '2.4.0', 'bp_activity_post_type_comment()' ); 25 bp_activity_post_type_comment( $comment_id, $is_approved ); 26 } 27 28 /** 29 * Remove a blog comment activity item from the activity stream. 30 * 31 * @deprecated BuddyPress (2.4.0) 32 * 33 * @param int $comment_id ID of the comment to be removed. 34 */ 35 function bp_blogs_remove_comment( $comment_id ) { 36 _deprecated_function( __FUNCTION__, '2.4.0', 'bp_activity_post_type_remove_comment()' ); 37 bp_activity_post_type_remove_comment( $comment_id ); 38 } 39 40 /** 41 * When a blog comment status transition occurs, update the relevant activity's status. 42 * 43 * @since BuddyPress (1.6.0) 44 * @deprecated BuddyPress (2.4.0) 45 * 46 * @param string $new_status New comment status. 47 * @param string $old_status Previous comment status. 48 * @param object $comment Comment data. 49 */ 50 function bp_blogs_transition_activity_status( $new_status, $old_status, $comment ) { 51 _deprecated_function( __FUNCTION__, '2.4.0', 'bp_activity_transition_post_type_comment_status()' ); 52 bp_activity_transition_post_type_comment_status( $new_status, $old_status, $comment ); 53 } 54 -
src/bp-loader.php
diff --git src/bp-loader.php src/bp-loader.php index a71c216..846240e 100644
class BuddyPress { 484 484 require( $this->plugin_dir . 'bp-core/deprecated/2.1.php' ); 485 485 require( $this->plugin_dir . 'bp-core/deprecated/2.2.php' ); 486 486 require( $this->plugin_dir . 'bp-core/deprecated/2.3.php' ); 487 require( $this->plugin_dir . 'bp-core/deprecated/2.4.php' ); 487 488 } 488 489 } 489 490 -
tests/phpunit/includes/testcase.php
diff --git tests/phpunit/includes/testcase.php tests/phpunit/includes/testcase.php index 4a1de2a..93139b3 100644
class BP_UnitTestCase extends WP_UnitTestCase { 40 40 41 41 // Fixes warnings in multisite functions 42 42 $_SERVER['REMOTE_ADDR'] = ''; 43 44 // Make sure Activity actions are reset before each test 45 $this->reset_bp_activity_actions(); 46 47 // Make sure all Post types activities globals are reset before each test 48 $this->reset_bp_activity_post_types_globals(); 43 49 } 44 50 45 51 function clean_up_global_scope() { … … class BP_UnitTestCase extends WP_UnitTestCase { 75 81 } 76 82 } 77 83 84 protected function reset_bp_activity_actions() { 85 buddypress()->activity->actions = new stdClass(); 86 87 /** 88 * Populate the global with default activity actions only 89 * before each test. 90 */ 91 do_action( 'bp_register_activity_actions' ); 92 } 93 94 protected function reset_bp_activity_post_types_globals() { 95 global $wp_post_types; 96 97 // Remove all remaining tracking arguments to each post type 98 foreach ( $wp_post_types as $post_type => $post_type_arg ) { 99 if ( post_type_supports( $post_type, 'buddypress-activity' ) ) { 100 remove_post_type_support( 'page', 'buddypress-activity' ); 101 } 102 103 if ( isset( $post_type_arg->bp_activity ) ) { 104 unset( $post_type_arg->bp_activity ); 105 } 106 } 107 108 buddypress()->activity->track = array(); 109 } 110 78 111 function assertPreConditions() { 79 112 parent::assertPreConditions(); 80 113 -
tests/phpunit/testcases/activity/template.php
diff --git tests/phpunit/testcases/activity/template.php tests/phpunit/testcases/activity/template.php index fc58a21..8e69bfd 100644
class BP_Tests_Activity_Template extends BP_UnitTestCase { 1216 1216 1217 1217 /** 1218 1218 * @group bp_has_activities 1219 * @group post_type_comment_activities 1219 1220 */ 1220 1221 public function test_bp_has_activities_with_type_new_blog_comments() { 1221 1222 add_filter( 'bp_disable_blogforum_comments', '__return_false' ); -
tests/phpunit/testcases/blogs/filters.php
diff --git tests/phpunit/testcases/blogs/filters.php tests/phpunit/testcases/blogs/filters.php index a0fc961..2c17bda 100644
2 2 /** 3 3 * @group blogs 4 4 * @ticket BP6306 5 * @group post_type_comment_activities 5 6 */ 6 7 class BP_Tests_Blogs_Filters extends BP_UnitTestCase { 7 8 protected $activity_actions; … … class BP_Tests_Blogs_Filters extends BP_UnitTestCase { 42 43 } 43 44 44 45 /** 45 * @g oup bp_activity_get_actions46 * @group bp_activity_get_actions 46 47 */ 47 48 public function test_bp_activity_get_actions() { 48 49 $activity_actions = bp_activity_get_actions(); … … class BP_Tests_Blogs_Filters extends BP_UnitTestCase { 51 52 } 52 53 53 54 /** 54 * @g oup bp_activity_catch_transition_post_type_status55 * @group bp_activity_catch_transition_post_type_status 55 56 */ 56 57 public function test_bp_activity_catch_transition_post_type_status() { 57 58 $post_id = $this->factory->post->create( array( … … class BP_Tests_Blogs_Filters extends BP_UnitTestCase { 63 64 } 64 65 65 66 /** 66 * @g oup bp_blogs_record_comment67 * @group bp_blogs_record_comment 67 68 */ 68 69 public function test_bp_blogs_record_comment() { 69 70 $u = $this->factory->user->create(); … … class BP_Tests_Blogs_Filters extends BP_UnitTestCase { 88 89 } 89 90 90 91 /** 91 * @g oup bp_blogs_record_comment_sync_activity_comment92 * @group bp_blogs_record_comment_sync_activity_comment 92 93 */ 93 94 public function test_bp_blogs_record_comment_sync_activity_comment() { 94 95 $u = $this->factory->user->create(); -
tests/phpunit/testcases/blogs/functions.php
diff --git tests/phpunit/testcases/blogs/functions.php tests/phpunit/testcases/blogs/functions.php index d2e36b2..4396639 100644
class BP_Tests_Blogs_Functions extends BP_UnitTestCase { 513 513 514 514 /** 515 515 * @group bp_blogs_catch_transition_post_status 516 * @group post_type_comment_activities 516 517 */ 517 518 public function test_update_blog_post_and_new_blog_comment_and_activity_comment_meta() { 518 519 // save the current user and override logged-in user