Adjusted glm_get_header() to break less
authorLaury GvR <laury@gaslightmedia.com>
Fri, 23 Mar 2018 16:11:05 +0000 (12:11 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Fri, 23 Mar 2018 16:11:05 +0000 (12:11 -0400)
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

index b312a32..3836f4c 100644 (file)
@@ -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 '<div style="background-image: url('.$image_data.');height:0;padding:0;padding-bottom:50%;'
-                . 'background-position:center center;background-size: cover;background-repeat:no-repeat;max-height: 600px; "';
+                . 'background-position:center center;background-size: cover;background-repeat:no-repeat;max-height: 600px; "'
+                . 'class="' . implode(' ',$featured_classes) . '"';
         echo '>';
         
         if ($image_caption) {    
@@ -102,19 +122,15 @@ function glm_get_header($memberID = false) {
             echo '</div>';
             echo '</div>';
         }
-    } else if (!is_page('member-detail')) {
+    } else {
+        $featured_classes[] = "interior-default";
         echo '<div';
         echo ' style="background-image: url('.get_template_directory_uri().'/assets/default-header.png);height:0;padding:0;padding-bottom:50%;'
-                . 'background-position:center center;background-size: cover;background-repeat:no-repeat;max-height: 600px; "';
+                . 'background-position:center center;background-size: cover;background-repeat:no-repeat;max-height: 600px; "'
+                . 'class="' . implode(' ',$featured_classes) . '"';
         echo '>';
-    } else {
-        echo '<div>';
     }
     echo '</div>';
-    echo '<div class="row">';
-    echo '<div class="small-12 columns">';
-    echo '</div>';
-    echo '</div>';
 }
 if (!function_exists('write_log')) {
     function write_log ( $log )  {