Created
October 7, 2016 16:43
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); | |
} | |
} | |
} |
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
Needs more testing. For example what if the current user or displayed member used to have a membership level?