Skip to:
Content

BuddyPress.org

Changeset 8945


Ignore:
Timestamp:
08/18/2014 05:32:37 PM (10 years ago)
Author:
r-a-y
Message:

Do not use get_comments() with fields=ids parameter.

fields=ids is only supported in WordPress 4.0:
https://core.trac.wordpress.org/ticket/28434

This was causing unit test failures in older versions of WordPress.

To workaround this, this commit introduces bp_blogs_comments_clauses_select_by_id(),
which is used as a filter so we can select comments by the comment_ID
column only and is an alternative to the fields=ids approach.

Fixes #5609.

Location:
trunk/src/bp-blogs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-filters.php

    r7555 r8945  
    3737}
    3838add_filter( 'wp_signup_location', 'bp_blogs_creation_location' );
     39
     40/**
     41 * Only select comments by ID instead of all fields when using get_comments().
     42 *
     43 * @since BuddyPress (2.1.0)
     44 *
     45 * @see bp_blogs_update_post()
     46 *
     47 * @param array Current SQL clauses in array format
     48 * @return array
     49 */
     50function bp_blogs_comments_clauses_select_by_id( $retval ) {
     51    $retval['fields'] = 'comment_ID';
     52   
     53    return $retval;
     54}
  • trunk/src/bp-blogs/bp-blogs-functions.php

    r8944 r8945  
    594594
    595595        // now update activity meta for post comments... sigh
    596         $comment_ids = get_comments( array( 'post_id' => $post->ID, 'fields' => 'ids' ) );
    597 
    598         if ( ! empty( $comment_ids ) ) {
     596        add_filter( 'comments_clauses', 'bp_blogs_comments_clauses_select_by_id' );
     597        $comments = get_comments( array( 'post_id' => $post->ID ) );
     598        remove_filter( 'comments_clauses', 'bp_blogs_comments_clauses_select_by_id' );
     599
     600        if ( ! empty( $comments ) ) {
    599601            $activity_ids = array();
     602            $comment_ids  = wp_list_pluck( $comments, 'comment_ID' );
    600603
    601604            // setup activity args
     
    608611            // query for old-style "new_blog_comment" activity items
    609612            $args['filter'] = array(
    610                 'object'     => buddypress()->blogs->id,
    611                 'action'     => 'new_blog_comment',
     613                'object'       => buddypress()->blogs->id,
     614                'action'       => 'new_blog_comment',
    612615                'secondary_id' => implode( ',', $comment_ids ),
    613616            );
     
    640643            }
    641644
    642             unset( $activities, $activity_ids, $comment_ids );
     645            unset( $activities, $activity_ids, $comment_ids, $comments );
    643646        }
    644647    }
Note: See TracChangeset for help on using the changeset viewer.