Control if user can record voice messages with hooks

You are here:
< All Topics
add_action('init', 'disable_voice_messages');
function disable_voice_messages(){
if (!function_exists('BP_Better_Messages_Voice_Messages')) return false;

    $user_id = get_current_user_id();
    $user = get_userdata($user_id);
    $allowed_roles = (array)['administrator', 'other_role'];
    $user_roles = (array)$user->roles;

    $is_allowed = false;
    foreach ($user_roles as $user_role) {
        if (in_array($user_role, $allowed_roles)) {
            $is_allowed = true;
        }
    }

    if ( ! $is_allowed ) {
        remove_action('bp_better_messages_before_reply_send', array(BP_Better_Messages_Voice_Messages(), 'add_voice_message_button'));
    }
}
Previous Control if user can make audio/video call with hooks
Next Control if user can reply to thread with hooks
Table of Contents