From 30ed2a1559c14b7579ca30b31413804ff7e9d8cb Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Fri, 9 Nov 2018 20:04:35 -0500 Subject: [PATCH 1/2] wip --- image.php | 1 + inc/avatars.php | 14 ++++++++------ inc/enqueue.php | 4 ++-- inc/widgets/largo-author-bio.php | 9 +++++++-- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/image.php b/image.php index 5e14919b6..9daf8de30 100644 --- a/image.php +++ b/image.php @@ -5,6 +5,7 @@ * @package Largo */ +add_action( 'wp_enqueue_scripts', 'largo_gallery_enqueue' ); get_header(); ?>
diff --git a/inc/avatars.php b/inc/avatars.php index 88769241e..78a9a44f4 100644 --- a/inc/avatars.php +++ b/inc/avatars.php @@ -40,13 +40,15 @@ function largo_has_gravatar( $email ) { */ function largo_has_avatar( $email ) { $user = get_user_by( 'email', $email ); - $result = largo_get_user_avatar_id( $user->ID ); - if ( ! empty ( $result ) ) { - return true; - } else { - if ( largo_has_gravatar( $email ) ) { + if ( ! empty( $user ) ) { + $result = largo_get_user_avatar_id( $user->ID ); + if ( ! empty ( $result ) ) { return true; - } + } else { + if ( largo_has_gravatar( $email ) ) { + return true; + } + } } return false; } diff --git a/inc/enqueue.php b/inc/enqueue.php index abe8a7082..a86a33081 100644 --- a/inc/enqueue.php +++ b/inc/enqueue.php @@ -86,13 +86,13 @@ function largo_enqueue_js() { */ function largo_gallery_enqueue() { $slick_css = get_template_directory_uri() . '/lib/navis-slideshows/vendor/slick/slick.css'; - wp_enqueue_style( 'navis-slick', $slick_css, array(), '1.0' ); + wp_enqueue_style( 'navis-slick', $slick_css, array(), '1.0', true ); $slides_src = get_template_directory_uri() . '/lib/navis-slideshows/vendor/slick/slick.min.js'; wp_enqueue_script( 'jquery-slick', $slides_src, array( 'jquery' ), '3.0', true ); $slides_css = get_template_directory_uri() . '/lib/navis-slideshows/css/slides.css'; - wp_enqueue_style( 'navis-slides', $slides_css, array(), '1.0' ); + wp_enqueue_style( 'navis-slides', $slides_css, array(), '1.0', true ); $show_src = get_template_directory_uri() . '/lib/navis-slideshows/js/navis-slideshows.js'; wp_enqueue_script( 'navis-slideshows', $show_src, array( 'jquery-slick' ), '0.11', true ); diff --git a/inc/widgets/largo-author-bio.php b/inc/widgets/largo-author-bio.php index 5cac8bb51..65f7e0236 100644 --- a/inc/widgets/largo-author-bio.php +++ b/inc/widgets/largo-author-bio.php @@ -48,8 +48,13 @@ function widget( $args, $instance ) { // make sure we have at least one bio before we show the widget foreach ( $authors as $key => $author ) { - $bio = trim( $author->description ); - if ( !is_author() && empty( $bio ) ) { + if ( is_object( $author ) && isset( $author->description ) ) { + $bio = trim( $author->description ); + } else { + $bio = ''; + } + + if ( ! is_author() && empty( $bio ) ) { unset( $authors[$key] ); } else { $bios .= $bio; From 74b75d17fa76377ed760be62d29929ccda65adc5 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Fri, 9 Nov 2018 20:17:23 -0500 Subject: [PATCH 2/2] Attempt at conditionally enqueueing slideshow assets --- image.php | 9 ++++++--- inc/enqueue.php | 1 - lib/navis-slideshows/navis-slideshows.php | 8 +++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/image.php b/image.php index 9daf8de30..97dbf205a 100644 --- a/image.php +++ b/image.php @@ -5,7 +5,6 @@ * @package Largo */ -add_action( 'wp_enqueue_scripts', 'largo_gallery_enqueue' ); get_header(); ?>
@@ -49,15 +48,19 @@ if ( $attachment->ID == $post->ID ) break; } + $k++; + // If there is more than 1 attachment in a gallery if ( count( $attachments ) > 1 ) { - if ( isset( $attachments[ $k ] ) ) + largo_gallery_enqueue(); + if ( isset( $attachments[ $k ] ) ) { // get the URL of the next image attachment $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID ); - else + } else { // or get the URL of the first image attachment $next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID ); + } } else { // or, if there's only 1 image, get the URL of the image $next_attachment_url = wp_get_attachment_url(); diff --git a/inc/enqueue.php b/inc/enqueue.php index a86a33081..7abc257bf 100644 --- a/inc/enqueue.php +++ b/inc/enqueue.php @@ -97,7 +97,6 @@ function largo_gallery_enqueue() { $show_src = get_template_directory_uri() . '/lib/navis-slideshows/js/navis-slideshows.js'; wp_enqueue_script( 'navis-slideshows', $show_src, array( 'jquery-slick' ), '0.11', true ); } - add_action( 'wp_enqueue_scripts', 'largo_gallery_enqueue' ); } if ( ! function_exists( 'largo_enqueue_child_theme_css' ) ) { diff --git a/lib/navis-slideshows/navis-slideshows.php b/lib/navis-slideshows/navis-slideshows.php index 4a7d088cb..3751b48c7 100644 --- a/lib/navis-slideshows/navis-slideshows.php +++ b/lib/navis-slideshows/navis-slideshows.php @@ -38,16 +38,18 @@ function __construct() { if ( ! is_admin() ) return; - add_action('save_post', array( &$this, 'tag_post_as_slideshow' ), 10, 2); - remove_shortcode('gallery'); - add_shortcode('gallery', array(&$this, 'handle_slideshow'), 10, 2); + add_action( 'save_post', array( &$this, 'tag_post_as_slideshow' ), 10, 2); + remove_shortcode( 'gallery' ); + add_shortcode( 'gallery', array( &$this, 'handle_slideshow' ), 10, 2); } /** * * @uses global $post WP Post object + * @uses largo_gallery_enqueue(); */ function handle_slideshow( $output, $attr ) { + largo_gallery_enqueue(); /** * Grab attachments */