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

Merge branch 'update/prep-for-dotorg' into 'master'

Prepare plugin for WP.org

See merge request wp-plugins/redis-user-session-storage!5
parents 182c1dde 711abeeb
No related branches found
No related tags found
1 merge request!5Prepare plugin for WP.org
Pipeline #5036 failed with stages
in 2 minutes and 11 seconds
...@@ -9,7 +9,7 @@ module.exports = function( grunt ) { ...@@ -9,7 +9,7 @@ module.exports = function( grunt ) {
addtextdomain: { addtextdomain: {
options: { options: {
textdomain: 'wp_redis_user_session_storage', textdomain: 'redis-user-session-storage',
}, },
update_all_domains: { update_all_domains: {
options: { options: {
...@@ -32,8 +32,8 @@ module.exports = function( grunt ) { ...@@ -32,8 +32,8 @@ module.exports = function( grunt ) {
options: { options: {
domainPath: '/languages', domainPath: '/languages',
exclude: [ '\.git/*', 'bin/*', 'node_modules/*', 'tests/*' ], exclude: [ '\.git/*', 'bin/*', 'node_modules/*', 'tests/*' ],
mainFile: 'wp-redis-user-session-storage.php', mainFile: 'redis-user-session-storage.php',
potFilename: 'wp-redis-user-session-storage.pot', potFilename: 'redis-user-session-storage.pot',
potHeaders: { potHeaders: {
poedit: true, poedit: true,
'x-poedit-keywordslist': true 'x-poedit-keywordslist': true
......
# WP Redis User Session Storage # # Redis User Session Storage #
**Contributors:** [ethitter](https://profiles.wordpress.org/ethitter/) **Contributors:** [ethitter](https://profiles.wordpress.org/ethitter/)
**Donate link:** https://ethitter.com/donate/ **Donate link:** https://ethitter.com/donate/
**Tags:** user sessions, session tokens, session storage **Tags:** user sessions, session tokens, session storage
**Requires at least:** 4.0 **Requires at least:** 4.0
**Tested up to:** 5.2 **Tested up to:** 6.0
**Stable tag:** 0.1 **Stable tag:** 0.2
**Requires PHP:** 5.3 **Requires PHP:** 5.6
**License:** GPLv2 or later **License:** GPLv2 or later
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html **License URI:** http://www.gnu.org/licenses/gpl-2.0.html
...@@ -15,21 +15,39 @@ Store WordPress session tokens in Redis rather than the usermeta table. ...@@ -15,21 +15,39 @@ Store WordPress session tokens in Redis rather than the usermeta table.
Store WordPress user session tokens in Redis rather than the usermeta table. Store WordPress user session tokens in Redis rather than the usermeta table.
This plugin was previously known as `WP Redis User Session Storage` and was renamed to comply with WordPress.org naming constraints.
## Installation ## ## Installation ##
1. Install and configure Redis. There is a good tutorial [here](http://www.saltwebsites.com/2012/install-redis-245-service-centos-6). 1. Install and configure Redis.
2. Install the [Redis PECL module](http://pecl.php.net/package/redis). 2. Install the [Redis PECL module](http://pecl.php.net/package/redis).
3. Activate the plugin network-wide or by placing it in `mu-plugins`. 3. Activate the plugin network-wide or by placing it in `mu-plugins`.
4. By default, the script will connect to Redis at 127.0.0.1:6379. See the *Connecting to Redis* section for further options. 4. By default, the script will connect to Redis at `127.0.0.1:6379`. See the *Connecting to Redis* section for further options.
## Frequently Asked Questions ## ## Frequently Asked Questions ##
### Connecting to Redis ### ### Connecting to Redis ###
By default, the plugin uses `127.0.0.1` and `6379` as the default host and port when creating a new client instance; the default database of `0` is also used. Three constants are provided to override these default values. By default, the plugin uses `127.0.0.1` and `6379` as the default host and port, respectively, when creating a new client instance; the default database of `0` is also used.
Specify any of the following constants to set the necessary, non-default connection values for your Redis instance:
* `WP_REDIS_USER_SESSION_HOST` - Hostname or IP of the Redis server, defaults to `127.0.0.1`.
* `WP_REDIS_USER_SESSION_PORT` - Port of the Redis server, defaults to `6379`.
* `WP_REDIS_USER_SESSION_SOCKET` - Path to a Unix socket file for the Redis server, if available. Takes precedence over the port value when set.
* `WP_REDIS_USER_SESSION_AUTH` - Password for the Redis server, if required.
* `WP_REDIS_USER_SESSION_DB` - Database number to use for the Redis server, defaults to `0`.
* `WP_REDIS_USER_SESSION_SERIALIZER` - Serializer to use for the Redis server, defaults to `Redis::SERIALIZER_PHP`.
Specify `WP_REDIS_USER_SESSION_HOST`, `WP_REDIS_USER_SESSION_PORT`, and `WP_REDIS_USER_SESSION_DB` to set the necessary, non-default connection values for your Redis instance. ### How do I upgrade from WP Redis User Session Storage? ###
Install and activate this plugin, then deactivate the old plugin. Both plugins can safely be activated together as long as no additional classes extend the `WP_Redis_User_Session_Storage` class. After activating this plugin, deactivate the `WP Redis User Session Storage` plugin and remove it.
## Changelog ## ## Changelog ##
### 0.2 ###
* Rename plugin to `Redis User Session Storage` to submit to WordPress.org plugins repository.
* Allow two versions of this plugin to co-exist safely to support seamless migration.
* Changes plugin class name to `Redis_User_Session_Storage` from `WP_Redis_User_Session_Storage`.
### 0.1 ### ### 0.1 ###
* Initial public release * Initial public release
{ {
"name" : "ethitter/wp-redis-user-session-storage", "name" : "ethitter/redis-user-session-storage",
"description" : "Store WordPress session tokens in Redis rather than the usermeta table. Requires the Redis PECL extension.", "description" : "Store WordPress session tokens in Redis rather than the usermeta table. Requires the Redis PECL extension.",
"homepage" : "https://ethitter.com/", "homepage" : "https://ethitter.com/",
"type" : "wordpress-plugin", "type" : "wordpress-plugin",
......
...@@ -2,22 +2,21 @@ ...@@ -2,22 +2,21 @@
/** /**
* Offload session storage to Redis. * Offload session storage to Redis.
* *
* @package WP_Redis_User_Session_Storage * @package Redis_User_Session_Storage
*/ */
/** namespace Redis_User_Session_Storage;
* Don't load in contexts that lack the WP_Session_Tokens class
*/ use Redis;
if ( ! class_exists( 'WP_Session_Tokens' ) ) { use RedisException;
return; use WP_Session_Tokens;
}
/** /**
* Redis-based user sessions token manager. * Redis-based user sessions token manager.
* *
* @since 0.1 * @since 0.1
*/ */
class WP_Redis_User_Session_Storage extends WP_Session_Tokens { class Plugin extends WP_Session_Tokens {
/** /**
* Holds the Redis client. * Holds the Redis client.
* *
...@@ -270,13 +269,3 @@ class WP_Redis_User_Session_Storage extends WP_Session_Tokens { ...@@ -270,13 +269,3 @@ class WP_Redis_User_Session_Storage extends WP_Session_Tokens {
return $this->prefix . ':' . $this->user_id; return $this->prefix . ':' . $this->user_id;
} }
} }
/**
* Override Core's default usermeta-based token storage
*
* @return string
*/
function wp_redis_user_session_storage() {
return 'WP_Redis_User_Session_Storage';
}
add_filter( 'session_token_manager', 'wp_redis_user_session_storage' );
# Copyright (C) 2022 Erick Hitter # Copyright (C) 2022 Erick Hitter
# This file is distributed under the same license as the WP Redis User Session Storage package. # This file is distributed under the same license as the Redis User Session Storage package.
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: WP Redis User Session Storage 0.1\n" "Project-Id-Version: Redis User Session Storage 0.2\n"
"Report-Msgid-Bugs-To: " "Report-Msgid-Bugs-To: "
"https://wordpress.org/support/plugin/wp-redis-user-session-storage\n" "https://wordpress.org/support/plugin/redis-user-session-storage\n"
"POT-Creation-Date: 2022-07-01 04:12:36+00:00\n" "POT-Creation-Date: 2022-07-09 03:45:24+00:00\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n" "Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
...@@ -25,12 +25,19 @@ msgstr "" ...@@ -25,12 +25,19 @@ msgstr ""
"X-Textdomain-Support: yes\n" "X-Textdomain-Support: yes\n"
"X-Generator: grunt-wp-i18n 1.0.3\n" "X-Generator: grunt-wp-i18n 1.0.3\n"
#: redis-user-session-storage.php:90
#. translators: 1: New plugin name, 2: Old plugin name
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 #. Plugin Name of the plugin/theme
msgid "WP Redis User Session Storage" msgid "Redis User Session Storage"
msgstr "" msgstr ""
#. Plugin URI of the plugin/theme #. Plugin URI of the plugin/theme
msgid "https://ethitter.com/plugins/wp-redis-user-session-storage/" msgid "https://ethitter.com/plugins/redis-user-session-storage/"
msgstr "" msgstr ""
#. Description of the plugin/theme #. Description of the plugin/theme
......
{ {
"name": "wp-redis-user-session-storage", "name": "redis-user-session-storage",
"version": "0.1.0", "version": "0.1.0",
"main": "Gruntfile.js", "main": "Gruntfile.js",
"author": "Erick Hitter", "author": "Erick Hitter",
......
<?xml version="1.0"?> <?xml version="1.0"?>
<ruleset name="WP Redis User Session Storage"> <ruleset name="Redis User Session Storage">
<description>Generally-applicable sniffs for WordPress plugins.</description> <description>Generally-applicable sniffs for WordPress plugins.</description>
<!-- What to scan --> <!-- What to scan -->
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<!-- Rules: Check PHP version compatibility --> <!-- Rules: Check PHP version compatibility -->
<!-- https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions --> <!-- https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
<config name="testVersion" value="5.3-"/> <config name="testVersion" value="5.6-"/>
<!-- https://github.com/PHPCompatibility/PHPCompatibilityWP --> <!-- https://github.com/PHPCompatibility/PHPCompatibilityWP -->
<rule ref="PHPCompatibilityWP"/> <rule ref="PHPCompatibilityWP"/>
...@@ -32,13 +32,13 @@ ...@@ -32,13 +32,13 @@
<rule ref="WordPress.NamingConventions.PrefixAllGlobals"> <rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties> <properties>
<!-- Value: replace the function, class, and variable prefixes used. Separate multiple prefixes with a comma. --> <!-- Value: replace the function, class, and variable prefixes used. Separate multiple prefixes with a comma. -->
<property name="prefixes" type="array" value="wp_redis_user_session_storage"/> <property name="prefixes" type="array" value="redis_user_session_storage,wp_redis_user_session_storage"/>
</properties> </properties>
</rule> </rule>
<rule ref="WordPress.WP.I18n"> <rule ref="WordPress.WP.I18n">
<properties> <properties>
<!-- Value: replace the text domain used. --> <!-- Value: replace the text domain used. -->
<property name="text_domain" type="array" value="wp_redis_user_session_storage"/> <property name="text_domain" type="array" value="redis-user-session-storage"/>
</properties> </properties>
</rule> </rule>
<rule ref="WordPress.WhiteSpace.ControlStructureSpacing"> <rule ref="WordPress.WhiteSpace.ControlStructureSpacing">
......
=== WP Redis User Session Storage === === Redis User Session Storage ===
Contributors: ethitter Contributors: ethitter
Donate link: https://ethitter.com/donate/ Donate link: https://ethitter.com/donate/
Tags: user sessions, session tokens, session storage Tags: user sessions, session tokens, session storage
Requires at least: 4.0 Requires at least: 4.0
Tested up to: 5.2 Tested up to: 6.0
Stable tag: 0.1 Stable tag: 0.2
Requires PHP: 5.3 Requires PHP: 5.6
License: GPLv2 or later License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html License URI: http://www.gnu.org/licenses/gpl-2.0.html
...@@ -15,21 +15,39 @@ Store WordPress session tokens in Redis rather than the usermeta table. ...@@ -15,21 +15,39 @@ Store WordPress session tokens in Redis rather than the usermeta table.
Store WordPress user session tokens in Redis rather than the usermeta table. Store WordPress user session tokens in Redis rather than the usermeta table.
This plugin was previously known as `WP Redis User Session Storage` and was renamed to comply with WordPress.org naming constraints.
== Installation == == Installation ==
1. Install and configure Redis. There is a good tutorial [here](http://www.saltwebsites.com/2012/install-redis-245-service-centos-6). 1. Install and configure Redis.
2. Install the [Redis PECL module](http://pecl.php.net/package/redis). 2. Install the [Redis PECL module](http://pecl.php.net/package/redis).
3. Activate the plugin network-wide or by placing it in `mu-plugins`. 3. Activate the plugin network-wide or by placing it in `mu-plugins`.
4. By default, the script will connect to Redis at 127.0.0.1:6379. See the *Connecting to Redis* section for further options. 4. By default, the script will connect to Redis at `127.0.0.1:6379`. See the *Connecting to Redis* section for further options.
== Frequently Asked Questions == == Frequently Asked Questions ==
= Connecting to Redis = = Connecting to Redis =
By default, the plugin uses `127.0.0.1` and `6379` as the default host and port when creating a new client instance; the default database of `0` is also used. Three constants are provided to override these default values. By default, the plugin uses `127.0.0.1` and `6379` as the default host and port, respectively, when creating a new client instance; the default database of `0` is also used.
Specify any of the following constants to set the necessary, non-default connection values for your Redis instance:
* `WP_REDIS_USER_SESSION_HOST` - Hostname or IP of the Redis server, defaults to `127.0.0.1`.
* `WP_REDIS_USER_SESSION_PORT` - Port of the Redis server, defaults to `6379`.
* `WP_REDIS_USER_SESSION_SOCKET` - Path to a Unix socket file for the Redis server, if available. Takes precedence over the port value when set.
* `WP_REDIS_USER_SESSION_AUTH` - Password for the Redis server, if required.
* `WP_REDIS_USER_SESSION_DB` - Database number to use for the Redis server, defaults to `0`.
* `WP_REDIS_USER_SESSION_SERIALIZER` - Serializer to use for the Redis server, defaults to `Redis::SERIALIZER_PHP`.
Specify `WP_REDIS_USER_SESSION_HOST`, `WP_REDIS_USER_SESSION_PORT`, and `WP_REDIS_USER_SESSION_DB` to set the necessary, non-default connection values for your Redis instance. = How do I upgrade from WP Redis User Session Storage? =
Install and activate this plugin, then deactivate the old plugin. Both plugins can safely be activated together as long as no additional classes extend the `WP_Redis_User_Session_Storage` class. After activating this plugin, deactivate the `WP Redis User Session Storage` plugin and remove it.
== Changelog == == Changelog ==
= 0.2 =
* Rename plugin to `Redis User Session Storage` to submit to WordPress.org plugins repository.
* Allow two versions of this plugin to co-exist safely to support seamless migration.
* Changes plugin class name to `Redis_User_Session_Storage` from `WP_Redis_User_Session_Storage`.
= 0.1 = = 0.1 =
* Initial public release * Initial public release
<?php <?php
/** /**
* Load plugin. * Plugin Name: Redis User Session Storage
* * Plugin URI: https://ethitter.com/plugins/redis-user-session-storage/
* @package WP_Redis_User_Session_Storage
*/
/**
* Plugin Name: WP Redis User Session Storage
* Plugin URI: https://ethitter.com/plugins/wp-redis-user-session-storage/
* Description: Store WordPress session tokens in Redis rather than the usermeta table. Requires the Redis PECL extension. * Description: Store WordPress session tokens in Redis rather than the usermeta table. Requires the Redis PECL extension.
* Version: 0.1 * Version: 0.2
* Author: Erick Hitter * Author: Erick Hitter
* Author URI: https://ethitter.com/ * Author URI: https://ethitter.com/
* *
...@@ -26,6 +20,79 @@ ...@@ -26,6 +20,79 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package Redis_User_Session_Storage
*/
namespace Redis_User_Session_Storage;
use Redis;
use WP_Redis_User_Session_Storage;
use WP_Session_Tokens;
/**
* Load plugin when safe to do so, accounting for previous plugin name.
*
* WordPress.org no longer accepts plugins beginning with the `WP` prefix, so
* this was renamed to comply.
*
* @return void
*/
function load() {
if (
! class_exists( Redis::class, false )
|| ! class_exists( WP_Session_Tokens::class, false )
) {
return;
}
require_once __DIR__ . '/inc/class-plugin.php';
// Hooked at 9 in case old plugin is also active.
add_filter(
'session_token_manager',
__NAMESPACE__ . '\set_session_token_manager',
9
);
}
load();
/**
* Override Core's default usermeta-based token storage.
*
* @param string $manager Name of session-manager class.
* @return string
*/
function set_session_token_manager( $manager ) {
if ( class_exists( WP_Redis_User_Session_Storage::class, false ) ) {
add_action( 'admin_notices', __NAMESPACE__ . '\admin_notice' );
}
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;
}
require_once __DIR__ . '/inc/class-wp-redis-user-session-storage.php'; ?>
<div id="message" class="error">
<p>
<?php
printf(
/* translators: 1: New plugin name, 2: Old plugin name */
esc_html__( '%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
}
...@@ -5,39 +5,27 @@ ...@@ -5,39 +5,27 @@
* @package WP_Revisions_Control * @package WP_Revisions_Control
*/ */
$wp_redis_user_session_storage = getenv( 'WP_TESTS_DIR' ); $redis_user_session_storage = getenv( 'WP_TESTS_DIR' );
if ( ! $wp_redis_user_session_storage ) { if ( ! $redis_user_session_storage ) {
$wp_redis_user_session_storage = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib'; $redis_user_session_storage = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
} }
if ( ! file_exists( $wp_redis_user_session_storage . '/includes/functions.php' ) ) { if ( ! file_exists( $redis_user_session_storage . '/includes/functions.php' ) ) {
echo "Could not find $wp_redis_user_session_storage/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL; // WPCS: XSS ok. echo "Could not find $redis_user_session_storage/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL; // WPCS: XSS ok.
exit( 1 ); exit( 1 );
} }
// Give access to tests_add_filter() function. // Give access to tests_add_filter() function.
require_once $wp_redis_user_session_storage . '/includes/functions.php'; require_once $redis_user_session_storage . '/includes/functions.php';
/**
* Stub admin-only function not needed for testing.
*/
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
if ( ! function_exists( 'post_revisions_meta_box' ) ) {
/**
* Stub for Core's revisions meta box.
*/
function post_revisions_meta_box() {}
}
// phpcs:enable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
/** /**
* Manually load the plugin being tested. * Manually load the plugin being tested.
*/ */
function wp_redis_user_session_storage_tests_manually_load_plugin() { function redis_user_session_storage_tests_manually_load_plugin() {
require dirname( dirname( __FILE__ ) ) . '/wp-redis-user-session-storage.php'; require dirname( dirname( __FILE__ ) ) . '/redis-user-session-storage.php';
} }
tests_add_filter( 'muplugins_loaded', 'wp_redis_user_session_storage_tests_manually_load_plugin' ); tests_add_filter( 'muplugins_loaded', 'redis_user_session_storage_tests_manually_load_plugin' );
// Start up the WP testing environment. // Start up the WP testing environment.
require $wp_redis_user_session_storage . '/includes/bootstrap.php'; require $redis_user_session_storage . '/includes/bootstrap.php';
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/** /**
* Class SampleTest * Class SampleTest
* *
* @package WP_Redis_User_Session_Storage * @package Redis_User_Session_Storage
*/ */
/** /**
......
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