bp_displayed_user_get_front_template

Locate a custom user front template if it exists.

Description

(string|bool) bp_displayed_user_get_front_template( (null) $displayed_user = null ); 

Returns (string|bool)

Path to front template on success; boolean false on failure.

Parameters (1)

0. $displayed_user — Optional. (null) => null
Falls back to current user if not passed.

Usage

  1. if ( !function_exists( 'bp_displayed_user_get_front_template' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-members/bp-members-template.php'; 
  3.  
  4. // Optional. Falls back to current user if not passed. 
  5. $displayed_user = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_displayed_user_get_front_template($displayed_user); 
  9.  

Defined (1)

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

/bp-members/bp-members-template.php  
  1. function bp_displayed_user_get_front_template( $displayed_user = null ) { 
  2. if ( ! is_object( $displayed_user ) || empty( $displayed_user->id ) ) { 
  3. $displayed_user = bp_get_displayed_user(); 
  4.  
  5. if ( ! isset( $displayed_user->id ) ) { 
  6. return false; 
  7.  
  8. if ( isset( $displayed_user->front_template ) ) { 
  9. return $displayed_user->front_template; 
  10.  
  11. // Init the hierarchy 
  12. $template_names = array( 
  13. 'members/single/front-id-' . sanitize_file_name( $displayed_user->id ) . '.php',  
  14. 'members/single/front-nicename-' . sanitize_file_name( $displayed_user->userdata->user_nicename ) . '.php',  
  15. ); 
  16.  
  17. /** 
  18. * Check for member types and add it to the hierarchy 
  19. * Make sure to register your member 
  20. * type using the hook 'bp_register_member_types
  21. */ 
  22. if ( bp_get_member_types() ) { 
  23. $displayed_user_member_type = bp_get_member_type( $displayed_user->id ); 
  24. if ( ! $displayed_user_member_type ) { 
  25. $displayed_user_member_type = 'none'; 
  26.  
  27. $template_names[] = 'members/single/front-member-type-' . sanitize_file_name( $displayed_user_member_type ) . '.php'; 
  28.  
  29. // Add The generic template to the end of the hierarchy 
  30. $template_names[] = 'members/single/front.php'; 
  31.  
  32. /** 
  33. * Filters the hierarchy of user front templates corresponding to a specific user. 
  34. * @since 2.6.0 
  35. * @param array $template_names Array of template paths. 
  36. */ 
  37. return bp_locate_template( apply_filters( 'bp_displayed_user_get_front_template', $template_names ), false, true );