Created
July 27, 2020 10:49
-
-
Save ipokkel/8cb2691b6054d8910aef06ffc15bce71 to your computer and use it in GitHub Desktop.
Add a hide member profile from Member Directory in Add Member from Admin
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 creates a checkbox in addmember to optionally | |
* hide a member's profile from the Member Directory and Profile | |
* pages. | |
* | |
* @requires Register Helper Add On | |
* @link https://www.paidmembershipspro.com/add-ons/pmpro-register-helper-add-checkout-and-profile-fields/ | |
* | |
* 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 pmpromd_hide_from_directory_addmember_field() { | |
// Don't break if Register Helper is not loaded. | |
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) { | |
return false; | |
} | |
// Bail if not in administrative area or Member Directory not active. | |
if ( ! is_admin() || ! function_exists( 'pmpro_addmember' ) || ! defined( 'PMPRO_MEMBER_DIRECTORY_VERSION' ) ) { | |
return; | |
} | |
// Define the field. | |
$fields = array(); | |
$fields[] = new PMProRH_Field( | |
'pmpromd_hide_directory', | |
'checkbox', | |
array( | |
'label' => 'Member Directory', | |
'text' => 'Exclude profile from the member directory.', | |
'profile' => false, | |
'addmember' => true, | |
) | |
); | |
// Add the fields into the checkout_boxes are of the checkout page. | |
foreach ( $fields as $field ) { | |
pmprorh_add_registration_field( | |
'checkout_boxes', | |
$field | |
); | |
} | |
} | |
add_action( 'init', 'pmpromd_hide_from_directory_addmember_field' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment