PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.6
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.6
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
charitable / includes / widgets / class-charitable-donors-widget.php

class-charitable-donors-widget.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.7.0.6, at includes/widgets/class-charitable-donors-widget.php

233 lines 9.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Campaign donors widget class.
4 *
5 * @version 1.0.0
6 * @package Charitable/Widgets/Donors
7 * @author David Bisset
8 */
9
10 // Exit if accessed directly.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 if ( ! class_exists( 'Charitable_Donors_Widget' ) ) :
16
17 /**
18 * Charitable_Donors_Widget class.
19 *
20 * @since 1.0.0
21 */
22 class Charitable_Donors_Widget extends WP_Widget {
23
24 /**
25 * Instantiate the widget and set up basic configuration.
26 *
27 * @since 1.0.0
28 */
29 public function __construct() {
30 parent::__construct(
31 'charitable_donors_widget',
32 __( 'Donors', 'charitable' ),
33 array(
34 'description' => __( 'Display a list of donors.', 'charitable' ),
35 'customize_selective_refresh' => true,
36 )
37 );
38 }
39
40 /**
41 * Display the widget contents on the front-end.
42 *
43 * @since 1.0.0
44 *
45 * @param array $args Display arguments including 'before_title', 'after_title', 'before_widget' and 'after_widget'.
46 * @param array $instance The settings for the particular instance of the widget.
47 * @return void
48 */
49 public function widget( $args, $instance ) {
50 $instance = $this->get_parsed_args( $instance );
51 $view_args = array_merge( $args, $instance );
52 $instance['campaign'] = $view_args['campaign_id'];
53 $view_args['campaign'] = $view_args['campaign_id'];
54 $view_args['orderby'] = $view_args['order'];
55 $view_args['order'] = 'DESC';
56 $view_args['donors'] = $this->get_widget_donors( $instance );
57
58 charitable_template( 'widgets/donors.php', $view_args );
59 }
60
61 /**
62 * Display the widget form in the admin.
63 *
64 * @since 1.0.0
65 *
66 * @param array $instance The current settings for the widget options.
67 * @return void
68 */
69 public function form( $instance ) {
70 $args = $this->get_parsed_args( $instance );
71 $campaigns = Charitable_Campaigns::query( array( 'posts_per_page' => -1 ) );
72 ?>
73 <p>
74 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title', 'charitable' ); ?>:</label>
75 <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" value="<?php echo esc_attr( $args['title'] ); ?>" class="widefat" />
76 </p>
77 <p>
78 <label for="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>"><?php _e( 'Number of donors to display', 'charitable' ); ?>:</label>
79 <input type="number" name="<?php echo esc_attr( $this->get_field_name( 'number' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>" value="<?php echo intval( $args['number'] ); ?>" min="1" size="3" />
80 </p>
81 <p>
82 <label for="<?php echo esc_attr( $this->get_field_id( 'order' ) ); ?>"><?php _e( 'Order by', 'charitable' ); ?>:</label>
83 <select name="<?php echo esc_attr( $this->get_field_name( 'order' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'order' ) ); ?>">
84 <option value="recent" <?php selected( 'recent', $args['order'] ); ?>><?php _e( 'Most recent', 'charitable' ); ?></option>
85 <option value="amount" <?php selected( 'amount', $args['order'] ); ?>><?php _e( 'Amount donated', 'charitable' ); ?></option>
86 </select>
87 </p>
88 <p>
89 <label for="<?php echo esc_attr( $this->get_field_id( 'campaign_id' ) ); ?>"><?php _e( 'Show donors by campaign', 'charitable' ); ?>:</label>
90 <select name="<?php echo esc_attr( $this->get_field_name( 'campaign_id' ) ); ?>">
91 <option value="all" <?php selected( 'all', $args['campaign_id'] ); ?>><?php _e( 'Include all campaigns' ); ?></option>
92 <option value="current" <?php selected( 'current', $args['campaign_id'] ); ?>><?php _e( 'Campaign currently viewed', 'charitable' ); ?></option>
93 <optgroup label="<?php _e( 'Specific campaign', 'charitable' ); ?>">
94 <?php foreach ( $campaigns->posts as $campaign ) : ?>
95 <option value="<?php echo intval( $campaign->ID ); ?>" <?php selected( $campaign->ID, $args['campaign_id'] ); ?>><?php echo $campaign->post_title; ?></option>
96 <?php endforeach ?>
97 </optgroup>
98 </select>
99 </p>
100 <p>
101 <input id="<?php echo esc_attr( $this->get_field_id( 'show_distinct' ) ); ?>" type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'show_distinct' ) ); ?>" <?php checked( $args['show_distinct'] ); ?>>
102 <label for="<?php echo esc_attr( $this->get_field_id( 'show_distinct' ) ); ?>"><?php _e( 'Group donations by the same person', 'charitable' ); ?></label>
103 </p>
104 <p>
105 <input id="<?php echo esc_attr( $this->get_field_id( 'show_avatar' ) ); ?>" type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'show_avatar' ) ); ?>" <?php checked( $args['show_avatar'] ); ?>>
106 <label for="<?php echo esc_attr( $this->get_field_id( 'show_avatar' ) ); ?>"><?php _e( 'Show donor\'s avatar', 'charitable' ); ?></label>
107 </p>
108 <p>
109 <input id="<?php echo esc_attr( $this->get_field_id( 'show_name' ) ); ?>" type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'show_name' ) ); ?>" <?php checked( $args['show_name'] ); ?>>
110 <label for="<?php echo esc_attr( $this->get_field_id( 'show_name' ) ); ?>"><?php _e( 'Show donor\'s name', 'charitable' ); ?></label>
111 </p>
112 <p>
113 <input id="<?php echo esc_attr( $this->get_field_id( 'show_amount' ) ); ?>" type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'show_amount' ) ); ?>" <?php checked( $args['show_amount'] ); ?>>
114 <label for="<?php echo esc_attr( $this->get_field_id( 'show_amount' ) ); ?>"><?php _e( 'Show donor\'s donation amount', 'charitable' ); ?></label>
115 </p>
116 <p>
117 <input id="<?php echo esc_attr( $this->get_field_id( 'show_location' ) ); ?>" type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'show_location' ) ); ?>" <?php checked( $args['show_location'] ); ?>>
118 <label for="<?php echo esc_attr( $this->get_field_id( 'show_location' ) ); ?>"><?php _e( 'Show donor\'s location', 'charitable' ); ?></label>
119 </p>
120 <p>
121 <input id="<?php echo esc_attr( $this->get_field_id( 'hide_if_no_donors' ) ); ?>" type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'hide_if_no_donors' ) ); ?>" <?php checked( $args['hide_if_no_donors'] ); ?>>
122 <label for="<?php echo esc_attr( $this->get_field_id( 'hide_if_no_donors' ) ); ?>"><?php _e( 'Hide if there are no donors', 'charitable' ); ?></label>
123 </p>
124 <?php
125 /**
126 * Add extra settings for the widget.
127 *
128 * @param array $args Widget instance arguments.
129 * @param Charitable_Donors_Widget $this This widget instance.
130 */
131 do_action( 'charitable_donor_widget_settings_bottom', $args, $this );
132 }
133
134 /**
135 * Update the widget settings in the admin.
136 *
137 * @since 1.0.0
138 *
139 * @param array $new_instance The updated settings.
140 * @param array $old_instance The old settings.
141 * @return array
142 */
143 public function update( $new_instance, $old_instance ) {
144 $instance = $new_instance;
145
146 foreach ( array( 'show_distinct', 'show_avatar', 'show_location', 'show_amount', 'show_name', 'hide_if_no_donors' ) as $key ) {
147 $instance[ $key ] = array_key_exists( $key, $instance )
148 ? charitable_sanitize_checkbox( $instance[ $key ] )
149 : 0;
150 }
151
152 /**
153 * Filter the instance arguments.
154 *
155 * @since 1.0.0
156 *
157 * @param array $instance The parsed instance settings.
158 * @param array $new_instance The updated settings.
159 * @param array $old_instance The old settings.
160 */
161 return apply_filters( 'charitable_donors_widget_update_instance', $instance, $new_instance, $old_instance );
162 }
163
164 /**
165 * Return parsed array of arguments.
166 *
167 * @since 1.0.0
168 *
169 * @param array $instance The settings for the particular instance of the widget.
170 * @return mixed[]
171 */
172 protected function get_parsed_args( $instance ) {
173 /**
174 * Filter the default widget arguments.
175 *
176 * @since 1.0.0
177 *
178 * @param array $args The default arguments.
179 * @param array $instance The widget instance settings.
180 */
181 $defaults = apply_filters(
182 'charitable_donors_widget_default_args',
183 array(
184 'title' => '',
185 'number' => 10,
186 'order' => 'recent',
187 'campaign_id' => 'all',
188 'show_distinct' => 1,
189 'show_avatar' => 1,
190 'show_location' => 0,
191 'show_amount' => 0,
192 'show_name' => 0,
193 'hide_if_no_donors' => 0,
194 ),
195 $instance
196 );
197
198 return wp_parse_args( $instance, $defaults );
199 }
200
201 /**
202 * Return the donors to display in the widget.
203 *
204 * @since 1.0.0
205 *
206 * @param mixed[] $instance The widget instance.
207 * @return Charitable_Donor_Query
208 */
209 protected function get_widget_donors( $instance ) {
210 $query_args = charitable_array_subset( $instance, array( 'number', 'campaign' ) );
211
212 if ( 'amount' == $instance['order'] ) {
213 $query_args['orderby'] = 'amount';
214 }
215
216 $query_args['distinct_donors'] = $instance['show_distinct'];
217
218 /**
219 * Filter the arguments passed to Charitable_Donor_Query.
220 *
221 * @since 1.0.0
222 *
223 * @param array $query_args The arguments to be passed to Charitable_Donor_Query::__construct.
224 * @param array $args All the parsed arguments.
225 */
226 $query_args = apply_filters( 'charitable_donors_widget_donor_query_args', $query_args, $instance );
227
228 return new Charitable_Donor_Query( $query_args );
229 }
230 }
231
232 endif;
233