PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.6.3
GiveWP – Donation Plugin and Fundraising Platform v2.6.3
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / forms / widget.php
give / includes / forms Last commit date
class-give-forms-query.php 6 years ago functions.php 6 years ago template.php 6 years ago widget.php 6 years ago
widget.php
245 lines
1 <?php
2 /**
3 * Give Form Widget
4 *
5 * @package GiveWP
6 * @subpackage Admin/Forms
7 * @copyright Copyright (c) 2016, GiveWP
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Give Form widget
19 *
20 * @since 1.0
21 */
22 class Give_Forms_Widget extends WP_Widget {
23
24 /**
25 * The widget class name
26 *
27 * @var string
28 */
29 protected $self;
30
31 /**
32 * Instantiate the class
33 */
34 public function __construct() {
35 $this->self = get_class( $this );
36
37 parent::__construct(
38 strtolower( $this->self ),
39 esc_html__( 'GiveWP - Donation Form', 'give' ),
40 array(
41 'description' => esc_html__( 'Display a GiveWP Donation Form in your theme\'s widget powered sidebar.', 'give' ),
42 )
43 );
44
45 add_action( 'widgets_init', array( $this, 'widget_init' ) );
46 add_action( 'admin_enqueue_scripts', array( $this, 'admin_widget_scripts' ) );
47 }
48
49 /**
50 * Load widget assets only on the widget page
51 *
52 * @param string $hook Use it to target a specific admin page.
53 *
54 * @return void
55 */
56 public function admin_widget_scripts( $hook ) {
57
58 // Directories of assets.
59 $js_dir = GIVE_PLUGIN_URL . 'assets/js/admin/';
60 $js_plugins = GIVE_PLUGIN_URL . 'assets/js/plugins/';
61 $css_dir = GIVE_PLUGIN_URL . 'assets/css/';
62
63 // Use minified libraries if SCRIPT_DEBUG is turned off.
64 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
65
66 // Widget Script.
67 if ( 'widgets.php' === $hook ) {
68
69 wp_enqueue_script( 'give-admin-widgets-scripts', $js_dir . 'admin-widgets' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false );
70 }
71 }
72
73 /**
74 * Echo the widget content.
75 *
76 * @param array $args Display arguments including before_title, after_title,
77 * before_widget, and after_widget.
78 * @param array $instance The settings for the particular instance of the widget.
79 */
80 public function widget( $args, $instance ) {
81 $title = ! empty( $instance['title'] ) ? $instance['title'] : '';
82 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
83 $form_id = (int) $instance['id'];
84
85 echo $args['before_widget']; // XSS ok.
86
87 /**
88 * Fires before widget settings form in the admin area.
89 *
90 * @param integer $form_id Form ID.
91 *
92 * @since 1.0
93 */
94 do_action( 'give_before_forms_widget', $form_id );
95
96 echo $title ? $args['before_title'] . $title . $args['after_title'] : ''; // XSS ok.
97
98 give_get_donation_form( $instance );
99
100 echo $args['after_widget']; // XSS ok.
101
102 /**
103 * Fires after widget settings form in the admin area.
104 *
105 * @param integer $form_id Form ID.
106 *
107 * @since 1.0
108 */
109 do_action( 'give_after_forms_widget', $form_id );
110 }
111
112 /**
113 * Output the settings update form.
114 *
115 * @param array $instance Current settings.
116 */
117 public function form( $instance ) {
118 $defaults = array(
119 'title' => '',
120 'id' => '',
121 'float_labels' => 'global',
122 'display_style' => 'modal',
123 'show_content' => 'none',
124 'continue_button_title' => '',
125 );
126
127 $instance = wp_parse_args( (array) $instance, $defaults );
128
129 // Backward compatibility: Set float labels as default if, it was set as empty previous.
130 $instance['float_labels'] = empty( $instance['float_labels'] ) ? 'global' : $instance['float_labels'];
131
132 // Query Give Forms.
133 $args = array(
134 'post_type' => 'give_forms',
135 'posts_per_page' => - 1,
136 'post_status' => 'publish',
137 );
138
139 $give_forms = get_posts( $args );
140 ?>
141 <div class="give_forms_widget_container">
142
143 <?php // Widget: widget Title. ?>
144 <p>
145 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'give' ); ?></label>
146 <input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" /><br>
147 <small class="give-field-description"><?php esc_html_e( 'Leave blank to hide the widget title.', 'give' ); ?></small>
148 </p>
149
150 <?php // Widget: Give Form. ?>
151 <p>
152 <label for="<?php echo esc_attr( $this->get_field_id( 'id' ) ); ?>"><?php esc_html_e( 'GiveWP Form:', 'give' ); ?></label>
153 <select class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'id' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'id' ) ); ?>">
154 <option value="current"><?php esc_html_e( '- Select -', 'give' ); ?></option>
155 <?php foreach ( $give_forms as $give_form ) { ?>
156 <?php /* translators: %s: Title */ ?>
157 <?php $form_title = empty( $give_form->post_title ) ? sprintf( __( 'Untitled (#%s)', 'give' ), $give_form->ID ) : $give_form->post_title; ?>
158 <option <?php selected( absint( $instance['id'] ), $give_form->ID ); ?> value="<?php echo esc_attr( $give_form->ID ); ?>"><?php echo esc_html( $form_title ); ?></option>
159 <?php } ?>
160 </select><br>
161 <small class="give-field-description"><?php esc_html_e( 'Select a GiveWP Form to embed in this widget.', 'give' ); ?></small>
162 </p>
163
164 <?php // Widget: Display Style. ?>
165 <p class="give_forms_display_style_setting_row">
166 <label for="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>"><?php esc_html_e( 'Display Style:', 'give' ); ?></label><br>
167 <label for="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>-onpage"><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>-onpage" name="<?php echo esc_attr( $this->get_field_name( 'display_style' ) ); ?>" value="onpage" <?php checked( $instance['display_style'], 'onpage' ); ?>> <?php echo esc_html__( 'All Fields', 'give' ); ?></label>
168 &nbsp;&nbsp;<label for="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>-reveal"><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>-reveal" name="<?php echo esc_attr( $this->get_field_name( 'display_style' ) ); ?>" value="reveal" <?php checked( $instance['display_style'], 'reveal' ); ?>> <?php echo esc_html__( 'Reveal', 'give' ); ?></label>
169 &nbsp;&nbsp;<label for="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>-modal"><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>-modal" name="<?php echo esc_attr( $this->get_field_name( 'display_style' ) ); ?>" value="modal" <?php checked( $instance['display_style'], 'modal' ); ?>> <?php echo esc_html__( 'Modal', 'give' ); ?></label>
170 &nbsp;&nbsp;<label for="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>-button"><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>-button" name="<?php echo esc_attr( $this->get_field_name( 'display_style' ) ); ?>" value="button" <?php checked( $instance['display_style'], 'button' ); ?>> <?php echo esc_html__( 'Button', 'give' ); ?></label><br>
171 <small class="give-field-description">
172 <?php echo esc_html__( 'Select a GiveWP donation form style.', 'give' ); ?>
173 </small>
174 </p>
175
176 <?php // Widget: Continue Button Title. ?>
177 <p class="give_forms_continue_button_title_setting_row">
178 <label for="<?php echo esc_attr( $this->get_field_id( 'continue_button_title' ) ); ?>"><?php esc_html_e( 'Button Text:', 'give' ); ?></label>
179 <input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'continue_button_title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'continue_button_title' ) ); ?>" value="<?php echo esc_attr( $instance['continue_button_title'] ); ?>" /><br>
180 <small class="give-field-description"><?php esc_html_e( 'The button label for displaying the additional payment fields.', 'give' ); ?></small>
181 </p>
182
183 <?php // Widget: Floating Labels. ?>
184 <p>
185 <label for="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>"><?php esc_html_e( 'Floating Labels (optional):', 'give' ); ?></label><br>
186 <label for="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>-global"><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>-global" name="<?php echo esc_attr( $this->get_field_name( 'float_labels' ) ); ?>" value="global" <?php checked( $instance['float_labels'], 'global' ); ?>> <?php echo esc_html__( 'Global Option', 'give' ); ?></label>
187 &nbsp;&nbsp;<label for="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>-enabled"><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>-enabled" name="<?php echo esc_attr( $this->get_field_name( 'float_labels' ) ); ?>" value="enabled" <?php checked( $instance['float_labels'], 'enabled' ); ?>> <?php echo esc_html__( 'Enabled', 'give' ); ?></label>
188 &nbsp;&nbsp;<label for="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>-disabled"><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>-disabled" name="<?php echo esc_attr( $this->get_field_name( 'float_labels' ) ); ?>" value="disabled" <?php checked( $instance['float_labels'], 'disabled' ); ?>> <?php echo esc_html__( 'Disabled', 'give' ); ?></label><br>
189 <small class="give-field-description">
190 <?php
191 printf(
192 /* translators: %s: Documentation link to http://docs.givewp.com/form-floating-labels */
193 __( 'Override the <a href="%s" target="_blank">floating labels</a> setting for this GiveWP form.', 'give' ),
194 esc_url( 'http://docs.givewp.com/form-floating-labels' )
195 );
196 ?>
197 </small>
198 </p>
199
200 <?php // Widget: Display Content. ?>
201 <p>
202 <label for="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>"><?php esc_html_e( 'Display Content (optional):', 'give' ); ?></label><br>
203 <label for="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>-none"><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>-none" name="<?php echo esc_attr( $this->get_field_name( 'show_content' ) ); ?>" value="none" <?php checked( $instance['show_content'], 'none' ); ?>> <?php echo esc_html__( 'None', 'give' ); ?></label>
204 &nbsp;&nbsp;<label for="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>-above"><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>-above" name="<?php echo esc_attr( $this->get_field_name( 'show_content' ) ); ?>" value="above" <?php checked( $instance['show_content'], 'above' ); ?>> <?php echo esc_html__( 'Above', 'give' ); ?></label>
205 &nbsp;&nbsp;<label for="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>-below"><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>-below" name="<?php echo esc_attr( $this->get_field_name( 'show_content' ) ); ?>" value="below" <?php checked( $instance['show_content'], 'below' ); ?>> <?php echo esc_html__( 'Below', 'give' ); ?></label><br>
206 <small class="give-field-description"><?php esc_html_e( 'Override the display content setting for this GiveWP form.', 'give' ); ?></small>
207 </div>
208 <?php
209 }
210
211 /**
212 * Register the widget
213 *
214 * @return void
215 */
216 public function widget_init() {
217 register_widget( $this->self );
218 }
219
220 /**
221 * Update the widget
222 *
223 * @param array $new_instance The new options.
224 * @param array $old_instance The previous options.
225 *
226 * @return array
227 */
228 public function update( $new_instance, $old_instance ) {
229 $this->flush_widget_cache();
230
231 return $new_instance;
232 }
233
234 /**
235 * Flush widget cache
236 *
237 * @return void
238 */
239 public function flush_widget_cache() {
240 wp_cache_delete( $this->self, 'widget' );
241 }
242 }
243
244 new Give_Forms_Widget();
245