Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mahfelwp/0a4f23104d21e4dbae4d2229bf831772 to your computer and use it in GitHub Desktop.
Save mahfelwp/0a4f23104d21e4dbae4d2229bf831772 to your computer and use it in GitHub Desktop.
Force user to choose pic for profile avatar in buddypress
<?php
function bp_force_user_to_set_profile_avatar() {
if ( ! is_user_logged_in() ) {
return;
}
$user_id = get_current_user_id();
if ( ! bp_get_user_has_avatar( $user_id ) && bp_current_action() != 'change-avatar' ) {
bp_core_add_message( __( 'please, set avatar for your profile, if you dont choose any picture for your profile avatar, you cant use website features', 'textdomain' ), 'error' );
bp_core_redirect( bp_loggedin_user_domain() . buddypress()->profile->slug . '/change-avatar/' );
}
}
add_action( 'template_redirect', 'bp_force_user_to_set_profile_avatar' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment