Ticket #7218: 7218.activity-original.patch
File 7218.activity-original.patch, 43.3 KB (added by , 7 years ago) |
---|
-
src/bp-activity/bp-activity-actions.php
12 12 // Exit if accessed directly. 13 13 defined( 'ABSPATH' ) || exit; 14 14 15 /**16 * Allow core components and dependent plugins to register activity actions.17 *18 * @since 1.2.019 *20 */21 function bp_register_activity_actions() {22 23 /**24 * Fires on bp_init to allow core components and dependent plugins to register activity actions.25 *26 * @since 1.2.027 */28 do_action( 'bp_register_activity_actions' );29 }30 add_action( 'bp_init', 'bp_register_activity_actions', 8 );31 32 15 /** 33 16 * Catch and route requests for single activity item permalinks. 34 17 * … … 428 411 bp_core_redirect( wp_get_referer() . '#activity-' . bp_action_variable( 0 ) ); 429 412 } 430 413 add_action( 'bp_actions', 'bp_activity_action_remove_favorite' ); 431 432 /**433 * Load the sitewide activity feed.434 *435 * @since 1.0.0436 *437 * @return bool False on failure.438 */439 function bp_activity_action_sitewide_feed() {440 $bp = buddypress();441 442 if ( ! bp_is_activity_component() || ! bp_is_current_action( 'feed' ) || bp_is_user() || ! empty( $bp->groups->current_group ) )443 return false;444 445 // Setup the feed.446 buddypress()->activity->feed = new BP_Activity_Feed( array(447 'id' => 'sitewide',448 449 /* translators: Sitewide activity RSS title - "[Site Name] | Site Wide Activity" */450 'title' => sprintf( __( '%s | Site-Wide Activity', 'buddypress' ), bp_get_site_name() ),451 452 'link' => bp_get_activity_directory_permalink(),453 'description' => __( 'Activity feed for the entire site.', 'buddypress' ),454 'activity_args' => 'display_comments=threaded'455 ) );456 }457 add_action( 'bp_actions', 'bp_activity_action_sitewide_feed' );458 459 /**460 * Load a user's personal activity feed.461 *462 * @since 1.0.0463 *464 * @return bool False on failure.465 */466 function bp_activity_action_personal_feed() {467 if ( ! bp_is_user_activity() || ! bp_is_current_action( 'feed' ) ) {468 return false;469 }470 471 // Setup the feed.472 buddypress()->activity->feed = new BP_Activity_Feed( array(473 'id' => 'personal',474 475 /* translators: Personal activity RSS title - "[Site Name] | [User Display Name] | Activity" */476 'title' => sprintf( __( '%1$s | %2$s | Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),477 478 'link' => trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() ),479 'description' => sprintf( __( 'Activity feed for %s.', 'buddypress' ), bp_get_displayed_user_fullname() ),480 'activity_args' => 'user_id=' . bp_displayed_user_id()481 ) );482 }483 add_action( 'bp_actions', 'bp_activity_action_personal_feed' );484 485 /**486 * Load a user's friends' activity feed.487 *488 * @since 1.0.0489 *490 * @return bool False on failure.491 */492 function bp_activity_action_friends_feed() {493 if ( ! bp_is_active( 'friends' ) || ! bp_is_user_activity() || ! bp_is_current_action( bp_get_friends_slug() ) || ! bp_is_action_variable( 'feed', 0 ) ) {494 return false;495 }496 497 // Setup the feed.498 buddypress()->activity->feed = new BP_Activity_Feed( array(499 'id' => 'friends',500 501 /* translators: Friends activity RSS title - "[Site Name] | [User Display Name] | Friends Activity" */502 'title' => sprintf( __( '%1$s | %2$s | Friends Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),503 504 'link' => trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() ),505 'description' => sprintf( __( "Activity feed for %s's friends.", 'buddypress' ), bp_get_displayed_user_fullname() ),506 'activity_args' => 'scope=friends'507 ) );508 }509 add_action( 'bp_actions', 'bp_activity_action_friends_feed' );510 511 /**512 * Load the activity feed for a user's groups.513 *514 * @since 1.2.0515 *516 * @return bool False on failure.517 */518 function bp_activity_action_my_groups_feed() {519 if ( ! bp_is_active( 'groups' ) || ! bp_is_user_activity() || ! bp_is_current_action( bp_get_groups_slug() ) || ! bp_is_action_variable( 'feed', 0 ) ) {520 return false;521 }522 523 // Get displayed user's group IDs.524 $groups = groups_get_user_groups();525 $group_ids = implode( ',', $groups['groups'] );526 527 // Setup the feed.528 buddypress()->activity->feed = new BP_Activity_Feed( array(529 'id' => 'mygroups',530 531 /* translators: Member groups activity RSS title - "[Site Name] | [User Display Name] | Groups Activity" */532 'title' => sprintf( __( '%1$s | %2$s | Group Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),533 534 'link' => trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_groups_slug() ),535 'description' => sprintf( __( "Public group activity feed of which %s is a member.", 'buddypress' ), bp_get_displayed_user_fullname() ),536 'activity_args' => array(537 'object' => buddypress()->groups->id,538 'primary_id' => $group_ids,539 'display_comments' => 'threaded'540 )541 ) );542 }543 add_action( 'bp_actions', 'bp_activity_action_my_groups_feed' );544 545 /**546 * Load a user's @mentions feed.547 *548 * @since 1.2.0549 *550 * @return bool False on failure.551 */552 function bp_activity_action_mentions_feed() {553 if ( ! bp_activity_do_mentions() ) {554 return false;555 }556 557 if ( !bp_is_user_activity() || ! bp_is_current_action( 'mentions' ) || ! bp_is_action_variable( 'feed', 0 ) ) {558 return false;559 }560 561 // Setup the feed.562 buddypress()->activity->feed = new BP_Activity_Feed( array(563 'id' => 'mentions',564 565 /* translators: User mentions activity RSS title - "[Site Name] | [User Display Name] | Mentions" */566 'title' => sprintf( __( '%1$s | %2$s | Mentions', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),567 568 'link' => bp_displayed_user_domain() . bp_get_activity_slug() . '/mentions/',569 'description' => sprintf( __( "Activity feed mentioning %s.", 'buddypress' ), bp_get_displayed_user_fullname() ),570 'activity_args' => array(571 'search_terms' => '@' . bp_core_get_username( bp_displayed_user_id() )572 )573 ) );574 }575 add_action( 'bp_actions', 'bp_activity_action_mentions_feed' );576 577 /**578 * Load a user's favorites feed.579 *580 * @since 1.2.0581 *582 * @return bool False on failure.583 */584 function bp_activity_action_favorites_feed() {585 if ( ! bp_is_user_activity() || ! bp_is_current_action( 'favorites' ) || ! bp_is_action_variable( 'feed', 0 ) ) {586 return false;587 }588 589 // Get displayed user's favorite activity IDs.590 $favs = bp_activity_get_user_favorites( bp_displayed_user_id() );591 $fav_ids = implode( ',', (array) $favs );592 593 // Setup the feed.594 buddypress()->activity->feed = new BP_Activity_Feed( array(595 'id' => 'favorites',596 597 /* translators: User activity favorites RSS title - "[Site Name] | [User Display Name] | Favorites" */598 'title' => sprintf( __( '%1$s | %2$s | Favorites', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),599 600 'link' => bp_displayed_user_domain() . bp_get_activity_slug() . '/favorites/',601 'description' => sprintf( __( "Activity feed of %s's favorites.", 'buddypress' ), bp_get_displayed_user_fullname() ),602 'activity_args' => 'include=' . $fav_ids603 ) );604 }605 add_action( 'bp_actions', 'bp_activity_action_favorites_feed' );606 607 /**608 * AJAX endpoint for Suggestions API lookups.609 *610 * @since 2.1.0611 */612 function bp_ajax_get_suggestions() {613 if ( ! bp_is_user_active() || empty( $_GET['term'] ) || empty( $_GET['type'] ) ) {614 wp_send_json_error( 'missing_parameter' );615 exit;616 }617 618 $args = array(619 'term' => sanitize_text_field( $_GET['term'] ),620 'type' => sanitize_text_field( $_GET['type'] ),621 );622 623 // Support per-Group suggestions.624 if ( ! empty( $_GET['group-id'] ) ) {625 $args['group_id'] = absint( $_GET['group-id'] );626 }627 628 $results = bp_core_get_suggestions( $args );629 630 if ( is_wp_error( $results ) ) {631 wp_send_json_error( $results->get_error_message() );632 exit;633 }634 635 wp_send_json_success( $results );636 }637 add_action( 'wp_ajax_bp_get_suggestions', 'bp_ajax_get_suggestions' );638 639 /**640 * Detect a change in post type status, and initiate an activity update if necessary.641 *642 * @since 2.2.0643 *644 * @todo Support untrashing better.645 *646 * @param string $new_status New status for the post.647 * @param string $old_status Old status for the post.648 * @param object $post Post data.649 */650 function bp_activity_catch_transition_post_type_status( $new_status, $old_status, $post ) {651 if ( ! post_type_supports( $post->post_type, 'buddypress-activity' ) ) {652 return;653 }654 655 // This is an edit.656 if ( $new_status === $old_status ) {657 // An edit of an existing post should update the existing activity item.658 if ( $new_status == 'publish' ) {659 $edit = bp_activity_post_type_update( $post );660 661 // Post was never recorded into activity stream, so record it now!662 if ( null === $edit ) {663 bp_activity_post_type_publish( $post->ID, $post );664 }665 666 // Allow plugins to eventually deal with other post statuses.667 } else {668 /**669 * Fires when editing the post and the new status is not 'publish'.670 *671 * This is a variable filter that is dependent on the post type672 * being untrashed.673 *674 * @since 2.5.0675 *676 * @param WP_Post $post Post data.677 * @param string $new_status New status for the post.678 * @param string $old_status Old status for the post.679 */680 do_action( 'bp_activity_post_type_edit_' . $post->post_type, $post, $new_status, $old_status );681 }682 683 return;684 }685 686 // Publishing a previously unpublished post.687 if ( 'publish' === $new_status ) {688 // Untrashing the post type - nothing here yet.689 if ( 'trash' == $old_status ) {690 691 /**692 * Fires if untrashing post in a post type.693 *694 * This is a variable filter that is dependent on the post type695 * being untrashed.696 *697 * @since 2.2.0698 *699 * @param WP_Post $post Post data.700 */701 do_action( 'bp_activity_post_type_untrash_' . $post->post_type, $post );702 } else {703 // Record the post.704 bp_activity_post_type_publish( $post->ID, $post );705 }706 707 // Unpublishing a previously published post.708 } elseif ( 'publish' === $old_status ) {709 // Some form of pending status - only remove the activity entry.710 bp_activity_post_type_unpublish( $post->ID, $post );711 712 // For any other cases, allow plugins to eventually deal with it.713 } else {714 /**715 * Fires when the old and the new post status are not 'publish'.716 *717 * This is a variable filter that is dependent on the post type718 * being untrashed.719 *720 * @since 2.5.0721 *722 * @param WP_Post $post Post data.723 * @param string $new_status New status for the post.724 * @param string $old_status Old status for the post.725 */726 do_action( 'bp_activity_post_type_transition_status_' . $post->post_type, $post, $new_status, $old_status );727 }728 }729 add_action( 'transition_post_status', 'bp_activity_catch_transition_post_type_status', 10, 3 );730 731 /**732 * When a post type comment status transition occurs, update the relevant activity's status.733 *734 * @since 2.5.0735 *736 * @param string $new_status New comment status.737 * @param string $old_status Previous comment status.738 * @param WP_Comment $comment Comment data.739 */740 function bp_activity_transition_post_type_comment_status( $new_status, $old_status, $comment ) {741 $post_type = get_post_type( $comment->comment_post_ID );742 if ( ! $post_type ) {743 return;744 }745 746 // Get the post type tracking args.747 $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type );748 749 // Bail if the activity type does not exist750 if ( empty( $activity_post_object->comments_tracking->action_id ) ) {751 return false;752 753 // Set the $activity_comment_object754 } else {755 $activity_comment_object = $activity_post_object->comments_tracking;756 }757 758 // Init an empty activity ID759 $activity_id = 0;760 761 /**762 * Activity currently doesn't have any concept of a trash, or an unapproved/approved state.763 *764 * If a blog comment transitions to a "delete" or "hold" status, delete the activity item.765 * If a blog comment transitions to trashed, or spammed, mark the activity as spam.766 * If a blog comment transitions to approved (and the activity exists), mark the activity as ham.767 * If a blog comment transitions to unapproved (and the activity exists), mark the activity as spam.768 * Otherwise, record the comment into the activity stream.769 */770 771 // This clause handles delete/hold.772 if ( in_array( $new_status, array( 'delete', 'hold' ) ) ) {773 return bp_activity_post_type_remove_comment( $comment->comment_ID, $activity_post_object );774 775 // These clauses handle trash, spam, and un-spams.776 } elseif ( in_array( $new_status, array( 'trash', 'spam', 'unapproved' ) ) ) {777 $action = 'spam_activity';778 } elseif ( 'approved' == $new_status ) {779 $action = 'ham_activity';780 }781 782 // Get the activity783 if ( bp_disable_blogforum_comments() ) {784 $activity_id = bp_activity_get_activity_id( array(785 'component' => $activity_comment_object->component_id,786 'item_id' => get_current_blog_id(),787 'secondary_item_id' => $comment->comment_ID,788 'type' => $activity_comment_object->action_id,789 ) );790 } else {791 $activity_id = get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true );792 }793 794 /**795 * Leave a chance to plugins to manage activity comments differently.796 *797 * @since 2.5.0798 *799 * @param bool $value True to override BuddyPress management.800 * @param string $post_type The post type name.801 * @param int $activity_id The post type activity (0 if not found).802 * @param string $new_status The new status of the post type comment.803 * @param string $old_status The old status of the post type comment.804 * @param WP_Comment $comment Comment data.805 */806 if ( true === apply_filters( 'bp_activity_pre_transition_post_type_comment_status', false, $post_type, $activity_id, $new_status, $old_status, $comment ) ) {807 return false;808 }809 810 // Check activity item exists811 if ( empty( $activity_id ) ) {812 // If no activity exists, but the comment has been approved, record it into the activity table.813 if ( 'approved' == $new_status ) {814 return bp_activity_post_type_comment( $comment->comment_ID, true, $activity_post_object );815 }816 817 return;818 }819 820 // Create an activity object821 $activity = new BP_Activity_Activity( $activity_id );822 if ( empty( $activity->component ) ) {823 return;824 }825 826 // Spam/ham the activity if it's not already in that state827 if ( 'spam_activity' === $action && ! $activity->is_spam ) {828 bp_activity_mark_as_spam( $activity );829 } elseif ( 'ham_activity' == $action) {830 bp_activity_mark_as_ham( $activity );831 }832 833 // Add "new_post_type_comment" to the whitelisted activity types, so that the activity's Akismet history is generated834 $post_type_comment_action = $activity_comment_object->action_id;835 $comment_akismet_history = function ( $activity_types ) use ( $post_type_comment_action ) {836 $activity_types[] = $post_type_comment_action;837 838 return $activity_types;839 };840 add_filter( 'bp_akismet_get_activity_types', $comment_akismet_history );841 842 // Make sure the activity change won't edit the comment if sync is on843 remove_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 );844 845 // Save the updated activity846 $activity->save();847 848 // Restore the action849 add_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 );850 851 // Remove the "new_blog_comment" activity type whitelist so we don't break anything852 remove_filter( 'bp_akismet_get_activity_types', $comment_akismet_history );853 }854 add_action( 'transition_comment_status', 'bp_activity_transition_post_type_comment_status', 10, 3 ); -
new file src/bp-activity/bp-activity-feeds.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Feeds. 4 * 5 * @package BuddyPress 6 * @subpackage ActivityFeeds 7 * @since 2.9.0 8 */ 9 10 /** 11 * Load the sitewide activity feed. 12 * 13 * @since 1.0.0 14 * 15 * @return bool False on failure. 16 */ 17 function bp_activity_action_sitewide_feed() { 18 $bp = buddypress(); 19 20 if ( ! bp_is_activity_component() || ! bp_is_current_action( 'feed' ) || bp_is_user() || ! empty( $bp->groups->current_group ) ) 21 return false; 22 23 // Setup the feed. 24 buddypress()->activity->feed = new BP_Activity_Feed( array( 25 'id' => 'sitewide', 26 27 /* translators: Sitewide activity RSS title - "[Site Name] | Site Wide Activity" */ 28 'title' => sprintf( __( '%s | Site-Wide Activity', 'buddypress' ), bp_get_site_name() ), 29 30 'link' => bp_get_activity_directory_permalink(), 31 'description' => __( 'Activity feed for the entire site.', 'buddypress' ), 32 'activity_args' => 'display_comments=threaded' 33 ) ); 34 } 35 add_action( 'bp_actions', 'bp_activity_action_sitewide_feed' ); 36 37 /** 38 * Load a user's personal activity feed. 39 * 40 * @since 1.0.0 41 * 42 * @return bool False on failure. 43 */ 44 function bp_activity_action_personal_feed() { 45 if ( ! bp_is_user_activity() || ! bp_is_current_action( 'feed' ) ) { 46 return false; 47 } 48 49 // Setup the feed. 50 buddypress()->activity->feed = new BP_Activity_Feed( array( 51 'id' => 'personal', 52 53 /* translators: Personal activity RSS title - "[Site Name] | [User Display Name] | Activity" */ 54 'title' => sprintf( __( '%1$s | %2$s | Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ), 55 56 'link' => trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() ), 57 'description' => sprintf( __( 'Activity feed for %s.', 'buddypress' ), bp_get_displayed_user_fullname() ), 58 'activity_args' => 'user_id=' . bp_displayed_user_id() 59 ) ); 60 } 61 add_action( 'bp_actions', 'bp_activity_action_personal_feed' ); 62 63 /** 64 * Load a user's friends' activity feed. 65 * 66 * @since 1.0.0 67 * 68 * @return bool False on failure. 69 */ 70 function bp_activity_action_friends_feed() { 71 if ( ! bp_is_active( 'friends' ) || ! bp_is_user_activity() || ! bp_is_current_action( bp_get_friends_slug() ) || ! bp_is_action_variable( 'feed', 0 ) ) { 72 return false; 73 } 74 75 // Setup the feed. 76 buddypress()->activity->feed = new BP_Activity_Feed( array( 77 'id' => 'friends', 78 79 /* translators: Friends activity RSS title - "[Site Name] | [User Display Name] | Friends Activity" */ 80 'title' => sprintf( __( '%1$s | %2$s | Friends Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ), 81 82 'link' => trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() ), 83 'description' => sprintf( __( "Activity feed for %s's friends.", 'buddypress' ), bp_get_displayed_user_fullname() ), 84 'activity_args' => 'scope=friends' 85 ) ); 86 } 87 add_action( 'bp_actions', 'bp_activity_action_friends_feed' ); 88 89 /** 90 * Load the activity feed for a user's groups. 91 * 92 * @since 1.2.0 93 * 94 * @return bool False on failure. 95 */ 96 function bp_activity_action_my_groups_feed() { 97 if ( ! bp_is_active( 'groups' ) || ! bp_is_user_activity() || ! bp_is_current_action( bp_get_groups_slug() ) || ! bp_is_action_variable( 'feed', 0 ) ) { 98 return false; 99 } 100 101 // Get displayed user's group IDs. 102 $groups = groups_get_user_groups(); 103 $group_ids = implode( ',', $groups['groups'] ); 104 105 // Setup the feed. 106 buddypress()->activity->feed = new BP_Activity_Feed( array( 107 'id' => 'mygroups', 108 109 /* translators: Member groups activity RSS title - "[Site Name] | [User Display Name] | Groups Activity" */ 110 'title' => sprintf( __( '%1$s | %2$s | Group Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ), 111 112 'link' => trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_groups_slug() ), 113 'description' => sprintf( __( "Public group activity feed of which %s is a member.", 'buddypress' ), bp_get_displayed_user_fullname() ), 114 'activity_args' => array( 115 'object' => buddypress()->groups->id, 116 'primary_id' => $group_ids, 117 'display_comments' => 'threaded' 118 ) 119 ) ); 120 } 121 add_action( 'bp_actions', 'bp_activity_action_my_groups_feed' ); 122 123 /** 124 * Load a user's @mentions feed. 125 * 126 * @since 1.2.0 127 * 128 * @return bool False on failure. 129 */ 130 function bp_activity_action_mentions_feed() { 131 if ( ! bp_activity_do_mentions() ) { 132 return false; 133 } 134 135 if ( !bp_is_user_activity() || ! bp_is_current_action( 'mentions' ) || ! bp_is_action_variable( 'feed', 0 ) ) { 136 return false; 137 } 138 139 // Setup the feed. 140 buddypress()->activity->feed = new BP_Activity_Feed( array( 141 'id' => 'mentions', 142 143 /* translators: User mentions activity RSS title - "[Site Name] | [User Display Name] | Mentions" */ 144 'title' => sprintf( __( '%1$s | %2$s | Mentions', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ), 145 146 'link' => bp_displayed_user_domain() . bp_get_activity_slug() . '/mentions/', 147 'description' => sprintf( __( "Activity feed mentioning %s.", 'buddypress' ), bp_get_displayed_user_fullname() ), 148 'activity_args' => array( 149 'search_terms' => '@' . bp_core_get_username( bp_displayed_user_id() ) 150 ) 151 ) ); 152 } 153 add_action( 'bp_actions', 'bp_activity_action_mentions_feed' ); 154 155 /** 156 * Load a user's favorites feed. 157 * 158 * @since 1.2.0 159 * 160 * @return bool False on failure. 161 */ 162 function bp_activity_action_favorites_feed() { 163 if ( ! bp_is_user_activity() || ! bp_is_current_action( 'favorites' ) || ! bp_is_action_variable( 'feed', 0 ) ) { 164 return false; 165 } 166 167 // Get displayed user's favorite activity IDs. 168 $favs = bp_activity_get_user_favorites( bp_displayed_user_id() ); 169 $fav_ids = implode( ',', (array) $favs ); 170 171 // Setup the feed. 172 buddypress()->activity->feed = new BP_Activity_Feed( array( 173 'id' => 'favorites', 174 175 /* translators: User activity favorites RSS title - "[Site Name] | [User Display Name] | Favorites" */ 176 'title' => sprintf( __( '%1$s | %2$s | Favorites', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ), 177 178 'link' => bp_displayed_user_domain() . bp_get_activity_slug() . '/favorites/', 179 'description' => sprintf( __( "Activity feed of %s's favorites.", 'buddypress' ), bp_get_displayed_user_fullname() ), 180 'activity_args' => 'include=' . $fav_ids 181 ) ); 182 } 183 add_action( 'bp_actions', 'bp_activity_action_favorites_feed' ); -
src/bp-activity/bp-activity-functions.php
1418 1418 } 1419 1419 add_action( 'bp_make_ham_user', 'bp_activity_ham_all_user_data' ); 1420 1420 1421 /** 1422 * Allow core components and dependent plugins to register activity actions. 1423 * 1424 * @since 1.2.0 1425 * 1426 */ 1427 function bp_register_activity_actions() { 1428 1429 /** 1430 * Fires on bp_init to allow core components and dependent plugins to register activity actions. 1431 * 1432 * @since 1.2.0 1433 */ 1434 do_action( 'bp_register_activity_actions' ); 1435 } 1436 add_action( 'bp_init', 'bp_register_activity_actions', 8 ); 1437 1421 1438 /** 1422 1439 * Register the activity stream actions for updates. 1423 1440 * … … 3891 3908 */ 3892 3909 return (bool) apply_filters( 'bp_activity_do_heartbeat', $retval ); 3893 3910 } 3911 3912 3913 /** 3914 * AJAX endpoint for Suggestions API lookups. 3915 * 3916 * @since 2.1.0 3917 */ 3918 function bp_ajax_get_suggestions() { 3919 if ( ! bp_is_user_active() || empty( $_GET['term'] ) || empty( $_GET['type'] ) ) { 3920 wp_send_json_error( 'missing_parameter' ); 3921 exit; 3922 } 3923 3924 $args = array( 3925 'term' => sanitize_text_field( $_GET['term'] ), 3926 'type' => sanitize_text_field( $_GET['type'] ), 3927 ); 3928 3929 // Support per-Group suggestions. 3930 if ( ! empty( $_GET['group-id'] ) ) { 3931 $args['group_id'] = absint( $_GET['group-id'] ); 3932 } 3933 3934 $results = bp_core_get_suggestions( $args ); 3935 3936 if ( is_wp_error( $results ) ) { 3937 wp_send_json_error( $results->get_error_message() ); 3938 exit; 3939 } 3940 3941 wp_send_json_success( $results ); 3942 } 3943 add_action( 'wp_ajax_bp_get_suggestions', 'bp_ajax_get_suggestions' ); 3944 3945 /** 3946 * Detect a change in post type status, and initiate an activity update if necessary. 3947 * 3948 * @since 2.2.0 3949 * 3950 * @todo Support untrashing better. 3951 * 3952 * @param string $new_status New status for the post. 3953 * @param string $old_status Old status for the post. 3954 * @param object $post Post data. 3955 */ 3956 function bp_activity_catch_transition_post_type_status( $new_status, $old_status, $post ) { 3957 if ( ! post_type_supports( $post->post_type, 'buddypress-activity' ) ) { 3958 return; 3959 } 3960 3961 // This is an edit. 3962 if ( $new_status === $old_status ) { 3963 // An edit of an existing post should update the existing activity item. 3964 if ( $new_status == 'publish' ) { 3965 $edit = bp_activity_post_type_update( $post ); 3966 3967 // Post was never recorded into activity stream, so record it now! 3968 if ( null === $edit ) { 3969 bp_activity_post_type_publish( $post->ID, $post ); 3970 } 3971 3972 // Allow plugins to eventually deal with other post statuses. 3973 } else { 3974 /** 3975 * Fires when editing the post and the new status is not 'publish'. 3976 * 3977 * This is a variable filter that is dependent on the post type 3978 * being untrashed. 3979 * 3980 * @since 2.5.0 3981 * 3982 * @param WP_Post $post Post data. 3983 * @param string $new_status New status for the post. 3984 * @param string $old_status Old status for the post. 3985 */ 3986 do_action( 'bp_activity_post_type_edit_' . $post->post_type, $post, $new_status, $old_status ); 3987 } 3988 3989 return; 3990 } 3991 3992 // Publishing a previously unpublished post. 3993 if ( 'publish' === $new_status ) { 3994 // Untrashing the post type - nothing here yet. 3995 if ( 'trash' == $old_status ) { 3996 3997 /** 3998 * Fires if untrashing post in a post type. 3999 * 4000 * This is a variable filter that is dependent on the post type 4001 * being untrashed. 4002 * 4003 * @since 2.2.0 4004 * 4005 * @param WP_Post $post Post data. 4006 */ 4007 do_action( 'bp_activity_post_type_untrash_' . $post->post_type, $post ); 4008 } else { 4009 // Record the post. 4010 bp_activity_post_type_publish( $post->ID, $post ); 4011 } 4012 4013 // Unpublishing a previously published post. 4014 } elseif ( 'publish' === $old_status ) { 4015 // Some form of pending status - only remove the activity entry. 4016 bp_activity_post_type_unpublish( $post->ID, $post ); 4017 4018 // For any other cases, allow plugins to eventually deal with it. 4019 } else { 4020 /** 4021 * Fires when the old and the new post status are not 'publish'. 4022 * 4023 * This is a variable filter that is dependent on the post type 4024 * being untrashed. 4025 * 4026 * @since 2.5.0 4027 * 4028 * @param WP_Post $post Post data. 4029 * @param string $new_status New status for the post. 4030 * @param string $old_status Old status for the post. 4031 */ 4032 do_action( 'bp_activity_post_type_transition_status_' . $post->post_type, $post, $new_status, $old_status ); 4033 } 4034 } 4035 add_action( 'transition_post_status', 'bp_activity_catch_transition_post_type_status', 10, 3 ); 4036 4037 /** 4038 * When a post type comment status transition occurs, update the relevant activity's status. 4039 * 4040 * @since 2.5.0 4041 * 4042 * @param string $new_status New comment status. 4043 * @param string $old_status Previous comment status. 4044 * @param WP_Comment $comment Comment data. 4045 */ 4046 function bp_activity_transition_post_type_comment_status( $new_status, $old_status, $comment ) { 4047 $post_type = get_post_type( $comment->comment_post_ID ); 4048 if ( ! $post_type ) { 4049 return; 4050 } 4051 4052 // Get the post type tracking args. 4053 $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type ); 4054 4055 // Bail if the activity type does not exist 4056 if ( empty( $activity_post_object->comments_tracking->action_id ) ) { 4057 return false; 4058 4059 // Set the $activity_comment_object 4060 } else { 4061 $activity_comment_object = $activity_post_object->comments_tracking; 4062 } 4063 4064 // Init an empty activity ID 4065 $activity_id = 0; 4066 4067 /** 4068 * Activity currently doesn't have any concept of a trash, or an unapproved/approved state. 4069 * 4070 * If a blog comment transitions to a "delete" or "hold" status, delete the activity item. 4071 * If a blog comment transitions to trashed, or spammed, mark the activity as spam. 4072 * If a blog comment transitions to approved (and the activity exists), mark the activity as ham. 4073 * If a blog comment transitions to unapproved (and the activity exists), mark the activity as spam. 4074 * Otherwise, record the comment into the activity stream. 4075 */ 4076 4077 // This clause handles delete/hold. 4078 if ( in_array( $new_status, array( 'delete', 'hold' ) ) ) { 4079 return bp_activity_post_type_remove_comment( $comment->comment_ID, $activity_post_object ); 4080 4081 // These clauses handle trash, spam, and un-spams. 4082 } elseif ( in_array( $new_status, array( 'trash', 'spam', 'unapproved' ) ) ) { 4083 $action = 'spam_activity'; 4084 } elseif ( 'approved' == $new_status ) { 4085 $action = 'ham_activity'; 4086 } 4087 4088 // Get the activity 4089 if ( bp_disable_blogforum_comments() ) { 4090 $activity_id = bp_activity_get_activity_id( array( 4091 'component' => $activity_comment_object->component_id, 4092 'item_id' => get_current_blog_id(), 4093 'secondary_item_id' => $comment->comment_ID, 4094 'type' => $activity_comment_object->action_id, 4095 ) ); 4096 } else { 4097 $activity_id = get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true ); 4098 } 4099 4100 /** 4101 * Leave a chance to plugins to manage activity comments differently. 4102 * 4103 * @since 2.5.0 4104 * 4105 * @param bool $value True to override BuddyPress management. 4106 * @param string $post_type The post type name. 4107 * @param int $activity_id The post type activity (0 if not found). 4108 * @param string $new_status The new status of the post type comment. 4109 * @param string $old_status The old status of the post type comment. 4110 * @param WP_Comment $comment Comment data. 4111 */ 4112 if ( true === apply_filters( 'bp_activity_pre_transition_post_type_comment_status', false, $post_type, $activity_id, $new_status, $old_status, $comment ) ) { 4113 return false; 4114 } 4115 4116 // Check activity item exists 4117 if ( empty( $activity_id ) ) { 4118 // If no activity exists, but the comment has been approved, record it into the activity table. 4119 if ( 'approved' == $new_status ) { 4120 return bp_activity_post_type_comment( $comment->comment_ID, true, $activity_post_object ); 4121 } 4122 4123 return; 4124 } 4125 4126 // Create an activity object 4127 $activity = new BP_Activity_Activity( $activity_id ); 4128 if ( empty( $activity->component ) ) { 4129 return; 4130 } 4131 4132 // Spam/ham the activity if it's not already in that state 4133 if ( 'spam_activity' === $action && ! $activity->is_spam ) { 4134 bp_activity_mark_as_spam( $activity ); 4135 } elseif ( 'ham_activity' == $action) { 4136 bp_activity_mark_as_ham( $activity ); 4137 } 4138 4139 // Add "new_post_type_comment" to the whitelisted activity types, so that the activity's Akismet history is generated 4140 $post_type_comment_action = $activity_comment_object->action_id; 4141 $comment_akismet_history = function ( $activity_types ) use ( $post_type_comment_action ) { 4142 $activity_types[] = $post_type_comment_action; 4143 4144 return $activity_types; 4145 }; 4146 add_filter( 'bp_akismet_get_activity_types', $comment_akismet_history ); 4147 4148 // Make sure the activity change won't edit the comment if sync is on 4149 remove_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 ); 4150 4151 // Save the updated activity 4152 $activity->save(); 4153 4154 // Restore the action 4155 add_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 ); 4156 4157 // Remove the "new_blog_comment" activity type whitelist so we don't break anything 4158 remove_filter( 'bp_akismet_get_activity_types', $comment_akismet_history ); 4159 } 4160 add_action( 'transition_comment_status', 'bp_activity_transition_post_type_comment_status', 10, 3 ); -
src/bp-activity/bp-activity-screens.php
260 260 $url = bp_loggedin_user_domain(); 261 261 262 262 } else { 263 $url = sprintf( 264 wp_login_url( 'wp-login.php?redirect_to=%s' ), 265 esc_url_raw( bp_activity_get_permalink( $action ) ) 266 ); 263 $url = wp_login_url( bp_activity_get_permalink( $action ) ); 267 264 } 268 265 269 266 bp_core_redirect( $url ); … … 283 280 } 284 281 add_action( 'bp_screens', 'bp_activity_screen_single_activity_permalink' ); 285 282 286 /**287 * Add activity notifications settings to the notifications settings page.288 *289 * @since 1.2.0290 *291 */292 function bp_activity_screen_notification_settings() {293 294 if ( bp_activity_do_mentions() ) {295 if ( ! $mention = bp_get_user_meta( bp_displayed_user_id(), 'notification_activity_new_mention', true ) ) {296 $mention = 'yes';297 }298 }299 300 if ( ! $reply = bp_get_user_meta( bp_displayed_user_id(), 'notification_activity_new_reply', true ) ) {301 $reply = 'yes';302 }303 304 ?>305 306 <table class="notification-settings" id="activity-notification-settings">307 <thead>308 <tr>309 <th class="icon"> </th>310 <th class="title"><?php _e( 'Activity', 'buddypress' ) ?></th>311 <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>312 <th class="no"><?php _e( 'No', 'buddypress' )?></th>313 </tr>314 </thead>315 316 <tbody>317 <?php if ( bp_activity_do_mentions() ) : ?>318 <tr id="activity-notification-settings-mentions">319 <td> </td>320 <td><?php printf( __( 'A member mentions you in an update using "@%s"', 'buddypress' ), bp_core_get_username( bp_displayed_user_id() ) ) ?></td>321 <td class="yes"><input type="radio" name="notifications[notification_activity_new_mention]" id="notification-activity-new-mention-yes" value="yes" <?php checked( $mention, 'yes', true ) ?>/><label for="notification-activity-new-mention-yes" class="bp-screen-reader-text"><?php322 /* translators: accessibility text */323 _e( 'Yes, send email', 'buddypress' );324 ?></label></td>325 <td class="no"><input type="radio" name="notifications[notification_activity_new_mention]" id="notification-activity-new-mention-no" value="no" <?php checked( $mention, 'no', true ) ?>/><label for="notification-activity-new-mention-no" class="bp-screen-reader-text"><?php326 /* translators: accessibility text */327 _e( 'No, do not send email', 'buddypress' );328 ?></label></td>329 </tr>330 <?php endif; ?>331 332 <tr id="activity-notification-settings-replies">333 <td> </td>334 <td><?php _e( "A member replies to an update or comment you've posted", 'buddypress' ) ?></td>335 <td class="yes"><input type="radio" name="notifications[notification_activity_new_reply]" id="notification-activity-new-reply-yes" value="yes" <?php checked( $reply, 'yes', true ) ?>/><label for="notification-activity-new-reply-yes" class="bp-screen-reader-text"><?php336 /* translators: accessibility text */337 _e( 'Yes, send email', 'buddypress' );338 ?></label></td>339 <td class="no"><input type="radio" name="notifications[notification_activity_new_reply]" id="notification-activity-new-reply-no" value="no" <?php checked( $reply, 'no', true ) ?>/><label for="notification-activity-new-reply-no" class="bp-screen-reader-text"><?php340 /* translators: accessibility text */341 _e( 'No, do not send email', 'buddypress' );342 ?></label></td>343 </tr>344 345 <?php346 347 /**348 * Fires inside the closing </tbody> tag for activity screen notification settings.349 *350 * @since 1.2.0351 */352 do_action( 'bp_activity_screen_notification_settings' ) ?>353 </tbody>354 </table>355 356 <?php357 }358 add_action( 'bp_notification_settings', 'bp_activity_screen_notification_settings', 1 );359 360 283 /** Theme Compatibility *******************************************************/ 361 284 362 285 new BP_Activity_Theme_Compat(); -
new file src/bp-activity/bp-activity-settings.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Activity Settings. 4 * 5 * @package BuddyPress 6 * @subpackage ActivitySettings 7 * @since 2.9.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Add activity notifications settings to the notifications settings page. 15 * 16 * @since 1.2.0 17 * 18 */ 19 function bp_activity_screen_notification_settings() { 20 21 if ( bp_activity_do_mentions() ) { 22 if ( ! $mention = bp_get_user_meta( bp_displayed_user_id(), 'notification_activity_new_mention', true ) ) { 23 $mention = 'yes'; 24 } 25 } 26 27 if ( ! $reply = bp_get_user_meta( bp_displayed_user_id(), 'notification_activity_new_reply', true ) ) { 28 $reply = 'yes'; 29 } 30 31 ?> 32 33 <table class="notification-settings" id="activity-notification-settings"> 34 <thead> 35 <tr> 36 <th class="icon"> </th> 37 <th class="title"><?php _e( 'Activity', 'buddypress' ) ?></th> 38 <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th> 39 <th class="no"><?php _e( 'No', 'buddypress' )?></th> 40 </tr> 41 </thead> 42 43 <tbody> 44 <?php if ( bp_activity_do_mentions() ) : ?> 45 <tr id="activity-notification-settings-mentions"> 46 <td> </td> 47 <td><?php printf( __( 'A member mentions you in an update using "@%s"', 'buddypress' ), bp_core_get_username( bp_displayed_user_id() ) ) ?></td> 48 <td class="yes"><input type="radio" name="notifications[notification_activity_new_mention]" id="notification-activity-new-mention-yes" value="yes" <?php checked( $mention, 'yes', true ) ?>/><label for="notification-activity-new-mention-yes" class="bp-screen-reader-text"><?php 49 /* translators: accessibility text */ 50 _e( 'Yes, send email', 'buddypress' ); 51 ?></label></td> 52 <td class="no"><input type="radio" name="notifications[notification_activity_new_mention]" id="notification-activity-new-mention-no" value="no" <?php checked( $mention, 'no', true ) ?>/><label for="notification-activity-new-mention-no" class="bp-screen-reader-text"><?php 53 /* translators: accessibility text */ 54 _e( 'No, do not send email', 'buddypress' ); 55 ?></label></td> 56 </tr> 57 <?php endif; ?> 58 59 <tr id="activity-notification-settings-replies"> 60 <td> </td> 61 <td><?php _e( "A member replies to an update or comment you've posted", 'buddypress' ) ?></td> 62 <td class="yes"><input type="radio" name="notifications[notification_activity_new_reply]" id="notification-activity-new-reply-yes" value="yes" <?php checked( $reply, 'yes', true ) ?>/><label for="notification-activity-new-reply-yes" class="bp-screen-reader-text"><?php 63 /* translators: accessibility text */ 64 _e( 'Yes, send email', 'buddypress' ); 65 ?></label></td> 66 <td class="no"><input type="radio" name="notifications[notification_activity_new_reply]" id="notification-activity-new-reply-no" value="no" <?php checked( $reply, 'no', true ) ?>/><label for="notification-activity-new-reply-no" class="bp-screen-reader-text"><?php 67 /* translators: accessibility text */ 68 _e( 'No, do not send email', 'buddypress' ); 69 ?></label></td> 70 </tr> 71 72 <?php 73 74 /** 75 * Fires inside the closing </tbody> tag for activity screen notification settings. 76 * 77 * @since 1.2.0 78 */ 79 do_action( 'bp_activity_screen_notification_settings' ) ?> 80 </tbody> 81 </table> 82 83 <?php 84 } 85 add_action( 'bp_notification_settings', 'bp_activity_screen_notification_settings', 1 ); 86 No newline at end of file -
src/bp-activity/classes/class-bp-activity-component.php
51 51 // Files to include. 52 52 $includes = array( 53 53 'cssjs', 54 'actions',55 'screens',56 54 'filters', 57 55 'adminbar', 58 56 'template', … … 85 83 parent::includes( $includes ); 86 84 } 87 85 86 /** 87 * Late includes method. 88 * 89 * Only load up certain code when on specific pages. 90 * 91 * @since 3.0.0 92 */ 93 public function late_includes() { 94 /* 95 * Laod activity action and screen code if PHPUnit isn't running. 96 * 97 * For PHPUnit, we load these files in tests/phpunit/includes/install.php. 98 */ 99 if ( bp_is_current_component( 'activity' ) && ! defined( 'BP_TESTS_DIR' ) ) { 100 require $this->path . 'bp-activity/bp-activity-actions.php'; 101 require $this->path . 'bp-activity/bp-activity-screens.php'; 102 } 103 104 // Activity notifications HTML table. 105 if ( bp_is_user_settings_notifications() ) { 106 require $this->path . 'bp-activity/bp-activity-settings.php'; 107 } 108 109 // RSS feeds. 110 if ( bp_is_current_action( 'feed' ) || bp_is_action_variable( 'feed', 0 ) ) { 111 require $this->path . 'bp-activity/bp-activity-feeds.php'; 112 } 113 } 114 88 115 /** 89 116 * Set up component global variables. 90 117 * -
src/bp-core/bp-core-actions.php
85 85 */ 86 86 add_action( 'bp_register_taxonomies', 'bp_register_member_types' ); 87 87 88 /** 89 * Late includes. 90 * 91 * Run after the canonical stack is setup to allow for conditional includes 92 * on certain pages. 93 */ 94 add_action( 'bp_setup_canonical_stack', 'bp_late_include', 20 ); 95 88 96 /** 89 97 * The bp_template_redirect hook - Attached to 'template_redirect' above. 90 98 * -
src/bp-core/bp-core-dependency.php
33 33 do_action( 'bp_include' ); 34 34 } 35 35 36 /** 37 * Fire the 'bp_late_include' action for loading conditional files. 38 * 39 * @since 3.0.0 40 */ 41 function bp_late_include() { 42 43 /** 44 * Fires the 'bp_late_include' action. 45 * 46 * Allow for conditional includes on certain pages. 47 * 48 * @since 3.0.0 49 */ 50 do_action( 'bp_late_include' ); 51 } 52 36 53 /** 37 54 * Fire the 'bp_setup_components' action, where plugins should initialize components. 38 55 * -
src/bp-core/classes/class-bp-component.php
393 393 do_action( 'bp_' . $this->id . '_includes' ); 394 394 } 395 395 396 /** 397 * Late includes method. 398 * 399 * Components should include files here only on specific pages using 400 * conditionals such as {@link bp_is_current_component()}. Intentionally left 401 * empty. 402 * 403 * @since 3.0.0 404 */ 405 public function late_includes() {} 406 396 407 /** 397 408 * Set up the actions. 398 409 * … … 414 425 // extending this base class. 415 426 add_action( 'bp_include', array( $this, 'includes' ), 8 ); 416 427 428 // Load files conditionally, based on certain pages. 429 add_action( 'bp_late_include', array( $this, 'late_includes' ) ); 430 417 431 // Setup navigation. 418 432 add_action( 'bp_setup_nav', array( $this, 'setup_nav' ), 10 ); 419 433 -
tests/phpunit/includes/loader.php
13 13 return 'BP_UnitTest_Mailer'; 14 14 } 15 15 tests_add_filter( 'bp_send_email_delivery_class', '_bp_mock_mailer' ); 16 17 /** 18 * Load up activity action and screen code. 19 * 20 * In BuddyPress, this is loaded conditionally, but PHPUnit needs all files 21 * loaded at the same time to prevent weird load order issues. 22 */ 23 add_action( 'bp_activity_includes', function() { 24 require buddypress()->plugin_dir . 'bp-activity/bp-activity-actions.php'; 25 require buddypress()->plugin_dir . 'bp-activity/bp-activity-screens.php'; 26 } ); 27 No newline at end of file