| 1 |
<?php |
| 2 |
|
| 3 |
// Exit if accessed directly. |
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Display the donations widget on the dashboard. |
| 10 |
* |
| 11 |
* @author WP Charitable LLC |
| 12 |
* @package Charitable/Admin View/Dashboard Widgets |
| 13 |
* @since 1.2.0 |
| 14 |
* @version 1.8.8.6 |
| 15 |
*/ |
| 16 |
|
| 17 |
$charitable_statuses = charitable_get_valid_donation_statuses(); |
| 18 |
|
| 19 |
$charitable_donation_args = array( |
| 20 |
'post_type' => Charitable::DONATION_POST_TYPE, |
| 21 |
'posts_per_page' => 5, |
| 22 |
'post_status' => array_keys( $charitable_statuses ), |
| 23 |
'fields' => 'ids', |
| 24 |
); |
| 25 |
$charitable_donation_args = apply_filters( 'charitable_donations_widget_summary_donation_args', $charitable_donation_args ); |
| 26 |
$charitable_donations = get_posts( $charitable_donation_args ); |
| 27 |
|
| 28 |
$charitable_table = charitable_get_table( 'campaign_donations' ); |
| 29 |
|
| 30 |
$charitable_today = $charitable_table->get_donations_summary_by_period( apply_filters( 'charitable_donations_widget_summary_today', wp_date( 'Y-m-d%' ) ) ); |
| 31 |
$charitable_this_month = $charitable_table->get_donations_summary_by_period( apply_filters( 'charitable_donations_widget_summary_this_month', wp_date( 'Y-m%' ) ) ); |
| 32 |
$charitable_last_month = $charitable_table->get_donations_summary_by_period( apply_filters( 'charitable_donations_widget_summary_last_month', wp_date( 'Y-m%', strtotime( '-1 month' ) ) ) ); |
| 33 |
$charitable_this_year = $charitable_table->get_donations_summary_by_period( apply_filters( 'charitable_donations_widget_summary_this_year', wp_date( 'Y-%' ) ) ); |
| 34 |
|
| 35 |
?> |
| 36 |
<div class="charitable-donation-statistics"> |
| 37 |
<div class="cell"> |
| 38 |
<h3 class="amount"> |
| 39 |
<?php echo esc_html( charitable_format_money( $charitable_today->amount ) ); ?> |
| 40 |
</h3> |
| 41 |
<p class="summary"> |
| 42 |
<?php |
| 43 |
printf( |
| 44 |
/* translators: %d: number of donations */ |
| 45 |
esc_html( _n( '%d donation <span class="time-period">today</span>', '%d donations <span class="time-period">today</span>', $charitable_today->count, 'charitable' ) ), |
| 46 |
intval( $charitable_today->count ) |
| 47 |
); |
| 48 |
?> |
| 49 |
</p> |
| 50 |
</div> |
| 51 |
<div class="cell"> |
| 52 |
<h3 class="amount"> |
| 53 |
<?php echo esc_html( charitable_format_money( $charitable_this_month->amount ) ); ?> |
| 54 |
</h3> |
| 55 |
<p class="summary"> |
| 56 |
<?php |
| 57 |
printf( |
| 58 |
/* translators: %d: number of donations */ |
| 59 |
esc_html( _n( '%d donation <span class="time-period">this month</span>', '%d donations <span class="time-period">this month</span>', $charitable_this_month->count, 'charitable' ) ), |
| 60 |
intval( $charitable_this_month->count ) |
| 61 |
); |
| 62 |
?> |
| 63 |
</p> |
| 64 |
</div> |
| 65 |
<div class="cell"> |
| 66 |
<h3 class="amount"> |
| 67 |
<?php echo esc_html( charitable_format_money( $charitable_last_month->amount ) ); ?> |
| 68 |
</h3> |
| 69 |
<p class="summary"> |
| 70 |
<?php |
| 71 |
printf( |
| 72 |
/* translators: %d: number of donations */ |
| 73 |
esc_html( _n( '%d donation <span class="time-period">last month</span>', '%d donations <span class="time-period">last month</span>', $charitable_last_month->count, 'charitable' ) ), |
| 74 |
intval( $charitable_last_month->count ) |
| 75 |
); |
| 76 |
?> |
| 77 |
</p> |
| 78 |
</div> |
| 79 |
<div class="cell"> |
| 80 |
<h3 class="amount"> |
| 81 |
<?php echo esc_html( charitable_format_money( $charitable_this_year->amount ) ); ?> |
| 82 |
</h3> |
| 83 |
<p class="summary"> |
| 84 |
<?php |
| 85 |
printf( |
| 86 |
/* translators: %d: number of donations */ |
| 87 |
esc_html( _n( '%d donation <span class="time-period">this year</span>', '%d donations <span class="time-period">this year</span>', $charitable_this_year->count, 'charitable' ) ), |
| 88 |
intval( $charitable_this_year->count ) |
| 89 |
); |
| 90 |
?> |
| 91 |
</p> |
| 92 |
</div> |
| 93 |
</div> |
| 94 |
<?php if ( count( $charitable_donations ) ) : ?> |
| 95 |
<div class="recent-donations"> |
| 96 |
<table> |
| 97 |
<caption><h3><?php esc_html_e( 'Recent Donations', 'charitable' ); ?></h3></caption> |
| 98 |
<?php |
| 99 |
foreach ( $charitable_donations as $charitable_donation_id ) : |
| 100 |
$charitable_donation = charitable_get_donation( $charitable_donation_id ); |
| 101 |
?> |
| 102 |
<tr> |
| 103 |
<td class="donation-date"><?php echo esc_html( $charitable_donation->get_date() ); ?></td> |
| 104 |
<td class="donation-id">#<?php echo esc_html( $charitable_donation->get_number() ); ?></td> |
| 105 |
<td class="donation-status"><?php echo esc_html( $charitable_donation->get_status_label() ); ?></td> |
| 106 |
<td class="donation-total"><?php echo esc_html( charitable_format_money( $charitable_donation->get_total(), false, true, $charitable_donation->get_currency() ) ); ?></td> |
| 107 |
</tr> |
| 108 |
<?php |
| 109 |
endforeach; |
| 110 |
?> |
| 111 |
</table> |
| 112 |
</div> |
| 113 |
<?php endif ?> |
| 114 |
|