Exemple #1
0
function hocwp_post_get_top_parent_terms($post, $taxonomy = 'any')
{
    $result = array();
    $taxonomies = array($taxonomy);
    if ('any' === $taxonomy) {
        $taxonomies = hocwp_post_get_taxonomies($post);
    }
    foreach ($taxonomies as $tax) {
        $terms = wp_get_post_terms($post->ID, $tax);
        foreach ($terms as $term) {
            if ($term->parent != 0) {
                $term = hocwp_term_get_top_most_parent($term);
            }
            $result[] = $term;
        }
    }
    return $result;
}
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);
            }
        }
    }
}