PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 All 211 releases
← All changes | includes/donations/class-charitable-donations.php +35 -31 1.6.7 → 1.8.13 View file →
@@ -1,16 +1,19 @@
1 1 <?php
2 2 /**
3 3 * The class that is responsible for querying data about donations.
4 4 *
5 - * @version 1.0.0
6 - * @package Charitable/Classes/Charitable_Donations
7 - * @author Eric Daams
8 - * @copyright Copyright (c) 2018, Studio 164a
9 - * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
5 + * @package Charitable/Classes/Charitable_Donations
6 + * @author David Bisset
7 + * @copyright Copyright (c) 2023, WP Charitable LLC
8 + * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 + * @since 1.0.0
10 + * @version 1.6.39
10 11 */
11 12
12 -if ( ! defined( 'ABSPATH' ) ) { exit; }
13 +if ( ! defined( 'ABSPATH' ) ) {
14 + exit;
15 +}
13 16
14 17 if ( ! class_exists( 'Charitable_Donations' ) ) :
15 18
16 19 /**
@@ -15,10 +18,9 @@
15 18
16 19 /**
17 20 * Charitable_Donations
18 21 *
19 - * @since 1.0.0
20 - * @uses WP_Query
22 + * @since 1.0.0
21 23 */
22 24 class Charitable_Donations {
23 25
24 26 /**
@@ -23,12 +25,12 @@
23 25
24 26 /**
25 27 * Return WP_Query object with predefined defaults to query only donations.
26 28 *
27 - * @since 1.0.0
29 + * @since 1.0.0
28 30 *
29 - * @param array $args Query arguments.
30 - * @return WP_Query
31 + * @param array $args Query arguments.
32 + * @return WP_Query
31 33 */
32 34 public static function query( $args = array() ) {
33 35 $defaults = array(
34 36 'post_type' => array( Charitable::DONATION_POST_TYPE ),
@@ -42,32 +44,32 @@
42 44
43 45 /**
44 46 * Return the number of all donations.
45 47 *
46 - * @global WPDB $wpdb
47 - * @since 1.0.0
48 + * @since 1.0.0
48 49 *
49 - * @param string $post_type Type of post to count.
50 - * @return int
50 + * @global WPDB $wpdb
51 + * @param string $post_type Type of post to count.
52 + * @return int
51 53 */
52 54 public static function count_all( $post_type = 'donation' ) {
53 55 global $wpdb;
54 56
55 - $sql = "SELECT COUNT( * )
56 - FROM $wpdb->posts
57 + $sql = "SELECT COUNT( * )
58 + FROM $wpdb->posts
57 59 WHERE post_type = %s";
58 60
59 - return $wpdb->get_var( $wpdb->prepare( $sql, $post_type ) );
61 + return $wpdb->get_var( $wpdb->prepare( $sql, $post_type ) ); // phpcs:ignore
60 62 }
61 63
62 64 /**
63 65 * Return count of donations grouped by status.
64 66 *
65 - * @global WPDB $wpdb
66 - * @since 1.0.0
67 + * @since 1.0.0
67 68 *
68 - * @param array $args Additional query arguments.
69 - * @return array
69 + * @global WPDB $wpdb
70 + * @param array $args Additional query arguments.
71 + * @return array
70 72 */
71 73 public static function count_by_status( $args = array() ) {
72 74 global $wpdb;
73 75
@@ -75,8 +77,9 @@
75 77 's' => null,
76 78 'start_date' => null,
77 79 'end_date' => null,
78 80 'post_type' => 'donation',
81 + 'author' => null,
79 82 );
80 83
81 84 $args = wp_parse_args( $args, $defaults );
82 85
@@ -82,41 +85,42 @@
82 85
83 86 $where_clause = $wpdb->prepare( 'post_type = %s', $args['post_type'] );
84 87
85 88 if ( ! empty( $args['s'] ) ) {
86 - $where_clause .= " AND ((post_title LIKE '%{$args['s']}%') OR (post_content LIKE '%{$args['s']}%'))";
89 + $like = '%' . $wpdb->esc_like( $args['s'] ) . '%';
90 + $where_clause .= $wpdb->prepare( ' AND ((post_title LIKE %s) OR (post_content LIKE %s))', $like, $like );
87 91 }
88 92
89 93 if ( ! empty( $args['start_date'] ) ) {
90 -
91 94 $year = $args['start_date']['year'];
92 95 $month = $args['start_date']['month'];
93 96 $day = $args['start_date']['day'];
94 97
95 98 if ( false !== checkdate( $month, $day, $year ) ) {
96 - $where_clause .= $wpdb->prepare( " AND post_date >= '%s'", date( 'Y-m-d', mktime( 0, 0, 0, $month, $day, $year ) ) );
99 + $where_clause .= $wpdb->prepare( " AND post_date >= '%s'", date( 'Y-m-d', mktime( 0, 0, 0, $month, $day, $year ) ) ); // phpcs:ignore
97 100 }
98 101 }
99 102
100 103 if ( ! empty( $args['end_date'] ) ) {
101 -
102 104 $year = $args['end_date']['year'];
103 105 $month = $args['end_date']['month'];
104 106 $day = $args['end_date']['day'];
105 107
106 108 if ( false !== checkdate( $month, $day, $year ) ) {
109 + $where_clause .= $wpdb->prepare( " AND post_date <= '%s'", date( 'Y-m-d', mktime( 0, 0, 0, $month, $day, $year ) ) ); // phpcs:ignore
110 + }
111 + }
107 112
108 - $where_clause .= $wpdb->prepare( " AND post_date <= '%s'", date( 'Y-m-d', mktime( 0, 0, 0, $month, $day, $year ) ) );
109 -
110 - }
113 + if ( ! is_null( $args['author'] ) ) {
114 + $where_clause .= $wpdb->prepare( " AND post_author = %d", $args['author'] ); // phpcs:ignore
111 115 }
112 116
113 117 $sql = "SELECT post_status, COUNT( * ) AS num_donations
114 - FROM $wpdb->posts
118 + FROM $wpdb->posts
115 119 WHERE $where_clause
116 120 GROUP BY post_status";
117 121
118 - return $wpdb->get_results( $sql, OBJECT_K );
122 + return $wpdb->get_results( $sql, OBJECT_K ); // phpcs:ignore
119 123 }
120 124 }
121 125
122 126 endif;