search_form = $search_form;
$this->index_conflicts = $this->get_index_conflicts();
}
function is_name( $string )
{
return preg_match( '/^[A-Za-z][-A-Za-z0-9_:.]*$/', $string );
}
public function add_panel(
$id,
$title,
$callback,
$description
)
{
if ( $this->is_name( $id ) ) {
$this->panels[$id] = array(
'title' => $title,
'callback' => $callback,
'description' => $description,
);
}
}
public function display()
{
if ( empty($this->panels) ) {
return;
}
echo '
' ;
echo sprintf( '', esc_attr( $tab ) ) ;
$this->notice( $tab, $tab . '_panel' );
$callback = $tab . '_panel';
if ( method_exists( $this, $callback ) ) {
$this->{$callback}( $this->search_form );
} else {
_e( 'The requested section does not exist.', 'add-search-to-menu' );
}
echo '
' ;
}
public function notice( $id, $panel )
{
echo '
' ;
}
/**
* Gets all public meta keys of post types
*
* @global Object $wpdb WPDB object
* @return Array array of meta keys
*/
function is_meta_keys()
{
global $wpdb ;
$is_fields = $wpdb->get_results( apply_filters( 'is_meta_keys_query', "select DISTINCT meta_key from {$wpdb->postmeta} pt LEFT JOIN {$wpdb->posts} p ON (pt.post_id = p.ID) where meta_key NOT LIKE '\\_%' ORDER BY meta_key ASC" ) );
$meta_keys = array();
if ( is_array( $is_fields ) && !empty($is_fields) ) {
foreach ( $is_fields as $field ) {
if ( isset( $field->meta_key ) ) {
$meta_keys[] = $field->meta_key;
}
}
}
/**
* Filter results of SQL query for meta keys
*/
return apply_filters( 'is_meta_keys', $meta_keys );
}
public function inc_exc_url( $section )
{
$includes_url = '';
$sec_name = __( "Search", 'add-search-to-menu' );
if ( 'excludes' === $section ) {
$sec_name = __( "Exclude", 'add-search-to-menu' );
}
if ( isset( $_REQUEST['post'] ) ) {
$includes_url = '' . esc_html( $sec_name ) . ' ';
} else {
if ( isset( $_REQUEST['page'] ) && 'ivory-search-new' === $_REQUEST['page'] ) {
$includes_url = '' . esc_html( $sec_name ) . ' ';
}
}
return $includes_url;
}
public function includes_panel( $post )
{
$id = '_is_includes';
$includes = $post->prop( $id );
$excludes = $post->prop( '_is_excludes' );
$settings = $post->prop( '_is_settings' );
$default_search = ( NULL == $post->id() ? true : false );
?>
' ;
$comment_count_disable = ( is_fs()->is_plan_or_trial( 'pro' ) && $this->is_premium_plugin ? '' : ' disabled ' );
if ( '' !== $comment_count_disable ) {
echo '
' . IS_Admin::pro_link() ;
}
echo ' ' . esc_html( __( 'Search posts having number of comments', 'add-search-to-menu' ) ) . ' ' ;
echo '' ;
if ( '' !== $comment_count_disable ) {
echo '
' ;
}
$checked = ( isset( $includes['search_comment'] ) && $includes['search_comment'] ? 1 : 0 );
echo '
' ;
echo ' ' . esc_html__( "Search approved comment content", 'add-search-to-menu' ) . '
' ;
echo $this->get_conflicts_info( 'search_comment' ) ;
?>
' ;
$range = array( 'after', 'before' );
foreach ( $range as $value ) {
$col_title = ( 'after' == $value ? __( 'From', 'add-search-to-menu' ) : __( 'To', 'add-search-to-menu' ) );
echo '
' . esc_html( $col_title ) . '
' ;
$checked = ( isset( $includes['date_query'][$value]['date'] ) ? $includes['date_query'][$value]['date'] : '' );
echo '
' ;
echo '
' ;
}
?>
prop( $id );
$enable_customize = ( isset( $settings['enable_customize'] ) ? $settings['enable_customize'] : false );
$is_ajax = $post->prop( '_is_ajax' );
?>
prop( $id );
$includes = $post->prop( '_is_includes' );
// If not have any settings saved then set default value for fields.
if ( empty($settings) ) {
$show_description = true;
$show_details_box = true;
$show_more_result = true;
$show_more_func = false;
$show_price = true;
$show_matching_categories = true;
$show_image = true;
$search_results = 'both';
} else {
$show_description = ( isset( $settings['show_description'] ) && $settings['show_description'] ? 1 : 0 );
$show_details_box = ( isset( $settings['show_details_box'] ) ? $settings['show_details_box'] : false );
$show_more_result = ( isset( $settings['show_more_result'] ) && $settings['show_more_result'] ? 1 : 0 );
$show_more_func = ( isset( $settings['show_more_func'] ) && $settings['show_more_func'] ? 1 : 0 );
$show_price = ( isset( $settings['show_price'] ) && $settings['show_price'] ? 1 : 0 );
$show_matching_categories = ( isset( $settings['show_matching_categories'] ) && $settings['show_matching_categories'] ? 1 : 0 );
$show_image = ( isset( $settings['show_image'] ) ? 1 : 0 );
$search_results = ( isset( $settings['search_results'] ) ? $settings['search_results'] : 'both' );
}
$enable_ajax = ( isset( $settings['enable_ajax'] ) ? $settings['enable_ajax'] : false );
$description_source = ( isset( $settings['description_source'] ) ? $settings['description_source'] : 'excerpt' );
$description_length = ( isset( $settings['description_length'] ) ? $settings['description_length'] : 20 );
$hide_price_out_of_stock = ( isset( $settings['hide_price_out_of_stock'] ) && $settings['hide_price_out_of_stock'] ? 1 : 0 );
$show_sale_badge = ( isset( $settings['show_sale_badge'] ) && $settings['show_sale_badge'] ? 1 : 0 );
$show_categories = ( isset( $settings['show_categories'] ) && $settings['show_categories'] ? 1 : 0 );
$show_tags = ( isset( $settings['show_tags'] ) && $settings['show_tags'] ? 1 : 0 );
$show_sku = ( isset( $settings['show_sku'] ) && $settings['show_sku'] ? 1 : 0 );
$show_matching_tags = ( isset( $settings['show_matching_tags'] ) && $settings['show_matching_tags'] ? 1 : 0 );
$show_stock_status = ( isset( $settings['show_stock_status'] ) && $settings['show_stock_status'] ? 1 : 0 );
$show_featured_icon = ( isset( $settings['show_featured_icon'] ) && $settings['show_featured_icon'] ? 1 : 0 );
$nothing_found_text = ( isset( $settings['nothing_found_text'] ) ? $settings['nothing_found_text'] : __( 'Nothing found', 'add-search-to-menu' ) );
$min_no_for_search = ( isset( $settings['min_no_for_search'] ) ? $settings['min_no_for_search'] : 1 );
$view_all_results = ( isset( $settings['view_all_results'] ) ? $settings['view_all_results'] : false );
$view_all_text = ( isset( $settings['view_all_text'] ) ? $settings['view_all_text'] : __( 'View All', 'add-search-to-menu' ) );
// Result Layout.
$result_box_max_height = ( isset( $settings['result_box_max_height'] ) ? $settings['result_box_max_height'] : 400 );
$more_result_text = ( isset( $settings['more_result_text'] ) ? $settings['more_result_text'] : __( 'More Results..', 'add-search-to-menu' ) );
$show_author = ( isset( $settings['show_author'] ) && $settings['show_author'] ? 1 : 0 );
$show_date = ( isset( $settings['show_date'] ) && $settings['show_date'] ? 1 : 0 );
// Details Box.
$product_list = ( isset( $settings['product_list'] ) ? $settings['product_list'] : 'all' );
$order_by = ( isset( $settings['order_by'] ) ? $settings['order_by'] : 'date' );
$order = ( isset( $settings['order'] ) ? $settings['order'] : 'desc' );
$field_class = ( $enable_ajax ? '' : 'is-field-disabled' );
?>
prop( $id );
$includes = $post->prop( '_is_includes' );
$default_search = ( NULL == $post->id() ? true : false );
?>
' ;
continue;
}
echo ' ' ;
echo ' ' . sprintf( esc_html__( "Do not exclude any %s from search", 'add-search-to-menu' ), strtolower( $post_types2[$post_type]->labels->singular_name ) ) . '
' ;
echo ' ' ;
echo ' ' . sprintf( esc_html__( "Exclude selected %s from search", 'add-search-to-menu' ), strtolower( $post_types2[$post_type]->labels->name ) ) . '
' ;
echo $html ;
} else {
echo '' . sprintf( esc_html__( 'The search form is configured in the %1$s section to only search specific %2$s.', 'add-search-to-menu' ), $this->inc_exc_url( 'includes' ), strtolower( $post_types2[$post_type]->labels->name ) ) . ' ' ;
}
}
$tax_objs = get_object_taxonomies( $post_type, 'objects' );
if ( !empty($tax_objs) ) {
$terms_exist = false;
$html = '';
$selected_tax = false;
foreach ( $tax_objs as $key => $tax_obj ) {
$terms = get_terms( array(
'taxonomy' => $key,
'lang' => '',
) );
if ( !empty($terms) && !empty($tax_obj->labels->name) ) {
$terms_exist = true;
$html .= '
';
}
}
if ( $terms_exist ) {
$html .= '
' . esc_html__( "Hold down the control (ctrl) or command button to select multiple options.", 'add-search-to-menu' ) . ' ';
$html .= '
';
$checked = ( $selected_tax ? 'selected' : 'all' );
echo ' ' ;
echo ' ' . sprintf(
esc_html__( "Do not exclude any %s from search of any taxonomies (%s categories, tags & terms %s)", 'add-search-to-menu' ),
strtolower( $post_types2[$post_type]->labels->singular_name ),
'',
' '
) . '
' ;
echo ' ' ;
echo ' ' . sprintf(
esc_html__( "Exclude %s from search of selected taxonomies (%s categories, tags & terms %s)", 'add-search-to-menu' ),
strtolower( $post_types2[$post_type]->labels->name ),
'',
' '
) . '
' ;
echo $html ;
}
}
if ( 'product' == $post_type ) {
echo ' ' ;
$outofstock_disable = ( is_fs()->is_plan_or_trial( 'pro_plus' ) && $this->is_premium_plugin ? '' : ' disabled ' );
if ( '' !== $outofstock_disable ) {
echo '' ;
}
$checked = ( isset( $excludes['woo']['outofstock'] ) && $excludes['woo']['outofstock'] ? 1 : 0 );
echo '
' ;
echo ' ' . esc_html__( "Exclude 'Out of Stock' products from search", 'add-search-to-menu' ) . '
' ;
echo IS_Admin::pro_link( 'pro_plus' ) ;
if ( '' !== $outofstock_disable ) {
echo '
' ;
}
}
if ( 'attachment' == $post_type ) {
global $wp_version ;
if ( 4.9 <= $wp_version ) {
if ( !isset( $includes['post_file_type'] ) ) {
echo ' ' ;
$file_types = get_allowed_mime_types();
if ( !empty($file_types) ) {
$file_type_disable = ( is_fs()->is_plan_or_trial( 'pro_plus' ) && $this->is_premium_plugin ? '' : ' disabled ' );
if ( '' !== $file_type_disable ) {
echo '' ;
}
ksort( $file_types );
$html = '
';
$html .= ' ';
$html .= '';
foreach ( $file_types as $key => $file_type ) {
$checked = ( isset( $excludes['post_file_type'] ) && in_array( $file_type, $excludes['post_file_type'] ) ? $file_type : 0 );
$html .= '' . esc_html( $key ) . ' ';
}
$html .= ' ';
echo IS_Admin::pro_link( 'pro_plus' ) ;
$html .= '' . esc_html__( "Hold down the control (ctrl) or command button to select multiple options.", 'add-search-to-menu' ) . ' ';
if ( isset( $excludes['post_file_type'] ) ) {
$html .= __( 'Excluded File Types :', 'add-search-to-menu' );
foreach ( $excludes['post_file_type'] as $post_file_type ) {
$html .= '' . $post_file_type . ' ';
}
}
$html .= '
';
$checked = ( isset( $excludes['post_file_type'] ) && !empty($excludes['post_file_type']) ? 'selected' : 'all' );
echo '
' ;
echo ' ' . esc_html__( "Search all MIME types", 'add-search-to-menu' ) . '
' ;
echo '
' ;
echo ' ' . esc_html__( "Exclude selected MIME types from search", 'add-search-to-menu' ) . '
' ;
echo $html ;
echo '
' ;
echo ' ' ;
echo ' ' . esc_html__( "Exclude Images", 'add-search-to-menu' ) . '
' ;
echo ' ' ;
echo ' ' . esc_html__( "Exclude Videos", 'add-search-to-menu' ) . '
' ;
echo ' ' ;
echo ' ' . esc_html__( "Exclude Audios", 'add-search-to-menu' ) . '
' ;
echo ' ' ;
echo ' ' . esc_html__( "Exclude Text Files", 'add-search-to-menu' ) . '
' ;
echo ' ' ;
echo ' ' . esc_html__( "Exclude PDF Files", 'add-search-to-menu' ) . '
' ;
echo ' ' ;
echo ' ' . esc_html__( "Exclude Document Files", 'add-search-to-menu' ) . '
' ;
echo ' ' ;
if ( '' !== $file_type_disable ) {
echo '
' ;
}
}
} else {
echo '' . sprintf( esc_html__( "This search form is configured in the %s section to search specific attachments.", 'add-search-to-menu' ), $this->inc_exc_url( 'includes' ) ) . ' ' ;
}
} else {
echo '' . __( 'You are using WordPress version less than 4.9 which does not support searching by MIME type.', 'add-search-to-menu' ) . ' ' ;
}
}
?>
' ;
if ( !isset( $includes['author'] ) ) {
$author_disable = ( is_fs()->is_plan_or_trial( 'pro' ) && $this->is_premium_plugin ? '' : ' disabled ' );
$args = array(
'fields' => array( 'ID', 'display_name' ),
'orderby' => 'post_count',
'order' => 'DESC',
);
if ( version_compare( $GLOBALS['wp_version'], '5.9', '<' ) ) {
$args['who'] = 'authors';
} else {
$args['capability'] = [ 'edit_posts' ];
}
$authors = get_users( $args );
if ( !empty($authors) ) {
if ( '' !== $author_disable ) {
echo IS_Admin::pro_link() ;
}
echo '
' ;
echo '
' ;
if ( !isset( $excludes['author'] ) || empty($excludes['author']) ) {
echo '' . __( 'Search all author posts', 'add-search-to-menu' ) . ' ' ;
} else {
echo '' . __( 'Search all author posts', 'add-search-to-menu' ) . ' ' ;
foreach ( $excludes['author'] as $author2 ) {
$display_name = get_userdata( $author2 );
if ( $display_name ) {
echo ' ' . esc_html( $display_name->display_name ) . ' ' ;
}
}
echo ' ' ;
}
echo '
' ;
echo '
' ;
foreach ( $authors as $author ) {
$post_count = count_user_posts( $author->ID );
// Move on if user has not published a post (yet).
if ( !$post_count ) {
continue;
}
$checked = ( isset( $excludes['author'][esc_attr( $author->ID )] ) ? $excludes['author'][esc_attr( $author->ID )] : 0 );
echo ' ID, $checked, false ) . '/>' ;
echo ' ' . ucfirst( esc_html( $author->display_name ) ) . ' ' ;
}
echo '
' ;
}
} else {
echo '
' . sprintf( esc_html__( "This search form is configured in the %s section to search posts created by specific authors.", 'add-search-to-menu' ), $this->inc_exc_url( 'includes' ) ) . ' ' ;
}
?>
' ;
$checked = ( isset( $excludes['ignore_sticky_posts'] ) && $excludes['ignore_sticky_posts'] ? 1 : 0 );
echo ' ' ;
echo ' ' . esc_html__( "Exclude sticky posts from search", 'add-search-to-menu' ) . ' ' ;
?>
prop( $id );
?>
' . __( 'For Example: If you search "doing" then it also searches base word of "doing" that is "do" in the specified post types.', 'add-search-to-menu' ) . '';
$content .= '
' . __( 'Not recommended to use when Fuzzy Matching option is set to Whole.', 'add-search-to-menu' ) . '
';
IS_Help::help_info( $content );
echo '
' ;
$stem_disable = ( is_fs()->is_plan_or_trial( 'pro_plus' ) && $this->is_premium_plugin ? '' : ' disabled ' );
$checked = ( isset( $settings['keyword_stem'] ) && $settings['keyword_stem'] ? 1 : 0 );
echo '
' ;
echo ' ' . esc_html__( "Also search base word of searched keyword", 'add-search-to-menu' ) . '
' ;
echo IS_Admin::pro_link( 'pro_plus' ) ;
?>
' ;
$checked = ( isset( $settings['search_engine'] ) && "index" === $settings['search_engine'] ? "index" : "wp" );
echo '
' ;
echo ' ' . esc_html__( "Default WordPress Search Engine", 'add-search-to-menu' ) . '
' ;
echo '
' ;
echo ' ' . esc_html__( "Inverted Index Search Engine", 'add-search-to-menu' ) . '
' ;
?>
index_conflicts ) ) {
foreach ( $this->index_conflicts as $option => $conflicts ) {
echo $this->get_conflicts_info( $option ) ;
}
}
?>
search_form->group_prop( '_is_settings', 'search_engine' );
$conflict = null;
if ( 'index' == $search_engine && !empty($this->index_conflicts[$option]) ) {
if ( !empty($post_type) ) {
if ( !empty($this->index_conflicts[$option][$post_type]) ) {
$conflict = $this->index_conflicts[$option][$post_type];
}
} else {
if ( is_array( $this->index_conflicts[$option] ) ) {
$conflict = implode( ' ', $this->index_conflicts[$option] );
} else {
$conflict = $this->index_conflicts[$option];
}
}
if ( $conflict ) {
return sprintf( '%s ', wp_kses_post( $conflict ) );
}
}
}
/**
* Get index settings conflicts with this search form.
*
* @since 5.0
* @return array {
* string $key The option key
* string $notice The html escaped notice to show.
* }
*/
public function get_index_conflicts()
{
$conflicts = [];
$index_opt = IS_Index_Options::getInstance();
if ( IS_Index_Model::is_index_empty() ) {
$conflicts['index'] = esc_html__( 'The Index should be created to use this option in the Index ' ) . $index_opt->get_index_settings_link();
}
$props = $this->search_form->get_properties();
foreach ( $props as $key => $group ) {
if ( !empty($group) && is_array( $group ) ) {
foreach ( $group as $prop => $val ) {
$diff = array();
switch ( $prop ) {
case 'post_type':
$diff = array_diff( $val, $index_opt->get_post_types() );
if ( !empty($diff) ) {
$conflicts[$prop] = sprintf( esc_html( _n(
'The %s post type is not selected in Index',
'The %s post types are not selected in Index',
count( $diff ),
'add-search-to-menu'
) ), implode( ', ', $diff ) ) . $index_opt->get_index_settings_link( 'post_types' );
}
break;
case 'custom_field':
$indexed_meta_fields = $index_opt->get_meta_keys();
$meta_keys = $this->is_meta_keys();
$selected = array_intersect( $meta_keys, $val );
$diff = array_diff( $selected, $indexed_meta_fields );
if ( !empty($diff) ) {
$conflicts[$prop] = sprintf( esc_html( _n(
'The %s meta field is not selected in Index',
'The %s meta fields are not selected in Index',
count( $diff ),
'add-search-to-menu'
) ), implode( ', ', $diff ) ) . $index_opt->get_index_settings_link( 'meta_fields' );
}
break;
case 'search_title':
if ( $val && !$index_opt->index_title ) {
$conflicts[$prop] = esc_html__( 'The post title is not selected in Index', 'add-search-to-menu' ) . $index_opt->get_index_settings_link( 'extra' );
}
break;
case 'search_content':
if ( $val && !$index_opt->index_content ) {
$conflicts[$prop] = esc_html__( 'The post content is not selected in Index', 'add-search-to-menu' ) . $index_opt->get_index_settings_link( 'extra' );
}
break;
case 'search_excerpt':
if ( $val && !$index_opt->index_excerpt ) {
$conflicts[$prop] = esc_html__( 'The post excerpt is not selected in Index', 'add-search-to-menu' ) . $index_opt->get_index_settings_link( 'extra' );
}
break;
case 'search_tax_title':
if ( $val && !$index_opt->index_tax_title ) {
$conflicts[$prop] = esc_html__( 'The taxonomy title is not selected in Index', 'add-search-to-menu' ) . $index_opt->get_index_settings_link( 'extra' );
}
break;
case 'search_tax_desp':
if ( $val && !$index_opt->index_tax_desp ) {
$conflicts[$prop] = esc_html__( 'The taxonomy description is not selected in Index', 'add-search-to-menu' ) . $index_opt->get_index_settings_link( 'extra' );
}
break;
case 'search_author':
if ( $val && !$index_opt->index_author_info ) {
$conflicts[$prop] = esc_html__( 'The Author info is not selected in Index', 'add-search-to-menu' ) . $index_opt->get_index_settings_link( 'extra' );
}
break;
case 'search_comment':
if ( $val && !$index_opt->index_comments ) {
$conflicts[$prop] = esc_html__( 'The comments are not selected in Index', 'add-search-to-menu' ) . $index_opt->get_index_settings_link( 'extra' );
}
break;
case 'woo':
if ( !empty($val['sku']) && !$index_opt->index_product_sku ) {
$conflicts[$prop]['sku'] = esc_html__( 'The product SKU is not selected in Index', 'add-search-to-menu' ) . $index_opt->get_index_settings_link( 'extra' );
}
if ( !empty($val['variation']) && !$index_opt->index_product_variation ) {
$conflicts[$prop]['variation'] = esc_html__( 'The product variation is not selected in Index', 'add-search-to-menu' ) . $index_opt->get_index_settings_link( 'extra' );
}
break;
case 'fuzzy_match':
if ( 3 == $val && $this->search_form->is_index_search() ) {
$link = sprintf( ' %s ', 'is-option-link', esc_html__( 'Anywhere Fuzzy Matching', 'add-search-to-menu' ) );
$link1 = sprintf( ' %s ', 'is-option-link', esc_html__( 'Inverted Index Search Engine', 'add-search-to-menu' ) );
$conflicts[$prop] = sprintf(
'%s %s %s %s',
esc_html__( 'It is not recommended to use the', 'add-search-to-menu' ),
$link,
esc_html__( 'option along with', 'add-search-to-menu' ),
$link1
);
}
break;
}
}
}
}
return $conflicts;
}
}