| @@ -1,94 +1,98 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * Class weForms_Widget | |
| 5 | - * | |
| 6 | - * Widget class for weForms Form widget | |
| 7 | - * | |
| 8 | - * @since 1.2.7 | |
| 9 | - */ | |
| 10 | -class weForms_Widget extends WP_Widget { | |
| 11 | - | |
| 12 | - /** | |
| 13 | - * weForms_Widget constructor. | |
| 14 | - */ | |
| 15 | - public function __construct() { | |
| 16 | - parent::__construct( | |
| 17 | - 'weforms_widget', | |
| 18 | - __( 'weForms Widget', 'weforms' ), | |
| 19 | - [ 'description' => __( 'Add weForms Form to Sidebar', 'weforms' )] | |
| 20 | - ); | |
| 21 | - } | |
| 22 | - | |
| 23 | - /** | |
| 24 | - * Render widget | |
| 25 | - * | |
| 26 | - * @return void | |
| 27 | - */ | |
| 28 | - public function widget( $args, $instance ) { | |
| 29 | - $title = apply_filters( 'widget_title', $instance['title'] ); | |
| 30 | - $form_id = apply_filters( 'weforms_widget_form_id', $instance['form_id'] ); | |
| 31 | - | |
| 32 | - echo wp_kses_post( $args['before_widget'] ); | |
| 33 | - | |
| 34 | - if ( ! empty( $title ) ) { | |
| 35 | - echo wp_kses_post( $args['before_title'] ) . wp_kses_post( $title ) . wp_kses_post( $args['after_title'] ); | |
| 36 | - } | |
| 37 | - | |
| 38 | - echo do_shortcode( sprintf( '[weforms id ="%s" ]', $form_id ) ); | |
| 39 | - | |
| 40 | - echo wp_kses_post( $args['after_widget'] ); | |
| 41 | - } | |
| 42 | - | |
| 43 | - /** | |
| 44 | - * weForms widget backend | |
| 45 | - * | |
| 46 | - * @return void | |
| 47 | - */ | |
| 48 | - public function form( $instance ) { | |
| 49 | - $title = isset( $instance[ 'title' ] ) ? $instance[ 'title' ] : __( 'Form', 'weforms' ); | |
| 50 | - $form_id = isset( $instance[ 'form_id' ] ) ? $instance[ 'form_id' ] : 0; | |
| 51 | - | |
| 52 | - $all_forms = weforms()->form->all(); | |
| 53 | - $options = sprintf( "<option value='%s'>%s</option>", 0, __( 'Select Form', 'weforms' ) ); | |
| 54 | - | |
| 55 | - foreach ( $all_forms['forms'] as $form ) { | |
| 56 | - $options .= sprintf( "<option value='%s' %s >%s</option>", $form->id, selected( $form_id, $form->id, false ), $form->name ); | |
| 57 | - } ?> | |
| 58 | - | |
| 59 | - <p> | |
| 60 | - <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'weforms' ); ?></label> | |
| 61 | - <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo wp_kses_post( $title ); ?>" /> | |
| 62 | - </p> | |
| 63 | - <p> | |
| 64 | - <label for="<?php echo esc_attr( $this->get_field_id( 'form_id' ) ); ?>"> <?php esc_html_e( 'Form:', 'weforms' ); ?></label> | |
| 65 | - <select id="<?php echo esc_attr( $this->get_field_id( 'form_id' ) ); ?>" class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'form_id' ) ); ?>"> | |
| 66 | - <?php echo $options; ?> // WPCS: sanitization ok. | |
| 67 | - </select> | |
| 68 | - </p> | |
| 69 | - | |
| 70 | - <?php | |
| 71 | - } | |
| 72 | - | |
| 73 | - /** | |
| 74 | - * Updating widget replacing old instances with new | |
| 75 | - * | |
| 76 | - * @return $instance | |
| 77 | - */ | |
| 78 | - public function update( $new_instance, $old_instance ) { | |
| 79 | - $instance = []; | |
| 80 | - $instance['title'] = ( !empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : ''; | |
| 81 | - $instance['form_id'] = ( !empty( $new_instance['form_id'] ) ) ? strip_tags( $new_instance['form_id'] ) : ''; | |
| 82 | - | |
| 83 | - return $instance; | |
| 84 | - } | |
| 85 | -} | |
| 86 | -/** | |
| 87 | - * Register weForms widget | |
| 88 | - * | |
| 89 | - * @return void | |
| 90 | - */ | |
| 91 | -function weforms_register_widget() { | |
| 92 | - register_widget( 'weforms_widget' ); | |
| 93 | -} | |
| 94 | -add_action( 'widgets_init', 'weforms_register_widget' ); | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Class weForms_Widget | |
| 5 | + * | |
| 6 | + * Widget class for weForms Form widget | |
| 7 | + * | |
| 8 | + * @since 1.2.7 | |
| 9 | + */ | |
| 10 | +class weForms_Widget extends WP_Widget { | |
| 11 | + | |
| 12 | + /** | |
| 13 | + * weForms_Widget constructor. | |
| 14 | + */ | |
| 15 | + function __construct() { | |
| 16 | + | |
| 17 | + parent::__construct( | |
| 18 | + 'weforms_widget', | |
| 19 | + __('weForms Widget', 'weforms'), | |
| 20 | + array( 'description' => __( 'Add weForms Form to Sidebar', 'weforms' ), ) | |
| 21 | + ); | |
| 22 | + } | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * Render widget | |
| 26 | + * | |
| 27 | + * @return void | |
| 28 | + */ | |
| 29 | + public function widget( $args, $instance ) { | |
| 30 | + | |
| 31 | + $title = apply_filters( 'widget_title', $instance['title'] ); | |
| 32 | + $form_id = apply_filters( 'weforms_widget_form_id', $instance['form_id'] ); | |
| 33 | + | |
| 34 | + echo $args['before_widget']; | |
| 35 | + | |
| 36 | + if ( ! empty( $title ) ) { | |
| 37 | + echo $args['before_title'] . $title . $args['after_title']; | |
| 38 | + } | |
| 39 | + | |
| 40 | + echo do_shortcode( sprintf( '[weforms id ="%s" ]', $form_id ) ); | |
| 41 | + | |
| 42 | + echo $args['after_widget']; | |
| 43 | + } | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * weForms widget backend | |
| 47 | + * | |
| 48 | + * @return void | |
| 49 | + */ | |
| 50 | + public function form( $instance ) { | |
| 51 | + | |
| 52 | + $title = isset( $instance[ 'title' ] ) ? $instance[ 'title' ] : __( 'Form', 'weforms' ); | |
| 53 | + $form_id = isset( $instance[ 'form_id' ] ) ? $instance[ 'form_id' ] : 0; | |
| 54 | + | |
| 55 | + $all_forms = weforms()->form->all(); | |
| 56 | + $options = sprintf( "<option value='%s'>%s</option>", 0, __('Select Form', 'weforms') ); | |
| 57 | + foreach ( $all_forms['forms'] as $form ) { | |
| 58 | + $options.= sprintf( "<option value='%s' %s >%s</option>", $form->id, selected( $form_id, $form->id, false) ,$form->name ); | |
| 59 | + } | |
| 60 | + ?> | |
| 61 | + | |
| 62 | + <p> | |
| 63 | + <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'weforms' ); ?></label> | |
| 64 | + <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /> | |
| 65 | + </p> | |
| 66 | + <p> | |
| 67 | + <label for="<?php echo $this->get_field_id( 'form_id' ); ?>"> <?php _e( 'Form:', 'weforms' ); ?></label> | |
| 68 | + <select id="<?php echo $this->get_field_id( 'form_id' ); ?>" class="widefat" name="<?php echo $this->get_field_name( 'form_id' ); ?>"> | |
| 69 | + <?php echo $options ?> | |
| 70 | + </select> | |
| 71 | + </p> | |
| 72 | + | |
| 73 | + <?php | |
| 74 | + } | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * Updating widget replacing old instances with new | |
| 78 | + * | |
| 79 | + * @return $instance | |
| 80 | + */ | |
| 81 | + public function update( $new_instance, $old_instance ) { | |
| 82 | + | |
| 83 | + $instance = array(); | |
| 84 | + $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : ''; | |
| 85 | + $instance['form_id'] = ( ! empty( $new_instance['form_id'] ) ) ? strip_tags( $new_instance['form_id'] ) : ''; | |
| 86 | + return $instance; | |
| 87 | + } | |
| 88 | + | |
| 89 | +} | |
| 90 | +/** | |
| 91 | + * Register weForms widget | |
| 92 | + * | |
| 93 | + * @return void | |
| 94 | + */ | |
| 95 | +function weforms_register_widget() { | |
| 96 | + register_widget( 'weforms_widget' ); | |
| 97 | +} | |
| 98 | +add_action( 'widgets_init', 'weforms_register_widget' ); | |