PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.12
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.12
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-donate-widget.php

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

120 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class responsible for setting up the donate widget.
4 *
5 * @package Charitable/Classes/Charitable_Donate_Widget
6 * @version 1.0.0
7 * @author David Bisset
8 * @copyright Copyright (c) 2022, WP Charitable LLC
9 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Charitable_Donate_Widget' ) ) :
18
19 /**
20 * A widget to display the downloads that are connected to the campaign.
21 *
22 * @see WP_Widget
23 * @since 1.0.0
24 */
25 class Charitable_Donate_Widget extends WP_Widget {
26
27 /**
28 * Register the widget.
29 *
30 * @since 1.0.0
31 */
32 public function __construct() {
33
34 parent::__construct(
35 'charitable_donate_widget',
36 __( 'Campaign Donation', 'charitable' ),
37 array(
38 'description' => __( 'Display a donation widget.', 'charitable' ),
39 'customize_selective_refresh' => true,
40 )
41 );
42
43 }
44
45 /**
46 * Displays the widget on the frontend.
47 *
48 * @since 1.0.0
49 *
50 * @param array $args Widget args.
51 * @param array $instance Widget instance.
52 * @return void
53 */
54 public function widget( $args, $instance ) {
55 if ( ! array_key_exists( 'campaign_id', $instance ) || '' == $instance['campaign_id'] ) {
56 return;
57 }
58
59 charitable_template( 'widgets/donate.php', array_merge( $args, $instance ) );
60 }
61
62 /**
63 * Displays the widget form.
64 *
65 * @since 1.0.0
66 *
67 * @param array $instance Widget instance.
68 * @return void
69 */
70 public function form( $instance ) {
71
72 $defaults = array(
73 'title' => '',
74 'campaign_id' => '',
75 );
76
77 $instance = wp_parse_args( (array) $instance, $defaults );
78 $title = $instance['title'];
79 $campaign_id = $instance['campaign_id'];
80 $campaigns = Charitable_Campaigns::query( array( 'posts_per_page' => -1 ) );
81 ?>
82 <p>
83 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'charitable' ) ?>
84 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
85 </label>
86 </p>
87 <p>
88 <label for="<?php echo $this->get_field_id( 'campaign_id' ); ?>"><?php _e( 'Campaign:', 'charitable' ) ?>
89 <select name="<?php echo $this->get_field_name( 'campaign_id' ) ?>">
90 <option value="current"><?php _e( 'Campaign currently viewed', 'charitable' ) ?></option>
91 <optgroup label="<?php _e( 'Specific campaigns', 'charitable' ) ?>">
92 <?php foreach ( $campaigns->posts as $campaign ) : ?>
93 <option value="<?php echo $campaign->ID ?>" <?php selected( $campaign->ID, $campaign_id ) ?>><?php echo $campaign->post_title ?></option>
94 <?php endforeach ?>
95 </optgroup>
96 </select>
97 </label>
98 </p>
99 <?php
100 }
101
102 /**
103 * Update the widget settings.
104 *
105 * @since 1.0.0
106 *
107 * @param array $new_instance New widget instance arguments.
108 * @param array $old_instance Old widget instance arguments.
109 * @return array
110 */
111 public function update( $new_instance, $old_instance ) {
112 $instance = $old_instance;
113 $instance['title'] = $new_instance['title'];
114 $instance['campaign_id'] = $new_instance['campaign_id'];
115 return $instance;
116 }
117 }
118
119 endif;
120