Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.03 KB | None | 0 0
  1. <?php
  2. /**
  3. * @package WordPress
  4. * @subpackage Kleo
  5. * @author SeventhQueen <themesupport@seventhqueen.com>
  6. * @since Kleo 1.0
  7. */
  8.  
  9. function my_theme_enqueue_styles() {
  10.  
  11. $parent_style = 'kleo-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
  12.  
  13. wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
  14. wp_enqueue_style( 'child-style',
  15. get_stylesheet_directory_uri() . '/style.css',
  16. array( $parent_style ),
  17. wp_get_theme()->get('Version')
  18. );
  19. }
  20. add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
  21.  
  22. /**
  23. * Kleo Child Theme Functions
  24. * Add custom code below
  25. */
  26.  
  27. add_filter( 'wc_product_enable_dimensions_display', '__return_false' );
  28.  
  29. function change_translate_text_multiple( $translated ) {
  30. $text = array(
  31. 'Join Group' => 'Join Fanclub',
  32. 'commented on the post' => 'commented on the article',
  33. 'Leave Group' => 'Leave Fanclub',
  34. 'Search Groups...' => 'Search Fanclubs',
  35. 'Public Group' => 'Public Fanclub',
  36. 'CREATE A GROUP' => 'CREATE A FANCLUB',
  37. 'You joined the group!' => 'You joined the Fanclub!',
  38. 'You successfully left the group.' => 'You succesfully left the Fanclub',
  39. 'Groups' => 'Fanclubs',
  40. 'Your full name' => 'Nickname',
  41. 'Posts' => '',
  42. 'POSTS' => '',
  43. 'Gallery' => 'Media',
  44. 'Create a media' => 'Create an album',
  45. 'Archive for Category:' => '',
  46. 'View Group Results' => 'View Fanclub results',
  47. );
  48. $translated = str_ireplace( array_keys($text), $text, $translated );
  49. return $translated;
  50. }
  51. add_filter( 'gettext', 'change_translate_text_multiple', 20 );
  52.  
  53. add_action( 'widgets_init', 'rkk_widgets_init' );
  54.  
  55. add_post_type_support('forum', array('thumbnail'));
  56. function ks_forum_icons() {
  57. if ( 'forum' == get_post_type() ) {
  58. global $post;
  59. if ( has_post_thumbnail($post->ID) )
  60. echo '<a href="' . get_permalink( $_post->ID ) . '" title="' . get_the_title( $_post->ID ) . '">';
  61. echo get_the_post_thumbnail($post->ID,array(100,100),array('class' => 'alignleft forum-icon'));
  62. echo '</a>';
  63. }
  64. }
  65. add_action('bbp_theme_before_forum_title','ks_forum_icons');
  66.  
  67. function hide_role ($args) {
  68. $args['show_role'] = false ;
  69. Return $args ;
  70. }
  71. add_filter ('bbp_before_get_reply_author_link_parse_args', 'hide_role') ;
  72.  
  73.  
  74. function my_change_profile_tab_order() {
  75. global $bp;
  76. $bp->bp_nav['settings']['position'] = 10;
  77. $bp->bp_nav['activity']['position'] = 20;
  78. $bp->bp_nav['friends']['position'] = 30;
  79. $bp->bp_nav['groups']['position'] = 40;
  80. $bp->bp_nav['articles']['position'] = 20;
  81. $bp->bp_nav['messages']['position'] = 10;
  82. $bp->bp_nav['profile']['position'] = 10;
  83. $bp->bp_nav['bp-messages']['position'] = 10;
  84. $bp->bp_nav['shop']['position'] = 10;
  85. }
  86. add_action( 'bp_setup_nav', 'my_change_profile_tab_order', 999 );
  87.  
  88. function sqr_fix_hover_22082017() {
  89.  
  90. echo '
  91. <style>
  92. .open .kleo-toggle-submenu { display:block !important; }
  93. </style>
  94. ';
  95.  
  96. }
  97.  
  98. add_action('wp_footer', 'sqr_fix_hover_22082017');
  99.  
  100. add_filter('private_title_format', 'ntwb_remove_private_title');
  101. function ntwb_remove_private_title($title) {
  102. return '%s';
  103. }
  104. // class iWC_Orderby_Stock_Status {
  105. // public function __construct() {
  106. // if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
  107. // add_filter('posts_clauses', array($this, 'order_by_stock_status'), 2000);
  108. // }
  109. // }
  110. // public function order_by_stock_status($posts_clauses) {
  111. // global $wpdb;
  112. // if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
  113. // $posts_clauses['join'] .= " INNER JOIN $wpdb->postmeta istockstatus ON ($wpdb->posts.ID = istockstatus.post_id) ";
  114. // $posts_clauses['orderby'] = " istockstatus.meta_value ASC, " . $posts_clauses['orderby'];
  115. // $posts_clauses['where'] = " AND istockstatus.meta_key = '_stock_status' AND istockstatus.meta_value <> '' " . $posts_clauses['where'];
  116. // }
  117. // return $posts_clauses;
  118. // }
  119. // }
  120. // new iWC_Orderby_Stock_Status;
  121. // wp_reset_query();
  122.  
  123.  
  124.  
  125. //Catch ajax requests SuperRadu SQ CUSTOM
  126. add_action( 'wp_ajax_kleo_ajax_search', 'kleo_ajax_search' );
  127. add_action( 'wp_ajax_nopriv_kleo_ajax_search', 'kleo_ajax_search' );
  128.  
  129. if ( ! function_exists( 'kleo_ajax_search' ) ) {
  130. function kleo_ajax_search() {
  131.  
  132. //if "s" input is missing exit
  133. if ( empty( $_REQUEST['s'] ) && empty( $_REQUEST['bbp_search'] ) ) {
  134. die();
  135. }
  136.  
  137. if ( ! empty( $_REQUEST['bbp_search'] ) ) {
  138. $search_string = $_REQUEST['bbp_search'];
  139. } else {
  140. $search_string = $_REQUEST['s'];
  141. }
  142.  
  143. $output = '';
  144. // $context = 'any';
  145. $context = array('post', 'pages', 'groups', 'members', 'forum','product');
  146.  
  147. $defaults = array(
  148. 'numberposts' => 4,
  149. 'posts_per_page' => 20,
  150. 'post_type' => $context,
  151. 'post_status' => array( 'publish', 'inherit' ),
  152. 'post_password' => '',
  153. 'suppress_filters' => false,
  154. 's' => $_REQUEST['s'],
  155. 'category__not_in' => array('1134')
  156. );
  157.  
  158. //Remove woocomerce products since it is handled with a different function
  159. if ( ! empty( $defaults['post_type'] ) && is_array( $defaults['post_type'] ) ) {
  160. foreach ( $defaults['post_type'] as $ptk => $ptv ) {
  161. if ( 'products' == $ptv ) {
  162. unset( $defaults['post_type'][ $ptk ] );
  163. break;
  164. }
  165. }
  166. }
  167.  
  168. //Remove forum since it is handled with a different function
  169. if ( ! empty( $defaults['post_type'] ) && is_array( $defaults['post_type'] ) ) {
  170. foreach ( $defaults['post_type'] as $ptk => $ptv ) {
  171. if ( 'forum' == $ptv ) {
  172. unset( $defaults['post_type'][ $ptk ] );
  173. break;
  174. }
  175. }
  176. }
  177.  
  178. if ( empty( $defaults['post_type'] ) ) {
  179. $posts = null;
  180. } else {
  181.  
  182.  
  183.  
  184. $defaults = apply_filters( 'kleo_ajax_query_args', $defaults );
  185.  
  186. $the_query = new WP_Query( $defaults );
  187. $posts = $the_query->get_posts();
  188. $members = array();
  189. $members['total'] = 0;
  190. $groups = array();
  191. $groups['total'] = 0;
  192. $forums = false;
  193.  
  194. }
  195.  
  196. if ( function_exists( 'bp_is_active' ) && ( $context == "any" || in_array( "members", $context ) ) ) {
  197. $members = bp_core_get_users( array(
  198. 'search_terms' => $search_string,
  199. 'per_page' => $defaults['numberposts'],
  200. 'populate_extras' => false,
  201. ) );
  202. }
  203.  
  204. if ( function_exists( 'bp_is_active' ) && bp_is_active( "groups" ) && ( $context == "any" || in_array( "groups", $context ) ) ) {
  205. $groups = groups_get_groups( array(
  206. 'search_terms' => $search_string,
  207. 'per_page' => $defaults['numberposts'],
  208. 'populate_extras' => false,
  209. ) );
  210. }
  211.  
  212. if ( class_exists( 'bbPress' ) && ( $context == "any" || in_array( "forum", $context ) ) ) {
  213. $forums = kleo_bbp_get_replies( $search_string );
  214. }
  215.  
  216.  
  217. //if there are no posts, groups nor members
  218. if ( empty( $posts ) && $members['total'] == 0 && $groups['total'] == 0 && ! $forums ) {
  219. $output = "<div class='kleo_ajax_entry ajax_not_found'>";
  220. $output .= "<div class='ajax_search_content'>";
  221. $output .= "<i class='icon icon-attention-circled'></i> ";
  222. $output .= esc_html__( "Sorry, we haven't found anything based on your criteria.", 'kleo' );
  223. $output .= "<br>";
  224. $output .= esc_html__( "Please try searching by different terms.", 'kleo' );
  225. $output .= "</div>";
  226. $output .= "</div>";
  227. echo $output; // PHPCS: XSS ok.
  228. die();
  229. }
  230.  
  231. //if there are members
  232. if ( $members['total'] != 0 ) {
  233.  
  234. $output .= '<div class="kleo-ajax-part kleo-ajax-type-members">';
  235. $output .= '<h4><span>' . esc_html__( "Members", 'kleo' ) . '</span></h4>';
  236. foreach ( (array) $members['users'] as $member ) {
  237. $image = '<img src="' . bp_core_fetch_avatar( array(
  238. 'item_id' => $member->ID,
  239. 'width' => 25,
  240. 'height' => 25,
  241. 'html' => false
  242. ) ) . '" class="kleo-rounded" alt="' . esc_attr( $member->display_name ) . '">';
  243. if ( $update = bp_get_user_meta( $member->ID, 'bp_latest_update', true ) ) {
  244. $latest_activity = char_trim( trim( strip_tags( bp_create_excerpt( $update['content'], 50, "..." ) ) ) );
  245. } else {
  246. $latest_activity = '';
  247. }
  248. $output .= "<div class ='kleo_ajax_entry'>";
  249. $output .= "<div class='ajax_search_image'>$image</div>";
  250. $output .= "<div class='ajax_search_content'>";
  251. $output .= "<a href='" . bp_core_get_user_domain( $member->ID ) . "' class='search_title'>";
  252. $output .= esc_html( $member->display_name );
  253. $output .= "</a>";
  254. $output .= "<span class='search_excerpt'>";
  255. $output .= $latest_activity;
  256. $output .= "</span>";
  257. $output .= "</div>";
  258. $output .= "</div>";
  259. }
  260. $output .= "<a class='ajax_view_all' href='" . esc_url( bp_get_members_directory_permalink() . "?s=" . $search_string ) . "'>" . esc_html__( 'View member results', 'kleo' ) . "</a>";
  261. $output .= "</div>";
  262. }
  263.  
  264. //if there are groups
  265. if ( $groups['total'] != 0 ) {
  266.  
  267. $output .= '<div class="kleo-ajax-part kleo-ajax-type-groups">';
  268. $output .= '<h4><span>' . esc_html__( "Groups", 'kleo' ) . '</span></h4>';
  269. foreach ( (array) $groups['groups'] as $group ) {
  270. $image = '<img src="' . bp_core_fetch_avatar( array(
  271. 'item_id' => $group->id,
  272. 'object' => 'group',
  273. 'width' => 25,
  274. 'height' => 25,
  275. 'html' => false
  276. ) ) . '" class="kleo-rounded" alt="' . esc_attr( $group->name ) . '">';
  277. $output .= "<div class ='kleo_ajax_entry'>";
  278. $output .= "<div class='ajax_search_image'>$image</div>";
  279. $output .= "<div class='ajax_search_content'>";
  280. $output .= "<a href='" . bp_get_group_permalink( $group ) . "' class='search_title'>";
  281. $output .= esc_html( $group->name );
  282. $output .= "</a>";
  283. $output .= "</div>";
  284. $output .= "</div>";
  285. }
  286. $output .= "<a class='ajax_view_all' href='" . esc_url( bp_get_groups_directory_permalink() . "?s=" . $search_string ) . "'>" . esc_html__( 'View group results', 'kleo' ) . "</a>";
  287. $output .= "</div>";
  288. }
  289.  
  290. //woocommerce products out of stock at the end SuperRadu SQ CUSTOM
  291. if ( class_exists( 'WooCommerce' ) ) {
  292. $output .= '<div class="kleo-ajax-part kleo-ajax-type-product">';
  293.  
  294. // stuff
  295. $prod_args = array(
  296. 'numberposts' => 4,
  297. 'posts_per_page' => 20,
  298. // 'post_type' => array('product_variation','product'),
  299. 'post_type' => 'product',
  300. 'post_status' => array( 'publish', 'inherit' ),
  301. 'post_password' => '',
  302. 's' => $_REQUEST['s'],
  303. 'meta_key' => '_stock',
  304. // 'meta_key' => '_stock_status',
  305. 'orderby' => array(
  306. 'meta_value_num' => 'DESC',
  307. 'relevance' => 'ASC'
  308.  
  309. ),
  310. // 'orderby' => 'meta_value_num',
  311. 'order' => array(
  312. 'meta_value_num' => 'DESC',
  313. 'relevance' => 'ASC'
  314. ),
  315. );
  316. $prod_query = new WP_Query( $prod_args );
  317. $prod_posts = $prod_query->get_posts();
  318.  
  319. function wc_get_variable_product_stock_quantity( $output = 'raw', $product_id = 0 ){
  320. global $wpdb, $product;
  321.  
  322. // Get the product ID (can be defined)
  323. $product_id = $product_id > 0 ? $product_id : get_the_id();
  324.  
  325. // Check and get the instance of the WC_Product Object
  326. $product = is_a( $product, 'WC_Product' ) ? $product : wc_get_product($product_id);
  327. // Get the stock quantity sum of all product variations (children)
  328. $stock_quantity = $wpdb->get_var("
  329. SELECT SUM(pm.meta_value)
  330. FROM {$wpdb->prefix}posts as p
  331. JOIN {$wpdb->prefix}postmeta as pm ON p.ID = pm.post_id
  332. WHERE p.post_type = 'product_variation'
  333. AND p.post_status = 'publish'
  334. AND p.post_parent = '$product_id'
  335. AND pm.meta_key = '_stock'
  336. AND pm.meta_value IS NOT NULL
  337. ");
  338. return $stock_quantity;
  339. }
  340.  
  341. if ( ! empty( $prod_posts ) ) {
  342. $post_types = array();
  343. $post_type_obj = array();
  344.  
  345. $output .= "<h4><span>PRODUCTS</span></h4>";
  346. $count = 0;
  347. foreach ( $prod_posts as $post ) {
  348. $count ++;
  349. if ( $count > 4 ) {
  350. continue;
  351. }
  352. $format = get_post_format( $post->ID );
  353.  
  354.  
  355. if ( $post->post_type == 'attachment' ) {
  356. $img_url = wp_get_attachment_thumb_url( $post->ID );
  357. $image = '<img src="' . aq_resize( $img_url, 44, 44, true, true, true ) . '" class="kleo-rounded"/>';
  358. } else {
  359. if ( $img_url = kleo_get_post_thumbnail_url( $post->ID ) ) {
  360. $image = aq_resize( $img_url, 44, 44, true, true, true );
  361. if ( ! $image ) {
  362. $image = $img_url;
  363. }
  364. $image = '<img src="' . $image . '" class="kleo-rounded">';
  365. } else {
  366. if ( $format == 'video' ) {
  367. $image = "<i class='icon icon-video'></i>";
  368. } elseif ( $format == 'image' || $format == 'gallery' ) {
  369. $image = "<i class='icon icon-picture'></i>";
  370. } else {
  371. $image = "<i class='icon icon-link'></i>";
  372. }
  373. }
  374. }
  375. $excerpt = "";
  376.  
  377.  
  378. if ( ! empty( $post->post_content ) ) {
  379. $excerpt = $post->post_content;
  380. $excerpt = preg_replace( "/\[(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", '', $excerpt );
  381. $excerpt = wp_strip_all_tags( $excerpt ); //added to remove gogole adsense code from search excerpt
  382. $excerpt = char_trim( trim( strip_tags( $excerpt ) ), 40, "..." );
  383. }
  384. $link = apply_filters( 'kleo_custom_url', get_permalink( $post->ID ) );
  385. $classes = "format-" . $format;
  386. $output .= "<div class ='kleo_ajax_entry $classes'>";
  387. $output .= "<div class='ajax_search_image'>$image</div>";
  388. $output .= "<div class='ajax_search_content'>";
  389. $output .= "<a href='$link' class='search_title'>";
  390. $output .= get_the_title( $post->ID );
  391. $variation_stock_quantity = wc_get_variable_product_stock_quantity( 'raw', $post->ID );
  392.  
  393. if(get_post_meta( $post->ID, '_stock', true) >= 1 or $variation_stock_quantity >= 1 ) {
  394. $output .= '<span class="instock"> <i class="icon-dot icon-2x"></i> </span>';
  395. }else {
  396. $output .= '<span class="out-of-stock"> <i class="icon-dot icon-2x"></i> </span>';
  397.  
  398. }
  399. $output .= "</a>";
  400. $output .= "<span class='search_excerpt'>";
  401. $output .= $excerpt;
  402. $output .= "</span>";
  403. $output .= "</div>";
  404. $output .= "</div>";
  405. $output .= "</div>";
  406. }
  407.  
  408. }
  409.  
  410. wp_reset_query();
  411. }
  412.  
  413. //if there are posts form certain category SuperRadu SQ CUSTOM
  414. $category = get_category('1134');
  415. $cat_has_posts = $category->category_count;
  416.  
  417. if( $cat_has_posts > 1 ) {
  418. // stuff
  419.  
  420. $args = array(
  421. 's' => $_REQUEST['s'],
  422. 'category__in' => '1134'
  423. //meta_key=keyname
  424. );
  425. $cat_query = new WP_Query( $args );
  426.  
  427. $cat_posts = $cat_query->get_posts();
  428.  
  429. if ( ! empty( $cat_posts ) ) {
  430.  
  431. $output .= '<div class="kleo-ajax-part kleo-ajax-type-news-cat">';
  432. $post_types = array();
  433. $post_type_obj = array();
  434.  
  435. $output .= "<h4><span>NEWS</span></h4>";
  436. $count = 0;
  437. foreach ( $cat_posts as $post ) {
  438. $count ++;
  439. if ( $count > 4 ) {
  440. continue;
  441. }
  442. $format = get_post_format( $post->ID );
  443.  
  444.  
  445. if ( $post->post_type == 'attachment' ) {
  446. $img_url = wp_get_attachment_thumb_url( $post->ID );
  447. $image = '<img src="' . aq_resize( $img_url, 44, 44, true, true, true ) . '" class="kleo-rounded"/>';
  448. } else {
  449. if ( $img_url = kleo_get_post_thumbnail_url( $post->ID ) ) {
  450. $image = aq_resize( $img_url, 44, 44, true, true, true );
  451. if ( ! $image ) {
  452. $image = $img_url;
  453. }
  454. $image = '<img src="' . $image . '" class="kleo-rounded">';
  455. } else {
  456. if ( $format == 'video' ) {
  457. $image = "<i class='icon icon-video'></i>";
  458. } elseif ( $format == 'image' || $format == 'gallery' ) {
  459. $image = "<i class='icon icon-picture'></i>";
  460. } else {
  461. $image = "<i class='icon icon-link'></i>";
  462. }
  463. }
  464. }
  465. $excerpt = "";
  466.  
  467. if ( ! empty( $post->post_content ) ) {
  468. $excerpt = $post->post_content;
  469. $excerpt = preg_replace( "/\[(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", '', $excerpt );
  470. $excerpt = wp_strip_all_tags( $excerpt ); //added to remove gogole adsense code from search excerpt
  471. $excerpt = char_trim( trim( strip_tags( $excerpt ) ), 40, "..." );
  472. }
  473. $link = apply_filters( 'kleo_custom_url', get_permalink( $post->ID ) );
  474. $classes = "format-" . $format;
  475. $output .= "<div class ='kleo_ajax_entry $classes'>";
  476. $output .= "<div class='ajax_search_image'>$image</div>";
  477. $output .= "<div class='ajax_search_content'>";
  478. $output .= "<a href='$link' class='search_title'>";
  479. $output .= get_the_title( $post->ID );
  480. $output .= "</a>";
  481. $output .= "<span class='search_excerpt'>";
  482. $output .= $excerpt;
  483. $output .= "</span>";
  484. $output .= "</div>";
  485. $output .= "</div>";
  486. $output .= "</div>";
  487. }
  488.  
  489. }
  490.  
  491. wp_reset_query();
  492. }
  493.  
  494. $p_defaults = array(
  495. 'numberposts' => 4,
  496. 'posts_per_page' => 20,
  497. 'post_type' => 'post', 'pages', 'forum',
  498. 'post_status' => array( 'publish', 'inherit' ),
  499. 'post_password' => '',
  500. 'suppress_filters' => false,
  501. 's' => $_REQUEST['s'],
  502. 'category__not_in' => array('1134')
  503. );
  504. // $the_p_query = new WP_Query( $p_defaults );
  505. $the_p_query = new WP_Query( $p_defaults );
  506. $pposts = $the_p_query->get_posts();
  507. //if there are posts
  508. if ( ! empty( $pposts ) ) {
  509. $post_type_str = array();
  510. $post_types = array();
  511. $post_type_obj = array();
  512.  
  513.  
  514. foreach ( $pposts as $post ) {
  515. $post_types[ $post->post_type ][] = $post;
  516. if ( empty( $post_type_obj[ $ppost->post_type ] ) ) {
  517. $post_type_obj[ $post->post_type ] = get_post_type_object( $post->post_type );
  518. }
  519. }
  520.  
  521. // if(key($post_types) == 'product') {
  522. // echo 'products';
  523. // }else {
  524. // echo 'else ok';
  525. // }
  526.  
  527. if(key($post_types) != 'product' ) {
  528. // if(key($post_types) != 'product' and key($post_types) != 'product_variation') {
  529.  
  530. foreach ( $post_types as $ptype => $post_type ) {
  531.  
  532. $output .= '<div class="kleo-ajax-part kleo-ajax-type-' . esc_attr( $post_type_obj[ $ptype ]->name ) . '">';
  533. if ( isset( $post_type_obj[ $ptype ]->labels->name ) ) {
  534. $output .= "<h4><span>" . $post_type_obj[ $ptype ]->labels->name . "</span></h4>";
  535. } else {
  536. $output .= "<hr>";
  537. }
  538. $count = 0;
  539.  
  540. foreach ( $post_type as $post ) {
  541.  
  542. $post_type_str[ $post->post_type ] = $post->post_type;
  543. $count ++;
  544. if ( $count > 4 ) {
  545. continue;
  546. }
  547. $format = get_post_format( $post->ID );
  548.  
  549. if ( $post->post_type == 'attachment' ) {
  550. $img_url = wp_get_attachment_thumb_url( $post->ID );
  551. $image = '<img src="' . aq_resize( $img_url, 44, 44, true, true, true ) . '" class="kleo-rounded"/>';
  552. } else {
  553. if ( $img_url = kleo_get_post_thumbnail_url( $post->ID ) ) {
  554. $image = aq_resize( $img_url, 44, 44, true, true, true );
  555. if ( ! $image ) {
  556. $image = $img_url;
  557. }
  558. $image = '<img src="' . $image . '" class="kleo-rounded">';
  559. } else {
  560. if ( $format == 'video' ) {
  561. $image = "<i class='icon icon-video'></i>";
  562. } elseif ( $format == 'image' || $format == 'gallery' ) {
  563. $image = "<i class='icon icon-picture'></i>";
  564. } else {
  565. $image = "<i class='icon icon-link'></i>";
  566. }
  567. }
  568. }
  569. $excerpt = "";
  570.  
  571. if ( ! empty( $post->post_content ) ) {
  572. $excerpt = $post->post_content;
  573. $excerpt = preg_replace( "/\[(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", '', $excerpt );
  574. $excerpt = wp_strip_all_tags( $excerpt ); //added to remove gogole adsense code from search excerpt
  575. $excerpt = char_trim( trim( strip_tags( $excerpt ) ), 40, "..." );
  576. }
  577. $link = apply_filters( 'kleo_custom_url', get_permalink( $post->ID ) );
  578. $classes = "format-" . $format;
  579. $output .= "<div class ='kleo_ajax_entry $classes'>";
  580. $output .= "<div class='ajax_search_image'>$image</div>";
  581. $output .= "<div class='ajax_search_content'>";
  582. $output .= "<a href='$link' class='search_title'>";
  583. $output .= get_the_title( $post->ID );
  584. $output .= "</a>";
  585. $output .= "<span class='search_excerpt'>";
  586. $output .= $excerpt;
  587. $output .= "</span>";
  588. $output .= "</div>";
  589. $output .= "</div>";
  590.  
  591. $output .= '</div>';
  592.  
  593. }
  594. }
  595. wp_reset_query();
  596.  
  597. }
  598.  
  599. if ( ! empty( $post_type_str ) ) {
  600. if ( count( $post_type_str ) > 1 ) {
  601. $search_str_posts = '&post_type[]=' . implode( '&post_type[]=', $post_type_str );
  602. } else {
  603. $search_str_posts = '&post_type=' . implode( ',', $post_type_str );
  604. }
  605.  
  606. } else {
  607. $search_str_posts = '';
  608. }
  609.  
  610. $output .= "<a class='ajax_view_all' href='" . esc_url( home_url( '/' ) . '?s=' . $search_string ) . $search_str_posts . "'>" . esc_html__( 'View all results', 'kleo' ) . "</a>";
  611.  
  612.  
  613.  
  614. }
  615.  
  616. /* Forums topics search */
  617. if ( ! empty( $forums ) ) {
  618. $output .= '<div class="kleo-ajax-part kleo-ajax-type-forums">';
  619. $output .= '<h4><span>' . esc_html__( "Forums", 'kleo' ) . '</span></h4>';
  620.  
  621. $i = 0;
  622. foreach ( $forums as $fk => $forum ) {
  623.  
  624. $i ++;
  625. if ( $i <= 4 ) {
  626. $image = "<i class='icon icon-chat-1'></i>";
  627.  
  628. $output .= "<div class ='kleo_ajax_entry'>";
  629. $output .= "<div class='ajax_search_image'>$image</div>";
  630. $output .= "<div class='ajax_search_content'>";
  631. $output .= "<a href='" . esc_url( $forum['url'] ) . "' class='search_title'>";
  632. $output .= wp_kses_post( $forum['name'] );
  633. $output .= "</a>";
  634. //$output .= "<span class='search_excerpt'>";
  635. //$output .= $latest_activity;
  636. //$output .= "</span>";
  637. $output .= "</div>";
  638. $output .= "</div>";
  639. }
  640. }
  641. $output .= "<a class='ajax_view_all' href='" . esc_url( bbp_get_search_url() . "?bbp_search=" . $search_string ) . "'>" .
  642. esc_html__( 'View forum results', 'kleo' ) .
  643. "</a>";
  644. $output .= "</div>";
  645.  
  646. // wp_reset_query();
  647. }
  648.  
  649.  
  650. echo $output; // PHPCS: XSS ok.
  651. die();
  652. }
  653. }
  654.  
  655.  
  656.  
  657. //add_action( 'pre_get_posts', function ( $q ) {
  658. // if ( !is_admin() // Target only front end
  659. // && $q->is_main_query() // Only target the main query
  660. // && $q->is_search() // Change to suite your needs
  661. // ) {
  662. // $q->set( 'meta_key', '_stock_status' );
  663. // $q->set( 'orderby', 'meta_value' );
  664. // $q->set( 'order', 'ASC' );
  665. // }
  666. // }, PHP_INT_MAX );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement