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