ivory_search = true;
}
if ( null !== $is ) {
$this->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 '' . $field['title'] . ' ' ;
} else {
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_settings'] ) ) {
add_filter( 'whitelist_options', function ( $whitelist_options ) {
$whitelist_options['ivory_search'][0] = 'is_settings';
return $whitelist_options;
} );
}
}
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',
__( 'Select Menu', 'ivory-search' ),
array( $this, 'menu_locations' ),
'ivory_search',
'ivory_search_section'
);
add_settings_field(
'ivory_search_form',
__( 'Search Form', 'ivory-search' ),
array( $this, 'menu_search_form' ),
'ivory_search',
'ivory_search_section'
);
add_settings_field(
'ivory_search_style',
__( 'Form Style', 'ivory-search' ),
array( $this, 'menu_form_style' ),
'ivory_search',
'ivory_search_section'
);
add_settings_field(
'ivory_search_title',
__( 'Menu Title', 'ivory-search' ),
array( $this, 'menu_title' ),
'ivory_search',
'ivory_search_section'
);
add_settings_field(
'ivory_search_classes',
__( 'Menu Classes', 'ivory-search' ),
array( $this, 'menu_classes' ),
'ivory_search',
'ivory_search_section'
);
add_settings_field(
'ivory_search_gcse',
__( 'Google CSE', 'ivory-search' ),
array( $this, 'menu_google_cse' ),
'ivory_search',
'ivory_search_section'
);
add_settings_field(
'ivory_search_close_icon',
__( 'Close Icon', 'ivory-search' ),
array( $this, 'menu_close_icon' ),
'ivory_search',
'ivory_search_section'
);
register_setting( 'ivory_search', 'is_menu_search' );
} else {
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', 'ivory-search' ),
array( $this, 'header' ),
'ivory_search',
'ivory_search_settings'
);
add_settings_field(
'ivory_search_footer',
__( 'Footer', 'ivory-search' ),
array( $this, 'footer' ),
'ivory_search',
'ivory_search_settings'
);
add_settings_field(
'ivory_search_display_in_header',
__( 'Mobile Display', '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',
__( 'Not load files', 'ivory-search' ),
array( $this, 'plugin_files' ),
'ivory_search',
'ivory_search_settings'
);
add_settings_field(
'ivory_search_disable',
__( 'Disable', 'ivory-search' ),
array( $this, 'disable' ),
'ivory_search',
'ivory_search_settings'
);
add_settings_field(
'ivory_search_default',
__( 'Default Search', 'ivory-search' ),
array( $this, 'default_search' ),
'ivory_search',
'ivory_search_settings'
);
register_setting( 'ivory_search', 'is_settings' );
}
}
}
/**
* Displays Search To Menu section description text.
*/
function menu_search_section_desc()
{
echo '' . __( 'Use below options to display search in menu and configure it.', 'ivory-search' ) . ' ' ;
}
/**
* Displays Settings section description text.
*/
function settings_section_desc()
{
echo '' . __( 'Use below options to make sitewide changes in search.', 'ivory-search' ) . ' ' ;
}
/**
* Displays choose menu locations field.
*/
function menu_locations()
{
$content = __( 'Select menu here where you want to display search form.', 'ivory-search' );
IS_Help::help_info( $content );
$html = '';
$menus = get_registered_nav_menus();
if ( !empty($menus) ) {
$check_value = '';
foreach ( $menus as $location => $description ) {
if ( $this->ivory_search ) {
$check_value = ( isset( $this->opt['menus'][$location] ) ? $this->opt['menus'][$location] : 0 );
} else {
$check_value = ( isset( $this->opt['add_search_to_menu_locations'][$location] ) ? $this->opt['add_search_to_menu_locations'][$location] : 0 );
}
$html .= '';
$html .= ' ' . esc_html( $description ) . '
';
}
} else {
$html = __( 'No navigation menu registered on your site.', 'ivory-search' );
}
echo '' . $html . '
' ;
}
/**
* Displays menu search form field.
*/
function menu_search_form()
{
$content = __( 'Select search form that will control search performed using menu search.', 'ivory-search' );
IS_Help::help_info( $content );
$html = '';
$form_disable = ( is_fs()->is_plan_or_trial( 'pro' ) && $this->is_premium_plugin ? false : true );
if ( $form_disable ) {
$html .= IS_Admin::pro_link();
}
$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' );
$select_disable = ( $form_disable ? 'disabled' : '' );
$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 form style field.
*/
function menu_form_style()
{
$content = __( 'Select form style for the search form displayed in the menu.', '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' ),
);
$popup_disable = ( is_fs()->is_plan_or_trial( 'pro' ) && $this->is_premium_plugin ? false : true );
if ( empty($this->opt) || !isset( $this->opt['add_search_to_menu_style'] ) && !isset( $this->opt['menu_style'] ) ) {
$this->opt['menu_style'] = 'default';
update_option( 'ivory_search', $this->opt );
}
$html = '';
$check_value = ( isset( $this->opt['add_search_to_menu_style'] ) ? $this->opt['add_search_to_menu_style'] : 'default' );
$check_value = ( isset( $this->opt['menu_style'] ) ? $this->opt['menu_style'] : $check_value );
foreach ( $styles as $key => $style ) {
if ( $popup_disable && 'popup' === $key ) {
$html .= '' . IS_Admin::pro_link();
} else {
$html .= '
';
}
$html .= '';
$html .= ' ' . esc_html( $style ) . ' ';
$html .= '
';
}
echo '' . $html . '
' ;
}
/**
* Displays search menu title field.
*/
function menu_title()
{
$content = __( 'Displays set menu title text in place of search icon displays in navigation menu.', 'ivory-search' );
IS_Help::help_info( $content );
$this->opt['add_search_to_menu_title'] = ( isset( $this->opt['add_search_to_menu_title'] ) ? $this->opt['add_search_to_menu_title'] : '' );
$this->opt['menu_title'] = ( isset( $this->opt['menu_title'] ) ? $this->opt['menu_title'] : $this->opt['add_search_to_menu_title'] );
$html = '';
echo '' . $html . '
' ;
}
/**
* Displays search menu classes field.
*/
function menu_classes()
{
$content = __( 'Adds set classes in the search navigation menu item.', 'ivory-search' );
IS_Help::help_info( $content );
$this->opt['add_search_to_menu_classes'] = ( isset( $this->opt['add_search_to_menu_classes'] ) ? $this->opt['add_search_to_menu_classes'] : '' );
$this->opt['menu_classes'] = ( isset( $this->opt['menu_classes'] ) ? $this->opt['menu_classes'] : $this->opt['add_search_to_menu_classes'] );
$html = '';
$html .= '' . esc_html__( "Add classes seperated by space.", 'ivory-search' ) . ' ';
echo '' . $html . '
' ;
}
/**
* Displays google cse field.
*/
function menu_google_cse()
{
$content = __( 'Add only Google Custom Search( CSE ) search form code in the above text box that will replace default search form.', 'ivory-search' );
IS_Help::help_info( $content );
$this->opt['add_search_to_menu_gcse'] = ( isset( $this->opt['add_search_to_menu_gcse'] ) ? $this->opt['add_search_to_menu_gcse'] : '' );
$this->opt['menu_gcse'] = ( isset( $this->opt['menu_gcse'] ) ? $this->opt['menu_gcse'] : $this->opt['add_search_to_menu_gcse'] );
$html = '';
echo '' . $html . '
' ;
}
/**
* Displays search form close icon field.
*/
function menu_close_icon()
{
$check_value = ( isset( $this->opt['add_search_to_menu_close_icon'] ) ? $this->opt['add_search_to_menu_close_icon'] : 0 );
$check_string = checked( 'add_search_to_menu_close_icon', $check_value, false );
if ( $this->ivory_search ) {
$check_value = ( isset( $this->opt['menu_close_icon'] ) ? $this->opt['menu_close_icon'] : 0 );
$check_string = checked( 'menu_close_icon', $check_value, false );
}
$html = '';
$html .= ' ' . esc_html__( 'Display Search Form Close Icon', 'ivory-search' ) . ' ';
echo '' . $html . '
' ;
}
/**
* Displays search form in site header.
*/
function header()
{
$content = __( 'Displays search form in site header using wp_head hook.', '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 = __( 'Displays search form in site footer using wp_footer hook.', '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()
{
$content = __( 'Note: Does not work with caching as this functionality uses the WordPress wp_is_mobile function.', 'ivory-search' );
IS_Help::help_info( $content );
$check_value = ( isset( $this->opt['add_search_to_menu_display_in_header'] ) ? $this->opt['add_search_to_menu_display_in_header'] : 0 );
$check_string = checked( 'add_search_to_menu_display_in_header', $check_value, false );
if ( $this->ivory_search ) {
$check_value = ( isset( $this->opt['header_menu_search'] ) ? $this->opt['header_menu_search'] : 0 );
$check_string = checked( 'header_menu_search', $check_value, false );
}
$html = '';
$html .= ' ' . esc_html__( 'Display search form in header on mobile devices', 'ivory-search' ) . ' ';
echo '' . $html . '
' ;
$html = '';
$content = __( 'Use this option to display search form in your site header and hide the search form on desktop using CSS code.', 'ivory-search' );
IS_Help::help_info( $content );
$check_value = ( isset( $this->opt['astm_site_uses_cache'] ) ? $this->opt['astm_site_uses_cache'] : 0 );
$check_string = checked( 'astm_site_uses_cache', $check_value, false );
if ( $this->ivory_search ) {
$check_value = ( isset( $this->opt['site_uses_cache'] ) ? $this->opt['site_uses_cache'] : 0 );
$check_string = checked( 'site_uses_cache', $check_value, false );
}
$html .= '';
$html .= ' ' . esc_html__( 'This site uses cache', 'ivory-search' ) . ' ';
echo '' . $html . '
' ;
}
/**
* Displays custom css field.
*/
function custom_css()
{
$content = __( 'Add custom css code if any to style search form.', 'ivory-search' );
IS_Help::help_info( $content );
$this->opt['add_search_to_menu_css'] = ( isset( $this->opt['add_search_to_menu_css'] ) ? $this->opt['add_search_to_menu_css'] : '' );
$this->opt['custom_css'] = ( isset( $this->opt['custom_css'] ) ? $this->opt['custom_css'] : $this->opt['add_search_to_menu_css'] );
$html = '';
echo '' . $html . '
' ;
}
/**
* Displays stopwords field.
*/
function stopwords()
{
$content = __( 'Enter words here to add them to the list of stopwords. The stopwords will not be searched.', 'ivory-search' );
$content .= ' ' . __( 'This works with search form.', 'ivory-search' );
IS_Help::help_info( $content );
$this->opt['stopwords'] = ( isset( $this->opt['stopwords'] ) ? $this->opt['stopwords'] : '' );
$html = '';
$html .= '' . esc_html__( "Please separate words with commas.", 'ivory-search' ) . ' ';
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 and in OR searches. In AND searches the synonyms only restrict the search, as now the search only finds posts that contain both bird and crow.', 'ivory-search' );
IS_Help::help_info( $content );
$this->opt['synonyms'] = ( isset( $this->opt['synonyms'] ) ? $this->opt['synonyms'] : '' );
$html = '';
$html .= '' . esc_html__( 'The format here is key = value;. Please separate every synonyms key = value pairs with semicolon.', 'ivory-search' ) . ' ';
$synonyms_disable = ( is_fs()->is_plan_or_trial( 'pro' ) && $this->is_premium_plugin ? '' : ' disabled ' );
$check_value = ( isset( $this->opt['synonyms_and'] ) ? $this->opt['synonyms_and'] : 0 );
$disable = checked( 1, $check_value, false );
if ( '' !== $synonyms_disable ) {
$html .= '' . IS_Admin::pro_link();
} else {
$html .= '
';
}
$html .= ' ';
$html .= ' ' . esc_html__( 'Disable synonyms for the search forms having AND search terms relation.', 'ivory-search' ) . ' ';
echo '
' . $html . '
' ;
}
/**
* Displays do not load plugin files field.
*/
function plugin_files()
{
$content = __( 'Configure to disable loading plugin CSS and JavaScript files.', 'ivory-search' );
IS_Help::help_info( $content );
$styles = array(
'css' => __( 'Plugin CSS File', 'ivory-search' ),
'js' => __( 'Plugin JavaScript File', 'ivory-search' ),
);
$html = '';
foreach ( $styles as $key => $file ) {
$check_value = ( isset( $this->opt['do_not_load_plugin_files']["plugin-{$key}-file"] ) ? $this->opt['do_not_load_plugin_files']["plugin-{$key}-file"] : 0 );
$check_string = checked( "plugin-{$key}-file", $check_value, false );
if ( $this->ivory_search ) {
$check_value = ( isset( $this->opt['not_load_files'][$key] ) ? $this->opt['not_load_files'][$key] : 0 );
$check_string = checked( $key, $check_value, false );
}
$html .= ' ';
$html .= ' ' . esc_html( $file ) . ' ';
if ( 'css' == $key ) {
$html .= '' . esc_html__( 'If checked, you have to add following plugin file code into your child theme CSS file.', 'ivory-search' ) . ' ';
$html .= '' . plugins_url( '/public/css/ivory-search.css', IS_PLUGIN_FILE ) . ' ';
$html .= ' ';
} else {
$html .= '' . esc_html__( "If checked, you have to add following plugin files code into your child theme JavaScript file.", 'ivory-search' ) . ' ';
$html .= '' . plugins_url( '/public/js/ivory-search.js', IS_PLUGIN_FILE ) . ' ';
$html .= '' . plugins_url( '/public/js/is-highlight.js', IS_PLUGIN_FILE ) . ' ';
}
}
echo '' . $html . '
' ;
}
/**
* Disables search functionality on whole site.
*/
function disable()
{
$check_value = ( isset( $this->opt['disable'] ) ? $this->opt['disable'] : 0 );
$disable = checked( 1, $check_value, false );
$html = ' ';
$html .= ' ' . esc_html__( 'Disable search functionality on whole site.', 'ivory-search' ) . ' ';
echo '' . $html . '
' ;
}
/**
* Controls default search functionality.
*/
function default_search()
{
$check_value = ( isset( $this->opt['default_search'] ) ? $this->opt['default_search'] : 0 );
$disable = checked( 1, $check_value, false );
$html = ' ';
$html .= ' ' . esc_html__( 'Do not use default search form to control WordPress default search functionality.', 'ivory-search' ) . ' ';
echo '' . $html . '
' ;
}
}