Ticket #8208: 8208.patch
File 8208.patch, 10.7 KB (added by , 5 years ago) |
---|
-
src/bp-activity/bp-activity-functions.php
597 597 $track_post_type = bp_activity_get_post_type_tracking_args( $post_type ); 598 598 599 599 if ( ! empty( $track_post_type ) ) { 600 // Set the post type comments tracking args 600 // Set the post type comments tracking args. 601 601 if ( ! empty( $track_post_type->comments_tracking->action_id ) ) { 602 // Used to check support for comment tracking by activity type (new_post_type_comment) 602 // Used to check support for comment tracking by activity type (new_post_type_comment). 603 603 $track_post_type->comments_tracking->comments_tracking = true; 604 604 605 605 // Used to be able to find the post type this activity type is associated to. … … 607 607 608 608 $post_types_tracking_args[ $track_post_type->comments_tracking->action_id ] = $track_post_type->comments_tracking; 609 609 610 // Used to check support for comment tracking by activity type (new_post_type) 610 // Used to check support for comment tracking by activity type (new_post_type). 611 611 $track_post_type->comments_tracking = true; 612 612 } 613 613 … … 650 650 * eg. 'new_blog_post' and 'new_blog_comment' will both return true. 651 651 */ 652 652 case 'post-type-comment-tracking' : 653 // Set the activity track global if not set yet 653 // Set the activity track global if not set yet. 654 654 if ( empty( $bp->activity->track ) ) { 655 655 $bp->activity->track = bp_activity_get_post_types_tracking_args(); 656 656 } … … 726 726 727 727 $bp = buddypress(); 728 728 729 // Set the activity track global if not set yet 729 // Set the activity track global if not set yet. 730 730 if ( empty( $bp->activity->track ) ) { 731 731 $bp->activity->track = bp_activity_get_post_types_tracking_args(); 732 732 } … … 1702 1702 'max' => false, // Maximum number of results to return. 1703 1703 'fields' => 'all', 1704 1704 'page' => 1, // Page 1 without a per_page will result in no pagination. 1705 'per_page' => false, // results per page 1706 'sort' => 'DESC', // sort ASC or DESC 1705 'per_page' => false, // results per page. 1706 'sort' => 'DESC', // sort ASC or DESC. 1707 1707 'display_comments' => false, // False for no comments. 'stream' for within stream display, 'threaded' for below each activity item. 1708 1708 1709 'search_terms' => false, // Pass search terms as a string 1710 'meta_query' => false, // Filter by activity meta. See WP_Meta_Query for format 1709 'search_terms' => false, // Pass search terms as a string. 1710 'meta_query' => false, // Filter by activity meta. See WP_Meta_Query for format. 1711 1711 'date_query' => false, // Filter by date. See first parameter of WP_Date_Query for format. 1712 1712 'filter_query' => false, 1713 1713 'show_hidden' => false, // Show activity items that are hidden site-wide? 1714 1714 'exclude' => false, // Comma-separated list of activity IDs to exclude. 1715 'in' => false, // Comma-separated list or array of activity IDs to which you 1715 'in' => false, // Comma-separated list or array of activity IDs to which you. 1716 1716 // want to limit the query. 1717 1717 'spam' => 'ham_only', // 'ham_only' (default), 'spam_only' or 'all'. 1718 1718 'update_meta_cache' => true, … … 1861 1861 1862 1862 $r = bp_parse_args( $args, array( 1863 1863 'id' => false, // Pass an existing activity ID to update an existing entry. 1864 'action' => '', // The activity action - e.g. "Jon Doe posted an update" 1865 'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!" 1864 'action' => '', // The activity action - e.g. "Jon Doe posted an update". 1865 'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!". 1866 1866 'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent. 1867 1867 'type' => false, // The activity type e.g. activity_update, profile_updated. 1868 1868 'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink). … … 2298 2298 * @return null|WP_Error|bool|int The ID of the activity on success. False on error. 2299 2299 */ 2300 2300 function bp_activity_post_type_comment( $comment_id = 0, $is_approved = true, $activity_post_object = null ) { 2301 // Get the users comment 2301 // Get the users comment. 2302 2302 $post_type_comment = get_comment( $comment_id ); 2303 2303 2304 // Don't record activity if the comment hasn't been approved 2304 // Don't record activity if the comment hasn't been approved. 2305 2305 if ( empty( $is_approved ) ) { 2306 2306 return false; 2307 2307 } 2308 2308 2309 // Don't record activity if no email address has been included 2309 // Don't record activity if no email address has been included. 2310 2310 if ( empty( $post_type_comment->comment_author_email ) ) { 2311 2311 return false; 2312 2312 } 2313 2313 2314 // Don't record activity if the comment has already been marked as spam 2314 // Don't record activity if the comment has already been marked as spam. 2315 2315 if ( 'spam' === $is_approved ) { 2316 2316 return false; 2317 2317 } … … 2319 2319 // Get the user by the comment author email. 2320 2320 $user = get_user_by( 'email', $post_type_comment->comment_author_email ); 2321 2321 2322 // If user isn't registered, don't record activity 2322 // If user isn't registered, don't record activity. 2323 2323 if ( empty( $user ) ) { 2324 2324 return false; 2325 2325 } 2326 2326 2327 // Get the user_id 2327 // Get the user_id. 2328 2328 $user_id = (int) $user->ID; 2329 2329 2330 // Get blog and post data 2330 // Get blog and post data. 2331 2331 $blog_id = get_current_blog_id(); 2332 2332 2333 // Get the post 2333 // Get the post. 2334 2334 $post_type_comment->post = get_post( $post_type_comment->comment_post_ID ); 2335 2335 2336 2336 if ( ! is_a( $post_type_comment->post, 'WP_Post' ) ) { … … 2346 2346 */ 2347 2347 $is_post_status_not_allowed = (bool) apply_filters( 'bp_activity_post_type_is_post_status_allowed', 'publish' !== $post_type_comment->post->post_status || ! empty( $post_type_comment->post->post_password ) ); 2348 2348 2349 // If this is a password protected post, or not a public post don't record the comment 2349 // If this is a password protected post, or not a public post don't record the comment. 2350 2350 if ( $is_post_status_not_allowed ) { 2351 2351 return false; 2352 2352 } 2353 2353 2354 // Set post type 2354 // Set post type. 2355 2355 $post_type = $post_type_comment->post->post_type; 2356 2356 2357 2357 if ( empty( $activity_post_object ) ) { … … 2358 2358 // Get the post type tracking args. 2359 2359 $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type ); 2360 2360 2361 // Bail if the activity type does not exist 2361 // Bail if the activity type does not exist. 2362 2362 if ( empty( $activity_post_object->comments_tracking->action_id ) ) { 2363 2363 return false; 2364 2364 } 2365 2365 } 2366 2366 2367 // Set the $activity_comment_object 2367 // Set the $activity_comment_object. 2368 2368 $activity_comment_object = $activity_post_object->comments_tracking; 2369 2369 2370 2370 /** … … 2503 2503 // Get the post type tracking args. 2504 2504 $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type ); 2505 2505 2506 // Bail if the activity type does not exist 2506 // Bail if the activity type does not exist. 2507 2507 if ( empty( $activity_post_object->comments_tracking->action_id ) ) { 2508 2508 return false; 2509 2509 } 2510 2510 } 2511 2511 2512 // Set the $activity_comment_object 2512 // Set the $activity_comment_object. 2513 2513 $activity_comment_object = $activity_post_object->comments_tracking; 2514 2514 2515 2515 if ( empty( $activity_comment_object->action_id ) ) { … … 4032 4032 // Get the post type tracking args. 4033 4033 $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type ); 4034 4034 4035 // Bail if the activity type does not exist 4035 // Bail if the activity type does not exist. 4036 4036 if ( empty( $activity_post_object->comments_tracking->action_id ) ) { 4037 4037 return false; 4038 4038 4039 // Set the $activity_comment_object 4039 // Set the $activity_comment_object. 4040 4040 } else { 4041 4041 $activity_comment_object = $activity_post_object->comments_tracking; 4042 4042 } 4043 4043 4044 // Init an empty activity ID 4044 // Init an empty activity ID. 4045 4045 $activity_id = 0; 4046 4046 4047 4047 /** … … 4065 4065 $action = 'ham_activity'; 4066 4066 } 4067 4067 4068 // Get the activity 4068 // Get the activity. 4069 4069 if ( bp_disable_blogforum_comments() ) { 4070 4070 $activity_id = bp_activity_get_activity_id( array( 4071 4071 'component' => $activity_comment_object->component_id, … … 4093 4093 return false; 4094 4094 } 4095 4095 4096 // Check activity item exists 4096 // Check activity item exists. 4097 4097 if ( empty( $activity_id ) ) { 4098 4098 // If no activity exists, but the comment has been approved, record it into the activity table. 4099 4099 if ( 'approved' == $new_status ) { … … 4103 4103 return; 4104 4104 } 4105 4105 4106 // Create an activity object 4106 // Create an activity object. 4107 4107 $activity = new BP_Activity_Activity( $activity_id ); 4108 4108 if ( empty( $activity->component ) ) { 4109 4109 return; 4110 4110 } 4111 4111 4112 // Spam/ham the activity if it's not already in that state 4112 // Spam/ham the activity if it's not already in that state. 4113 4113 if ( 'spam_activity' === $action && ! $activity->is_spam ) { 4114 4114 bp_activity_mark_as_spam( $activity ); 4115 4115 } elseif ( 'ham_activity' == $action) { … … 4116 4116 bp_activity_mark_as_ham( $activity ); 4117 4117 } 4118 4118 4119 // Add "new_post_type_comment" to the whitelisted activity types, so that the activity's Akismet history is generated 4119 // Add "new_post_type_comment" to the whitelisted activity types, so that the activity's Akismet history is generated. 4120 4120 $post_type_comment_action = $activity_comment_object->action_id; 4121 4121 $comment_akismet_history = function ( $activity_types ) use ( $post_type_comment_action ) { 4122 4122 $activity_types[] = $post_type_comment_action; … … 4125 4125 }; 4126 4126 add_filter( 'bp_akismet_get_activity_types', $comment_akismet_history ); 4127 4127 4128 // Make sure the activity change won't edit the comment if sync is on 4128 // Make sure the activity change won't edit the comment if sync is on. 4129 4129 remove_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 ); 4130 4130 4131 // Save the updated activity 4131 // Save the updated activity. 4132 4132 $activity->save(); 4133 4133 4134 // Restore the action 4134 // Restore the action. 4135 4135 add_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 ); 4136 4136 4137 // Remove the "new_blog_comment" activity type whitelist so we don't break anything 4137 // Remove the "new_blog_comment" activity type whitelist so we don't break anything. 4138 4138 remove_filter( 'bp_akismet_get_activity_types', $comment_akismet_history ); 4139 4139 } 4140 4140 add_action( 'transition_comment_status', 'bp_activity_transition_post_type_comment_status', 10, 3 );