| @@ -1,18 +1,16 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * Give Form Widget |
| 4 | 4 | * |
| 5 | - * @package GiveWP | |
| 5 | + * @package WordImpress | |
| 6 | 6 | * @subpackage Admin/Forms |
| 7 | - * @copyright Copyright (c) 2016, GiveWP | |
| 7 | + * @copyright Copyright (c) 2016, WordImpress | |
| 8 | 8 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
| 9 | 9 | * @since 1.0 |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly. |
| 13 | -use Give\Helpers\Form\Utils as FormUtils; | |
| 14 | - | |
| 15 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | 14 | exit; |
| 17 | 15 | } |
| 18 | 16 | |
| @@ -20,38 +18,10 @@ | ||
| 20 | 18 | * Give Form widget |
| 21 | 19 | * |
| 22 | 20 | * @since 1.0 |
| 23 | 21 | */ |
| 24 | -class Give_Forms_Widget extends WP_Widget { | |
| 22 | +class Give_Forms_Widget extends WP_Widget{ | |
| 25 | 23 | /** |
| 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 | 24 | * The widget class name |
| 55 | 25 | * |
| 56 | 26 | * @var string |
| 57 | 27 | */ |
| @@ -59,40 +29,44 @@ | ||
| 59 | 29 | |
| 60 | 30 | /** |
| 61 | 31 | * Instantiate the class |
| 62 | 32 | */ |
| 63 | - public function __construct() { | |
| 33 | + public function __construct(){ | |
| 64 | 34 | $this->self = get_class( $this ); |
| 35 | + | |
| 65 | 36 | parent::__construct( |
| 66 | 37 | 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 | - ] | |
| 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 | + ) | |
| 71 | 42 | ); |
| 72 | 43 | |
| 73 | - add_action( 'widgets_init', [ $this, 'widget_init' ] ); | |
| 74 | - add_action( 'admin_enqueue_scripts', [ $this, 'admin_widget_scripts' ] ); | |
| 44 | + add_action( 'widgets_init', array( $this, 'widget_init' ) ); | |
| 45 | + add_action( 'admin_enqueue_scripts', array( $this, 'admin_widget_scripts' ) ); | |
| 75 | 46 | } |
| 76 | 47 | |
| 77 | 48 | /** |
| 78 | 49 | * Load widget assets only on the widget page |
| 79 | 50 | * |
| 51 | + * @param string $hook | |
| 52 | + * | |
| 80 | 53 | * @return void |
| 81 | 54 | */ |
| 82 | - public function admin_widget_scripts() { | |
| 83 | - global $pagenow; | |
| 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/'; | |
| 84 | 60 | |
| 85 | - // Load script only on widgets.php page. | |
| 86 | - if ( ! in_array( $pagenow, [ 'widgets.php', 'customize.php' ] ) ) { | |
| 87 | - return; | |
| 88 | - } | |
| 61 | + // Use minified libraries if SCRIPT_DEBUG is turned off | |
| 62 | + $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; | |
| 89 | 63 | |
| 90 | - // Directories of assets. | |
| 91 | - $js_dir = GIVE_PLUGIN_URL . 'assets/dist/'; | |
| 64 | + // Widget Script | |
| 65 | + if ( $hook == 'widgets.php' ) { | |
| 92 | 66 | |
| 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 ); | |
| 67 | + wp_enqueue_script( 'give-admin-widgets-scripts', $js_dir . 'admin-widgets' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false ); | |
| 68 | + } | |
| 95 | 69 | } |
| 96 | 70 | |
| 97 | 71 | /** |
| 98 | 72 | * Echo the widget content. |
| @@ -100,60 +74,33 @@ | ||
| 100 | 74 | * @param array $args Display arguments including before_title, after_title, |
| 101 | 75 | * before_widget, and after_widget. |
| 102 | 76 | * @param array $instance The settings for the particular instance of the widget. |
| 103 | 77 | */ |
| 104 | - public function widget( $args, $instance ) { | |
| 105 | - $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; | |
| 78 | + public function widget( $args, $instance ){ | |
| 79 | + $title = !empty( $instance['title'] ) ? $instance['title'] : ''; | |
| 106 | 80 | $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
| 107 | 81 | |
| 108 | - // Exit do not have valid for id. | |
| 109 | - if ( ! array_key_exists( 'id', $instance ) || empty( $instance['id'] ) ) { | |
| 110 | - return; | |
| 111 | - } | |
| 82 | + echo $args['before_widget']; | |
| 112 | 83 | |
| 113 | - $form_id = (int) $instance['id']; | |
| 114 | - $isLegacyForm = FormUtils::isLegacyForm( $form_id ); | |
| 115 | - | |
| 116 | - echo $args['before_widget']; // XSS ok. | |
| 117 | - | |
| 118 | 84 | /** |
| 119 | 85 | * Fires before widget settings form in the admin area. |
| 120 | 86 | * |
| 121 | - * @param integer $form_id Form ID. | |
| 122 | - * | |
| 123 | 87 | * @since 1.0 |
| 124 | 88 | */ |
| 125 | - do_action( 'give_before_forms_widget', $form_id ); | |
| 89 | + do_action( 'give_before_forms_widget' ); | |
| 126 | 90 | |
| 127 | - echo $title ? $args['before_title'] . $title . $args['after_title'] : ''; // XSS ok. | |
| 91 | + echo $title ? $args['before_title'] . $title . $args['after_title'] : ''; | |
| 128 | 92 | |
| 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']; | |
| 93 | + give_get_donation_form( $instance ); | |
| 133 | 94 | |
| 134 | - unset( $instance['tmp_display_style'], $instance['tmp_continue_button_title'] ); | |
| 95 | + echo $args['after_widget']; | |
| 135 | 96 | |
| 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 | 97 | /** |
| 149 | 98 | * Fires after widget settings form in the admin area. |
| 150 | 99 | * |
| 151 | - * @param integer $form_id Form ID. | |
| 152 | - * | |
| 153 | 100 | * @since 1.0 |
| 154 | 101 | */ |
| 155 | - do_action( 'give_after_forms_widget', $form_id ); | |
| 102 | + do_action( 'give_after_forms_widget' ); | |
| 156 | 103 | } |
| 157 | 104 | |
| 158 | 105 | /** |
| 159 | 106 | * Output the settings update form. |
| @@ -158,152 +105,99 @@ | ||
| 158 | 105 | /** |
| 159 | 106 | * Output the settings update form. |
| 160 | 107 | * |
| 161 | 108 | * @param array $instance Current settings. |
| 109 | + * | |
| 110 | + * @return string | |
| 162 | 111 | */ |
| 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', | |
| 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 | + ); | |
| 174 | 121 | |
| 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 | 122 | $instance = wp_parse_args( (array) $instance, $defaults ); |
| 181 | 123 | |
| 182 | 124 | // Backward compatibility: Set float labels as default if, it was set as empty previous. |
| 183 | 125 | $instance['float_labels'] = empty( $instance['float_labels'] ) ? 'global' : $instance['float_labels']; |
| 184 | 126 | |
| 185 | - $this->getScriptForBuilders(); | |
| 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 ); | |
| 186 | 135 | ?> |
| 187 | - <div id="<?php echo $this->widgetIdPrefix . $this->widgetIdentifier; ?>" class="give_forms_widget_container"> | |
| 136 | + <div class="give_forms_widget_container"> | |
| 188 | 137 | |
| 189 | 138 | <?php // Widget: widget Title. ?> |
| 190 | 139 | <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'] ); ?>" /> | |
| 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> | |
| 193 | 142 | <small class="give-field-description"><?php esc_html_e( 'Leave blank to hide the widget title.', 'give' ); ?></small> |
| 194 | 143 | </p> |
| 195 | 144 | |
| 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 | - ); | |
| 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> | |
| 206 | 157 | |
| 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> | |
| 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 | + <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 | + <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 | + <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> | |
| 221 | 168 | </p> |
| 222 | 169 | |
| 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> | |
| 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> | |
| 234 | 176 | |
| 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> | |
| 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 | + <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 | + <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> | |
| 241 | 192 | |
| 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 ); ?> | |
| 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 | + <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 | + <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> | |
| 306 | 200 | </div> |
| 307 | 201 | <?php |
| 308 | 202 | } |
| 309 | 203 | |
| @@ -311,9 +205,9 @@ | ||
| 311 | 205 | * Register the widget |
| 312 | 206 | * |
| 313 | 207 | * @return void |
| 314 | 208 | */ |
| 315 | - public function widget_init() { | |
| 209 | + function widget_init(){ | |
| 316 | 210 | register_widget( $this->self ); |
| 317 | 211 | } |
| 318 | 212 | |
| 319 | 213 | /** |
| @@ -318,14 +212,14 @@ | ||
| 318 | 212 | |
| 319 | 213 | /** |
| 320 | 214 | * Update the widget |
| 321 | 215 | * |
| 322 | - * @param array $new_instance The new options. | |
| 323 | - * @param array $old_instance The previous options. | |
| 216 | + * @param array $new_instance | |
| 217 | + * @param array $old_instance | |
| 324 | 218 | * |
| 325 | 219 | * @return array |
| 326 | 220 | */ |
| 327 | - public function update( $new_instance, $old_instance ) { | |
| 221 | + public function update( $new_instance, $old_instance ){ | |
| 328 | 222 | $this->flush_widget_cache(); |
| 329 | 223 | |
| 330 | 224 | return $new_instance; |
| 331 | 225 | } |
| @@ -334,175 +228,10 @@ | ||
| 334 | 228 | * Flush widget cache |
| 335 | 229 | * |
| 336 | 230 | * @return void |
| 337 | 231 | */ |
| 338 | - public function flush_widget_cache() { | |
| 232 | + public function flush_widget_cache(){ | |
| 339 | 233 | wp_cache_delete( $this->self, 'widget' ); |
| 340 | 234 | } |
| 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 | 235 | } |
| 507 | 236 | |
| 508 | -new Give_Forms_Widget(); | |
| 237 | +new Give_Forms_Widget; | |