コード例 #1
0
function appthemes_process_membership_order($current_user, $order)
{
    //if order ID matches pending membership id suffix, then process the order by extendning the date and setting the ID
    if (isset($current_user->active_membership_pack)) {
        $user_active_pack_id = get_pack_id($current_user->active_membership_pack);
    } else {
        $user_active_pack_id = false;
    }
    if (isset($current_user->membership_expires)) {
        $user_active_pack_expiration = $current_user->membership_expires;
    } else {
        $user_active_pack_expiration = strtotime(current_time('mysql'));
    }
    if ($order['total_cost'] == 0 || $order['order_id'] == $_REQUEST['oid'] || $order['order_id'] == $_REQUEST['custom'] || $order['order_id'] == $_REQUEST['invoice']) {
        //update the user profile to current order pack_id taking it off "pending" status and setup the membership object
        update_user_meta($current_user->ID, 'active_membership_pack', $order['pack_id']);
        $membership = get_pack($order['pack_id']);
        //extend membership if its still active, so long as its not free (otherwise free extentions could be infinite)
        $expires_in_days = appthemes_seconds_to_days(strtotime($user_active_pack_expiration) - strtotime(current_time('mysql')));
        $purchase = $order['pack_duration'] . ' ' . __('days', 'appthemes');
        if ($expires_in_days > 0 && $order['total_cost'] > 0 && $order['pack_id'] == $user_active_pack_id) {
            $updated_expires_date = appthemes_mysql_date($user_active_pack_expiration, $order['pack_duration']);
        } else {
            $updated_expires_date = appthemes_mysql_date(current_time('mysql'), $order['pack_duration']);
        }
        update_user_meta($current_user->ID, 'membership_expires', $updated_expires_date);
        $order['updated_expires_date'] = $updated_expires_date;
        delete_option($order['option_order_id']);
        //return the order information in case its needed
        return $order;
    } else {
        //get orders of the user
        $the_order = get_user_orders($current_user->ID, $order['order_id']);
        return false;
    }
}
function get_pack($theID, $type = '', $return = '')
{
    global $wpdb, $the_pack;
    if (stristr($theID, 'pend')) {
        $theID = get_pack_id($theID);
    }
    //if the type is dashboard or ad, then get the assume the ID sent is the postID and packID needs to be obtained
    if ($type == 'ad' || $type == 'dashboard') {
        $theID = get_pack_id($theID, $type);
    }
    //make sure the value is a proper MySQL int value
    $theID = intval($theID);
    if ($theID > 0) {
        $the_pack = $wpdb->get_row("SELECT * FROM {$wpdb->cp_ad_packs} WHERE pack_id = '{$theID}'");
        $the_pack = apply_filters('cp_get_package', $the_pack, $theID);
    }
    if (!empty($return) && !empty($the_pack)) {
        $the_pack = (array) $the_pack;
        if ($return == 'array') {
            return $the_pack;
        } else {
            return $the_pack[$return];
        }
    }
    return $the_pack;
}