Created
April 3, 2016 13:45
-
-
Save carlodaniele/6ac5eb12ca3ddb215d479ca74ebe511c to your computer and use it in GitHub Desktop.
This file contains hidden or 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( 'personal_options_update', 'wpmu_usermeta_update' ); | |
add_action( 'edit_user_profile_update', 'wpmu_usermeta_update' ); | |
/** | |
* Save user extra meta data | |
* | |
* @param $user_id The user ID of the user being edited | |
* | |
* @link https://developer.wordpress.org/reference/hooks/personal_options_update/ | |
* @link https://developer.wordpress.org/reference/hooks/edit_user_profile_update/ | |
*/ | |
function wpmu_usermeta_update( $user_id ){ | |
if ( !current_user_can( 'edit_user', $user_id ) ){ | |
return false; | |
} | |
// Reset the checkbox | |
if( !isset( $_POST['wpmu']['guitar'] ) ){ | |
$_POST['wpmu']['guitar'] = 'No'; | |
} | |
if( isset($_POST['wpmu']) ){ | |
foreach ( $_POST['wpmu'] as $key => $value ) { | |
update_user_meta( $user_id, 'wpmu_' . $key, $value ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment