opt = $is; } else { $this->opt = Ivory_Search::load_options(); } } /** * Gets the instance of this class. * * @return self */ public static function getInstance() { if ( !self::$_instance instanceof self ) { self::$_instance = new self(); } return self::$_instance; } /** * Displays settings sections having custom markup. */ public function is_do_settings_sections( $page, $sec ) { global $wp_settings_sections, $wp_settings_fields ; if ( !isset( $wp_settings_sections[$page] ) ) { return; } $section = (array) $wp_settings_sections[$page][$sec]; if ( $section['title'] ) { echo "

{$section['title']}

\n" ; } if ( $section['callback'] ) { call_user_func( $section['callback'], $section ); } if ( !isset( $wp_settings_fields ) || !isset( $wp_settings_fields[$page] ) || !isset( $wp_settings_fields[$page][$section['id']] ) ) { return; } echo '
' ; $this->is_do_settings_fields( $page, $section['id'] ); echo '
' ; } /** * Displays settings fields having custom markup. */ public function is_do_settings_fields( $page, $section ) { global $wp_settings_fields ; if ( !isset( $wp_settings_fields[$page][$section] ) ) { return; } foreach ( (array) $wp_settings_fields[$page][$section] as $field ) { $class = ''; if ( !empty($field['args']['class']) ) { $class = ' class="' . esc_attr( $field['args']['class'] ) . '"'; } if ( !empty($field['args']['label_for']) ) { echo '

' ; } else { echo '

' . $field['title'] ; } if ( 'Header Search' == $field['title'] || 'Extras' == $field['title'] ) { echo '' . esc_html__( 'Expand All', 'ivory-search' ) . '' ; } echo '

' ; call_user_func( $field['callback'], $field['args'] ); echo '
' ; } } /** * Registers plugin settings fields. */ function register_settings_fields() { if ( !empty($GLOBALS['pagenow']) && 'options.php' === $GLOBALS['pagenow'] ) { if ( isset( $_POST['is_menu_search'] ) ) { add_filter( 'whitelist_options', function ( $whitelist_options ) { $whitelist_options['ivory_search'][0] = 'is_menu_search'; return $whitelist_options; } ); } } if ( !isset( $_GET['tab'] ) || 'settings' == $_GET['tab'] ) { add_settings_section( 'ivory_search_settings', '', array( $this, 'settings_section_desc' ), 'ivory_search' ); add_settings_field( 'ivory_search_header', __( 'Header Search', 'ivory-search' ), array( $this, 'header' ), 'ivory_search', 'ivory_search_settings' ); add_settings_field( 'ivory_search_footer', __( 'Footer Search', 'ivory-search' ), array( $this, 'footer' ), 'ivory_search', 'ivory_search_settings' ); add_settings_field( 'ivory_search_display_in_header', __( 'Mobile Search', 'ivory-search' ), array( $this, 'menu_search_in_header' ), 'ivory_search', 'ivory_search_settings' ); add_settings_field( 'ivory_search_css', __( 'Custom CSS', 'ivory-search' ), array( $this, 'custom_css' ), 'ivory_search', 'ivory_search_settings' ); add_settings_field( 'ivory_search_stopwords', __( 'Stopwords', 'ivory-search' ), array( $this, 'stopwords' ), 'ivory_search', 'ivory_search_settings' ); add_settings_field( 'ivory_search_synonyms', __( 'Synonyms', 'ivory-search' ), array( $this, 'synonyms' ), 'ivory_search', 'ivory_search_settings' ); add_settings_field( 'not_load_files', __( 'Plugin Files', 'ivory-search' ), array( $this, 'plugin_files' ), 'ivory_search', 'ivory_search_settings' ); add_settings_field( 'ivory_search_extras', __( 'Extras', 'ivory-search' ), array( $this, 'extras' ), 'ivory_search', 'ivory_search_settings' ); register_setting( 'ivory_search', 'is_settings' ); } else { if ( isset( $_GET['tab'] ) && 'menu-search' == $_GET['tab'] ) { add_settings_section( 'ivory_search_section', '', array( $this, 'menu_search_section_desc' ), 'ivory_search' ); add_settings_field( 'ivory_search_locations', __( 'Menu Search Form Settings', 'ivory-search' ), array( $this, 'menu_settings' ), 'ivory_search', 'ivory_search_section' ); register_setting( 'ivory_search', 'is_menu_search' ); } } } /** * Displays Search To Menu section description text. */ function menu_search_section_desc() { echo '

' . __( 'Display search in menu and configure it using below options.', 'ivory-search' ) . '

' ; } /** * Displays Settings section description text. */ function settings_section_desc() { echo '

' . __( 'Make search changes on entire website using below options.', 'ivory-search' ) . '

' ; } /** * Displays menu settings fields. */ function menu_settings() { /** * Displays choose menu locations field. */ $content = __( 'Display search form on selected menu.', 'ivory-search' ); IS_Help::help_info( $content ); $html = ''; $check_value = ''; $menus = get_registered_nav_menus(); if ( !empty($menus) ) { foreach ( $menus as $location => $description ) { if ( has_nav_menu( $location ) ) { $check_value = ( isset( $this->opt['menus'][$location] ) ? $this->opt['menus'][$location] : 0 ); $html .= '

'; } } if ( '' === $check_value ) { $html = '' . sprintf( __( 'Please assign menu to navigation menu location in the %sMenus screen%s.', 'ivory-search' ), '', '' ) . ''; } } else { $html = __( 'Navigation menu location is not registered on the site.', 'ivory-search' ); } echo '
' . $html . '
' ; if ( !isset( $this->opt['menus'] ) || '' === $check_value ) { return; } echo '

' ; /** * Displays form style field. */ $content = __( 'Select menu search form style.', 'ivory-search' ); IS_Help::help_info( $content ); $styles = array( 'default' => __( 'Default', 'ivory-search' ), 'dropdown' => __( 'Dropdown', 'ivory-search' ), 'sliding' => __( 'Sliding', 'ivory-search' ), 'full-width-menu' => __( 'Full Width', 'ivory-search' ), 'popup' => __( 'Popup', 'ivory-search' ), ); if ( empty($this->opt) || !isset( $this->opt['menu_style'] ) ) { $this->opt['menu_style'] = 'default'; } $html = ''; $check_value = ( isset( $this->opt['menu_style'] ) ? $this->opt['menu_style'] : 'default' ); foreach ( $styles as $key => $style ) { $html .= '

'; $html .= ''; $html .= '

'; } echo '
' . $html . '


' ; if ( 'default' != $check_value ) { if ( 'popup' != $check_value ) { /** * Displays search form close icon field. */ $check_value = ( isset( $this->opt['menu_close_icon'] ) ? $this->opt['menu_close_icon'] : 0 ); $check_string = checked( 'menu_close_icon', $check_value, false ); $html = ''; echo '
' . $html . '


' ; } /** * Displays search menu title field. */ $content = __( 'Add menu title to display in place of search icon.', 'ivory-search' ); IS_Help::help_info( $content ); $this->opt['menu_title'] = ( isset( $this->opt['menu_title'] ) ? $this->opt['menu_title'] : '' ); $html = ''; echo '
' . $html . '


' ; } /** * Displays search menu classes field. */ $content = __( 'Add class to search form menu item.', 'ivory-search' ); IS_Help::help_info( $content ); $this->opt['menu_classes'] = ( isset( $this->opt['menu_classes'] ) ? $this->opt['menu_classes'] : '' ); $html = ''; $html .= '
'; echo '
' . $html . '


' ; /** * Displays menu search form field. */ $content = __( 'Select search form that will control menu search functionality.', 'ivory-search' ); IS_Help::help_info( $content ); $html = ''; $args = array( 'numberposts' => -1, 'post_type' => 'is_search_form', 'order' => 'ASC', ); $posts = get_posts( $args ); if ( !empty($posts) ) { $check_value = ( isset( $this->opt['menu_search_form'] ) ? $this->opt['menu_search_form'] : 0 ); $check_value = ( $check_value ? $check_value : 'default' ); $html .= ''; if ( $check_value ) { $html .= ' ' . esc_html__( "Edit Search Form", 'ivory-search' ) . ''; } else { $html .= ' ' . esc_html__( "Create New", 'ivory-search' ) . ''; } } echo '
' . $html . '


' ; /** * Displays google cse field. */ $content = __( 'Add Google Custom Search( CSE ) search form code that will replace default search form.', 'ivory-search' ); IS_Help::help_info( $content ); $this->opt['menu_gcse'] = ( isset( $this->opt['menu_gcse'] ) ? $this->opt['menu_gcse'] : '' ); $html = ''; echo '
' . $html . '
' ; } /** * Displays search form in site header. */ function header() { $content = __( 'Select search form to display in site header.', 'ivory-search' ); IS_Help::help_info( $content ); $html = ''; $args = array( 'numberposts' => -1, 'post_type' => 'is_search_form', ); $posts = get_posts( $args ); if ( !empty($posts) ) { $check_value = ( isset( $this->opt['header_search'] ) ? $this->opt['header_search'] : 0 ); $html .= ''; if ( $check_value && get_post_type( $check_value ) ) { $html .= ' ' . esc_html__( "Edit", 'ivory-search' ) . ''; } else { $html .= ' ' . esc_html__( "Create New", 'ivory-search' ) . ''; } } echo '
' . $html . '
' ; } /** * Displays search form in site footer. */ function footer() { $content = __( 'Select search form to display in site footer.', 'ivory-search' ); IS_Help::help_info( $content ); $html = ''; $args = array( 'numberposts' => -1, 'post_type' => 'is_search_form', ); $posts = get_posts( $args ); if ( !empty($posts) ) { $check_value = ( isset( $this->opt['footer_search'] ) ? $this->opt['footer_search'] : 0 ); $html .= ''; if ( $check_value && get_post_type( $check_value ) ) { $html .= ' ' . esc_html__( "Edit", 'ivory-search' ) . ''; } else { $html .= ' ' . esc_html__( "Create New", 'ivory-search' ) . ''; } } echo '
' . $html . '
' ; } /** * Displays display in header field. */ function menu_search_in_header() { $check_value = ( isset( $this->opt['header_menu_search'] ) ? $this->opt['header_menu_search'] : 0 ); $check_string = checked( 'header_menu_search', $check_value, false ); $html = ''; echo '
' . $html . '

' ; $html = ''; $content = __( 'If this site uses cache then please select the below option to display search form on mobile.', 'ivory-search' ); IS_Help::help_info( $content ); $check_value = ( isset( $this->opt['site_uses_cache'] ) ? $this->opt['site_uses_cache'] : 0 ); $check_string = checked( 'site_uses_cache', $check_value, false ); $html .= ''; echo '
' . $html . '
' ; } /** * Displays custom css field. */ function custom_css() { $content = __( 'Add custom css code.', 'ivory-search' ); IS_Help::help_info( $content ); $this->opt['custom_css'] = ( isset( $this->opt['custom_css'] ) ? $this->opt['custom_css'] : '' ); $html = ''; echo '
' . $html . '
' ; } /** * Displays stopwords field. */ function stopwords() { $content = __( 'Enter stopwords here that will not be searched.', 'ivory-search' ); IS_Help::help_info( $content ); $this->opt['stopwords'] = ( isset( $this->opt['stopwords'] ) ? $this->opt['stopwords'] : '' ); $html = ''; $html .= '
'; echo '
' . $html . '
' ; } /** * Displays synonyms field. */ function synonyms() { $content = __( 'Add synonyms here to make the searches find better results.', 'ivory-search' ); $content .= '

' . __( 'If you add bird = crow to the list of synonyms, searches for bird automatically become a search for bird crow and will thus match to posts that include either bird or crow.', 'ivory-search' ); $content .= '

' . __( 'This only works for search forms configured to search any of the search terms(OR) and not all search terms(AND) in the search form Options.', 'ivory-search' ) . ''; IS_Help::help_info( $content ); $this->opt['synonyms'] = ( isset( $this->opt['synonyms'] ) ? $this->opt['synonyms'] : '' ); $html = ''; $html .= '
'; $html .= '
'; echo '
' . $html . '
' ; $html = ''; } /** * Displays do not load plugin files field. */ function plugin_files() { $content = __( 'Enable below options to disable loading of plugin CSS and JavaScript files.', 'ivory-search' ); IS_Help::help_info( $content ); $styles = array( 'css' => __( 'Do not load plugin CSS files', 'ivory-search' ), 'js' => __( 'Do not load plugin JavaScript files', 'ivory-search' ), ); $html = ''; foreach ( $styles as $key => $file ) { $check_value = ( isset( $this->opt['not_load_files'][$key] ) ? $this->opt['not_load_files'][$key] : 0 ); $check_string = checked( $key, $check_value, false ); if ( 'js' == $key ) { $html .= '
'; } $html .= '
'; $html .= ''; if ( 'css' == $key ) { $html .= '
'; $html .= '
' . plugins_url( '/public/css/ivory-search.css', IS_PLUGIN_FILE ) . ''; $html .= '
'; } else { $html .= '
'; $html .= '
' . plugins_url( '/public/js/ivory-search.js', IS_PLUGIN_FILE ) . ''; $html .= '
' . plugins_url( '/public/js/is-highlight.js', IS_PLUGIN_FILE ) . ''; $html .= '
' . plugins_url( '/public/js/ivory-ajax-search.js', IS_PLUGIN_FILE ) . ''; } $html .= '
'; } echo '
' . $html . '
' ; } function extras() { /** * Disables search functionality on whole site. */ $check_value = ( isset( $this->opt['disable'] ) ? $this->opt['disable'] : 0 ); $disable = checked( 1, $check_value, false ); $html = ''; echo '
' . $html . '


' ; /** * Controls default search functionality. */ $content = __( 'Warning: Use with caution.', 'ivory-search' ); IS_Help::help_info( $content ); $check_value = ( isset( $this->opt['default_search'] ) ? $this->opt['default_search'] : 0 ); $disable = checked( 1, $check_value, false ); $html = ''; echo '
' . $html . '
' ; } }