/**
  * 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();
 }
 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;
 }
Esempio n. 3
0
 /**
  * Wrap wp_get_object_terms to cache it and return only one object
  * inspired by the function get_the_terms
  *
  * @since 1.2
  *
  * @param int    $object_id post_id or term_id
  * @param string $taxonomy  Polylang taxonomy depending if we are looking for a post ( or term ) language ( or translation )
  * @return bool|object the term associated to the object in the requested taxonomy if exists, false otherwise
  */
 public function get_object_term($object_id, $taxonomy)
 {
     if (empty($object_id)) {
         return false;
     }
     $object_id = (int) $object_id;
     $term = get_object_term_cache($object_id, $taxonomy);
     if (false === $term) {
         // query language and translations at the same time
         $taxonomies = array($this->tax_language, $this->tax_translations);
         // query terms
         foreach (wp_get_object_terms($object_id, $taxonomies) as $t) {
             $terms[$t->taxonomy] = $t;
             if ($t->taxonomy == $taxonomy) {
                 $term = $t;
             }
         }
         // store it the way WP wants it
         // set an empty cache if no term found in the taxonomy
         foreach ($taxonomies as $tax) {
             wp_cache_add($object_id, empty($terms[$tax]) ? array() : array($terms[$tax]), $tax . '_relationships');
         }
     } else {
         $term = reset($term);
     }
     return empty($term) ? false : $term;
 }
 function get_tags($postid)
 {
     $tags = get_object_term_cache($postid, 'post_tag');
     if (false === $tags) {
         $tags = wp_get_object_terms($postid, 'post_tag');
     }
     $tags = apply_filters('get_the_tags', $tags);
     if (!empty($tags)) {
         foreach ($tags as $tag) {
             $newtags[] = $tag->name;
         }
         $tags = implode(',', $newtags);
     } else {
         $tags = '';
     }
     return $tags;
 }
/**
 *  Attach information about a question's topic 
 */
function attach_actions_meta(&$post)
{
    if ($post->post_type === 'question') {
        // Try to get tax
        // Term cache should already be primed by 'update_post_term_cache'.
        $terms = get_object_term_cache($post->ID, 'faq-topic');
        // Guess not
        if (empty($terms)) {
            $terms = wp_get_object_terms($post->ID, 'faq-topic');
            wp_cache_add($post->ID, $terms, 'faq-topic' . '_relationships');
        }
        // We got some hits
        if (!empty($terms)) {
            $interim_term = false;
            foreach ($terms as $key => $term) {
                if (!$interim_term || $term->parent) {
                    $interim_term = $term;
                }
            }
            $post->term = $interim_term->slug;
        }
        $post->action_attr = 'answers';
        $post->action_hash = '/' . $post->term . '/' . $post->post_name;
    } elseif ($post->post_type === 'payment') {
        $post->action_attr = 'payments';
        $post->action_hash = '/' . $post->post_name;
    } elseif ($post->post_type === 'issue') {
        $issue_type = get_post_meta($post->ID, 'issue_category_type', true);
        switch ($issue_type) {
            case 'link':
                $post->action_url = get_post_meta($post->ID, 'url', true);
                return;
            case 'iframe':
                $post->action_attr = 'report';
                $post->action_hash = '/embed/' . $post->post_name;
                break;
            case 'form':
                $post->action_url = $post->guid;
                break;
        }
    }
    return;
}
/**
 * get_the_series() - calls up all the series info from the taxonomy tables (for a particular post).
*/
function get_the_series($id = false, $cache = true)
{
    global $post, $term_cache;
    $id = (int) $id;
    if (!$id && (!empty($post) || $post != '' || $post != null)) {
        $id = (int) $post->ID;
    }
    if (empty($id)) {
        return false;
    }
    $series = $cache ? get_object_term_cache($id, 'series') : false;
    if (false === $series) {
        $series = wp_get_object_terms($id, 'series');
    }
    $series = apply_filters('get_the_series', $series);
    //adds a new filter for users to hook into
    if (!empty($series)) {
        usort($series, '_usort_terms_by_name');
    }
    return $series;
}
function get_blogtrip_taxonomies($post = 0, $args = array(), $format = '')
{
    if (is_int($post)) {
        $post =& get_post($post);
    } elseif (!is_object($post)) {
        $post =& $GLOBALS['post'];
    }
    $args = wp_parse_args($args, array('template' => '%s: %l.'));
    extract($args, EXTR_SKIP);
    $taxonomies = array();
    if (!$post) {
        return $taxonomies;
    }
    foreach (get_object_taxonomies($post) as $taxonomy) {
        $t = (array) get_taxonomy($taxonomy);
        if (empty($t['label'])) {
            $t['label'] = $taxonomy;
        }
        if (empty($t['args'])) {
            $t['args'] = array();
        }
        if (empty($t['template'])) {
            $t['template'] = $template;
        }
        $terms = get_object_term_cache($post->ID, $taxonomy);
        if (empty($terms)) {
            $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
        }
        if ('' != $format) {
            $taxonomies[$taxonomy] = array();
            foreach ($terms as $term) {
                $taxonomies[$taxonomy][$term->slug] = isset($term->{$format}) ? $term->{$format} : $term->name;
            }
        } else {
            $taxonomies[$taxonomy] = $terms;
        }
    }
    return $taxonomies;
}
Esempio n. 8
0
 function get_the_tags($id = 0)
 {
     $tags = $this->tags;
     if (is_single() || is_page()) {
         global $post;
         $id = (int) $id;
         if (!$id) {
             $id = (int) $post->ID;
         }
         $tagsextra = get_object_term_cache($id, 'post_tag');
         if (false === $tagsextra) {
             $tagsextra = wp_get_object_terms($id, 'post_tag');
         }
         $tagsextra = apply_filters('get_the_tags', $tagsextra);
         if (!empty($tagsextra)) {
             foreach ($tagsextra as $tag) {
                 $newtags[] = $tag->name;
             }
             $tags .= ',' . implode(',', $newtags);
         }
     }
     return trim($tags, ',');
 }
Esempio n. 9
0
/**
 * Adds hidden fields with the data for use in the inline editor for posts and pages.
 *
 * @since 2.7.0
 *
 * @param WP_Post $post Post object.
 */
function get_inline_data($post)
{
    $post_type_object = get_post_type_object($post->post_type);
    if (!current_user_can('edit_post', $post->ID)) {
        return;
    }
    $title = esc_textarea(trim($post->post_title));
    /** This filter is documented in wp-admin/edit-tag-form.php */
    echo '
<div class="hidden" id="inline_' . $post->ID . '">
	<div class="post_title">' . $title . '</div>' . '<div class="post_name">' . apply_filters('editable_slug', $post->post_name, $post) . '</div>
	<div class="post_author">' . $post->post_author . '</div>
	<div class="comment_status">' . esc_html($post->comment_status) . '</div>
	<div class="ping_status">' . esc_html($post->ping_status) . '</div>
	<div class="_status">' . esc_html($post->post_status) . '</div>
	<div class="jj">' . mysql2date('d', $post->post_date, false) . '</div>
	<div class="mm">' . mysql2date('m', $post->post_date, false) . '</div>
	<div class="aa">' . mysql2date('Y', $post->post_date, false) . '</div>
	<div class="hh">' . mysql2date('H', $post->post_date, false) . '</div>
	<div class="mn">' . mysql2date('i', $post->post_date, false) . '</div>
	<div class="ss">' . mysql2date('s', $post->post_date, false) . '</div>
	<div class="post_password">' . esc_html($post->post_password) . '</div>';
    if ($post_type_object->hierarchical) {
        echo '<div class="post_parent">' . $post->post_parent . '</div>';
    }
    if ($post->post_type == 'page') {
        echo '<div class="page_template">' . esc_html(get_post_meta($post->ID, '_wp_page_template', true)) . '</div>';
    }
    if (post_type_supports($post->post_type, 'page-attributes')) {
        echo '<div class="menu_order">' . $post->menu_order . '</div>';
    }
    $taxonomy_names = get_object_taxonomies($post->post_type);
    foreach ($taxonomy_names as $taxonomy_name) {
        $taxonomy = get_taxonomy($taxonomy_name);
        if ($taxonomy->hierarchical && $taxonomy->show_ui) {
            $terms = get_object_term_cache($post->ID, $taxonomy_name);
            if (false === $terms) {
                $terms = wp_get_object_terms($post->ID, $taxonomy_name);
                wp_cache_add($post->ID, wp_list_pluck($terms, 'term_id'), $taxonomy_name . '_relationships');
            }
            $term_ids = empty($terms) ? array() : wp_list_pluck($terms, 'term_id');
            echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">' . implode(',', $term_ids) . '</div>';
        } elseif ($taxonomy->show_ui) {
            $terms_to_edit = get_terms_to_edit($post->ID, $taxonomy_name);
            if (!is_string($terms_to_edit)) {
                $terms_to_edit = '';
            }
            echo '<div class="tags_input" id="' . $taxonomy_name . '_' . $post->ID . '">' . esc_html(str_replace(',', ', ', $terms_to_edit)) . '</div>';
        }
    }
    if (!$post_type_object->hierarchical) {
        echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>';
    }
    if (post_type_supports($post->post_type, 'post-formats')) {
        echo '<div class="post_format">' . esc_html(get_post_format($post->ID)) . '</div>';
    }
    echo '</div>';
}
Esempio n. 10
0
/**
 * Determine if the given object is associated with any of the given terms.
 *
 * The given terms are checked against the object's terms' term_ids, names and slugs.
 * Terms given as integers will only be checked against the object's terms' term_ids.
 * If no terms are given, determines if object is associated with any terms in the given taxonomy.
 *
 * @since 2.7.0
 *
 * @param int              $object_id ID of the object (post ID, link ID, ...).
 * @param string           $taxonomy  Single taxonomy name.
 * @param int|string|array $terms     Optional. Term term_id, name, slug or array of said. Default null.
 * @return bool|WP_Error WP_Error on input error.
 */
function is_object_in_term($object_id, $taxonomy, $terms = null)
{
    if (!($object_id = (int) $object_id)) {
        return new WP_Error('invalid_object', __('Invalid object ID'));
    }
    $object_terms = get_object_term_cache($object_id, $taxonomy);
    if (false === $object_terms) {
        $object_terms = wp_get_object_terms($object_id, $taxonomy, array('update_term_meta_cache' => false));
        wp_cache_set($object_id, $object_terms, "{$taxonomy}_relationships");
    }
    if (is_wp_error($object_terms)) {
        return $object_terms;
    }
    if (empty($object_terms)) {
        return false;
    }
    if (empty($terms)) {
        return !empty($object_terms);
    }
    $terms = (array) $terms;
    if ($ints = array_filter($terms, 'is_int')) {
        $strs = array_diff($terms, $ints);
    } else {
        $strs =& $terms;
    }
    foreach ($object_terms as $object_term) {
        // If term is an int, check against term_ids only.
        if ($ints && in_array($object_term->term_id, $ints)) {
            return true;
        }
        if ($strs) {
            // Only check numeric strings against term_id, to avoid false matches due to type juggling.
            $numeric_strs = array_map('intval', array_filter($strs, 'is_numeric'));
            if (in_array($object_term->term_id, $numeric_strs, true)) {
                return true;
            }
            if (in_array($object_term->name, $strs)) {
                return true;
            }
            if (in_array($object_term->slug, $strs)) {
                return true;
            }
        }
    }
    return false;
}
Esempio n. 11
0
/**
 * {@internal Missing Short Description}}
 *
 * @since unknown
 *
 * @param unknown_type $post
 * @param unknown_type $errors
 * @return unknown
 */
function get_attachment_fields_to_edit($post, $errors = null)
{
    if (is_int($post)) {
        $post =& get_post($post);
    }
    if (is_array($post)) {
        $post = (object) $post;
    }
    $image_url = wp_get_attachment_url($post->ID);
    $edit_post = sanitize_post($post, 'edit');
    $form_fields = array('post_title' => array('label' => __('Title'), 'value' => $edit_post->post_title), 'post_excerpt' => array('label' => __('Caption'), 'value' => $edit_post->post_excerpt), 'post_content' => array('label' => __('Description'), 'value' => $edit_post->post_content, 'input' => 'textarea'), 'url' => array('label' => __('Link URL'), 'input' => 'html', 'html' => image_link_input_fields($post, get_option('image_default_link_type')), 'helps' => __('Enter a link URL or click above for presets.')), 'menu_order' => array('label' => __('Order'), 'value' => $edit_post->menu_order), 'image_url' => array('label' => __('File URL'), 'input' => 'html', 'html' => "<input type='text' class='urlfield' readonly='readonly' name='attachments[{$post->ID}][url]' value='" . esc_attr($image_url) . "' /><br />", 'value' => isset($edit_post->post_url) ? $edit_post->post_url : '', 'helps' => __('Location of the uploaded file.')));
    foreach (get_attachment_taxonomies($post) as $taxonomy) {
        $t = (array) get_taxonomy($taxonomy);
        if (empty($t['label'])) {
            $t['label'] = $taxonomy;
        }
        if (empty($t['args'])) {
            $t['args'] = array();
        }
        $terms = get_object_term_cache($post->ID, $taxonomy);
        if (empty($terms)) {
            $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
        }
        $values = array();
        foreach ($terms as $term) {
            $values[] = $term->name;
        }
        $t['value'] = join(', ', $values);
        $form_fields[$taxonomy] = $t;
    }
    // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
    // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing )
    $form_fields = array_merge_recursive($form_fields, (array) $errors);
    $form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post);
    return $form_fields;
}
Esempio n. 12
0
/**
 * Get comma-separated list of terms available to edit for the given post ID.
 *
 * @since 2.8.0
 *
 * @param int    $post_id
 * @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
 * @return string|bool|WP_Error
 */
function get_terms_to_edit($post_id, $taxonomy = 'post_tag')
{
    $post_id = (int) $post_id;
    if (!$post_id) {
        return false;
    }
    $terms = get_object_term_cache($post_id, $taxonomy);
    if (false === $terms) {
        $terms = wp_get_object_terms($post_id, $taxonomy);
        wp_cache_add($post_id, $terms, $taxonomy . '_relationships');
    }
    if (!$terms) {
        return false;
    }
    if (is_wp_error($terms)) {
        return $terms;
    }
    $term_names = array();
    foreach ($terms as $term) {
        $term_names[] = $term->name;
    }
    $terms_to_edit = esc_attr(join(',', $term_names));
    /**
     * Filter the comma-separated list of terms available to edit.
     *
     * @since 2.8.0
     *
     * @see get_terms_to_edit()
     *
     * @param array  $terms_to_edit An array of terms.
     * @param string $taxonomy     The taxonomy for which to retrieve terms. Default 'post_tag'.
     */
    $terms_to_edit = apply_filters('terms_to_edit', $terms_to_edit, $taxonomy);
    return $terms_to_edit;
}
 /**
  * Lazy-loads termmeta for located posts.
  * As a rule, term queries (`get_terms()` and `wp_get_object_terms()`) prime the metadata cache for matched
  * terms by default. However, this can cause a slight performance penalty, especially when that metadata is
  * not actually used. In the context of a `WP_Query` instance, we're able to avoid this potential penalty.
  * `update_object_term_cache()`, called from `update_post_caches()`, does not 'update_term_meta_cache'.
  * Instead, the first time `get_term_meta()` is called from within a `WP_Query` loop, the current method
  * detects the fact, and then primes the metadata cache for all terms attached to all posts in the loop,
  * with a single database query.
  * This method is public so that it can be used as a filter callback. As a rule, there is no need to invoke it
  * directly, from either inside or outside the `WP_Query` object.
  * @param mixed $check  The `$check` param passed from the 'get_term_metadata' hook.
  * @param int  $term_id ID of the term whose metadata is being cached.
  * @return mixed In order not to short-circuit `get_metadata()`. Generally, this is `null`, but it could be
  *               another value if filtered by a plugin.
  */
 public function lazyload_term_meta($check, $term_id)
 {
     /*
      * We only do this once per `WP_Query` instance.
      * Can't use `remove_filter()` because of non-unique object hashes.
      */
     if ($this->updated_term_meta_cache) {
         return $check;
     }
     // We can only lazyload if the entire post object is present.
     $posts = array();
     foreach ($this->posts as $post) {
         if ($post instanceof WP_Post) {
             $posts[] = $post;
         }
     }
     if (!empty($posts)) {
         // Fetch cached term_ids for each post. Keyed by term_id for faster lookup.
         $term_ids = array();
         foreach ($posts as $post) {
             $taxonomies = get_object_taxonomies($post->post_type);
             foreach ($taxonomies as $taxonomy) {
                 // Term cache should already be primed by 'update_post_term_cache'.
                 $terms = get_object_term_cache($post->ID, $taxonomy);
                 if (false !== $terms) {
                     foreach ($terms as $term) {
                         if (!isset($term_ids[$term->term_id])) {
                             $term_ids[$term->term_id] = 1;
                         }
                     }
                 }
             }
         }
         /*
          * Only update the metadata cache for terms belonging to these posts if the term_id passed
          * to `get_term_meta()` matches one of those terms. This prevents a single call to
          * `get_term_meta()` from priming metadata for all `WP_Query` objects.
          */
         if (isset($term_ids[$term_id])) {
             update_termmeta_cache(array_keys($term_ids));
             $this->updated_term_meta_cache = true;
         }
     }
     // If no terms were found, there's no need to run this again.
     if (empty($term_ids)) {
         $this->updated_term_meta_cache = true;
     }
     return $check;
 }
Esempio n. 14
0
function get_the_tags($id = 0)
{
    global $post;
    $id = (int) $id;
    if (!$id && !in_the_loop()) {
        return false;
    }
    // in-the-loop function
    if (!$id) {
        $id = (int) $post->ID;
    }
    $tags = get_object_term_cache($id, 'post_tag');
    if (false === $tags) {
        $tags = wp_get_object_terms($id, 'post_tag');
    }
    $tags = apply_filters('get_the_tags', $tags);
    if (empty($tags)) {
        return false;
    }
    return $tags;
}
Esempio n. 15
0
/**
 * Retrieve the terms of the taxonomy that are attached to the post.
 *
 * This function can only be used within the loop.
 *
 * @since 2.5.0
 *
 * @param int $id Post ID. Is not optional.
 * @param string $taxonomy Taxonomy name.
 * @return array|bool False on failure. Array of term objects on success.
 */
function get_the_terms($id = 0, $taxonomy)
{
    global $post;
    $id = (int) $id;
    if (!$id && !in_the_loop()) {
        return false;
    }
    // in-the-loop function
    if (!$id) {
        $id = (int) $post->ID;
    }
    $terms = get_object_term_cache($id, $taxonomy);
    if (false === $terms) {
        $terms = wp_get_object_terms($id, $taxonomy);
    }
    if (empty($terms)) {
        return false;
    }
    return $terms;
}
Esempio n. 16
0
 static function get_the_terms_silently($post_id = 0, $taxonomy = '')
 {
     if (empty($post_id)) {
         $post_id = get_the_ID();
     }
     if (empty($post_id) || empty($taxonomy)) {
         return false;
     }
     $terms = get_object_term_cache($post_id, $taxonomy);
     if (false === $terms) {
         $terms = wp_get_object_terms($post_id, $taxonomy);
         if ($terms instanceof WP_Error) {
             return false;
         }
     }
     return get_the_terms($post_id, $taxonomy);
 }
Esempio n. 17
0
 protected function get_object_term($object_id, $taxonomy)
 {
     $term = get_object_term_cache($object_id, $taxonomy);
     if (false === $term) {
         // query language and translations at the same time
         $taxonomies = false !== strpos($taxonomy, 'term_') ? array('term_language', 'term_translations') : array('language', 'post_translations');
         foreach (wp_get_object_terms($object_id, $taxonomies) as $t) {
             wp_cache_add($object_id, array($t), $t->taxonomy . '_relationships');
             // store it the way WP wants it
             if ($t->taxonomy == $taxonomy) {
                 $term = $t;
             }
         }
     } else {
         $term = reset($term);
     }
     return empty($term) ? false : $term;
 }
Esempio n. 18
0
 /**
  * Prepare Bulk Edit field-level updates
  *
  * @since 2.11
  *
  * @param	integer	$post_id Current post ID
  * @param	array	$request Form elements, e.g., from $_REQUEST
  * @param	array	$custom_field_map Form id to field name mapping
  *
  * @return	array	Non-empty form elements
  */
 public static function mla_prepare_bulk_edits($post_id, $request, $custom_field_map)
 {
     /*
      * Copy the edit form contents to $new_data
      * Trim text values for testing purposes only
      */
     $new_data = array();
     if (isset($request['post_title'])) {
         $test_value = self::_process_bulk_value($post_id, $request['post_title']);
         if (!empty($test_value)) {
             $new_data['post_title'] = $test_value;
         } elseif (is_null($test_value)) {
             $new_data['post_title'] = '';
         }
     }
     if (isset($request['post_excerpt'])) {
         $test_value = self::_process_bulk_value($post_id, $request['post_excerpt']);
         if (!empty($test_value)) {
             $new_data['post_excerpt'] = $test_value;
         } elseif (is_null($test_value)) {
             $new_data['post_excerpt'] = '';
         }
     }
     if (isset($request['post_content'])) {
         $test_value = self::_process_bulk_value($post_id, $request['post_content']);
         if (!empty($test_value)) {
             $new_data['post_content'] = $test_value;
         } elseif (is_null($test_value)) {
             $new_data['post_content'] = '';
         }
     }
     /*
      * image_alt requires a separate key because some attachment types
      * should not get a value, e.g., text or PDF documents
      */
     if (isset($request['image_alt'])) {
         $test_value = self::_process_bulk_value($post_id, $request['image_alt']);
         if (!empty($test_value)) {
             $new_data['bulk_image_alt'] = $test_value;
         } elseif (is_null($test_value)) {
             $new_data['bulk_image_alt'] = '';
         }
     }
     if (isset($request['post_parent'])) {
         if (is_numeric($request['post_parent'])) {
             $new_data['post_parent'] = $request['post_parent'];
         }
     }
     if (isset($request['post_author'])) {
         if (-1 != $request['post_author']) {
             $new_data['post_author'] = $request['post_author'];
         }
     }
     if (isset($request['comment_status'])) {
         if (-1 != $request['comment_status']) {
             $new_data['comment_status'] = $request['comment_status'];
         }
     }
     if (isset($request['ping_status'])) {
         if (-1 != $request['ping_status']) {
             $new_data['ping_status'] = $request['ping_status'];
         }
     }
     /*
      * Custom field support
      */
     $custom_fields = array();
     if (is_array($custom_field_map)) {
         foreach ($custom_field_map as $slug => $details) {
             if (isset($request[$slug])) {
                 $test_value = self::_process_bulk_value($post_id, $request[$slug]);
                 if (!empty($test_value)) {
                     $custom_fields[$details['name']] = $test_value;
                 } elseif (is_null($test_value)) {
                     if ($details['no_null']) {
                         $custom_fields[$details['name']] = NULL;
                     } else {
                         $custom_fields[$details['name']] = '';
                     }
                 }
             }
         }
         // foreach
     }
     if (!empty($custom_fields)) {
         $new_data['custom_updates'] = $custom_fields;
     }
     /*
      * Taxonomy Support
      */
     $tax_inputs = array();
     $tax_actions = array();
     self::mla_debug_add("mla_prepare_bulk_edits( {$post_id} ) tax_input = " . var_export($request['tax_input'], true), MLA::MLA_DEBUG_CATEGORY_AJAX);
     if (isset($request['tax_input']) && is_array($request['tax_input'])) {
         foreach ($request['tax_input'] as $taxonomy => $terms) {
             if (!empty($request['tax_action'])) {
                 $tax_action = $request['tax_action'][$taxonomy];
             } else {
                 $tax_action = 'replace';
             }
             self::mla_debug_add("mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) terms = " . var_export($terms, true), MLA::MLA_DEBUG_CATEGORY_AJAX);
             /*
              * Ignore empty updates
              */
             if ($hierarchical = is_array($terms)) {
                 if (false !== ($index = array_search(0, $terms))) {
                     unset($terms[$index]);
                 }
             } else {
                 /*
                  * Parse out individual terms
                  */
                 $comma = _x(',', 'tag_delimiter', 'media-library-assistant');
                 if (',' !== $comma) {
                     $tags = str_replace($comma, ',', $terms);
                 }
                 $fragments = explode(',', trim($terms, " \n\t\r\v,"));
                 $terms = array();
                 foreach ($fragments as $fragment) {
                     // WordPress encodes special characters, e.g., "&" as HTML entities in term names
                     if (MLATest::$wp_3dot5) {
                         $fragment = _wp_specialchars(trim(stripslashes_deep($fragment)));
                     } else {
                         $fragment = _wp_specialchars(trim(wp_unslash($fragment)));
                     }
                     if (!empty($fragment)) {
                         $terms[] = $fragment;
                     }
                 }
                 // foreach fragment
                 $terms = array_unique($terms);
             }
             if (empty($terms) && 'replace' != $tax_action) {
                 continue;
             }
             $post_terms = get_object_term_cache($post_id, $taxonomy);
             if (false === $post_terms) {
                 $post_terms = wp_get_object_terms($post_id, $taxonomy);
                 wp_cache_add($post_id, $post_terms, $taxonomy . '_relationships');
             }
             $current_terms = array();
             foreach ($post_terms as $new_term) {
                 if ($hierarchical) {
                     $current_terms[$new_term->term_id] = $new_term->term_id;
                 } else {
                     $current_terms[$new_term->name] = $new_term->name;
                 }
             }
             self::mla_debug_add("mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) current_terms = " . var_export($current_terms, true), MLA::MLA_DEBUG_CATEGORY_AJAX);
             if ('add' == $tax_action) {
                 /*
                  * Add new terms; remove existing terms
                  */
                 foreach ($terms as $index => $new_term) {
                     if (isset($current_terms[$new_term])) {
                         unset($terms[$index]);
                     }
                 }
                 $do_update = !empty($terms);
             } elseif ('remove' == $tax_action) {
                 /*
                  * Remove only the existing terms
                  */
                 foreach ($terms as $index => $new_term) {
                     if (!isset($current_terms[$new_term])) {
                         unset($terms[$index]);
                     }
                 }
                 $do_update = !empty($terms);
             } else {
                 /*
                  * Replace all terms; if the new terms match the term
                  * cache, we can skip the update
                  */
                 foreach ($terms as $new_term) {
                     if (isset($current_terms[$new_term])) {
                         unset($current_terms[$new_term]);
                     } else {
                         $current_terms[$new_term] = $new_term;
                         break;
                         // not a match; stop checking
                     }
                 }
                 $do_update = !empty($current_terms);
             }
             self::mla_debug_add("mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) do_update = " . var_export($do_update, true), MLA::MLA_DEBUG_CATEGORY_AJAX);
             self::mla_debug_add("mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) new terms = " . var_export($terms, true), MLA::MLA_DEBUG_CATEGORY_AJAX);
             if ($do_update) {
                 $tax_inputs[$taxonomy] = $terms;
                 $tax_actions[$taxonomy] = $tax_action;
             }
         }
         // foreach taxonomy
     }
     $new_data['tax_input'] = $tax_inputs;
     $new_data['tax_action'] = $tax_actions;
     return $new_data;
 }
Esempio n. 19
0
 /**
  * Get a post and associated data in the standard JP format.
  * Cannot be called statically
  *
  * @param int $id Post ID
  * @param bool|array $columns Columns/fields to get.
  * @return Array containing full post details
  */
 function get_post($id, $columns = true)
 {
     $post_obj = get_post($id);
     if (!$post_obj) {
         return false;
     }
     $post = get_object_vars($post_obj);
     // Only send specific columns if requested
     if (is_array($columns)) {
         $keys = array_keys($post);
         foreach ($keys as $column) {
             if (!in_array($column, $columns)) {
                 unset($post[$column]);
             }
         }
         if (in_array('_jetpack_backfill', $columns)) {
             $post['_jetpack_backfill'] = true;
         }
     }
     if (true === $columns || in_array('tax', $columns)) {
         $tax = array();
         $taxonomies = get_object_taxonomies($post_obj);
         foreach ($taxonomies as $taxonomy) {
             $t = get_taxonomy($taxonomy);
             $terms = get_object_term_cache($post_obj->ID, $taxonomy);
             if (empty($terms)) {
                 $terms = wp_get_object_terms($post_obj->ID, $taxonomy);
             }
             $term_names = array();
             foreach ($terms as $term) {
                 $term_names[] = $term->name;
             }
             $tax[$taxonomy] = $term_names;
         }
         $post['tax'] = $tax;
     }
     // Include all postmeta for requests that specifically ask for it, or ask for everything
     if (true == $columns || in_array('meta', $columns)) {
         $meta = get_post_meta($post_obj->ID, false);
         $post['meta'] = array();
         foreach ($meta as $key => $value) {
             $post['meta'][$key] = array_map('maybe_unserialize', $value);
         }
     }
     $post['extra'] = array('author' => get_the_author_meta('display_name', $post_obj->post_author), 'author_email' => get_the_author_meta('email', $post_obj->post_author));
     $post['permalink'] = get_permalink($post_obj->ID);
     return $post;
 }
 /**
  * Get a post and associated data in the standard JP format.
  * Cannot be called statically
  *
  * @param int $id Post ID
  * @return Array containing full post details
  */
 function get_post($id)
 {
     $post_obj = get_post($id);
     if (!$post_obj) {
         return false;
     }
     if (is_callable($post_obj, 'to_array')) {
         // WP >= 3.5
         $post = $post_obj->to_array();
     } else {
         // WP < 3.5
         $post = get_object_vars($post_obj);
     }
     if (0 < strlen($post['post_password'])) {
         $post['post_password'] = '******' . wp_generate_password(10, false);
         // We don't want the real password.  Just pass something random.
     }
     // local optimizations
     unset($post['filter'], $post['ancestors'], $post['post_content_filtered'], $post['to_ping'], $post['pinged']);
     if ($this->is_post_public($post)) {
         $post['post_is_public'] = Jetpack_Options::get_option('public');
     } else {
         //obscure content
         $post['post_content'] = '';
         $post['post_excerpt'] = '';
         $post['post_is_public'] = false;
     }
     $post_type_obj = get_post_type_object($post['post_type']);
     $post['post_is_excluded_from_search'] = $post_type_obj->exclude_from_search;
     $post['tax'] = array();
     $taxonomies = get_object_taxonomies($post_obj);
     foreach ($taxonomies as $taxonomy) {
         $terms = get_object_term_cache($post_obj->ID, $taxonomy);
         if (empty($terms)) {
             $terms = wp_get_object_terms($post_obj->ID, $taxonomy);
         }
         $term_names = array();
         foreach ($terms as $term) {
             $term_names[] = $term->name;
         }
         $post['tax'][$taxonomy] = $term_names;
     }
     $meta = get_post_meta($post_obj->ID, false);
     $post['meta'] = array();
     foreach ($meta as $key => $value) {
         $post['meta'][$key] = array_map('maybe_unserialize', $value);
     }
     $post['extra'] = array('author' => get_the_author_meta('display_name', $post_obj->post_author), 'author_email' => get_the_author_meta('email', $post_obj->post_author), 'dont_email_post_to_subs' => get_post_meta($post_obj->ID, '_jetpack_dont_email_post_to_subs', true));
     if ($fid = get_post_thumbnail_id($id)) {
         $feature = wp_get_attachment_image_src($fid, 'large');
         if (!empty($feature[0])) {
             $post['extra']['featured_image'] = $feature[0];
         }
         $attachment = get_post($fid);
         if (!empty($attachment)) {
             $metadata = wp_get_attachment_metadata($fid);
             $post['extra']['post_thumbnail'] = array('ID' => (int) $fid, 'URL' => (string) wp_get_attachment_url($fid), 'guid' => (string) $attachment->guid, 'mime_type' => (string) $attachment->post_mime_type, 'width' => (int) isset($metadata['width']) ? $metadata['width'] : 0, 'height' => (int) isset($metadata['height']) ? $metadata['height'] : 0);
             if (isset($metadata['duration'])) {
                 $post['extra']['post_thumbnail'] = (int) $metadata['duration'];
             }
             /**
              * Filters the Post Thumbnail information returned for a specific post.
              *
              * @since 3.3.0
              *
              * @param array $post['extra']['post_thumbnail'] {
              * 	Array of details about the Post Thumbnail.
              *	@param int ID Post Thumbnail ID.
              *	@param string URL Post thumbnail URL.
              *	@param string guid Post thumbnail guid.
              *	@param string mime_type Post thumbnail mime type.
              *	@param int width Post thumbnail width.
              *	@param int height Post thumbnail height.
              * }
              */
             $post['extra']['post_thumbnail'] = (object) apply_filters('get_attachment', $post['extra']['post_thumbnail']);
         }
     }
     $post['permalink'] = get_permalink($post_obj->ID);
     $post['shortlink'] = wp_get_shortlink($post_obj->ID);
     /**
      * Allow modules to send extra info on the sync post process.
      *
      * @since 2.8.0
      *
      * @param array $args Array of custom data to attach to a post.
      * @param Object $post_obj Object returned by get_post() for a given post ID.
      */
     $post['module_custom_data'] = apply_filters('jetpack_sync_post_module_custom_data', array(), $post_obj);
     return $post;
 }
function get_the_taxonomies($post = 0) {
	if ( is_int($post) )
		$post =& get_post($post);
	elseif ( !is_object($post) )
		$post =& $GLOBALS['post'];

	$taxonomies = array();

	if ( !$post )
		return $taxonomies;

	$template = apply_filters('taxonomy_template', '%s: %l.');

	foreach ( get_object_taxonomies($post) as $taxonomy ) {
		$t = (array) get_taxonomy($taxonomy);
		if ( empty($t['label']) )
			$t['label'] = $taxonomy;
		if ( empty($t['args']) )
			$t['args'] = array();
		if ( empty($t['template']) )
			$t['template'] = $template;

		$terms = get_object_term_cache($post->ID, $taxonomy);
		if ( empty($terms) )
			$terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);

		$links = array();

		foreach ( $terms as $term )
			$links[] = "<a href='" . attribute_escape(get_term_link($term, $taxonomy)) . "'>$term->name</a>";

		if ( $links )
			$taxonomies[$taxonomy] = wp_sprintf($t['template'], $t['label'], $links, $terms);
	}
	return $taxonomies;
}
 function wpuxss_eml_attachment_fields_to_edit($form_fields, $post)
 {
     $wpuxss_eml_tax_options = get_option('wpuxss_eml_tax_options');
     foreach (get_attachment_taxonomies($post) as $taxonomy) {
         $t = (array) get_taxonomy($taxonomy);
         if (!$t['show_ui']) {
             continue;
         }
         if (empty($t['label'])) {
             $t['label'] = $taxonomy;
         }
         if (empty($t['args'])) {
             $t['args'] = array();
         }
         $terms = get_object_term_cache($post->ID, $taxonomy);
         if (false === $terms) {
             $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
         }
         $values = array();
         foreach ($terms as $term) {
             $values[] = $term->slug;
         }
         $t['value'] = join(', ', $values);
         $t['show_in_edit'] = false;
         if (($wpuxss_eml_tax_options['edit_all_as_hierarchical'] || $t['hierarchical']) && function_exists('wp_terms_checklist')) {
             ob_start();
             wp_terms_checklist($post->ID, array('taxonomy' => $taxonomy, 'checked_ontop' => false, 'walker' => new Walker_Media_Taxonomy_Checklist()));
             if (ob_get_contents() != false) {
                 $html = '<ul class="term-list">' . ob_get_contents() . '</ul>';
             } else {
                 $html = '<ul class="term-list"><li>No ' . $t['label'] . ' found.</li></ul>';
             }
             ob_end_clean();
             unset($t['value']);
             $t['input'] = 'html';
             $t['html'] = $html;
         }
         $form_fields[$taxonomy] = $t;
     }
     return $form_fields;
 }
Esempio n. 23
0
function get_attachment_fields_to_edit($post, $errors = null)
{
    if (is_int($post)) {
        $post =& get_post($post);
    }
    if (is_array($post)) {
        $post = (object) $post;
    }
    $edit_post = sanitize_post($post, 'edit');
    $file = wp_get_attachment_url($post->ID);
    $link = get_attachment_link($post->ID);
    $form_fields = array('post_title' => array('label' => __('Title'), 'value' => $edit_post->post_title), 'post_excerpt' => array('label' => __('Caption'), 'value' => $edit_post->post_excerpt), 'post_content' => array('label' => __('Description'), 'value' => $edit_post->post_content, 'input' => 'textarea'), 'url' => array('label' => __('Link URL'), 'input' => 'html', 'html' => "\n\t\t\t\t<input type='text' name='attachments[{$post->ID}][url]' value='" . attribute_escape($file) . "' /><br />\n\t\t\t\t<button type='button' class='button url-{$post->ID}' value=''>" . __('None') . "</button>\n\t\t\t\t<button type='button' class='button url-{$post->ID}' value='" . attribute_escape($file) . "'>" . __('File URL') . "</button>\n\t\t\t\t<button type='button' class='button url-{$post->ID}' value='" . attribute_escape($link) . "'>" . __('Post URL') . "</button>\n\t\t\t\t<script type='text/javascript'>\n\t\t\t\tjQuery('button.url-{$post->ID}').bind('click', function(){jQuery(this).siblings('input').val(this.value);});\n\t\t\t\t</script>\n", 'helps' => __('Enter a link URL or click above for presets.')));
    foreach (get_attachment_taxonomies($post) as $taxonomy) {
        $t = (array) get_taxonomy($taxonomy);
        if (empty($t['label'])) {
            $t['label'] = $taxonomy;
        }
        if (empty($t['args'])) {
            $t['args'] = array();
        }
        $terms = get_object_term_cache($post->ID, $taxonomy);
        if (empty($terms)) {
            $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
        }
        $values = array();
        foreach ($terms as $term) {
            $values[] = $term->name;
        }
        $t['value'] = join(', ', $values);
        $form_fields[$taxonomy] = $t;
    }
    // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
    // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing )
    $form_fields = array_merge_recursive($form_fields, (array) $errors);
    $form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post);
    return $form_fields;
}
Esempio n. 24
0
/**
 * Determine if the given object is associated with any of the given terms.
 *
 * The given terms are checked against the object's terms' term_ids, names and slugs.
 * Terms given as integers will only be checked against the object's terms' term_ids.
 * If no terms are given, determines if object is associated with any terms in the given taxonomy.
 *
 * @since 2.7.0
 * @uses get_object_term_cache()
 * @uses wp_get_object_terms()
 *
 * @param int $object_id.  ID of the object (post ID, link ID, ...)
 * @param string $taxonomy.  Single taxonomy name
 * @param int|string|array $terms Optional.  Term term_id, name, slug or array of said
 * @return bool|WP_Error. WP_Error on input error.
 */
function is_object_in_term($object_id, $taxonomy, $terms = null)
{
    if (!($object_id = (int) $object_id)) {
        return new WP_Error('invalid_object', __('Invalid object ID'));
    }
    $object_terms = get_object_term_cache($object_id, $taxonomy);
    if (empty($object_terms)) {
        $object_terms = wp_get_object_terms($object_id, $taxonomy);
    }
    if (is_wp_error($object_terms)) {
        return $object_terms;
    }
    if (empty($object_terms)) {
        return false;
    }
    if (empty($terms)) {
        return !empty($object_terms);
    }
    $terms = (array) $terms;
    if ($ints = array_filter($terms, 'is_int')) {
        $strs = array_diff($terms, $ints);
    } else {
        $strs =& $terms;
    }
    foreach ($object_terms as $object_term) {
        if ($ints && in_array($object_term->term_id, $ints)) {
            return true;
        }
        // If int, check against term_id
        if ($strs) {
            if (in_array($object_term->term_id, $strs)) {
                return true;
            }
            if (in_array($object_term->name, $strs)) {
                return true;
            }
            if (in_array($object_term->slug, $strs)) {
                return true;
            }
        }
    }
    return false;
}
/**
 * Retrieve the terms of the taxonomy that are attached to the post.
 *
 * @since 2.5.0
 *
 * @param int|object $post Post ID or object.
 * @param string $taxonomy Taxonomy name.
 * @return array|false|WP_Error Array of WP_Term objects on success, false if there are no terms
 *                              or the post does not exist, WP_Error on failure.
 */
function get_the_terms($post, $taxonomy)
{
    if (!($post = get_post($post))) {
        return false;
    }
    $terms = get_object_term_cache($post->ID, $taxonomy);
    if (false === $terms) {
        $terms = wp_get_object_terms($post->ID, $taxonomy);
        if (!is_wp_error($terms)) {
            $term_ids = wp_list_pluck($terms, 'term_id');
            wp_cache_add($post->ID, $term_ids, $taxonomy . '_relationships');
        }
    }
    /**
     * Filters the list of terms attached to the given post.
     *
     * @since 3.1.0
     *
     * @param array|WP_Error $terms    List of attached terms, or WP_Error on failure.
     * @param int            $post_id  Post ID.
     * @param string         $taxonomy Name of the taxonomy.
     */
    $terms = apply_filters('get_the_terms', $terms, $post->ID, $taxonomy);
    if (empty($terms)) {
        return false;
    }
    return $terms;
}
/**
 * Retrieve the terms of the taxonomy that are attached to the post.
 *
 * @since 2.5.0
 *
 * @param int $id Post ID.
 * @param string $taxonomy Taxonomy name.
 * @return array|bool False on failure. Array of term objects on success.
 */
function get_the_terms($id, $taxonomy)
{
    global $post;
    $id = (int) $id;
    if (!$id) {
        if (empty($post->ID)) {
            return false;
        } else {
            $id = (int) $post->ID;
        }
    }
    $terms = get_object_term_cache($id, $taxonomy);
    if (false === $terms) {
        $terms = wp_get_object_terms($id, $taxonomy);
        wp_cache_add($id, $terms, $taxonomy . '_relationships');
    }
    $terms = apply_filters('get_the_terms', $terms, $id, $taxonomy);
    if (empty($terms)) {
        return false;
    }
    return $terms;
}
Esempio n. 27
0
function get_compat_media_markup($attachment_id, $args = null)
{
    $post = get_post($attachment_id);
    $default_args = array('errors' => null, 'in_modal' => false);
    $user_can_edit = current_user_can('edit_post', $attachment_id);
    $args = wp_parse_args($args, $default_args);
    /** This filter is documented in wp-admin/includes/media.php */
    $args = apply_filters('get_media_item_args', $args);
    $form_fields = array();
    if ($args['in_modal']) {
        foreach (get_attachment_taxonomies($post) as $taxonomy) {
            $t = (array) get_taxonomy($taxonomy);
            if (!$t['public'] || !$t['show_ui']) {
                continue;
            }
            if (empty($t['label'])) {
                $t['label'] = $taxonomy;
            }
            if (empty($t['args'])) {
                $t['args'] = array();
            }
            $terms = get_object_term_cache($post->ID, $taxonomy);
            if (false === $terms) {
                $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
            }
            $values = array();
            foreach ($terms as $term) {
                $values[] = $term->slug;
            }
            $t['value'] = join(', ', $values);
            $t['taxonomy'] = true;
            $form_fields[$taxonomy] = $t;
        }
    }
    // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
    // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing )
    $form_fields = array_merge_recursive($form_fields, (array) $args['errors']);
    /** This filter is documented in wp-admin/includes/media.php */
    $form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post);
    unset($form_fields['image-size'], $form_fields['align'], $form_fields['image_alt'], $form_fields['post_title'], $form_fields['post_excerpt'], $form_fields['post_content'], $form_fields['url'], $form_fields['menu_order'], $form_fields['image_url']);
    /** This filter is documented in wp-admin/includes/media.php */
    $media_meta = apply_filters('media_meta', '', $post);
    $defaults = array('input' => 'text', 'required' => false, 'value' => '', 'extra_rows' => array(), 'show_in_edit' => true, 'show_in_modal' => true);
    $hidden_fields = array();
    $item = '';
    foreach ($form_fields as $id => $field) {
        if ($id[0] == '_') {
            continue;
        }
        $name = "attachments[{$attachment_id}][{$id}]";
        $id_attr = "attachments-{$attachment_id}-{$id}";
        if (!empty($field['tr'])) {
            $item .= $field['tr'];
            continue;
        }
        $field = array_merge($defaults, $field);
        if (!$field['show_in_edit'] && !$args['in_modal'] || !$field['show_in_modal'] && $args['in_modal']) {
            continue;
        }
        if ($field['input'] == 'hidden') {
            $hidden_fields[$name] = $field['value'];
            continue;
        }
        $readonly = !$user_can_edit && !empty($field['taxonomy']) ? " readonly='readonly' " : '';
        $required = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : '';
        $aria_required = $field['required'] ? " aria-required='true' " : '';
        $class = 'compat-field-' . $id;
        $class .= $field['required'] ? ' form-required' : '';
        $item .= "\t\t<tr class='{$class}'>";
        $item .= "\t\t\t<th scope='row' class='label'><label for='{$id_attr}'><span class='alignleft'>{$field['label']}</span>{$required}<br class='clear' /></label>";
        $item .= "</th>\n\t\t\t<td class='field'>";
        if (!empty($field[$field['input']])) {
            $item .= $field[$field['input']];
        } elseif ($field['input'] == 'textarea') {
            if ('post_content' == $id && user_can_richedit()) {
                // sanitize_post() skips the post_content when user_can_richedit.
                $field['value'] = htmlspecialchars($field['value'], ENT_QUOTES);
            }
            $item .= "<textarea id='{$id_attr}' name='{$name}' {$aria_required}>" . $field['value'] . '</textarea>';
        } else {
            $item .= "<input type='text' class='text' id='{$id_attr}' name='{$name}' value='" . esc_attr($field['value']) . "' {$readonly} {$aria_required} />";
        }
        if (!empty($field['helps'])) {
            $item .= "<p class='help'>" . join("</p>\n<p class='help'>", array_unique((array) $field['helps'])) . '</p>';
        }
        $item .= "</td>\n\t\t</tr>\n";
        $extra_rows = array();
        if (!empty($field['errors'])) {
            foreach (array_unique((array) $field['errors']) as $error) {
                $extra_rows['error'][] = $error;
            }
        }
        if (!empty($field['extra_rows'])) {
            foreach ($field['extra_rows'] as $class => $rows) {
                foreach ((array) $rows as $html) {
                    $extra_rows[$class][] = $html;
                }
            }
        }
        foreach ($extra_rows as $class => $rows) {
            foreach ($rows as $html) {
                $item .= "\t\t<tr><td></td><td class='{$class}'>{$html}</td></tr>\n";
            }
        }
    }
    if (!empty($form_fields['_final'])) {
        $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
    }
    if ($item) {
        $item = '<table class="compat-attachment-fields">' . $item . '</table>';
    }
    foreach ($hidden_fields as $hidden_field => $value) {
        $item .= '<input type="hidden" name="' . esc_attr($hidden_field) . '" value="' . esc_attr($value) . '" />' . "\n";
    }
    if ($item) {
        $item = '<input type="hidden" name="attachments[' . $attachment_id . '][menu_order]" value="' . esc_attr($post->menu_order) . '" />' . $item;
    }
    return array('item' => $item, 'meta' => $media_meta);
}
/**
 * in_series() - will check if the current post is in a given series OR if the post is in ANY series (when series ID isn't provided. Works similarily to in_category()
 * Needs to be in the loop.
 *
 * @package Organize Series WordPress Plugin
 * @since 2.0
 *
 * @uses get_object_term_cache() - pulls info from the wp_cache if there.
 * @uses wp_get_object_terms() - gets the series the post belongs to if the post belongs to a series.
 * @uses get_series_ID() - gets the ID of the series if the param supplied is the name - else the series_term is an id already.
 * @uses array_key_exists()
 *
 * @param string|int $series_term Can be the series_id or the series name.
 *
 * @return bool true if the post is in the supplied series.
*/
function in_series($series_term = 0)
{
    //check if the current post is in the given series
    global $post;
    if ($series_term == 0 && empty($post->ID)) {
        return false;
    }
    if ($series_term == 0) {
        // we're just checking if the post is in ANY series
        $check_any = true;
    }
    $ser_ID = get_series_ID($series_term);
    if ($ser_ID) {
        $series_term = $ser_ID;
    }
    $series = get_object_term_cache($post->ID, 'series');
    if (false === $series) {
        $series = wp_get_object_terms($post->ID, 'series');
    }
    if ($check_any) {
        if ($series) {
            return true;
        } else {
            return false;
        }
    }
    if (array_key_exists($series_term, $series)) {
        return true;
    } else {
        return false;
    }
}
 /**
  * Get a post and associated data in the standard JP format.
  * Cannot be called statically
  *
  * @param int $id Post ID
  * @return Array containing full post details
  */
 function get_post($id)
 {
     $post_obj = get_post($id);
     if (!$post_obj) {
         return false;
     }
     if (is_callable($post_obj, 'to_array')) {
         // WP >= 3.5
         $post = $post_obj->to_array();
     } else {
         // WP < 3.5
         $post = get_object_vars($post_obj);
     }
     if (0 < strlen($post['post_password'])) {
         $post['post_password'] = '******' . wp_generate_password(10, false);
         // We don't want the real password.  Just pass something random.
     }
     // local optimizations
     unset($post['filter'], $post['ancestors'], $post['post_content_filtered'], $post['to_ping'], $post['pinged']);
     if ($this->is_post_public($post)) {
         $post['post_is_public'] = Jetpack::get_option('public');
     } else {
         //obscure content
         $post['post_content'] = '';
         $post['post_excerpt'] = '';
         $post['post_is_public'] = false;
     }
     $post_type_obj = get_post_type_object($post['post_type']);
     $post['post_is_excluded_from_search'] = $post_type_obj->exclude_from_search;
     $post['tax'] = array();
     $taxonomies = get_object_taxonomies($post_obj);
     foreach ($taxonomies as $taxonomy) {
         $terms = get_object_term_cache($post_obj->ID, $taxonomy);
         if (empty($terms)) {
             $terms = wp_get_object_terms($post_obj->ID, $taxonomy);
         }
         $term_names = array();
         foreach ($terms as $term) {
             $term_names[] = $term->name;
         }
         $post['tax'][$taxonomy] = $term_names;
     }
     $meta = get_post_meta($post_obj->ID, false);
     $post['meta'] = array();
     foreach ($meta as $key => $value) {
         $post['meta'][$key] = array_map('maybe_unserialize', $value);
     }
     $post['extra'] = array('author' => get_the_author_meta('display_name', $post_obj->post_author), 'author_email' => get_the_author_meta('email', $post_obj->post_author));
     if ($fid = get_post_thumbnail_id($id)) {
         $feature = wp_get_attachment_image_src($fid, 'large');
         if (!empty($feature[0])) {
             $post['extra']['featured_image'] = $feature[0];
         }
     }
     $post['permalink'] = get_permalink($post_obj->ID);
     $post['shortlink'] = wp_get_shortlink($post_obj->ID);
     return $post;
 }
Esempio n. 30
0
/**
 * Queue posts for lazyloading of term meta.
 *
 * @since 4.5.0
 *
 * @param array $posts Array of WP_Post objects.
 */
function wp_queue_posts_for_term_meta_lazyload($posts)
{
    $post_type_taxonomies = $term_ids = array();
    foreach ($posts as $post) {
        if (!$post instanceof WP_Post) {
            continue;
        }
        if (!isset($post_type_taxonomies[$post->post_type])) {
            $post_type_taxonomies[$post->post_type] = get_object_taxonomies($post->post_type);
        }
        foreach ($post_type_taxonomies[$post->post_type] as $taxonomy) {
            // Term cache should already be primed by `update_post_term_cache()`.
            $terms = get_object_term_cache($post->ID, $taxonomy);
            if (false !== $terms) {
                foreach ($terms as $term) {
                    if (!isset($term_ids[$term->term_id])) {
                        $term_ids[] = $term->term_id;
                    }
                }
            }
        }
    }
    if ($term_ids) {
        $lazyloader = wp_metadata_lazyloader();
        $lazyloader->queue_objects('term', $term_ids);
    }
}