| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 3 | +// Exit if accessed directly. | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | + | |
| 2 | 8 | /** |
| 3 | 9 | * Displays the campaign thumbnail. |
| 4 | 10 | * |
| 5 | 11 | * @author WP Charitable LLC |
| @@ -4,12 +10,34 @@ | ||
| 4 | 10 | * |
| 5 | 11 | * @author WP Charitable LLC |
| 6 | 12 | * @package Charitable/Templates/Campaign |
| 7 | 13 | * @since 1.0.0 |
| 8 | - * @version 1.0.0 | |
| 14 | + * @version 1.8.2 | |
| 15 | + * @version 1.8.3.7 - added force_featured_thumbnail parameter/filter. | |
| 16 | + * @version 1.8.8.6 | |
| 9 | 17 | */ |
| 10 | 18 | |
| 11 | -$campaign = $view_args['campaign']; | |
| 19 | +$charitable_campaign = $view_args['campaign']; | |
| 20 | +$charitable_force_featured_thumbnail = apply_filters( 'charitable_campaign_loop_featured_thumbnail', empty( $view_args['force_featured_thumbnail'] ) ? false : true ); | |
| 12 | 21 | |
| 13 | -if ( has_post_thumbnail( $campaign->ID ) ) : | |
| 14 | - echo get_the_post_thumbnail( $campaign->ID, apply_filters( 'charitable_campaign_loop_thumbnail_size', 'medium' ) ); | |
| 22 | +// determine if this is a legacy campaign, or a new campaign built with the visual editor. | |
| 23 | +if ( ! function_exists( 'charitable_is_campaign_legacy' ) ) : | |
| 24 | + if ( has_post_thumbnail( $charitable_campaign->ID ) ) : | |
| 25 | + echo get_the_post_thumbnail( $charitable_campaign->ID, apply_filters( 'charitable_campaign_loop_thumbnail_size', 'medium' ) ); | |
| 26 | + endif; | |
| 27 | +elseif ( charitable_is_campaign_legacy( $charitable_campaign ) || $charitable_force_featured_thumbnail ) : | |
| 28 | + $charitable_thumbnail_id = get_post_thumbnail_id( $charitable_campaign->ID ); | |
| 29 | + if ( $charitable_thumbnail_id ) : | |
| 30 | + echo wp_get_attachment_image( $charitable_thumbnail_id, apply_filters( 'charitable_campaign_loop_thumbnail_size', 'medium' ) ); | |
| 31 | + endif; | |
| 32 | + return; | |
| 33 | +elseif ( function_exists( 'charitable_find_photo_in_campaign_settings' ) ) : | |
| 34 | + $charitable_campaign_settings = get_post_meta( $charitable_campaign->ID, 'campaign_settings_v2', true ); | |
| 35 | + $charitable_media_info = charitable_find_photo_in_campaign_settings( $charitable_campaign_settings ); | |
| 36 | + if ( ! empty( $charitable_media_info['media_id'] ) ) { | |
| 37 | + $charitable_image_attributes = wp_get_attachment_image_src( $charitable_media_info['media_id'], apply_filters( 'charitable_campaign_loop_thumbnail_size', 'medium' ) ); | |
| 38 | + if ( ! empty( $charitable_image_attributes ) ) : ?> | |
| 39 | + <img src="<?php echo esc_url( $charitable_image_attributes[0] ); ?>" width="<?php echo esc_html( $charitable_image_attributes[1] ); ?>" height="<?php echo esc_html( $charitable_image_attributes[2] ); ?>" /> | |
| 40 | + <?php | |
| 41 | + endif; | |
| 42 | + } | |
| 15 | 43 | endif; |