Skip to content

Instantly share code, notes, and snippets.

@contemplate
Created April 17, 2020 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save contemplate/4541dcc0b2db241b8a398418336fd059 to your computer and use it in GitHub Desktop.
Save contemplate/4541dcc0b2db241b8a398418336fd059 to your computer and use it in GitHub Desktop.
Kleo K Elements kleo_search_form shortcode fix
add_shortcode( 'kleo_search_form', 'kleo_search_form_func' );
function kleo_search_form_func( $atts, $content = null ) {
$form_style = $type = $placeholder = $context = $el_class = '';
extract( shortcode_atts( array(
'form_style' => 'default',
'type' => 'both',
'context' => '',
'placeholder' => '',
'el_class' => ''
), $atts ) );
global $kleo_config;
$class = '';
if ( $el_class != '' ) {
$class = ' ' . $el_class;
}
$class .= ' search-style-' . $form_style;
$context_array = explode( ',', $context );
if ( is_array( $context ) ) {
$context = implode( ',', $context );
}
//Defaults
$action = home_url( '/' );
$hidden = '';
$input_name = 's';
$ajax_results = 'yes';
$search_page = 'yes';
if ( $type == 'ajax' ) {
$search_page = 'no';
} elseif ( $type == 'form_submit' ) {
$ajax_results = 'no';
}
if ( function_exists( 'bp_is_active' ) && $context == 'members' ) {
//Buddypress members form link
$action = bp_get_members_directory_permalink();
} elseif ( function_exists( 'bp_is_active' ) && bp_is_active( 'groups' ) && $context == 'groups' ) {
//Buddypress group directory link
$action = bp_get_groups_directory_permalink();
} elseif ( class_exists( 'bbPress' ) && $context == 'forum' ) {
$action = bbp_get_search_url();
$input_name = 'bbp_search';
} elseif ( $context == 'product' ) {
$hidden .= '<input type="hidden" name="post_type" value="product">';
$action = home_url( '/' ) . '?post_type=product';
} else {
foreach ( $context_array as $post_type ) {
if( in_array( $post_type, ['members', 'groups'] ) ) {
continue;
}
$hidden .= '<input type="hidden" name="post_type[]" value="' . $post_type . '">';
}
}
$value = isset( $_REQUEST['s'] ) ? esc_attr( $_REQUEST['s'] ) : '';
$output = '<div class="kleo-search-wrap kleo-search-form' . $class . '">';
$output .= '<form role="search" method="get" class="searchform" ' . ( $search_page == 'no' ? ' onsubmit="return false;"' : '' ) . ' action="' . esc_url($action) . '" data-context="' . esc_attr( $context ) . '">
' . $hidden . '
<div class="input-group">
<input name="' . $input_name . '" id="' . $input_name . '" autocomplete="off" type="text" class="ajax_s form-control input-lg" value="'.esc_attr( $value ).'" placeholder="' . esc_attr( $placeholder ) . '">';
if ( $search_page == 'yes' ) {
$output .= '<span class="input-group-btn">' .
'<input type="submit" value="' . __( "Search" ) . '" class="button searchsubmit">' .
'</span>';
}
$output .= '</div></form>';
if ( $ajax_results == 'yes' ) {
$output .= '<span class="kleo-ajax-search-loading"><span class="kleo-loading-icon"></span></span><div class="kleo_ajax_results"></div>';
}
$output .= '</div>';
return $output;
}
@contemplate
Copy link
Author

Plugin: K Elements
Found in: /plugins/k-elements/shortcodes/shortcodes.php
Version 4.9.100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment