Last active
August 26, 2017 15:02
-
-
Save zacwasielewski/ce638c822f04389d33f0 to your computer and use it in GitHub Desktop.
Lock editing of BuddyPress profile fields. Plugin here: https://github.com/zacwasielewski/buddypress-lock-profile-fields/
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 snippet hides locked fields on the profile edit form. | |
Add to `wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/members/single/profile/edit.php` | |
immediately after <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?> (near line 22): | |
*/ | |
<?php if ( in_array( bp_get_the_profile_field_name(), bp_get_locked_profile_fields() )) { continue; } ?> |
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 to the end of your theme's `functions.php`, and customize $bp_locked_profile_fields if necessary: | |
*/ | |
global $bp_locked_profile_fields; | |
$bp_locked_profile_fields = array( | |
'Assumption of Risk (please initial)', | |
'Waiver (please initial)', | |
'Indemnification (please initial)', | |
'Acknowledgment (please type your full name and date)' | |
); | |
function bp_get_locked_profile_fields() { | |
global $bp_locked_profile_fields; | |
return $bp_locked_profile_fields; | |
} | |
function bp_get_locked_field_ids( $locked_field_names ) { | |
$ids = array(); | |
while ( bp_profile_fields() ): bp_the_profile_field(); | |
$field_name = bp_get_the_profile_field_name(); | |
if ( in_array($field_name, $locked_field_names )) { | |
$ids[] = bp_get_the_profile_field_id(); | |
} | |
endwhile; | |
return $ids; | |
} | |
function bp_exclude_locked_field_ids( $ids_string ) { | |
$locked_ids = bp_get_locked_field_ids( bp_get_locked_profile_fields() ); | |
$ids = explode(',',$ids_string); | |
return implode(',',array_diff($ids, $locked_ids)); | |
} | |
function bp_modify_locked_profile_field_type( $type ) { | |
$locked_field_names = bp_get_locked_profile_fields(); | |
$field_name = bp_get_the_profile_field_name(); | |
if ( in_array($field_name, $locked_field_names )) { | |
return 'locked'; | |
} | |
return $type; | |
} | |
function lock_profile_edit_fields() { | |
add_filter( 'bp_get_the_profile_field_ids', 'bp_exclude_locked_field_ids', 10, 1 ); | |
add_filter( 'bp_the_profile_field_type', 'bp_modify_locked_profile_field_type', 10, 1 ); | |
} | |
add_action( 'xprofile_screen_edit_profile', 'lock_profile_edit_fields'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment