Ticket #7218: 7218.activity-ray-ocd.patch
File 7218.activity-ray-ocd.patch, 86.2 KB (added by , 7 years ago) |
---|
-
new file src/bp-activity/actions/delete.php
new file mode 100644
- + 1 <?php 2 3 /** 4 * Delete specific activity item and redirect to previous page. 5 * 6 * @since 1.1.0 7 * 8 * @param int $activity_id Activity id to be deleted. Defaults to 0. 9 * @return bool False on failure. 10 */ 11 function bp_activity_action_delete_activity( $activity_id = 0 ) { 12 13 // Not viewing activity or action is not delete. 14 if ( !bp_is_activity_component() || !bp_is_current_action( 'delete' ) ) 15 return false; 16 17 if ( empty( $activity_id ) && bp_action_variable( 0 ) ) 18 $activity_id = (int) bp_action_variable( 0 ); 19 20 // Not viewing a specific activity item. 21 if ( empty( $activity_id ) ) 22 return false; 23 24 // Check the nonce. 25 check_admin_referer( 'bp_activity_delete_link' ); 26 27 // Load up the activity item. 28 $activity = new BP_Activity_Activity( $activity_id ); 29 30 // Check access. 31 if ( ! bp_activity_user_can_delete( $activity ) ) 32 return false; 33 34 /** 35 * Fires before the deletion so plugins can still fetch information about it. 36 * 37 * @since 1.5.0 38 * 39 * @param int $activity_id The activity ID. 40 * @param int $user_id The user associated with the activity. 41 */ 42 do_action( 'bp_activity_before_action_delete_activity', $activity_id, $activity->user_id ); 43 44 // Delete the activity item and provide user feedback. 45 if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) ) 46 bp_core_add_message( __( 'Activity deleted successfully', 'buddypress' ) ); 47 else 48 bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' ); 49 50 /** 51 * Fires after the deletion so plugins can act afterwards based on the activity. 52 * 53 * @since 1.1.0 54 * 55 * @param int $activity_id The activity ID. 56 * @param int $user_id The user associated with the activity. 57 */ 58 do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id ); 59 60 // Check for the redirect query arg, otherwise let WP handle things. 61 if ( !empty( $_GET['redirect_to'] ) ) 62 bp_core_redirect( esc_url( $_GET['redirect_to'] ) ); 63 else 64 bp_core_redirect( wp_get_referer() ); 65 } 66 add_action( 'bp_actions', 'bp_activity_action_delete_activity' ); 67 No newline at end of file -
new file src/bp-activity/actions/favorite.php
new file mode 100644
- + 1 <?php 2 3 /** 4 * Mark activity as favorite. 5 * 6 * @since 1.2.0 7 * 8 * @return bool False on failure. 9 */ 10 function bp_activity_action_mark_favorite() { 11 12 if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'favorite' ) ) 13 return false; 14 15 // Check the nonce. 16 check_admin_referer( 'mark_favorite' ); 17 18 if ( bp_activity_add_user_favorite( bp_action_variable( 0 ) ) ) 19 bp_core_add_message( __( 'Activity marked as favorite.', 'buddypress' ) ); 20 else 21 bp_core_add_message( __( 'There was an error marking that activity as a favorite. Please try again.', 'buddypress' ), 'error' ); 22 23 bp_core_redirect( wp_get_referer() . '#activity-' . bp_action_variable( 0 ) ); 24 } 25 add_action( 'bp_actions', 'bp_activity_action_mark_favorite' ); 26 No newline at end of file -
new file src/bp-activity/actions/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' ); -
new file src/bp-activity/actions/post.php
new file mode 100644
- + 1 <?php 2 3 /** 4 * Post user/group activity update. 5 * 6 * @since 1.2.0 7 * 8 * @return bool False on failure. 9 */ 10 function bp_activity_action_post_update() { 11 12 // Do not proceed if user is not logged in, not viewing activity, or not posting. 13 if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'post' ) ) 14 return false; 15 16 // Check the nonce. 17 check_admin_referer( 'post_update', '_wpnonce_post_update' ); 18 19 /** 20 * Filters the content provided in the activity input field. 21 * 22 * @since 1.2.0 23 * 24 * @param string $value Activity message being posted. 25 */ 26 $content = apply_filters( 'bp_activity_post_update_content', $_POST['whats-new'] ); 27 28 if ( ! empty( $_POST['whats-new-post-object'] ) ) { 29 30 /** 31 * Filters the item type that the activity update should be associated with. 32 * 33 * @since 1.2.0 34 * 35 * @param string $value Item type to associate with. 36 */ 37 $object = apply_filters( 'bp_activity_post_update_object', $_POST['whats-new-post-object'] ); 38 } 39 40 if ( ! empty( $_POST['whats-new-post-in'] ) ) { 41 42 /** 43 * Filters what component the activity is being to. 44 * 45 * @since 1.2.0 46 * 47 * @param string $value Chosen component to post activity to. 48 */ 49 $item_id = apply_filters( 'bp_activity_post_update_item_id', $_POST['whats-new-post-in'] ); 50 } 51 52 // No activity content so provide feedback and redirect. 53 if ( empty( $content ) ) { 54 bp_core_add_message( __( 'Please enter some content to post.', 'buddypress' ), 'error' ); 55 bp_core_redirect( wp_get_referer() ); 56 } 57 58 // No existing item_id. 59 if ( empty( $item_id ) ) { 60 $activity_id = bp_activity_post_update( array( 'content' => $content ) ); 61 62 // Post to groups object. 63 } elseif ( 'groups' == $object && bp_is_active( 'groups' ) ) { 64 if ( (int) $item_id ) { 65 $activity_id = groups_post_update( array( 'content' => $content, 'group_id' => $item_id ) ); 66 } 67 68 } else { 69 70 /** 71 * Filters activity object for BuddyPress core and plugin authors before posting activity update. 72 * 73 * @since 1.2.0 74 * 75 * @param string $object Activity item being associated to. 76 * @param string $item_id Component ID being posted to. 77 * @param string $content Activity content being posted. 78 */ 79 $activity_id = apply_filters( 'bp_activity_custom_update', $object, $item_id, $content ); 80 } 81 82 // Provide user feedback. 83 if ( !empty( $activity_id ) ) 84 bp_core_add_message( __( 'Update Posted!', 'buddypress' ) ); 85 else 86 bp_core_add_message( __( 'There was an error when posting your update. Please try again.', 'buddypress' ), 'error' ); 87 88 // Redirect. 89 bp_core_redirect( wp_get_referer() ); 90 } 91 add_action( 'bp_actions', 'bp_activity_action_post_update' ); 92 No newline at end of file -
new file src/bp-activity/actions/reply.php
new file mode 100644
- + 1 <?php 2 3 /** 4 * Post new activity comment. 5 * 6 * @since 1.2.0 7 * 8 * @return bool False on failure. 9 */ 10 function bp_activity_action_post_comment() { 11 12 if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'reply' ) ) 13 return false; 14 15 // Check the nonce. 16 check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' ); 17 18 /** 19 * Filters the activity ID a comment will be in reply to. 20 * 21 * @since 1.2.0 22 * 23 * @param string $value ID of the activity being replied to. 24 */ 25 $activity_id = apply_filters( 'bp_activity_post_comment_activity_id', $_POST['comment_form_id'] ); 26 27 /** 28 * Filters the comment content for a comment reply. 29 * 30 * @since 1.2.0 31 * 32 * @param string $value Comment content being posted. 33 */ 34 $content = apply_filters( 'bp_activity_post_comment_content', $_POST['ac_input_' . $activity_id] ); 35 36 if ( empty( $content ) ) { 37 bp_core_add_message( __( 'Please do not leave the comment area blank.', 'buddypress' ), 'error' ); 38 bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id ); 39 } 40 41 $comment_id = bp_activity_new_comment( array( 42 'content' => $content, 43 'activity_id' => $activity_id, 44 'parent_id' => false 45 )); 46 47 if ( !empty( $comment_id ) ) 48 bp_core_add_message( __( 'Reply Posted!', 'buddypress' ) ); 49 else 50 bp_core_add_message( __( 'There was an error posting that reply. Please try again.', 'buddypress' ), 'error' ); 51 52 bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id ); 53 } 54 add_action( 'bp_actions', 'bp_activity_action_post_comment' ); 55 No newline at end of file -
new file src/bp-activity/actions/spam.php
new file mode 100644
- + 1 <?php 2 3 /** 4 * Mark specific activity item as spam and redirect to previous page. 5 * 6 * @since 1.6.0 7 * 8 * @param int $activity_id Activity id to be deleted. Defaults to 0. 9 * @return bool False on failure. 10 */ 11 function bp_activity_action_spam_activity( $activity_id = 0 ) { 12 $bp = buddypress(); 13 14 // Not viewing activity, or action is not spam, or Akismet isn't present. 15 if ( !bp_is_activity_component() || !bp_is_current_action( 'spam' ) || empty( $bp->activity->akismet ) ) 16 return false; 17 18 if ( empty( $activity_id ) && bp_action_variable( 0 ) ) 19 $activity_id = (int) bp_action_variable( 0 ); 20 21 // Not viewing a specific activity item. 22 if ( empty( $activity_id ) ) 23 return false; 24 25 // Is the current user allowed to spam items? 26 if ( !bp_activity_user_can_mark_spam() ) 27 return false; 28 29 // Load up the activity item. 30 $activity = new BP_Activity_Activity( $activity_id ); 31 if ( empty( $activity->id ) ) 32 return false; 33 34 // Check nonce. 35 check_admin_referer( 'bp_activity_akismet_spam_' . $activity->id ); 36 37 /** 38 * Fires before the marking activity as spam so plugins can modify things if they want to. 39 * 40 * @since 1.6.0 41 * 42 * @param int $activity_id Activity ID to be marked as spam. 43 * @param object $activity Activity object for the ID to be marked as spam. 44 */ 45 do_action( 'bp_activity_before_action_spam_activity', $activity->id, $activity ); 46 47 // Mark as spam. 48 bp_activity_mark_as_spam( $activity ); 49 $activity->save(); 50 51 // Tell the user the spamming has been successful. 52 bp_core_add_message( __( 'The activity item has been marked as spam and is no longer visible.', 'buddypress' ) ); 53 54 /** 55 * Fires after the marking activity as spam so plugins can act afterwards based on the activity. 56 * 57 * @since 1.6.0 58 * 59 * @param int $activity_id Activity ID that was marked as spam. 60 * @param int $user_id User ID associated with activity. 61 */ 62 do_action( 'bp_activity_action_spam_activity', $activity_id, $activity->user_id ); 63 64 // Check for the redirect query arg, otherwise let WP handle things. 65 if ( !empty( $_GET['redirect_to'] ) ) 66 bp_core_redirect( esc_url( $_GET['redirect_to'] ) ); 67 else 68 bp_core_redirect( wp_get_referer() ); 69 } 70 add_action( 'bp_actions', 'bp_activity_action_spam_activity' ); 71 No newline at end of file -
new file src/bp-activity/actions/unfavorite.php
new file mode 100644
- + 1 <?php 2 3 /** 4 * Remove activity from favorites. 5 * 6 * @since 1.2.0 7 * 8 * @return bool False on failure. 9 */ 10 function bp_activity_action_remove_favorite() { 11 12 if ( ! is_user_logged_in() || ! bp_is_activity_component() || ! bp_is_current_action( 'unfavorite' ) ) 13 return false; 14 15 // Check the nonce. 16 check_admin_referer( 'unmark_favorite' ); 17 18 if ( bp_activity_remove_user_favorite( bp_action_variable( 0 ) ) ) 19 bp_core_add_message( __( 'Activity removed as favorite.', 'buddypress' ) ); 20 else 21 bp_core_add_message( __( 'There was an error removing that activity as a favorite. Please try again.', 'buddypress' ), 'error' ); 22 23 bp_core_redirect( wp_get_referer() . '#activity-' . bp_action_variable( 0 ) ); 24 } 25 add_action( 'bp_actions', 'bp_activity_action_remove_favorite' ); 26 No newline at end of file -
deleted file src/bp-activity/bp-activity-actions.php
deleted file mode 100644
+ - 1 <?php2 /**3 * Action functions are exactly the same as screen functions, however they do4 * not have a template screen associated with them. Usually they will send the5 * user back to the default screen after execution.6 *7 * @package BuddyPress8 * @subpackage ActivityActions9 * @since 1.5.010 */11 12 // Exit if accessed directly.13 defined( 'ABSPATH' ) || exit;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 /**33 * Catch and route requests for single activity item permalinks.34 *35 * @since 1.2.036 *37 * @return bool False on failure.38 */39 function bp_activity_action_permalink_router() {40 41 // Not viewing activity.42 if ( ! bp_is_activity_component() || ! bp_is_current_action( 'p' ) )43 return false;44 45 // No activity to display.46 if ( ! bp_action_variable( 0 ) || ! is_numeric( bp_action_variable( 0 ) ) )47 return false;48 49 // Get the activity details.50 $activity = bp_activity_get_specific( array( 'activity_ids' => bp_action_variable( 0 ), 'show_hidden' => true ) );51 52 // 404 if activity does not exist53 if ( empty( $activity['activities'][0] ) ) {54 bp_do_404();55 return;56 } else {57 $activity = $activity['activities'][0];58 }59 60 // Do not redirect at default.61 $redirect = false;62 63 // Redirect based on the type of activity.64 if ( bp_is_active( 'groups' ) && $activity->component == buddypress()->groups->id ) {65 66 // Activity is a user update.67 if ( ! empty( $activity->user_id ) ) {68 $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/';69 70 // Activity is something else.71 } else {72 73 // Set redirect to group activity stream.74 if ( $group = groups_get_group( $activity->item_id ) ) {75 $redirect = bp_get_group_permalink( $group ) . bp_get_activity_slug() . '/' . $activity->id . '/';76 }77 }78 79 // Set redirect to users' activity stream.80 } elseif ( ! empty( $activity->user_id ) ) {81 $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/';82 }83 84 // If set, add the original query string back onto the redirect URL.85 if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {86 $query_frags = array();87 wp_parse_str( $_SERVER['QUERY_STRING'], $query_frags );88 $redirect = add_query_arg( urlencode_deep( $query_frags ), $redirect );89 }90 91 /**92 * Filter the intended redirect url before the redirect occurs for the single activity item.93 *94 * @since 1.2.295 *96 * @param array $value Array with url to redirect to and activity related to the redirect.97 */98 if ( ! $redirect = apply_filters_ref_array( 'bp_activity_permalink_redirect_url', array( $redirect, &$activity ) ) ) {99 bp_core_redirect( bp_get_root_domain() );100 }101 102 // Redirect to the actual activity permalink page.103 bp_core_redirect( $redirect );104 }105 add_action( 'bp_actions', 'bp_activity_action_permalink_router' );106 107 /**108 * Delete specific activity item and redirect to previous page.109 *110 * @since 1.1.0111 *112 * @param int $activity_id Activity id to be deleted. Defaults to 0.113 * @return bool False on failure.114 */115 function bp_activity_action_delete_activity( $activity_id = 0 ) {116 117 // Not viewing activity or action is not delete.118 if ( !bp_is_activity_component() || !bp_is_current_action( 'delete' ) )119 return false;120 121 if ( empty( $activity_id ) && bp_action_variable( 0 ) )122 $activity_id = (int) bp_action_variable( 0 );123 124 // Not viewing a specific activity item.125 if ( empty( $activity_id ) )126 return false;127 128 // Check the nonce.129 check_admin_referer( 'bp_activity_delete_link' );130 131 // Load up the activity item.132 $activity = new BP_Activity_Activity( $activity_id );133 134 // Check access.135 if ( ! bp_activity_user_can_delete( $activity ) )136 return false;137 138 /**139 * Fires before the deletion so plugins can still fetch information about it.140 *141 * @since 1.5.0142 *143 * @param int $activity_id The activity ID.144 * @param int $user_id The user associated with the activity.145 */146 do_action( 'bp_activity_before_action_delete_activity', $activity_id, $activity->user_id );147 148 // Delete the activity item and provide user feedback.149 if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) )150 bp_core_add_message( __( 'Activity deleted successfully', 'buddypress' ) );151 else152 bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' );153 154 /**155 * Fires after the deletion so plugins can act afterwards based on the activity.156 *157 * @since 1.1.0158 *159 * @param int $activity_id The activity ID.160 * @param int $user_id The user associated with the activity.161 */162 do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id );163 164 // Check for the redirect query arg, otherwise let WP handle things.165 if ( !empty( $_GET['redirect_to'] ) )166 bp_core_redirect( esc_url( $_GET['redirect_to'] ) );167 else168 bp_core_redirect( wp_get_referer() );169 }170 add_action( 'bp_actions', 'bp_activity_action_delete_activity' );171 172 /**173 * Mark specific activity item as spam and redirect to previous page.174 *175 * @since 1.6.0176 *177 * @param int $activity_id Activity id to be deleted. Defaults to 0.178 * @return bool False on failure.179 */180 function bp_activity_action_spam_activity( $activity_id = 0 ) {181 $bp = buddypress();182 183 // Not viewing activity, or action is not spam, or Akismet isn't present.184 if ( !bp_is_activity_component() || !bp_is_current_action( 'spam' ) || empty( $bp->activity->akismet ) )185 return false;186 187 if ( empty( $activity_id ) && bp_action_variable( 0 ) )188 $activity_id = (int) bp_action_variable( 0 );189 190 // Not viewing a specific activity item.191 if ( empty( $activity_id ) )192 return false;193 194 // Is the current user allowed to spam items?195 if ( !bp_activity_user_can_mark_spam() )196 return false;197 198 // Load up the activity item.199 $activity = new BP_Activity_Activity( $activity_id );200 if ( empty( $activity->id ) )201 return false;202 203 // Check nonce.204 check_admin_referer( 'bp_activity_akismet_spam_' . $activity->id );205 206 /**207 * Fires before the marking activity as spam so plugins can modify things if they want to.208 *209 * @since 1.6.0210 *211 * @param int $activity_id Activity ID to be marked as spam.212 * @param object $activity Activity object for the ID to be marked as spam.213 */214 do_action( 'bp_activity_before_action_spam_activity', $activity->id, $activity );215 216 // Mark as spam.217 bp_activity_mark_as_spam( $activity );218 $activity->save();219 220 // Tell the user the spamming has been successful.221 bp_core_add_message( __( 'The activity item has been marked as spam and is no longer visible.', 'buddypress' ) );222 223 /**224 * Fires after the marking activity as spam so plugins can act afterwards based on the activity.225 *226 * @since 1.6.0227 *228 * @param int $activity_id Activity ID that was marked as spam.229 * @param int $user_id User ID associated with activity.230 */231 do_action( 'bp_activity_action_spam_activity', $activity_id, $activity->user_id );232 233 // Check for the redirect query arg, otherwise let WP handle things.234 if ( !empty( $_GET['redirect_to'] ) )235 bp_core_redirect( esc_url( $_GET['redirect_to'] ) );236 else237 bp_core_redirect( wp_get_referer() );238 }239 add_action( 'bp_actions', 'bp_activity_action_spam_activity' );240 241 /**242 * Post user/group activity update.243 *244 * @since 1.2.0245 *246 * @return bool False on failure.247 */248 function bp_activity_action_post_update() {249 250 // Do not proceed if user is not logged in, not viewing activity, or not posting.251 if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'post' ) )252 return false;253 254 // Check the nonce.255 check_admin_referer( 'post_update', '_wpnonce_post_update' );256 257 /**258 * Filters the content provided in the activity input field.259 *260 * @since 1.2.0261 *262 * @param string $value Activity message being posted.263 */264 $content = apply_filters( 'bp_activity_post_update_content', $_POST['whats-new'] );265 266 if ( ! empty( $_POST['whats-new-post-object'] ) ) {267 268 /**269 * Filters the item type that the activity update should be associated with.270 *271 * @since 1.2.0272 *273 * @param string $value Item type to associate with.274 */275 $object = apply_filters( 'bp_activity_post_update_object', $_POST['whats-new-post-object'] );276 }277 278 if ( ! empty( $_POST['whats-new-post-in'] ) ) {279 280 /**281 * Filters what component the activity is being to.282 *283 * @since 1.2.0284 *285 * @param string $value Chosen component to post activity to.286 */287 $item_id = apply_filters( 'bp_activity_post_update_item_id', $_POST['whats-new-post-in'] );288 }289 290 // No activity content so provide feedback and redirect.291 if ( empty( $content ) ) {292 bp_core_add_message( __( 'Please enter some content to post.', 'buddypress' ), 'error' );293 bp_core_redirect( wp_get_referer() );294 }295 296 // No existing item_id.297 if ( empty( $item_id ) ) {298 $activity_id = bp_activity_post_update( array( 'content' => $content ) );299 300 // Post to groups object.301 } elseif ( 'groups' == $object && bp_is_active( 'groups' ) ) {302 if ( (int) $item_id ) {303 $activity_id = groups_post_update( array( 'content' => $content, 'group_id' => $item_id ) );304 }305 306 } else {307 308 /**309 * Filters activity object for BuddyPress core and plugin authors before posting activity update.310 *311 * @since 1.2.0312 *313 * @param string $object Activity item being associated to.314 * @param string $item_id Component ID being posted to.315 * @param string $content Activity content being posted.316 */317 $activity_id = apply_filters( 'bp_activity_custom_update', $object, $item_id, $content );318 }319 320 // Provide user feedback.321 if ( !empty( $activity_id ) )322 bp_core_add_message( __( 'Update Posted!', 'buddypress' ) );323 else324 bp_core_add_message( __( 'There was an error when posting your update. Please try again.', 'buddypress' ), 'error' );325 326 // Redirect.327 bp_core_redirect( wp_get_referer() );328 }329 add_action( 'bp_actions', 'bp_activity_action_post_update' );330 331 /**332 * Post new activity comment.333 *334 * @since 1.2.0335 *336 * @return bool False on failure.337 */338 function bp_activity_action_post_comment() {339 340 if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'reply' ) )341 return false;342 343 // Check the nonce.344 check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );345 346 /**347 * Filters the activity ID a comment will be in reply to.348 *349 * @since 1.2.0350 *351 * @param string $value ID of the activity being replied to.352 */353 $activity_id = apply_filters( 'bp_activity_post_comment_activity_id', $_POST['comment_form_id'] );354 355 /**356 * Filters the comment content for a comment reply.357 *358 * @since 1.2.0359 *360 * @param string $value Comment content being posted.361 */362 $content = apply_filters( 'bp_activity_post_comment_content', $_POST['ac_input_' . $activity_id] );363 364 if ( empty( $content ) ) {365 bp_core_add_message( __( 'Please do not leave the comment area blank.', 'buddypress' ), 'error' );366 bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );367 }368 369 $comment_id = bp_activity_new_comment( array(370 'content' => $content,371 'activity_id' => $activity_id,372 'parent_id' => false373 ));374 375 if ( !empty( $comment_id ) )376 bp_core_add_message( __( 'Reply Posted!', 'buddypress' ) );377 else378 bp_core_add_message( __( 'There was an error posting that reply. Please try again.', 'buddypress' ), 'error' );379 380 bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );381 }382 add_action( 'bp_actions', 'bp_activity_action_post_comment' );383 384 /**385 * Mark activity as favorite.386 *387 * @since 1.2.0388 *389 * @return bool False on failure.390 */391 function bp_activity_action_mark_favorite() {392 393 if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'favorite' ) )394 return false;395 396 // Check the nonce.397 check_admin_referer( 'mark_favorite' );398 399 if ( bp_activity_add_user_favorite( bp_action_variable( 0 ) ) )400 bp_core_add_message( __( 'Activity marked as favorite.', 'buddypress' ) );401 else402 bp_core_add_message( __( 'There was an error marking that activity as a favorite. Please try again.', 'buddypress' ), 'error' );403 404 bp_core_redirect( wp_get_referer() . '#activity-' . bp_action_variable( 0 ) );405 }406 add_action( 'bp_actions', 'bp_activity_action_mark_favorite' );407 408 /**409 * Remove activity from favorites.410 *411 * @since 1.2.0412 *413 * @return bool False on failure.414 */415 function bp_activity_action_remove_favorite() {416 417 if ( ! is_user_logged_in() || ! bp_is_activity_component() || ! bp_is_current_action( 'unfavorite' ) )418 return false;419 420 // Check the nonce.421 check_admin_referer( 'unmark_favorite' );422 423 if ( bp_activity_remove_user_favorite( bp_action_variable( 0 ) ) )424 bp_core_add_message( __( 'Activity removed as favorite.', 'buddypress' ) );425 else426 bp_core_add_message( __( 'There was an error removing that activity as a favorite. Please try again.', 'buddypress' ), 'error' );427 428 bp_core_redirect( wp_get_referer() . '#activity-' . bp_action_variable( 0 ) );429 }430 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 ); -
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 ); -
deleted file src/bp-activity/bp-activity-screens.php
deleted file mode 100644
+ - 1 <?php2 /**3 * BuddyPress Activity Screens.4 *5 * The functions in this file detect, with each page load, whether an Activity6 * component page is being requested. If so, it parses any necessary data from7 * the URL, and tells BuddyPress to load the appropriate template.8 *9 * @package BuddyPress10 * @subpackage ActivityScreens11 * @since 1.5.012 */13 14 // Exit if accessed directly.15 defined( 'ABSPATH' ) || exit;16 17 /**18 * Load the Activity directory.19 *20 * @since 1.5.021 *22 */23 function bp_activity_screen_index() {24 if ( bp_is_activity_directory() ) {25 bp_update_is_directory( true, 'activity' );26 27 /**28 * Fires right before the loading of the Activity directory screen template file.29 *30 * @since 1.5.031 */32 do_action( 'bp_activity_screen_index' );33 34 /**35 * Filters the template to load for the Activity directory screen.36 *37 * @since 1.5.038 *39 * @param string $template Path to the activity template to load.40 */41 bp_core_load_template( apply_filters( 'bp_activity_screen_index', 'activity/index' ) );42 }43 }44 add_action( 'bp_screens', 'bp_activity_screen_index' );45 46 /**47 * Load the 'My Activity' page.48 *49 * @since 1.0.050 *51 */52 function bp_activity_screen_my_activity() {53 54 /**55 * Fires right before the loading of the "My Activity" screen template file.56 *57 * @since 1.0.058 */59 do_action( 'bp_activity_screen_my_activity' );60 61 /**62 * Filters the template to load for the "My Activity" screen.63 *64 * @since 1.0.065 *66 * @param string $template Path to the activity template to load.67 */68 bp_core_load_template( apply_filters( 'bp_activity_template_my_activity', 'members/single/home' ) );69 }70 71 /**72 * Load the 'My Friends' activity page.73 *74 * @since 1.0.075 *76 */77 function bp_activity_screen_friends() {78 if ( !bp_is_active( 'friends' ) )79 return false;80 81 bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' );82 83 /**84 * Fires right before the loading of the "My Friends" screen template file.85 *86 * @since 1.2.087 */88 do_action( 'bp_activity_screen_friends' );89 90 /**91 * Filters the template to load for the "My Friends" screen.92 *93 * @since 1.0.094 *95 * @param string $template Path to the activity template to load.96 */97 bp_core_load_template( apply_filters( 'bp_activity_template_friends_activity', 'members/single/home' ) );98 }99 100 /**101 * Load the 'My Groups' activity page.102 *103 * @since 1.2.0104 *105 */106 function bp_activity_screen_groups() {107 if ( !bp_is_active( 'groups' ) )108 return false;109 110 bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' );111 112 /**113 * Fires right before the loading of the "My Groups" screen template file.114 *115 * @since 1.2.0116 */117 do_action( 'bp_activity_screen_groups' );118 119 /**120 * Filters the template to load for the "My Groups" screen.121 *122 * @since 1.2.0123 *124 * @param string $template Path to the activity template to load.125 */126 bp_core_load_template( apply_filters( 'bp_activity_template_groups_activity', 'members/single/home' ) );127 }128 129 /**130 * Load the 'Favorites' activity page.131 *132 * @since 1.2.0133 *134 */135 function bp_activity_screen_favorites() {136 bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' );137 138 /**139 * Fires right before the loading of the "Favorites" screen template file.140 *141 * @since 1.2.0142 */143 do_action( 'bp_activity_screen_favorites' );144 145 /**146 * Filters the template to load for the "Favorites" screen.147 *148 * @since 1.2.0149 *150 * @param string $template Path to the activity template to load.151 */152 bp_core_load_template( apply_filters( 'bp_activity_template_favorite_activity', 'members/single/home' ) );153 }154 155 /**156 * Load the 'Mentions' activity page.157 *158 * @since 1.2.0159 *160 */161 function bp_activity_screen_mentions() {162 bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' );163 164 /**165 * Fires right before the loading of the "Mentions" screen template file.166 *167 * @since 1.2.0168 */169 do_action( 'bp_activity_screen_mentions' );170 171 /**172 * Filters the template to load for the "Mentions" screen.173 *174 * @since 1.2.0175 *176 * @param string $template Path to the activity template to load.177 */178 bp_core_load_template( apply_filters( 'bp_activity_template_mention_activity', 'members/single/home' ) );179 }180 181 /**182 * Reset the logged-in user's new mentions data when he visits his mentions screen.183 *184 * @since 1.5.0185 *186 */187 function bp_activity_reset_my_new_mentions() {188 if ( bp_is_my_profile() )189 bp_activity_clear_new_mentions( bp_loggedin_user_id() );190 }191 add_action( 'bp_activity_screen_mentions', 'bp_activity_reset_my_new_mentions' );192 193 /**194 * Load the page for a single activity item.195 *196 * @since 1.2.0197 *198 * @return bool|string Boolean on false or the template for a single activity item on success.199 */200 function bp_activity_screen_single_activity_permalink() {201 // No displayed user or not viewing activity component.202 if ( ! bp_is_activity_component() ) {203 return false;204 }205 206 $action = bp_current_action();207 if ( ! $action || ! is_numeric( $action ) ) {208 return false;209 }210 211 // Get the activity details.212 $activity = bp_activity_get_specific( array(213 'activity_ids' => $action,214 'show_hidden' => true,215 'spam' => 'ham_only',216 ) );217 218 // 404 if activity does not exist219 if ( empty( $activity['activities'][0] ) || bp_action_variables() ) {220 bp_do_404();221 return;222 223 } else {224 $activity = $activity['activities'][0];225 }226 227 $user_id = bp_displayed_user_id();228 229 /**230 * Check user access to the activity item.231 *232 * @since 3.0.0233 */234 $has_access = bp_activity_user_can_read( $activity, $user_id );235 236 // If activity author does not match displayed user, block access.237 // More info:https://buddypress.trac.wordpress.org/ticket/7048#comment:28238 if ( true === $has_access && $user_id !== $activity->user_id ) {239 $has_access = false;240 }241 242 /**243 * Fires before the loading of a single activity template file.244 *245 * @since 1.2.0246 *247 * @param BP_Activity_Activity $activity Object representing the current activity item being displayed.248 * @param bool $has_access Whether or not the current user has access to view activity.249 */250 do_action( 'bp_activity_screen_single_activity_permalink', $activity, $has_access );251 252 // Access is specifically disallowed.253 if ( false === $has_access ) {254 255 // User feedback.256 bp_core_add_message( __( 'You do not have access to this activity.', 'buddypress' ), 'error' );257 258 // Redirect based on logged in status.259 if ( is_user_logged_in() ) {260 $url = bp_loggedin_user_domain();261 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 );267 }268 269 bp_core_redirect( $url );270 }271 272 /**273 * Filters the template to load for a single activity screen.274 *275 * @since 1.0.0276 *277 * @param string $template Path to the activity template to load.278 */279 $template = apply_filters( 'bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink' );280 281 // Load the template.282 bp_core_load_template( $template );283 }284 add_action( 'bp_screens', 'bp_activity_screen_single_activity_permalink' );285 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 /** Theme Compatibility *******************************************************/361 362 new BP_Activity_Theme_Compat(); -
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 // Bail if PHPUnit is running. 95 if ( defined( 'BP_TESTS_DIR' ) ) { 96 return; 97 } 98 99 /* 100 * Load activity action and screen code if PHPUnit isn't running. 101 * 102 * For PHPUnit, we load these files in tests/phpunit/includes/install.php. 103 */ 104 if ( bp_is_current_component( 'activity' ) ) { 105 // Authenticated actions - Only fires when JS is disabled. 106 if ( is_user_logged_in() && 107 in_array( bp_current_action(), array( 'delete', 'spam', 'post', 'reply', 'favorite', 'unfavorite' ), true ) 108 ) { 109 require $this->path . 'bp-activity/actions/' . bp_current_action() . '.php'; 110 } 111 112 // RSS feeds. 113 if ( bp_is_current_action( 'feed' ) || bp_is_action_variable( 'feed', 0 ) ) { 114 require $this->path . 'bp-activity/actions/feeds.php'; 115 } 116 117 // Screens - Directory. 118 if ( bp_is_activity_directory() ) { 119 require $this->path . 'bp-activity/screens/directory.php'; 120 } 121 122 // Screens - User main nav. 123 if ( bp_is_user() ) { 124 require $this->path . 'bp-activity/screens/just-me.php'; 125 } 126 127 // Screens - User secondary nav. 128 if ( bp_is_user() && in_array( bp_current_action(), array( 'friends', 'groups', 'favorites', 'mentions' ), true ) ) { 129 require $this->path . 'bp-activity/screens/' . bp_current_action() . '.php'; 130 } 131 132 // Screens - Single permalink. 133 if ( bp_is_current_action( 'p' ) || is_numeric( bp_current_action() ) ) { 134 require $this->path . 'bp-activity/screens/permalink.php'; 135 } 136 137 // Theme compatibility. 138 new BP_Activity_Theme_Compat(); 139 } 140 141 // Activity notifications HTML table. 142 if ( bp_is_user_settings_notifications() ) { 143 require $this->path . 'bp-activity/screens/settings-email.php'; 144 } 145 } 146 88 147 /** 89 148 * Set up component global variables. 90 149 * -
new file src/bp-activity/screens/directory.php
new file mode 100644
- + 1 <?php 2 3 /** 4 * Load the Activity directory. 5 * 6 * @since 1.5.0 7 * 8 */ 9 function bp_activity_screen_index() { 10 if ( bp_is_activity_directory() ) { 11 bp_update_is_directory( true, 'activity' ); 12 13 /** 14 * Fires right before the loading of the Activity directory screen template file. 15 * 16 * @since 1.5.0 17 */ 18 do_action( 'bp_activity_screen_index' ); 19 20 /** 21 * Filters the template to load for the Activity directory screen. 22 * 23 * @since 1.5.0 24 * 25 * @param string $template Path to the activity template to load. 26 */ 27 bp_core_load_template( apply_filters( 'bp_activity_screen_index', 'activity/index' ) ); 28 } 29 } 30 add_action( 'bp_screens', 'bp_activity_screen_index' ); 31 No newline at end of file -
new file src/bp-activity/screens/favorites.php
new file mode 100644
- + 1 <?php 2 3 /** 4 * Load the 'Favorites' activity page. 5 * 6 * @since 1.2.0 7 * 8 */ 9 function bp_activity_screen_favorites() { 10 bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' ); 11 12 /** 13 * Fires right before the loading of the "Favorites" screen template file. 14 * 15 * @since 1.2.0 16 */ 17 do_action( 'bp_activity_screen_favorites' ); 18 19 /** 20 * Filters the template to load for the "Favorites" screen. 21 * 22 * @since 1.2.0 23 * 24 * @param string $template Path to the activity template to load. 25 */ 26 bp_core_load_template( apply_filters( 'bp_activity_template_favorite_activity', 'members/single/home' ) ); 27 } 28 No newline at end of file -
new file src/bp-activity/screens/friends.php
new file mode 100644
- + 1 <?php 2 3 /** 4 * Load the 'My Friends' activity page. 5 * 6 * @since 1.0.0 7 * 8 */ 9 function bp_activity_screen_friends() { 10 if ( !bp_is_active( 'friends' ) ) 11 return false; 12 13 bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' ); 14 15 /** 16 * Fires right before the loading of the "My Friends" screen template file. 17 * 18 * @since 1.2.0 19 */ 20 do_action( 'bp_activity_screen_friends' ); 21 22 /** 23 * Filters the template to load for the "My Friends" screen. 24 * 25 * @since 1.0.0 26 * 27 * @param string $template Path to the activity template to load. 28 */ 29 bp_core_load_template( apply_filters( 'bp_activity_template_friends_activity', 'members/single/home' ) ); 30 } 31 No newline at end of file -
new file src/bp-activity/screens/groups.php
new file mode 100644
- + 1 <?php 2 3 /** 4 * Load the 'My Groups' activity page. 5 * 6 * @since 1.2.0 7 * 8 */ 9 function bp_activity_screen_groups() { 10 if ( !bp_is_active( 'groups' ) ) 11 return false; 12 13 bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' ); 14 15 /** 16 * Fires right before the loading of the "My Groups" screen template file. 17 * 18 * @since 1.2.0 19 */ 20 do_action( 'bp_activity_screen_groups' ); 21 22 /** 23 * Filters the template to load for the "My Groups" screen. 24 * 25 * @since 1.2.0 26 * 27 * @param string $template Path to the activity template to load. 28 */ 29 bp_core_load_template( apply_filters( 'bp_activity_template_groups_activity', 'members/single/home' ) ); 30 } 31 No newline at end of file -
new file src/bp-activity/screens/just-me.php
new file mode 100644
- + 1 <?php 2 3 /** 4 * Load the 'My Activity' page. 5 * 6 * @since 1.0.0 7 * 8 */ 9 function bp_activity_screen_my_activity() { 10 11 /** 12 * Fires right before the loading of the "My Activity" screen template file. 13 * 14 * @since 1.0.0 15 */ 16 do_action( 'bp_activity_screen_my_activity' ); 17 18 /** 19 * Filters the template to load for the "My Activity" screen. 20 * 21 * @since 1.0.0 22 * 23 * @param string $template Path to the activity template to load. 24 */ 25 bp_core_load_template( apply_filters( 'bp_activity_template_my_activity', 'members/single/home' ) ); 26 } 27 No newline at end of file -
new file src/bp-activity/screens/mentions.php
new file mode 100644
- + 1 <?php 2 3 /** 4 * Load the 'Mentions' activity page. 5 * 6 * @since 1.2.0 7 * 8 */ 9 function bp_activity_screen_mentions() { 10 bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' ); 11 12 /** 13 * Fires right before the loading of the "Mentions" screen template file. 14 * 15 * @since 1.2.0 16 */ 17 do_action( 'bp_activity_screen_mentions' ); 18 19 /** 20 * Filters the template to load for the "Mentions" screen. 21 * 22 * @since 1.2.0 23 * 24 * @param string $template Path to the activity template to load. 25 */ 26 bp_core_load_template( apply_filters( 'bp_activity_template_mention_activity', 'members/single/home' ) ); 27 } 28 29 /** 30 * Reset the logged-in user's new mentions data when he visits his mentions screen. 31 * 32 * @since 1.5.0 33 * 34 */ 35 function bp_activity_reset_my_new_mentions() { 36 if ( bp_is_my_profile() ) 37 bp_activity_clear_new_mentions( bp_loggedin_user_id() ); 38 } 39 add_action( 'bp_activity_screen_mentions', 'bp_activity_reset_my_new_mentions' ); 40 No newline at end of file -
new file src/bp-activity/screens/permalink.php
new file mode 100644
- + 1 <?php 2 3 /** 4 * Catch and route requests for single activity item permalinks. 5 * 6 * @since 1.2.0 7 * 8 * @return bool False on failure. 9 */ 10 function bp_activity_action_permalink_router() { 11 12 // Not viewing activity. 13 if ( ! bp_is_activity_component() || ! bp_is_current_action( 'p' ) ) 14 return false; 15 16 // No activity to display. 17 if ( ! bp_action_variable( 0 ) || ! is_numeric( bp_action_variable( 0 ) ) ) 18 return false; 19 20 // Get the activity details. 21 $activity = bp_activity_get_specific( array( 'activity_ids' => bp_action_variable( 0 ), 'show_hidden' => true ) ); 22 23 // 404 if activity does not exist 24 if ( empty( $activity['activities'][0] ) ) { 25 bp_do_404(); 26 return; 27 } else { 28 $activity = $activity['activities'][0]; 29 } 30 31 // Do not redirect at default. 32 $redirect = false; 33 34 // Redirect based on the type of activity. 35 if ( bp_is_active( 'groups' ) && $activity->component == buddypress()->groups->id ) { 36 37 // Activity is a user update. 38 if ( ! empty( $activity->user_id ) ) { 39 $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/'; 40 41 // Activity is something else. 42 } else { 43 44 // Set redirect to group activity stream. 45 if ( $group = groups_get_group( $activity->item_id ) ) { 46 $redirect = bp_get_group_permalink( $group ) . bp_get_activity_slug() . '/' . $activity->id . '/'; 47 } 48 } 49 50 // Set redirect to users' activity stream. 51 } elseif ( ! empty( $activity->user_id ) ) { 52 $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/'; 53 } 54 55 // If set, add the original query string back onto the redirect URL. 56 if ( ! empty( $_SERVER['QUERY_STRING'] ) ) { 57 $query_frags = array(); 58 wp_parse_str( $_SERVER['QUERY_STRING'], $query_frags ); 59 $redirect = add_query_arg( urlencode_deep( $query_frags ), $redirect ); 60 } 61 62 /** 63 * Filter the intended redirect url before the redirect occurs for the single activity item. 64 * 65 * @since 1.2.2 66 * 67 * @param array $value Array with url to redirect to and activity related to the redirect. 68 */ 69 if ( ! $redirect = apply_filters_ref_array( 'bp_activity_permalink_redirect_url', array( $redirect, &$activity ) ) ) { 70 bp_core_redirect( bp_get_root_domain() ); 71 } 72 73 // Redirect to the actual activity permalink page. 74 bp_core_redirect( $redirect ); 75 } 76 add_action( 'bp_actions', 'bp_activity_action_permalink_router' ); 77 78 /** 79 * Load the page for a single activity item. 80 * 81 * @since 1.2.0 82 * 83 * @return bool|string Boolean on false or the template for a single activity item on success. 84 */ 85 function bp_activity_screen_single_activity_permalink() { 86 // No displayed user or not viewing activity component. 87 if ( ! bp_is_activity_component() ) { 88 return false; 89 } 90 91 $action = bp_current_action(); 92 if ( ! $action || ! is_numeric( $action ) ) { 93 return false; 94 } 95 96 // Get the activity details. 97 $activity = bp_activity_get_specific( array( 98 'activity_ids' => $action, 99 'show_hidden' => true, 100 'spam' => 'ham_only', 101 ) ); 102 103 // 404 if activity does not exist 104 if ( empty( $activity['activities'][0] ) || bp_action_variables() ) { 105 bp_do_404(); 106 return; 107 108 } else { 109 $activity = $activity['activities'][0]; 110 } 111 112 $user_id = bp_displayed_user_id(); 113 114 /** 115 * Check user access to the activity item. 116 * 117 * @since 3.0.0 118 */ 119 $has_access = bp_activity_user_can_read( $activity, $user_id ); 120 121 // If activity author does not match displayed user, block access. 122 // More info:https://buddypress.trac.wordpress.org/ticket/7048#comment:28 123 if ( true === $has_access && $user_id !== $activity->user_id ) { 124 $has_access = false; 125 } 126 127 /** 128 * Fires before the loading of a single activity template file. 129 * 130 * @since 1.2.0 131 * 132 * @param BP_Activity_Activity $activity Object representing the current activity item being displayed. 133 * @param bool $has_access Whether or not the current user has access to view activity. 134 */ 135 do_action( 'bp_activity_screen_single_activity_permalink', $activity, $has_access ); 136 137 // Access is specifically disallowed. 138 if ( false === $has_access ) { 139 140 // User feedback. 141 bp_core_add_message( __( 'You do not have access to this activity.', 'buddypress' ), 'error' ); 142 143 // Redirect based on logged in status. 144 if ( is_user_logged_in() ) { 145 $url = bp_loggedin_user_domain(); 146 147 } else { 148 $url = wp_login_url( bp_activity_get_permalink( $action ) ); 149 } 150 151 bp_core_redirect( $url ); 152 } 153 154 /** 155 * Filters the template to load for a single activity screen. 156 * 157 * @since 1.0.0 158 * 159 * @param string $template Path to the activity template to load. 160 */ 161 $template = apply_filters( 'bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink' ); 162 163 // Load the template. 164 bp_core_load_template( $template ); 165 } 166 add_action( 'bp_screens', 'bp_activity_screen_single_activity_permalink' ); 167 No newline at end of file -
new file src/bp-activity/screens/settings-email.php
new file mode 100644 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-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 $dirs = array( 25 buddypress()->plugin_dir . 'bp-activity/actions/', 26 buddypress()->plugin_dir . 'bp-activity/screens/', 27 ); 28 29 foreach ( $dirs as $dir ) { 30 foreach ( glob( $dir . "*.php" ) as $file ) { 31 require $file; 32 } 33 } 34 } ); 35 No newline at end of file