| 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 |
* @version 1.8.8.6 |
| 12 |
*/ |
| 13 |
|
| 14 |
// Exit if accessed directly. |
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; |
| 17 |
} |
| 18 |
|
| 19 |
/* Donors have to be included in the view args. */ |
| 20 |
if ( ! array_key_exists( 'donors', $view_args ) ) { |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
$charitable_donors = $view_args['donors']; |
| 25 |
$charitable_args = $view_args; |
| 26 |
$charitable_campaign_id = $view_args['campaign']; |
| 27 |
$charitable_hide_if_no_donors = array_key_exists( 'hide_if_no_donors', $view_args ) && $view_args['hide_if_no_donors']; |
| 28 |
|
| 29 |
if ( ! charitable_is_campaign_page() && 'current' === $charitable_campaign_id ) { |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
if ( ! $charitable_donors->count() && $charitable_hide_if_no_donors ) { |
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
if ( 'all' == $charitable_campaign_id ) { |
| 38 |
$charitable_args['campaign'] = false; |
| 39 |
} elseif ( 'current' == $charitable_campaign_id ) { |
| 40 |
$charitable_args['campaign'] = get_the_ID(); |
| 41 |
} |
| 42 |
|
| 43 |
$charitable_orientation = array_key_exists( 'orientation', $view_args ) ? $view_args['orientation'] : 'vertical'; |
| 44 |
$charitable_style = ''; |
| 45 |
|
| 46 |
if ( 'horizontal' == $charitable_orientation ) { |
| 47 |
$charitable_width = array_key_exists( 'width', $view_args ) ? $view_args['width'] : get_option( 'thumbnail_size_w', 100 ); |
| 48 |
if ( 100 !== $charitable_width ) { |
| 49 |
$charitable_style = '<style>.donors-list.donors-list-horizontal .donor{ width:' . intval( $charitable_width ) . 'px; }</style>'; |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Add something before the donors loop logic. |
| 55 |
* |
| 56 |
* @since 1.8.1.12 |
| 57 |
* |
| 58 |
* @param mixed $campaign_id The campaign ID. |
| 59 |
* @param array $args Loop args. |
| 60 |
*/ |
| 61 |
do_action( 'charitable_donor_list_before', $charitable_campaign_id, $charitable_args ); |
| 62 |
|
| 63 |
if ( $charitable_donors->count() ) : |
| 64 |
echo $charitable_style; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 65 |
|
| 66 |
/** |
| 67 |
* Add something before the donors loop. |
| 68 |
* |
| 69 |
* @since 1.8.1.12 |
| 70 |
* |
| 71 |
* @param array $donors The donors. |
| 72 |
* @param mixed $campaign_id The campaign ID. |
| 73 |
* @param array $args Loop args. |
| 74 |
*/ |
| 75 |
do_action( 'charitable_donor_list_loop_before', $charitable_donors, $charitable_campaign_id, $charitable_args ); |
| 76 |
|
| 77 |
?> |
| 78 |
<ol class="donors-list donors-list-<?php echo esc_attr( $charitable_orientation ); ?>"> |
| 79 |
<?php |
| 80 |
foreach ( $charitable_donors as $charitable_donor ) : |
| 81 |
|
| 82 |
$charitable_args['donor'] = $charitable_donor; |
| 83 |
|
| 84 |
charitable_template( 'donor-loop/donor.php', $charitable_args ); |
| 85 |
|
| 86 |
endforeach; |
| 87 |
?> |
| 88 |
</ol> |
| 89 |
<?php else : ?> |
| 90 |
<?php if ( is_admin() && 1 === intval( $view_args['builder_preview'] ) ) : ?> |
| 91 |
<?php |
| 92 |
/* fake data for preview area */ |
| 93 |
$charitable_limit = isset( $view_args['number'] ) && intval( $view_args['number'] > 0 ) && intval( $view_args['number'] <= 10 ) ? intval( $view_args['number'] ) : 10; |
| 94 |
|
| 95 |
/** |
| 96 |
* Add something before the donors loop. |
| 97 |
* |
| 98 |
* @since 1.8.1.12 |
| 99 |
* |
| 100 |
* @param array $donors The donors. |
| 101 |
* @param mixed $campaign_id The campaign ID. |
| 102 |
* @param array $args Loop args. |
| 103 |
*/ |
| 104 |
do_action( 'charitable_campaign_loop_before', $charitable_donors, $charitable_campaign_id, $charitable_args ); |
| 105 |
|
| 106 |
?> |
| 107 |
<ol class="donors-list donors-list-<?php echo esc_attr( $charitable_orientation ); ?>"> |
| 108 |
<?php for ( $charitable_x = 1; $charitable_x <= $charitable_limit; $charitable_x++ ) : ?> |
| 109 |
<li class="donor"> |
| 110 |
<?php if ( ! empty( $args['show_avatar'] ) && 1 === intval( $args['show_avatar'] ) ) : ?> |
| 111 |
<img alt="" src="<?php echo esc_url( 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"> |
| 112 |
<?php endif; ?> |
| 113 |
<?php if ( ! empty( $args['show_name'] ) && 1 === intval( $args['show_name'] ) ) : ?> |
| 114 |
<p class="donor-name"><?php esc_html_e( 'John Smith', 'charitable' ); ?></p> |
| 115 |
<?php endif; ?> |
| 116 |
<?php if ( ! empty( $args['show_location'] ) && 1 === intval( $args['show_location'] ) ) : ?> |
| 117 |
<div class="donor-location"><?php esc_html_e( 'US', 'charitable' ); ?></div> |
| 118 |
<?php endif; ?> |
| 119 |
<?php if ( ! empty( $args['show_amount'] ) && 1 === intval( $args['show_amount'] ) ) : ?> |
| 120 |
<div class="donor-donation-amount"><?php esc_html_e( '$100.00', 'charitable' ); ?></div> |
| 121 |
<?php endif; ?> |
| 122 |
</li><!-- .donor-x --> |
| 123 |
<?php endfor; ?> |
| 124 |
</ol> |
| 125 |
<?php |
| 126 |
|
| 127 |
/** |
| 128 |
* Add something before the donors loop. |
| 129 |
* |
| 130 |
* @since 1.8.1.12 |
| 131 |
* |
| 132 |
* @param array $donors The donors. |
| 133 |
* @param mixed $campaign_id The campaign ID. |
| 134 |
* @param array $args Loop args. |
| 135 |
*/ |
| 136 |
do_action( 'charitable_donor_list_loop_after', $charitable_donors, $charitable_campaign_id, $charitable_args ); |
| 137 |
|
| 138 |
?> |
| 139 |
<?php else : ?> |
| 140 |
<p><?php echo esc_html__( 'No donors yet. Be the first!', 'charitable' ); ?></p> |
| 141 |
<?php endif; ?> |
| 142 |
<?php |
| 143 |
endif; |
| 144 |
|
| 145 |
/** |
| 146 |
* Add something before the donors loop logic. |
| 147 |
* |
| 148 |
* @since 1.8.1.12 |
| 149 |
* |
| 150 |
* @param mixed $campaign_id The campaign ID. |
| 151 |
* @param array $args Loop args. |
| 152 |
*/ |
| 153 |
do_action( 'charitable_donor_list_after', $charitable_campaign_id, $charitable_args ); |
| 154 |
|