Пример #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));
 }
Пример #2
0
 /**
  * Uninstall
  * TODO: Add a call to all add-ons to allow them to uninstall their own
  * settings and data once the core is gone.
  * @filter 'mycred_uninstall_this'
  * @since 0.1
  * @version 1.3
  */
 public function uninstall()
 {
     // Everyone should use this filter to delete everything else they have created before returning the option ids.
     $installed = apply_filters('mycred_uninstall_this', array('mycred_pref_core', 'mycred_pref_hooks', 'mycred_pref_addons', 'mycred_pref_bank'));
     // Delete each option
     foreach ($installed as $option_id) {
         delete_option($GLOBALS['blog_id'], $option_id);
     }
     // Delete flags
     delete_option('mycred_setup_completed');
     delete_option('mycred_version');
     delete_option('mycred_version_db');
     delete_option('mycred_key');
     // Delete widget options
     delete_option('widget_mycred_widget_balance');
     delete_option('widget_mycred_widget_list');
     delete_option('widget_mycred_widget_transfer');
     delete_option('mycred_ref_hook_counter');
     // Remove Add-on settings
     delete_option('mycred_espresso_gateway_prefs');
     delete_option('mycred_eventsmanager_gateway_prefs');
     // Clear Cron
     wp_clear_scheduled_hook('mycred_reset_key');
     wp_clear_scheduled_hook('mycred_banking_recurring_payout');
     wp_clear_scheduled_hook('mycred_banking_do_batch');
     wp_clear_scheduled_hook('mycred_banking_interest_compound');
     wp_clear_scheduled_hook('mycred_banking_do_compound_batch');
     wp_clear_scheduled_hook('mycred_banking_interest_payout');
     wp_clear_scheduled_hook('mycred_banking_interest_do_batch');
     global $wpdb;
     // Get log table
     if (defined('MYCRED_LOG_TABLE')) {
         $table_name = MYCRED_LOG_TABLE;
     } else {
         if (mycred_centralize_log()) {
             $table_name = $wpdb->base_prefix . 'myCRED_log';
         } else {
             $table_name = $wpdb->prefix . 'myCRED_log';
         }
     }
     // Delete log table
     $wpdb->query("DROP TABLE IF EXISTS {$table_name};");
     // Multisite
     if (is_multisite()) {
         delete_site_option('mycred_network');
     }
     // Delete custom post types
     $post_types = apply_filters('mycred_custom_post_types', array('mycred_rank', 'mycred_email_notice'));
     if (is_array($post_types) || !empty($post_types)) {
         $wpdb->query("DELETE FROM {$wpdb->posts} WHERE post_type IN ('" . implode("','", $post_types) . "');");
     }
     // Delete all point types
     $mycred_types = mycred_get_types();
     foreach ($mycred_types as $type => $label) {
         $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE meta_key = %s;", $type));
     }
     // Good bye.
 }
Пример #3
0
 function mycred_render_shortcode_best_user($attr, $content = '')
 {
     extract(shortcode_atts(array('ref' => '', 'from' => '', 'until' => '', 'types' => 'mycred_default', 'nothing' => 'No user found', 'order' => 'DESC', 'avatar' => 50), $attr));
     if ($ref != '') {
         $references = explode(',', $ref);
     } else {
         $references = '';
     }
     $point_types = explode(',', $types);
     if (empty($point_types)) {
         $point_types = array('mycred_default');
     }
     $now = current_time('timestamp');
     if ($from == 'now') {
         $from = $now;
     } elseif ($from != '') {
         $from = strtotime($from);
     }
     if ($from == 0) {
         $from = '';
     }
     if ($until == 'now') {
         $until = $now;
     } elseif ($until != '') {
         $until = strtotime($until);
     }
     if ($until == 0) {
         $until = '';
     }
     global $wpdb;
     if (defined('MYCRED_LOG_TABLE')) {
         $table = MYCRED_LOG_TABLE;
     } else {
         if (is_multisite() && mycred_centralize_log()) {
             $table = $wpdb->base_prefix . 'myCRED_log';
         } else {
             $table = $wpdb->prefix . 'myCRED_log';
         }
     }
     $wheres = $preps = array();
     if (!empty($references)) {
         $wheres[] = "ref IN (" . str_repeat('%s', count($references)) . ")";
         foreach ($references as $reference) {
             $preps[] = $reference;
         }
     }
     $wheres[] = "ctype IN (" . str_repeat('%s', count($point_types)) . ")";
     foreach ($point_types as $point_type) {
         $preps[] = $point_type;
     }
     if ($from != '' || $until != '') {
         if ($from != '' && $until == '') {
             $wheres[] = $wpdb->prepare("time >= %d", $from);
         } elseif ($from == '' && $until != '') {
             $wheres[] = $wpdb->prepare("time <= %d", $until);
         } elseif ($from != '' && $until != '') {
             $wheres[] = $wpdb->prepare("time BETWEEN %d AND %d", $from, $until);
         }
     }
     $where = 'WHERE ' . implode(' AND ', $wheres);
     $where = $wpdb->prepare($where, $preps);
     if (!in_array($order, array('DESC', 'ASC'))) {
         $order = 'DESC';
     }
     $result = $wpdb->get_row("SELECT user_id, SUM( creds ) AS total, COUNT(*) AS count FROM {$table} {$where} ORDER BY SUM( creds ) {$order} LIMIT 0,1;");
     if (!isset($result->user_id)) {
         return '<p class="mycred-best-user-no-results text-center">' . $nothing . '</p>';
     }
     $user = get_userdata($result->user_id);
     if (!isset($user->display_name)) {
         return '<p class="mycred-best-user-no-results text-center">' . $nothing . '</p>';
     }
     if (empty($content)) {
         $content = '<div class="mycred-best-user text-center">%avatar%<h4>%display_name%</h4></div>';
     }
     $content = apply_filters('mycred_best_user_content', $content, $attr, $table);
     $content = str_replace('%display_name%', $user->display_name, $content);
     $content = str_replace('%first_name%', $user->first_name, $content);
     $content = str_replace('%last_name%', $user->last_name, $content);
     $content = str_replace('%user_email%', $user->user_email, $content);
     $content = str_replace('%user_login%', $user->user_login, $content);
     $content = str_replace('%avatar%', get_avatar($result->user_id, $avatar), $content);
     $content = str_replace('%total%', $user->total, $content);
     $content = str_replace('%total_abs%', abs($user->total), $content);
     $content = str_replace('%count%', $user->count, $content);
     $content = str_replace('%debug%', print_r($sql, true), $content);
     return apply_filters('mycred_render_best_user', $content, $result, $atts, $table);
 }
Пример #4
0
        /**
         * Admin Page
         * @since 0.1
         * @version 1.4
         */
        public function admin_page()
        {
            // Security
            if (!$this->core->can_edit_plugin()) {
                wp_die(__('Access Denied', 'mycred'));
            }
            // General Settings
            $general = $this->general;
            $action_hook = '';
            if (!$this->is_main_type) {
                $action_hook = $this->mycred_type;
            }
            $delete_user = 0;
            if (isset($this->core->delete_user)) {
                $delete_user = $this->core->delete_user;
            }
            // Social Media Links
            $facebook = '<a href="https://www.facebook.com/myCRED" class="facebook" target="_blank">Facebook</a>';
            $google = '<a href="https://plus.google.com/+MycredMe/posts" class="googleplus" target="_blank">Google+</a>';
            ?>
<div class="wrap list" id="myCRED-wrap">
	<h2><?php 
            echo sprintf(__('%s Settings', 'mycred'), mycred_label());
            ?>
 <?php 
            echo myCRED_VERSION;
            ?>
</h2>

	<?php 
            $this->update_notice();
            ?>

	<p><?php 
            _e('Adjust your core or add-on settings.', 'mycred');
            ?>
<span id="mycred-social-media"><?php 
            echo $facebook . $google;
            ?>
</span></p>
	<form method="post" action="options.php" name="mycred-core-settings-form" novalidate>

		<?php 
            settings_fields($this->settings_name);
            ?>

		<div class="list-items expandable-li" id="accordion">
			<h4><div class="icon icon-inactive core"></div><label><?php 
            _e('Core Settings', 'mycred');
            ?>
</label></h4>
			<div class="body" style="display:none;">
				<label class="subheader"><?php 
            _e('Name', 'mycred');
            ?>
</label>
				<ol id="myCRED-settings-name" class="inline">
					<li>
						<label for="<?php 
            echo $this->field_id(array('name' => 'singular'));
            ?>
"><?php 
            _e('Name (Singular)', 'mycred');
            ?>
</label>
						<div class="h2"><input type="text" name="<?php 
            echo $this->field_name(array('name' => 'singular'));
            ?>
" id="<?php 
            echo $this->field_id(array('name' => 'singular'));
            ?>
" value="<?php 
            echo $this->core->name['singular'];
            ?>
" size="30" /></div>
						<span class="description"><?php 
            _e('Accessible though the %singular% template tag.', 'mycred');
            ?>
</span>
					</li>
					<li>
						<label for="<?php 
            echo $this->field_id(array('name' => 'plural'));
            ?>
"><?php 
            _e('Name (Plural)', 'mycred');
            ?>
</label>
						<div class="h2"><input type="text" name="<?php 
            echo $this->field_name(array('name' => 'plural'));
            ?>
" id="<?php 
            echo $this->field_id(array('name' => 'plural'));
            ?>
" value="<?php 
            echo $this->core->name['plural'];
            ?>
" size="30" /></div>
						<span class="description"><?php 
            _e('Accessible though the %plural% template tag.', 'mycred');
            ?>
</span>
					</li>
					<li class="block">
						<span class="description"><strong><?php 
            _e('Tip', 'mycred');
            ?>
:</strong> <?php 
            _e('Adding an underscore at the beginning of template tag for names will return them in lowercase. i.e. %_singular%', 'mycred');
            ?>
</span>
					</li>
				</ol>
				<label class="subheader"><?php 
            _e('Decimals', 'mycred');
            ?>
</label>
				<ol>

					<?php 
            $this->adjust_decimal_places();
            ?>

				</ol>
				<label class="subheader"><?php 
            _e('Presentation', 'mycred');
            ?>
</label>
				<ol id="myCRED-settings-layout" class="inline">
					<li>
						<label for="<?php 
            echo $this->field_id('before');
            ?>
"><?php 
            _e('Prefix', 'mycred');
            ?>
</label>
						<div class="h2"><input type="text" size="5" name="<?php 
            echo $this->field_name('before');
            ?>
" id="<?php 
            echo $this->field_id('before');
            ?>
" value="<?php 
            echo $this->core->before;
            ?>
" /></div>
					</li>
					<li>
						<label>&nbsp;</label>
						<div class="h2"><?php 
            echo $this->core->format_number(1000);
            ?>
</div>
					</li>
					<li>
						<label for="<?php 
            echo $this->field_id('after');
            ?>
"><?php 
            _e('Suffix', 'mycred');
            ?>
</label>
						<div class="h2"><input type="text" size="5" name="<?php 
            echo $this->field_name('after');
            ?>
" id="<?php 
            echo $this->field_id('after');
            ?>
" value="<?php 
            echo $this->core->after;
            ?>
" /></div>
					</li>
					<li class="block">
						<label for="myCRED-prefix"><?php 
            echo _n('Separator', 'Separators', (int) $this->core->format['decimals'] > 0 ? 2 : 1, 'mycred');
            ?>
</label>
						<div class="h2">1 <input type="text" size="1" maxlength="1" name="<?php 
            echo $this->field_name(array('format' => 'separators'));
            ?>
[thousand]" id="<?php 
            echo $this->field_id(array('format' => 'separators'));
            ?>
-thousand" value="<?php 
            echo $this->core->format['separators']['thousand'];
            ?>
" /> 000 <input type="<?php 
            if ((int) $this->core->format['decimals'] > 0) {
                echo 'text';
            } else {
                echo 'hidden';
            }
            ?>
" size="1" maxlength="1" name="<?php 
            echo $this->field_name(array('format' => 'separators'));
            ?>
[decimal]" id="<?php 
            echo $this->field_id(array('format' => 'separators'));
            ?>
-decimal" value="<?php 
            echo $this->core->format['separators']['decimal'];
            ?>
" /><?php 
            if ((int) $this->core->format['decimals'] > 0) {
                echo ' ' . str_repeat('0', $this->core->format['decimals']);
            }
            ?>
</div>
					</li>
				</ol>
				<label class="subheader"><?php 
            _e('Security', 'mycred');
            ?>
</label>
				<ol id="myCRED-settings-security" class="inline">
					<li>
						<label for="<?php 
            echo $this->field_id(array('caps' => 'plugin'));
            ?>
"><?php 
            _e('Edit Settings', 'mycred');
            ?>
</label>
						<div class="h2"><input type="text" name="<?php 
            echo $this->field_name(array('caps' => 'plugin'));
            ?>
" id="<?php 
            echo $this->field_id(array('caps' => 'plugin'));
            ?>
" value="<?php 
            echo $this->core->caps['plugin'];
            ?>
" size="30" /></div>
						<span class="description"><?php 
            _e('Capability to check for.', 'mycred');
            ?>
</span>
					</li>
					<li>
						<label for="<?php 
            echo $this->field_id(array('caps' => 'creds'));
            ?>
"><?php 
            echo $this->core->template_tags_general(__('Edit Users %plural%', 'mycred'));
            ?>
</label>
						<div class="h2"><input type="text" name="<?php 
            echo $this->field_name(array('caps' => 'creds'));
            ?>
" id="<?php 
            echo $this->field_id(array('caps' => 'creds'));
            ?>
" value="<?php 
            echo $this->core->caps['creds'];
            ?>
" size="30" /></div>
						<span class="description"><?php 
            _e('Capability to check for.', 'mycred');
            ?>
</span>
					</li>
					<li class="block"><?php 
            if (!isset($this->core->max)) {
                $this->core->max();
            }
            ?>
						<label for="<?php 
            echo $this->field_id('max');
            ?>
"><?php 
            echo $this->core->template_tags_general(__('Maximum %plural% payouts', 'mycred'));
            ?>
</label>
						<div class="h2"><input type="text" name="<?php 
            echo $this->field_name('max');
            ?>
" id="<?php 
            echo $this->field_id('max');
            ?>
" value="<?php 
            echo $this->core->max;
            ?>
" size="8" /></div>
						<span class="description"><?php 
            _e('As an added security, you can set the maximum amount a user can gain or loose in a single instance. If used, make sure this is the maximum amount a user would be able to transfer, buy, or spend in your store. Use zero to disable.', 'mycred');
            ?>
</span>
					</li>
				</ol>
				<label class="subheader"><?php 
            _e('Excludes', 'mycred');
            ?>
</label>
				<ol id="myCRED-settings-excludes">
					<li>
						<input type="checkbox" name="<?php 
            echo $this->field_name(array('exclude' => 'plugin_editors'));
            ?>
" id="<?php 
            echo $this->field_id(array('exclude' => 'plugin_editors'));
            ?>
" <?php 
            checked($this->core->exclude['plugin_editors'], 1);
            ?>
 value="1" />
						<label for="<?php 
            echo $this->field_id(array('exclude' => 'plugin_editors'));
            ?>
"><?php 
            _e('Exclude those who can "Edit Settings".', 'mycred');
            ?>
</label>
					</li>
					<li>
						<input type="checkbox" name="<?php 
            echo $this->field_name(array('exclude' => 'cred_editors'));
            ?>
" id="<?php 
            echo $this->field_id(array('exclude' => 'cred_editors'));
            ?>
" <?php 
            checked($this->core->exclude['cred_editors'], 1);
            ?>
 value="1" />
						<label for="<?php 
            echo $this->field_id(array('exclude' => 'cred_editors'));
            ?>
"><?php 
            echo $this->core->template_tags_general(__('Exclude those who can "Edit Users %plural%".', 'mycred'));
            ?>
</label>
					</li>
					<li class="empty">&nbsp;</li>
					<li>
						<label for="<?php 
            echo $this->field_id(array('exclude' => 'list'));
            ?>
"><?php 
            _e('Exclude the following user IDs:', 'mycred');
            ?>
</label>
						<div class="h2"><input type="text" name="<?php 
            echo $this->field_name(array('exclude' => 'list'));
            ?>
" id="<?php 
            echo $this->field_id(array('exclude' => 'list'));
            ?>
" value="<?php 
            echo $this->core->exclude['list'];
            ?>
" class="long" /></div>
						<span class="description"><?php 
            _e('Comma separated list of user ids to exclude. No spaces allowed!', 'mycred');
            ?>
</span>
					</li>
				</ol>
				<label class="subheader"><?php 
            _e('User Deletions', 'mycred');
            ?>
</label>
				<ol id="myCRED-settings-delete-user">
					<li>
						<input type="checkbox" name="<?php 
            echo $this->field_name('delete_user');
            ?>
" id="<?php 
            echo $this->field_id('delete_user');
            ?>
" <?php 
            checked($delete_user, 1);
            ?>
 value="1" /><label for="<?php 
            echo $this->field_id('delete_user');
            ?>
"><?php 
            _e('Delete log entries when user is deleted.', 'mycred');
            ?>
</label>
					</li>
				</ol>

				<?php 
            do_action('mycred_core_prefs' . $action_hook, $this);
            ?>

			</div>
<?php 
            global $wpdb;
            $total_rows = $wpdb->get_var("SELECT COUNT(1) FROM {$this->core->log_table} WHERE ctype = '{$this->mycred_type}';");
            $reset_block = false;
            if (get_transient('mycred-accounts-reset') !== false) {
                $reset_block = true;
            }
            ?>
			<h4><div class="icon icon-active core"></div><label><?php 
            _e('Management', 'mycred');
            ?>
</label></h4>
			<div class="body" style="display:none;">
				<label class="subheader"><?php 
            _e('The Log', 'mycred');
            ?>
</label>
				<ol id="myCRED-actions-log" class="inline">
					<li>
						<label><?php 
            _e('Table Name', 'mycred');
            ?>
</label>
						<div class="h2"><input type="text" id="mycred-manage-table-name" disabled="disabled" value="<?php 
            echo $this->core->log_table;
            ?>
" class="readonly" /></div>
					</li>
					<li>
						<label><?php 
            _e('Entries', 'mycred');
            ?>
</label>
						<div class="h2"><input type="text" id="mycred-manage-table-rows" disabled="disabled" value="<?php 
            echo $total_rows;
            ?>
" class="readonly short" /></div>
					</li>
					<li>
						<label><?php 
            _e('Actions', 'mycred');
            ?>
</label>
						<div class="h2"><?php 
            if (!mycred_centralize_log() || mycred_centralize_log() && $GLOBALS['blog_id'] == 1) {
                ?>
<input type="button" id="mycred-manage-action-empty-log" data-type="<?php 
                echo $this->mycred_type;
                ?>
" value="<?php 
                _e('Empty Log', 'mycred');
                ?>
" class="button button-large large <?php 
                if ($total_rows == 0) {
                    echo '"disabled="disabled';
                } else {
                    echo 'button-primary';
                }
                ?>
" /><?php 
            }
            ?>
</div>
					</li>
				</ol>
				<label class="subheader"><?php 
            echo $this->core->plural();
            ?>
</label>
				<ol id="myCRED-actions-cred" class="inline">
					<li>
						<label><?php 
            _e('User Meta Key', 'mycred');
            ?>
</label>
						<div class="h2"><input type="text" disabled="disabled" value="<?php 
            echo $this->core->cred_id;
            ?>
" class="readonly" /></div>
					</li>
					<li>
						<label><?php 
            _e('Users', 'mycred');
            ?>
</label>
						<div class="h2"><input type="text" disabled="disabled" value="<?php 
            echo $this->core->count_members();
            ?>
" class="readonly short" /></div>
					</li>
					<li>
						<label><?php 
            _e('Actions', 'mycred');
            ?>
</label>
						<div class="h2"><input type="button" id="mycred-manage-action-reset-accounts" data-type="<?php 
            echo $this->mycred_type;
            ?>
" value="<?php 
            _e('Set all to zero', 'mycred');
            ?>
" class="button button-large large <?php 
            if ($reset_block) {
                echo '" disabled="disabled';
            } else {
                echo 'button-primary';
            }
            ?>
" /> <input type="button" id="mycred-export-users-points" value="<?php 
            _e('CSV Export', 'mycred');
            ?>
" class="button button-large large"<?php 
            if ($reset_block) {
                echo ' disabled="disabled"';
            }
            ?>
 /></div>
					</li>
				</ol>

				<?php 
            do_action('mycred_management_prefs' . $action_hook, $this);
            ?>

			</div>

			<?php 
            do_action('mycred_after_management_prefs' . $action_hook, $this);
            ?>

<?php 
            if (isset($this->mycred_type) && $this->mycred_type == 'mycred_default') {
                ?>
			<h4><div class="icon single"></div><label><?php 
                _e('Point Types', 'mycred');
                ?>
</label></h4>
			<div class="body" style="display:none;">
<?php 
                if (!empty($this->point_types)) {
                    foreach ($this->point_types as $type => $label) {
                        if ($type == 'mycred_default') {
                            ?>
				<label class="subheader"><?php 
                            _e('Default', 'mycred');
                            ?>
</label>
				<ol id="myCRED-default-type" class="inline">
					<li>
						<label><?php 
                            _e('Meta Key', 'mycred');
                            ?>
</label>
						<div class="h2"><input type="text" disabled="disabled" value="<?php 
                            echo $type;
                            ?>
" class="readonly" /></div>
					</li>
					<li>
						<label><?php 
                            _e('Label', 'mycred');
                            ?>
</label>
						<div class="h2"><input type="text" disabled="disabled" value="<?php 
                            echo strip_tags($label);
                            ?>
" class="readonly" /></div>
					</li>
					<li>
						<label><?php 
                            _e('Delete', 'mycred');
                            ?>
</label>
						<div class="h2"><input type="checkbox" disabled="disabled" class="disabled" value="<?php 
                            echo $type;
                            ?>
" /></div>
					</li>
				</ol>
<?php 
                        } else {
                            ?>
				<label class="subheader"><?php 
                            echo $label;
                            ?>
</label>
				<ol id="myCRED-<?php 
                            echo $type;
                            ?>
-type" class="inline">
					<li>
						<label><?php 
                            _e('Meta Key', 'mycred');
                            ?>
</label>
						<div class="h2"><input type="text" name="mycred_pref_core[types][<?php 
                            echo $type;
                            ?>
][key]" value="<?php 
                            echo $type;
                            ?>
" class="medium" /></div>
					</li>
					<li>
						<label><?php 
                            _e('Label', 'mycred');
                            ?>
</label>
						<div class="h2"><input type="text" name="mycred_pref_core[types][<?php 
                            echo $type;
                            ?>
][label]" value="<?php 
                            echo strip_tags($label);
                            ?>
" class="medium" /></div>
					</li>
					<li>
						<label><?php 
                            _e('Delete', 'mycred');
                            ?>
</label>
						<div class="h2"><input type="checkbox" name="mycred_pref_core[delete_types][]" value="<?php 
                            echo $type;
                            ?>
" /></div>
					</li>
				</ol>
<?php 
                        }
                    }
                }
                ?>
				<label class="subheader"><?php 
                _e('Add New Type', 'mycred');
                ?>
</label>
				<ol id="myCRED-add-new-type" class="inline">
					<li>
						<label><?php 
                _e('Meta Key', 'mycred');
                ?>
</label>
						<div class="h2"><input type="text" id="mycred-new-ctype-key-value" name="mycred_pref_core[types][new][key]" value="" class="medium" /></div>
						<span class="description"><?php 
                _e('A unique ID for this type.', 'mycred');
                ?>
</span>
					</li>
					<li>
						<label><?php 
                _e('Label', 'mycred');
                ?>
</label>
						<div class="h2"><input type="text" id="mycred-new-ctype-key-label" name="mycred_pref_core[types][new][label]" value="" class="medium" /></div>
						<span class="description"><?php 
                _e('Menu and page title.', 'mycred');
                ?>
</span>
					</li>
					<li class="block">
						<p id="mycred-ctype-warning"><strong><?php 
                _e('The meta key must be lowercase and only contain letters or underscores. All other characters will be deleted!', 'mycred');
                ?>
</strong></p>
					</li>
				</ol>
			</div>
<?php 
            }
            ?>

			<?php 
            do_action('mycred_after_core_prefs' . $action_hook, $this);
            ?>

		</div>

		<?php 
            submit_button(__('Update Settings', 'mycred'), 'primary large', 'submit', false);
            ?>

	</form>

	<?php 
            do_action('mycred_bottom_settings_page' . $action_hook, $this);
            ?>

	<div id="export-points" style="display:none;">
		<ul>
			<li>
				<label><?php 
            _e('Identify users by', 'mycred');
            ?>
:</label><br />
				<select id="mycred-export-identify-by">
<?php 
            // Identify users by...
            $identify = apply_filters('mycred_export_by', array('ID' => __('User ID', 'mycred'), 'email' => __('User Email', 'mycred'), 'login' => __('User Login', 'mycred')));
            foreach ($identify as $id => $label) {
                echo '<option value="' . $id . '">' . $label . '</option>';
            }
            ?>
				</select><br />
				<span class="description"><?php 
            _e('Use ID if you intend to use this export as a backup of your current site while Email is recommended if you want to export to a different site.', 'mycred');
            ?>
</span>
			</li>
			<li>
				<label><?php 
            _e('Import Log Entry', 'mycred');
            ?>
:</label><br />
				<input type="text" id="mycred-export-log-template" value="" class="regular-text" /><br />
				<span class="description"><?php 
            echo sprintf(__('Optional log entry to use if you intend to import this file in a different %s installation.', 'mycred'), mycred_label());
            ?>
</span>
			</li>
			<li class="action">
				<input type="button" id="mycred-run-exporter" value="<?php 
            _e('Export', 'mycred');
            ?>
" data-type="<?php 
            echo $this->mycred_type;
            ?>
" class="button button-large button-primary" />
			</li>
		</ul>
		<div class="clear"></div>
	</div>
</div>
<?php 
        }
 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;
 }