diff --git src/bp-activity/bp-activity-functions.php src/bp-activity/bp-activity-functions.php
index 8bcc546..423fdf9 100644
|
|
function bp_activity_get( $args = '' ) { |
1451 | 1451 | |
1452 | 1452 | $r = bp_parse_args( $args, array( |
1453 | 1453 | 'max' => false, // Maximum number of results to return |
| 1454 | 'fields' => 'all', |
1454 | 1455 | 'page' => 1, // page 1 without a per_page will result in no pagination. |
1455 | 1456 | 'per_page' => false, // results per page |
1456 | 1457 | 'sort' => 'DESC', // sort ASC or DESC |
… |
… |
function bp_activity_get( $args = '' ) { |
1482 | 1483 | ) ); |
1483 | 1484 | |
1484 | 1485 | // Attempt to return a cached copy of the first page of sitewide activity. |
1485 | | if ( ( 1 === (int) $r['page'] ) && empty( $r['max'] ) && empty( $r['search_terms'] ) && empty( $r['meta_query'] ) && empty( $r['date_query'] ) && empty( $r['filter_query'] ) && empty( $r['filter'] ) && empty( $r['scope'] )&& empty( $r['exclude'] ) && empty( $r['in'] ) && ( 'DESC' === $r['sort'] ) && empty( $r['exclude'] ) && ( 'ham_only' === $r['spam'] ) ) { |
| 1486 | if ( ( 1 === (int) $r['page'] ) && empty( $r['max'] ) && ( 'all' === $r['fields'] ) && empty( $r['search_terms'] ) && empty( $r['meta_query'] ) && empty( $r['date_query'] ) && empty( $r['filter_query'] ) && empty( $r['filter'] ) && empty( $r['scope'] )&& empty( $r['exclude'] ) && empty( $r['in'] ) && ( 'DESC' === $r['sort'] ) && empty( $r['exclude'] ) && ( 'ham_only' === $r['spam'] ) ) { |
1486 | 1487 | |
1487 | 1488 | $activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' ); |
1488 | 1489 | if ( false === $activity ) { |
… |
… |
function bp_activity_get( $args = '' ) { |
1491 | 1492 | 'page' => $r['page'], |
1492 | 1493 | 'per_page' => $r['per_page'], |
1493 | 1494 | 'max' => $r['max'], |
| 1495 | 'fields' => $r['fields'], |
1494 | 1496 | 'sort' => $r['sort'], |
1495 | 1497 | 'search_terms' => $r['search_terms'], |
1496 | 1498 | 'meta_query' => $r['meta_query'], |
diff --git src/bp-activity/bp-activity-template.php src/bp-activity/bp-activity-template.php
index f055a23..7926653 100644
|
|
class BP_Activity_Template { |
270 | 270 | 'per_page' => 20, |
271 | 271 | 'page_arg' => 'acpage', |
272 | 272 | 'max' => false, |
| 273 | 'fields' => 'all', |
273 | 274 | 'count_total' => false, |
274 | 275 | 'sort' => false, |
275 | 276 | 'include' => false, |
… |
… |
class BP_Activity_Template { |
536 | 537 | * @type int|bool $per_page Number of results per page. Default: 20. |
537 | 538 | * @type string $page_arg String used as a query parameter in pagination links. Default: 'acpage'. |
538 | 539 | * @type int|bool $max Maximum number of results to return. Default: false (unlimited). |
| 540 | * @type string $fields Activity fields to retrieve. 'all' to fetch entire activity objects, |
| 541 | * 'ids' to get only the activity IDs. Default 'all'. |
539 | 542 | * @type string|bool $count_total If true, an additional DB query is run to count the total activity items |
540 | 543 | * for the query. Default: false. |
541 | 544 | * @type string $sort 'ASC' or 'DESC'. Default: 'DESC'. |
… |
… |
function bp_has_activities( $args = '' ) { |
661 | 664 | 'per_page' => 20, // number of items per page |
662 | 665 | 'page_arg' => 'acpage', // See https://buddypress.trac.wordpress.org/ticket/3679 |
663 | 666 | 'max' => false, // max number to return |
| 667 | 'fields' => 'all', |
664 | 668 | 'count_total' => false, |
665 | 669 | 'show_hidden' => $show_hidden, // Show activity items that are hidden site-wide? |
666 | 670 | 'spam' => 'ham_only', // Hide spammed items |
diff --git src/bp-activity/classes/class-bp-activity-activity.php src/bp-activity/classes/class-bp-activity-activity.php
index 5081009..b25d3d5 100644
|
|
class BP_Activity_Activity { |
260 | 260 | /** |
261 | 261 | * Get activity items, as specified by parameters. |
262 | 262 | * |
| 263 | * @since 1.0.0 |
| 264 | * @since 2.4.0 Introduced the `$fields` parameter. |
| 265 | * |
263 | 266 | * @see BP_Activity_Activity::get_filter_sql() for a description of the |
264 | 267 | * 'filter' parameter. |
265 | 268 | * @see WP_Meta_Query::queries for a description of the 'meta_query' |
… |
… |
class BP_Activity_Activity { |
272 | 275 | * in no pagination. Default: 1. |
273 | 276 | * @type int|bool $per_page Number of results per page. Default: 25. |
274 | 277 | * @type int|bool $max Maximum number of results to return. Default: false (unlimited). |
| 278 | * @type string $fields Activity fields to return. Pass 'ids' to get only the activity IDs. |
| 279 | * 'all' returns full activity objects. |
275 | 280 | * @type string $sort ASC or DESC. Default: 'DESC'. |
276 | 281 | * @type array $exclude Array of activity IDs to exclude. Default: false. |
277 | 282 | * @type array $in Array of ids to limit query by (IN). Default: false. |
… |
… |
class BP_Activity_Activity { |
323 | 328 | 'page' => 1, // The current page |
324 | 329 | 'per_page' => 25, // Activity items per page |
325 | 330 | 'max' => false, // Max number of items to return |
| 331 | 'fields' => 'all', |
326 | 332 | 'sort' => 'DESC', // ASC or DESC |
327 | 333 | 'exclude' => false, // Array of ids to exclude |
328 | 334 | 'in' => false, // Array of ids to limit query by (IN) |
… |
… |
class BP_Activity_Activity { |
570 | 576 | array_pop( $activity_ids ); |
571 | 577 | } |
572 | 578 | |
573 | | $activities = self::get_activity_data( $activity_ids ); |
| 579 | if ( 'ids' === $r['fields'] ) { |
| 580 | $activities = array_map( 'intval', $activity_ids ); |
| 581 | } else { |
| 582 | $activities = self::get_activity_data( $activity_ids ); |
| 583 | } |
574 | 584 | } |
575 | 585 | |
576 | | // Get the fullnames of users so we don't have to query in the loop |
577 | | $activities = self::append_user_fullnames( $activities ); |
| 586 | if ( 'ids' !== $r['fields'] ) { |
| 587 | // Get the fullnames of users so we don't have to query in the loop |
| 588 | $activities = self::append_user_fullnames( $activities ); |
578 | 589 | |
579 | | // Get activity meta |
580 | | $activity_ids = array(); |
581 | | foreach ( (array) $activities as $activity ) { |
582 | | $activity_ids[] = $activity->id; |
583 | | } |
| 590 | // Get activity meta |
| 591 | $activity_ids = array(); |
| 592 | foreach ( (array) $activities as $activity ) { |
| 593 | $activity_ids[] = $activity->id; |
| 594 | } |
584 | 595 | |
585 | | if ( ! empty( $activity_ids ) && $r['update_meta_cache'] ) { |
586 | | bp_activity_update_meta_cache( $activity_ids ); |
587 | | } |
| 596 | if ( ! empty( $activity_ids ) && $r['update_meta_cache'] ) { |
| 597 | bp_activity_update_meta_cache( $activity_ids ); |
| 598 | } |
588 | 599 | |
589 | | if ( $activities && $r['display_comments'] ) { |
590 | | $activities = BP_Activity_Activity::append_comments( $activities, $r['spam'] ); |
591 | | } |
| 600 | if ( $activities && $r['display_comments'] ) { |
| 601 | $activities = BP_Activity_Activity::append_comments( $activities, $r['spam'] ); |
| 602 | } |
592 | 603 | |
593 | | // Pre-fetch data associated with activity users and other objects |
594 | | BP_Activity_Activity::prefetch_object_data( $activities ); |
| 604 | // Pre-fetch data associated with activity users and other objects |
| 605 | BP_Activity_Activity::prefetch_object_data( $activities ); |
595 | 606 | |
596 | | // Generate action strings |
597 | | $activities = BP_Activity_Activity::generate_action_strings( $activities ); |
| 607 | // Generate action strings |
| 608 | $activities = BP_Activity_Activity::generate_action_strings( $activities ); |
| 609 | } |
598 | 610 | |
599 | 611 | $retval['activities'] = $activities; |
600 | 612 | |
diff --git tests/phpunit/testcases/activity/class.BP_Activity_Activity.php tests/phpunit/testcases/activity/class.BP_Activity_Activity.php
index 6a52f4e..3da21f1 100644
|
|
class BP_Tests_Activity_Class extends BP_UnitTestCase { |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @group get |
| 59 | * @group fields |
| 60 | * @ticket BP6426 |
| 61 | */ |
| 62 | public function test_get_with_fields_parameter_by_id() { |
| 63 | $a = $this->factory->activity->create_many( 3, array( |
| 64 | 'type' => 'activity_update', |
| 65 | ) ); |
| 66 | |
| 67 | $result = BP_Activity_Activity::get( array( |
| 68 | 'fields' => 'ids', |
| 69 | ) ); |
| 70 | $this->assertEqualSets( $a, $result['activities'] ); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @group get |
59 | 75 | */ |
60 | 76 | public function test_hide_all_for_user() { |
61 | 77 | $activity = $this->factory->activity->create( array( |