WordPressAuthService
in package
Service class for WordPress authentication integration.
Handles WordPress authentication and session management. Links WordPress users to LWT users for multi-user support.
Tags
Table of Contents
Constants
- SESSION_KEY = 'LWT-WP-User'
- Session key for WordPress user ID.
Properties
Methods
- __construct() : mixed
- Create a new WordPressAuthService.
- clearSessionUser() : void
- Clear the WordPress user from the session.
- destroySession() : void
- Destroy the current PHP session completely.
- getCurrentUserId() : int|null
- Get the current WordPress user ID.
- getCurrentUserInfo() : array{id: int, username: string, email: string}|null
- Get the current WordPress user information.
- getLoginUrl() : string
- Get the WordPress login URL with redirect.
- getSessionUser() : int|null
- Get the WordPress user ID from the session.
- handleStart() : array{success: bool, redirect: string, error: string|null}
- Handle the WordPress start flow.
- handleStop() : array{success: bool, redirect: string}
- Handle the WordPress stop flow.
- isUserLoggedIn() : bool
- Check if the current user is logged into WordPress.
- loadWordPress() : bool
- Check if WordPress is available and load it.
- logout() : void
- Logout from WordPress and destroy the session.
- setSessionUser() : void
- Store the WordPress user ID in the session.
- startSession() : array{success: bool, error: string|null}
- Start a PHP session for LWT-WordPress integration.
- validateRedirectUrl() : string
- Validate and sanitize a redirect URL.
- getWordPressLoadPath() : string
- Get the path to WordPress wp-load.php.
Constants
SESSION_KEY
Session key for WordPress user ID.
private
mixed
SESSION_KEY
= 'LWT-WP-User'
Properties
$userFacade
private
UserFacade
$userFacade
User facade for LWT user management
Methods
__construct()
Create a new WordPressAuthService.
public
__construct(UserFacade $userFacade) : mixed
Parameters
- $userFacade : UserFacade
-
User facade for user management
clearSessionUser()
Clear the WordPress user from the session.
public
clearSessionUser() : void
destroySession()
Destroy the current PHP session completely.
public
destroySession() : void
getCurrentUserId()
Get the current WordPress user ID.
public
getCurrentUserId() : int|null
Return values
int|null —User ID or null if not logged in
getCurrentUserInfo()
Get the current WordPress user information.
public
getCurrentUserInfo() : array{id: int, username: string, email: string}|null
Return values
array{id: int, username: string, email: string}|null —User info or null if not logged in
getLoginUrl()
Get the WordPress login URL with redirect.
public
getLoginUrl([string $redirectTo = './lwt/wp_lwt_start.php' ]) : string
Parameters
- $redirectTo : string = './lwt/wp_lwt_start.php'
-
URL to redirect to after login
Return values
string —WordPress login URL
getSessionUser()
Get the WordPress user ID from the session.
public
getSessionUser() : int|null
Return values
int|null —User ID or null if not set
handleStart()
Handle the WordPress start flow.
public
handleStart([string|null $redirectUrl = null ]) : array{success: bool, redirect: string, error: string|null}
Authenticates via WordPress and links the WP user to an LWT user. If multi-user mode is enabled, creates or finds the corresponding LWT user and sets up the user context.
Parameters
- $redirectUrl : string|null = null
-
Requested redirect URL
Return values
array{success: bool, redirect: string, error: string|null}handleStop()
Handle the WordPress stop flow.
public
handleStop() : array{success: bool, redirect: string}
Logs out from WordPress and clears the LWT user context.
Return values
array{success: bool, redirect: string}isUserLoggedIn()
Check if the current user is logged into WordPress.
public
isUserLoggedIn() : bool
Return values
bool —True if user is logged in
loadWordPress()
Check if WordPress is available and load it.
public
loadWordPress() : bool
Return values
bool —True if WordPress was loaded successfully
logout()
Logout from WordPress and destroy the session.
public
logout() : void
setSessionUser()
Store the WordPress user ID in the session.
public
setSessionUser(int $userId) : void
Parameters
- $userId : int
-
WordPress user ID
startSession()
Start a PHP session for LWT-WordPress integration.
public
startSession() : array{success: bool, error: string|null}
Return values
array{success: bool, error: string|null}validateRedirectUrl()
Validate and sanitize a redirect URL.
public
validateRedirectUrl(string|null $redirectUrl) : string
Ensures the redirect target exists as a local file.
Parameters
- $redirectUrl : string|null
-
The requested redirect URL
Return values
string —Safe redirect URL (defaults to 'index.php')
getWordPressLoadPath()
Get the path to WordPress wp-load.php.
private
getWordPressLoadPath() : string
LWT must be installed in a subdirectory "lwt" under the WordPress main directory.
Return values
string —Path to wp-load.php