Last active
July 17, 2018 09:44
-
-
Save unaibamir/96770d6c6405419f8b0c25407143785a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function get_timefilter() { | |
$query = ''; | |
if ( $this->args['timeframe'] === NULL || strlen( $this->args['timeframe'] ) == 0 ) return $query; | |
global $wpdb; | |
// Start of the week based of our settings | |
$week_starts = get_option( 'start_of_week' ); | |
if ( $week_starts == 0 ) | |
$week_starts = 'sunday'; | |
else | |
$week_starts = 'monday'; | |
// Filter: Daily | |
if ( $this->args['timeframe'] == 'today' ) | |
$query = $wpdb->prepare( "AND l.time BETWEEN %d AND %d", strtotime( 'today midnight', $this->now ), $this->now ); | |
// Filter: Weekly | |
elseif ( $this->args['timeframe'] == 'this-week' ) | |
$query = $wpdb->prepare( "AND l.time BETWEEN %d AND %d", strtotime( $week_starts . ' this week', $this->now ), $this->now ); | |
// Filter: Monthly | |
elseif ( $this->args['timeframe'] == 'this-month' ) | |
$query = $wpdb->prepare( "AND l.time BETWEEN %d AND %d", strtotime( date( 'Y-m-01', $this->now ) ), $this->now ); | |
else { | |
$start_from = strtotime( $this->args['timeframe'], $this->now ); | |
if ( $start_from !== false && $start_from > 0 ) | |
$query = $wpdb->prepare( "AND l.time BETWEEN %d AND %d", $start_from, $this->now ); | |
} | |
return apply_filters( 'mycred_leaderboard_time_filter', $query, $this ); | |
} | |
add_filter( "mycred_leaderboard_time_filter", "wn_test_func", 10, 2 ); | |
function wn_test_func( $query, $object ) { | |
if ( $object->args['timeframe'] === NULL || strlen( $object->args['timeframe'] ) == 0 ) return $query; | |
global $wpdb; | |
if( strpos( $object->args['timeframe'], "last-month") !== false ) { | |
$last_month = new DateTime('-1 month'); | |
$query = $wpdb->prepare( "AND l.time BETWEEN %d AND %d", strtotime($last_month->format("Y-m-01")), strtotime($last_month->format("Y-m-t")) ); | |
} | |
else if( strpos( $object->args['timeframe'], "last-year") !== false ) { | |
$last_year = new DateTime('-1 year'); | |
$query = $wpdb->prepare( "AND l.time BETWEEN %d AND %d", strtotime($last_year->format("Y-m-01")), $object->now ); | |
} | |
return $query; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment