Guest User

Untitled

a guest
Aug 1st, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. // Register the Cover Image feature for Users profiles
  2. function bp_default_register_feature() {
  3. /**
  4. * You can choose to register it for Members and / or Groups by including (or not)
  5. * the corresponding components in your feature's settings. In this example, we
  6. * chose to register it for both components.
  7. */
  8. $components = array( 'groups', 'xprofile');
  9.  
  10. // Define the feature's settings
  11. $cover_image_settings = array(
  12. 'name' => 'cover_image', // feature name
  13. 'settings' => array(
  14. 'components' => $components,
  15. 'width' => 900,
  16. 'height' => 700,
  17. 'callback' => 'bp_default_cover_image',
  18. 'theme_handle' => 'bp-default-main',
  19. ),
  20. );
  21.  
  22.  
  23. // Register the feature for your theme according to the defined settings.
  24. bp_set_theme_compat_feature( bp_get_theme_compat_id(), $cover_image_settings );
  25. }
  26. add_action( 'bp_after_setup_theme', 'bp_default_register_feature' );
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34. function dd_xprofile_cover_image( $settings = array() ) {
  35. $settings['default_cover'] = '';
  36. $settings['width'] = 900;
  37. $settings['height'] = 700;
  38.  
  39. return $settings;
  40. }
  41. add_filter( 'bp_before_xprofile_cover_image_settings_parse_args', 'dd_xprofile_cover_image', 10, 1 );
  42.  
  43. function dd_groups_cover_image( $settings = array() ) {
  44. $settings['default_cover'] = '';
  45. $settings['width'] = 900;
  46. $settings['height'] = 700;
  47.  
  48. return $settings;
  49. }
  50. add_filter( 'bp_before_groups_cover_image_settings_parse_args', 'dd_groups_cover_image', 10, 1 );
  51.  
  52.  
  53.  
  54. function bp_cover_img_path() {
  55. // Is the current page a user page?
  56. if ( bp_is_user() ) {
  57.  
  58. $user_id = bp_displayed_user_id();
  59.  
  60. $attachment = bp_attachments_get_attachment( 'url', array( 'item_id' => $user_id ) );
  61.  
  62. $image_path = $attachment;
  63. // output only if an attachment exist
  64. if( !empty( $attachment ) ) { ?>
  65. <style type="text/css">
  66. #item-header { background-image: url( '<?php echo $image_path; ?>' ) }
  67. </style>
  68. <?php } else { ?>
  69. <style type="text/css">
  70. #item-header { background-image: url( '<?php echo get_template_directory_uri(); ?>/images/cover-profile-default.jpg' ) }
  71. </style>
  72. <?php }
  73.  
  74. }
  75. }
  76. add_action( 'bp_profile_cover_path', 'bp_cover_img_path' );
  77.  
  78.  
  79. function bp_cover_group_img_path() {
  80. // Is the current page a user page?
  81. if ( bp_is_group() ) {
  82.  
  83. $group_id = bp_get_group_id();
  84.  
  85. $attachment = bp_attachments_get_attachment( 'url', array(
  86. 'object_dir' => 'groups',
  87. 'item_id' => $group_id,
  88. ) );
  89.  
  90. $image_path = $attachment;
  91. // output only if an attachment exist
  92. if( !empty( $attachment ) ) { ?>
  93.  
  94. <style type="text/css">
  95. #item-header { background-image: url( '<?php echo $image_path; ?>' ) }
  96. </style>
  97. <?php } else { ?>
  98. <style type="text/css">
  99. #item-header { background-image: url( '<?php echo get_template_directory_uri(); ?>/images/cover-group-default.jpg' ) }
  100. </style>
  101.  
  102. <?php }
  103. }
  104. }
  105. add_action( 'bp_group_cover_path', 'bp_cover_group_img_path' );
Add Comment
Please, Sign In to add comment