Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/11/2014 03:13:23 PM (12 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/src/bp-core/bp-core-classes.php

    r8753 r8787  
    15081508}
    15091509
     1510if ( class_exists( 'WP_Date_Query' ) ) :
     1511/**
     1512 * BuddyPress date query class.
     1513 *
     1514 * Extends the {@link WP_Date_Query} class for use with BuddyPress.
     1515 *
     1516 * @since BuddyPress (2.1.0)
     1517 *
     1518 * @param array $date_query {
     1519 *     Date query arguments.  See first parameter of {@link WP_Date_Query::__construct()}.
     1520 * }
     1521 * @param string $column The DB column to query against.
     1522 */
     1523class BP_Date_Query extends WP_Date_Query {
     1524    /**
     1525     * The column to query against. Can be changed via the query arguments.
     1526     *
     1527     * @var string
     1528     */
     1529    public $column;
     1530
     1531    /**
     1532     * Constructor.
     1533     *
     1534     * @see WP_Date_Query::__construct()
     1535     */
     1536    public function __construct( $date_query, $column = '' ) {
     1537        if ( ! empty( $column ) ) {
     1538            $this->column = $column;
     1539            add_filter( 'date_query_valid_columns', array( $this, 'register_date_column' ) );
     1540        }
     1541
     1542        parent::__construct( $date_query, $column );
     1543    }
     1544
     1545    /**
     1546     * Destructor.
     1547     */
     1548    public function __destruct() {
     1549        remove_filter( 'date_query_valid_columns', array( $this, 'register_date_column' ) );   
     1550    }
     1551
     1552    /**
     1553     * Registers our date column with WP Date Query to pass validation.
     1554     *
     1555     * @param array $retval Current DB columns
     1556     * @return array
     1557     */
     1558    public function register_date_column( $retval = array() ) {
     1559        $retval[] = $this->column;
     1560        return $retval;
     1561    }
     1562}
     1563endif;
    15101564
    15111565/**
Note: See TracChangeset for help on using the changeset viewer.