function chef_gift_registry_add_action_callback() { if (!wp_verify_nonce($_POST['_wpnonce'], 'add_to_wishlist') || !absint($_POST['u'])) { _e('Adding the item to your wishlist failed.', 'ignitewoo-wishlists-pro'); die; } $taxonomy_id = absint($_POST['wishlist_num']); if (!$taxonomy_id) { _e('There was an error adding the wishlist. Please try again shortly.', 'ignitewoo-wishlists-pro'); die; } $wishlist_type = get_term($taxonomy_id, 'c_wishlists_cat', OBJECT); if (!$wishlist_type) { _e('There was an error adding the wishlist. Please try again shortly.', 'ignitewoo-wishlists-pro'); die; } if ('' == trim(strip_tags($_POST['wishlist_title']))) { _e('You must specify a Wishlist title.', 'ignitewoo-wishlists-pro'); die; } $user = absint($_POST['u']); // We have 3 predefined types: public, private, and shared. // Parse to find which string is in the slug so we can define the list. // Do this just in case an admin modifies the taxonomies. if (strpos($wishlist_type->slug, 'wishlist_public') !== false) { $wishlist_type = 'public'; } else { if (strpos($wishlist_type->slug, 'wishlist_private') !== false) { $wishlist_type = 'private'; } else { if (strpos($wishlist_type->slug, 'wishlist_shared') !== false) { $wishlist_type = 'shared'; } else { $wishlist_type = 'public'; } } } $wishlist_title = $_POST['wishlist_title']; $args = array('post_type' => 'custom_wishlists', 'post_title' => strip_tags($wishlist_title), 'post_content' => '', 'post_status' => 'publish', 'post_author' => $user); $post_id = wp_insert_post($args); if ($post_id) { wp_set_post_terms($post_id, array($taxonomy_id), 'c_wishlists_cat'); update_post_meta($post_id, 'wishlist_type', $wishlist_type); $event_type = isset($_POST['event-type']) ? $_POST['event-type'] : ""; $event_date = isset($_POST['event-date']) ? $_POST['event-date'] : ""; $co_registrant_name = isset($_POST['co-registrant-name']) ? $_POST['co-registrant-name'] : ""; $co_registrant_email = isset($_POST['co-registrant-email']) ? $_POST['co-registrant-email'] : ""; save_additional_wishlists_info($post_id, $user, $event_type, $event_date, $co_registrant_name, $co_registrant_email); include CHEF_GIFT_REGISTRY_PLUGIN_DIR . '/wishlist-add-action-success-result.tpl.php'; die; } else { _e('There was an error adding the wishlist. Please try again shortly.', 'ignitewoo-wishlists-pro'); die; } }
function wishlist_add_action_callback() { global $user_ID; if (!wp_verify_nonce($_POST['_wpnonce'], 'add_to_wishlist') || !absint($_POST['u']) || !absint($_POST['p'])) { _e('Adding the item to your wishlist failed.', 'ignitewoo-wishlists-pro'); die; } if (isset($_POST['existing_or_new'])) { $existing_or_new = absint($_POST['existing_or_new']); } else { $existing_or_new = 0; } $user = absint($_POST['u']); $prod = absint($_POST['p']); $variation = absint($_POST['v']); $qty = absint($_POST['q']); switch ($existing_or_new) { // no wishlists defined yet, or user opted to created one case 0: case 2: $taxonomy_id = absint($_POST['wishlist_num']); if (!$taxonomy_id) { _e('There was an error adding the wishlist. Please try again shortly.', 'ignitewoo-wishlists-pro'); die; } $wishlist_type = get_term($taxonomy_id, 'c_wishlists_cat', OBJECT); if (!$wishlist_type) { _e('There was an error adding the wishlist. Please try again shortly.', 'ignitewoo-wishlists-pro'); die; } if ('' == trim(strip_tags($_POST['wishlist_title']))) { _e('You must specify a Wishlist title.', 'ignitewoo-wishlists-pro'); die; } // We have 3 predefined types: public, private, and shared. // Parse to find which string is in the slug so we can define the list. // Do this just in case an admin modifies the taxonomies. if (strpos($wishlist_type->slug, 'wishlist_public') !== false) { $wishlist_type = 'public'; } else { if (strpos($wishlist_type->slug, 'wishlist_private') !== false) { $wishlist_type = 'private'; } else { if (strpos($wishlist_type->slug, 'wishlist_shared') !== false) { $wishlist_type = 'shared'; } else { $wishlist_type = 'public'; } } } $args = array('post_type' => 'custom_wishlists', 'post_title' => strip_tags($_POST['wishlist_title']), 'post_content' => '', 'post_status' => 'publish', 'post_author' => $user); $post_id = wp_insert_post($args); if ($post_id) { wp_set_post_terms($post_id, array($taxonomy_id), 'c_wishlists_cat'); } else { _e('There was an error adding the wishlist. Please try again shortly.', 'ignitewoo-wishlists-pro'); die; } $products[] = array('id' => $prod, 'vid' => $variation, 'purchased' => '', 'qty' => $qty); // just the product ID and purchased flag update_post_meta($post_id, 'wishlist_products', $products); update_post_meta($post_id, 'wishlist_type', $wishlist_type); $event_type = isset($_POST['event-type']) ? $_POST['event-type'] : ""; $event_date = isset($_POST['event-date']) ? $_POST['event-date'] : ""; $co_registrant_name = isset($_POST['co-registrant-name']) ? $_POST['co-registrant-name'] : ""; $co_registrant_email = isset($_POST['co-registrant-email']) ? $_POST['co-registrant-email'] : ""; save_additional_wishlists_info($post_id, $user, $event_type, $event_date, $co_registrant_name, $co_registrant_email); echo '<p class="wishlist_p">'; _e("Your new wishlist was created.\n\n", 'ignitewoo-wishlists-pro'); echo '</p>'; echo '<p class="wishlist_p">'; _e("The URL is :", 'ignitewoo-wishlists-pro'); echo get_permalink($post_id); echo '</p>'; die; break; // use existing wishlist // use existing wishlist case 1: $existing_wishlist_id = isset($_POST['existing_wishlist']) ? absint($_POST['existing_wishlist']) : 0; if (!$existing_wishlist_id || $existing_wishlist_id < 0) { _e('There was an error adding the wishlist. Please try again shortly.', 'ignitewoo-wishlists-pro'); die; } $products = get_post_meta($existing_wishlist_id, 'wishlist_products', true); $added = false; foreach ($products as $k => $p) { if (!empty($p['qty'])) { $pq = $p['qty']; } else { $pg = 1; } //var_dump( $variation, $prod, $p['id'], $p['vid'] ); //echo '<p>'; if (!empty($variation) && $p['id'] == $prod && $p['vid'] == $variation) { $qty = $pq + $qty; $products[$k]['qty'] = $qty; $added = true; } else { if (!empty($variation)) { $added = false; } else { if ($p['id'] == $prod) { $qty = $pq + $qty; $products[$k]['qty'] = $qty; $added = true; } } } } if (!$added) { $products[] = array('id' => $prod, 'vid' => $variation, 'purchased' => array(), 'purchased_by' => array(), 'qty' => $qty); } //var_dump( $products ); //die; update_post_meta($existing_wishlist_id, 'wishlist_products', $products); break; } _e('The product was added to your wishlist!', 'ignitewoo-wishlists-pro'); die; }