[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-core/classes/ -> class-bp-date-query.php (source)

   1  <?php
   2  /**
   3   * Core component classes.
   4   *
   5   * @package BuddyPress
   6   * @subpackage Core
   7   * @since 2.1.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  if ( class_exists( 'WP_Date_Query' ) ) :
  14  
  15  /**
  16   * BuddyPress date query class.
  17   *
  18   * Extends the {@link WP_Date_Query} class for use with BuddyPress.
  19   *
  20   * @since 2.1.0
  21   *
  22   * @param array $date_query {
  23   *     Date query arguments.  See first parameter of {@link WP_Date_Query::__construct()}.
  24   * }
  25   * @param string $column The DB column to query against.
  26   */
  27  class BP_Date_Query extends WP_Date_Query {
  28      /**
  29       * The column to query against. Can be changed via the query arguments.
  30       *
  31       * @var string
  32       */
  33      public $column;
  34  
  35      /**
  36       * Constructor.
  37       *
  38       * @param array  $date_query Date query arguments.
  39       * @param string $column     THe DB column to query against.
  40       *
  41       * @see WP_Date_Query::__construct()
  42       */
  43  	public function __construct( $date_query, $column = '' ) {
  44          if ( ! empty( $column ) ) {
  45              $this->column = $column;
  46              add_filter( 'date_query_valid_columns', array( $this, 'register_date_column' ) );
  47          }
  48  
  49          parent::__construct( $date_query, $column );
  50      }
  51  
  52      /**
  53       * Destructor.
  54       */
  55  	public function __destruct() {
  56          remove_filter( 'date_query_valid_columns', array( $this, 'register_date_column' ) );
  57      }
  58  
  59      /**
  60       * Registers our date column with WP Date Query to pass validation.
  61       *
  62       * @param array $retval Current DB columns.
  63       * @return array
  64       */
  65  	public function register_date_column( $retval = array() ) {
  66          $retval[] = $this->column;
  67          return $retval;
  68      }
  69  }
  70  endif;


Generated: Thu Dec 12 01:01:36 2019 Cross-referenced by PHPXref 0.7.1