Advertisement
vapvarun

Function to set a default cover image for groups created by the site admin

Nov 30th, 2023
983
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | Software | 0 0
  1. // Function to set a default cover image for groups created by the site admin
  2. function my_custom_group_cover_image_for_admin( $settings = array() ) {
  3.     // Check if we are within a group context
  4.     if ( bp_is_group() ) {
  5.         // Fetches the current group details
  6.         $group = groups_get_current_group();
  7.  
  8.         // Set this to the user ID of the site admin
  9.         $admin_id = 1; // Replace with the actual admin user ID
  10.  
  11.         // Check if the group creator is the site admin
  12.         if ( $group->creator_id == $admin_id ) {
  13.             // If the creator is the admin, set the default cover image
  14.             $settings['default_cover'] = 'https://buddypress.local/wp-content/uploads/2023/11/road-g3567f8d60_1280.jpg'; // Replace with the URL of your default image
  15.         }
  16.     }
  17.  
  18.     // Return the settings, modified or not
  19.     return $settings;
  20. }
  21.  
  22. // Add the function to the BuddyPress filter hook to modify group cover image settings
  23. add_filter( 'bp_before_groups_cover_image_settings_parse_args', 'my_custom_group_cover_image_for_admin' );
  24.  
Tags: Buddypress
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement