bp_add_cover_image_inline_css

Add inline css to display the component's single item cover image.

Description

(string|array) bp_add_cover_image_inline_css( (bool) $return = false ); 

Returns (string|array)

the inline css or an associative array containing the css rules and the style handle

Parameters (1)

0. $return — Optional. (bool) => false
True to get the inline css.

Usage

  1. if ( !function_exists( 'bp_add_cover_image_inline_css' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-cssjs.php'; 
  3.  
  4. // True to get the inline css. 
  5. $return = false; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_add_cover_image_inline_css($return); 
  9.  

Defined (1)

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

/bp-core/bp-core-cssjs.php  
  1. function bp_add_cover_image_inline_css( $return = false ) { 
  2. $bp =buddypress); 
  3.  
  4. // Find the component of the current item. 
  5. if ( bp_is_user() ) { 
  6.  
  7. // User is not allowed to upload cover images 
  8. // no need to carry on. 
  9. return; 
  10.  
  11. $cover_image_object = array( 
  12. 'component' => 'xprofile',  
  13. 'object' => $bp->displayed_user 
  14. ); 
  15. } elseif ( bp_is_group() ) { 
  16.  
  17. // Users are not allowed to upload cover images for their groups 
  18. // no need to carry on. 
  19. return; 
  20.  
  21. $cover_image_object = array( 
  22. 'component' =>'groups',  
  23. 'object' => $bp->groups->current_group 
  24. ); 
  25. } else { 
  26. $cover_image_object = apply_filters( 'bp_current_cover_image_object_inline_css', array() ); 
  27.  
  28. // Bail if no component were found. 
  29. if ( empty( $cover_image_object['component'] ) || empty( $cover_image_object['object'] ) || ! bp_is_active( $cover_image_object['component'], 'cover_image' ) ) { 
  30. return; 
  31.  
  32. // Get the settings of the cover image feature for the current component. 
  33. $params = bp_attachments_get_cover_image_settings( $cover_image_object['component'] ); 
  34.  
  35. // Bail if no params. 
  36. if ( empty( $params ) ) { 
  37. return; 
  38.  
  39. // Try to call the callback. 
  40. if ( is_callable( $params['callback'] ) ) { 
  41.  
  42. $object_dir = $cover_image_object['component']; 
  43.  
  44. if ( 'xprofile' === $object_dir ) { 
  45. $object_dir = 'members'; 
  46.  
  47. $cover_image = bp_attachments_get_attachment( 'url', array( 
  48. 'object_dir' => $object_dir,  
  49. 'item_id' => $cover_image_object['object']->id,  
  50. ) ); 
  51.  
  52. if ( empty( $cover_image ) ) { 
  53. if ( ! empty( $params['default_cover'] ) ) { 
  54. $cover_image = $params['default_cover']; 
  55.  
  56. $inline_css = call_user_func_array( $params['callback'], array( array( 
  57. 'cover_image' => esc_url_raw( $cover_image ),  
  58. 'component' => sanitize_key( $cover_image_object['component'] ),  
  59. 'object_id' => (int) $cover_image_object['object']->id,  
  60. 'width' => (int) $params['width'],  
  61. 'height' => (int) $params['height'],  
  62. ) ) ); 
  63.  
  64. // Finally add the inline css to the handle. 
  65. if ( ! empty( $inline_css ) ) { 
  66.  
  67. // Used to get the css when Ajax setting the cover image. 
  68. if ( true === $return ) { 
  69. return array( 
  70. 'css_rules' => '<style type="text/css">' . "\n" . $inline_css . "\n" . '</style>',  
  71. 'handle' => $params['theme_handle'],  
  72. ); 
  73.  
  74. wp_add_inline_style( $params['theme_handle'], $inline_css ); 
  75. } else { 
  76. return false;