function get_button_code($pack, $user_id, $override_price = FALSE) { global $ym_sys; $cost = $override_price ? $override_price : $pack['cost']; $cost = $cost * 100; //convert to pence $data = array('CpiDirectResultUrl' => site_url('?ym_process=' . $this->code), 'CpiReturnUrl' => site_url('?ym_process=' . $this->code), 'MerchantData' => '', 'Mode' => $this->mode, 'OrderDesc' => isset($pack['item_name']) && $pack['item_name'] ? $pack['item_name'] : $ym_sys->item_name, 'OrderId' => '', 'PurchaseAmount' => $cost, 'PurchaseCurrency' => $this->currency_to_code(ym_get_currency()), 'StorefrontId' => $this->store_front_id, 'TimeStamp' => time() * 1000, 'TransactionType' => 'Capture', 'UserId' => $user_id); if ($this->map_billingaddress1) { $data = array_merge($data, array('BillingAddress1' => '', 'BillingCity' => '', 'BillingCountry' => '', 'BillingFirstName' => get_user_by('id', $user_id)->user_firstname, 'BillingLastName' => get_user_by('id', $user_id)->user_lastname, 'BillingPostal' => '', 'ShopperEmail' => get_user_by('id', $user_id)->user_email, 'ShippingAddress1' => '', 'ShippingCity' => '', 'ShippingCountry' => '', 'ShippingFirstName' => '', 'ShippingLastName' => '', 'ShippingPostal' => '')); $data['ShippingFirstName'] = $data['BillingFirstName']; $data['ShippingLastName'] = $data['BillingLastName']; } // custom if (isset($pack['id']) && $pack['id']) { $data['MerchantData'] = 'buy_subscription_' . $pack['id'] . '_' . $user_id; } else { if (isset($pack['ppp_pack_id'])) { $data['MerchantData'] = 'buy_bundle_' . $pack['ppp_pack_id'] . '_' . $user_id; } else { $data['MerchantData'] = 'buy_post_' . ($pack['post_id'] ? $pack['post_id'] : get_the_ID()) . '_' . $user_id; } } $data['OrderId'] = $data['MerchantData'] . '_' . time(); wp_set_current_user($user_id); $customs = ym_get_custom_fields($user_id); // MAP if ($this->map_billingaddress1) { $data['BillingAddress1'] = ym_shortcode_user(array('name' => $this->map_billingaddress1), '', 'ym_user_custom'); $data['BillingCity'] = ym_shortcode_user(array('name' => $this->map_billingcity), '', 'ym_user_custom'); $data['BillingCountry'] = ym_shortcode_user(array('name' => $this->map_billingcountry), '', 'ym_user_custom'); $data['BillingPostal'] = ym_shortcode_user(array('name' => $this->map_billingpostal), '', 'ym_user_custom'); $data['ShippingAddress1'] = ym_shortcode_user(array('name' => $this->map_shippingaddress1), '', 'ym_user_custom'); $data['ShippingCity'] = ym_shortcode_user(array('name' => $this->map_shippingcity), '', 'ym_user_custom'); $data['ShippingCountry'] = ym_shortcode_user(array('name' => $this->map_shippingcountry), '', 'ym_user_custom'); $data['ShippingPostal'] = ym_shortcode_user(array('name' => $this->map_shippingpostal), '', 'ym_user_custom'); // code convert $data['BillingCountry'] = $this->country_to_code($data['BillingCountry']); $data['ShippingCountry'] = $this->country_to_code($data['ShippingCountry']); } // all fields for hash present $data['OrderHash'] = $this->generateHash($data, $this->cpi_hash_key); if ($this->map_billingaddress1) { // add optional fields if ($this->map_billingaddress2) { $data['BillingAddress2'] = ym_shortcode_user(array('name' => $this->map_billingaddress2), '', 'ym_user_custom'); } if ($this->map_billingcounty) { $data['BillingCounty'] = ym_shortcode_user(array('name' => $this->map_billingcounty), '', 'ym_user_custom'); } if ($this->map_shippingaddress2) { $data['ShippingAddress2'] = ym_shortcode_user(array('name' => $this->map_shippingaddress2), '', 'ym_user_custom'); } if ($this->map_shippingcounty) { $data['ShippingCounty'] = ym_shortcode_user(array('name' => $this->map_shippingcounty), '', 'ym_user_custom'); } } return $data; }
function ym_custom_value($id, $alt = '') { // get field $custom_field = ym_get_custom_field($id); global $ym_user; if (!isset($ym_user->ID)) { return $alt; } $user_fields = ym_get_custom_fields($ym_user->ID); foreach ($user_fields as $id => $data) { if ($custom_field['id'] == $id) { return $data; } } return $alt; }
function ym_user_custom_is_test($args = array()) { if (!is_array($args)) { return NULL; } if (count($args) != 1) { // error return NULL; } //Call the Users custom fields :) global $current_user; get_currentuserinfo(); $customfields = ym_get_custom_fields($current_user->ID); //OK let's see what we got hiding in the array foreach ($args as $key => $value) { if (is_numeric($key)) { //naughty hack to save rewriting the function. $field = array(); $field['id'] = $key; } else { $field = ym_get_custom_field_by_name($key); } //Quick check to make sure we have a field to test against if (is_null($field)) { return NULL; } //Check the custom field against the users and if doesn't match return false or carry through the loop if ($customfields[$field['id']] != $value) { return FALSE; } } return TRUE; }
function ym_shortcode_user($args, $content = '', $tag) { $return = ''; $name = isset($args['name']) ? $args['name'] : ''; $name = strtolower($name); $alt = isset($args['alt']) ? $args['alt'] : ''; $user_id = isset($args['user_id']) ? $args['user_id'] : ''; $exempt = isset($args['exempt']) ? $args['exempt'] : ''; if ($user_id) { if (is_numeric($user_id)) { $user = get_userdata($user_id); } else { $user_id = isset($_REQUEST[$user_id]) ? $_REQUEST[$user_id] : ''; if (is_numeric($user_id)) { $user = get_userdata($user_id); } else { return false; } } if (isset($exempt)) { $user_ids = explode(',', $exempt); foreach ($user_ids as $userID) { if ($userID == $user->ID) { return false; } } } } else { get_currentuserinfo(); global $current_user; $user = $current_user; } if ($tag == 'ym_user_url' || $name == 'user_url') { $return = $user->user_url ? $user->user_url : '-'; } else { if ($tag == 'ym_user_register_date') { $return = $user->user_registered; } else { if ($tag == 'ym_user_email' || $name == 'user_email') { $return = $user->user_email; } else { if ($tag == 'ym_user_first_name' || $name == 'first_name') { $return = $user->user_firstname; } else { if ($tag == 'ym_user_last_name' || $name == 'last_name') { $return = $user->user_lastname; } else { if ($tag == 'ym_user_username') { $return = $user->user_login; } else { if ($tag == 'ym_user_nickname') { $return = $user->nickname; } else { if ($tag == 'ym_user_displayname') { $return = $user->display_name; } else { if ($tag == 'ym_user_description' || $name == 'user_description') { $return = get_user_meta($user->ID, 'description', TRUE); } else { if ($tag == 'ym_user_custom' && $name) { $custom_field = ym_get_custom_field_by_name($name); $id = $custom_field['id']; $user_fields = ym_get_custom_fields($user->ID); // convert key to value? $keys = array(); if ($custom_field['type'] == 'multiselect' || $custom_field['type'] == 'select') { $options = explode(';', $custom_field['available_values']); foreach ($options as $option) { if (strpos($option, ':')) { list($key, $value) = explode(':', $option); } else { $key = $value = $option; } $keys[$key] = $value; } } if (is_array($user_fields[$id])) { foreach ($user_fields[$id] as $x => $entry) { $user_fields[$id][$x] = isset($keys[$entry]) ? $keys[$entry] : $entry; } $user_fields[$id] = implode($user_fields[$id], ', '); } else { $user_fields[$id] = isset($keys[$user_fields[$id]]) ? $keys[$user_fields[$id]] : $user_fields[$id]; } $return = $user_fields[$id] ? $user_fields[$id] : $alt; } } } } } } } } } } return $return; }