public function create_post($sku, $content = '', $excerpt = '') { CC_Log::write("Creating post for product sku: {$sku}"); $post_id = null; $search_results = CC_Cloud_Product::search($sku); CC_Log::write("Cloud product search results: " . print_r($search_results, true)); if (is_array($search_results) && count($search_results)) { $product_info = array_shift($search_results); if (is_array($product_info) && count($product_info)) { $slug = sanitize_key(str_replace(' ', '-', strtolower($product_info['name']))); $title = cc_sanitize('name', 'text_field', $product_info); if (null == $this->page_exists($title)) { $post_data = array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => 1, 'post_name' => $slug, 'post_title' => $title, 'post_status' => 'publish', 'post_type' => 'cc_product'); if (!empty($content)) { $post_data['post_content'] = $content; } if (!empty($excerpt)) { $post_data['post_excerpt'] = $excerpt; } CC_Log::write('About to create cart66 product post with this post data: ' . print_r($post_data, true)); $post_id = wp_insert_post($post_data); if ($post_id > 0) { CC_Log::write('Created cart66 product post with id: ' . $post_id . "\nNow adding meta data: " . print_r($product_info, true)); update_post_meta($post_id, $this->json_key, $product_info); foreach ($product_info as $key => $value) { update_post_meta($post_id, $this->prefix . $key, $value); } } else { CC_Log::write('Unable to create cart66 product post: ' . $post_id); } } else { CC_Log::write('Not creating new product post because a post already exists with title: ' . $title); } } } else { CC_Log::write('Unable to retrieve product information for SKU: ' . $sku); } return $post_id; }
function cc_post($name, $type = 'text_field') { return cc_sanitize($name, $type, $_POST); }