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

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