| 1 |
<?php |
| 2 |
/** |
| 3 |
* Display a list of donors, either for a specific campaign or sitewide. |
| 4 |
* |
| 5 |
* Override this template by copying it to yourtheme/charitable/donor-loop.php |
| 6 |
* |
| 7 |
* @package Charitable/Templates/Donor |
| 8 |
* @author WP Charitable LLC |
| 9 |
* @since 1.5.0 |
| 10 |
* @version 1.8.0 |
| 11 |
*/ |
| 12 |
|
| 13 |
// Exit if accessed directly. |
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
/* Donors have to be included in the view args. */ |
| 19 |
if ( ! array_key_exists( 'donors', $view_args ) ) { |
| 20 |
return; |
| 21 |
} |
| 22 |
|
| 23 |
$donors = $view_args['donors']; |
| 24 |
$args = $view_args; |
| 25 |
$campaign_id = $view_args['campaign']; |
| 26 |
$hide_if_no_donors = array_key_exists( 'hide_if_no_donors', $view_args ) && $view_args['hide_if_no_donors']; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
if ( ! charitable_is_campaign_page() && 'current' === $campaign_id ) { |
| 31 |
return; |
| 32 |
} |
| 33 |
|
| 34 |
if ( ! $donors->count() && $hide_if_no_donors ) { |
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 38 |
if ( 'all' == $campaign_id ) { |
| 39 |
$args['campaign'] = false; |
| 40 |
} elseif ( 'current' == $campaign_id ) { |
| 41 |
$args['campaign'] = get_the_ID(); |
| 42 |
} |
| 43 |
|
| 44 |
$orientation = array_key_exists( 'orientation', $view_args ) ? $view_args['orientation'] : 'vertical'; |
| 45 |
$style = ''; |
| 46 |
|
| 47 |
if ( 'horizontal' == $orientation ) { |
| 48 |
$width = array_key_exists( 'width', $view_args ) ? $view_args['width'] : get_option( 'thumbnail_size_w', 100 ); |
| 49 |
if ( 100 !== $width ) { |
| 50 |
$style = '<style>.donors-list.donors-list-horizontal .donor{ width:' . $width . 'px; }</style>'; |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
if ( $donors->count() ) : |
| 55 |
echo $style; |
| 56 |
?> |
| 57 |
<ol class="donors-list donors-list-<?php echo esc_attr( $orientation ); ?>"> |
| 58 |
<?php |
| 59 |
foreach ( $donors as $donor ) : |
| 60 |
|
| 61 |
$args['donor'] = $donor; |
| 62 |
|
| 63 |
charitable_template( 'donor-loop/donor.php', $args ); |
| 64 |
|
| 65 |
endforeach; |
| 66 |
?> |
| 67 |
</ol> |
| 68 |
<?php else : ?> |
| 69 |
<?php if ( is_admin() && 1 === intval( $view_args['builder_preview'] ) ) : ?> |
| 70 |
<?php |
| 71 |
/* fake data for preview area */ |
| 72 |
$limit = isset( $view_args['number'] ) && intval( $view_args['number'] > 0 ) && intval( $view_args['number'] <= 10 ) ? intval( $view_args['number'] ) : 10; |
| 73 |
?> |
| 74 |
<ol class="donors-list donors-list-<?php echo esc_attr( $orientation ); ?>"> |
| 75 |
<?php for ( $x = 1; $x <= $limit; $x++ ) : ?> |
| 76 |
<li class="donor"> |
| 77 |
<?php if ( ! empty( $args['show_avatar'] ) && 1 === intval( $args['show_avatar'] ) ) : ?> |
| 78 |
<img alt="" src="<?php echo charitable()->get_path( 'directory', false ) . 'assets/images/campaign-builder/fields/donor-wall/avatar.jpg'; ?>" class="avatar avatar-100 photo" loading="lazy" decoding="async" width="100" height="100"> |
| 79 |
<?php endif; ?> |
| 80 |
<?php if ( ! empty( $args['show_name'] ) && 1 === intval( $args['show_name'] ) ) : ?> |
| 81 |
<p class="donor-name"><?php _e( 'John Smith', 'charitable' ); ?></p> |
| 82 |
<?php endif; ?> |
| 83 |
<?php if ( ! empty( $args['show_location'] ) && 1 === intval( $args['show_location'] ) ) : ?> |
| 84 |
<div class="donor-location"><?php _e( 'US', 'charitable' ); ?></div> |
| 85 |
<?php endif; ?> |
| 86 |
<?php if ( ! empty( $args['show_amount'] ) && 1 === intval( $args['show_amount'] ) ) : ?> |
| 87 |
<div class="donor-donation-amount"><?php _e( '$100.00', 'charitable' ); ?></div> |
| 88 |
<?php endif; ?> |
| 89 |
</li><!-- .donor-x --> |
| 90 |
<?php endfor; ?> |
| 91 |
</ol> |
| 92 |
<?php else : ?> |
| 93 |
<p><?php echo esc_html__( 'No donors yet. Be the first!', 'charitable' ); ?></p> |
| 94 |
<?php endif; ?> |
| 95 |
<?php |
| 96 |
endif; |
| 97 |
|