Skip to content
Snippets Groups Projects
Commit f3b96f7c authored by Erick Hitter's avatar Erick Hitter
Browse files

Add admin notice

parent df370039
No related branches found
No related tags found
1 merge request!5Prepare plugin for WP.org
Pipeline #5031 failed with stages
in 2 minutes and 5 seconds
......@@ -5,7 +5,7 @@ msgstr ""
"Project-Id-Version: Redis User Session Storage 0.2\n"
"Report-Msgid-Bugs-To: "
"https://wordpress.org/support/plugin/redis-user-session-storage\n"
"POT-Creation-Date: 2022-07-09 00:58:27+00:00\n"
"POT-Creation-Date: 2022-07-09 03:01:34+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
......@@ -25,6 +25,12 @@ msgstr ""
"X-Textdomain-Support: yes\n"
"X-Generator: grunt-wp-i18n 1.0.3\n"
#: redis-user-session-storage.php:89
msgid ""
"%1$s: An outdated version of this plugin, %2$s, is active. Please "
"deactivate it to use the current version."
msgstr ""
#. Plugin Name of the plugin/theme
msgid "Redis User Session Storage"
msgstr ""
......
......@@ -39,40 +39,59 @@ use WP_Session_Tokens;
* @return void
*/
function load() {
if ( ! class_exists( Redis::class, false ) ) {
return;
}
if ( ! class_exists( WP_Session_Tokens::class, false ) ) {
return;
}
if ( class_exists( WP_Redis_User_Session_Storage::class, false ) ) {
// TODO: warn user to disable old plugin.
if (
! class_exists( Redis::class, false )
|| ! class_exists( WP_Session_Tokens::class, false )
) {
return;
}
require_once __DIR__ . '/inc/class-plugin.php';
class_alias(
Plugin::class,
'WP_Redis_User_Session_Storage',
false
);
add_filter(
'session_token_manager',
__NAMESPACE__ . '\set_session_token_manager'
);
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\load' );
load();
/**
* Override Core's default usermeta-based token storage.
*
* @param string $manager
* @return string
*/
function set_session_token_manager() {
function set_session_token_manager( $manager ) {
if ( class_exists( WP_Redis_User_Session_Storage::class, false ) ) {
add_action( 'admin_notices', __NAMESPACE__ . '\admin_notice' );
return $manager;
}
return Plugin::class;
}
/**
* Show admin notice to certain users when older version is active.
*
* @return void
*/
function admin_notice() {
if ( ! current_user_can( 'activate_plugins' ) ) {
return;
}
?>
<div id="message" class="error">
<p>
<?php
printf(
__( '%1$s: An outdated version of this plugin, %2$s, is active. Please deactivate it to use the current version.', 'redis-user-session-storage' ),
'<strong>Redis User Session Storage</strong>',
'<em>WP Redis User Session Storage</em>'
);
?>
</p>
</div>
<?php
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment