Skip to:
Content

BuddyPress.org

Ticket #3521: 3521.patch

File 3521.patch, 4.3 KB (added by ericlewis, 7 years ago)

basic implementation; makes use of WP's built-in WP_Meta_Query class.

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

     
    809809                'exclude'          => false,        // Comma-separated list of activity IDs to exclude
    810810                'in'               => false,        // Comma-separated list or array of activity IDs to which you want to limit the query
    811811                'spam'             => 'ham_only',   // 'ham_only' (default), 'spam_only' or 'all'.
     812                'meta_query'       => false,        // Activity Meta Query
    812813
    813814                /**
    814815                 * Pass filters as an array -- all filter items can be multiple values comma separated:
     
    837838                                'filter'           => $filter,
    838839                                'display_comments' => $display_comments,
    839840                                'show_hidden'      => $show_hidden,
    840                                 'spam'             => $spam
     841                                'spam'             => $spam,
     842                                'meta_query'       => $meta_query,
    841843                        );
    842844                        $activity = BP_Activity_Activity::get( $args );
    843845                        wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' );
     
    855857                        'show_hidden'      => $show_hidden,
    856858                        'exclude'          => $exclude,
    857859                        'in'               => $in,
    858                         'spam'             => $spam
     860                        'spam'             => $spam,
     861                        'meta_query'       => $meta_query,
    859862                );
    860863                $activity = BP_Activity_Activity::get( $args );
    861864        }
  • bp-activity/bp-activity-classes.php

     
    149149                        'display_comments' => false,      // Whether to include activity comments
    150150                        'show_hidden'      => false,      // Show items marked hide_sitewide
    151151                        'spam'             => 'ham_only', // Spam status
     152                        'meta_query'       => false,
    152153                );
    153154                $r = wp_parse_args( $args, $defaults );
    154155                extract( $r );
    155 
    156156                // Select conditions
    157157                $select_sql = "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name";
    158158
     
    197197                        $where_conditions['in'] = "a.id IN ({$in})";
    198198                }
    199199
     200                // Meta Query
     201                if ( !empty( $meta_query ) ) {
     202                        $this_meta_query = new WP_Meta_Query( $meta_query );
     203                        $wpdb->activitymeta = $bp->activity->table_name_meta;
     204                        $meta_sql = $this_meta_query->get_sql( 'activity', 'a', 'id' );
     205                        $where_conditions['meta_query'] = preg_replace( '/^\sAND/', '', $meta_sql['where'] );
     206                        $join_sql = $meta_sql['join'];
     207                } else
     208                        $join_sql = '';
     209
    200210                // Alter the query based on whether we want to show activity item
    201211                // comments in the stream like normal comments or threaded below
    202212                // the activity.
     
    228238                        $per_page = absint( $per_page );
    229239
    230240                        $pag_sql    = $wpdb->prepare( "LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page );
    231                         $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}" ), $select_sql, $from_sql, $where_sql, $sort, $pag_sql ) );
     241                        $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', $wpdb->prepare( "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}" ), $select_sql, $from_sql, $where_sql, $sort, $pag_sql ) );
    232242                } else {
    233                         $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort}" ), $select_sql, $from_sql, $where_sql, $sort ) );
     243                        $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', $wpdb->prepare( "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}" ), $select_sql, $from_sql, $where_sql, $sort ) );
    234244                }
    235245
    236                 $total_activities_sql = apply_filters( 'bp_activity_total_activities_sql', $wpdb->prepare( "SELECT count(a.id) FROM {$bp->activity->table_name} a {$index_hint_sql} {$where_sql} ORDER BY a.date_recorded {$sort}" ), $where_sql, $sort );
     246                $total_activities_sql = apply_filters( 'bp_activity_total_activities_sql', $wpdb->prepare( "SELECT count(a.id) FROM {$bp->activity->table_name} a {$index_hint_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}" ), $where_sql, $sort );
    237247
    238248                $total_activities = $wpdb->get_var( $total_activities_sql );
    239249