PluginProbe
ElasticPress / 5.3.5
ElasticPress v5.3.5
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
← All changes | includes/classes/Feature/Comments/Widget.php +19 -60 4.3.05.3.5 View file →
@@ -7,12 +7,8 @@
7 7 */
8 8
9 9 namespace ElasticPress\Feature\Comments;
10 10
11 -use \WP_Widget as WP_Widget;
12 -use ElasticPress\Features as Features;
13 -use ElasticPress\Utils;
14 -
15 11 if ( ! defined( 'ABSPATH' ) ) {
16 12 exit; // Exit if accessed directly.
17 13 }
18 14
@@ -18,9 +14,9 @@
18 14
19 15 /**
20 16 * Search comment widget class
21 17 */
22 -class Widget extends WP_Widget {
18 +class Widget extends \WP_Widget {
23 19
24 20 /**
25 21 * Initialize the widget
26 22 *
@@ -26,9 +22,13 @@
26 22 *
27 23 * @since 3.6.0
28 24 */
29 25 public function __construct() {
30 - $options = array( 'description' => esc_html__( 'A search form for comments.', 'elasticpress' ) );
26 + $options = array(
27 + 'description' => esc_html__( 'A search form for comments.', 'elasticpress' ),
28 + 'show_instance_in_rest' => true,
29 + );
30 +
31 31 parent::__construct( 'ep-comments', esc_html__( 'ElasticPress - Comments', 'elasticpress' ), $options );
32 32 }
33 33
34 34 /**
@@ -47,16 +47,18 @@
47 47 if ( ! empty( $instance['title'] ) ) {
48 48 echo wp_kses_post( $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'] );
49 49 }
50 50
51 + $wrapper_id = 'ep-search-comments-' . uniqid();
51 52 ?>
52 - <div class="ep-widget-search-comments">
53 + <div id="<?php echo esc_attr( $wrapper_id ); ?>" class="ep-widget-search-comments">
53 54 <?php
54 55 if ( ! empty( $instance['post_type'] ) ) {
55 56 ?>
56 57 <input
58 + class="ep-widget-search-comments-post-type"
57 59 type="hidden"
58 - id="ep-widget-search-comments-post-type"
60 + id="<?php echo esc_attr( $wrapper_id ); ?>-post-type"
59 61 value="<?php echo esc_attr( implode( ',', $instance['post_type'] ) ); ?>"
60 62 />
61 63 <?php
62 64 }
@@ -66,45 +68,11 @@
66 68 <?php
67 69 $search_comments_html = ob_get_clean();
68 70
69 71 // Enqueue Script & Styles
70 - wp_enqueue_script(
71 - 'elasticpress-comments',
72 - EP_URL . 'dist/js/comments-script.min.js',
73 - Utils\get_asset_info( 'comments-script', 'dependencies' ),
74 - Utils\get_asset_info( 'comments-script', 'version' ),
75 - true
76 - );
72 + wp_enqueue_script( 'elasticpress-comments' );
73 + wp_enqueue_style( 'elasticpress-comments' );
77 74
78 - wp_enqueue_style(
79 - 'elasticpress-comments',
80 - EP_URL . 'dist/css/comments-styles.min.css',
81 - Utils\get_asset_info( 'comments-styles', 'dependencies' ),
82 - Utils\get_asset_info( 'comments-styles', 'version' )
83 - );
84 -
85 - $default_script_data = [
86 - 'noResultsFoundText' => esc_html__( 'We could not find any results', 'elasticpress' ),
87 - 'minimumLengthToSearch' => 2,
88 - 'restApiEndpoint' => get_rest_url( null, 'elasticpress/v1/comments' ),
89 - ];
90 -
91 - /**
92 - * Filter the l10n data attached to the Widget Search Comments script
93 - *
94 - * @since 3.6.0
95 - * @hook ep_comment_search_widget_l10n_data_script
96 - * @param {array} $default_script_data Default data attached to the script
97 - * @return {array} New l10n data to be attached
98 - */
99 - $script_data = apply_filters( 'ep_comment_search_widget_l10n_data_script', $default_script_data );
100 -
101 - wp_localize_script(
102 - 'elasticpress-comments',
103 - 'epc',
104 - $script_data
105 - );
106 -
107 75 // phpcs:disable
108 76 /**
109 77 * Filter comment search widget HTML
110 78 *
@@ -129,18 +97,9 @@
129 97 public function form( $instance ) {
130 98 $title = ( isset( $instance['title'] ) ) ? $instance['title'] : '';
131 99 $post_type = ( isset( $instance['post_type'] ) ) ? $instance['post_type'] : [];
132 100
133 - $post_types_options = array_map(
134 - 'get_post_type_object',
135 - array_filter(
136 - Features::factory()->get_registered_feature( 'search' )->get_searchable_post_types(),
137 - function ( $post_type ) {
138 - return post_type_supports( $post_type, 'comments' );
139 - }
140 - )
141 - );
142 -
101 + $post_types_options = Comments::get_searchable_post_types();
143 102 ?>
144 103 <p>
145 104 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
146 105 <?php esc_html_e( 'Title:', 'elasticpress' ); ?>
@@ -152,20 +111,20 @@
152 111 <label for="<?php echo esc_attr( $this->get_field_id( 'post_type' ) ); ?>">
153 112 <?php esc_html_e( 'Search for comments on:', 'elasticpress' ); ?>
154 113 </label>
155 114
156 - <?php foreach ( $post_types_options as $indexable_post_type ) : ?>
115 + <?php foreach ( $post_types_options as $indexable_post_type => $label ) : ?>
157 116 <p>
158 117 <input
159 118 class="checkbox"
160 119 type="checkbox"
161 - id="<?php echo esc_attr( $this->get_field_id( 'post_type' ) . '-' . $indexable_post_type->name ); ?>"
120 + id="<?php echo esc_attr( $this->get_field_id( 'post_type' ) . '-' . $indexable_post_type ); ?>"
162 121 name="<?php echo esc_attr( $this->get_field_name( 'post_type' ) ); ?>[]"
163 - value="<?php echo esc_attr( $indexable_post_type->name ); ?>"
164 - <?php checked( in_array( $indexable_post_type->name, $post_type, true ) ); ?>
122 + value="<?php echo esc_attr( $indexable_post_type ); ?>"
123 + <?php checked( in_array( $indexable_post_type, $post_type, true ) ); ?>
165 124 />
166 - <label for="<?php echo esc_attr( $this->get_field_id( 'post_type' ) . '-' . $indexable_post_type->name ); ?>">
167 - <?php echo esc_html( $indexable_post_type->label ); ?>
125 + <label for="<?php echo esc_attr( $this->get_field_id( 'post_type' ) . '-' . $indexable_post_type ); ?>">
126 + <?php echo esc_html( $label ); ?>
168 127 </label>
169 128 </p>
170 129 <?php endforeach; ?>
171 130 </p>