Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Redis User Session Storage
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WP Plugins
Redis User Session Storage
Commits
048c03fe
Commit
048c03fe
authored
10 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Initial commit using Core's usermeta implementation as a template
From
https://core.trac.wordpress.org/browser/trunk/src/wp-includes/session.php?rev=29635
parents
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wp-redis-session-storage.php
+136
-0
136 additions, 0 deletions
wp-redis-session-storage.php
with
136 additions
and
0 deletions
wp-redis-session-storage.php
0 → 100644
+
136
−
0
View file @
048c03fe
<?php
/**
* Meta-based user sessions token manager.
*
* @since 4.0.0
*/
class
WP_Redis_Session_Storage
extends
WP_Session_Tokens
{
/**
* Get all sessions of a user.
*
* @since 4.0.0
* @access protected
*
* @return array Sessions of a user.
*/
protected
function
get_sessions
()
{
$sessions
=
get_user_meta
(
$this
->
user_id
,
'session_tokens'
,
true
);
if
(
!
is_array
(
$sessions
)
)
{
return
array
();
}
$sessions
=
array_map
(
array
(
$this
,
'prepare_session'
),
$sessions
);
return
array_filter
(
$sessions
,
array
(
$this
,
'is_still_valid'
)
);
}
/**
* Converts an expiration to an array of session information.
*
* @param mixed $session Session or expiration.
* @return array Session.
*/
protected
function
prepare_session
(
$session
)
{
if
(
is_int
(
$session
)
)
{
return
array
(
'expiration'
=>
$session
);
}
return
$session
;
}
/**
* Retrieve a session by its verifier (token hash).
*
* @since 4.0.0
* @access protected
*
* @param string $verifier Verifier of the session to retrieve.
* @return array|null The session, or null if it does not exist
*/
protected
function
get_session
(
$verifier
)
{
$sessions
=
$this
->
get_sessions
();
if
(
isset
(
$sessions
[
$verifier
]
)
)
{
return
$sessions
[
$verifier
];
}
return
null
;
}
/**
* Update a session by its verifier.
*
* @since 4.0.0
* @access protected
*
* @param string $verifier Verifier of the session to update.
* @param array $session Optional. Session. Omitting this argument destroys the session.
*/
protected
function
update_session
(
$verifier
,
$session
=
null
)
{
$sessions
=
$this
->
get_sessions
();
if
(
$session
)
{
$sessions
[
$verifier
]
=
$session
;
}
else
{
unset
(
$sessions
[
$verifier
]
);
}
$this
->
update_sessions
(
$sessions
);
}
/**
* Update a user's sessions in the usermeta table.
*
* @since 4.0.0
* @access protected
*
* @param array $sessions Sessions.
*/
protected
function
update_sessions
(
$sessions
)
{
if
(
!
has_filter
(
'attach_session_information'
)
)
{
$sessions
=
wp_list_pluck
(
$sessions
,
'expiration'
);
}
if
(
$sessions
)
{
update_user_meta
(
$this
->
user_id
,
'session_tokens'
,
$sessions
);
}
else
{
delete_user_meta
(
$this
->
user_id
,
'session_tokens'
);
}
}
/**
* Destroy all session tokens for a user, except a single session passed.
*
* @since 4.0.0
* @access protected
*
* @param string $verifier Verifier of the session to keep.
*/
protected
function
destroy_other_sessions
(
$verifier
)
{
$session
=
$this
->
get_session
(
$verifier
);
$this
->
update_sessions
(
array
(
$verifier
=>
$session
)
);
}
/**
* Destroy all session tokens for a user.
*
* @since 4.0.0
* @access protected
*/
protected
function
destroy_all_sessions
()
{
$this
->
update_sessions
(
array
()
);
}
/**
* Destroy all session tokens for all users.
*
* @since 4.0.0
* @access public
* @static
*/
public
static
function
drop_sessions
()
{
delete_metadata
(
'user'
,
false
,
'session_tokens'
,
false
,
true
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment