public static function generate_mycred_datatoken($group = 'mycred_default', $points = '1') { $salt = mt_rand(); $result = ""; if (function_exists('mycred_create_token')) { if ($points == "") { $points = "1"; } if ($group == "") { $group = "mycred_default"; } $result = mycred_create_token(array($points, $group, $salt)); if ($result != '') { $result = ' data-token="' . $result . '"'; } } return $result; }
function mycred_render_shortcode_exchange($atts, $content = '') { if (!is_user_logged_in()) { return $content; } extract(shortcode_atts(array('from' => '', 'to' => '', 'rate' => 1, 'min' => 1), $atts)); if ($from == '' || $to == '') { return ''; } $types = mycred_get_types(); if (!array_key_exists($from, $types) || !array_key_exists($to, $types)) { return __('Point types not found.', 'mycred'); } $user_id = get_current_user_id(); $mycred_from = mycred($from); if ($mycred_from->exclude_user($user_id)) { return sprintf(__('You are excluded from using %s.', 'mycred'), $mycred_from->plural()); } $balance = $mycred_from->get_users_balance($user_id, $from); if ($balance < $mycred_from->number($min)) { return __('Your balance is too low to use this feature.', 'mycred'); } $mycred_to = mycred($to); if ($mycred_to->exclude_user($user_id)) { return sprintf(__('You are excluded from using %s.', 'mycred'), $mycred_to->plural()); } global $mycred_exchange; $token = mycred_create_token(array($from, $to, $user_id, $rate, $min)); ob_start(); ?> <style type="text/css"> #mycred-exchange table tr td { width: 50%; } #mycred-exchange table tr td label { display: block; font-weight: bold; font-size: 12px; } #mycred-exchange { margin-bottom: 24px; } .alert-success { color: green; } .alert-warning { color: red; } </style> <div class="mycred-exchange"> <form action="" method="post"> <h3><?php printf(__('Convert <span>%s</span> to <span>%s</span>', 'mycred'), $mycred_from->plural(), $mycred_to->plural()); ?> </h3> <?php if (isset($mycred_exchange['message'])) { ?> <div class="alert alert-<?php if ($mycred_exchange['success']) { echo 'success'; } else { echo 'warning'; } ?> "><?php echo $mycred_exchange['message']; ?> </div> <?php } ?> <table class="table"> <tr> <td colspan="2"> <label><?php printf(__('Your current %s balance', 'mycred'), $mycred_from->singular()); ?> </label> <p><?php echo $mycred_from->format_creds($balance); ?> </p> </td> </tr> <tr> <td> <label for="mycred-exchange-amount"><?php _e('Amount', 'mycred'); ?> </label> <input type="text" size="12" value="0" id="mycred-exchange-amount" name="mycred_exchange[amount]" /> <?php if ($min != 0) { ?> <p><small><?php printf(__('Minimum %s', 'mycred'), $mycred_from->format_creds($min)); ?> </small></p><?php } ?> </td> <td> <label for="exchange-rate"><?php _e('Exchange Rate', 'mycred'); ?> </label> <p><?php printf(__('1 %s = <span class="rate">%s</span> %s', 'mycred'), $mycred_from->singular(), $rate, $mycred_to->plural()); ?> </p> </td> </tr> </table> <input type="hidden" name="mycred_exchange[token]" value="<?php echo $token; ?> " /> <input type="hidden" name="mycred_exchange[nonce]" value="<?php echo wp_create_nonce('mycred-exchange'); ?> " /> <input type="submit" class="btn btn-primary button button-primary" value="<?php _e('Exchange', 'mycred'); ?> " /> <div class="clear clearfix"></div> </form> </div> <?php $output = ob_get_contents(); ob_end_clean(); return apply_filters('mycred_exchange_output', $output, $atts); }