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-campaigns-widget.php

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

141 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Campaigns widget class.
4 *
5 * @class Charitable_Campaigns_Widget
6 * @version 1.0.0
7 * @package Charitable/Widgets/Campaigns Widget
8 * @category Class
9 * @author Eric Daams
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) { exit; }
14
15 if ( ! class_exists( 'Charitable_Campaigns_Widget' ) ) :
16
17 /**
18 * Charitable_Campaigns_Widget class.
19 *
20 * @since 1.0.0
21 */
22 class Charitable_Campaigns_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_campaigns_widget',
32 __( 'Campaigns', 'charitable' ),
33 array(
34 'description' => __( 'Displays your Charitable campaigns.', '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
46 * @param array $instance
47 */
48 public function widget( $args, $instance ) {
49
50 $view_args = array_merge( $args, $instance );
51 $view_args['campaigns'] = $this->get_widget_campaigns( $instance );
52
53 charitable_template( 'widgets/campaigns.php', $view_args );
54 }
55
56 /**
57 * Display the widget form in the admin.
58 *
59 * @since 1.0.0
60 *
61 * @param array $instance The current settings for the widget options.
62 * @return void
63 */
64 public function form( $instance ) {
65 $defaults = array(
66 'title' => '',
67 'number' => 10,
68 'order' => 'recent',
69 'show_thumbnail' => false,
70 );
71
72 $args = wp_parse_args( $instance, $defaults );
73 ?>
74 <p>
75 <label for="<?php echo $this->get_field_id( 'title' ) ?>"><?php _e( 'Title:', 'charitable' ) ?></label>
76 <input type="text" name="<?php echo $this->get_field_name( 'title' ) ?>" id="<?php echo $this->get_field_id( 'title' ) ?>" value="<?php echo $args['title'] ?>"/>
77 </p>
78 <p>
79 <label for="<?php echo $this->get_field_id( 'number' ) ?>"><?php _e( 'Number of campaigns to display:', 'charitable' ) ?></label>
80 <input type="text" name="<?php echo $this->get_field_name( 'number' ) ?>" id="<?php echo $this->get_field_id( 'number' ) ?>" value="<?php echo $args['number'] ?>" />
81 </p>
82 <p>
83 <input id="<?php echo esc_attr( $this->get_field_id( 'show_thumbnail' ) ) ?>" type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'show_thumbnail' ) ); ?>" <?php checked( $args['show_thumbnail'] ) ?>>
84 <label for="<?php echo esc_attr( $this->get_field_id( 'show_thumbnail' ) ) ?>"><?php _e( 'Show thumbnail', 'charitable' ) ?></label>
85 </p>
86 <p>
87 <label for="<?php echo $this->get_field_id( 'order' ) ?>"><?php _e( 'Order:', 'charitable' ) ?></label>
88 <select name="<?php echo $this->get_field_name( 'order' ) ?>" id="<?php echo $this->get_field_id( 'order' ) ?>">
89 <option value="recent" <?php selected( 'recent', $args['order'] ) ?>><?php _e( 'Date published', 'charitable' ) ?></option>
90 <option value="ending" <?php selected( 'ending', $args['order'] ) ?>><?php _e( 'Ending soonest', 'charitable' ) ?></option>
91 </select>
92 </p>
93 <?php
94 }
95
96 /**
97 * Update the widget settings in the admin.
98 *
99 * @since 1.0.0
100 *
101 * @param array $new_instance The updated settings.
102 * @param array $new_instance The old settings.
103 * @return void
104 */
105 public function update( $new_instance, $old_instance ) {
106
107 $instance = array();
108 $instance['title'] = isset( $new_instance['title'] ) ? $new_instance['title'] : $old_instance['title'];
109 $instance['number'] = isset( $new_instance['number'] ) ? $new_instance['number'] : $old_instance['number'];
110 $instance['show_thumbnail'] = isset( $new_instance['show_thumbnail'] ) && $new_instance['show_thumbnail'];
111 $instance['order'] = isset( $new_instance['order'] ) ? $new_instance['order'] : $old_instance['order'];
112 return $instance;
113 }
114
115 /**
116 * Return campaigns to display in the widget.
117 *
118 * @since 1.0.0
119 *
120 * @param array $instance
121 * @return WP_Query
122 */
123 protected function get_widget_campaigns( $instance ) {
124
125 $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
126 $args = array(
127 'posts_per_page' => $number,
128 );
129
130 if ( isset( $instance['order'] ) && 'recent' == $instance['order'] ) {
131 $args['orderby'] = 'date';
132 $args['order'] = 'DESC';
133 return Charitable_Campaigns::query( $args );
134 }
135
136 return Charitable_Campaigns::ordered_by_ending_soon( $args );
137 }
138 }
139
140 endif;
141