Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save dwanjuki/8159cfde63b7695ac59cc22bea6b38ea to your computer and use it in GitHub Desktop.

Select an option

Save dwanjuki/8159cfde63b7695ac59cc22bea6b38ea to your computer and use it in GitHub Desktop.
Remove "Hide from PMPro Directory?" checkbox from checkout and member profile edit page
<?php
/**
* Remove "Hide from PMPro Directory?" checkbox from checkout and member profile edit.
*
* 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 my_pmpromd_remove_hide_directory_field() {
global $pmpro_user_fields;
$field_group_name = esc_html__( 'Directory and Profile Preferences', 'pmpro-member-directory' );
// Bail if fields aren't set.
if ( empty( $pmpro_user_fields ) || empty( $pmpro_user_fields[ $field_group_name ] ) ) {
return;
}
// Find pmpromd_hide_directory field.
foreach ( $pmpro_user_fields[ $field_group_name ] as $key => $field ) {
if ( 'pmpromd_hide_directory' === $field->name ) {
// Show this field for admins only.
$pmpro_user_fields[ $field_group_name ][ $key ]->profile = 'only_admin';
return;
}
}
}
add_action( 'init', 'my_pmpromd_remove_hide_directory_field' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment