public function generate_gifts($args) { $default_args = array('quantity' => 0, 'discount' => '', 'directive' => '', 'singulars' => ''); $args = array_merge($default_args, $args); $args = array_intersect_key($args, $default_args); $quantity = (int) $args['quantity']; $discount = str_replace('|', '', trim((string) $args['discount'])); $directive = str_replace('|', '', trim((string) $args['directive'])); $singulars = str_replace('|', '', trim((string) $args['singulars'])); if (!($quantity = (int) $quantity) || $quantity < 1) { return array(); } // Not possible. for ($_i = 0, $gifts = array(); $_i < $quantity; $_i++) { $_gift_code = c_ws_plugin__s2member_utils_encryption::uunnci_key_20_max(); $_gift_code = $this->n_code('GC' . str_pad($_gift_code, 20, '0', STR_PAD_LEFT)); $_gift_list = $_gift_code . '|' . $discount . '||' . $directive . '|' . $singulars . '||1'; // `code|discount|dates|directive|singulars|users|max uses`. $_gift = $this->list_to_coupons($_gift_list, FALSE); $_gift = array_merge(array_pop($_gift), array('is_gift' => TRUE)); $gifts[$_gift_code] = $_gift; // A coupon code that's a gift. add_option($this->gift_option_key($_gift_code), $gifts[$_gift_code], '', 'no'); } unset($_i, $_gift_code, $_gift_list, $_gift); // Housekeeping. return $gifts; }