Last active
August 9, 2022 20:34
-
-
Save fida02/5fde0757eb41c18a351d4ed4bd2ba33e to your computer and use it in GitHub Desktop.
WPMUDEV Unique customer ID Task
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 | |
| /** | |
| * Unique customer ID | |
| * | |
| * @return string | |
| */ | |
| function wpmu_unique_id() { | |
| // Get current user object | |
| $current_user = wp_get_current_user(); | |
| // Check is user logged in | |
| if( $current_user->exists() ) { | |
| // Unique ID prefix | |
| $prefix = 'wpmu-'; | |
| // User registration date and time | |
| $registered_date_time = date( 'jis', strtotime( $current_user->user_registered ) ) ; | |
| // User ID | |
| $user_id = esc_html( $current_user->ID ); | |
| // Create the unique ID | |
| $unique_id = $prefix . $registered_date_time . $user_id; | |
| return $unique_id; | |
| } | |
| } | |
| // Add shortcode [wpmu_unique_id] | |
| add_shortcode( 'wpmu_unique_id', 'wpmu_unique_id' ); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment