bp_core_action_search_site

A JavaScript-free implementation of the search functions in BuddyPress.

Description

bp_core_action_search_site( (string) $slug = '' ); 

Parameters (1)

0. $slug — Optional. (string) => ''
The slug to redirect to for searching.

Usage

  1. if ( !function_exists( 'bp_core_action_search_site' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-functions.php'; 
  3.  
  4. // The slug to redirect to for searching. 
  5. $slug = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_core_action_search_site($slug); 
  9.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-functions.php  
  1. function bp_core_action_search_site( $slug = '' ) { 
  2.  
  3. return; 
  4.  
  5. if ( empty( $_POST['search-terms'] ) ) { 
  6. return; 
  7.  
  8. $search_terms = stripslashes( $_POST['search-terms'] ); 
  9. $search_which = !empty( $_POST['search-which'] ) ? $_POST['search-which'] : ''; 
  10. $query_string = '/?s='; 
  11.  
  12. if ( empty( $slug ) ) { 
  13. switch ( $search_which ) { 
  14. case 'posts': 
  15. $slug = ''; 
  16. $var = '/?s='; 
  17.  
  18. // If posts aren't displayed on the front page, find the post page's slug. 
  19. if ( 'page' == get_option( 'show_on_front' ) ) { 
  20. $page = get_post( get_option( 'page_for_posts' ) ); 
  21.  
  22. if ( !is_wp_error( $page ) && !empty( $page->post_name ) ) { 
  23. $slug = $page->post_name; 
  24. $var = '?s='; 
  25. break; 
  26.  
  27. case 'blogs': 
  28. $slug = bp_is_active( 'blogs' ) ? bp_get_blogs_root_slug() : ''; 
  29. break; 
  30.  
  31. case 'forums': 
  32. $slug = bp_is_active( 'forums' ) ? bp_get_forums_root_slug() : ''; 
  33. $query_string = '/?fs='; 
  34. break; 
  35.  
  36. case 'groups': 
  37. $slug = bp_is_active( 'groups' ) ? bp_get_groups_root_slug() : ''; 
  38. break; 
  39.  
  40. case 'members': 
  41. default: 
  42. break; 
  43.  
  44. if ( empty( $slug ) && 'posts' != $search_which ) { 
  45. return; 
  46.  
  47. /** 
  48. * Filters the constructed url for use with site searching. 
  49. * @since 1.0.0 
  50. * @param string $value URL for use with site searching. 
  51. * @param array $search_terms Array of search terms. 
  52. */ 
  53. bp_core_redirect( apply_filters( 'bp_core_search_site', home_url( $slug . $query_string . urlencode( $search_terms ) ), $search_terms ) );