prefix = Easy_get_prefix(); /* Set the widget textdomain. */ $this->textdomain = Easy_get_textdomain(); /* Set up the widget options. */ $widget_options = array( 'classname' => 'search', 'description' => esc_html__( 'An advanced widget that gives you total control over the output of your search form.', $this->textdomain ) ); /* Set up the widget control options. */ $control_options = array( 'width' => 525, 'height' => 350, 'id_base' => "{$this->prefix}-search" ); /* Create the widget. */ $this->WP_Widget( "{$this->prefix}-search", esc_attr__( 'Search', $this->textdomain ), $widget_options, $control_options ); } /** * Outputs the widget based on the arguments input through the widget controls. * @since 0.6 */ function widget( $args, $instance ) { extract( $args ); /* Output the theme's $before_widget wrapper. */ echo $before_widget; /* If a title was input by the user, display it. */ if ( !empty( $instance['title'] ) ) echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title; /* If the user chose to use the theme's search form, load it. */ if ( !empty( $instance['theme_search'] ) ) { get_search_form(); } /* Else, create the form based on the user-selected arguments. */ else { /* Set up some variables for the search form. */ global $search_form_num; $search_num = ( ( $search_form_num ) ? '-' . esc_attr( $search_form_num ) : '' ); $search_text = ( ( is_search() ) ? esc_attr( get_search_query() ) : esc_attr( $instance['search_text'] ) ); /* Open the form. */ $search = '
'; /* If a search label was set, add it. */ if ( !empty( $instance['search_label'] ) ) $search .= ''; /* Search form text input. */ $search .= ''; /* Search form submit button. */ if ( $instance['search_submit'] ) $search .= ''; /* Close the form. */ $search .= '
'; /* Display the form. */ echo $search; $search_form_num++; } /* Close the theme's widget wrapper. */ echo $after_widget; } /** * Updates the widget control options for the particular instance of the widget. * @since 0.6 */ function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags( $new_instance['title'] ); $instance['search_label'] = strip_tags( $new_instance['search_label'] ); $instance['search_text'] = strip_tags( $new_instance['search_text'] ); $instance['search_submit'] = strip_tags( $new_instance['search_submit'] ); $instance['theme_search'] = ( isset( $new_instance['theme_search'] ) ? 1 : 0 ); return $instance; } /** * Displays the widget control options in the Widgets admin screen. * @since 0.6 */ function form( $instance ) { /* Set up the default form values. */ $defaults = array( 'title' => esc_attr__( 'Search', $this->textdomain ), 'theme_search' => false, 'search_label' => '', 'search_text' => '', 'search_submit' => '' ); /* Merge the user-selected arguments with the defaults. */ $instance = wp_parse_args( (array) $instance, $defaults ); ?>