Ejemplo n.º 1
0
/**
 * Add the "Set Featured Media" button in the term edit page
 *
 * @since 0.5.4
 * @see largo_term_featured_media_enqueue_post_editor
 */
function largo_add_term_featured_media_button($context = '')
{
    // Post ID here is the id of the post that Largo uses to keep track of the term's metadata. See largo_get_term_meta_post.
    $post_id = largo_get_term_meta_post($context->taxonomy, $context->term_id);
    $has_featured_media = largo_has_featured_media($post_id);
    $language = !empty($has_featured_media) ? 'Edit' : 'Set';
    $featured = largo_get_featured_media($post_id);
    ?>
	<tr class="form-field">
		<th scope="row" valign="top"><?php 
    _e('Term banner image', 'largo');
    ?>
</th>
		<td>
			<p><a href="#" id="set-featured-media-button" class="button set-featured-media add_media" data-editor="content" title="<?php 
    echo $language;
    ?>
 Featured Media"><span class="dashicons dashicons-admin-generic"></span> <?php 
    echo $language;
    ?>
 Featured Media</a> <span class="spinner" style="display: none;"></span></p>
			<p class="description">This image will be displayed on the top of the term's archive page.</p>
			<input type="hidden" id="post_ID" value="<?php 
    echo $post_id;
    ?>
" />
			<input type="hidden" id="featured_image_id" value="<?php 
    echo $featured['attachment'];
    ?>
" />

			<?php 
    # echo get_the_post_thumbnail($post_id);
    ?>
		</td>
	</tr>
	<?php 
}
Ejemplo n.º 2
0
 function test_largo_get_featured_media()
 {
     update_post_meta($this->post, 'featured_media', $this->media_types['image']);
     $featured_media = largo_get_featured_media($this->post);
     $this->assertEquals($featured_media, $this->media_types['image']);
 }
Ejemplo n.º 3
0
/**
 * Read the `featured_media` meta for a given post. Expects array $_POST['data']
 * with an `id` key corresponding to post ID to look up.
 */
function largo_featured_media_read()
{
    if (!empty($_POST['data'])) {
        $data = json_decode(stripslashes($_POST['data']), true);
        $ret = largo_get_featured_media($data['id']);
        // Otherwise, check for `featured_media` post meta
        if (!empty($ret)) {
            print json_encode($ret);
            wp_die();
        }
        // No featured thumbnail and not `featured_media`, so just return
        // an array with the post ID
        print json_encode(array('id' => $data['id']));
        wp_die();
    }
}
Ejemplo n.º 4
0
 function largo_hero_class($post_id, $echo = TRUE)
 {
     $hero_class = "is-empty";
     $featured_media = largo_has_featured_media($post_id) ? largo_get_featured_media($post_id) : array();
     $type = isset($featured_media['type']) ? $featured_media['type'] : false;
     if (get_post_meta($post_id, 'youtube_url', true) || $type == 'video') {
         $hero_class = 'is-video';
     } else {
         if (has_post_thumbnail($post_id) || $type == 'image') {
             $hero_class = 'is-image';
         } else {
             if ($type == 'gallery') {
                 $hero_class = 'is-gallery';
             } else {
                 if ($type == 'embed-code') {
                     $hero_class = 'is-embed';
                 }
             }
         }
     }
     if ($echo) {
         echo $hero_class;
     } else {
         return $hero_class;
     }
 }
Ejemplo n.º 5
0
/**
 * Add post classes to indicate whether a post has featured media and what type it is
 *
 * @since 0.5.2
 */
function largo_featured_media_post_classes($classes)
{
    global $post;
    $featured = largo_get_featured_media($post->ID);
    if (!empty($featured)) {
        $classes = array_merge($classes, array('featured-media', 'featured-media-' . $featured['type']));
    }
    return $classes;
}