| 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 |
<p><?php echo esc_html__( 'No donors yet. Be the first!', 'charitable' ); ?></p> |
| 91 |
<?php |
| 92 |
endif; |
| 93 |
|
| 94 |
/** |
| 95 |
* Add something before the donors loop logic. |
| 96 |
* |
| 97 |
* @since 1.8.1.12 |
| 98 |
* |
| 99 |
* @param mixed $campaign_id The campaign ID. |
| 100 |
* @param array $args Loop args. |
| 101 |
*/ |
| 102 |
do_action( 'charitable_donor_list_after', $charitable_campaign_id, $charitable_args ); |
| 103 |
|