search_form = $search_form;
}
function is_name( $string )
{
return preg_match( '/^[A-Za-z][-A-Za-z0-9_:.]*$/', $string );
}
public function add_panel( $id, $title, $callback )
{
if ( $this->is_name( $id ) ) {
$this->panels[$id] = array(
'title' => $title,
'callback' => $callback,
);
}
}
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.', 'ivory-search' );
}
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( $post_types )
{
global $wpdb ;
$post_types = implode( "', '", $post_types );
$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 '\\_%' AND post_type IN ( '{$post_types}' ) 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 includes_panel( $post )
{
$id = '_is_includes';
$includes = $post->prop( $id );
$excludes = $post->prop( '_is_excludes' );
$settings = $post->prop( '_is_settings' );
?>
' ;
$args = array( 'post', 'page' );
if ( isset( $includes['post_type'] ) && !empty($includes['post_type']) && is_array( $includes['post_type'] ) ) {
$args = array_values( $includes['post_type'] );
}
$tax_objs = get_object_taxonomies( $args, 'objects' );
if ( !empty($tax_objs) ) {
foreach ( $tax_objs as $key => $tax_obj ) {
$terms = get_terms( array(
'taxonomy' => $key,
'hide_empty' => false,
) );
if ( !empty($terms) ) {
echo '
' ;
}
}
echo '
' . esc_html__( "Press CTRL key & Left Mouse button to select multiple terms or deselect them.", 'ivory-search' ) . ' ' ;
$ind_status = false;
if ( isset( $includes['tax_query'] ) && !empty($includes['tax_query']) ) {
$ind_status = true;
}
$checked = ( isset( $includes['tax_rel'] ) && "OR" == $includes['tax_rel'] ? "OR" : "AND" );
if ( !$ind_status && "AND" !== $checked ) {
$ind_status = true;
}
echo '
' ;
echo ' ' . esc_html__( "AND - Search posts having all the above selected terms", 'ivory-search' ) . '
' ;
echo '
' ;
echo ' ' . esc_html__( "OR - Search posts having any one of the above selected terms", 'ivory-search' ) . '
' ;
$checked = ( isset( $includes['search_tax_title'] ) && $includes['search_tax_title'] ? 1 : 0 );
if ( !$ind_status && $checked ) {
$ind_status = true;
}
echo '
' ;
echo ' ' . esc_html__( "Search term title", 'ivory-search' ) . '
' ;
$checked = ( isset( $includes['search_tax_desp'] ) && $includes['search_tax_desp'] ? 1 : 0 );
if ( !$ind_status && $checked ) {
$ind_status = true;
}
echo '
' ;
echo ' ' . esc_html__( "Search term description", 'ivory-search' ) . '
' ;
if ( $ind_status ) {
echo '
' ;
}
} else {
echo '
' . __( 'No taxonomies registered for selected post types.', 'ivory-search' ) . ' ' ;
}
?>
' ;
$args = array( 'post', 'page' );
if ( isset( $includes['post_type'] ) && !empty($includes['post_type']) && is_array( $includes['post_type'] ) ) {
$args = array_values( $includes['post_type'] );
}
$meta_keys = $this->is_meta_keys( $args );
if ( !empty($meta_keys) ) {
echo ' ' ;
echo '' ;
foreach ( $meta_keys as $meta_key ) {
$checked = ( isset( $includes['custom_field'] ) && in_array( $meta_key, $includes['custom_field'] ) ? $meta_key : 0 );
echo '' . esc_html( $meta_key ) . ' ' ;
}
echo ' ' ;
echo '' . esc_html__( "Press CTRL key & Left Mouse button to select multiple terms or deselect them.", 'ivory-search' ) . ' ' ;
} else {
echo '' . __( 'No custom fields created for selected post types.', 'ivory-search' ) . ' ' ;
}
if ( isset( $includes['custom_field'] ) ) {
echo ' ' . __( 'Selected Custom Fields :', 'ivory-search' ) ;
foreach ( $includes['custom_field'] as $custom_field ) {
echo '' . $custom_field . ' ' ;
}
echo ' ' ;
}
?>
' ;
if ( class_exists( 'WooCommerce' ) ) {
$args = array( 'post', 'page' );
if ( isset( $includes['post_type'] ) && !empty($includes['post_type']) && is_array( $includes['post_type'] ) ) {
$args = array_values( $includes['post_type'] );
}
if ( in_array( 'product', $args ) ) {
$ind_status = false;
$woo_sku_disable = ( is_fs()->is_plan_or_trial( 'pro_plus' ) && $this->is_premium_plugin ? '' : ' disabled ' );
$checked = ( isset( $includes['woo']['sku'] ) && $includes['woo']['sku'] ? 1 : 0 );
if ( $checked ) {
$ind_status = true;
}
echo '
' ;
echo ' ' . esc_html__( "Search product SKU", 'ivory-search' ) . '
' ;
$checked = ( isset( $includes['woo']['variation'] ) && $includes['woo']['variation'] ? 1 : 0 );
if ( !$ind_status && $checked ) {
$ind_status = true;
}
echo '
' ;
echo ' ' . esc_html__( "Search product variation", 'ivory-search' ) . ' ' ;
echo IS_Admin::pro_link( 'pro_plus' ) . '
' ;
if ( $ind_status ) {
echo '
' ;
}
} else {
echo '
' . __( 'This search form is not configured to search WooCommerce product post type.', 'ivory-search' ) . ' ' ;
}
} else {
echo '
' . __( 'Activate WooCommerce plugin to use this option.', 'ivory-search' ) . ' ' ;
}
?>
' ;
$author_disable = ( is_fs()->is_plan_or_trial( 'pro' ) && $this->is_premium_plugin ? '' : ' disabled ' );
if ( !isset( $excludes['author'] ) ) {
$authors = get_users( array(
'fields' => array( 'ID', 'display_name' ),
'orderby' => 'post_count',
'order' => 'DESC',
'who' => 'authors',
) );
if ( !empty($authors) ) {
if ( '' !== $author_disable ) {
echo '
' . IS_Admin::pro_link() ;
}
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( $includes['author'][esc_attr( $author->ID )] ) ? $includes['author'][esc_attr( $author->ID )] : 0 );
echo '
ID, $checked, false ) . '/>' ;
echo ' ' . ucfirst( esc_html( $author->display_name ) ) . '
' ;
}
}
} else {
echo '
' . esc_html__( "This search form is already configured in the Excludes section to not search for specific author posts.", 'ivory-search' ) . ' ' ;
}
if ( '' !== $author_disable ) {
echo '
' ;
}
$checked = ( isset( $includes['search_author'] ) && $includes['search_author'] ? 1 : 0 );
echo '
' ;
echo ' ' . esc_html__( "Search author Display Name and display the posts created by that author", 'ivory-search' ) . '
' ;
if ( $checked || isset( $includes['author'] ) && !empty($includes['author']) ) {
echo '
' ;
}
?>
' ;
if ( !isset( $excludes['post_status'] ) ) {
$post_statuses = get_post_stati();
$post_status_disable = ( is_fs()->is_plan_or_trial( 'pro' ) && $this->is_premium_plugin ? '' : ' disabled ' );
if ( !empty($post_statuses) ) {
if ( '' !== $post_status_disable ) {
echo IS_Admin::pro_link() ;
}
foreach ( $post_statuses as $key => $post_status ) {
$checked = ( isset( $includes['post_status'][esc_attr( $key )] ) ? $includes['post_status'][esc_attr( $key )] : 0 );
echo '
' ;
echo ' ' . ucwords( str_replace( '-', ' ', esc_html( $post_status ) ) ) . '
' ;
}
}
if ( isset( $includes['post_status'] ) && !empty($includes['post_status']) ) {
echo '
' ;
}
} else {
echo '
' . esc_html__( "This search form is already configured in the Excludes section to not search posts of specific post statuses.", 'ivory-search' ) . ' ' ;
}
?>
' ;
$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', 'ivory-search' ) ) . ' ' ;
echo '' ;
if ( '' !== $comment_count_disable ) {
echo '
' ;
}
$checked = ( isset( $includes['search_comment'] ) && $includes['search_comment'] ? 1 : 0 );
if ( !$ind_status && $checked ) {
$ind_status = true;
}
echo '
' ;
echo ' ' . esc_html__( "Search approved comment content", 'ivory-search' ) . '
' ;
if ( $ind_status ) {
echo '' ;
}
?>
' ;
$range = array( 'after', 'before' );
$ind_status = false;
foreach ( $range as $value ) {
$col_title = ( 'after' == $value ? __( 'From', 'ivory-search' ) : __( 'To', 'ivory-search' ) );
echo '
' . $col_title . '
' ;
echo '
' ;
$checked = ( isset( $includes['date_query'][$value]['day'] ) ? $includes['date_query'][$value]['day'] : 'day' );
if ( 'day' !== $checked ) {
$ind_status = true;
}
echo '' . esc_html( __( 'Day', 'ivory-search' ) ) . ' ' ;
for ( $d = 1 ; $d <= 31 ; $d++ ) {
echo '' . $d . ' ' ;
}
echo ' ' ;
echo '
' ;
$checked = ( isset( $includes['date_query'][$value]['month'] ) ? $includes['date_query'][$value]['month'] : 'month' );
if ( !$ind_status && 'month' !== $checked ) {
$ind_status = true;
}
echo '' . esc_html( __( 'Month', 'ivory-search' ) ) . ' ' ;
for ( $m = 1 ; $m <= 12 ; $m++ ) {
echo '' . date( 'F', mktime(
0,
0,
0,
$m,
1
) ) . ' ' ;
}
echo ' ' ;
echo '
' ;
$checked = ( isset( $includes['date_query'][$value]['year'] ) ? $includes['date_query'][$value]['year'] : 'year' );
if ( !$ind_status && 'year' !== $checked ) {
$ind_status = true;
}
echo '' . esc_html( __( 'Year', 'ivory-search' ) ) . ' ' ;
for ( $y = date( "Y" ) ; $y >= 1995 ; $y-- ) {
echo '' . $y . ' ' ;
}
echo ' ' ;
}
if ( $ind_status ) {
echo '
' ;
}
?>
' ;
if ( isset( $includes['post_type'] ) && in_array( 'attachment', $includes['post_type'] ) ) {
if ( !isset( $excludes['post_file_type'] ) ) {
$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 ' );
ksort( $file_types );
echo ' ' ;
echo '' ;
foreach ( $file_types as $key => $file_type ) {
$checked = ( isset( $includes['post_file_type'] ) && in_array( $file_type, $includes['post_file_type'] ) ? $file_type : 0 );
echo '' . esc_html( $key ) . ' ' ;
}
echo ' ' ;
echo IS_Admin::pro_link( 'pro_plus' ) ;
echo '' . esc_html__( "Press CTRL key & Left Mouse button to select multiple terms or deselect them.", 'ivory-search' ) . ' ' ;
}
} else {
echo '' . esc_html__( "This search form is already configured in the Excludes section to not search specific file & MIME types.", 'ivory-search' ) . ' ' ;
}
} else {
echo '' . __( 'This search form is not configured to search Attachment post type.', 'ivory-search' ) . ' ' ;
}
if ( isset( $includes['post_file_type'] ) ) {
echo ' ' . __( 'Selected File Types :', 'ivory-search' ) ;
foreach ( $includes['post_file_type'] as $post_file_type ) {
echo '' . $post_file_type . ' ' ;
}
echo ' ' ;
}
?>
prop( $id );
$includes = $post->prop( '_is_includes' );
?>
' ;
$meta_keys = $this->is_meta_keys( $post_types );
if ( !empty($meta_keys) ) {
$custom_field_disable = ( is_fs()->is_plan_or_trial( 'pro' ) && $this->is_premium_plugin ? '' : ' disabled ' );
echo ' ' ;
echo '' ;
foreach ( $meta_keys as $meta_key ) {
$checked = ( isset( $excludes['custom_field'] ) && in_array( $meta_key, $excludes['custom_field'] ) ? $meta_key : 0 );
echo '' . esc_html( $meta_key ) . ' ' ;
}
echo ' ' ;
echo IS_Admin::pro_link() ;
echo '' . esc_html__( "Press CTRL key & Left Mouse button to select multiple terms or deselect them.", 'ivory-search' ) . ' ' ;
} else {
echo '' . __( 'No custom fields created for selected post types.', 'ivory-search' ) . ' ' ;
}
if ( isset( $excludes['custom_field'] ) ) {
echo ' ' . __( 'Excluded Custom Fields :', 'ivory-search' ) ;
foreach ( $excludes['custom_field'] as $custom_field ) {
echo '' . $custom_field . ' ' ;
}
echo ' ' ;
}
?>
' ;
if ( class_exists( 'WooCommerce' ) ) {
$args = array( 'post', 'page' );
if ( isset( $includes['post_type'] ) && !empty($includes['post_type']) && is_array( $includes['post_type'] ) ) {
$args = array_values( $includes['post_type'] );
}
if ( in_array( 'product', $args ) ) {
$outofstock_disable = ( is_fs()->is_plan_or_trial( 'pro_plus' ) && $this->is_premium_plugin ? '' : ' disabled ' );
$checked = ( isset( $excludes['woo']['outofstock'] ) && $excludes['woo']['outofstock'] ? 1 : 0 );
if ( $checked ) {
echo '
' ;
}
echo '
' ;
echo ' ' . esc_html__( "Exclude 'Out of Stock' products", 'ivory-search' ) . '
' ;
echo IS_Admin::pro_link( 'pro_plus' ) ;
} else {
echo '
' . __( 'This search form is not configured to search WooCommerce product post type.', 'ivory-search' ) . ' ' ;
}
} else {
echo '
' . __( 'Activate WooCommerce plugin to use this option.', 'ivory-search' ) . ' ' ;
}
?>
' ;
if ( !isset( $includes['author'] ) ) {
$author_disable = ( is_fs()->is_plan_or_trial( 'pro' ) && $this->is_premium_plugin ? '' : ' disabled ' );
$authors = get_users( array(
'fields' => array( 'ID', 'display_name' ),
'orderby' => 'post_count',
'order' => 'DESC',
'who' => 'authors',
) );
if ( !empty($authors) ) {
if ( '' !== $author_disable ) {
echo IS_Admin::pro_link() ;
}
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 ) ) . '
' ;
}
if ( isset( $excludes['author'] ) && !empty($excludes['author']) ) {
echo '
' ;
}
}
} else {
echo '
' . esc_html__( "This search form is already configured in the Includes section to search posts created by specific authors.", 'ivory-search' ) . ' ' ;
}
?>
' ;
if ( !isset( $includes['post_status'] ) ) {
$post_statuses = get_post_stati();
$post_status_disable = ( is_fs()->is_plan_or_trial( 'pro' ) && $this->is_premium_plugin ? '' : ' disabled ' );
if ( !empty($post_statuses) ) {
if ( '' !== $post_status_disable ) {
echo '
' . IS_Admin::pro_link() ;
}
foreach ( $post_statuses as $key => $post_status ) {
$checked = ( isset( $excludes['post_status'][esc_attr( $key )] ) ? $excludes['post_status'][esc_attr( $key )] : 0 );
echo '
' ;
echo ' ' . ucwords( str_replace( '-', ' ', esc_html( $post_status ) ) ) . '
' ;
}
if ( '' !== $post_status_disable ) {
echo '
' ;
}
}
} else {
echo '
' . esc_html__( "This search form is already configured in the Includes section to search posts of specific post statuses.", 'ivory-search' ) . ' ' ;
}
$checked = ( isset( $excludes['ignore_sticky_posts'] ) && $excludes['ignore_sticky_posts'] ? 1 : 0 );
if ( isset( $excludes['post_status'] ) && !empty($excludes['post_status']) || $checked ) {
echo '
' ;
}
echo '
' ;
echo ' ' . esc_html__( "Exclude sticky posts from search", 'ivory-search' ) . '
' ;
?>
' ;
if ( isset( $includes['post_type'] ) && in_array( 'attachment', $includes['post_type'] ) ) {
if ( !isset( $includes['post_file_type'] ) ) {
$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 ' );
ksort( $file_types );
echo ' ' ;
echo '' ;
foreach ( $file_types as $key => $file_type ) {
$checked = ( isset( $excludes['post_file_type'] ) && in_array( $file_type, $excludes['post_file_type'] ) ? $file_type : 0 );
echo '' . esc_html( $key ) . ' ' ;
}
echo ' ' ;
echo IS_Admin::pro_link( 'pro_plus' ) ;
echo '' . esc_html__( "Press CTRL key & Left Mouse button to select multiple terms or deselect them.", 'ivory-search' ) . ' ' ;
}
} else {
echo '' . esc_html__( "This search form is already configured in the Includes section to search specific Attachments, Media or Files.", 'ivory-search' ) . ' ' ;
}
} else {
echo '' . __( 'This search form is not configured to search Attachment post type.', 'ivory-search' ) . ' ' ;
}
if ( isset( $excludes['post_file_type'] ) ) {
echo ' ' . __( 'Excluded File Types :', 'ivory-search' ) ;
foreach ( $excludes['post_file_type'] as $post_file_type ) {
echo '' . $post_file_type . ' ' ;
}
echo ' ' ;
}
?>
prop( $id );
?>
' ;
$term_rel_disable = ( is_fs()->is_plan_or_trial( 'pro' ) && $this->is_premium_plugin ? '' : ' disabled ' );
$checked = ( isset( $settings['term_rel'] ) && "OR" === $settings['term_rel'] ? "OR" : "AND" );
echo '
' ;
echo ' ' . esc_html__( "OR - Display content having any of the search terms", 'ivory-search' ) . ' ' . IS_Admin::pro_link() . '
' ;
echo '
' ;
echo ' ' . esc_html__( "AND - Display content having all the search terms", 'ivory-search' ) . '
' ;
if ( "AND" !== $checked ) {
echo '
' ;
}
?>
' ;
$checked = ( isset( $settings['fuzzy_match'] ) ? $settings['fuzzy_match'] : '2' );
echo '
' ;
echo ' ' . esc_html__( "Whole - Search posts that include the whole search term", 'ivory-search' ) . '
' ;
echo '
' ;
echo ' ' . esc_html__( "Partial - Also search words in the posts that begins or ends with the search term", 'ivory-search' ) . '
' ;
if ( "2" !== $checked ) {
echo '
' ;
}
?>
' . __( 'For Example: If you search "doing" then it also searches base word of "doing" that is "do" in the specified post types.', 'ivory-search' ) . '';
$content .= '
' . __( 'Not recommended to use when Fuzzy Matching option is set to Whole.', 'ivory-search' ) . '
';
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", 'ivory-search' ) . '
' ;
echo IS_Admin::pro_link( 'pro_plus' ) ;
if ( $checked ) {
echo '
' ;
}
?>
' ;
$checked = ( isset( $settings['empty_search'] ) && $settings['empty_search'] ? 1 : 0 );
echo '
' ;
echo ' ' . esc_html__( "Display an error for empty search query", 'ivory-search' ) . '
' ;
if ( $checked ) {
echo '
' ;
}
?>