function test_largo_has_featured_media() { // If the post doesn't have featured media set, `largo_has_featured_media` should return false $has_featured_media = largo_has_featured_media($this->post); $this->assertTrue(!$has_featured_media); // If the post does have featured media set, `largo_has_featured_media` should return true update_post_meta($this->post, 'featured_media', $this->media_types['image']); $has_featured_media = largo_has_featured_media($this->post); $this->assertTrue($has_featured_media); }
/** * 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 }
/** * Adds the "Set Featured Media" button above the post editor */ function largo_add_featured_media_button($context) { global $post; $has_featured_media = largo_has_featured_media($post->ID); $language = !empty($has_featured_media) ? 'Edit' : 'Set'; ob_start(); ?> <a href="#" id="set-featured-media-button" class="button set-featured-media add_media" data-editor="content" title="<?php echo $language; ?> Featured Media"><?php echo $language; ?> Featured Media</a> <span class="spinner"></span> <?php $context .= ob_get_contents(); ob_end_clean(); return $context; }
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; } }