class-give-forms-query.php
6 years ago
functions.php
5 years ago
template.php
5 years ago
widget.php
6 years ago
widget.php
509 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 | use Give\Helpers\Form\Utils as FormUtils; |
| 14 | |
| 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | exit; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Give Form widget |
| 21 | * |
| 22 | * @since 1.0 |
| 23 | */ |
| 24 | class Give_Forms_Widget extends WP_Widget { |
| 25 | /** |
| 26 | * Script handle name. |
| 27 | * |
| 28 | * @since 2.7.0 |
| 29 | * @var string |
| 30 | */ |
| 31 | private $scriptHandle = 'give-admin-widgets-scripts'; |
| 32 | |
| 33 | /** |
| 34 | * Widget identifier. |
| 35 | * |
| 36 | * We will use this to assign unique id to widget setting container and to generate unique inline script. |
| 37 | * |
| 38 | * @since 2.7.0 |
| 39 | * @var string |
| 40 | */ |
| 41 | private $widgetIdentifier = ''; |
| 42 | |
| 43 | /** |
| 44 | * Widget id prefix. |
| 45 | * |
| 46 | * We will use this to assign unique id to widget setting container. |
| 47 | * |
| 48 | * @since 2.7.0 |
| 49 | * @var string |
| 50 | */ |
| 51 | private $widgetIdPrefix = 'give_forms_widget_container-'; |
| 52 | |
| 53 | /** |
| 54 | * The widget class name |
| 55 | * |
| 56 | * @var string |
| 57 | */ |
| 58 | protected $self; |
| 59 | |
| 60 | /** |
| 61 | * Instantiate the class |
| 62 | */ |
| 63 | public function __construct() { |
| 64 | $this->self = get_class( $this ); |
| 65 | parent::__construct( |
| 66 | strtolower( $this->self ), |
| 67 | esc_html__( 'GiveWP - Donation Form', 'give' ), |
| 68 | [ |
| 69 | 'description' => esc_html__( 'Display a GiveWP Donation Form in your theme\'s widget powered sidebar.', 'give' ), |
| 70 | ] |
| 71 | ); |
| 72 | |
| 73 | add_action( 'widgets_init', [ $this, 'widget_init' ] ); |
| 74 | add_action( 'admin_enqueue_scripts', [ $this, 'admin_widget_scripts' ] ); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Load widget assets only on the widget page |
| 79 | * |
| 80 | * @return void |
| 81 | */ |
| 82 | public function admin_widget_scripts() { |
| 83 | global $pagenow; |
| 84 | |
| 85 | // Load script only on widgets.php page. |
| 86 | if ( ! in_array( $pagenow, [ 'widgets.php', 'customize.php' ] ) ) { |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | // Directories of assets. |
| 91 | $js_dir = GIVE_PLUGIN_URL . 'assets/dist/'; |
| 92 | |
| 93 | wp_enqueue_script( "{$this->scriptHandle}-js", $js_dir . 'js/admin-widgets.js', [ 'give-admin-scripts' ], GIVE_VERSION, false ); |
| 94 | wp_enqueue_style( "{$this->scriptHandle}-css", $js_dir . 'css/admin-widgets.css', [], GIVE_VERSION, false ); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Echo the widget content. |
| 99 | * |
| 100 | * @param array $args Display arguments including before_title, after_title, |
| 101 | * before_widget, and after_widget. |
| 102 | * @param array $instance The settings for the particular instance of the widget. |
| 103 | */ |
| 104 | public function widget( $args, $instance ) { |
| 105 | $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; |
| 106 | $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
| 107 | |
| 108 | // Exit do not have valid for id. |
| 109 | if ( ! array_key_exists( 'id', $instance ) || empty( $instance['id'] ) ) { |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | $form_id = (int) $instance['id']; |
| 114 | $isLegacyForm = FormUtils::isLegacyForm( $form_id ); |
| 115 | |
| 116 | echo $args['before_widget']; // XSS ok. |
| 117 | |
| 118 | /** |
| 119 | * Fires before widget settings form in the admin area. |
| 120 | * |
| 121 | * @param integer $form_id Form ID. |
| 122 | * |
| 123 | * @since 1.0 |
| 124 | */ |
| 125 | do_action( 'give_before_forms_widget', $form_id ); |
| 126 | |
| 127 | echo $title ? $args['before_title'] . $title . $args['after_title'] : ''; // XSS ok. |
| 128 | |
| 129 | // Use alias setting to set display setting when form template other then Legacy. |
| 130 | if ( ! $isLegacyForm ) { |
| 131 | $instance['display_style'] = $instance['tmp_display_style']; |
| 132 | $instance['continue_button_title'] = $instance['tmp_continue_button_title']; |
| 133 | |
| 134 | unset( $instance['tmp_display_style'], $instance['tmp_continue_button_title'] ); |
| 135 | |
| 136 | if ( 'button' === $instance['display_style'] && ! empty( $instance['introduction_text'] ) ) { |
| 137 | printf( |
| 138 | '<p>%1$s</p>', |
| 139 | $instance['introduction_text'] |
| 140 | ); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | echo give_form_shortcode( $instance ); |
| 145 | |
| 146 | echo $args['after_widget']; // XSS ok. |
| 147 | |
| 148 | /** |
| 149 | * Fires after widget settings form in the admin area. |
| 150 | * |
| 151 | * @param integer $form_id Form ID. |
| 152 | * |
| 153 | * @since 1.0 |
| 154 | */ |
| 155 | do_action( 'give_after_forms_widget', $form_id ); |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Output the settings update form. |
| 160 | * |
| 161 | * @param array $instance Current settings. |
| 162 | */ |
| 163 | public function form( $instance ) { |
| 164 | $defaults = [ |
| 165 | 'title' => '', |
| 166 | 'id' => 0, |
| 167 | 'float_labels' => 'global', |
| 168 | 'display_style' => 'modal', |
| 169 | 'show_content' => 'none', |
| 170 | 'continue_button_title' => __( 'Continue', 'give' ), |
| 171 | 'introduction_text' => __( 'Help our organization by donating today! All donations go directly to making a difference for our cause.', 'give' ), |
| 172 | 'button_text' => __( 'Donate Now', 'give' ), |
| 173 | 'button_color' => '#28C77B', |
| 174 | |
| 175 | // These settings are aliases for shortcode setting which prevent conflict when saving and showing setting. Later we will use them to set original settings. |
| 176 | 'tmp_display_style' => 'button', |
| 177 | 'tmp_continue_button_title' => __( 'Continue', 'give' ), |
| 178 | ]; |
| 179 | |
| 180 | $instance = wp_parse_args( (array) $instance, $defaults ); |
| 181 | |
| 182 | // Backward compatibility: Set float labels as default if, it was set as empty previous. |
| 183 | $instance['float_labels'] = empty( $instance['float_labels'] ) ? 'global' : $instance['float_labels']; |
| 184 | |
| 185 | $this->getScriptForBuilders(); |
| 186 | ?> |
| 187 | <div id="<?php echo $this->widgetIdPrefix . $this->widgetIdentifier; ?>" class="give_forms_widget_container"> |
| 188 | |
| 189 | <?php // Widget: widget Title. ?> |
| 190 | <p> |
| 191 | <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'give' ); ?></label> |
| 192 | <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'] ); ?>" /> |
| 193 | <small class="give-field-description"><?php esc_html_e( 'Leave blank to hide the widget title.', 'give' ); ?></small> |
| 194 | </p> |
| 195 | |
| 196 | <?php // Widget: Give Form. ?> |
| 197 | <p class="donation-form give-hidden"> |
| 198 | <?php |
| 199 | $selectFieldName = esc_attr( $this->get_field_name( 'id' ) ); |
| 200 | $selectFieldId = esc_attr( sanitize_key( str_replace( '-', '_', esc_attr( $this->get_field_id( 'id' ) ) ) ) ); |
| 201 | printf( |
| 202 | '<label for="%1$s">%2$s</label>', |
| 203 | $selectFieldId, |
| 204 | esc_html__( 'Donation Form:', 'give' ) |
| 205 | ); |
| 206 | |
| 207 | echo Give()->html->forms_dropdown( |
| 208 | [ |
| 209 | 'selected' => $instance['id'] ?: false, |
| 210 | 'id' => $selectFieldId, |
| 211 | 'name' => $selectFieldName, |
| 212 | 'placeholder' => esc_attr__( '- Select -', 'give' ), |
| 213 | 'query_args' => [ |
| 214 | 'post_status' => 'publish', |
| 215 | ], |
| 216 | 'select_atts' => 'style="width: 100%"', |
| 217 | ] |
| 218 | ); |
| 219 | ?> |
| 220 | <small class="give-field-description"><?php esc_html_e( 'Select a donation form to use for this widget.', 'give' ); ?></small> |
| 221 | </p> |
| 222 | |
| 223 | <div class="js-legacy-form-template-settings js-form-template-settings give-hidden"> |
| 224 | <legend class="screen-reader-text"><?php _e( 'Options for Legacy form template ', 'give' ); ?></legend> |
| 225 | <?php // Widget: Display Style. ?> |
| 226 | <p class="give_forms_display_style_setting_row"> |
| 227 | <label for="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>"><?php esc_html_e( 'Display Style:', 'give' ); ?></label> |
| 228 | <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> |
| 229 | <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> |
| 230 | <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> |
| 231 | <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> |
| 232 | <small class="give-field-description"><?php echo esc_html__( 'Select a donation form style.', 'give' ); ?></small> |
| 233 | </p> |
| 234 | |
| 235 | <?php // Widget: Continue Button Title. ?> |
| 236 | <p class="give_forms_continue_button_title_setting_row"> |
| 237 | <label for="<?php echo esc_attr( $this->get_field_id( 'continue_button_title' ) ); ?>"><?php esc_html_e( 'Button Text:', 'give' ); ?></label> |
| 238 | <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'] ); ?>" /> |
| 239 | <small class="give-field-description"><?php esc_html_e( 'The button label for displaying the additional payment fields.', 'give' ); ?></small> |
| 240 | </p> |
| 241 | |
| 242 | <?php // Widget: Floating Labels. ?> |
| 243 | <p> |
| 244 | <label for="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>"><?php esc_html_e( 'Floating Labels (optional):', 'give' ); ?></label> |
| 245 | <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> |
| 246 | <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> |
| 247 | <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> |
| 248 | <small class="give-field-description"> |
| 249 | <?php |
| 250 | printf( |
| 251 | /* translators: %s: Documentation link to http://docs.givewp.com/form-floating-labels */ |
| 252 | __( 'Override the <a href="%s" target="_blank">floating labels</a> setting for this GiveWP form.', 'give' ), |
| 253 | esc_url( 'http://docs.givewp.com/form-floating-labels' ) |
| 254 | ); |
| 255 | ?> |
| 256 | </small> |
| 257 | </p> |
| 258 | |
| 259 | <?php // Widget: Display Content. ?> |
| 260 | <p> |
| 261 | <label for="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>"><?php esc_html_e( 'Display Content (optional):', 'give' ); ?></label> |
| 262 | <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> |
| 263 | <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> |
| 264 | <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> |
| 265 | <small class="give-field-description"><?php esc_html_e( 'Override the display content setting for this GiveWP form.', 'give' ); ?></small> |
| 266 | </p> |
| 267 | </div> |
| 268 | |
| 269 | <div class="js-new-form-template-settings js-form-template-settings give-hidden"> |
| 270 | <legend class="screen-reader-text"><?php _e( 'Options for Legacy form template ', 'give' ); ?></legend> |
| 271 | |
| 272 | <?php // Widget: Display Style. ?> |
| 273 | <p class="give_forms_display_style_setting_row"> |
| 274 | <label for="<?php echo esc_attr( $this->get_field_id( 'tmp_display_style' ) ); ?>"><?php esc_html_e( 'Display Style:', 'give' ); ?></label> |
| 275 | <label for="<?php echo esc_attr( $this->get_field_id( 'tmp_display_style' ) ); ?>-button"><span><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'tmp_display_style' ) ); ?>-button" name="<?php echo esc_attr( $this->get_field_name( 'tmp_display_style' ) ); ?>" value="button" <?php checked( $instance['tmp_display_style'], 'button' ); ?>></span><span><?php echo esc_html__( 'Display a button and launch the donation form on click', 'give' ); ?></span></label> |
| 276 | <label for="<?php echo esc_attr( $this->get_field_id( 'tmp_display_style' ) ); ?>-onpage"><span><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'tmp_display_style' ) ); ?>-onpage" name="<?php echo esc_attr( $this->get_field_name( 'tmp_display_style' ) ); ?>" value="onpage" <?php checked( $instance['tmp_display_style'], 'onpage' ); ?>></span><span><?php echo esc_html__( 'Display the entire donation form in the sidebar', 'give' ); ?></span></label> |
| 277 | <small class="give-field-description"><?php echo esc_html__( 'Select a donation form style.', 'give' ); ?></small> |
| 278 | </p> |
| 279 | |
| 280 | <?php // Widget: Introduction Text. ?> |
| 281 | <p class="give_forms_introduction_text_setting_row"> |
| 282 | <label for="<?php echo esc_attr( $this->get_field_id( 'introduction_text' ) ); ?>"><?php esc_html_e( 'Widget Text:', 'give' ); ?></label> |
| 283 | <textarea id="<?php echo esc_attr( $this->get_field_id( 'introduction_text' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'introduction_text' ) ); ?>" class="widefat"><?php echo esc_textarea( $instance['introduction_text'] ); ?></textarea> |
| 284 | <small class="give-field-description"><?php esc_html_e( 'Provide an introduction text to invite the visitor to become a donor. Leave this blank to not display any text.', 'give' ); ?></small> |
| 285 | </p> |
| 286 | |
| 287 | <?php // Widget: Continue Button Text. ?> |
| 288 | <p class="give_forms_button_text_setting_row"> |
| 289 | <label for="<?php echo esc_attr( $this->get_field_id( 'tmp_continue_button_title' ) ); ?>"><?php esc_html_e( 'Button Text:', 'give' ); ?></label> |
| 290 | <input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'tmp_continue_button_title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'tmp_continue_button_title' ) ); ?>" value="<?php echo esc_attr( $instance['tmp_continue_button_title'] ); ?>" /> |
| 291 | <small class="give-field-description"><?php esc_html_e( 'This label will appear on button.', 'give' ); ?></small> |
| 292 | </p> |
| 293 | |
| 294 | <?php // Widget: Continue Button Color. ?> |
| 295 | <p class="give_forms_button_color_setting_row"> |
| 296 | <label for="<?php echo esc_attr( $this->get_field_id( 'button_color' ) ); ?>"><?php esc_html_e( 'Button Color:', 'give' ); ?></label> |
| 297 | <input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'button_color' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'button_color' ) ); ?>" value="<?php echo esc_attr( $instance['button_color'] ); ?>" /> |
| 298 | <small class="give-field-description"><?php esc_html_e( 'Set the color of button.', 'give' ); ?></small> |
| 299 | </p> |
| 300 | </div> |
| 301 | |
| 302 | <div class="js-loader"> |
| 303 | <p><span class="give-spinner spinner is-show"></span> <i><?php _e( 'Loading settings...', 'give' ); ?></i></p> |
| 304 | </div> |
| 305 | <?php wp_nonce_field( 'give-donation-form-widget', '_wpnonce', false ); ?> |
| 306 | </div> |
| 307 | <?php |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Register the widget |
| 312 | * |
| 313 | * @return void |
| 314 | */ |
| 315 | public function widget_init() { |
| 316 | register_widget( $this->self ); |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * Update the widget |
| 321 | * |
| 322 | * @param array $new_instance The new options. |
| 323 | * @param array $old_instance The previous options. |
| 324 | * |
| 325 | * @return array |
| 326 | */ |
| 327 | public function update( $new_instance, $old_instance ) { |
| 328 | $this->flush_widget_cache(); |
| 329 | |
| 330 | return $new_instance; |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * Flush widget cache |
| 335 | * |
| 336 | * @return void |
| 337 | */ |
| 338 | public function flush_widget_cache() { |
| 339 | wp_cache_delete( $this->self, 'widget' ); |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * Get inline script for widget to add support for widget in page builder like Divi, Elementor and Beaver Builder. |
| 344 | * |
| 345 | * @since 2.7.0 |
| 346 | */ |
| 347 | private function getScriptForBuilders() { |
| 348 | global $pagenow; |
| 349 | |
| 350 | // Do not output inline script if admin widget script already printed. |
| 351 | if ( wp_script_is( "{$this->scriptHandle}-js", 'done' ) || in_array( $pagenow, [ 'widgets.php', 'customize.php' ] ) ) { |
| 352 | return; |
| 353 | } |
| 354 | |
| 355 | $this->widgetIdentifier = uniqid(); |
| 356 | $containerId = $this->widgetIdPrefix . $this->widgetIdentifier; |
| 357 | ?> |
| 358 | <style> |
| 359 | .give_forms_widget_container label:not([for*='display_style']):not([for*='float_labels']):not([for*='show_content']), |
| 360 | p.give_forms_display_style_setting_row > label:first-child, |
| 361 | .give_forms_widget_container label[for$='float_labels'], |
| 362 | .give_forms_widget_container label[for$='show_content']{ |
| 363 | display: block; |
| 364 | font-weight: 500; |
| 365 | } |
| 366 | |
| 367 | p.give_forms_display_style_setting_row > label:first-child, |
| 368 | .give_forms_widget_container label[for$='float_labels'], |
| 369 | .give_forms_widget_container label[for$='show_content']{ |
| 370 | margin-bottom: 8px; |
| 371 | } |
| 372 | |
| 373 | .give_forms_widget_container input { |
| 374 | margin-left: 0 !important; |
| 375 | margin-bottom: 0 !important; |
| 376 | } |
| 377 | |
| 378 | .give_forms_widget_container input[type="radio"]{ |
| 379 | margin: 0! important; |
| 380 | } |
| 381 | |
| 382 | .give_forms_widget_container .give-field-description { |
| 383 | color: #aaaaaa; |
| 384 | font-style: italic; |
| 385 | margin: 0; |
| 386 | padding-top: 8px; |
| 387 | display: block; |
| 388 | } |
| 389 | |
| 390 | .give_forms_widget_container select, |
| 391 | .give_forms_widget_container textarea{ |
| 392 | margin: 5px 10px 0 0; |
| 393 | } |
| 394 | |
| 395 | .give_forms_widget_container .give_forms_display_style_setting_row label[for$="tmp_display_style"]{ |
| 396 | display: flex; |
| 397 | align-items: center; |
| 398 | } |
| 399 | |
| 400 | .give_forms_widget_container .give_forms_display_style_setting_row label[for*="tmp_display_style-"]{ |
| 401 | display: flex; |
| 402 | } |
| 403 | |
| 404 | .give_forms_widget_container .give_forms_display_style_setting_row label[for*="tmp_display_style-"] span:last-child{ |
| 405 | margin-left: 5px; |
| 406 | } |
| 407 | </style> |
| 408 | <script> |
| 409 | /** |
| 410 | * Display setting fields on basis of donation form setting. |
| 411 | * |
| 412 | * @since 2.7.0 |
| 413 | * @param {Array} $el |
| 414 | */ |
| 415 | function showConditionalFieldWhenEditDonationFormSetting<?php echo esc_js( $this->widgetIdentifier ); ?>( $el ) { |
| 416 | const $this = $el, |
| 417 | $container = $this.closest( '.give_forms_widget_container' ), |
| 418 | $loader = jQuery( '.js-loader', $container ), |
| 419 | $oldSettings = jQuery( '.js-legacy-form-template-settings', $container ), |
| 420 | $newSettings = jQuery( '.js-new-form-template-settings', $container ); |
| 421 | |
| 422 | $oldSettings.hide().removeClass( 'active' ); |
| 423 | $newSettings.hide().removeClass( 'active' ); |
| 424 | |
| 425 | $loader.show(); |
| 426 | |
| 427 | jQuery.post( |
| 428 | ajaxurl, |
| 429 | { |
| 430 | action: 'give_get_form_template_id', |
| 431 | formId: $this.val(), |
| 432 | security: jQuery( 'input[name="_wpnonce"]', $container ).val(), |
| 433 | }, |
| 434 | function( response ) { |
| 435 | $loader.hide(); |
| 436 | |
| 437 | // Exit if result is not successful. |
| 438 | if (true === response.success) { |
| 439 | if ('legacy' === response.data) { |
| 440 | $oldSettings.show().addClass( 'active' ); |
| 441 | } else { |
| 442 | $newSettings.show().addClass( 'active' ); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | showConditionalFieldWhenEditDisplayStyleSetting<?php echo esc_js( $this->widgetIdentifier ); ?>( $this ); |
| 447 | }, |
| 448 | ); |
| 449 | } |
| 450 | |
| 451 | /** |
| 452 | * Display setting fields on basis of display_style setting. |
| 453 | * |
| 454 | * @since 2.7.0 |
| 455 | * @param {Array} $el |
| 456 | */ |
| 457 | function showConditionalFieldWhenEditDisplayStyleSetting<?php echo esc_js( $this->widgetIdentifier ); ?>( $el ) { |
| 458 | const $container = $el.closest( '.give_forms_widget_container' ), |
| 459 | $fieldset = jQuery( '.js-form-template-settings.active', $container ), |
| 460 | $parent = jQuery( 'p.give_forms_display_style_setting_row', $fieldset ), |
| 461 | isFormHasNewTemplate = $fieldset.hasClass( 'js-new-form-template-settings' ), |
| 462 | isFormHasLegacyTemplate = $fieldset.hasClass( 'js-legacy-form-template-settings' ); |
| 463 | |
| 464 | if (isFormHasLegacyTemplate) { |
| 465 | const $continue_button_title = $parent.next(); |
| 466 | |
| 467 | if ('onpage' === jQuery( 'input:checked', $parent ).val()) { |
| 468 | $continue_button_title.hide(); |
| 469 | } else { |
| 470 | $continue_button_title.show(); |
| 471 | } |
| 472 | } else if (isFormHasNewTemplate) { |
| 473 | if ('button' === jQuery( 'input:checked', $parent ).val()) { |
| 474 | $fieldset.find( 'p' ).not( $parent ).show(); |
| 475 | } else { |
| 476 | $fieldset.find( 'p' ).not( $parent ).hide(); |
| 477 | } |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | /* Display style change handler. */ |
| 482 | jQuery( document ).on( 'change', '#<?php echo esc_js( $containerId ); ?> .give_forms_display_style_setting_row input', function() { |
| 483 | showConditionalFieldWhenEditDisplayStyleSetting<?php echo esc_js( $this->widgetIdentifier ); ?>( jQuery( this ) ); |
| 484 | } ); |
| 485 | |
| 486 | /* Donation form change handler. */ |
| 487 | jQuery( document ).on( 'change', '#<?php echo esc_js( $containerId ); ?> select.give-select', function() { |
| 488 | const $container = jQuery(this).closest('.give_forms_widget_container'), |
| 489 | $parent = jQuery( this ).parent(); |
| 490 | |
| 491 | $parent.removeClass('give-hidden'); |
| 492 | jQuery('.js-loader', $container ).addClass('give-hidden'); |
| 493 | |
| 494 | // Render form template settings only if form selected. |
| 495 | if( parseInt(jQuery( this ).val()) ) { |
| 496 | showConditionalFieldWhenEditDonationFormSetting<?php echo esc_js( $this->widgetIdentifier ); ?>( jQuery( this ) ); |
| 497 | } else{ |
| 498 | jQuery( '#<?php echo esc_js( $containerId ); ?> .give-hidden' ).hide(); |
| 499 | } |
| 500 | } ); |
| 501 | |
| 502 | jQuery( '#<?php echo esc_js( $containerId ); ?> select.give-select' ).trigger('change'); |
| 503 | </script> |
| 504 | <?php |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | new Give_Forms_Widget(); |
| 509 |