本文整理汇总了PHP中mycred函数的典型用法代码示例。如果您正苦于以下问题:PHP mycred函数的具体用法?PHP mycred怎么用?PHP mycred使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mycred函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Construct
*/
function __construct()
{
// Default settings
$defaults = array('setup' => 'off', 'type' => 'mycred_default', 'rate' => 100, 'share' => 0, 'log' => array('purchase' => __('Payment for tickets to %link_with_title%', 'mycred'), 'refund' => __('Ticket refund for %link_with_title%', 'mycred')), 'refund' => 0, 'labels' => array('header' => __('Pay using your %_plural% balance', 'mycred'), 'button' => __('Pay Now', 'mycred'), 'link' => __('Pay', 'mycred'), 'checkout' => __('%plural% Cost', 'mycred')), 'messages' => array('success' => __('Thank you for your payment!', 'mycred'), 'error' => __("I'm sorry but you can not pay for these tickets using %_plural%", 'mycred')));
// Settings
$settings = get_option('mycred_eventsmanager_gateway_prefs');
$this->prefs = mycred_apply_defaults($defaults, $settings);
$this->mycred_type = $this->prefs['type'];
// Load myCRED
$this->core = mycred($this->mycred_type);
// Apply Whitelabeling
$this->label = mycred_label();
$this->title = strip_tags($this->label);
$this->status_txt = 'Paid using ' . strip_tags($this->label);
parent::__construct();
if (!$this->is_active()) {
return;
}
// Currency
add_filter('em_get_currencies', array($this, 'add_currency'));
if ($this->single_currency()) {
add_filter('em_get_currency_formatted', array($this, 'format_price'), 10, 4);
}
// Adjust Ticket Columns
add_filter('em_booking_form_tickets_cols', array($this, 'ticket_columns'), 10, 2);
add_action('em_booking_form_tickets_col_mycred', array($this, 'ticket_col'), 10, 2);
add_filter('em_bookings_table_cols_col_action', array($this, 'bookings_table_actions'), 10, 2);
add_action('em_cart_form_after_totals', array($this, 'checkout_total'));
// Refund
if ($this->prefs['refund'] != 0) {
add_filter('em_booking_set_status', array($this, 'refunds'), 10, 2);
}
}
开发者ID:socialray,项目名称:surfied-2-0,代码行数:36,代码来源:mycred-eventsmanager-pro.php
示例2: __construct
/**
* Construct
*/
function __construct($args = array(), $hook_prefs = NULL, $type = 'mycred_default')
{
if (!empty($args)) {
foreach ($args as $key => $value) {
$this->{$key} = $value;
}
}
// Grab myCRED Settings
$this->core = mycred($type);
if (!empty($type)) {
$this->core->cred_id = sanitize_text_field($type);
$this->mycred_type = $this->core->cred_id;
}
if ($this->mycred_type != 'mycred_default') {
$this->is_main_type = false;
}
// Grab settings
if ($hook_prefs !== NULL) {
// Assign prefs if set
if (isset($hook_prefs[$this->id])) {
$this->prefs = $hook_prefs[$this->id];
}
// Defaults must be set
if (!isset($this->defaults)) {
$this->defaults = array();
}
}
// Apply default settings if needed
if (!empty($this->defaults)) {
$this->prefs = mycred_apply_defaults($this->defaults, $this->prefs);
}
}
开发者ID:nfer,项目名称:mycred,代码行数:35,代码来源:mycred-abstract-hook.php
示例3: the_quiz_button
function the_quiz_button($button, $quiz_id)
{
global $post;
$quiz_id = get_the_ID();
$user_id = get_current_user_id();
$flag = 1;
if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
$pid = get_post_meta($quiz_id, 'vibe_quiz_product', true);
if (isset($pid) && is_numeric($pid) && get_post_type($pid) == 'product') {
$product_taken = wc_customer_bought_product('', $user_id, $pid);
if (!$product_taken) {
$pid = get_permalink($pid);
$check = vibe_get_option('direct_checkout');
$check = intval($check);
if (isset($check) && $check) {
$pid .= '?redirect';
}
$flag = 0;
$html = '<a href="' . $pid . '"class="button create-group-button full"> ' . __('Take this Quiz', 'vibe') . '</a>';
} else {
$flag = 1;
}
}
}
if (in_array('paid-memberships-pro/paid-memberships-pro.php', apply_filters('active_plugins', get_option('active_plugins'))) && is_user_logged_in()) {
$membership_ids = vibe_sanitize(get_post_meta($quiz_id, 'vibe_quiz_membership', false));
if (!pmpro_hasMembershipLevel($membership_ids, $user_id) && isset($membership_ids) && count($membership_ids) >= 1) {
$membership_taken = get_user_meta($user_id, $quiz_id, true);
if (!$membership_taken) {
$pmpro_levels_page_id = get_option('pmpro_levels_page_id');
$link = get_permalink($pmpro_levels_page_id);
$html = '<a href="' . $link . '"class="button create-group-button full"> ' . __('Take this Quiz', 'vibe') . '</a>';
$flag = 0;
} else {
$flag = 1;
}
}
}
if (in_array('wplms-mycred-addon/wplms-mycred-addon.php', apply_filters('active_plugins', get_option('active_plugins')))) {
$points = get_post_meta($quiz_id, 'vibe_quiz_mycred_points', true);
$mycred = mycred();
$balance = $mycred->get_users_cred($user_id);
if ($balance < $points) {
$flag = 0;
$html = '<a href="#"class="button create-group-button full"> ' . __('Take this Quiz', 'vibe') . '<span>' . __('<br/>Not enough points.', 'vibe') . '</span></a>';
}
if (!$mycred->has_entry('purchase_quiz', $quiz_id, $user_id)) {
$flag = 1;
$deduct = -1 * $points;
$mycred->update_users_balance($user_id, $deduct);
$mycred->add_to_log('purchase_quiz', $user_id, $deduct, __('Student subscibed to quiz', 'wplms-mycred'), $quiz_id);
} else {
$flag = 1;
}
}
if (!$flag) {
return $html;
}
return $button;
}
开发者ID:VibeThemes,项目名称:wplms_sell_quiz,代码行数:60,代码来源:sell_quiz.php
示例4: __construct
/**
* Construct
*/
function __construct($args = array(), $service_prefs = NULL)
{
if (!empty($args)) {
foreach ($args as $key => $value) {
$this->{$key} = $value;
}
}
// Grab myCRED Settings
$this->core = mycred();
// Grab settings
if ($service_prefs !== NULL) {
// Assign prefs if set
if (isset($service_prefs[$this->id])) {
$this->prefs = $service_prefs[$this->id];
}
// Defaults must be set
if (!isset($this->defaults) || empty($this->defaults)) {
$this->defaults = array();
}
}
// Apply default settings if needed
if (!empty($this->defaults)) {
$this->prefs = wp_parse_args($this->prefs, $this->defaults);
}
}
开发者ID:nfer,项目名称:mycred,代码行数:28,代码来源:mycred-abstract-service.php
示例5: __construct
/**
* Construct
*/
function __construct()
{
// Default settings
$defaults = array('labels' => array('gateway' => $this->label, 'payment' => $this->label . ' ' . __('Payments', 'mycred'), 'button' => __('Pay Now', 'mycred')), 'type' => 'mycred_default', 'rate' => 100, 'share' => 0, 'log' => __('Payment for Event Registration', 'mycred'), 'messages' => array('solvent' => 'Click "Pay Now" to pay using your %plural%.', 'insolvent' => 'Unfortunately you do not have enough %plural% to pay for this event.', 'visitors' => 'Payments using %_plural% is only available for registered members.'));
// Settings
$settings = get_option('mycred_espresso_gateway_prefs');
$this->prefs = mycred_apply_defaults($defaults, $settings);
$this->mycred_type = $this->prefs['type'];
// Load myCRED
$this->core = mycred($this->mycred_type);
}
开发者ID:nfer,项目名称:mycred,代码行数:14,代码来源:mycred-eventespresso3.php
示例6: __construct
/**
* Construct
*/
function __construct()
{
parent::__construct('myCRED_Sell_Content_Module', array('module_name' => 'sell_content', 'register' => false, 'defaults' => array('post_types' => 'post,page', 'type' => 'mycred_default', 'pay' => 'none', 'pay_percent' => 100, 'templates' => array('members' => '<p>Buy this %post_type% for only %price% %buy_button%</p>', 'visitors' => '<p><a href="%login_url_here%">Login</a> to buy access to this %post_type%.</p>', 'cantafford' => "<p>You do not have enough %plural% to buy access to this %post_type%.</p>\n<p><strong>Price</strong>: %price%</p>"), 'defaults' => array('price' => 10, 'overwrite_price' => 0, 'button_label' => __('Buy Now', 'mycred'), 'overwrite_buttonlabel' => 0, 'expire' => 0), 'logs' => array('buy' => 'Purchase of %link_with_title%', 'sell' => 'Sale of %link_with_title%')), 'add_to_core' => true));
// Adjust Module to the selected point type
$this->mycred_type = 'mycred_default';
if (isset($this->sell_content['type'])) {
$this->mycred_type = $this->sell_content['type'];
}
$this->core = mycred($this->mycred_type);
add_filter('mycred_email_before_send', array($this, 'email_notices'), 10, 2);
}
开发者ID:rafasashi,项目名称:mycred,代码行数:14,代码来源:myCRED-addon-sell-content.php
示例7: mycred_bbp_add_balance_in_profile
function mycred_bbp_add_balance_in_profile()
{
$user_id = bbp_get_displayed_user_id();
$mycred = mycred();
if ($mycred->exclude_user($user_id)) {
return;
}
$balance = $mycred->get_users_cred($user_id, $mycred->mycred_type);
$layout = $mycred->plural() . ': ' . $mycred->format_creds($balance);
$layout = apply_filters('mycred_bbp_authors_profile_balance', $layout, $balance, $user_id);
echo apply_filters('mycred_bbp_profile_balance', '<div class="users-mycred-balance">' . $layout . '</div>', $user_id, $balance);
}
开发者ID:socialray,项目名称:surfied-2-0,代码行数:12,代码来源:mycred-hook-bbPress.php
示例8: mycred_render_shortcode_load_coupon
function mycred_render_shortcode_load_coupon($atts, $content = NULL)
{
if (!is_user_logged_in()) {
return $content;
}
$mycred = mycred();
if (!isset($mycred->coupons)) {
return '<p><strong>Coupon Add-on settings are missing! Please visit the myCRED > Settings page to save your settings before using this shortcode.</strong></p>';
}
// Prep
$output = '
<div class="mycred-coupon-form">';
$user_id = get_current_user_id();
// No show for excluded users
if ($mycred->exclude_user($user_id)) {
return '';
}
// On submits
if (isset($_POST['mycred_coupon_load']['token']) && wp_verify_nonce($_POST['mycred_coupon_load']['token'], 'mycred-load-coupon' . $user_id)) {
$coupon = mycred_get_coupon_post($_POST['mycred_coupon_load']['couponkey']);
$load = mycred_use_coupon($_POST['mycred_coupon_load']['couponkey'], $user_id);
// Coupon does not exist
if ($load === 'missing') {
$output .= '<p class="mycred-coupon-status">' . $mycred->coupons['invalid'] . '</p>';
} elseif ($load === 'expired') {
$output .= '<p class="mycred-coupon-status">' . $mycred->coupons['expired'] . '</p>';
} elseif ($load === 'max') {
$output .= '<p class="mycred-coupon-status">' . $mycred->coupons['user_limit'] . '</p>';
} elseif ($load === 'min_balance') {
$min = get_post_meta($coupon->ID, 'min', true);
$template = str_replace('%min%', $min, $mycred->coupons['min']);
$output .= '<p class="mycred-coupon-status">' . $template . '</p>';
} elseif ($load === 'max_balance') {
$max = get_post_meta($coupon->ID, 'max', true);
$template = str_replace('%max%', $max, $mycred->coupons['max']);
$output .= '<p class="mycred-coupon-status">' . $template . '</p>';
} else {
$output .= '<p class="mycred-coupon-status">' . $mycred->coupons['success'] . '</p>';
}
}
$output .= '
<form action="" method="post">
<p>
<label for="mycred-coupon-code">' . __('Coupon', 'mycred') . '</label><br />
<input type="text" name="mycred_coupon_load[couponkey]" id="mycred-coupon-couponkey" value="" />
<input type="hidden" name="mycred_coupon_load[token]" value="' . wp_create_nonce('mycred-load-coupon' . $user_id) . '" />
<input type="submit" class="btn btn-primary btn-large button button-large button-primary" value="' . __('Apply Coupon', 'mycred') . '" />
</p>
</form>
</div>';
return apply_filters('mycred_load_coupon', $output, $atts, $content);
}
开发者ID:nfer,项目名称:mycred,代码行数:52,代码来源:mycred-coupon-shortcodes.php
示例9: __construct
/**
* Construct
*/
function __construct($key = NULL)
{
$this->handle_magic();
$this->core = mycred();
$this->key = $key;
$this->method = $_SERVER['REQUEST_METHOD'];
$this->uri = explode('/', $_SERVER['REQUEST_URI']);
$this->format = '';
$this->parse_call();
$this->get_host_IP();
// Let others play
do_action_ref_array('mycred_remote', array(&$this));
}
开发者ID:socialray,项目名称:surfied-2-0,代码行数:16,代码来源:mycred-remote.php
示例10: __construct
/**
* Construct
*/
function __construct()
{
// Default settings
$defaults = array('setup' => 'off', 'type' => 'mycred_default', 'rate' => 100, 'share' => 0, 'log' => array('purchase' => __('Payment for tickets to %link_with_title%', 'mycred'), 'refund' => __('Ticket refund for %link_with_title%', 'mycred')), 'refund' => 0, 'labels' => array('header' => __('Pay using your %_plural% balance', 'mycred'), 'button' => __('Pay Now', 'mycred'), 'link' => __('Pay', 'mycred')), 'messages' => array('success' => __('Thank you for your payment!', 'mycred'), 'error' => __("I'm sorry but you can not pay for these tickets using %_plural%", 'mycred')));
// Settings
$settings = get_option('mycred_eventsmanager_gateway_prefs');
$this->prefs = mycred_apply_defaults($defaults, $settings);
$this->mycred_type = $this->prefs['type'];
// Load myCRED
$this->core = mycred($this->mycred_type);
// Apply Whitelabeling
$this->label = mycred_label();
}
开发者ID:nfer,项目名称:mycred,代码行数:16,代码来源:mycred-eventsmanager.php
示例11: widget
/**
* Widget Output
*/
public function widget($args, $instance)
{
extract($args, EXTR_SKIP);
// Prep
$title = $instance['title'];
$mycred = mycred();
if (!isset($mycred->transfers)) {
return '<p>' . __('The myCRED Transfer add-on has not yet been setup!', 'mycred') . '</p>';
}
$pref = $mycred->transfers;
global $mycred_load_transfer;
// Members
if (is_user_logged_in()) {
// Excluded users
$user_id = get_current_user_id();
if ($mycred->exclude_user($user_id)) {
return;
}
echo $before_widget;
// Title
if (!empty($title)) {
echo $before_title;
echo $mycred->template_tags_general($title);
echo $after_title;
}
// Prep shortcode
$attr = array('show_balance' => $instance['show_balance'], 'show_limit' => $instance['show_limit']);
if (isset($instance['button']) && !empty($instance['button'])) {
$attr['button'] = $instance['button'];
}
echo mycred_transfer_render($attr, '');
$mycred_load_transfer = true;
echo $after_widget;
} else {
$mycred_load = false;
// If login message is set
if (!empty($pref['templates']['login'])) {
echo $before_widget;
if (!empty($instance['title'])) {
echo $before_title;
echo $mycred->template_tags_general($title);
echo $after_title;
}
// Show login message
echo '<p>' . $mycred->template_tags_general($pref['templates']['login']) . '</p>';
echo $after_widget;
}
return;
}
}
开发者ID:socialray,项目名称:surfied-2-0,代码行数:53,代码来源:mycred-transfer-widgets.php
示例12: __toString
public function __toString()
{
$mycred = mycred();
$count = 1;
$output = '<ul class="wl-leaderboard">';
foreach ($this->data as $position => $data) {
$avatar = get_avatar($data->user_id, 24);
$output .= "<li>{$avatar}<span><strong>{$data->user_login}</strong> avec " . $mycred->format_creds($data->total) . '</span>';
$output .= "<span class=\"pull\">{$count}</span>";
$output .= '</li>';
$count++;
}
$output .= '</ul>';
return $output;
}
开发者ID:warlegend,项目名称:wl-leaderboards,代码行数:15,代码来源:leaderboard.php
示例13: __construct
/**
* Construct
*/
function __construct($module_id = '', $args = array(), $type = 'mycred_default')
{
// Module ID is required
if (empty($module_id)) {
wp_die('myCRED_Module() Error. A Module ID is required!');
}
$this->module_id = $module_id;
$this->core = mycred($type);
if (!empty($type)) {
$this->core->cred_id = sanitize_text_field($type);
$this->mycred_type = $this->core->cred_id;
}
if ($this->mycred_type != 'mycred_default') {
$this->is_main_type = false;
}
$this->point_types = mycred_get_types();
// Default arguments
$defaults = array('module_name' => '', 'option_id' => '', 'defaults' => array(), 'labels' => array('menu' => '', 'page_title' => ''), 'register' => true, 'screen_id' => '', 'add_to_core' => false, 'accordion' => false, 'cap' => 'plugin', 'menu_pos' => 10);
$args = wp_parse_args($args, $defaults);
$this->module_name = $args['module_name'];
$this->option_id = $args['option_id'];
if (!$this->is_main_type) {
$this->option_id .= '_' . $this->mycred_type;
}
$this->settings_name = 'myCRED-' . $this->module_name;
if (!$this->is_main_type) {
$this->settings_name .= '-' . $this->mycred_type;
}
$this->labels = $args['labels'];
$this->register = $args['register'];
$this->screen_id = $args['screen_id'];
if (!$this->is_main_type && !empty($this->screen_id)) {
$this->screen_id = 'myCRED_' . $this->mycred_type . substr($this->screen_id, 6);
}
$this->add_to_core = $args['add_to_core'];
$this->accordion = $args['accordion'];
$this->cap = $args['cap'];
$this->menu_pos = $args['menu_pos'];
$this->default_prefs = $args['defaults'];
$this->current_user_id = get_current_user_id();
$this->now = current_time('timestamp');
$this->set_settings();
}
开发者ID:sebastianringel,项目名称:stammtisch,代码行数:46,代码来源:mycred-abstract-module.php
示例14: widget
public function widget($args, $instance)
{
if (!$instance['show_visitors'] && !is_user_logged_in()) {
return;
}
$leaderboard = WL_Leaderboard::current($instance['number']);
$mycred = mycred();
// Start constructing Widget
$output = $args['before_widget'];
// Title (if not empty)
if (!empty($instance['title'])) {
$output .= $args['before_title'];
// Allow general template tags in the title
$output .= $mycred->template_tags_general($instance['title']);
$output .= $args['after_title'];
}
$output .= $leaderboard;
$output .= $args['after_widget'];
echo $output;
}
开发者ID:warlegend,项目名称:wl-leaderboards,代码行数:20,代码来源:widget.php
示例15: get_spending
/**
* Get Spending
* @version 1.0
*/
function get_spending()
{
global $wpdb;
if ($this->args['ctypes'] == 'all') {
$point_types = $this->ctypes;
} else {
$point_types = array($this->args['ctypes'] => $this->ctypes[$this->args['ctypes']]);
}
$series = $ctypes = $categories = array();
$num = 0;
if (count($point_types) > 0) {
foreach ($point_types as $type_id => $label) {
$num++;
$count = $wpdb->get_var("SELECT COUNT( * ) FROM {$this->core->log_table} WHERE ctype = '{$type_id}';");
if ($count === NULL) {
$count = $num;
}
$ctypes[$count] = $type_id;
}
ksort($ctypes, SORT_NUMERIC);
}
foreach ($ctypes as $count => $type_id) {
$values = array();
foreach ($this->dates as $date) {
$query = $wpdb->get_var($wpdb->prepare("\n\t\t\t\t\t\tSELECT SUM( creds ) \n\t\t\t\t\t\tFROM {$this->core->log_table} \n\t\t\t\t\t\tWHERE creds < 0 \n\t\t\t\t\t\tAND ctype = %s \n\t\t\t\t\t\tAND time BETWEEN %d AND %d;", $type_id, $date['from'], $date['until']));
if ($query === NULL) {
$query = 0;
}
$values[] = abs($query);
if (!in_array($date['label'], $categories)) {
$categories[] = esc_attr($date['label']);
}
}
$mycred = mycred($type_id);
$series[] = "{ label : '" . esc_js($mycred->plural()) . "', fillColor : '" . str_replace(',1)', ',0.3)', $this->colors[$type_id]) . "', strokeColor : '" . $this->colors[$type_id] . "', pointColor : '" . $this->colors[$type_id] . "', data : [" . implode(', ', $values) . "] }";
}
return array('categories' => $categories, 'series' => $series);
}
开发者ID:socialray,项目名称:surfied-2-0,代码行数:42,代码来源:mycred-stats-widget-daily-loses.php
示例16: mycred_check_if_user_gets_badge
function mycred_check_if_user_gets_badge($user_id = NULL, $badge_ids = array(), $save = true)
{
if ($user_id === NULL || empty($badge_ids)) {
return;
}
global $wpdb;
$ids = array();
foreach ($badge_ids as $badge_id) {
$level = false;
$requirements = mycred_get_badge_requirements($badge_id);
foreach ($requirements as $req_level => $needs) {
if ($needs['type'] == '') {
$needs['type'] = 'mycred_default';
}
$mycred = mycred($needs['type']);
// Count occurences
if ($needs['by'] == 'count') {
$select = 'COUNT( * )';
$amount = absint($needs['amount']);
} else {
$select = 'SUM( creds )';
$amount = $mycred->number($needs['amount']);
}
$result = $wpdb->get_var(apply_filters('mycred_if_user_gets_badge_sql', $wpdb->prepare("\n\t\t\t\t\tSELECT {$select} \n\t\t\t\t\tFROM {$mycred->log_table} \n\t\t\t\t\tWHERE user_id = %d \n\t\t\t\t\t\tAND ctype = %s \n\t\t\t\t\t\tAND ref = %s;", $user_id, $needs['type'], $needs['reference']), $user_id, $badge_id, $req_level, $needs));
if ($result === NULL) {
$result = 0;
}
if ($needs['by'] != 'count') {
$result = $mycred->number($result);
} else {
$result = absint($result);
}
$level = NULL;
if ($result >= $amount) {
$level = absint($req_level);
}
$current = mycred_get_user_meta($user_id, 'mycred_badge' . $badge_id, '', true);
if ($current == '') {
$current = -1;
}
// If a level has been reached assign it now unless the user has this level already
if ($level !== NULL && $current < $level) {
if ($save) {
mycred_update_user_meta($user_id, 'mycred_badge' . $badge_id, '', apply_filters('mycred_badge_user_value', $level, $user_id, $badge_id));
}
$ids[$badge_id] = $level;
}
}
}
return $ids;
}
开发者ID:socialray,项目名称:surfied-2-0,代码行数:51,代码来源:mycred-badge-functions.php
示例17: mycred_woo_payout_rewards
function mycred_woo_payout_rewards($order_id)
{
// Get Order
$order = new WC_Order($order_id);
// If we paid with myCRED we do not award points by default
if ($order->payment_method == 'mycred' && apply_filters('mycred_woo_reward_mycred_payment', false) === false) {
return;
}
// Get items
$items = $order->get_items();
// Get point types
$types = mycred_get_types();
// Loop
foreach ($types as $type => $label) {
// Load type
$mycred = mycred($type);
// Check for exclusions
if ($mycred->exclude_user($order->user_id)) {
continue;
}
// Calculate reward
$reward = $mycred->zero();
foreach ($items as $item) {
$prefs = (array) get_post_meta($item['product_id'], 'mycred_reward', true);
if (isset($prefs[$type]) && $prefs[$type] != '') {
$reward = $reward + $prefs[$type] * $item['qty'];
}
}
// Award
if ($reward != $mycred->zero()) {
// Let others play with the reference and log entry
$reference = apply_filters('mycred_woo_reward_reference', 'reward', $order_id, $type);
$log = apply_filters('mycred_woo_reward_log', '%plural% reward for store purchase', $order_id, $type);
// Execute
$mycred->add_creds($reference, $order->user_id, $reward, $log, $order_id, array('ref_type' => 'post'), $type);
}
}
}
开发者ID:socialray,项目名称:surfied-2-0,代码行数:38,代码来源:mycred-hook-woocommerce.php
示例18: mycred_use_coupon
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
$now = current_time('timestamp');
$expires = mycred_get_coupon_expire_date($coupon->ID, true);
if (!empty($expires) && $expires !== 0 && $expires <= $now) {
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 ($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
if (!isset($mycred->core['coupons']['log'])) {
$mycred->core['coupons']['log'] = 'Coupon redemption';
}
// 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);
}
开发者ID:sebastianringel,项目名称:stammtisch,代码行数:69,代码来源:mycred-coupon-functions.php
示例19: __construct
/**
* Construct
* @since 1.6
* @version 1.0
*/
public function __construct()
{
// Get all types
$this->point_types = mycred_get_types();
// Get the used type (if used)
$type = 'mycred_default';
$currency = affiliate_wp()->settings->get('currency', 'mycred_default');
if (array_key_exists($currency, $this->point_types)) {
$type = $currency;
}
// Load myCRED
$this->mycred = mycred($type);
}
开发者ID:socialray,项目名称:surfied-2-0,代码行数:18,代码来源:mycred-hook-affiliatewp.php
示例20: template_tags_request
/**
* Request Related Template Tags
* @since 1.1
* @version 1.2.1
*/
public function template_tags_request($content, $request)
{
$type = $this->core;
if ($request['type'] != 'mycred_default') {
$type = mycred($request['type']);
}
$user_id = $request['user_id'];
$new_balance = $type->get_users_balance($user_id, $request['type']);
$content = str_replace('%new_balance%', $new_balance, $content);
$content = str_replace('%new_balance_f%', $type->format_creds($new_balance), $content);
if ($request['amount'] > 0) {
$old_balance = $type->number($new_balance - $request['amount']);
} else {
$old_balance = $type->number($new_balance + $request['amount']);
}
$content = str_replace('%old_balance%', $old_balance, $content);
$content = str_replace('%old_balance_f%', $type->format_creds($old_balance), $content);
$content = str_replace('%amount%', $request['amount'], $content);
$content = str_replace('%entry%', $request['entry'], $content);
$content = str_replace('%data%', $request['data'], $content);
$content = str_replace('%blog_name%', get_option('blogname'), $content);
$content = str_replace('%blog_url%', get_option('home'), $content);
$content = str_replace('%blog_info%', get_option('blogdescription'), $content);
$content = str_replace('%admin_email%', get_option('admin_email'), $content);
$content = str_replace('%num_members%', $this->core->count_members(), $content);
// Badges related
if (function_exists('mycred_ref_has_badge') && isset($request['badges'])) {
$titles = array();
$images = array();
foreach ($request['badges'] as $level => $badge_id) {
$badge_id = absint($badge_id);
$title = sprintf(_x('%s - Level %d', 'Badge Title - Level 1,2,3..', 'mycred'), get_the_title($badge_id), $level);
$titles[] = $title;
// Level image first
$level_image = get_post_meta($badge_id, 'level_image' . $level, true);
// Default to main image
if ($level_image == '') {
$level_image = get_post_meta($badge_id, 'main_image', true);
}
if ($level_image == '') {
$images[] = '<img src="' . $level_image . '" alt="' . $title . '" />';
}
}
$title = implode(', ', $titles);
$content = str_replace('%badge_title%', $title, $content);
$image = implode(' ', $images);
$content = str_replace('%badge_image%', $image, $content);
}
return $content;
}
开发者ID:kfwebdev,项目名称:wp-atd,代码行数:55,代码来源:myCRED-addon-email-notices.php
注:本文中的mycred函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论