bp_get_search_default_text

Return the default text for the search box for a given component.

Description

(string) bp_get_search_default_text( (string) $component = '' ); 

Returns (string)

Placeholder text for search field.

Parameters (1)

0. $component — Optional. (string) => ''
Component name. Default: current component.

Usage

  1. if ( !function_exists( 'bp_get_search_default_text' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-template.php'; 
  3.  
  4. // Component name. Default: current component. 
  5. $component = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_get_search_default_text($component); 
  9.  

Defined (1)

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

/bp-core/bp-core-template.php  
  1. function bp_get_search_default_text( $component = '' ) { 
  2.  
  3. $bp =buddypress); 
  4.  
  5. if ( empty( $component ) ) { 
  6. $component = bp_current_component(); 
  7.  
  8. $default_text = __( 'Search anything...', buddypress ); 
  9.  
  10. // Most of the time, $component will be the actual component ID. 
  11. if ( !empty( $component ) ) { 
  12. if ( !empty( $bp->{$component}->search_string ) ) { 
  13. $default_text = $bp->{$component}->search_string; 
  14. } else { 
  15. // When the request comes through AJAX, we need to get the component 
  16. // name out of $bp->pages. 
  17. if ( !empty( $bp->pages->{$component}->slug ) ) { 
  18. $key = $bp->pages->{$component}->slug; 
  19. if ( !empty( $bp->{$key}->search_string ) ) { 
  20. $default_text = $bp->{$key}->search_string; 
  21.  
  22. /** 
  23. * Filters the default text for the search box for a given component. 
  24. * @since 1.5.0 
  25. * @param string $default_text Default text for search box. 
  26. * @param string $component Current component displayed. 
  27. */ 
  28. return apply_filters( 'bp_get_search_default_text', $default_text, $component );