Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRESS2-1259 | added get current user info #11

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions includes/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static function runtime() {
'settings' => Preview::get_settings(),
'stepPreviewData' => Themes::step_preview_data(),
),
'currentUserDetails' => self::wp_current_user_details(),
);
}

Expand Down Expand Up @@ -147,4 +148,24 @@ public static function coming_soon() {
return false;
}

/**
* Get the current WordPress admin user details.
*
* @return array
*/
public static function wp_current_user_details() {
$user = wp_get_current_user();
if ( $user->exists() ) {
return array(
'displayName' => $user->display_name,
'avatarUrl' => get_avatar_url( $user->ID ),
);
}

// If no user is found, return an empty array or default values as appropriate
return array(
'displayName' => '',
'avatarUrl' => '',
);
}
}