Created
April 14, 2021 09:58
-
-
Save ipokkel/aa07a52e10db3b0f5dcdc92e67aa2083 to your computer and use it in GitHub Desktop.
Hide a new member's profile from the PMPro Directory by default #pmpro-directory
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 | |
/** | |
* This recipe defaults to hide a new member's profile from the directory | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function hide_member_from_directory_by_default() { | |
global $wpdb, $current_user; | |
// Check if user previously belonged to a membership level | |
$levelshistory = $wpdb->get_results( "SELECT * FROM $wpdb->pmpro_memberships_users WHERE user_id = '$current_user->ID' ORDER BY id DESC" ); | |
// Bail if this is not member's first checkout | |
if ( count( $levelshistory ) > 1 ) { | |
return; | |
} | |
// Set hide from directory if it hasn't been set before. | |
if ( empty( get_user_meta( $current_user->ID, 'pmpromd_hide_directory', true ) ) ) { | |
update_user_meta( $current_user->ID, 'pmpromd_hide_directory', '1' ); | |
} | |
} | |
add_action( 'pmpro_after_checkout', 'hide_member_from_directory_by_default' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment