vapvarun icon

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

vapvarun | PRO | 11/30/23 04:43:34 PM UTC | 0 ⭐ | 1539 👁️ | Never ⏰ | [Buddypress]
PHP |

1.05 KB

|

Software

|

0 👍

/

0 👎

// Function to set a default cover image for groups created by the site admin
function my_custom_group_cover_image_for_admin( $settings = array() ) {
    // Check if we are within a group context
    if ( bp_is_group() ) {
        // Fetches the current group details
        $group = groups_get_current_group();
 
        // Set this to the user ID of the site admin
        $admin_id = 1; // Replace with the actual admin user ID
 
        // Check if the group creator is the site admin
        if ( $group->creator_id == $admin_id ) {
            // If the creator is the admin, set the default cover image
            $settings['default_cover'] = 'https://buddypress.local/wp-content/uploads/2023/11/road-g3567f8d60_1280.jpg'; // Replace with the URL of your default image
        }
    }
 
    // Return the settings, modified or not
    return $settings;
}
 
// Add the function to the BuddyPress filter hook to modify group cover image settings
add_filter( 'bp_before_groups_cover_image_settings_parse_args', 'my_custom_group_cover_image_for_admin' );
 

Comments