Ejemplo n.º 1
0
function manage_screen_options_columns($column, $post_id)
{
    global $post;
    $chosen_client_id = get_post_meta($post_id, 'chosen_client', true);
    switch ($column) {
        case 'invnumber':
            $invnumber = get_post_meta($post_id, 'invoice_serial_number', true);
            echo "№ " . str_pad($invnumber, 10, "0", STR_PAD_LEFT);
            break;
        case 'company_name':
            $company_name = get_post_meta($chosen_client_id, 'company_name', true);
            if (empty($company_name)) {
                echo __('Unknown');
            } else {
                echo __($company_name);
            }
            break;
        case 'status':
            $status = wp_get_object_terms($post_id, 'status');
            if (empty($status)) {
                echo __(' - ');
            } else {
                foreach ($status as $the_status) {
                    echo $the_status->name . " ";
                }
            }
        default:
            break;
    }
}
 public function prepare_items()
 {
     if (!empty($this->items)) {
         return;
     }
     $per_page = $this->get_items_per_page('edit_wpsc-product-variations_per_page');
     $per_page = apply_filters('edit_wpsc_product_variations_per_page', $per_page);
     $this->args = array('post_type' => 'wpsc-product', 'orderby' => 'menu_order title', 'post_parent' => $this->product_id, 'post_status' => 'publish, inherit', 'numberposts' => -1, 'order' => "ASC", 'posts_per_page' => $per_page);
     if (isset($_REQUEST['post_status'])) {
         $this->args['post_status'] = $_REQUEST['post_status'];
     }
     if (isset($_REQUEST['s'])) {
         $this->args['s'] = $_REQUEST['s'];
     }
     if (isset($_REQUEST['paged'])) {
         $this->args['paged'] = $_REQUEST['paged'];
     }
     $query = new WP_Query($this->args);
     $this->items = $query->posts;
     $total_items = $query->found_posts;
     $total_pages = $query->max_num_pages;
     $this->set_pagination_args(array('total_items' => $total_items, 'total_pages' => $total_pages, 'per_page' => $per_page));
     if (empty($this->items)) {
         return;
     }
     $ids = wp_list_pluck($this->items, 'ID');
     $object_terms = wp_get_object_terms($ids, 'wpsc-variation', array('fields' => 'all_with_object_id'));
     foreach ($object_terms as $term) {
         if (!array_key_exists($term->object_id, $this->object_terms_cache)) {
             $this->object_terms_cache[$term->object_id] = array();
         }
         $this->object_terms_cache[$term->object_id][$term->parent] = $term->name;
     }
 }
Ejemplo n.º 3
0
 public function filter_content($content)
 {
     // Get Templates
     $templates = self::get_option('rwp_templates');
     $terms = wp_get_object_terms(get_the_ID(), array_keys(get_taxonomies()));
     $terms_keys = array();
     foreach ($terms as $term) {
         $terms_keys[$term->taxonomy][] = $term->term_id;
     }
     //self::pretty_print( $terms_keys );
     foreach ($templates as $template) {
         if (isset($template['template_auto_reviews']) && !empty($template['template_auto_reviews'])) {
             if (is_singular($template['template_auto_reviews']) && is_main_query()) {
                 if (isset($template['template_exclude_terms'])) {
                     $to_exclude = false;
                     foreach ($template['template_exclude_terms'] as $id) {
                         $i = explode('-', $id);
                         if (in_array($i[1], $terms_keys[$i[0]])) {
                             $to_exclude = true;
                             break;
                         }
                     }
                     if ($to_exclude) {
                         continue;
                     }
                 }
                 $new_content = '[rwp-review id="-1" template="' . $template['template_id'] . '"]';
                 $content .= $new_content;
             }
         }
     }
     return $content;
 }
 function generate_tag_cloud($post_type)
 {
     global $wpdb;
     // database calls must be sensitive to multisite
     $query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = %s", $post_type);
     $attachment_ids = $wpdb->get_col($query);
     $terms = wp_get_object_terms($attachment_ids, 'post_tag', array('orderby' => 'count', 'order' => 'DESC'));
     $tags = array();
     // limit to 45 tags
     foreach ($terms as $term) {
         $tags[$term->term_id] = $term;
         if (count($tags) >= 45) {
             break;
         }
     }
     if (empty($tags)) {
         die(__('No tags found!', THEMEDOMAIN));
     }
     if (is_wp_error($tags)) {
         die($tags->get_error_message());
     }
     foreach ($tags as $key => $tag) {
         $tags[$key]->link = '#';
         $tags[$key]->id = $tag->term_id;
     }
     // We need raw tag names here, so don't filter the output
     $return = wp_generate_tag_cloud($tags, array('filter' => 0));
     if (empty($return)) {
         die('0');
     }
     echo $return;
     exit;
 }
Ejemplo n.º 5
0
 function type_permalink($permalink, $post_id, $leavename)
 {
     if (strpos($permalink, '%event_type%') === FALSE) {
         return $permalink;
     }
     if (strpos($permalink, '%event_place%') === FALSE) {
         return $permalink;
     }
     // Get post
     $post = get_post($post_id);
     if (!$post) {
         return $permalink;
     }
     // Get taxonomy terms
     $terms = wp_get_object_terms($post->ID, 'event_type');
     if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) {
         $taxonomy_slug = $terms[0]->slug;
     } else {
         $taxonomy_slug = 'no-type';
     }
     return str_replace('%event_type%', $taxonomy_slug, $permalink);
     // Get taxonomy terms
     $terms = wp_get_object_terms($post->ID, 'event_place');
     if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) {
         $taxonomy_slug = $terms[0]->slug;
     } else {
         $taxonomy_slug = 'no-place';
     }
     return str_replace('%event_place%', $taxonomy_slug, $permalink);
 }
 /**
  * widget function.
  *
  * @see WP_Widget
  * @access public
  * @param array $args
  * @param array $instance
  * @return void
  */
 function widget($args, $instance)
 {
     if ($this->get_cached_widget($args)) {
         return;
     }
     if (!class_exists('WP_Job_Manager_Job_Tags')) {
         return;
     }
     global $job_manager, $post;
     extract($args);
     $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
     $icon = isset($instance['icon']) ? $instance['icon'] : null;
     if ($icon) {
         $before_title = sprintf($before_title, 'ion-' . $icon);
     }
     $tags = wp_get_object_terms($post->ID, 'job_listing_tag');
     if (is_wp_error($tags) || empty($tags)) {
         return;
     }
     ob_start();
     echo $before_widget;
     if ($title) {
         echo $before_title . $title . $after_title;
     }
     do_action('listify_widget_job_listing_tags_before');
     wp_terms_checklist($post->ID, array('taxonomy' => 'job_listing_tag', 'checked_ontop' => false, 'walker' => new Listify_Walker_Tags_Checklist()));
     do_action('listify_widget_job_listing_tags_after');
     echo $after_widget;
     $content = ob_get_clean();
     echo apply_filters($this->widget_id, $content);
     $this->cache_widget($args, $content);
 }
Ejemplo n.º 7
0
 /**
  * convert post data to an object with meta data
  * @param object $post 
  * @return post object after convert
  * 		   - wp_error object if post invalid
  * @author Dakachi
  * @since 1.0
  */
 public function convert($post)
 {
     $result = array();
     $post = (array) $post;
     /**
      * convert need post data
      */
     foreach ($this->convert as $key) {
         if (isset($post[$key])) {
             $result[$key] = $post[$key];
         }
     }
     // generate post taxonomy
     if (!empty($this->taxs)) {
         foreach ($this->taxs as $name) {
             $result[$name] = wp_get_object_terms($post['ID'], $name);
         }
     }
     // generate meta data
     if (!empty($this->meta)) {
         foreach ($this->meta as $key) {
             $result[$key] = get_post_meta($post['ID'], $key, true);
         }
     }
     unset($result['post_password']);
     $result['id'] = $post['ID'];
     /**
      * assign convert post to current post
      */
     $this->current_post = apply_filters('ae_convert_post', (object) $result);
     return $this->current_post;
 }
 /**
  * Retrieve the values that should be output for a particular product
  * Takes into account store defaults, category defaults, and per-product
  * settings
  * 
  * @access public
  * @param  int  $product_id       The ID of the product to retrieve info for
  * @param  string  $feed_format   The feed format being generated
  * @param  boolean $defaults_only Whether to retrieve the
  *         store/category defaults only
  * @return array                  The values for the product
  */
 public function get_values_for_product($product_id = null, $feed_format = 'all', $defaults_only = false)
 {
     if (!$product_id) {
         return false;
     }
     // Get Store defaults
     $settings = $this->remove_blanks($this->settings['product_defaults']);
     if ($feed_format != 'all') {
         $settings = $this->remove_other_feeds($settings, $feed_format);
     }
     // Merge category settings
     $categories = wp_get_object_terms($product_id, 'product_cat', array('fields' => 'ids'));
     foreach ($categories as $category_id) {
         $category_settings = $this->get_values_for_category($category_id);
         $category_settings = $this->remove_blanks($category_settings);
         if ($feed_format != 'all') {
             $category_settings = $this->remove_other_feeds($category_settings, $feed_format);
         }
         if ($category_settings) {
             $settings = array_merge($settings, $category_settings);
         }
     }
     if ($defaults_only) {
         return $settings;
     }
     // Merge product settings
     $product_settings = get_post_meta($product_id, '_woocommerce_gpf_data', true);
     if ($product_settings) {
         $product_settings = $this->remove_blanks($product_settings);
         $settings = array_merge($settings, $product_settings);
     }
     return $settings;
 }
Ejemplo n.º 9
0
 function export_csv()
 {
     global $simple_map, $sm_locations;
     if (isset($_POST['sm-action']) && 'export-csv' == $_POST['sm-action']) {
         // Grab locations
         $content = array();
         set_time_limit(0);
         $location_offset = 0;
         while ($locations = query_posts(array('post_status' => 'publish', 'post_type' => 'sm-location', 'posts_per_page' => 200, 'offset' => $location_offset))) {
             // Include CSV library
             require_once SIMPLEMAP_PATH . '/classes/parsecsv.lib.php';
             $taxonomies = get_object_taxonomies('sm-location');
             foreach ($locations as $key => $location) {
                 $location_offset++;
                 $location_data = array('name' => esc_attr($location->post_title), 'address' => esc_attr(get_post_meta($location->ID, 'location_address', true)), 'address2' => esc_attr(get_post_meta($location->ID, 'location_address2', true)), 'city' => esc_attr(get_post_meta($location->ID, 'location_city', true)), 'state' => esc_attr(get_post_meta($location->ID, 'location_state', true)), 'zip' => esc_attr(get_post_meta($location->ID, 'location_zip', true)), 'country' => esc_attr(get_post_meta($location->ID, 'location_country', true)), 'phone' => esc_attr(get_post_meta($location->ID, 'location_phone', true)), 'email' => esc_attr(get_post_meta($location->ID, 'location_email', true)), 'fax' => esc_attr(get_post_meta($location->ID, 'location_fax', true)), 'url' => esc_attr(get_post_meta($location->ID, 'location_url', true)), 'description' => esc_attr($location->post_content), 'special' => esc_attr(get_post_meta($location->ID, 'location_special', true)), 'lat' => esc_attr(get_post_meta($location->ID, 'location_lat', true)), 'lng' => esc_attr(get_post_meta($location->ID, 'location_lng', true)), 'dateUpdated' => esc_attr($location->post_modified));
                 foreach ($taxonomies as $tax) {
                     $term_value = '';
                     if ($terms = wp_get_object_terms($location->ID, $tax, array('fields' => 'names'))) {
                         $term_value = implode(',', $terms);
                     }
                     $location_data["tax_{$tax}"] = esc_attr($term_value);
                 }
                 $content[] = $location_data;
             }
         }
         if (!empty($content)) {
             $csv = new smParseCSV();
             $csv->output(true, 'simplemap.csv', $content, array_keys(reset($content)));
             die;
         }
     }
 }
function get_offer_categories($post_id = null, $args = array())
{
    if (null === $post_id) {
        return get_terms('circleflip-offer-category');
    }
    return wp_get_object_terms($post_id, 'circleflip-offer-category', $args);
}
Ejemplo n.º 11
0
 function wpsc_variations($product_id)
 {
     global $wpdb;
     $product_terms = wp_get_object_terms($product_id, 'wpsc-variation');
     $this->variation_groups = array();
     $this->first_variations = array();
     $this->all_associated_variations = array();
     foreach ($product_terms as $product_term) {
         if ($product_term->parent > 0) {
             if (empty($this->all_associated_variations[$product_term->parent])) {
                 $this->all_associated_variations[$product_term->parent][0] = new stdClass();
                 $this->all_associated_variations[$product_term->parent][0]->term_id = 0;
                 $this->all_associated_variations[$product_term->parent][0]->name = '-- Escolha --';
             }
             $this->all_associated_variations[$product_term->parent][] = $product_term;
         } else {
             $this->variation_groups[] = $product_term;
         }
     }
     foreach ((array) $this->variation_groups as $variation_group) {
         $variation_id = $variation_group->term_id;
         $this->first_variations[] = $this->all_associated_variations[$variation_id][0]->term_id;
     }
     $this->variation_group_count = count($this->variation_groups);
 }
Ejemplo n.º 12
0
 /**
  * Test that a post is created for the function.
  */
 public function test_function_post_created()
 {
     $posts = get_posts(array('post_type' => $this->importer->post_type_function));
     $this->assertCount(1, $posts);
     $post = $posts[0];
     // Check that the post attributes are correct.
     $this->assertEquals('<p>This function is just here for tests. This is its longer description.</p>', $post->post_content);
     $this->assertEquals('This is a function summary.', $post->post_excerpt);
     $this->assertEquals('wp_parser_test_func', $post->post_name);
     $this->assertEquals(0, $post->post_parent);
     $this->assertEquals('wp_parser_test_func', $post->post_title);
     // It should be assigned to the file's taxonomy term.
     $terms = wp_get_object_terms($post->ID, $this->importer->taxonomy_file);
     $this->assertCount(1, $terms);
     $this->assertEquals('file.inc', $terms[0]->name);
     // It should be assigned to the correct @since taxonomy term.
     $terms = wp_get_object_terms($post->ID, $this->importer->taxonomy_since_version);
     $this->assertCount(1, $terms);
     $this->assertEquals('1.4.0', $terms[0]->name);
     // It should be assigned the correct @package taxonomy term.
     $terms = wp_get_object_terms($post->ID, $this->importer->taxonomy_package);
     $this->assertCount(1, $terms);
     $this->assertEquals('Something', $terms[0]->name);
     // Check that the metadata was imported.
     $this->assertEquals(array(array('name' => '$var', 'default' => null, 'type' => ''), array('name' => '$ids', 'default' => 'array()', 'type' => 'array')), get_post_meta($post->ID, '_wp-parser_args', true));
     $this->assertEquals(25, get_post_meta($post->ID, '_wp-parser_line_num', true));
     $this->assertEquals(28, get_post_meta($post->ID, '_wp-parser_end_line_num', true));
     $this->assertEquals(array(array('name' => 'since', 'content' => '1.4.0'), array('name' => 'param', 'content' => 'A string variable which is the first parameter.', 'types' => array('string'), 'variable' => '$var'), array('name' => 'param', 'content' => 'An array of user IDs.', 'types' => array('int[]'), 'variable' => '$ids'), array('name' => 'return', 'content' => 'The return type is random. (Not really.)', 'types' => array('mixed'))), get_post_meta($post->ID, '_wp-parser_tags', true));
 }
Ejemplo n.º 13
0
 /**
  * @param $entry_id
  *
  * @return LiveBlogging_LiveBlog|null
  */
 public static function live_blogs_for_entry_id($entry_id)
 {
     foreach (wp_get_object_terms(array($entry_id), 'liveblog') as $liveblog_term) {
         return new LiveBlogging_LiveBlog($liveblog_term);
     }
     return null;
 }
function edd_dwqa_categories_save_post_download($post_ID, $post, $update)
{
    global $wpdb;
    $bundle = get_post_meta($post_ID, '_edd_product_type', true);
    if ($bundle == 'bundle') {
        return true;
    }
    $checked_terms = wp_get_object_terms($post_ID, 'download_category', array('fields' => 'ids'));
    if (is_array($checked_terms) && !empty($checked_terms)) {
        foreach ($checked_terms as $category) {
            //check if product category is dwqa category also
            $term_taxonomy_id = $wpdb->get_results($wpdb->prepare("SELECT term_taxonomy_id FROM " . $wpdb->prefix . "term_taxonomy WHERE term_id = %d AND taxonomy = 'dwqa-question_category' ", $category));
            if ($term_taxonomy_id > 0) {
                $post_object['parent'] = $category;
            } else {
                $post_object['parent'] = 0;
            }
            $post_object = array();
            $post_object['action'] = 'add-tag';
            $tag = wp_insert_term($post->post_title, 'dwqa-question_category', $post_object);
            if (!is_wp_error($tag)) {
                $wpdb->query($wpdb->prepare("INSERT INTO " . $wpdb->prefix . "edd_dwqa_categories (id, dwqa_category_id, edd_product_id, edd_product_category_id) VALUES ('', %d, %d, '')", $tag['term_id'], $post_ID));
            }
        }
    } else {
        $post_object = array();
        $post_object['action'] = 'add-tag';
        $post_object['parent'] = 0;
        $tag = wp_insert_term($post->post_title, 'dwqa-question_category', $post_object);
        if (!is_wp_error($tag)) {
            $wpdb->query($wpdb->prepare("INSERT INTO " . $wpdb->prefix . "edd_dwqa_categories (id, dwqa_category_id, edd_product_id, edd_product_category_id) VALUES ('', %d, %d, '')", $tag['term_id'], $post_ID));
        }
    }
    return true;
}
 public function __construct($post = null)
 {
     if (!empty($post) && ($post = get_post($post))) {
         $this->id = $post->ID;
         $this->date = get_the_time(__('Y/m/d g:i:s A', 'flamingo'), $this->id);
         $this->subject = get_post_meta($post->ID, '_subject', true);
         $this->from = get_post_meta($post->ID, '_from', true);
         $this->from_name = get_post_meta($post->ID, '_from_name', true);
         $this->from_email = get_post_meta($post->ID, '_from_email', true);
         $this->fields = get_post_meta($post->ID, '_fields', true);
         foreach ($this->fields as $key => $value) {
             $meta_key = sanitize_key('_field_' . $key);
             if (metadata_exists('post', $post->ID, $meta_key)) {
                 $value = get_post_meta($post->ID, $meta_key, true);
                 $this->fields[$key] = $value;
             }
         }
         $this->meta = get_post_meta($post->ID, '_meta', true);
         $this->akismet = get_post_meta($post->ID, '_akismet', true);
         $terms = wp_get_object_terms($this->id, self::channel_taxonomy);
         if (!empty($terms) && !is_wp_error($terms)) {
             $this->channel = $terms[0]->slug;
         }
         if (self::spam_status == get_post_status($post)) {
             $this->spam = true;
         } else {
             $this->spam = !empty($this->akismet['spam']);
         }
     }
 }
 /**
  * Submit Step
  */
 public function submit()
 {
     global $post;
     $resume = get_post($this->resume_id);
     if (empty($this->resume_id) || $resume->post_status !== 'publish' && $resume->post_status !== 'hidden') {
         echo wpautop(__('Invalid resume', 'wp-job-manager-resumes'));
         return;
     }
     $this->init_fields();
     foreach ($this->fields as $group_key => $group_fields) {
         foreach ($group_fields as $key => $field) {
             if (!isset($this->fields[$group_key][$key]['value'])) {
                 if ('candidate_name' === $key) {
                     $this->fields[$group_key][$key]['value'] = $resume->post_title;
                 } elseif ('resume_content' === $key) {
                     $this->fields[$group_key][$key]['value'] = $resume->post_content;
                 } elseif (!empty($field['taxonomy'])) {
                     $this->fields[$group_key][$key]['value'] = wp_get_object_terms($resume->ID, $field['taxonomy'], array('fields' => 'ids'));
                 } elseif ('resume_skills' === $key) {
                     $this->fields[$group_key][$key]['value'] = implode(', ', wp_get_object_terms($resume->ID, 'resume_skill', array('fields' => 'names')));
                 } else {
                     $this->fields[$group_key][$key]['value'] = get_post_meta($resume->ID, '_' . $key, true);
                 }
             }
         }
     }
     $this->fields = apply_filters('submit_resume_form_fields_get_resume_data', $this->fields, $resume);
     get_job_manager_template('resume-submit.php', array('class' => $this, 'form' => $this->form_name, 'job_id' => '', 'resume_id' => $this->get_resume_id(), 'action' => $this->get_action(), 'resume_fields' => $this->get_fields('resume_fields'), 'step' => $this->get_step(), 'submit_button_text' => __('Save changes', 'wp-job-manager-resumes')), 'wp-job-manager-resumes', RESUME_MANAGER_PLUGIN_DIR . '/templates/');
 }
 /**
  * Submit Step
  */
 public function submit()
 {
     $job = get_post($this->job_id);
     if (empty($this->job_id) || $job->post_status !== 'publish' && !job_manager_user_can_edit_pending_submissions()) {
         echo wpautop(__('Invalid listing', 'wp-job-manager'));
         return;
     }
     $this->init_fields();
     foreach ($this->fields as $group_key => $group_fields) {
         foreach ($group_fields as $key => $field) {
             if (!isset($this->fields[$group_key][$key]['value'])) {
                 if ('job_title' === $key) {
                     $this->fields[$group_key][$key]['value'] = $job->post_title;
                 } elseif ('job_description' === $key) {
                     $this->fields[$group_key][$key]['value'] = $job->post_content;
                 } elseif ('company_logo' === $key) {
                     $this->fields[$group_key][$key]['value'] = has_post_thumbnail($job->ID) ? get_post_thumbnail_id($job->ID) : get_post_meta($job->ID, '_' . $key, true);
                 } elseif (!empty($field['taxonomy'])) {
                     $this->fields[$group_key][$key]['value'] = wp_get_object_terms($job->ID, $field['taxonomy'], array('fields' => 'ids'));
                 } else {
                     $this->fields[$group_key][$key]['value'] = get_post_meta($job->ID, '_' . $key, true);
                 }
             }
         }
     }
     $this->fields = apply_filters('submit_job_form_fields_get_job_data', $this->fields, $job);
     wp_enqueue_script('wp-job-manager-job-submission');
     get_job_manager_template('job-submit.php', array('form' => $this->form_name, 'job_id' => $this->get_job_id(), 'action' => $this->get_action(), 'job_fields' => $this->get_fields('job'), 'company_fields' => $this->get_fields('company'), 'step' => $this->get_step(), 'submit_button_text' => __('Save changes', 'wp-job-manager')));
 }
 static function add_attachment_fields_to_edit($form_fields, $post)
 {
     $terms = get_object_term_cache($post->ID, self::TAXONOMY);
     $field = array();
     $taxonomy_obj = (array) get_taxonomy(self::TAXONOMY);
     if (!$taxonomy_obj['public'] || !$taxonomy_obj['show_ui']) {
         continue;
     }
     if (false === $terms) {
         $terms = wp_get_object_terms($post->ID, self::TAXONOMY);
     }
     $values = wp_list_pluck($terms, 'term_id');
     ob_start();
     wp_terms_checklist($post->ID, array('taxonomy' => self::TAXONOMY, 'checked_ontop' => false, 'walker' => new Walker_WP_Media_Taxonomy_Checklist($post->ID)));
     $output = ob_get_clean();
     if (!empty($output)) {
         $output = '<ul class="term-list">' . $output . '</ul>';
         $output .= wp_nonce_field('save_attachment_media_categories', 'media_category_nonce', false, false);
     } else {
         $output = '<ul class="term-list"><li>No ' . $taxonomy_obj['label'] . '</li></ul>';
     }
     $field = array('label' => !empty($taxonomy_obj['label']) ? $taxonomy_obj['label'] : self::TAXONOMY, 'value' => join(', ', $values), 'show_in_edit' => false, 'input' => 'html', 'html' => $output);
     $form_fields[self::TAXONOMY] = $field;
     return $form_fields;
 }
 /**
  * @param int $original_post_id
  * @param string $lang
  * @param bool $duplicate sets whether missing terms should be created by duplicating the original term
  */
 private function synchronize_terms($original_post_id, $lang, $duplicate)
 {
     global $wpml_post_translations;
     $wpml_post_translations->reload();
     $translated_post_id = $wpml_post_translations->element_id_in($original_post_id, $lang);
     if ((bool) $translated_post_id === true) {
         $taxonomies = get_post_taxonomies($original_post_id);
         foreach ($taxonomies as $tax) {
             $terms_on_original = wp_get_object_terms($original_post_id, $tax);
             if (!$this->sitepress->is_translated_taxonomy($tax)) {
                 if ($this->sitepress->get_setting('sync_post_taxonomies')) {
                     // Taxonomy is not translated so we can just copy from the original
                     foreach ($terms_on_original as $key => $term) {
                         $terms_on_original[$key] = $term->term_id;
                     }
                     wp_set_object_terms($translated_post_id, $terms_on_original, $tax);
                 }
             } else {
                 /** @var int[] $translated_terms translated term_ids */
                 $translated_terms = $this->get_translated_term_ids($terms_on_original, $lang, $tax, $duplicate);
                 wp_set_object_terms($translated_post_id, $translated_terms, $tax);
             }
         }
     }
     clean_object_term_cache($original_post_id, get_post_type($original_post_id));
 }
Ejemplo n.º 20
0
 function load_value($value, $post_id, $field)
 {
     // get valid terms
     $value = acf_get_valid_terms($value, $field['taxonomy']);
     // load/save
     if ($field['load_save_terms']) {
         // bail early if no value
         if (empty($value)) {
             return $value;
         }
         // get current ID's
         $term_ids = wp_get_object_terms($post_id, $field['taxonomy'], array('fields' => 'ids', 'orderby' => 'none'));
         // case
         if (empty($term_ids)) {
             // 1. no terms for this post
             return null;
         } elseif (is_array($value)) {
             // 2. remove metadata terms which are no longer for this post
             $value = array_map('intval', $value);
             $value = array_intersect($value, $term_ids);
         } elseif (!in_array($value, $term_ids)) {
             // 3. term is no longer for this post
             return null;
         }
     }
     // return
     return $value;
 }
Ejemplo n.º 21
0
 /**
  * Display related projects.
  *
  */
 function presscore_display_related_projects()
 {
     global $post;
     $html = '';
     $config = presscore_get_config();
     // if related projects turn on in theme options
     if ($config->get('post.related_posts.enabled')) {
         $terms = array();
         switch ($config->get('post.related_posts.query.mode')) {
             case 'custom':
                 $terms = $config->get('post.related_posts.query.terms');
                 break;
             default:
                 $terms = wp_get_object_terms($post->ID, 'dt_portfolio_category', array('fields' => 'ids'));
         }
         if ($terms && !is_wp_error($terms)) {
             $options = array('cats' => $terms, 'select' => 'only', 'post_type' => 'dt_portfolio', 'taxonomy' => 'dt_portfolio_category', 'args' => array('posts_per_page' => intval($config->get('post.related_posts.query.posts_per_page')), 'post__not_in' => array(get_the_ID())));
             $posts = presscore_get_posts_in_categories($options);
             $portfolio_scroller = new Presscore_Portfolio_Posts_Scroller();
             $portfolio_scroller->setup($posts, array('class' => 'related-projects slider-wrapper', 'width' => $config->get('post.related_posts.width'), 'height' => $config->get('post.related_posts.height'), 'show_title' => $config->get('post.related_posts.show.title'), 'show_excerpt' => $config->get('post.related_posts.show.description'), 'appearance' => 'under_image', 'padding' => 20, 'bg_under_projects' => false, 'content_aligment' => 'center', 'hover_animation' => 'fade', 'hover_bg_color' => 'accent', 'hover_content_visibility' => 'on_hoover', 'show_link' => $config->get('post.related_posts.show.link'), 'show_details' => $config->get('post.related_posts.show.details_link'), 'show_zoom' => $config->get('post.related_posts.show.zoom'), 'show_date' => $config->get('post.related_posts.meta.fields.date'), 'show_categories' => $config->get('post.related_posts.meta.fields.categories'), 'show_comments' => $config->get('post.related_posts.meta.fields.comments'), 'show_author' => $config->get('post.related_posts.meta.fields.author'), 'arrows' => 'accent'));
             $html .= $portfolio_scroller->get_html();
             if ($html) {
                 $html = '<div class="full-width-wrap">' . $html . '</div>';
                 // fancy separator
                 $html = presscore_fancy_separator(array('title' => $config->get('post.related_posts.title'), 'class' => 'fancy-projects-title')) . $html;
                 if (!(post_password_required() || !comments_open() && 0 == get_comments_number())) {
                     // add gap after projects
                     $html .= do_shortcode('[dt_gap height="40"]');
                 }
             }
         }
     }
     echo (string) apply_filters('presscore_display_related_projects', $html);
 }
 /**
  * Get tags from current post views
  *
  * @return boolean
  */
 public static function get_tags_from_current_posts()
 {
     if (is_array(self::$posts) && count(self::$posts) > 0) {
         // Generate SQL from post id
         $postlist = implode("', '", self::$posts);
         // Generate key cache
         $key = md5(maybe_serialize($postlist));
         $results = array();
         // Get cache if exist
         $cache = wp_cache_get('generate_keywords', 'simpletags');
         if ($cache === false) {
             foreach (self::$posts as $object_id) {
                 // Get terms
                 $terms = get_object_term_cache($object_id, 'post_tag');
                 if (false === $terms) {
                     $terms = wp_get_object_terms($object_id, 'post_tag');
                 }
                 if ($terms != false) {
                     $results = array_merge($results, $terms);
                 }
             }
             $cache[$key] = $results;
             wp_cache_set('generate_keywords', $cache, 'simpletags');
         } else {
             if (isset($cache[$key])) {
                 return $cache[$key];
             }
         }
         return $results;
     }
     return array();
 }
Ejemplo n.º 23
0
/**
 * Retrieve Bookmark data based on ID
 *
 * @since 2.1.0
 * @uses $wpdb Database Object
 *
 * @param int $bookmark_id
 * @param string $output Optional. Either OBJECT, ARRAY_N, or ARRAY_A constant
 * @param string $filter Optional, default is 'raw'.
 * @return array|object Type returned depends on $output value.
 */
function get_bookmark($bookmark, $output = OBJECT, $filter = 'raw')
{
    global $wpdb;
    if (empty($bookmark)) {
        if (isset($GLOBALS['link'])) {
            $_bookmark =& $GLOBALS['link'];
        } else {
            $_bookmark = null;
        }
    } elseif (is_object($bookmark)) {
        wp_cache_add($bookmark->link_id, $bookmark, 'bookmark');
        $_bookmark = $bookmark;
    } else {
        if (isset($GLOBALS['link']) && $GLOBALS['link']->link_id == $bookmark) {
            $_bookmark =& $GLOBALS['link'];
        } elseif (!($_bookmark = wp_cache_get($bookmark, 'bookmark'))) {
            $_bookmark = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->links} WHERE link_id = %d LIMIT 1", $bookmark));
            $_bookmark->link_category = array_unique(wp_get_object_terms($_bookmark->link_id, 'link_category', 'fields=ids'));
            wp_cache_add($_bookmark->link_id, $_bookmark, 'bookmark');
        }
    }
    $_bookmark = sanitize_bookmark($_bookmark, $filter);
    if ($output == OBJECT) {
        return $_bookmark;
    } elseif ($output == ARRAY_A) {
        return get_object_vars($_bookmark);
    } elseif ($output == ARRAY_N) {
        return array_values(get_object_vars($_bookmark));
    } else {
        return $_bookmark;
    }
}
 protected function display_posts_filter($args = array())
 {
     $default_args = array('post_type' => 'post', 'taxonomy' => 'category', 'query' => null, 'select' => 'all', 'show_category_filter' => true);
     $args = wp_parse_args($args, $default_args);
     $filter_args = array();
     if ($args['show_category_filter']) {
         // categorizer args
         $filter_args = array('taxonomy' => $args['taxonomy'], 'post_type' => $args['post_type'], 'select' => $args['select']);
         if ('only' == $args['select'] && $args['query'] && $args['query']->posts && isset($args['query']->tax_query->queried_terms[$args['taxonomy']]['terms'])) {
             $filter_args['terms'] = array();
             $queried_terms = $args['query']->tax_query->queried_terms[$args['taxonomy']]['terms'];
             $posts_ids = wp_list_pluck($args['query']->posts, 'ID');
             $posts_terms = wp_get_object_terms($posts_ids, $args['taxonomy']);
             foreach ($posts_terms as $term) {
                 if (in_array($term->slug, $queried_terms)) {
                     $filter_args['terms'][] = intval($term->term_id);
                 }
             }
             $filter_args['terms'] = array_unique($filter_args['terms']);
         }
     }
     $filter_class = '';
     if (!$this->config->get('template.posts_filter.orderby.enabled') && !$this->config->get('template.posts_filter.order.enabled')) {
         $filter_class .= ' extras-off';
     }
     // display categorizer
     presscore_get_category_list(array('data' => dt_prepare_categorizer_data($filter_args), 'class' => 'filter iso-filter' . $filter_class));
 }
Ejemplo n.º 25
0
 /**
  * @ticket 26948
  */
 public function test_dont_process_terms_if_taxonomy_does_not_allow_show_on_quick_edit()
 {
     register_taxonomy('wptests_tax_1', 'post', array('show_in_quick_edit' => false, 'hierarchical' => true));
     register_taxonomy('wptests_tax_2', 'post', array('show_in_quick_edit' => true, 'hierarchical' => true));
     $t1 = self::factory()->term->create(array('taxonomy' => 'wptests_tax_1'));
     $t2 = self::factory()->term->create(array('taxonomy' => 'wptests_tax_2'));
     // Become an administrator.
     $this->_setRole('administrator');
     $post = self::factory()->post->create_and_get(array('post_author' => get_current_user_id()));
     // Set up a request.
     $_POST['_inline_edit'] = wp_create_nonce('inlineeditnonce');
     $_POST['post_ID'] = $post->ID;
     $_POST['post_type'] = $post->post_type;
     $_POST['content'] = $post->post_content;
     $_POST['excerpt'] = $post->post_excerpt;
     $_POST['_status'] = $post->post_status;
     $_POST['post_status'] = $post->post_status;
     $_POST['screen'] = 'post';
     $_POST['post_view'] = 'excerpt';
     $_POST['tax_input'] = array('wptests_tax_1' => array($t1), 'wptests_tax_2' => array($t2));
     // Make the request.
     try {
         $this->_handleAjax('inline-save');
     } catch (WPAjaxDieContinueException $e) {
         unset($e);
     }
     // wptests_tax_1 terms should have been refused.
     $post_terms_1 = wp_get_object_terms($post->ID, 'wptests_tax_1');
     $this->assertEmpty($post_terms_1);
     // wptests_tax_2 terms should have been added successfully.
     $post_terms_2 = wp_get_object_terms($post->ID, 'wptests_tax_2');
     $this->assertEqualSets(array($t2), wp_list_pluck($post_terms_2, 'term_id'));
 }
Ejemplo n.º 26
0
function data()
{
    // Attempt to retrieve the current post and exit early if we're not successful
    if (empty($id = get_the_ID())) {
        return;
    }
    // Retrieve the series terms for the current post
    $terms = array_map('intval', wp_get_object_terms($id, 'series', ['fields' => 'ids', 'orderby' => 'name', 'order' => 'ASC']));
    // Nothing found, let's return
    if (empty($terms)) {
        return false;
    }
    // Initialize series array
    $series = [];
    // Loop through the series this post belongs to and generate an array of post IDs
    foreach ($terms as $term) {
        // Fetch a list of posts in a given series in chronological order
        $query = new \WP_Query(['order' => 'ASC', 'nopaging' => true, 'tax_query' => [['taxonomy' => 'series', 'terms' => $term]]]);
        // Assign data to an array that will then be returned
        if (!empty($query)) {
            foreach ($query->posts as $post) {
                $series[$term][] = ['id' => $post->ID, 'title' => get_the_title($post->ID), 'link' => get_permalink($post->ID)];
            }
        }
    }
    return $series;
}
Ejemplo n.º 27
0
/**
 * This is a reusable function that allows us to grab place-specific data and
 * return it in a consistent way across our plugin scripts, and in theme
 * template files as well.
 */
function wanderlist_place_data($data, $post_ID = null)
{
    switch ($data) {
        case 'country':
            // We need to figure out our place's country. Here we go.
            $countries = wp_get_object_terms(get_the_ID(), 'wanderlist-country', array('fields' => 'names'));
            if ($countries) {
                $count = 0;
                foreach ($countries as $country => $name) {
                    if (0 === $count) {
                        $output = $name;
                    } else {
                        $output .= ', ' . $name;
                    }
                    $count++;
                }
            } else {
                $output = '';
            }
            break;
        case 'city':
            $output = get_post_meta($post_ID, 'wanderlist-city', true);
            break;
        case 'lat':
            $output = get_post_meta($post_ID, 'wanderlist-lat', true);
            break;
        case 'lng':
            $output = get_post_meta($post_ID, 'wanderlist-lng', true);
            break;
    }
    return $output;
}
Ejemplo n.º 28
0
 /**
  * Copy tags
  */
 function copy_tags($src_pid, $dest_pid)
 {
     $tags = wp_get_object_terms($src_pid, 'ngg_tag', 'fields=ids');
     $tags = array_map('intval', $tags);
     wp_set_object_terms($dest_pid, $tags, 'ngg_tag', true);
     return implode(',', $tags);
 }
Ejemplo n.º 29
0
function hmp_category_meta_box($post)
{
    global $post;
    ?>
	<p><label for="hmp_portfolio_category">Category</label></p>
	<select name="hmp_portfolio_category">
		<option value="">Select Category...</option>
		<?php 
    $cats = get_terms('hmp-entry-category', array('hide_empty' => false));
    $obj_cat = wp_get_object_terms($post->ID, 'hmp-entry-category');
    $obj_cat = $obj_cat[0];
    foreach ($cats as $cat) {
        ?>
			<option <?php 
        if ($cat->term_id == $obj_cat->term_id) {
            echo 'selected="selected" ';
        }
        ?>
value="<?php 
        echo $cat->term_id;
        ?>
"><?php 
        echo $cat->name;
        ?>
</option>
		<?php 
    }
    ?>
	</select>
	<p><label for="hmp_portfolio_new_category">Add New Category</label></p>
	<input name="hmp_portfolio_new_category" type="text" />
	<?php 
}
Ejemplo n.º 30
0
 function ubik_series()
 {
     // Attempt to retrieve the current post and exit early if we're not successful
     $post = get_post();
     if (empty($post)) {
         return;
     }
     // Retrieve the series terms for the current post
     $series_terms = array_map('intval', wp_get_object_terms($post->ID, 'series', array('fields' => 'ids', 'orderby' => 'name', 'order' => 'ASC')));
     // Cycle through and generate arrays of post IDs for each series
     if (!empty($series_terms)) {
         // Initialize series array
         $series = array();
         // Loop through the series this post belongs to and generate an array of post IDs
         foreach ($series_terms as $series_term) {
             // Fetch a list of posts in a given series in chronological order
             $series_query = new WP_Query(array('order' => 'ASC', 'nopaging' => true, 'tax_query' => array(array('taxonomy' => 'series', 'terms' => $series_term))));
             // Assign data to an array that will then be returned
             if (!empty($series_query)) {
                 foreach ($series_query->posts as $post) {
                     $series[$series_term][] = array('id' => $post->ID, 'title' => get_the_title($post->ID), 'link' => get_permalink($post->ID));
                 }
             }
         }
         return $series;
     }
     // No series found; return false
     return false;
 }