| 1 |
<?php |
| 2 |
|
| 3 |
// Exit if accessed directly. |
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Display the site donation stats. |
| 10 |
* |
| 11 |
* Override this template by copying it to yourtheme/charitable/donation-stats.php |
| 12 |
* |
| 13 |
* @package Charitable/Templates/Widgets |
| 14 |
* @author WP Charitable LLC |
| 15 |
* @since 1.5.0 |
| 16 |
* @version 1.6.57 |
| 17 |
* @version 1.8.8.6 |
| 18 |
*/ |
| 19 |
|
| 20 |
/** |
| 21 |
* Do something before displaying the donation stats. |
| 22 |
* |
| 23 |
* @since 1.6.57 |
| 24 |
* |
| 25 |
* @param array $view_args The view arguments. |
| 26 |
*/ |
| 27 |
do_action( 'charitable_donation_stats_before', $view_args ); |
| 28 |
|
| 29 |
$charitable_campaigns_count = Charitable_Campaigns::query( |
| 30 |
array( |
| 31 |
'posts_per_page' => -1, |
| 32 |
'fields' => 'ids', |
| 33 |
) |
| 34 |
)->found_posts; |
| 35 |
$charitable_campaigns_text = 1 === $charitable_campaigns_count ? __( 'Campaign', 'charitable' ) : __( 'Campaigns', 'charitable' ); |
| 36 |
|
| 37 |
/** |
| 38 |
* Filter the donation stats to show. |
| 39 |
* |
| 40 |
* @since 1.5.0 |
| 41 |
* |
| 42 |
* @param array $donation_stats The default stats to show. |
| 43 |
* @param array $view_args All arguments passed to the view. |
| 44 |
*/ |
| 45 |
$charitable_donation_stats = apply_filters( |
| 46 |
'charitable_donation_stats', |
| 47 |
array( |
| 48 |
'campaign_count' => array( |
| 49 |
'amount' => $charitable_campaigns_count, |
| 50 |
'description' => $charitable_campaigns_text, |
| 51 |
), |
| 52 |
'donated' => array( |
| 53 |
'amount' => charitable_format_money( charitable_get_table( 'campaign_donations' )->get_total() ), |
| 54 |
'description' => __( 'Donated', 'charitable' ), |
| 55 |
), |
| 56 |
'donor_count' => array( |
| 57 |
'amount' => charitable_get_table( 'donors' )->count_donors_with_donations(), |
| 58 |
'description' => __( 'Donors', 'charitable' ), |
| 59 |
), |
| 60 |
), |
| 61 |
$view_args |
| 62 |
); |
| 63 |
|
| 64 |
?> |
| 65 |
<ul class="donation-stats"> |
| 66 |
<?php |
| 67 |
foreach ( $charitable_donation_stats as $charitable_stat ) : |
| 68 |
printf( '<li><span class="figure">%s</span> %s</li>', esc_html( $charitable_stat['amount'] ), esc_html( $charitable_stat['description'] ) ); |
| 69 |
endforeach; |
| 70 |
?> |
| 71 |
</ul><!-- .donation-stats --> |
| 72 |
<?php |
| 73 |
|
| 74 |
/** |
| 75 |
* Do something after displaying the donation stats. |
| 76 |
* |
| 77 |
* @since 1.6.57 |
| 78 |
* |
| 79 |
* @param array $view_args The view arguments. |
| 80 |
*/ |
| 81 |
do_action( 'charitable_donation_stats_after', $view_args ); |