Ejemplo n.º 1
0
 /**
  * Construct
  */
 function __construct($type = 'mycred_default')
 {
     // Prep
     $this->is_multisite = is_multisite();
     $this->use_master_template = mycred_override_settings();
     $this->use_central_logging = mycred_centralize_log();
     if ($type == '' || $type === NULL) {
         $type = 'mycred_default';
     }
     // Load Settings
     $option_id = 'mycred_pref_core';
     if ($type != 'mycred_default' && $type != '') {
         $option_id .= '_' . $type;
     }
     $this->core = mycred_get_option($option_id, $this->defaults());
     if ($this->core !== false) {
         foreach ((array) $this->core as $key => $value) {
             $this->{$key} = $value;
         }
     }
     if ($type != '') {
         $this->cred_id = $type;
     }
     if (defined('MYCRED_LOG_TABLE')) {
         $this->log_table = MYCRED_LOG_TABLE;
     } else {
         global $wpdb;
         if ($this->is_multisite && $this->use_central_logging) {
             $this->log_table = $wpdb->base_prefix . 'myCRED_log';
         } else {
             $this->log_table = $wpdb->prefix . 'myCRED_log';
         }
     }
     do_action_ref_array('mycred_settings', array(&$this));
 }
Ejemplo n.º 2
0
 /**
  * Construct
  */
 public function __construct()
 {
     $skey = mycred_get_option('mycred_key', false);
     if ($skey === false) {
         $skey = $this->reset_key();
     }
     $this->skey = $skey;
 }
Ejemplo n.º 3
0
 function mycred_update_to_onefive($version = NULL)
 {
     if ($version === NULL) {
         return;
     }
     // Clean up after the 1.4.6 Email Notice bug
     if (version_compare($version, '1.4.7', '<')) {
         $cron = get_option('cron');
         if (!empty($cron)) {
             foreach ($cron as $time => $job) {
                 if (isset($job['mycred_send_email_notices'])) {
                     unset($cron[$time]);
                 }
             }
             update_option('cron', $cron);
         }
     }
     // 1.4 Update
     if (version_compare($version, '1.4', '>=')) {
         delete_option('mycred_update_req_settings');
         delete_option('mycred_update_req_hooks');
     }
     // 1.5 Update
     if (version_compare($version, '1.5', '<') && class_exists('myCRED_buyCRED_Module')) {
         // Update buyCRED Settings
         $type_set = 'mycred_default';
         $setup = mycred_get_option('mycred_pref_core', false);
         if (isset($setup['buy_creds'])) {
             if (isset($setup['buy_creds']['type'])) {
                 $type_set = $setup['buy_creds']['type'];
                 unset($setup['buy_creds']['type']);
                 $setup['buy_creds']['types'] = array($type_set);
                 mycred_update_option('mycred_pref_core', $setup);
             }
         }
         // Update buyCRED Gateways Settings
         $buy_cred = mycred_get_option('mycred_pref_buycreds', false);
         if (isset($buy_cred['gateway_prefs'])) {
             foreach ($buy_cred['gateway_prefs'] as $gateway_id => $prefs) {
                 if (!isset($prefs['exchange'])) {
                     continue;
                 }
                 $buy_cred['gateway_prefs'][$gateway_id]['exchange'] = array($type_set => $prefs['exchange']);
             }
             $buy_cred['active'] = array();
             mycred_update_option('mycred_pref_buycreds', $buy_cred);
             add_option('mycred_buycred_reset', 'true');
         }
         // Update complted
         update_option('mycred_version', '1.5.4');
     } else {
         delete_option('mycred_buycred_reset');
     }
 }
Ejemplo n.º 4
0
 /**
  * Construct
  */
 public function __construct($custom_key = NULL)
 {
     if ($custom_key !== NULL) {
         $this->skey = $custom_key;
     } else {
         $skey = mycred_get_option('mycred_key', false);
         if ($skey === false) {
             $skey = $this->reset_key();
         }
         $this->skey = $skey;
     }
 }
Ejemplo n.º 5
0
 /**
  * Save
  * Saves the given preference id for rates.
  * from the active list.
  * @since 1.2
  * @version 1.1
  */
 public function save($id, $now)
 {
     if (!isset($this->prefs[$id])) {
         return;
     }
     $this->prefs[$id] = $now;
     // Get Bank settings
     $bank = mycred_get_option('mycred_pref_bank');
     // Update settings
     $bank['service_prefs'][$this->id] = $this->prefs;
     // Save new settings
     mycred_update_option('mycred_pref_bank', $bank);
 }
 /**
  * Set Settings
  * @since 0.1
  * @version 1.2
  */
 function set_settings()
 {
     $module = $this->module_name;
     // Reqest not to register any settings
     if ($this->register === false) {
         // If settings does not exist apply defaults
         if (!isset($this->core->{$module})) {
             $this->{$module} = $this->default_prefs;
         } else {
             $this->{$module} = $this->core->{$module};
         }
         // Apply defaults in case new settings have been applied
         if (!empty($defaults)) {
             $this->{$module} = mycred_apply_defaults($this->default_prefs, $this->{$module});
         }
     } else {
         // Option IDs must be provided
         if (!empty($this->option_id)) {
             // Array = more then one
             if (is_array($this->option_id)) {
                 // General settings needs not to be loaded
                 $pattern = 'mycred_pref_core';
                 //$matches = array_filter( $this->option_id, function( $a ) use ( $pattern ) { return preg_grep( $a, $pattern ); } );
                 //if ( ! empty( $matches ) )
                 $this->{$module} = $this->core;
                 // Loop and grab
                 foreach ($this->option_id as $option_id => $option_name) {
                     $settings = mycred_get_option($option_name, false);
                     if ($settings === false && array_key_exists($option_id, $defaults)) {
                         $this->{$module}[$option_name] = $this->default_prefs[$option_id];
                     } else {
                         $this->{$module}[$option_name] = $settings;
                     }
                     // Apply defaults in case new settings have been applied
                     if (array_key_exists($option_id, $defaults)) {
                         $this->{$module}[$option_name] = mycred_apply_defaults($this->default_prefs[$option_id], $this->{$module}[$option_name]);
                     }
                 }
             } else {
                 // General settings needs not to be loaded
                 if (str_replace('mycred_pref_core', '', $this->option_id) == '') {
                     $this->{$module} = $this->core;
                 } else {
                     $this->{$module} = mycred_get_option($this->option_id, false);
                     if ($this->{$module} === false && !empty($this->default_prefs)) {
                         $this->{$module} = $this->default_prefs;
                     }
                     // Apply defaults in case new settings have been applied
                     if (!empty($this->default_prefs)) {
                         $this->{$module} = mycred_apply_defaults($this->default_prefs, $this->{$module});
                     }
                 }
             }
             if (is_array($this->{$module})) {
                 foreach ($this->{$module} as $key => $value) {
                     $this->{$key} = $value;
                 }
             }
         }
     }
 }
Ejemplo n.º 7
0
 function mycred_update_to_onesix($version = NULL)
 {
     if ($version === NULL) {
         return;
     }
     // 1.6 Update
     if (version_compare($version, '1.6', '<')) {
         global $wpdb;
         $types = mycred_get_types();
         // Remove Login hook markers
         if (count($types) == 1) {
             $wpdb->delete($wpdb->usermeta, array('meta_key' => 'mycred_last_login'), array('%s'));
         } else {
             foreach ($types as $type_id => $label) {
                 $wpdb->delete($wpdb->usermeta, array('meta_key' => 'mycred_last_login_' . $type_id), array('%s'));
             }
         }
         // Update email notices to support multiple point types
         if (class_exists('myCRED_Email_Notice_Module')) {
             $notices = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'mycred_email_notice' AND post_status != 'trash';");
             if (!empty($notices)) {
                 foreach ($notices as $notice_id) {
                     update_post_meta((int) $notice_id, 'mycred_email_ctype', 'all');
                 }
             }
         }
         // Update ranks to support multiple point types
         if (class_exists('myCRED_Ranks_Module')) {
             $ranks = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'mycred_rank' AND post_status != 'trash';");
             if (!empty($ranks)) {
                 foreach ($ranks as $rank_id) {
                     update_post_meta((int) $rank_id, 'ctype', 'mycred_default');
                 }
             }
         }
     } elseif (version_compare($version, '1.6.7', '<')) {
         $addons = mycred_get_option('mycred_pref_addons');
         $addons = maybe_unserialize($addons);
         // Remove built-in add-ons Paths.
         if (!empty($addons['installed'])) {
             foreach ($addons['installed'] as $id => $info) {
                 $addons['installed'][$id]['path'] = str_replace(myCRED_ADDONS_DIR, '', $info['path']);
             }
             mycred_update_option('mycred_pref_addons', $addons);
         }
     }
     // Update complted
     update_option('mycred_version', myCRED_VERSION);
 }
Ejemplo n.º 8
0
 /**
  * Sanititze Settings
  * @filter 'mycred_save_core_prefs'
  * @since 0.1
  * @version 1.4.1
  */
 public function sanitize_settings($post)
 {
     $new_data = array();
     if ($this->mycred_type == 'mycred_default') {
         if (isset($post['types'])) {
             $types = array('mycred_default' => mycred_label());
             foreach ($post['types'] as $item => $data) {
                 // Make sure it is not marked as deleted
                 if (isset($post['delete_types']) && in_array($item, $post['delete_types'])) {
                     continue;
                 }
                 // Skip if empty
                 if (empty($data['key']) || empty($data['label'])) {
                     continue;
                 }
                 // Add if not in array already
                 if (!array_key_exists($data['key'], $types)) {
                     $key = str_replace(array(' ', '-'), '_', $data['key']);
                     $key = sanitize_key($key);
                     $types[$key] = sanitize_text_field($data['label']);
                 }
             }
             mycred_update_option('mycred_types', $types);
             unset($post['types']);
             if (isset($post['delete_types'])) {
                 unset($post['delete_types']);
             }
         }
         $new_data['format'] = $this->core->core['format'];
         if (isset($post['format']['type']) && $post['format']['type'] != '') {
             $new_data['format']['type'] = absint($post['format']['type']);
         }
         if (isset($post['format']['decimals'])) {
             $new_data['format']['decimals'] = absint($post['format']['decimals']);
         }
     } else {
         $main_settings = mycred_get_option('mycred_pref_core');
         $new_data['format'] = $main_settings['format'];
         if (isset($post['format']['decimals'])) {
             $new_decimals = absint($post['format']['decimals']);
             if ($new_decimals <= $main_settings['format']['decimals']) {
                 $new_data['format']['decimals'] = $new_decimals;
             }
         }
     }
     // Format
     $new_data['cred_id'] = $this->mycred_type;
     $new_data['format']['separators']['decimal'] = $this->maybe_whitespace($post['format']['separators']['decimal']);
     $new_data['format']['separators']['thousand'] = $this->maybe_whitespace($post['format']['separators']['thousand']);
     // Name
     $new_data['name'] = array('singular' => sanitize_text_field($post['name']['singular']), 'plural' => sanitize_text_field($post['name']['plural']));
     // Look
     $new_data['before'] = sanitize_text_field($post['before']);
     $new_data['after'] = sanitize_text_field($post['after']);
     // Capabilities
     $new_data['caps'] = array('plugin' => sanitize_text_field($post['caps']['plugin']), 'creds' => sanitize_text_field($post['caps']['creds']));
     // Max
     $new_data['max'] = $this->core->number($post['max']);
     // Make sure multisites uses capabilities that exists
     if (in_array($new_data['caps']['creds'], array('create_users', 'delete_themes', 'edit_plugins', 'edit_themes', 'edit_users')) && is_multisite()) {
         $new_data['caps']['creds'] = 'delete_users';
     }
     // Excludes
     $new_data['exclude'] = array('plugin_editors' => isset($post['exclude']['plugin_editors']) ? $post['exclude']['plugin_editors'] : 0, 'cred_editors' => isset($post['exclude']['cred_editors']) ? $post['exclude']['cred_editors'] : 0, 'list' => sanitize_text_field($post['exclude']['list']));
     // Remove Exclude users balances
     if ($new_data['exclude']['list'] != '') {
         $excluded_ids = explode(',', $new_data['exclude']['list']);
         if (!empty($excluded_ids)) {
             foreach ((array) $excluded_ids as $user_id) {
                 $user_id = absint(trim($user_id));
                 if ($user_id == 0) {
                     continue;
                 }
                 mycred_delete_user_meta($user_id, $this->mycred_type);
                 mycred_delete_user_meta($user_id, $this->mycred_type, '_total');
             }
         }
     }
     // User deletions
     $new_data['delete_user'] = isset($post['delete_user']) ? $post['delete_user'] : 0;
     $action_hook = '';
     if (!$this->is_main_type) {
         $action_hook = $this->mycred_type;
     }
     $new_data = apply_filters('mycred_save_core_prefs' . $action_hook, $new_data, $post, $this);
     return $new_data;
 }
Ejemplo n.º 9
0
 function mycred_use_coupon($code = '', $user_id = 0)
 {
     // Missing required information
     if (empty($code) || $user_id === 0) {
         return 'missing';
     }
     // Get coupon by code (post title)
     $coupon = mycred_get_coupon_post($code);
     // Coupon does not exist
     if ($coupon === NULL) {
         return 'missing';
     }
     // Check Expiration
     $expires = mycred_get_coupon_expire_date($coupon->ID, true);
     if (!empty($expires) && $expires !== 0 && $expires < date_i18n('U')) {
         wp_trash_post($coupon->ID);
         return 'expired';
     }
     // Get Global Count
     $global_count = mycred_get_global_coupon_count($coupon->ID);
     // We start with enforcing the global count
     $global_max = mycred_get_coupon_global_max($coupon->ID);
     if ($global_count >= $global_max) {
         wp_trash_post($coupon->ID);
         return 'expired';
     }
     $type = get_post_meta($coupon->ID, 'type', true);
     if (empty($type)) {
         $type = 'mycred_default';
     }
     $mycred = mycred($type);
     // Get User max
     $user_count = mycred_get_users_coupon_count($code, $user_id);
     // Next we enforce the user max
     $user_max = mycred_get_coupon_user_max($coupon->ID);
     if ($user_count >= $user_max) {
         return 'max';
     }
     // Min balance requirement
     $users_balance = $mycred->get_users_cred($user_id, $type);
     $min_balance = mycred_get_coupon_min_balance($coupon->ID);
     if ($min_balance > $mycred->zero() && $users_balance < $min_balance) {
         return 'min_balance';
     }
     // Max balance requirement
     $max_balance = mycred_get_coupon_max_balance($coupon->ID);
     if ($max_balance > $mycred->zero() && $users_balance >= $max_balance) {
         return 'max_balance';
     }
     // Ready to use coupon!
     $value = mycred_get_coupon_value($coupon->ID);
     $value = $mycred->number($value);
     // Get Coupon log template
     $settings = mycred_get_option('mycred_pref_core');
     if (!isset($mycred->core['coupons']['log'])) {
         $mycred->core['coupons']['log'] = __('Coupon redemption', 'mycred');
     }
     // Apply Coupon
     $mycred->add_creds('coupon', $user_id, $value, $mycred->core['coupons']['log'], $coupon->ID, $code, $type);
     do_action('mycred_use_coupon', $user_id, $coupon);
     // Increment global counter
     $global_count++;
     update_post_meta($coupon->ID, 'global_count', $global_count);
     // If the updated counter reaches the max, trash the coupon now
     if ($global_count >= $global_max) {
         wp_trash_post($coupon->ID);
     }
     return $mycred->number($users_balance + $value);
 }
 /**
  * Save User Override
  * @since 1.5.2
  * @version 1.0.1
  */
 function save_user_override()
 {
     // Save interest rate
     if (isset($_POST['mycred_adjust_users_interest_rate_run']) && isset($_POST['mycred_adjust_users_interest_rate'])) {
         $ctype = sanitize_key($_GET['ctype']);
         $user_id = absint($_GET['user_id']);
         $rate = $_POST['mycred_adjust_users_interest_rate'];
         if ($rate != '') {
             if (isfloat($rate)) {
                 $rate = (double) $rate;
             } else {
                 $rate = (int) $rate;
             }
             mycred_update_user_meta($user_id, 'mycred_banking_rate_' . $ctype, '', $rate);
         } else {
             mycred_delete_user_meta($user_id, 'mycred_banking_rate_' . $ctype);
         }
         wp_safe_redirect(add_query_arg(array('result' => 'banking_interest_rate')));
         exit;
     } elseif (isset($_POST['mycred_exclude_users_interest_rate'])) {
         $ctype = sanitize_key($_GET['ctype']);
         $user_id = absint($_GET['user_id']);
         $excluded = explode(',', $this->prefs['exclude_ids']);
         $clean_ids = array();
         if (!empty($excluded)) {
             foreach ($excluded as $id) {
                 if ($id == 0) {
                     continue;
                 }
                 $clean_ids[] = (int) trim($id);
             }
         }
         if (!in_array($user_id, $clean_ids) && $user_id != 0) {
             $clean_ids[] = $user_id;
         }
         $option_id = 'mycred_pref_bank';
         if (!$this->is_main_type) {
             $option_id .= '_' . $ctype;
         }
         $data = mycred_get_option($option_id);
         $data['service_prefs'][$this->id]['exclude_ids'] = implode(',', $clean_ids);
         mycred_update_option($option_id, $data);
         wp_safe_redirect(add_query_arg(array('result' => 'banking_interest_excluded')));
         exit;
     } elseif (isset($_POST['mycred_include_users_interest_rate'])) {
         $ctype = sanitize_key($_GET['ctype']);
         $user_id = absint($_GET['user_id']);
         $excluded = explode(',', $this->prefs['exclude_ids']);
         if (!empty($excluded)) {
             $clean_ids = array();
             foreach ($excluded as $id) {
                 $clean_id = (int) trim($id);
                 if ($clean_id != $user_id && $user_id != 0) {
                     $clean_ids[] = $clean_id;
                 }
             }
             $option_id = 'mycred_pref_bank';
             if (!$this->is_main_type) {
                 $option_id .= '_' . $ctype;
             }
             $data = mycred_get_option($option_id);
             $data['service_prefs'][$this->id]['exclude_ids'] = implode(',', $clean_ids);
             mycred_update_option($option_id, $data);
             wp_safe_redirect(add_query_arg(array('result' => 'banking_interest_included')));
             exit;
         }
     }
 }
 /**
  * Update Cycles
  * @since 1.5.2
  * @version 1.0
  */
 public function update_cycles()
 {
     // Manage cycles if it's not set to unlimited
     if ($this->prefs['cycles'] != '-1' && $this->prefs['cycles'] != 0) {
         // Prep option id for this addon.
         $option_id = 'mycred_pref_bank';
         if (!$this->is_main_type) {
             $option_id .= '_' . $this->mycred_type;
         }
         // Get addon settings
         $addon = mycred_get_option($option_id);
         // Deduct cycle
         $current_cycle = (int) $this->prefs['cycles'];
         $current_cycle--;
         $addon['service_prefs'][$this->id]['cycles'] = $current_cycle;
         // If we reach zero, disable this service
         if ($current_cycle == 0 && in_array($this->id, $addon['active'])) {
             $new_active = array();
             foreach ($addon['active'] as $active) {
                 if ($active == $this->id || in_array($active, $new_active)) {
                     continue;
                 }
                 $new_active[] = $active;
             }
             $addon['active'] = $new_active;
         }
         // Update settings
         mycred_update_option($option_id, $addon);
     }
 }
 /**
  * Last Run
  * @since 1.2
  * @version 1.1
  */
 public function get_last_run($instance = '')
 {
     $key = 'mycred_banking_' . $this->id . '_' . $instance . $this->mycred_type;
     return mycred_get_option($key, 'n/a');
 }
Ejemplo n.º 13
0
    function mycred_render_shortcode_video($atts)
    {
        global $mycred_video_points;
        $hooks = mycred_get_option('mycred_pref_hooks', false);
        if ($hooks === false) {
            return;
        }
        $prefs = $hooks['hook_prefs']['video_view'];
        extract(shortcode_atts(array('id' => NULL, 'width' => 560, 'height' => 315, 'amount' => $prefs['creds'], 'logic' => $prefs['logic'], 'interval' => $prefs['interval'], 'ctype' => 'mycred_default'), $atts));
        // ID is required
        if ($id === NULL || empty($id)) {
            return __('A video ID is required for this shortcode', 'mycred');
        }
        // Interval
        if (strlen($interval) < 3) {
            $interval = abs($interval * 1000);
        }
        // Video ID
        $video_id = str_replace('-', '__', $id);
        // Create key
        $key = mycred_create_token(array('youtube', $video_id, $amount, $logic, $interval));
        if (!isset($mycred_video_points) || !is_array($mycred_video_points)) {
            $mycred_video_points = array();
        }
        // Construct YouTube Query
        $query = apply_filters('mycred_video_query_youtube', array('enablejsapi' => 1, 'version' => 3, 'playerapiid' => 'mycred_vvideo_v' . $video_id, 'rel' => 0, 'controls' => 1, 'showinfo' => 0), $atts, $video_id);
        // Construct Youtube Query Address
        $url = 'https://www.youtube.com/embed/' . $id;
        $url = add_query_arg($query, $url);
        $mycred_video_points[] = 'youtube';
        // Make sure video source ids are unique
        $mycred_video_points = array_unique($mycred_video_points);
        ob_start();
        ?>
<div class="mycred-video-wrapper youtube-video">
	<iframe id="mycred_vvideo_v<?php 
        echo $video_id;
        ?>
" class="mycred-video mycred-youtube-video" data-vid="<?php 
        echo $video_id;
        ?>
" src="<?php 
        echo $url;
        ?>
" width="<?php 
        echo $width;
        ?>
" height="<?php 
        echo $height;
        ?>
" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
	<script type="text/javascript">
function mycred_vvideo_v<?php 
        echo $video_id;
        ?>
( state ) {
	duration[ "<?php 
        echo $video_id;
        ?>
" ] = state.target.getDuration();
	mycred_view_video( "<?php 
        echo $video_id;
        ?>
", state.data, "<?php 
        echo $logic;
        ?>
", "<?php 
        echo $interval;
        ?>
", "<?php 
        echo $key;
        ?>
", "<?php 
        echo $ctype;
        ?>
" );
}
	</script>
</div>
<?php 
        $output = ob_get_contents();
        ob_end_clean();
        // Return the shortcode output
        return apply_filters('mycred_video_output', $output, $atts);
    }
 function mycred_render_shortcode_total_points($atts)
 {
     extract(shortcode_atts(array('type' => 'mycred_default', 'ref' => '', 'ref_id' => '', 'user_id' => '', 'formatted' => 1), $atts));
     $types = mycred_get_types();
     if (!array_key_exists($type, $types)) {
         $type = 'mycred_default';
     }
     // First we construct the meta_key
     $point_type = $type;
     if (is_multisite() && $GLOBALS['blog_id'] > 1 && !mycred_centralize_log()) {
         $type .= '_' . $GLOBALS['blog_id'];
     } elseif (is_multisite() && $GLOBALS['blog_id'] > 1 && !mycred_override_settings()) {
         $type .= '_' . $GLOBALS['blog_id'];
     }
     $mycred = mycred($point_type);
     global $wpdb;
     // Simple
     if ($ref == '' && $ref_id == '' && $user_id == '') {
         // Check if cached value exists
         $total = mycred_get_option('mycred-cache-total-' . $point_type, false);
         if ($total === false) {
             // Add up all balances
             $total = $wpdb->get_var($wpdb->prepare("SELECT SUM( meta_value ) FROM {$wpdb->usermeta} WHERE meta_key = %s", $type));
             if ($total !== NULL) {
                 mycred_update_option('mycred-cache-total-' . $point_type, $total);
             }
         }
     } else {
         $wheres = array();
         $wheres[] = $wpdb->prepare("ctype = %s", $point_type);
         $ref = sanitize_key($ref);
         if (strlen($ref) > 0) {
             // Either we have just one reference
             $multiple = explode(',', $ref);
             if (count($multiple) == 1) {
                 $wheres[] = $wpdb->prepare("ref = %s", $ref);
             } else {
                 $_clean = array();
                 foreach ($multiple as $ref) {
                     $ref = sanitize_key($ref);
                     if (strlen($ref) > 0) {
                         $_clean[] = $ref;
                     }
                 }
                 if (!empty($_clean)) {
                     $wheres[] = "ref IN ( '" . implode("', '", $_clean) . "' )";
                 }
             }
         }
         $ref_id = sanitize_text_field($ref);
         if (strlen($ref_id) > 0) {
             $wheres[] = $wpdb->prepare("ref_id = %d", $ref_id);
         }
         $user_id = sanitize_text_field($ref);
         if (strlen($user_id) > 0) {
             $wheres[] = $wpdb->prepare("user_id = %d", $user_id);
         }
         $wheres = implode(" AND ", $wheres);
         $total = $wpdb->get_var("SELECT SUM( creds ) FROM {$mycred->log_table} WHERE {$wheres};");
     }
     if ($total === NULL) {
         $total = 0;
     }
     if ($formatted == 1) {
         return $mycred->format_creds($total);
     }
     return $total;
 }