13 'classname' =>
'widget_gravityview_search',
14 'description' => __(
'A search form for a specific GravityView.',
'gk-gravityview')
17 $widget_display = array(
21 parent::__construct(
'gravityview_search', __(
'GravityView Search',
'gk-gravityview' ), $widget_ops, $widget_display );
28 add_filter(
'gravityview_fe_search_criteria', array( $gravityview_widget,
'filter_entries' ), 10, 3 );
31 add_filter(
'gravityview_template_paths', array( $gravityview_widget,
'add_template_path' ) );
33 unset( $gravityview_widget );
37 if( !class_exists(
'GravityView_Widget_Search' ) ) {
47 'search_fields' =>
'',
49 'search_mode' =>
'any' 55 if ( defined(
'REST_REQUEST' ) && REST_REQUEST ) {
60 if( empty( $instance[
'view_id'] ) ) {
62 gravityview()->log->debug(
'No View ID has been defined. Not showing the widget.', array(
'data' => $instance ) );
67 if ( ! class_exists(
'GravityView_View' ) ) {
68 gravityview()->log->debug(
'GravityView_View does not exist. Not showing the widget.' );
73 $title = apply_filters(
'widget_title', empty( $instance[
'title'] ) ?
'' : $instance[
'title'], $instance, $this->id_base );
75 echo
$args[
'before_widget'];
78 echo $args[
'before_title'] .
$title . $args[
'after_title'];
82 $instance[
'search_layout'] = apply_filters(
'gravityview/widget/search/layout',
'vertical', $instance );
84 $instance[
'context'] =
'wp_widget';
104 echo $args[
'after_widget'];
110 public function update( $new_instance, $old_instance ) {
112 $instance = $old_instance;
114 if( $this->is_preview() ) {
119 $new_instance = wp_parse_args( (array) $new_instance, self::get_defaults() );
121 $instance[
'title'] = strip_tags( $new_instance[
'title'] );
122 $instance[
'view_id'] = absint( $new_instance[
'view_id'] );
123 $instance[
'search_fields'] = $new_instance[
'search_fields'];
124 $instance[
'post_id'] = $new_instance[
'post_id'];
125 $instance[
'search_clear'] = $new_instance[
'search_clear'];
126 $instance[
'search_mode'] = $new_instance[
'search_mode'];
131 $instance[
'error_post_id'] = is_wp_error( $is_valid_embed_id ) ? $is_valid_embed_id->get_error_message() : NULL;
134 $instance[
'updated'] = 1;
142 public function form( $instance ) {
145 if( $this->is_preview() ) {
147 $warning = sprintf( esc_html__(
'This widget is not configurable from this screen. Please configure it on the %sWidgets page%s.',
'gk-gravityview' ),
'<a href="'.admin_url(
'widgets.php').
'">',
'</a>' );
154 $instance = wp_parse_args( (array) $instance, self::get_defaults() );
156 $title = $instance[
'title'];
158 $post_id = $instance[
'post_id'];
159 $search_fields = $instance[
'search_fields'];
160 $search_clear = $instance[
'search_clear'];
161 $search_mode = $instance[
'search_mode'];
166 if( empty( $views ) ) { ?>
167 <div
id=
"select_gravityview_view">
174 <p><label
for=
"<?php echo $this->get_field_id('title'); ?>"><?php _e(
'Title:',
'gk-gravityview'); ?> <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 ); ?>" /></label></p>
181 if( isset( $instance[
'updated'] ) && empty( $instance[
'view_id'] ) ) {
183 <div
class=
"error inline hide-on-view-change">
184 <p><?php esc_html_e(
'Please select a View to search.',
'gk-gravityview'); ?></p>
192 <label
for=
"gravityview_view_id"><?php _e(
'View:',
'gk-gravityview' ); ?></label>
193 <select
id=
"gravityview_view_id" name=
"<?php echo $this->get_field_name('view_id'); ?>" class=
"widefat">
194 <option value=
""><?php esc_html_e(
'— Select a View —',
'gk-gravityview' ); ?></option>
196 foreach( $views as $view_option ) {
197 $title = empty( $view_option->post_title ) ? __(
'(no title)',
'gk-gravityview') : $view_option->post_title;
198 echo
'<option value="'. $view_option->ID .
'" ' . selected( esc_attr(
$view_id ), $view_option->ID,
false ) .
'>'. esc_html( sprintf(
'%s #%d',
$title, $view_option->ID ) ) .
'</option>';
210 if( !empty( $instance[
'error_post_id'] ) ) {
212 <div
class=
"error inline">
213 <p><?php echo $instance[
'error_post_id']; ?></p>
221 <label
for=
"<?php echo $this->get_field_id('post_id'); ?>"><?php esc_html_e(
'If Embedded, Page ID:',
'gk-gravityview' ); ?></label>
222 <input
class=
"code" size=
"3" id=
"<?php echo $this->get_field_id('post_id'); ?>" name=
"<?php echo $this->get_field_name('post_id'); ?>" type=
"text" value=
"<?php echo esc_attr( $post_id ); ?>" />
223 <span
class=
"howto gv-howto"><?php
224 esc_html_e(
'To have a search performed on an embedded View, enter the ID of the post or page where the View is embedded.',
'gk-gravityview' );
225 echo
' '.gravityview_get_link(
'https://docs.gravityview.co/article/222-the-search-widget', __(
'Learn more…',
'gk-gravityview' ),
'target=_blank' );
230 <label
for=
"<?php echo $this->get_field_id('search_clear'); ?>"><?php esc_html_e(
'Show Clear button',
'gk-gravityview' ); ?>:</label>
231 <input name=
"<?php echo $this->get_field_name('search_clear'); ?>" type=
"hidden" value=
"0">
232 <input
id=
"<?php echo $this->get_field_id('search_clear'); ?>" name=
"<?php echo $this->get_field_name('search_clear'); ?>" type=
"checkbox" class=
"checkbox" value=
"1" <?php checked( $search_clear, 1,
true ); ?>>
236 <label><?php esc_html_e(
'Search Mode',
'gk-gravityview' ); ?>:</label>
237 <label
for=
"<?php echo $this->get_field_id('search_mode'); ?>_any">
238 <input
id=
"<?php echo $this->get_field_id('search_mode'); ?>_any" name=
"<?php echo $this->get_field_name('search_mode'); ?>" type=
"radio" class=
"radio" value=
"any" <?php checked( $search_mode,
'any',
true ); ?>>
239 <?php esc_html_e(
'Match Any Fields',
'gk-gravityview' ); ?>
241 <label
for=
"<?php echo $this->get_field_id('search_mode'); ?>_all">
242 <input
id=
"<?php echo $this->get_field_id('search_mode'); ?>_all" name=
"<?php echo $this->get_field_name('search_mode'); ?>" type=
"radio" class=
"radio" value=
"all" <?php checked( $search_mode,
'all',
true ); ?>>
243 <?php esc_html_e(
'Match All Fields',
'gk-gravityview' ); ?>
245 <span
class=
"howto gv-howto"><?php esc_html_e(
'Should search results match all search fields, or any?',
'gk-gravityview' ); ?></span
251 <div style=
"margin-bottom: 1em;">
252 <label
class=
"screen-reader-text" for=
"<?php echo $this->get_field_id('search_fields'); ?>"><?php _e(
'Searchable fields:',
'gk-gravityview' ); ?></label>
253 <div
class=
"gv-widget-search-fields" title=
"<?php esc_html_e('Search Fields', 'gk-gravityview'); ?>">
254 <input
id=
"<?php echo $this->get_field_id('search_fields'); ?>" name=
"<?php echo $this->get_field_name('search_fields'); ?>" type=
"hidden" value=
"<?php echo esc_attr( $search_fields ); ?>" class=
"gv-search-fields-value">
262 jQuery(
'#<?php echo $this->get_field_id( 'view_id
' ); ?>').trigger(
'change' );
static getInstance( $passed_post=NULL)
static get_meta_form_id( $view_id)
Get the Gravity Forms form ID connected to a View.
static is_valid_embed_id( $post_id='', $view_id='', $empty_is_valid=false)
Checks if the passed post id has the passed View id embedded.
static no_views_text()
Get text for no views found.
If this file is called directly, abort.
static get_floaty()
Get an image of our intrepid explorer friend.
gravityview()
The main GravityView wrapper function.
static get_all_views( $args=array())
Get all existing Views.
static get_form( $form_id)
Returns the form object for a given Form ID.