Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save calliaweb/5969199277971e6987e497494c1ced92 to your computer and use it in GitHub Desktop.
Save calliaweb/5969199277971e6987e497494c1ced92 to your computer and use it in GitHub Desktop.
Remove Messages from Navigation and Add Friends, Private Message and Public Message from BuddyPress profiles if current user or profile viewed does not have a Paid Membership Pro member level
<?php
add_action( 'bp_init', 'jmw_remove_buddypress_messages_for_non_ppmpro_members' );
/**
* Remove Messages from Navigation and Add Friends, Private Message and Public Message from BuddyPress profiles
* if current user or profile viewed does not have a Paid Membership Pro member level
*/
function jmw_remove_buddypress_messages_for_non_ppmpro_members() {
global $current_user;
if( function_exists( 'pmpro_getMembershipLevelsForUser' ) && function_exists( 'bp_displayed_user_id' ) ) {
$current_user_levels = pmpro_getMembershipLevelsForUser( $current_user->ID );
$displayed_user_levels = pmpro_getMembershipLevelsForUser( bp_displayed_user_id() );
if( empty( $current_user_levels ) || empty( $displayed_user_levels ) ) {
remove_action( 'bp_member_header_actions', 'bp_add_friend_button', 5 );
remove_action( 'bp_member_header_actions', 'bp_send_public_message_button', 20 );
remove_action( 'bp_member_header_actions', 'bp_send_private_message_button', 20 );
bp_core_remove_nav_item( 'messages' );
}
}
}
@henrywright
Copy link

pmpro_getMembershipLevelsForUser() will return an array of level objects so maybe you could check for expired levels? I'm away from the desk so can't check what those level objects contain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment