Created
August 9, 2024 13:25
-
-
Save plugin-republic/f621c52f35eba82935ccc05e24ffa384 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 | |
/** | |
* Automatically populate a field with user data | |
* Enter the user field in the 'Default' field | |
* Wrapped in {} | |
* E.g. {first_name} | |
*/ | |
function junhee_populate_user_field( $value, $id, $item, $posted ) { | |
if( is_user_logged_in() ) { | |
// Check if the default value is wrapped in {} | |
if( substr( $value, 0, 1) == '{' ) { | |
$stripped_value = str_replace( array( '{', '}' ), '', $value ); | |
$user_id = get_current_user_id(); | |
$value = get_user_meta( $user_id, $stripped_value, true ); | |
} | |
} | |
return $value; | |
} | |
add_filter( 'pewc_default_field_value', 'junhee_populate_user_field', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment