Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Featured media fixes #1408

Merged
merged 2 commits into from
Mar 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions inc/featured-media.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ function largo_get_featured_media( $post = null ) {

$post = get_post( $post );

// make sure we actually have a valid post object before we try to get post meta
if ( ! is_object( $post ) ) {
return;
}

$ret = get_post_meta( $post->ID, 'featured_media', true );

// Check if the post has a thumbnail/featured image set.
Expand Down Expand Up @@ -266,13 +271,18 @@ function largo_enqueue_featured_media_js( $hook ) {
// Run this action on term edit pages
// edit-tags.php for wordpress before 4.5
// term.php for 4.5 and after
if ( in_array( $hook, array( 'edit-tags.php', 'term.php' ) ) && is_numeric( $_GET['tag_ID'] ) ) {
if ( in_array( $hook, array( 'edit-tags.php', 'term.php' ) ) && isset( $_GET['tag_ID'] ) && is_numeric( $_GET['tag_ID'] ) ) {
// After WordPress 4.5, the taxonomy is no longer in the URL
// So to compensate, we get the taxonomy from the current screen
$screen = get_current_screen();
$post = get_post( largo_get_term_meta_post( $screen->taxonomy, $_GET['tag_ID'] ) );
}

// make sure we actually have a valid post object before we try to get post meta
if ( ! is_object( $post ) ) {
return;
}

$featured_image_display = get_post_meta( $post->ID, 'featured-image-display', true );

// The scripts following depend upon the WordPress media APIs
Expand Down Expand Up @@ -454,7 +464,7 @@ function largo_featured_image_metabox_callback( $post, $metabox ) {

$checked = 'false' == get_post_meta( $post->ID, 'featured-image-display', true ) ? 'checked="checked"' : "";
echo wp_nonce_field( basename( __FILE__ ), 'featured_image_display_nonce' );

echo '<a href="#" class="set-featured-media">' . get_the_post_thumbnail() . '</a>';
echo '<a href="#" id="set-featured-media-button" class="button set-featured-media add_media" data-editor="content" title="' . __( $language . ' Featured Media', 'largo' ) . '"></span> ' . __( $language . ' Featured Media', 'largo' ) . '</a> <span class="spinner" style="display: none;"></span>';

Expand Down Expand Up @@ -707,7 +717,7 @@ function largo_content_partial_arguments_filter( $args, $queried_object ) {
* 'right_region' => 'sidebar-main',
* 'per_page' => '10',
* 'post_order' => 'DESC',
* 'show' =>
* 'show' =>
* array (
* 'image' => false,
* 'excerpt' => false,
Expand Down
117 changes: 59 additions & 58 deletions js/featured-media.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var LFM = _.extend(LFM || {}, {

// Make sure we tell the backend what post ID we're dealing with.
data = _.extend(data, { id: LFM.Utils.getPostId() });

var action;
if (method == 'read')
action = 'largo_featured_media_read';
Expand Down Expand Up @@ -79,70 +79,71 @@ var LFM = _.extend(LFM || {}, {

createStates: function() {
var options = this.options,
embed = [
// Embed code
new wp.media.controller.Embed({
title: largo_featured_media_vars.embed_title,
id: 'embed-code',
content: 'embed',
priority: 0
}),
],
video = [
// Video embed
new wp.media.controller.Embed({
title: largo_featured_media_vars.video_title,
id: 'video',
content: 'video',
priority: 10
}),
],
image = [
// Featured image
new wp.media.controller.FeaturedImage({
title: largo_featured_media_vars.image_title,
priority: 20,
id: 'image',
}),

new wp.media.controller.EditImage({ model: options.editImage })
],
gallery = [
// Featured gallery
new wp.media.controller.Library({
id: 'gallery',
title: largo_featured_media_vars.gallery_title,
priority: 30,
toolbar: 'main-gallery',
filterable: 'uploaded',
multiple: 'add',
editable: false,
library: wp.media.query(_.defaults({
type: 'image'
}, options.library))
}),

// Gallery states.
new wp.media.controller.GalleryEdit({
library: options.selection,
editing: options.editing,
menu: 'gallery'
}),

new wp.media.controller.GalleryAdd()
];
if (_.indexOf(options.states, 'embed-code') >= 0)
this.states.add(embed);

if (_.indexOf(options.states, 'video') >= 0)
this.states.add(video);
image = [
// Featured image
new wp.media.controller.FeaturedImage({
title: largo_featured_media_vars.image_title,
id: 'image',
priority: 10
}),

new wp.media.controller.EditImage({ model: options.editImage })
],
gallery = [
// Featured gallery
new wp.media.controller.Library({
title: largo_featured_media_vars.gallery_title,
id: 'gallery',
priority: 20,
toolbar: 'main-gallery',
filterable: 'uploaded',
multiple: 'add',
editable: false,
library: wp.media.query(_.defaults({
type: 'image'
}, options.library))
}),

// Gallery states.
new wp.media.controller.GalleryEdit({
library: options.selection,
editing: options.editing,
menu: 'gallery'
}),

new wp.media.controller.GalleryAdd()
],
video = [
// Video embed
new wp.media.controller.Embed({
title: largo_featured_media_vars.video_title,
id: 'video',
priority: 30,
content: 'video'
}),
],
embed = [
// Embed code
new wp.media.controller.Embed({
title: largo_featured_media_vars.embed_title,
id: 'embed-code',
priority: 40,
content: 'embed'
}),
];

if (_.indexOf(options.states, 'image') >= 0 )
this.states.add(image);

if (_.indexOf(options.states, 'gallery') >= 0)
this.states.add(gallery);

if (_.indexOf(options.states, 'video') >= 0)
this.states.add(video);

if (_.indexOf(options.states, 'embed-code') >= 0)
this.states.add(embed);

if (LFM.has_featured_media) {
this.states.add([
new LFM.Controller.removeFeaturedMedia()
Expand Down
Loading