opt = ( null !== $astm ) ? $astm->opt : get_option( 'add_search_to_menu' );
}
/**
* Gets the instance of this class.
*
* @return self
*/
public static function getInstance() {
if ( ! ( self::$_instance instanceof self ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Enqueues search menu style and script files.
*/
function enqueue_script_style(){
if ( ! isset( $this->opt['do_not_load_plugin_files']['plugin-css-file'] ) ){
wp_enqueue_style( 'add-search-to-menu-styles', plugins_url( '/public/css/add-search-to-menu.css', ASTM_PLUGIN_FILE ), array(), ASTM_VERSION );
}
if ( ! isset( $this->opt['do_not_load_plugin_files']['plugin-js-file'] ) && ( isset( $this->opt['add_search_to_menu_style'] ) && $this->opt['add_search_to_menu_style'] != 'default' ) ) {
wp_enqueue_script( 'add-search-to-menu-scripts', plugins_url( '/public/js/add-search-to-menu.js', ASTM_PLUGIN_FILE ), array( 'jquery' ), ASTM_VERSION, true );
}
}
/**
* Displays search form in the navigation bar in the front end of site.
*/
function search_menu_item( $items, $args ) {
if ( isset( $this->opt['add_search_to_menu_locations'] ) && isset( $this->opt['add_search_to_menu_locations'][ $args->theme_location ] ) ) {
if ( isset( $this->opt['add_search_to_menu_gcse'] ) && $this->opt['add_search_to_menu_gcse'] != '' ) {
$items .= '
';
} else {
$search_class = isset( $this->opt['add_search_to_menu_classes'] ) ? $this->opt['add_search_to_menu_classes'].' astm-search-menu ' : 'astm-search-menu ';
$search_class .= isset( $this->opt['add_search_to_menu_style'] ) ? $this->opt['add_search_to_menu_style'] : 'default';
$title = isset( $this->opt['add_search_to_menu_title'] ) ? $this->opt['add_search_to_menu_title'] : '';
$items .= '';
if ( $this->opt['add_search_to_menu_style'] != 'default' ){
$items .= '';
if ( '' == $title ) {
$items .= '
';
} else {
$items .= $title;
}
$items .= ' ';
}
$items .= get_search_form( false );
if ( isset( $this->opt['add_search_to_menu_close_icon'] ) && $this->opt['add_search_to_menu_close_icon'] ) {
$items .= '
';
}
$items .= ' ';
}
}
return $items;
}
/**
* Displays search form in mobile header in the front end of site.
*/
function search_in_header() {
$items = '';
if ( isset( $this->opt['add_search_to_menu_gcse'] ) && $this->opt['add_search_to_menu_gcse'] != '' ) {
$items .= '';
} else {
$search_class = isset( $this->opt['add_search_to_menu_classes'] ) ? $this->opt['add_search_to_menu_classes'].' astm-search-menu ' : 'astm-search-menu ';
$search_class .= isset( $this->opt['add_search_to_menu_style'] ) ? $this->opt['add_search_to_menu_style'] : 'default';
$title = isset( $this->opt['add_search_to_menu_title'] ) ? $this->opt['add_search_to_menu_title'] : '';
$items .= '';
}
echo $items;
}
/**
* Filters search results.
*/
function search_filter( $query ) {
if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) {
$query->set( 'post_type', $this->opt['add_search_to_menu_posts'] );
}
}
/**
* Adds custom CSS code in the site front end.
*/
function custom_css() {
if ( isset( $this->opt['add_search_to_menu_css'] ) && $this->opt['add_search_to_menu_css'] != '' ) {
echo '';
}
}
}
}