summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/modules/widgets/search.php')
-rw-r--r--plugins/jetpack/modules/widgets/search.php123
1 files changed, 78 insertions, 45 deletions
diff --git a/plugins/jetpack/modules/widgets/search.php b/plugins/jetpack/modules/widgets/search.php
index b217f1fe..8e176c8c 100644
--- a/plugins/jetpack/modules/widgets/search.php
+++ b/plugins/jetpack/modules/widgets/search.php
@@ -57,11 +57,14 @@ class Jetpack_Search_Widget extends WP_Widget {
*
* @since 5.0.0
*/
- public function __construct() {
+ public function __construct( $name = null ) {
+ if ( empty( $name ) ) {
+ $name = esc_html__( 'Search', 'jetpack' );
+ }
parent::__construct(
Jetpack_Search_Helpers::FILTER_WIDGET_BASE,
/** This filter is documented in modules/widgets/facebook-likebox.php */
- apply_filters( 'jetpack_widget_name', esc_html__( 'Search', 'jetpack' ) ),
+ apply_filters( 'jetpack_widget_name', $name ),
array(
'classname' => 'jetpack-filters widget_search',
'description' => __( 'Replaces the default search with an Elasticsearch-powered search interface and filters.', 'jetpack' ),
@@ -70,9 +73,9 @@ class Jetpack_Search_Widget extends WP_Widget {
if (
Jetpack_Search_Helpers::is_active_widget( $this->id ) &&
- ! Jetpack::is_module_active( 'search' )
+ ! $this->is_search_active()
) {
- Jetpack::activate_module( 'search', false, false );
+ $this->activate_search();
}
if ( is_admin() ) {
@@ -86,6 +89,25 @@ class Jetpack_Search_Widget extends WP_Widget {
}
/**
+ * Check whether search is currently active
+ *
+ * @since 6.3
+ */
+ public function is_search_active() {
+ return Jetpack::is_module_active( 'search' );
+ }
+
+ /**
+ * Activate search
+ *
+ * @since 6.3
+ */
+ public function activate_search() {
+ Jetpack::activate_module( 'search', false, false );
+ }
+
+
+ /**
* Enqueues the scripts and styles needed for the customizer.
*
* @since 5.7.0
@@ -117,19 +139,21 @@ class Jetpack_Search_Widget extends WP_Widget {
JETPACK__VERSION
);
- wp_localize_script( 'jetpack-search-widget-admin', 'jetpack_search_filter_admin', array(
- 'defaultFilterCount' => self::DEFAULT_FILTER_COUNT,
- 'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(),
- 'tracksEventData' => array(
- 'is_customizer' => ( function_exists( 'is_customize_preview' ) && is_customize_preview() ) ? 1 : 0,
- ),
- 'i18n' => array(
- 'month' => Jetpack_Search_Helpers::get_date_filter_type_name( 'month', false ),
- 'year' => Jetpack_Search_Helpers::get_date_filter_type_name( 'year', false ),
- 'monthUpdated' => Jetpack_Search_Helpers::get_date_filter_type_name( 'month', true ),
- 'yearUpdated' => Jetpack_Search_Helpers::get_date_filter_type_name( 'year', true ),
- ),
- ) );
+ wp_localize_script(
+ 'jetpack-search-widget-admin', 'jetpack_search_filter_admin', array(
+ 'defaultFilterCount' => self::DEFAULT_FILTER_COUNT,
+ 'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(),
+ 'tracksEventData' => array(
+ 'is_customizer' => ( function_exists( 'is_customize_preview' ) && is_customize_preview() ) ? 1 : 0,
+ ),
+ 'i18n' => array(
+ 'month' => Jetpack_Search_Helpers::get_date_filter_type_name( 'month', false ),
+ 'year' => Jetpack_Search_Helpers::get_date_filter_type_name( 'year', false ),
+ 'monthUpdated' => Jetpack_Search_Helpers::get_date_filter_type_name( 'month', true ),
+ 'yearUpdated' => Jetpack_Search_Helpers::get_date_filter_type_name( 'year', true ),
+ ),
+ )
+ );
wp_enqueue_script( 'jetpack-search-widget-admin' );
}
@@ -166,7 +190,7 @@ class Jetpack_Search_Widget extends WP_Widget {
return array(
'relevance|DESC' => is_admin() ? esc_html__( 'Relevance (recommended)', 'jetpack' ) : esc_html__( 'Relevance', 'jetpack' ),
'date|DESC' => esc_html__( 'Newest first', 'jetpack' ),
- 'date|ASC' => esc_html__( 'Oldest first', 'jetpack' )
+ 'date|ASC' => esc_html__( 'Oldest first', 'jetpack' ),
);
}
@@ -215,13 +239,16 @@ class Jetpack_Search_Widget extends WP_Widget {
}
public function jetpack_search_populate_defaults( $instance ) {
- $instance = wp_parse_args( (array) $instance, array(
- 'title' => '',
- 'search_box_enabled' => true,
- 'user_sort_enabled' => true,
- 'sort' => self::DEFAULT_SORT,
- 'filters' => array( array() ),
- ) );
+ $instance = wp_parse_args(
+ (array) $instance, array(
+ 'title' => '',
+ 'search_box_enabled' => true,
+ 'user_sort_enabled' => true,
+ 'sort' => self::DEFAULT_SORT,
+ 'filters' => array( array() ),
+ 'post_types' => array(),
+ )
+ );
return $instance;
}
@@ -269,7 +296,8 @@ class Jetpack_Search_Widget extends WP_Widget {
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
echo $args['before_widget'];
- ?><div id="<?php echo esc_attr( $this->id ); ?>-wrapper"><?php
+ ?><div id="<?php echo esc_attr( $this->id ); ?>-wrapper">
+ <?php
if ( ! empty( $title ) ) {
/**
@@ -286,9 +314,9 @@ class Jetpack_Search_Widget extends WP_Widget {
do_action( 'jetpack_search_render_filters_widget_title', $title, $args['before_title'], $args['after_title'] );
}
- $default_sort = isset( $instance['sort'] ) ? $instance['sort'] : self::DEFAULT_SORT;
+ $default_sort = isset( $instance['sort'] ) ? $instance['sort'] : self::DEFAULT_SORT;
list( $orderby, $order ) = $this->sorting_to_wp_query_param( $default_sort );
- $current_sort = "{$orderby}|{$order}";
+ $current_sort = "{$orderby}|{$order}";
// we need to dynamically inject the sort field into the search box when the search box is enabled, and display
// it separately when it's not.
@@ -296,8 +324,9 @@ class Jetpack_Search_Widget extends WP_Widget {
Jetpack_Search_Template_Tags::render_widget_search_form( $instance['post_types'], $orderby, $order );
}
- if ( ! empty( $instance['search_box_enabled'] ) && ! empty( $instance['user_sort_enabled'] ) ): ?>
- <div class="jetpack-search-sort-wrapper">
+ if ( ! empty( $instance['search_box_enabled'] ) && ! empty( $instance['user_sort_enabled'] ) ) :
+ ?>
+ <div class="jetpack-search-sort-wrapper">
<label>
<?php esc_html_e( 'Sort by', 'jetpack' ); ?>
<select class="jetpack-search-sort">
@@ -309,7 +338,8 @@ class Jetpack_Search_Widget extends WP_Widget {
</select>
</label>
</div>
- <?php endif;
+ <?php
+ endif;
if ( $display_filters ) {
/**
@@ -331,7 +361,7 @@ class Jetpack_Search_Widget extends WP_Widget {
$this->maybe_render_sort_javascript( $instance, $order, $orderby );
- echo "</div>";
+ echo '</div>';
echo $args['after_widget'];
}
@@ -438,7 +468,7 @@ class Jetpack_Search_Widget extends WP_Widget {
if ( isset( $new_instance['filter_type'] ) ) {
foreach ( (array) $new_instance['filter_type'] as $index => $type ) {
$count = intval( $new_instance['num_filters'][ $index ] );
- $count = min( 50, $count ); // Set max boundary at 20.
+ $count = min( 50, $count ); // Set max boundary at 50.
$count = max( 1, $count ); // Set min boundary at 1.
switch ( $type ) {
@@ -566,7 +596,7 @@ class Jetpack_Search_Widget extends WP_Widget {
</label>
</p>
- <?php if ( ! $hide_filters ): ?>
+ <?php if ( ! $hide_filters ) : ?>
<script class="jetpack-search-filters-widget__filter-template" type="text/template">
<?php echo $this->render_widget_edit_filter( array(), true ); ?>
</script>
@@ -598,7 +628,7 @@ class Jetpack_Search_Widget extends WP_Widget {
}
/**
- * We need to render HTML in two formats: an Underscore template (client-size)
+ * We need to render HTML in two formats: an Underscore template (client-side)
* and native PHP (server-side). This helper function allows for easy rendering
* of attributes in both formats.
*
@@ -640,15 +670,17 @@ class Jetpack_Search_Widget extends WP_Widget {
* @param bool $is_template Whether this is for an Underscore template or not.
*/
public function render_widget_edit_filter( $filter, $is_template = false ) {
- $args = wp_parse_args( $filter, array(
- 'name' => '',
- 'type' => 'taxonomy',
- 'taxonomy' => '',
- 'post_type' => '',
- 'field' => '',
- 'interval' => '',
- 'count' => self::DEFAULT_FILTER_COUNT,
- ) );
+ $args = wp_parse_args(
+ $filter, array(
+ 'name' => '',
+ 'type' => 'taxonomy',
+ 'taxonomy' => '',
+ 'post_type' => '',
+ 'field' => '',
+ 'interval' => '',
+ 'count' => self::DEFAULT_FILTER_COUNT,
+ )
+ );
$args['name_placeholder'] = Jetpack_Search_Helpers::generate_widget_filter_name( $args );
@@ -765,5 +797,6 @@ class Jetpack_Search_Widget extends WP_Widget {
<a href="#" class="delete"><?php esc_html_e( 'Remove', 'jetpack' ); ?></a>
</p>
</div>
- <?php }
+ <?php
+ }
}