/** * Get the SQL for the 'date_query' param in BP_Activity_Activity::get(). * * We use BP_Date_Query, which extends WP_Date_Query, to do the heavy lifting * of parsing the date_query array and creating the necessary SQL clauses. * However, since BP_Activity_Activity::get() builds its SQL differently than * WP_Query, we have to alter the return value (stripping the leading AND * keyword from the query). * * @since 2.1.0 * * @param array $date_query An array of date_query parameters. See the * documentation for the first parameter of WP_Date_Query. * @return string */ public static function get_date_query_sql($date_query = array()) { $sql = ''; // Date query. if (!empty($date_query) && is_array($date_query)) { $date_query = new BP_Date_Query($date_query, 'date_recorded'); $sql = preg_replace('/^\\sAND/', '', $date_query->get_sql()); } return $sql; }
/** * Get the SQL for the 'date_query' param in BP_Notifications_Notification::get(). * * We use BP_Date_Query, which extends WP_Date_Query, to do the heavy lifting * of parsing the date_query array and creating the necessary SQL clauses. * However, since BP_Notifications_Notification::get() builds its SQL * differently than WP_Query, we have to alter the return value (stripping * the leading AND keyword from the query). * * @since 2.3.0 * * @param array $date_query An array of date_query parameters. See the * documentation for the first parameter of WP_Date_Query. * @return string */ public static function get_date_query_sql($date_query = array()) { // Bail if not a proper date query format. if (empty($date_query) || !is_array($date_query)) { return ''; } // Date query. $date_query = new BP_Date_Query($date_query, 'date_recorded'); // Strip the leading AND - it's handled in get(). return preg_replace('/^\\sAND/', '', $date_query->get_sql()); }