PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.0.0
GiveWP – Donation Plugin and Fundraising Platform v2.0.0
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
functions.php 8 years ago template.php 8 years ago widget.php 8 years ago
widget.php
238 lines
1 <?php
2 /**
3 * Give Form Widget
4 *
5 * @package WordImpress
6 * @subpackage Admin/Forms
7 * @copyright Copyright (c) 2016, WordImpress
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 * The widget class name
25 *
26 * @var string
27 */
28 protected $self;
29
30 /**
31 * Instantiate the class
32 */
33 public function __construct(){
34 $this->self = get_class( $this );
35
36 parent::__construct(
37 strtolower( $this->self ),
38 esc_html__( 'Give - Donation Form', 'give' ),
39 array(
40 'description' => esc_html__( 'Display a Give Donation Form in your theme\'s widget powered sidebar.', 'give' )
41 )
42 );
43
44 add_action( 'widgets_init', array( $this, 'widget_init' ) );
45 add_action( 'admin_enqueue_scripts', array( $this, 'admin_widget_scripts' ) );
46 }
47
48 /**
49 * Load widget assets only on the widget page
50 *
51 * @param string $hook
52 *
53 * @return void
54 */
55 public function admin_widget_scripts( $hook ){
56 // Directories of assets
57 $js_dir = GIVE_PLUGIN_URL . 'assets/js/admin/';
58 $js_plugins = GIVE_PLUGIN_URL . 'assets/js/plugins/';
59 $css_dir = GIVE_PLUGIN_URL . 'assets/css/';
60
61 // Use minified libraries if SCRIPT_DEBUG is turned off
62 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
63
64 // Widget Script
65 if ( $hook == 'widgets.php' ) {
66
67 wp_enqueue_script( 'give-admin-widgets-scripts', $js_dir . 'admin-widgets' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false );
68 }
69 }
70
71 /**
72 * Echo the widget content.
73 *
74 * @param array $args Display arguments including before_title, after_title,
75 * before_widget, and after_widget.
76 * @param array $instance The settings for the particular instance of the widget.
77 */
78 public function widget( $args, $instance ){
79 $title = !empty( $instance['title'] ) ? $instance['title'] : '';
80 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
81
82 echo $args['before_widget'];
83
84 /**
85 * Fires before widget settings form in the admin area.
86 *
87 * @since 1.0
88 */
89 do_action( 'give_before_forms_widget' );
90
91 echo $title ? $args['before_title'] . $title . $args['after_title'] : '';
92
93 give_get_donation_form( $instance );
94
95 echo $args['after_widget'];
96
97 /**
98 * Fires after widget settings form in the admin area.
99 *
100 * @since 1.0
101 */
102 do_action( 'give_after_forms_widget' );
103 }
104
105 /**
106 * Output the settings update form.
107 *
108 * @param array $instance Current settings.
109 *
110 * @return string
111 */
112 public function form( $instance ){
113 $defaults = array(
114 'title' => '',
115 'id' => '',
116 'float_labels' => 'global',
117 'display_style' => 'modal',
118 'show_content' => 'none',
119 'continue_button_title' => '',
120 );
121
122 $instance = wp_parse_args( (array) $instance, $defaults );
123
124 // Backward compatibility: Set float labels as default if, it was set as empty previous.
125 $instance['float_labels'] = empty( $instance['float_labels'] ) ? 'global' : $instance['float_labels'];
126
127 // Query Give Forms
128 $args = array(
129 'post_type' => 'give_forms',
130 'posts_per_page' => - 1,
131 'post_status' => 'publish',
132 );
133
134 $give_forms = get_posts( $args );
135 ?>
136 <div class="give_forms_widget_container">
137
138 <?php // Widget: widget Title. ?>
139 <p>
140 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'give' ); ?></label>
141 <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php esc_attr_e( $instance['title'] ); ?>" /><br>
142 <small class="give-field-description"><?php esc_html_e( 'Leave blank to hide the widget title.', 'give' ); ?></small>
143 </p>
144
145 <?php // Widget: Give Form?>
146 <p>
147 <label for="<?php echo esc_attr( $this->get_field_id( 'id' ) ); ?>"><?php esc_html_e( 'Give Form:', 'give' ); ?></label>
148 <select class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'id' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'id' ) ); ?>">
149 <option value="current"><?php esc_html_e( '- Select -', 'give' ); ?></option>
150 <?php foreach ( $give_forms as $give_form ) { ?>
151 <?php $form_title = empty( $give_form->post_title ) ? sprintf( __( 'Untitled (#%s)', 'give' ), $give_form->ID ) : $give_form->post_title; ?>
152 <option <?php selected( absint( $instance['id'] ), $give_form->ID ); ?> value="<?php echo esc_attr( $give_form->ID ); ?>"><?php echo $form_title; ?></option>
153 <?php } ?>
154 </select><br>
155 <small class="give-field-description"><?php esc_html_e( 'Select a Give Form to embed in this widget.', 'give' ); ?></small>
156 </p>
157
158 <?php // Widget: Display Style ?>
159 <p class="give_forms_display_style_setting_row">
160 <label for="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>"><?php esc_html_e( 'Display Style:', 'give' ); ?></label><br>
161 <label for="<?php echo $this->get_field_id( 'display_style' ); ?>-onpage"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'display_style' ); ?>-onpage" name="<?php echo $this->get_field_name( 'display_style' ); ?>" value="onpage" <?php checked( $instance['display_style'], 'onpage' ); ?>> <?php echo esc_html__( 'All Fields', 'give' ); ?></label>
162 &nbsp;&nbsp;<label for="<?php echo $this->get_field_id( 'display_style' ); ?>-reveal"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'display_style' ); ?>-reveal" name="<?php echo $this->get_field_name( 'display_style' ); ?>" value="reveal" <?php checked( $instance['display_style'], 'reveal' ); ?>> <?php echo esc_html__( 'Reveal', 'give' ); ?></label>
163 &nbsp;&nbsp;<label for="<?php echo $this->get_field_id( 'display_style' ); ?>-modal"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'display_style' ); ?>-modal" name="<?php echo $this->get_field_name( 'display_style' ); ?>" value="modal" <?php checked( $instance['display_style'], 'modal' ); ?>> <?php echo esc_html__( 'Modal', 'give' ); ?></label>
164 &nbsp;&nbsp;<label for="<?php echo $this->get_field_id( 'display_style' ); ?>-button"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'display_style' ); ?>-button" name="<?php echo $this->get_field_name( 'display_style' ); ?>" value="button" <?php checked( $instance['display_style'], 'button' ); ?>> <?php echo esc_html__( 'Button', 'give' ); ?></label><br>
165 <small class="give-field-description">
166 <?php echo esc_html__( 'Select a Give Form style.', 'give' ); ?>
167 </small>
168 </p>
169
170 <?php // Widget: Continue Button Title. ?>
171 <p class="give_forms_continue_button_title_setting_row">
172 <label for="<?php echo $this->get_field_id( 'continue_button_title' ); ?>"><?php esc_html_e( 'Button Text:', 'give' ); ?></label>
173 <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'continue_button_title' ); ?>" name="<?php echo $this->get_field_name( 'continue_button_title' ); ?>" value="<?php esc_attr_e( $instance['continue_button_title'] ); ?>" /><br>
174 <small class="give-field-description"><?php esc_html_e( 'The button label for displaying the additional payment fields.', 'give' ); ?></small>
175 </p>
176
177 <?php // Widget: Floating Labels ?>
178 <p>
179 <label for="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>"><?php esc_html_e( 'Floating Labels (optional):', 'give' ); ?></label><br>
180 <label for="<?php echo $this->get_field_id( 'float_labels' ); ?>-global"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'float_labels' ); ?>-global" name="<?php echo $this->get_field_name( 'float_labels' ); ?>" value="global" <?php checked( $instance['float_labels'], 'global' ); ?>> <?php echo esc_html__( 'Global Option', 'give' ); ?></label>
181 &nbsp;&nbsp;<label for="<?php echo $this->get_field_id( 'float_labels' ); ?>-enabled"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'float_labels' ); ?>-enabled" name="<?php echo $this->get_field_name( 'float_labels' ); ?>" value="enabled" <?php checked( $instance['float_labels'], 'enabled' ); ?>> <?php echo esc_html__( 'Yes', 'give' ); ?></label>
182 &nbsp;&nbsp;<label for="<?php echo $this->get_field_id( 'float_labels' ); ?>-disabled"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'float_labels' ); ?>-disabled" name="<?php echo $this->get_field_name( 'float_labels' ); ?>" value="disabled" <?php checked( $instance['float_labels'], 'disabled' ); ?>> <?php echo esc_html__( 'No', 'give' ); ?></label><br>
183 <small class="give-field-description">
184 <?php
185 printf(
186 /* translators: %s: http://docs.givewp.com/form-floating-labels */
187 __( 'Override the <a href="%s" target="_blank">floating labels</a> setting for this Give form.', 'give' ),
188 esc_url( 'http://docs.givewp.com/form-floating-labels' )
189 );
190 ?></small>
191 </p>
192
193 <?php // Widget: Display Content ?>
194 <p>
195 <label for="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>"><?php esc_html_e( 'Display Content (optional):', 'give' ); ?></label><br>
196 <label for="<?php echo $this->get_field_id( 'show_content' ); ?>-none"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'show_content' ); ?>-none" name="<?php echo $this->get_field_name( 'show_content' ); ?>" value="none" <?php checked( $instance['show_content'], 'none' ); ?>> <?php echo esc_html__( 'None', 'give' ); ?></label>
197 &nbsp;&nbsp;<label for="<?php echo $this->get_field_id( 'show_content' ); ?>-above"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'show_content' ); ?>-above" name="<?php echo $this->get_field_name( 'show_content' ); ?>" value="above" <?php checked( $instance['show_content'], 'above' ); ?>> <?php echo esc_html__( 'Above', 'give' ); ?></label>
198 &nbsp;&nbsp;<label for="<?php echo $this->get_field_id( 'show_content' ); ?>-below"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'show_content' ); ?>-below" name="<?php echo $this->get_field_name( 'show_content' ); ?>" value="below" <?php checked( $instance['show_content'], 'below' ); ?>> <?php echo esc_html__( 'Below', 'give' ); ?></label><br>
199 <small class="give-field-description"><?php esc_html_e( 'Override the display content setting for this Give form.', 'give' ); ?></small>
200 </div>
201 <?php
202 }
203
204 /**
205 * Register the widget
206 *
207 * @return void
208 */
209 function widget_init(){
210 register_widget( $this->self );
211 }
212
213 /**
214 * Update the widget
215 *
216 * @param array $new_instance
217 * @param array $old_instance
218 *
219 * @return array
220 */
221 public function update( $new_instance, $old_instance ){
222 $this->flush_widget_cache();
223
224 return $new_instance;
225 }
226
227 /**
228 * Flush widget cache
229 *
230 * @return void
231 */
232 public function flush_widget_cache(){
233 wp_cache_delete( $this->self, 'widget' );
234 }
235 }
236
237 new Give_Forms_Widget;
238