Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function mycred_todays_entries( $ref = '', $user_id = NULL, $format = true )
- {
- // Reference is required
- if ( empty( $ref ) ) return false;
- global $wpdb;
- // The myCRED Log
- $db = $wpdb->prefix . 'myCRED_log';
- // Get myCRED
- $mycred = mycred_get_settings();
- // Get Now
- $now = date_i18n( 'U' );
- // Get start of today
- $today = date_i18n( 'Y/m/d 00:00:00' );
- $today = strtotime( $today );
- // The DB Query
- if ( $user_id !== NULL ) {
- // Query todays entries for a specific user
- $sql = "SELECT creds FROM {$db} WHERE ref = %s AND user_id = %d AND time >= %d AND time <= %d ORDER BY time ";
- $query = $wpdb->get_results( $wpdb->prepare( $sql, $ref, $user_id, $today, $now ) );
- }
- else {
- // Query todays entries for everyone
- $sql = "SELECT creds FROM {$db} WHERE ref = %s AND time >= %d AND time <= %d ORDER BY time ";
- $query = $wpdb->get_results( $wpdb->prepare( $sql, $ref, $today, $now ) );
- }
- $count = 0;
- // if we have results we add creds up
- if ( !empty( $query ) ) {
- foreach ( $query as $entry ) {
- $count = $count+$entry->creds;
- }
- }
- if ( $format )
- return $mycred->number( $count );
- else
- return $count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement