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

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

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