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( 'public' => true, ); if ( isset( $settings['exclude_from_search'] ) ) { $args = array( 'public' => true, 'exclude_from_search' => false, ); } $posts = get_post_types( $args ); if ( !empty($posts) ) { $ind_status = false; foreach ( $posts as $key => $post_type ) { $checked = ( isset( $includes['post_type'][esc_attr( $key )] ) ? $includes['post_type'][esc_attr( $key )] : 0 ); if ( !$ind_status && $checked && 'post' !== $key && 'page' !== $key ) { $ind_status = true; } echo '
' ; echo '
' ; } $checked = ( isset( $includes['search_title'] ) && $includes['search_title'] ? 1 : 0 ); if ( !$ind_status && !$checked ) { $ind_status = true; } echo '

' ; $checked = ( isset( $includes['search_content'] ) && $includes['search_content'] ? 1 : 0 ); if ( !$ind_status && !$checked ) { $ind_status = true; } echo '

' ; $checked = ( isset( $includes['search_excerpt'] ) && $includes['search_excerpt'] ? 1 : 0 ); if ( !$ind_status && !$checked ) { $ind_status = true; } echo '

' ; echo '
' ; if ( $ind_status ) { echo '' ; } } else { echo '' . __( 'No post types registered on your site.', 'ivory-search' ) . '' ; } ?>

' ; $post_types = array( 'post', 'page' ); if ( isset( $includes['post_type'] ) && !empty($includes['post_type']) && is_array( $includes['post_type'] ) ) { $post_types = array_values( $includes['post_type'] ); } $posts_found = false; foreach ( $post_types as $post_type ) { $posts = get_posts( array( 'post_type' => $post_type, 'posts_per_page' => 100, 'orderby' => 'title', 'order' => 'ASC', ) ); if ( !empty($posts) ) { $posts_found = true; $html = '
'; $col_title = '' . ucwords( $post_type ) . ''; $temp = ''; $selected_pt = array(); foreach ( $posts as $post2 ) { $checked = ( isset( $includes['post__in'] ) && in_array( $post2->ID, $includes['post__in'] ) ? $post2->ID : 0 ); if ( $checked ) { array_push( $selected_pt, $post_type ); } $post_title = ( isset( $post2->post_title ) && '' !== $post2->post_title ? esc_html( $post2->post_title ) : $post2->post_name ); $temp .= ''; } if ( !empty($selected_pt) && in_array( $post_type, $selected_pt ) ) { $col_title = '' . $col_title . ''; } $html .= $col_title . '
'; $html .= ''; if ( count( $posts ) >= 100 ) { $html .= '
' . __( 'Load All', 'ivory-search' ) . '
'; } $html .= '
'; echo $html ; if ( !empty($selected_pt) ) { echo '' ; } } } if ( !$posts_found ) { echo '' . __( 'No posts created for selected post types.', 'ivory-search' ) . '' ; } else { echo '
' ; } ?>

' ; $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 '
' ; $col_title = ucwords( str_replace( '-', ' ', str_replace( '_', ' ', esc_html( $key ) ) ) ); if ( isset( $includes['tax_query'][$key] ) ) { $col_title = '' . $col_title . ''; } echo $col_title . '
' ; echo '
' ; } } echo '
' ; $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 '

' ; $checked = ( isset( $includes['search_tax_title'] ) && $includes['search_tax_title'] ? 1 : 0 ); if ( !$ind_status && $checked ) { $ind_status = true; } echo '

' ; $checked = ( isset( $includes['search_tax_desp'] ) && $includes['search_tax_desp'] ? 1 : 0 ); if ( !$ind_status && $checked ) { $ind_status = true; } echo '

' ; 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 '' ; echo '
' ; } 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 '

' ; $checked = ( isset( $includes['woo']['variation'] ) && $includes['woo']['variation'] ? 1 : 0 ); if ( !$ind_status && $checked ) { $ind_status = true; } echo '

' ; 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 '
' ; } } } 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 '

' ; 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 '
' ; } } 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 '' ; echo '' ; if ( '' !== $comment_count_disable ) { echo '
' ; } $checked = ( isset( $includes['search_comment'] ) && $includes['search_comment'] ? 1 : 0 ); if ( !$ind_status && $checked ) { $ind_status = true; } echo '

' ; 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 '' ; echo '' ; echo '
' ; } if ( $ind_status ) { echo '' ; } ?>

' ; $checked = ( isset( $includes['has_password'] ) ? $includes['has_password'] : 'null' ); echo '

' ; echo '

' ; echo '

' ; if ( 'null' !== $checked ) { 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 '' ; echo IS_Admin::pro_link( 'pro_plus' ) ; echo '

' ; } } 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' ); ?>

' ; $post_types = array( 'post', 'page' ); if ( isset( $includes['post_type'] ) && !empty($includes['post_type']) && is_array( $includes['post_type'] ) ) { $post_types = array_values( $includes['post_type'] ); } if ( !isset( $includes['post__in'] ) ) { $posts_found = false; foreach ( $post_types as $post_type ) { $posts = get_posts( array( 'post_type' => $post_type, 'posts_per_page' => 100, 'orderby' => 'title', 'order' => 'ASC', ) ); if ( !empty($posts) ) { $posts_found = true; $html = '
'; $col_title = '' . ucwords( $post_type ) . ''; $temp = ''; $selected_pt = array(); foreach ( $posts as $post2 ) { $checked = ( isset( $excludes['post__not_in'] ) && in_array( $post2->ID, $excludes['post__not_in'] ) ? $post2->ID : 0 ); if ( $checked ) { array_push( $selected_pt, $post_type ); } $post_title = ( isset( $post2->post_title ) && '' !== $post2->post_title ? esc_html( $post2->post_title ) : $post2->post_name ); $temp .= ''; } if ( !empty($selected_pt) && in_array( $post_type, $selected_pt ) ) { $col_title = '' . $col_title . ''; } $html .= $col_title . '
'; $html .= ''; if ( count( $posts ) >= 100 ) { $html .= '
' . __( 'Load All', 'ivory-search' ) . '
'; } $html .= '
'; echo $html ; if ( !empty($selected_pt) ) { echo '' ; } } } if ( !$posts_found ) { echo '' . __( 'No posts created for selected post types.', 'ivory-search' ) . '' ; } else { echo '
' ; } } else { echo '' . __( 'This search form is already configured in the Includes section to search specific posts.', 'ivory-search' ) . '' ; } ?>

' ; $tax_objs = get_object_taxonomies( $post_types, '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 '
' ; $col_title = ucwords( str_replace( '-', ' ', str_replace( '_', ' ', esc_html( $key ) ) ) ); if ( isset( $excludes['tax_query'][$key] ) ) { $col_title = '' . $col_title . ''; } echo $col_title . '
' ; } } echo '
' ; if ( isset( $excludes['tax_query'] ) && !empty($excludes['tax_query']) ) { echo '' ; } } else { echo '' . __( 'No taxonomies registered for selected post types.', 'ivory-search' ) . '' ; } ?>

' ; $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 '' ; echo IS_Admin::pro_link() ; echo '

' ; } 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 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 '
' ; } 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 '
' ; } 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 '

' ; ?>

' ; 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 '' ; echo IS_Admin::pro_link( 'pro_plus' ) ; echo '

' ; } } 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 ); ?>

' ; echo '' ; if ( $checked !== $default_per_page ) { echo '' ; } ?>

' ; $ind_status = false; $orderby_disable = ( is_fs()->is_plan_or_trial( 'pro' ) && $this->is_premium_plugin ? '' : ' disabled ' ); echo '' ; echo IS_Admin::pro_link() ; if ( $ind_status ) { echo '' ; } ?>

' ; $color = ( isset( $settings['highlight_color'] ) ? $settings['highlight_color'] : '#FFFFB9' ); if ( !$ind_status && '#FFFFB9' !== $color ) { $ind_status = true; } echo '
' ; echo '' ; if ( $ind_status ) { echo '' ; } ?>

' ; $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 '

' . IS_Admin::pro_link() . '

' ; echo '

' ; if ( "AND" !== $checked ) { echo '' ; } ?>

' ; $checked = ( isset( $settings['fuzzy_match'] ) ? $settings['fuzzy_match'] : '2' ); echo '

' ; echo '

' ; 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 IS_Admin::pro_link( 'pro_plus' ) ; if ( $checked ) { echo '' ; } ?>

' ; if ( $checked ) { echo '' ; } ?>

' ; $checked = ( isset( $settings['empty_search'] ) && $settings['empty_search'] ? 1 : 0 ); echo '

' ; if ( $checked ) { echo '' ; } ?>

' ; if ( $checked ) { echo '' ; } ?>

' ; if ( $checked ) { echo '' ; } ?>

' ; if ( $checked ) { echo '' ; } ?>