From 534de6af2ffb37ee1869e997e42cac4e28f18f98 Mon Sep 17 00:00:00 2001 From: Laury GvR Date: Fri, 23 Mar 2018 12:11:05 -0400 Subject: [PATCH] Adjusted glm_get_header() to break less This function wasn't always doing its expected behavior. Now it properly checks for image data failures at any step and applies classes to the featured image based on which image it actually displays. e.g. if it passes into member detail but fails to get an image from the member it gets the 'member-default' class, unless there is no default member image, in which case it gets the 'wp-default' class. --- functions.php | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/functions.php b/functions.php index b312a32..3836f4c 100644 --- a/functions.php +++ b/functions.php @@ -81,18 +81,38 @@ function glm_site_scripts() /* Header for posts*/ function glm_get_header($memberID = false) { global $post; - + $default_image_path = get_template_directory_uri().'/assets/default-header.png'; + $default_member_image_path = $default_image_path; + $featured_classes[] = "featured-image"; if ((has_post_thumbnail() && $post->post_type == 'page') || is_page('member-detail')) { - if(!$memberID){ + if( !$memberID ) { $image_data = wp_get_attachment_image_src(get_post_thumbnail_id(), "full"); $image_caption = get_the_post_thumbnail_caption(); $image_data = $image_data[0]; + $featured_classes[] = $image_data ? "wp-featured" : ""; } else { $image_data = apply_filters('member_images',$memberID,true,'original'); + $featured_classes[] = $image_data ? "member-featured" : ""; + if ( !$image_data ) { + $image_data = wp_get_attachment_image_src(get_post_thumbnail_id(), "full"); + $image_caption = get_the_post_thumbnail_caption(); + $image_data = $image_data[0]; + $featured_classes[] = $image_data ? "wp-featured" : ""; + } + if ( !$image_data ) { + $image_data = $default_member_image_path; + $featured_classes[] = $image_data ? "member-default" : ""; + } } + if ( !$image_data ) { + $image_data = $default_image_path; + $featured_classes[] = $image_data ? "interior-default" : ""; + } + echo '
'; if ($image_caption) { @@ -102,19 +122,15 @@ function glm_get_header($memberID = false) { echo '
'; echo ''; } - } else if (!is_page('member-detail')) { + } else { + $featured_classes[] = "interior-default"; echo ''; - } else { - echo '
'; } echo '
'; - echo '
'; - echo '
'; - echo '
'; - echo '
'; } if (!function_exists('write_log')) { function write_log ( $log ) { -- 2.17.1