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

119 lines 3.4 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) 2023, 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 * Displays the widget on the frontend.
46 *
47 * @since 1.0.0
48 *
49 * @param array $args Widget args.
50 * @param array $instance Widget instance.
51 * @return void
52 */
53 public function widget( $args, $instance ) {
54 if ( ! array_key_exists( 'campaign_id', $instance ) || '' === $instance['campaign_id'] ) {
55 return;
56 }
57
58 charitable_template( 'widgets/donate.php', array_merge( $args, $instance ) );
59 }
60
61 /**
62 * Displays the widget form.
63 *
64 * @since 1.0.0
65 *
66 * @param array $instance Widget instance.
67 * @return void
68 */
69 public function form( $instance ) {
70
71 $defaults = array(
72 'title' => '',
73 'campaign_id' => '',
74 );
75
76 $instance = wp_parse_args( (array) $instance, $defaults );
77 $title = $instance['title'];
78 $campaign_id = $instance['campaign_id'];
79 $campaigns = Charitable_Campaigns::query( array( 'posts_per_page' => -1 ) );
80 ?>
81 <p>
82 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'charitable' ); ?>
83 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
84 </label>
85 </p>
86 <p>
87 <label for="<?php echo esc_attr( $this->get_field_id( 'campaign_id' ) ); ?>"><?php esc_html_e( 'Campaign:', 'charitable' ); ?>
88 <select name="<?php echo esc_attr( $this->get_field_name( 'campaign_id' ) ); ?>">
89 <option value="current"><?php esc_html_e( 'Campaign currently viewed', 'charitable' ); ?></option>
90 <optgroup label="<?php esc_html_e( 'Specific campaigns', 'charitable' ); ?>">
91 <?php foreach ( $campaigns->posts as $campaign ) : ?>
92 <option value="<?php echo esc_attr( $campaign->ID ); ?>" <?php selected( $campaign->ID, $campaign_id ); ?>><?php echo esc_html( $campaign->post_title ); ?></option>
93 <?php endforeach ?>
94 </optgroup>
95 </select>
96 </label>
97 </p>
98 <?php
99 }
100
101 /**
102 * Update the widget settings.
103 *
104 * @since 1.0.0
105 *
106 * @param array $new_instance New widget instance arguments.
107 * @param array $old_instance Old widget instance arguments.
108 * @return array
109 */
110 public function update( $new_instance, $old_instance ) {
111 $instance = $old_instance;
112 $instance['title'] = $new_instance['title'];
113 $instance['campaign_id'] = $new_instance['campaign_id'];
114 return $instance;
115 }
116 }
117
118 endif;
119