Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/11/2014 03:13:23 PM (11 years ago)
Author:
r-a-y
Message:

Add ability to query activity items by date.

This commit:

  • Introduces the BP_Date_Query class. This class extends WP_Date_Query, which will enable us to easily add support to query various BuddyPress items by date.
  • Adds a new 'date_query' parameter to BP_Activity_Activity::get(). This parameter utilizes the new BP_Date_Query class and is an example of how to use the class in BuddyPress. (Will add support for the Groups component in a later commit.)
  • Adds unit tests.

Due to the dependency on the WP_Date_Query class, this functionality is
only available in WordPress 3.7+.

Fixes #5803.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/activity/template.php

    r8747 r8787  
    513513        }
    514514    }
     515
     516    /**
     517     * Integration test for 'date_query' param
     518     *
     519     * @group date_query
     520     */
     521    function test_bp_has_activities_with_date_query() {
     522        if ( ! class_exists( 'WP_Date_Query' ) ) {
     523            return;
     524        }
     525
     526        $a1 = $this->factory->activity->create();
     527        $a2 = $this->factory->activity->create( array(
     528            'recorded_time' => '2001-01-01 12:00'
     529        ) );
     530        $a3 = $this->factory->activity->create( array(
     531            'recorded_time' => '2005-01-01 12:00'
     532        ) );
     533
     534        global $activities_template;
     535        bp_has_activities( array(
     536            'date_query' => array( array(
     537                'after' => '1 day ago'
     538            ) )
     539        ) );
     540
     541        $ids = wp_list_pluck( $activities_template->activities, 'id' );
     542        $this->assertEquals( $ids, array( $a1 ) );
     543    }
    515544}
Note: See TracChangeset for help on using the changeset viewer.