Skip to:
Content

BuddyPress.org

Ticket #8208: 8208.patch

File 8208.patch, 10.7 KB (added by passoniate, 5 years ago)

Patch

  • src/bp-activity/bp-activity-functions.php

     
    597597                $track_post_type = bp_activity_get_post_type_tracking_args( $post_type );
    598598
    599599                if ( ! empty( $track_post_type ) ) {
    600                         // Set the post type comments tracking args
     600                        // Set the post type comments tracking args.
    601601                        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).
    603603                                $track_post_type->comments_tracking->comments_tracking = true;
    604604
    605605                                // Used to be able to find the post type this activity type is associated to.
     
    607607
    608608                                $post_types_tracking_args[ $track_post_type->comments_tracking->action_id ] = $track_post_type->comments_tracking;
    609609
    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).
    611611                                $track_post_type->comments_tracking = true;
    612612                        }
    613613
     
    650650                 * eg. 'new_blog_post' and 'new_blog_comment' will both return true.
    651651                 */
    652652                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.
    654654                        if ( empty( $bp->activity->track ) ) {
    655655                                $bp->activity->track = bp_activity_get_post_types_tracking_args();
    656656                        }
     
    726726
    727727        $bp = buddypress();
    728728
    729         // Set the activity track global if not set yet
     729        // Set the activity track global if not set yet.
    730730        if ( empty( $bp->activity->track ) ) {
    731731                $bp->activity->track = bp_activity_get_post_types_tracking_args();
    732732        }
     
    17021702                'max'               => false,        // Maximum number of results to return.
    17031703                'fields'            => 'all',
    17041704                '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.
    17071707                'display_comments'  => false,        // False for no comments. 'stream' for within stream display, 'threaded' for below each activity item.
    17081708
    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.
    17111711                'date_query'        => false,        // Filter by date. See first parameter of WP_Date_Query for format.
    17121712                'filter_query'      => false,
    17131713                'show_hidden'       => false,        // Show activity items that are hidden site-wide?
    17141714                '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.
    17161716                                                     // want to limit the query.
    17171717                'spam'              => 'ham_only',   // 'ham_only' (default), 'spam_only' or 'all'.
    17181718                'update_meta_cache' => true,
     
    18611861
    18621862        $r = bp_parse_args( $args, array(
    18631863                '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!".
    18661866                'component'         => false,                  // The name/ID of the component e.g. groups, profile, mycomponent.
    18671867                'type'              => false,                  // The activity type e.g. activity_update, profile_updated.
    18681868                'primary_link'      => '',                     // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink).
     
    22982298 * @return null|WP_Error|bool|int The ID of the activity on success. False on error.
    22992299 */
    23002300function 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.
    23022302        $post_type_comment = get_comment( $comment_id );
    23032303
    2304         // Don't record activity if the comment hasn't been approved
     2304        // Don't record activity if the comment hasn't been approved.
    23052305        if ( empty( $is_approved ) ) {
    23062306                return false;
    23072307        }
    23082308
    2309         // Don't record activity if no email address has been included
     2309        // Don't record activity if no email address has been included.
    23102310        if ( empty( $post_type_comment->comment_author_email ) ) {
    23112311                return false;
    23122312        }
    23132313
    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.
    23152315        if ( 'spam' === $is_approved ) {
    23162316                return false;
    23172317        }
     
    23192319        // Get the user by the comment author email.
    23202320        $user = get_user_by( 'email', $post_type_comment->comment_author_email );
    23212321
    2322         // If user isn't registered, don't record activity
     2322        // If user isn't registered, don't record activity.
    23232323        if ( empty( $user ) ) {
    23242324                return false;
    23252325        }
    23262326
    2327         // Get the user_id
     2327        // Get the user_id.
    23282328        $user_id = (int) $user->ID;
    23292329
    2330         // Get blog and post data
     2330        // Get blog and post data.
    23312331        $blog_id = get_current_blog_id();
    23322332
    2333         // Get the post
     2333        // Get the post.
    23342334        $post_type_comment->post = get_post( $post_type_comment->comment_post_ID );
    23352335
    23362336        if ( ! is_a( $post_type_comment->post, 'WP_Post' ) ) {
     
    23462346         */
    23472347        $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 ) );
    23482348
    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.
    23502350        if ( $is_post_status_not_allowed ) {
    23512351                return false;
    23522352        }
    23532353
    2354         // Set post type
     2354        // Set post type.
    23552355        $post_type = $post_type_comment->post->post_type;
    23562356
    23572357        if ( empty( $activity_post_object ) ) {
     
    23582358                // Get the post type tracking args.
    23592359                $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type );
    23602360
    2361                 // Bail if the activity type does not exist
     2361                // Bail if the activity type does not exist.
    23622362                if ( empty( $activity_post_object->comments_tracking->action_id ) ) {
    23632363                        return false;
    23642364                }
    23652365        }
    23662366
    2367         // Set the $activity_comment_object
     2367        // Set the $activity_comment_object.
    23682368        $activity_comment_object = $activity_post_object->comments_tracking;
    23692369
    23702370        /**
     
    25032503                // Get the post type tracking args.
    25042504                $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type );
    25052505
    2506                 // Bail if the activity type does not exist
     2506                // Bail if the activity type does not exist.
    25072507                if ( empty( $activity_post_object->comments_tracking->action_id ) ) {
    25082508                        return false;
    25092509                }
    25102510        }
    25112511
    2512         // Set the $activity_comment_object
     2512        // Set the $activity_comment_object.
    25132513        $activity_comment_object = $activity_post_object->comments_tracking;
    25142514
    25152515        if ( empty( $activity_comment_object->action_id ) ) {
     
    40324032        // Get the post type tracking args.
    40334033        $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type );
    40344034
    4035         // Bail if the activity type does not exist
     4035        // Bail if the activity type does not exist.
    40364036        if ( empty( $activity_post_object->comments_tracking->action_id ) ) {
    40374037                return false;
    40384038
    4039         // Set the $activity_comment_object
     4039        // Set the $activity_comment_object.
    40404040        } else {
    40414041                $activity_comment_object = $activity_post_object->comments_tracking;
    40424042        }
    40434043
    4044         // Init an empty activity ID
     4044        // Init an empty activity ID.
    40454045        $activity_id = 0;
    40464046
    40474047        /**
     
    40654065                $action = 'ham_activity';
    40664066        }
    40674067
    4068         // Get the activity
     4068        // Get the activity.
    40694069        if ( bp_disable_blogforum_comments() ) {
    40704070                $activity_id = bp_activity_get_activity_id( array(
    40714071                        'component'         => $activity_comment_object->component_id,
     
    40934093                return false;
    40944094        }
    40954095
    4096         // Check activity item exists
     4096        // Check activity item exists.
    40974097        if ( empty( $activity_id ) ) {
    40984098                // If no activity exists, but the comment has been approved, record it into the activity table.
    40994099                if ( 'approved' == $new_status ) {
     
    41034103                return;
    41044104        }
    41054105
    4106         // Create an activity object
     4106        // Create an activity object.
    41074107        $activity = new BP_Activity_Activity( $activity_id );
    41084108        if ( empty( $activity->component ) ) {
    41094109                return;
    41104110        }
    41114111
    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.
    41134113        if ( 'spam_activity' === $action && ! $activity->is_spam ) {
    41144114                bp_activity_mark_as_spam( $activity );
    41154115        } elseif ( 'ham_activity' == $action) {
     
    41164116                bp_activity_mark_as_ham( $activity );
    41174117        }
    41184118
    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.
    41204120        $post_type_comment_action = $activity_comment_object->action_id;
    41214121        $comment_akismet_history = function ( $activity_types ) use ( $post_type_comment_action ) {
    41224122                $activity_types[] = $post_type_comment_action;
     
    41254125        };
    41264126        add_filter( 'bp_akismet_get_activity_types', $comment_akismet_history );
    41274127
    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.
    41294129        remove_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 );
    41304130
    4131         // Save the updated activity
     4131        // Save the updated activity.
    41324132        $activity->save();
    41334133
    4134         // Restore the action
     4134        // Restore the action.
    41354135        add_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 );
    41364136
    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.
    41384138        remove_filter( 'bp_akismet_get_activity_types', $comment_akismet_history );
    41394139}
    41404140add_action( 'transition_comment_status', 'bp_activity_transition_post_type_comment_status', 10, 3 );