function hocwp_slider_on_save_slider_info($post_id) { if (!hocwp_can_save_post($post_id)) { return; } $slider = get_post($post_id); if ('hocwp_slider' == $slider->post_type) { $items = hocwp_get_method_value('slider_items'); $saved = hocwp_get_post_meta('slider_items', $post_id); if (!is_array($items)) { $items = array(); } if (!is_array($saved)) { $saved = array(); } $items = wp_parse_args($items, $saved); update_post_meta($post_id, 'slider_items', $items); if (isset($_POST['position'])) { update_post_meta($post_id, 'position', $_POST['position']); } unset($_POST['slider_items']); } }
function hocwp_shop_save_product_meta($post_id) { if (!hocwp_can_save_post($post_id)) { return; } if (!hocwp_is_shop_site() || hocwp_wc_installed()) { return; } if (isset($_POST['sku'])) { update_post_meta($post_id, 'sku', $_POST['sku']); } $regular_price = hocwp_get_method_value('regular_price'); $sale_price = hocwp_get_method_value('sale_price'); $prices = hocwp_sanitize_product_price($regular_price, $sale_price, $post_id); update_post_meta($post_id, 'regular_price', $prices['regular_price']); update_post_meta($post_id, 'sale_price', $prices['sale_price']); update_post_meta($post_id, 'price', $prices['price']); if (isset($_POST['short_description'])) { update_post_meta($post_id, 'short_description', $_POST['short_description']); } $out_of_stock = hocwp_checkbox_post_data_value($_POST, 'out_of_stock'); update_post_meta($post_id, 'out_of_stock', $out_of_stock); if (isset($_POST['gallery'])) { update_post_meta($post_id, 'gallery', $_POST['gallery']); } }
function hocwp_save_video_default_meta($post_id) { if (!hocwp_can_save_post($post_id)) { return; } $video_url = get_post_meta($post_id, 'video_url'); $server_name = hocwp_detect_video_server_name($video_url); update_post_meta($post_id, 'video_server', $server_name); $video_id = hocwp_detect_video_id($video_url); update_post_meta($post_id, 'video_id', $video_id); if (!has_post_thumbnail($post_id)) { $thumbnail_url = ''; $thumbnails = array(); switch ($server_name) { case 'youtube': $api_key = hocwp_get_google_api_key(); $data = hocwp_get_youtube_thumbnail_data_object($api_key, $video_id); $thumbnails = hocwp_get_youtube_thumbnails($api_key, $video_id, $data); $thumbnail_url = hocwp_get_youtube_thumbnail($api_key, $video_id, 'medium', $thumbnails); break; case 'vimeo': $thumbnails = hocwp_get_vimeo_thumbnails($video_id); $thumbnail_url = hocwp_get_vimeo_thumbnail($video_id, 'medium', $thumbnails); break; case 'dailymotion': $thumbnails = hocwp_get_dailymotion_thumbnails($video_id); $thumbnail_url = hocwp_get_dailymotion_thumbnail($video_id, 'medium', $thumbnails); break; } update_post_meta($post_id, 'thumbnail_url', $thumbnail_url); update_post_meta($post_id, 'thumbnails', $thumbnails); } }
public function save_post($post_id) { if (!hocwp_can_save_post($post_id)) { return $post_id; } foreach ($this->get_fields() as $field) { $this->save_post_meta_helper($post_id, $field); } if (is_array($this->custom_fields)) { foreach ($this->custom_fields as $field) { $this->save_post_meta_helper($post_id, $field); } } return $post_id; }
function hocwp_setup_theme_save_post_meta_hook($post_id) { if (!hocwp_can_save_post($post_id)) { return $post_id; } $post = get_post($post_id); $post_type = $post->post_type; global $hocwp_metas; if (hocwp_array_has_value($hocwp_metas)) { foreach ($hocwp_metas as $meta) { if ('post' == $meta->get_type()) { $post_types = $meta->get_post_types(); $fields = $meta->get_fields(); foreach ($fields as $field) { $meta->save_post_meta_helper($post_id, $field); } $fields = $meta->get_custom_fields(); if (is_array($fields)) { foreach ($fields as $field) { $meta->save_post_meta_helper($post_id, $field); } } } } } $value = isset($_POST['featured']) ? 1 : 0; update_post_meta($post_id, 'featured', $value); $value = isset($_POST['active']) ? 1 : 0; update_post_meta($post_id, 'active', $value); if ('hocwp_subscriber' == $post->post_type) { update_post_meta($post_id, 'subscriber_verified', $value); } switch ($post_type) { case 'hocwp_sidebar': if (isset($_POST['sidebar_id'])) { update_post_meta($post_id, 'sidebar_id', hocwp_sanitize_id($_POST['sidebar_id'])); } if (isset($_POST['sidebar_name'])) { update_post_meta($post_id, 'sidebar_name', sanitize_text_field($_POST['sidebar_name'])); } if (isset($_POST['sidebar_description'])) { update_post_meta($post_id, 'sidebar_description', sanitize_text_field($_POST['sidebar_description'])); } if (isset($_POST['sidebar_tag'])) { update_post_meta($post_id, 'sidebar_tag', sanitize_text_field($_POST['sidebar_tag'])); } break; case 'hocwp_slider': if (isset($_POST['slider_items'])) { update_post_meta($post_id, 'slider_items', $_POST['slider_items']); } if (isset($_POST['position'])) { update_post_meta($post_id, 'position', $_POST['position']); } $fit_width = hocwp_get_method_value('fit_width'); update_post_meta($post_id, 'fit_width', $fit_width); if (isset($_POST['height'])) { update_post_meta($post_id, 'height', $_POST['height']); } break; case 'hocwp_ads': if (isset($_POST['position'])) { update_post_meta($post_id, 'position', $_POST['position']); } if (isset($_POST['expire'])) { update_post_meta($post_id, 'expire', strtotime($_POST['expire'])); } if (isset($_POST['code'])) { update_post_meta($post_id, 'code', $_POST['code']); } $image = hocwp_get_method_value('image'); update_post_meta($post_id, 'image', $image); $url = hocwp_get_method_value('url'); update_post_meta($post_id, 'url', $url); break; case 'hocwp_subscriber': if (isset($_POST['subscriber_name'])) { update_post_meta($post_id, 'subscriber_name', sanitize_text_field($_POST['subscriber_name'])); } if (isset($_POST['subscriber_phone'])) { update_post_meta($post_id, 'subscriber_phone', sanitize_text_field($_POST['subscriber_phone'])); } break; case 'coupon': if (isset($_POST['expired_date'])) { update_post_meta($post_id, 'expired_date', strtotime($_POST['expired_date'])); } break; case 'product': $args = array('posts_per_page' => -1, 'post_type' => 'hocwp_product_tab'); $query = hocwp_query($args); if ($query->have_posts()) { foreach ($query->posts as $product) { $field_name = hocwp_sanitize_id($product->post_name); if (isset($_POST[$field_name])) { update_post_meta($post_id, $field_name, $_POST[$field_name]); } } } break; case 'partner': if (isset($_POST['url'])) { update_post_meta($post_id, 'url', esc_url($_POST['url'])); } if (isset($_POST['thumbnail'])) { update_post_meta($post_id, 'thumbnail', $_POST['thumbnail']); } break; } return $post_id; }
function hocwp_classifieds_save_post($post_id) { if (!hocwp_can_save_post($post_id)) { return; } global $post_type; if (empty($post_type)) { $post_type = hocwp_get_current_post_type(); } if (empty($post_type) || 'post' == $post_type) { if (hocwp_is_subscriber()) { if (get_post_status($post_id) == 'publish') { $post_data = array('ID' => $post_id, 'post_status' => 'pending'); wp_update_post($post_data); } } if (is_admin() && !HOCWP_DOING_AJAX) { $taxonomies = hocwp_post_get_taxonomies(get_post($post_id), 'objects'); $custom_taxonomies = array(); $salary = hocwp_get_value_by_key($taxonomies, 'salary'); $acreage = hocwp_get_value_by_key($taxonomies, 'acreage'); $price = hocwp_get_value_by_key($taxonomies, 'price'); $classifieds_object = hocwp_get_value_by_key($taxonomies, 'classifieds_object'); if (hocwp_object_valid($salary)) { //$custom_taxonomies[$salary->name] = $salary; } if (hocwp_object_valid($price)) { //$custom_taxonomies[$price->name] = $price; } if (hocwp_object_valid($acreage)) { //$custom_taxonomies[$acreage->name] = $acreage; } if (hocwp_object_valid($classifieds_object)) { //$custom_taxonomies[$classifieds_object->name] = $classifieds_object; } unset($taxonomies['salary']); unset($taxonomies['acreage']); unset($taxonomies['price']); unset($taxonomies['classifieds_object']); $errors = array(); if (hocwp_array_has_value($taxonomies)) { foreach ($taxonomies as $taxonomy) { if ($taxonomy->hierarchical) { $terms = wp_get_post_terms($post_id, $taxonomy->name); if (!hocwp_array_has_value($terms)) { //$errors[] = sprintf(__('Please set %s for this post.', 'hocwp-theme'), '<strong>' . $taxonomy->labels->singular_name . '</strong>'); } } } } $acreages = hocwp_object_valid($acreage) ? wp_get_post_terms($post_id, $acreage->name) : ''; $prices = hocwp_object_valid($price) ? wp_get_post_terms($post_id, $price->name) : ''; $salaries = hocwp_object_valid($salary) ? wp_get_post_terms($post_id, $salary->name) : ''; $objects = hocwp_object_valid($classifieds_object) ? wp_get_post_terms($post_id, $classifieds_object->name) : ''; $terms = array(); foreach ($custom_taxonomies as $taxonomy) { if ($taxonomy->hierarchical) { $post_terms = wp_get_post_terms($post_id, $taxonomy->name); if (hocwp_array_has_value($post_terms)) { $terms = array_merge($terms, $post_terms); } } } if (!hocwp_array_has_value($errors) && !hocwp_array_has_value($terms)) { //$errors[] = __('Please set term for this post in right way.', 'hocwp-theme'); } if (hocwp_array_has_value($errors)) { if (get_post_status($post_id) == 'publish') { $post_data = array('ID' => $post_id, 'post_status' => 'pending'); wp_update_post($post_data); } set_transient('hocwp_save_classifieds_post_' . $post_id . '_error', $errors); } } } }