Merged in feature/MAW-855-import-code-into-aws (pull request #2)

code import from pantheon

* code import from pantheon
This commit is contained in:
Tony Volpe
2023-12-04 23:08:14 +00:00
parent 8c9b1312bc
commit 8f4b5efda6
4766 changed files with 185592 additions and 239967 deletions

View File

@@ -0,0 +1,11 @@
jQuery(document).ready(function($) {
$(document).on('click', '.notice-dismiss', function() {
$.ajax({
url: ajaxurl,
type: 'POST',
data: {
action: 'dismiss_notice'
}
});
});
});

View File

@@ -135,5 +135,4 @@ class Admin {
</script>
<?php
}
}

View File

@@ -79,6 +79,38 @@ class CLI_Command extends \WP_CLI_Command {
}
}
/**
* Set id as primary key in the Native PHP Sessions plugin table.
*
* @subcommand add-index
*/
public function add_index( $args, $assoc_args ) {
$pantheon_session = new \Pantheon_Sessions();
$resume_point = isset( $assoc_args['start_point'] ) ? $assoc_args['start_point'] : 0;
$pantheon_session->add_index( $resume_point );
}
/**
* Finalizes the creation of a primary key by deleting the old data.
*
* @subcommand primary-key-finalize
*/
public function primary_key_finalize( $args, $assoc_args ) {
$pantheon_session = new \Pantheon_Sessions();
$resume_point = isset( $assoc_args['start_point'] ) ? $assoc_args['start_point'] : 0;
$pantheon_session->primary_key_finalize( $resume_point );
}
/**
* Reverts addition of primary key.
*
* @subcommand primary-key-revert
*/
public function primary_key_revert( $args, $assoc_args ) {
$pantheon_session = new \Pantheon_Sessions();
$resume_point = isset( $assoc_args['start_point'] ) ? $assoc_args['start_point'] : 0;
$pantheon_session->primary_key_revert( $resume_point );
}
}
\WP_CLI::add_command( 'pantheon session', '\Pantheon_Sessions\CLI_Command' );

View File

@@ -42,7 +42,7 @@ class List_Table extends \WP_List_Table {
* Message for no items found
*/
public function no_items() {
_e( 'No sessions found.', 'wp-native-php-sessions' );
esc_html_e( 'No sessions found.', 'wp-native-php-sessions' );
}
/**
@@ -84,5 +84,4 @@ class List_Table extends \WP_List_Table {
return esc_html( $item->$column_name );
}
}
}

View File

@@ -123,5 +123,4 @@ class Session_Handler implements \SessionHandlerInterface {
public function close() {
return true;
}
}

View File

@@ -319,5 +319,4 @@ class Session {
return 'session_id';
}
}
}

View File

@@ -1,7 +1,7 @@
<?php
/**
* Plugin Name: Native PHP Sessions for WordPress
* Version: 1.3.6
* Version: 1.4.3
* Description: Offload PHP's native sessions to your database for multi-server compatibility.
* Author: Pantheon
* Author URI: https://www.pantheon.io/
@@ -13,12 +13,15 @@
use Pantheon_Sessions\Session;
define( 'PANTHEON_SESSIONS_VERSION', '1.3.6' );
define( 'PANTHEON_SESSIONS_VERSION', '1.4.3' );
/**
* Main controller class for the plugin.
*/
class Pantheon_Sessions {
private const BAK_PANTHEON_SESSIONS_TABLE = 'bak_pantheon_sessions';
private const TEMP_PANTHEON_SESSIONS_TABLE = 'temp_pantheon_sessions';
private const PANTHEON_SESSIONS_TABLE = 'pantheon_sessions';
/**
* Copy of the singleton instance.
@@ -49,7 +52,7 @@ class Pantheon_Sessions {
}
/**
* Load the plugin
* Load the plugin.
*/
private function load() {
@@ -72,6 +75,24 @@ class Pantheon_Sessions {
add_action( 'set_logged_in_cookie', [ __CLASS__, 'action_set_logged_in_cookie' ], 10, 4 );
add_action( 'clear_auth_cookie', [ __CLASS__, 'action_clear_auth_cookie' ] );
}
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
add_action( 'wp_ajax_dismiss_notice', [ $this, 'dismiss_notice' ] );
}
/**
* Enqueue scripts
*/
public function enqueue_scripts() {
wp_enqueue_script( 'notices', plugins_url( '/assets/js/notices.js', __FILE__ ), [ 'jquery' ], PANTHEON_SESSIONS_VERSION, true );
}
/**
* Dismiss the notice when the button is clicked.
*/
public function dismiss_notice() {
$user_id = get_current_user_id();
update_user_meta( $user_id, 'notice_dismissed', true );
}
/**
@@ -178,8 +199,8 @@ class Pantheon_Sessions {
sprintf(
/* translators: %1s: File path, %2d: Line number */
__( "Oops! The wp-native-php-sessions plugin couldn't start the session because output has already been sent. This might be caused by PHP throwing errors. Please check the code in %1s on line %2d.", 'wp-native-php-sessions' ),
$file,
$line
esc_html( $file ),
esc_html( $line )
),
E_USER_WARNING
);
@@ -199,7 +220,7 @@ class Pantheon_Sessions {
$table_name = "{$table_prefix}pantheon_sessions";
$wpdb->pantheon_sessions = $table_name;
$wpdb->tables[] = 'pantheon_sessions';
$wpdb->tables[] = self::PANTHEON_SESSIONS_TABLE;
if ( get_option( 'pantheon_session_version' ) ) {
return;
@@ -261,6 +282,454 @@ class Pantheon_Sessions {
}
}
}
/**
* Checks whether primary keys were set and notifies users if not.
*/
public static function check_native_primary_keys() {
global $wpdb;
$table_name = $wpdb->get_blog_prefix() . self::PANTHEON_SESSIONS_TABLE;
$old_table = $wpdb->get_blog_prefix() . self::BAK_PANTHEON_SESSIONS_TABLE;
$query = "SHOW KEYS FROM {$table_name} WHERE key_name = 'PRIMARY';";
$is_pantheon = isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ? true : false;
$wp_cli_cmd = $is_pantheon ? 'terminus wp &lt;site&gt;.&lt;env&gt; -- ' : 'wp ';
$cli_add_index = $wp_cli_cmd . 'pantheon session add-index';
$key_existence = $wpdb->get_results( $query );
$user_id = get_current_user_id();
$dismissed = get_user_meta( $user_id, 'notice_dismissed', true );
if ( empty( $key_existence ) && ! $dismissed ) {
// If the key doesn't exist, recommend remediation.
?>
<div class="notice notice-error is-dismissible">
<p>
<?php
echo esc_html__( 'Your PHP Native Sessions table is missing a primary key. This can cause performance issues for high-traffic sites.', 'wp-native-php-sessions' );
?>
</p>
<p>
<?php
// TODO: Integrate the notice into the Health Check page. See https://getpantheon.atlassian.net/browse/CMSP-745.
// Translators: %s is the add-index command.
echo wp_kses_post( sprintf( __( 'If you\'d like to resolve this, please use this WP CLI command: %s and verify that the process completes successfully. Otherwise, you may dismiss this notice.', 'wp-native-php-sessions' ), "<code>$cli_add_index</code>" ) );
?>
</p>
</div>
<?php
}
$query = $wpdb->prepare( 'SHOW TABLES LIKE %s',
$wpdb->esc_like( $old_table ) );
// Check for table existence and delete if present.
if ( $wpdb->get_var( $query ) == $old_table ) {
$cli_key_finalize = $wp_cli_cmd . 'pantheon session primary-key-finalize';
$cli_key_revert = $wp_cli_cmd . 'pantheon session primary-key-revert';
// If an old table exists but has not been removed, suggest doing so.
?>
<div class="notice notice-error">
<p>
<?php
// Translators: 1: the primary-key-finalize command, 2: the primary-key-revert command.
echo wp_kses_post( sprintf( __( 'An old version of the PHP Native Sessions table is detected. When testing is complete, run %1$s to clean up old data, or run %2$s if there were issues.', 'wp-native-php-sessions' ), "<code>$cli_key_finalize</code>", "<code>$cli_key_revert</code>" ) );
?>
</p>
</div>
<?php
}
}
/**
* Set id as primary key in the Native PHP Sessions plugin table.
*
* @param int $start_position Site index to begin from.
*/
public function add_index( $start_position ) {
global $wpdb;
if ( ! is_multisite() ) {
$this->safe_output( __( 'Single site detected. Beginning processing... \n', 'wp-native-php-sessions' ), 'log' );
$this->add_single_index( $wpdb->prefix );
$this->safe_output( __( 'Operation complete, please verify that your site is working as expected. When ready, run wp pantheon session primary-key-finalize to clean up old data, or run wp pantheon session primary-key-revert if there were issues.', 'wp-native-php-sessions' ), 'log' );
return;
}
$this->safe_output( __( 'Multisite installation detected. Processing Sites individually...', 'wp-native-php-sessions' ), 'log' );
$output = [
'no_session_table' => 0,
'id_column_exists' => 0,
];
$site_list = $this->get_all_sites( $start_position );
$site_count = count( $site_list );
for ( $i = $start_position; $i < $site_count; $i++ ) {
// translators: %s is the current blog, and then the array index of the current site.
$this->safe_output( __( 'Processing site %d. In the event of a timeout or error, resume execution starting from this point via "wp pantheon session add-index --start_point=%d". To skip this site if it does not need processing, run "wp pantheon session add-index --start_point=%d".', 'wp-native-php-sessions' ), 'log', [ $site_list[ $i ], $i, $i + 1 ] );
$blog_prefix = $wpdb->get_blog_prefix( $site_list[ $i ] );
$output = $this->add_single_index( $blog_prefix, $output, true );
// translators: %s is the current site id.
$this->safe_output( __( 'Processing for site %d complete.', 'wp-native-php-sessions' ), 'log', [ $site_list[ $i ] ] );
}
if ( $output['no_session_table'] != 0 ) {
// translators: %d is the number of sites which did not have a session table.
$this->safe_output( __( '%d site(s) did not have a session table and were skipped. If this was unexpected, please review output.', 'wp-native-php-sessions' ), 'log', [ $output['no_session_table'] ] );
}
if ( $output['id_column_exists'] != 0 ) {
// translators: %d is the number of sites which had an ID column already.
$this->safe_output( __( '%d site(s) already had an ID column and were skipped. If this was unexpected, please review output.', 'wp-native-php-sessions' ), 'log', [ $output['id_column_exists'] ] );
}
$this->safe_output( __( 'Operation complete, please verify that your site is working as expected. When ready, run wp pantheon session primary-key-finalize to clean up old data, or run wp pantheon session primary-key-revert if there were issues.', 'wp-native-php-sessions' ), 'log' );
}
/**
* Retrieves all sites with query batches.
*
* @param int $start_position Starting position of query.
*
* @return array
*/
public function get_all_sites( $start_position ) {
$num_sites = 2;
$sites = ( $start_position == 0 ) ? [] : array_fill( 0, $start_position, null );
$page = 0;
while ( true ) {
$offset = ( $page * $num_sites ) + $start_position;
$next_page = get_sites( [
'number' => $num_sites,
'offset' => $offset,
'fields' => 'ids',
] );
if ( empty( $next_page ) || empty( array_diff( $next_page, $sites ) ) ) {
break;
}
$sites = array_merge( $sites, $next_page );
++$page;
}
if ( $start_position == 0 ) {
unset( $sites[ $start_position - 1 ] );
}
return $sites;
}
/**
* Finalizes the creation of a primary key by deleting the old data.
*
* @param int $start_position Site index to begin from.
*/
public function primary_key_finalize( $start_position ) {
global $wpdb;
if ( ! is_multisite() ) {
$this->safe_output( __( 'Single site detected. Beginning finalization.', 'wp-native-php-sessions' ), 'log' );
$this->primary_key_finalize_single( $wpdb->prefix );
$this->safe_output( __( 'Operation complete.', 'wp-native-php-sessions' ), 'log' );
return;
}
$this->safe_output( __( 'Multisite installation detected. Processing sites individually.', 'wp-native-php-sessions' ), 'log' );
$site_list = $this->get_all_sites( $start_position );
$output = [ 'no_old_table' => 0 ];
$site_count = count( $site_list );
for ( $i = $start_position; $i < $site_count; $i++ ) {
// translators: $s is the array index of the current site.
$this->safe_output( __( 'Finalizing site %d. In the event of a timeout or error, resume execution starting from this point via "wp pantheon session primary-key-finalize --start_point=%d". To skip this site if it does not need processing, run "wp pantheon session primary-key-finalize --start_point=%d".', 'wp-native-php-sessions' ), 'log', [ $site_list[ $i ], $i, $i + 1 ] );
$blog_prefix = $wpdb->get_blog_prefix( $site_list[ $i ] );
$output = $this->primary_key_finalize_single( $blog_prefix, $output, true );
// translators: %s is the current site id.
$this->safe_output( __( 'Finalization of site %d complete.', 'wp-native-php-sessions' ), 'log', [ $site_list[ $i ] ] );
}
if ( $output['no_old_table'] != 0 ) {
// translators: %d is the number of sites which did not have an old table.
$this->safe_output( __( '%d site(s) did not have an old table to delete and were skipped. If this is not expected, please review output.', 'wp-native-php-sessions' ), 'log', [ $output['no_old_table'] ] );
}
$this->safe_output( __( 'Finalization of all sites complete.', 'wp-native-php-sessions' ), 'log' );
}
/**
* Finalizes the creation of a primary key by deleting the old data.
*
* @param int $start_position Site index to begin from.
*/
public function primary_key_revert( $start_position ) {
global $wpdb;
if ( ! is_multisite() ) {
$this->safe_output( __( 'Single site detected. Beginning revert.', 'wp-native-php-sessions' ), 'log' );
$this->primary_key_revert_single( $wpdb->prefix );
$this->safe_output( __( 'Operation complete.', 'wp-native-php-sessions' ), 'log' );
return;
}
$this->safe_output( __( 'Multisite installation detected. Processing Sites individually.', 'wp-native-php-sessions' ), 'log' );
$site_list = $this->get_all_sites( $start_position );
$output = [ 'no_rollback_table' => 0 ];
$site_count = count( $site_list );
for ( $i = $start_position; $i < $site_count; $i++ ) {
// translators: $s is the array index of the current site.
$this->safe_output( __( 'Processing site %d. In the event of a timeout or error, resume execution starting from this point via "wp pantheon session primary-key-finalize --start_point=%d". To skip this site if it does not need processing, run "wp pantheon session primary-key-finalize --start_point=%d".', 'wp-native-php-sessions' ), 'log', [ $site_list[ $i ], $i, $i + 1 ] );
$blog_prefix = $wpdb->get_blog_prefix( $site_list[ $i ] );
$output = $this->primary_key_revert_single( $blog_prefix, $output, true );
// translators: %d is the current site id.
$this->safe_output( __( 'Revert of site %d complete.', 'wp-native-php-sessions' ), 'log', [ $site_list[ $i ] ] );
}
if ( $output['no_rollback_table'] != 0 ) {
// translators: %d is the number of sites which did not have a rollback table.
$this->safe_output( __( '%d site(s) did not have a table to roll back to and were skipped. If this is not expected, please review output.', 'wp-native-php-sessions' ), 'log', [ $output['no_rollback_table'] ] );
}
$this->safe_output( __( 'Revert operation complete.', 'wp-native-php-sessions' ), 'log' );
}
/**
* Perform add_index functionality for a single site.
*
* @param string $prefix Database prefix for the blog.
* @param array $output An array of logs/errors which may occur.
* @param bool $multisite Whether the site is a multisite.
*/
public function add_single_index( $prefix, $output = [], $multisite = false ) {
global $wpdb;
$unprefixed_table = self::PANTHEON_SESSIONS_TABLE;
$table = esc_sql( $prefix . $unprefixed_table );
$temp_clone_table = esc_sql( $prefix . 'sessions_temp_clone' );
// If the command has been run multiple times and there is already a
// temp_clone table, drop it.
$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $temp_clone_table ) );
if ( $wpdb->get_var( $query ) == $temp_clone_table ) {
$query = "DROP TABLE {$temp_clone_table};";
$wpdb->query( $query );
}
if ( ! PANTHEON_SESSIONS_ENABLED ) {
$this->safe_output( __( 'Pantheon Sessions is currently disabled.', 'wp-native-php-sessions' ), 'error' );
}
$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table ) );
if ( ! $wpdb->get_var( $query ) == $table ) {
$this->safe_output( __( 'This site does not have a pantheon_sessions table, and is being skipped.', 'wp-native-php-sessions' ), 'log' );
$output['no_session_table'] = isset( $output['no_session_table'] ) ? $output['no_session_table'] + 1 : 1;
return $output;
}
// Verify that the ID column/primary key does not already exist.
$query = "SHOW KEYS FROM {$table} WHERE key_name = 'PRIMARY';";
$key_existence = $wpdb->get_results( $query );
// Avoid errors by not attempting to add a column that already exists.
if ( ! empty( $key_existence ) ) {
// If dealing with multisites, it's feasible that some may have the
// column and some may not, so don't stop execution if all that's
// wrong is the key exists on one.
if ( ! $multisite ) {
$type = 'error';
} else {
$type = 'log';
}
$output['id_column_exists'] = isset( $output['id_column_exists'] ) ? $output['id_column_exists'] + 1 : 1;
$this->safe_output( __( 'ID column already exists and does not need to be added to the table.', 'wp-native-php-sessions' ), $type );
return $output;
}
// Alert the user that the action is going to go through.
$this->safe_output( __( 'Primary Key does not exist, resolution starting.', 'wp-native-php-sessions' ), 'log' );
$count_query = "SELECT COUNT(*) FROM {$table};";
$count_total = $wpdb->get_results( $count_query );
// Avoid errors when object returns an empty object.
if ( ! empty( $count_total ) ) {
$count_total = $count_total[0]->{'COUNT(*)'};
} else {
$count_total = 0;
}
if ( $count_total >= 20000 ) {
// translators: %s is the total number of rows that exist in the pantheon_sessions table.
$this->safe_output( __( 'A total of %s rows exist. To avoid service interruptions, this operation will be run in batches. Any sessions created between now and when operation completes may need to be recreated.', 'wp-native-php-sessions' ), 'log', [ $count_total ] );
}
// Create temporary table to copy data into in batches.
$query = "CREATE TABLE {$temp_clone_table} LIKE {$table};";
$wpdb->query( $query );
$query = "ALTER TABLE {$temp_clone_table} ADD COLUMN id BIGINT AUTO_INCREMENT PRIMARY KEY FIRST";
$wpdb->query( $query );
$batch_size = 20000;
$loops = ceil( $count_total / $batch_size );
for ( $i = 0; $i < $loops; $i++ ) {
$offset = $i * $batch_size;
$query = sprintf( "INSERT INTO {$temp_clone_table}
(user_id, session_id, secure_session_id, ip_address, datetime, data)
SELECT user_id,session_id,secure_session_id,ip_address,datetime,data
FROM %s ORDER BY user_id LIMIT %d OFFSET %d", $table, $batch_size, $offset );
$results = $wpdb->query( $query );
$current_results = $results + ( $batch_size * $i );
// translators: %1 and %2 are how many rows have been processed out of how many total.
$this->safe_output( __( 'Updated %1$s / %2$s rows. ', 'wp-native-php-sessions' ), 'log', [ $current_results, $count_total ] );
}
// Hot swap the old table and the new table, deleting a previous old
// table if necessary.
$old_table = esc_sql( $prefix . 'bak_' . $unprefixed_table );
$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $old_table ) );
if ( $wpdb->get_var( $query ) == $old_table ) {
$query = "DROP TABLE {$old_table};";
$wpdb->query( $query );
}
$query = "ALTER TABLE {$table} RENAME {$old_table};";
$wpdb->query( $query );
$query = "ALTER TABLE {$temp_clone_table} RENAME {$table};";
$wpdb->query( $query );
return $output;
}
/**
* Finalizes the creation of a primary key by deleting the old data.
*
* @param string $prefix Database prefix for the blog.
* @param array $output An array of logs/errors which may occur.
* @param bool $multisite Whether the site is a multisite.
*/
public function primary_key_finalize_single( $prefix = null, $output = [], $multisite = false ) {
global $wpdb;
$table = esc_sql( $prefix . self::BAK_PANTHEON_SESSIONS_TABLE );
$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table ) );
// Check for table existence and delete if present.
if ( ! $wpdb->get_var( $query ) == $table ) {
// If dealing with multisites, it's feasible that some may have a
// table and some may not, so don't stop execution if it's not found.
if ( ! $multisite ) {
$type = 'error';
} else {
$output['no_old_table'] = isset( $output['no_old_table'] ) ? $output['no_old_table'] + 1 : 1;
$type = 'log';
}
$this->safe_output( __( 'Old table does not exist to be removed.', 'wp-native-php-sessions' ), $type );
} else {
$query = "DROP TABLE {$table};";
$wpdb->query( $query );
if ( ! $multisite ) {
$this->safe_output( __( 'Old table has been successfully removed.', 'wp-native-php-sessions' ), 'log' );
} else {
$this->safe_output( __( 'Old table has been successfully removed for this site.', 'wp-native-php-sessions' ), 'log' );
}
}
return $output;
}
/**
* Reverts addition of primary key.
*
* @param string $prefix Database prefix for the blog.
* @param array $output An array of logs/errors which may occur.
* @param bool $multisite Whether the site is a multisite.
*/
public function primary_key_revert_single( $prefix = null, $output = [], $multisite = false ) {
global $wpdb;
$old_clone_table = esc_sql( $prefix . self::BAK_PANTHEON_SESSIONS_TABLE );
$temp_clone_table = esc_sql( $prefix . self::TEMP_PANTHEON_SESSIONS_TABLE );
$table = esc_sql( $prefix . self::PANTHEON_SESSIONS_TABLE );
// If there is no old table to roll back to, error.
$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $old_clone_table ) );
// If dealing with multisites, it's feasible that some may have a
// table and some may not, so don't stop execution if it's not found.
if ( ! $multisite ) {
$type = 'error';
} else {
$type = 'log';
}
if ( ! $wpdb->get_var( $query ) == $old_clone_table ) {
$this->safe_output( __( 'There is no old table to roll back to.', 'wp-native-php-sessions' ), $type );
$output['no_rollback_table'] = isset( $output['no_rollback_table'] ) ? $output['no_rollback_table'] + 1 : 1;
return $output;
}
// Swap old table and new one.
$query = "ALTER TABLE {$table} RENAME {$temp_clone_table};";
$wpdb->query( $query );
$query = "ALTER TABLE {$old_clone_table} RENAME {$table};";
$wpdb->query( $query );
$this->safe_output( __( 'Rolled back to previous state successfully, dropping corrupt table.', 'wp-native-php-sessions' ), 'log' );
// Remove table which did not function.
$query = "DROP TABLE {$temp_clone_table}";
$wpdb->query( $query );
$this->safe_output( __( 'Site processing complete.', 'wp-native-php-sessions' ), 'log' );
return $output;
}
/**
* Provide output to users, whether it's being run in WP_CLI or not.
*
* @param string $message Message to be printed.
* @param string $type If message is being printed through WP_CLI, what type of message.
* @param array $variables If sprintf is needed, an array of values.
*
* @return void
*/
protected function safe_output( $message, $type, array $variables = [] ) {
if ( defined( 'WP_CLI' ) && WP_CLI ) {
WP_CLI::$type( vsprintf( $message, $variables ) );
return;
}
print "\n" . wp_kses_post( vsprintf( $message, $variables ) );
// Calling WP_CLI::error triggers an exit, but we still need to exist even if we don't have WP_CLI available.
if ( $type === 'error' ) {
exit( 1 );
}
}
}
/**
@@ -273,5 +742,6 @@ function Pantheon_Sessions() {
}
add_action( 'activated_plugin', 'Pantheon_Sessions::force_first_load' );
add_action( 'admin_notices', 'Pantheon_Sessions::check_native_primary_keys' );
Pantheon_Sessions();

View File

@@ -1,9 +1,9 @@
=== WordPress Native PHP Sessions ===
Contributors: getpantheon, outlandish josh, mpvanwinkle77, danielbachhuber, andrew.taylor, jazzs3quence, stovak, jspellman
Contributors: getpantheon, outlandish josh, mpvanwinkle77, danielbachhuber, andrew.taylor, jazzs3quence, stovak, jspellman, rwagner00
Tags: comments, sessions
Requires at least: 4.7
Tested up to: 6.2.2
Stable tag: 1.3.6
Tested up to: 6.3
Stable tag: 1.4.3
Requires PHP: 5.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -41,6 +41,23 @@ To override this use the `pantheon_session_expiration` filter before the WordPre
}
add_filter( 'pantheon_session_expiration', 'my_session_expiration_override' );
== CLI Commands ==
**wp pantheon session add-index**
Added in 1.4.0. This command should be run if your installation of the plugin occurred before the addition of the primary ID key to the session table in version 1.2.2. You will be automatically notified when you visit any admin page if this is the case. If there's no message, your version is good to go. Note that this command is non-destructive, a new table will be created and the existing one preserved in a backup state until you have verified that the upgrade is functioning as expected.
**wp pantheon session primary-key-finalize**
Added in 1.4.0. If you have run the `add-index` command and have verified that the new table is functioning correctly, running the `primary-key-finalize` command will perform a database cleanup and remove the backup table.
**wp pantheon session primary-key-revert**
Added in 1.4.0. If you have run the `add-index` command and something unexpected has occurred, just run the `primary-key-revert` command and the backup table will immediately be returned to being the active table.
= WordPress Multisite =
As of 1.4.2 the `add-index`, `primary-key-add` and `primary-key-revert` commands are fully multisite compatible.
== Contributing ==
See [CONTRIBUTING.md](https://github.com/pantheon-systems/wp-native-php-sessions/blob/main/CONTRIBUTING.md) for information on contributing.
@@ -57,6 +74,10 @@ PHP's fallback default functionality is to allow sessions to be stored in a temp
However, if you intend to scale your application, local tempfiles are a dangerous choice. They are not shared between different instances of the application, producing erratic behavior that can be impossible to debug. By storing them in the database the state of the sessions is shared across all application instances.
= Where do I report security bugs found in this plugin? =
Please report security bugs found in the source code of the WP Native PHP Sessions plugin through the [Patchstack Vulnerability Disclosure Program](https://patchstack.com/database/vdp/wp-native-php-sessions). The Patchstack team will assist you with verification, CVE assignment, and notify the developers of this plugin.
== Troubleshooting ==
If you see an error like "Fatal error: session_start(): Failed to initialize storage module:" or "Warning: ini_set(): A session is active.", then you likely have a plugin that is starting a session before WP Native PHP Sessions is loading.
@@ -68,8 +89,32 @@ To fix, create a new file at `wp-content/mu-plugins/000-loader.php` and include
This mu-plugin will load WP Native PHP Sessions before all other plugins, while letting you still use the WordPress plugin updater to keep the plugin up-to-date.
== Upgrade Notice ==
= 1.4.0 (October 17, 2023) =
Adds a WP-CLI command to add an index to the sessions table if one does not exist already. If you installed this plugin before version 1.2.2, you likely need to run this command. However, regardless of version at installation a notice will appear in your admin dashboard if your database table is missing the index. If no notice appears, no action is necessary.
== Changelog ==
= 1.4.3 (November 13, 2023) =
* Fixed a PHP warning when running the `pantheon session add-index` command on a single site installation. [[#285](https://github.com/pantheon-systems/wp-native-php-sessions/pull/285)]
= 1.4.2 (November 8, 2023) =
* Fixed an issue with the `pantheon session add-index` PHP warning. [[#276](https://github.com/pantheon-systems/wp-native-php-sessions/pull/276/files)]
* Fixed a syntax issue with the suggested WP CLI commands [[#278](https://github.com/pantheon-systems/wp-native-php-sessions/pull/278)]
* Made `wp pantheon session add-index`, `wp pantheon session primary-key-finalize`, and `wp pantheon session primary-key-revert` fully multisite compatible. [[#275](https://github.com/pantheon-systems/wp-native-php-sessions/pull/275)]
= 1.4.1 (October 23, 2023) =
* Fixed an issue with the `pantheon session add-index` command not working properly on WP multisite [[#270](https://github.com/pantheon-systems/wp-native-php-sessions/pull/270)]
* Made the notice added in 1.4.0 dismissable (stores in user meta) & hides for multisite (an update is coming to iterate through all sites on a network) [[#271](https://github.com/pantheon-systems/wp-native-php-sessions/pull/271)]
= 1.4.0 (October 17, 2023) =
* Adds new CLI command to add a Primary Column (id) to the `pantheon_sessions` table for users who do not have one. [[#265](https://github.com/pantheon-systems/wp-native-php-sessions/pull/265)]
* Adds alert to dashboard for users who need to run the command.
* 8.3 compatibility and code quality updates
* Updates Pantheon WP Coding Standards to 2.0 [[#264](https://github.com/pantheon-systems/wp-native-php-sessions/pull/264)]
= 1.3.6 (June 1, 2023) =
* Fixes PHP 8.2 deprecated dynamic property error [[#251](https://github.com/pantheon-systems/wp-native-php-sessions/pull/251)] (props @miguelaxcar)
* Update CONTRIBUTING.md [[#252](https://github.com/pantheon-systems/wp-native-php-sessions/pull/252)].