integrations
7 years ago
class-strong-form.php
7 years ago
class-strong-log.php
7 years ago
class-strong-mail.php
7 years ago
class-strong-templates.php
7 years ago
class-strong-testimonials-order.php
7 years ago
class-strong-testimonials-privacy.php
7 years ago
class-strong-testimonials-render.php
7 years ago
class-strong-testimonials-shortcode-average.php
7 years ago
class-strong-testimonials-shortcode-count.php
7 years ago
class-strong-testimonials-shortcode.php
7 years ago
class-strong-view-display.php
7 years ago
class-strong-view-form.php
7 years ago
class-strong-view-slideshow.php
7 years ago
class-strong-view.php
7 years ago
class-walker-strong-category-checklist-front.php
7 years ago
deprecated.php
7 years ago
filters.php
7 years ago
functions-activation.php
7 years ago
functions-content.php
7 years ago
functions-image.php
7 years ago
functions-rating.php
7 years ago
functions-template-form.php
7 years ago
functions-template.php
7 years ago
functions-views.php
7 years ago
functions.php
7 years ago
l10n-polylang.php
7 years ago
l10n-wpml.php
7 years ago
post-types.php
7 years ago
retro.php
7 years ago
scripts.php
7 years ago
widget2.php
7 years ago
widget2.php
152 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Strong Testimonials - View widget |
| 4 | * |
| 5 | * @since 1.21.0 |
| 6 | */ |
| 7 | |
| 8 | class Strong_Testimonials_View_Widget extends WP_Widget { |
| 9 | |
| 10 | function __construct() { |
| 11 | |
| 12 | $widget_ops = array( |
| 13 | 'classname' => 'strong-testimonials-view-widget', |
| 14 | 'description' => _x( 'Add one of your testimonial views.', 'widget description', 'strong-testimonials' ), |
| 15 | ); |
| 16 | $control_ops = array( |
| 17 | 'id_base' => 'strong-testimonials-view-widget', |
| 18 | ); |
| 19 | parent::__construct( |
| 20 | 'strong-testimonials-view-widget', |
| 21 | _x( 'Strong Testimonials View', 'widget label', 'strong-testimonials' ), |
| 22 | $widget_ops, |
| 23 | $control_ops |
| 24 | ); |
| 25 | |
| 26 | $this->defaults = array( |
| 27 | 'title' => _x( 'Testimonials', 'widget title', 'strong-testimonials' ), |
| 28 | 'text' => '', |
| 29 | 'filter' => 0, |
| 30 | 'view' => '0', |
| 31 | ); |
| 32 | |
| 33 | } |
| 34 | |
| 35 | function widget( $args, $instance ) { |
| 36 | $data = array_merge( $args, $instance ); |
| 37 | $title = apply_filters( 'widget_title', empty( $data['title'] ) ? '' : $data['title'], $instance, $this->id_base ); |
| 38 | |
| 39 | $widget_text = ! empty( $data['text'] ) ? $data['text'] : ''; |
| 40 | $text = apply_filters( 'widget_text', $widget_text, $data, $this ); |
| 41 | |
| 42 | echo wp_kses_post( $data['before_widget'] ); |
| 43 | |
| 44 | if ( ! empty( $title ) ) { |
| 45 | echo wp_kses_post( $data['before_title'] . $title . $data['after_title'] ); |
| 46 | } |
| 47 | |
| 48 | if ( ! empty( $text ) ) { |
| 49 | ?> |
| 50 | <div class="textwidget"><?php echo ! empty( $data['filter'] ) ? wp_kses_post( wpautop( $text ) ) : wp_kses_post( $text ); ?></div> |
| 51 | <?php |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Catch undefined view to avoid error in the Customizer. |
| 56 | */ |
| 57 | if ( isset( $data['view'] ) && $data['view'] ) { |
| 58 | /** |
| 59 | * Intermediate filter because `the_content` filters are not run on widget text. |
| 60 | * @since 2.11.9 |
| 61 | */ |
| 62 | ob_start(); |
| 63 | strong_testimonials_view( $instance['view'] ); |
| 64 | echo wp_kses_post( apply_filters( 'wpmtst_widget_text', ob_get_clean() ) ); |
| 65 | } |
| 66 | |
| 67 | echo wp_kses_post( $data['after_widget'] ); |
| 68 | } |
| 69 | |
| 70 | function form( $instance ) { |
| 71 | $instance = wp_parse_args( (array) $instance, $this->defaults ); |
| 72 | $filter = isset( $instance['filter'] ) ? $instance['filter'] : 0; |
| 73 | $title = sanitize_text_field( $instance['title'] ); |
| 74 | $views = wpmtst_get_views(); |
| 75 | ?> |
| 76 | <div class="wpmtst-widget-form"> |
| 77 | <p> |
| 78 | <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"> |
| 79 | <?php esc_html_e( 'Title:' ); ?> |
| 80 | </label> |
| 81 | <input class="widefat" type="text" 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( $title ); ?>"> |
| 82 | </p> |
| 83 | <p> |
| 84 | <label for="<?php echo esc_attr( $this->get_field_id( 'text' ) ); ?>"><?php esc_html_e( 'Content:' ); ?></label> |
| 85 | <textarea class="widefat" rows="8" id="<?php echo esc_attr( $this->get_field_id( 'text' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'text' ) ); ?>"><?php echo esc_textarea( $instance['text'] ); ?></textarea> |
| 86 | </p> |
| 87 | <p> |
| 88 | <input id="<?php echo esc_attr( $this->get_field_id( 'filter' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'filter' ) ); ?>" type="checkbox"<?php checked( $filter ); ?> /> <label for="<?php echo esc_attr( $this->get_field_id( 'filter' ) ); ?>"><?php esc_html_e( 'Automatically add paragraphs to above Content only', 'strong-testimonials' ); ?></label> |
| 89 | </p> |
| 90 | <p> |
| 91 | <label for="<?php echo esc_attr( $this->get_field_id( 'view' ) ); ?>"> |
| 92 | <?php echo esc_html_x( 'View:', 'widget setting', 'strong-testimonials' ); ?> |
| 93 | </label> |
| 94 | <select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'view' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'view' ) ); ?>" autocomplete="off"> |
| 95 | <option value=""><?php esc_html_e( '— Select —' ); ?></option> |
| 96 | <?php |
| 97 | foreach ( $views as $view ) { |
| 98 | printf( '<option value="%s" %s>%s</option>', esc_attr( $view['id'] ), selected( $view['id'], $instance['view'] ), esc_html( $view['name'] ) ); |
| 99 | } |
| 100 | ?> |
| 101 | </select> |
| 102 | </p> |
| 103 | </div> |
| 104 | <?php |
| 105 | } |
| 106 | |
| 107 | function update( $new_instance, $old_instance ) { |
| 108 | $instance = $old_instance; |
| 109 | $instance['title'] = sanitize_text_field( $new_instance['title'] ); |
| 110 | if ( current_user_can( 'unfiltered_html' ) ) { |
| 111 | $instance['text'] = $new_instance['text']; |
| 112 | } else { |
| 113 | $instance['text'] = wp_kses_post( stripslashes( $new_instance['text'] ) ); |
| 114 | } |
| 115 | $instance['filter'] = ! empty( $new_instance['filter'] ); |
| 116 | $instance['view'] = sanitize_text_field( $new_instance['view'] ); |
| 117 | return array_merge( $this->defaults, $instance ); |
| 118 | } |
| 119 | |
| 120 | } |
| 121 | |
| 122 | |
| 123 | /** |
| 124 | * Load widget |
| 125 | */ |
| 126 | function wpmtst_load_view_widget() { |
| 127 | register_widget( 'Strong_Testimonials_View_Widget' ); |
| 128 | } |
| 129 | add_action( 'widgets_init', 'wpmtst_load_view_widget' ); |
| 130 | |
| 131 | |
| 132 | /** |
| 133 | * Compatibility: CM Tooltip Glossary |
| 134 | * |
| 135 | * Instead of being registered, the [glossary_exclude] is handled in a late content filter |
| 136 | * which leaves the shortcode behind since we don't run that filter on widget content. |
| 137 | * |
| 138 | * @since 2.11.9 |
| 139 | * |
| 140 | * @param $content |
| 141 | * |
| 142 | * @return mixed |
| 143 | */ |
| 144 | function wpmtst_remove_glossary_exclude( $content ) { |
| 145 | if ( class_exists( 'CMTooltipGlossaryFrontend' ) ) { |
| 146 | $content = str_replace( array( '[glossary_exclude]', '[/glossary_exclude]' ), array( '', '' ), $content ); |
| 147 | } |
| 148 | |
| 149 | return $content; |
| 150 | } |
| 151 | add_filter( 'wpmtst_widget_text', 'wpmtst_remove_glossary_exclude' ); |
| 152 |