/** * Update coupon meta * * @param int $post_id * @param array $post * @return void */ function update_coupon_meta($post_id, $post) { $acccess = !empty($post['access']) ? explode("\n", $post['access']) : array(); update_post_meta($post_id, '_code', $post['code']); update_post_meta($post_id, '_package', $post['package']); update_post_meta($post_id, '_start_date', wpuf_date2mysql($post['start_date'])); update_post_meta($post_id, '_end_date', wpuf_date2mysql($post['end_date'])); update_post_meta($post_id, '_type', $post['type']); update_post_meta($post_id, '_amount', $post['amount']); update_post_meta($post_id, '_usage_limit', $post['usage_limit']); update_post_meta($post_id, '_access', $acccess); do_action('wpuf_update_coupon', $post_id, $post); }
/** * Adds the postlock form in users profile * * @param object $profileuser */ function profile_subscription_details($profileuser) { if (!is_admin() && !current_user_can('edit_users')) { return; } if (wpuf_get_option('charge_posting', 'wpuf_payment') != 'yes') { return; } $userdata = get_userdata($profileuser->ID); //wp 3.3 fix $packs = WPUF_Subscription::init()->get_subscriptions(); $user_sub = WPUF_Subscription::get_user_pack($userdata->ID); $pack_id = isset($user_sub['pack_id']) ? $user_sub['pack_id'] : ''; ?> <div class="wpuf-user-subscription"> <h3><?php _e('WPUF Subscription', 'wpuf'); ?> </h3> <a class="btn button-primary wpuf-assing-pack-btn wpuf-add-pack" href="#"><?php _e('Assign Package', 'wpuf'); ?> </a> <a class="btn button-primary wpuf-assing-pack-btn wpuf-cancel-pack" style="display:none;" href="#"><?php _e('Show Package', 'wpuf'); ?> </a> <table class="form-table wpuf-pack-dropdown" disabled="disabled" style="display: none;"> <tr> <th><label for="wpuf_sub_pack"><?php _e('Pack:', 'wpuf'); ?> </label></th> <td> <select name="pack_id" id="wpuf_sub_pack"> <option value="-1"><?php _e('--Select--', 'wpuf'); ?> </option> <?php $this->packdropdown_without_recurring($packs, $pack_id); //WPUF_Subscription::init()->packdropdown( $packs, $selected = '' ); ?> </select> </td> </tr> </table> <?php if (!isset($user_sub['pack_id'])) { return; } $pack = WPUF_Subscription::get_subscription($user_sub['pack_id']); $details_meta = WPUF_Subscription::init()->get_details_meta_value(); $billing_amount = intval($pack->meta_value['billing_amount']) > 0 ? $details_meta['symbol'] . $pack->meta_value['billing_amount'] : __('Free', 'wpuf'); if ($billing_amount && $pack->meta_value['recurring_pay'] == 'yes') { $recurring_des = sprintf('For each %s %s', $pack->meta_value['billing_cycle_number'], $pack->meta_value['cycle_period'], $pack->meta_value['trial_duration_type']); $recurring_des .= !empty($pack->meta_value['billing_limit']) ? sprintf(', for %s installments', $pack->meta_value['billing_limit']) : ''; $recurring_des = $recurring_des; } else { $recurring_des = ''; } ?> <div class="wpuf-user-sub-info"> <h3><?php _e('Subscription Details', 'wpuf'); ?> </h3> <div class="wpuf-text"> <div><strong><?php _e('Subcription Name: ', 'wpuf'); ?> </strong><?php echo $pack->post_title; ?> </div> <div> <strong><?php _e('Package billing details: '); ?> </strong> <div class="wpuf-pricing-wrap"> <div class="wpuf-sub-amount"> <?php echo $billing_amount; ?> <?php echo $recurring_des; ?> </div> </div> </div> <strong><?php _e('Remaining post: ', 'wpuf'); ?> </strong> <table class="form-table"> <?php foreach ($user_sub['posts'] as $key => $value) { ?> <tr> <th><label><?php echo $key; ?> </label></th> <td><input type="text" value="<?php echo $value; ?> " name="<?php echo $key; ?> " ></td> </tr> <?php } ?> <?php if ($user_sub['recurring'] != 'yes') { if (!empty($user_sub['expire'])) { $expire = $user_sub['expire'] == 'unlimited' ? ucfirst('unlimited') : wpuf_date2mysql($user_sub['expire']); ?> <tr> <th><label><?php echo _e('Expire date:'); ?> </label></th> <td><input type="text" class="wpuf-date-picker" name="expire" value="<?php echo wpuf_get_date($expire); ?> "></td> </tr> <?php } } ?> </table> </div> </div> </div> <?php }
/** * Generate users subscription info with a shortcode * * @global type $userdata */ function subscription_info() { if (wpuf_get_option('charge_posting', 'wpuf_payment') != 'yes' || !is_user_logged_in()) { return; } global $userdata; ob_start(); $userdata = get_userdata($userdata->ID); //wp 3.3 fix $user_sub = self::get_user_pack($userdata->ID); if (!isset($user_sub['pack_id'])) { return; } $pack = $this->get_subscription($user_sub['pack_id']); $details_meta = $this->get_details_meta_value(); $billing_amount = intval($pack->meta_value['billing_amount']) > 0 ? $details_meta['symbol'] . $pack->meta_value['billing_amount'] : __('Free', 'wpuf'); if ($pack->meta_value['recurring_pay'] == 'yes') { $recurring_des = sprintf('For each %s %s', $pack->meta_value['billing_cycle_number'], $pack->meta_value['cycle_period'], $pack->meta_value['trial_duration_type']); $recurring_des .= !empty($pack->meta_value['billing_limit']) ? sprintf(', for %s installments', $pack->meta_value['billing_limit']) : ''; $recurring_des = $recurring_des; } else { $recurring_des = ''; } ?> <div class="wpuf_sub_info"> <h3><?php _e('Subscription Details', 'wpuf'); ?> </h3> <div class="wpuf-text"> <div><strong><?php _e('Subcription Name: ', 'wpuf'); ?> </strong><?php echo $pack->post_title; ?> </div> <div> <strong><?php _e('Package & billing details: '); ?> </strong> <div class="wpuf-pricing-wrap"> <div class="wpuf-sub-amount"> <?php echo $billing_amount; ?> <?php echo $recurring_des; ?> </div> </div> </div> <div> <strong><?php _e('Remaining post: ', 'wpuf'); ?> </strong> <?php foreach ($user_sub['posts'] as $key => $value) { $value = intval($value); if ($value === 0) { continue; } $post_type_obj = get_post_type_object($key); if (!$post_type_obj) { continue; } ?> <div><?php echo $post_type_obj->labels->name . ': ' . $value; ?> </div> <?php } ?> </div> <?php if ($user_sub['recurring'] != 'yes') { if (!empty($user_sub['expire'])) { $expire = $user_sub['expire'] == 'unlimited' ? ucfirst('unlimited') : wpuf_date2mysql($user_sub['expire']); ?> <div class="wpuf-expire"> <strong><?php echo _e('Expire date:'); ?> </strong> <?php echo wpuf_get_date($expire); ?> </div> <?php } } ?> </div> <?php if ($user_sub['recurring'] == 'yes') { $payment_page = get_permalink(wpuf_get_option('payment_page', 'wpuf_payment')); ?> <form action="" method="post"> <?php wp_nonce_field('_wpnonce', 'wpuf_payment_cancel'); ?> <input type="hidden" name="user_id" value="<?php echo $userdata->ID; ?> "> <input type="hidden" name="action" value="wpuf_cancel_pay"> <input type="hidden" name="gateway" value="paypal"> <input type="submit" name="wpuf_payment_cancel_submit" value="cancel"> </form> <?php $subscription_page = wpuf_get_option('subscription_page', 'wpuf_payment'); ?> <a href="<?php echo get_permalink($subscription_page); ?> "><?php _e('Change', 'wpuf'); ?> </a> <?php } echo '</div>'; $content = ob_get_clean(); return apply_filters('wpuf_sub_info', $content, $userdata, $user_sub, $pack); }
/** * Adds the postlock form in users profile * * @param object $profileuser */ function profile_subscription_details($profileuser) { if (!current_user_can('edit_users')) { return; } if (wpuf_get_option('charge_posting', 'wpuf_payment') != 'yes') { return; } $userdata = get_userdata($profileuser->ID); //wp 3.3 fix $packs = WPUF_Subscription::init()->get_subscriptions(); $user_sub = WPUF_Subscription::get_user_pack($userdata->ID); $pack_id = isset($user_sub['pack_id']) ? $user_sub['pack_id'] : ''; ?> <div class="wpuf-user-subscription"> <h3><?php _e('WPUF Subscription', 'wpuf'); ?> </h3> <?php if (isset($user_sub['pack_id'])) { $pack = WPUF_Subscription::get_subscription($user_sub['pack_id']); $details_meta = WPUF_Subscription::init()->get_details_meta_value(); $billing_amount = intval($pack->meta_value['billing_amount']) > 0 ? $details_meta['symbol'] . $pack->meta_value['billing_amount'] : __('Free', 'wpuf'); if ($billing_amount && $pack->meta_value['recurring_pay'] == 'yes') { $recurring_des = sprintf('For each %s %s', $pack->meta_value['billing_cycle_number'], $pack->meta_value['cycle_period'], $pack->meta_value['trial_duration_type']); $recurring_des .= !empty($pack->meta_value['billing_limit']) ? sprintf(', for %s installments', $pack->meta_value['billing_limit']) : ''; $recurring_des = $recurring_des; } else { $recurring_des = ''; } ?> <div class="wpuf-user-sub-info"> <h3><?php _e('Subscription Details', 'wpuf'); ?> </h3> <?php if (isset($user_sub['recurring']) && $user_sub['recurring'] == 'yes') { ?> <div class="updated"> <p><?php _e('This user is using recurring subscription pack', 'wpuf'); ?> </p> </div> <?php } ?> <div class="wpuf-text"> <div><strong><?php _e('Subcription Name: ', 'wpuf'); ?> </strong><?php echo $pack->post_title; ?> </div> <div> <strong><?php _e('Package billing details: '); ?> </strong> <div class="wpuf-pricing-wrap"> <div class="wpuf-sub-amount"> <?php echo $billing_amount; ?> <?php echo $recurring_des; ?> </div> </div> </div> <strong><?php _e('Remaining post: ', 'wpuf'); ?> </strong> <table class="form-table"> <?php foreach ($user_sub['posts'] as $key => $value) { ?> <tr> <th><label><?php echo $key; ?> </label></th> <td><input type="text" value="<?php echo $value; ?> " name="<?php echo $key; ?> " ></td> </tr> <?php } ?> <?php if ($user_sub['recurring'] != 'yes') { if (!empty($user_sub['expire'])) { $expire = $user_sub['expire'] == 'unlimited' ? ucfirst('unlimited') : wpuf_date2mysql($user_sub['expire']); ?> <tr> <th><label><?php echo _e('Expire date:'); ?> </label></th> <td><input type="text" class="wpuf-date-picker" name="expire" value="<?php echo wpuf_get_date($expire); ?> "></td> </tr> <?php } } ?> <?php $is_post_exp_selected = isset($user_sub['_enable_post_expiration']) ? 'checked' : ''; $_post_expiration_time = explode(' ', isset($user_sub['_post_expiration_time']) ? $user_sub['_post_expiration_time'] : ' '); $time_value = isset($_post_expiration_time[0]) && !empty($_post_expiration_time[0]) ? $_post_expiration_time[0] : '1'; $time_type = isset($_post_expiration_time[1]) && !empty($_post_expiration_time[1]) ? $_post_expiration_time[1] : 'day'; ?> <tr> <th><label><?php echo _e('Post Expiration Enabled'); ?> </label></th> <td><input type="checkbox" name="is_post_expiration_enabled" value="on" <?php echo $is_post_exp_selected; ?> ></td> </tr> <tr> <?php $timeType_array = array('year' => 100, 'month' => 12, 'day' => 30); ?> <th><?php _e('Post Expiration Time', 'wpuf'); ?> </th> <td> <select name="post_expiration_settings[expiration_time_value]" id="wpuf-expiration_time_value"> <?php for ($i = 1; $i <= $timeType_array[$time_type]; $i++) { ?> <option value="<?php echo $i; ?> " <?php echo $i == $time_value ? 'selected' : ''; ?> ><?php echo $i; ?> </option> <?php } ?> </select> <select name="post_expiration_settings[expiration_time_type]" id="wpuf-expiration_time_type"> <?php foreach ($timeType_array as $each_time_type => $each_time_type_val) { ?> <option value="<?php echo $each_time_type; ?> " <?php echo $each_time_type == $time_type ? 'selected' : ''; ?> ><?php echo ucfirst($each_time_type); ?> </option> <?php } ?> </select> </td> </tr> </table> </div> </div> <?php } ?> <?php if (!isset($user_sub['recurring']) || $user_sub['recurring'] != 'yes') { ?> <a class="btn button-primary wpuf-assing-pack-btn wpuf-add-pack" href="#"><?php _e('Assign Package', 'wpuf'); ?> </a> <a class="btn button-primary wpuf-assing-pack-btn wpuf-cancel-pack" style="display:none;" href="#"><?php _e('Show Package', 'wpuf'); ?> </a> <table class="form-table wpuf-pack-dropdown" disabled="disabled" style="display: none;"> <tr> <th><label for="wpuf_sub_pack"><?php _e('Pack:', 'wpuf'); ?> </label></th> <td> <select name="pack_id" id="wpuf_sub_pack"> <option value="-1"><?php _e('--Select--', 'wpuf'); ?> </option> <?php $this->packdropdown_without_recurring($packs, $pack_id); //WPUF_Subscription::init()->packdropdown( $packs, $selected = '' ); ?> </select> </td> </tr> </table> <?php } ?> <?php if (!empty($user_sub)) { ?> <a class="btn button-primary wpuf-delete-pack-btn" href="javascript:" data-userid = "<?php echo $userdata->ID; ?> "><?php _e('Delete Package', 'wpuf'); ?> </a> <?php } ?> </div> <?php }