Changeset 2982749
- Timestamp:
- 10/23/2023 06:53:44 PM (2 years ago)
- Location:
- wp-native-php-sessions
- Files:
-
- 6 added
- 4 edited
- 1 copied
-
tags/1.4.1 (copied) (copied from wp-native-php-sessions/trunk)
-
tags/1.4.1/assets (added)
-
tags/1.4.1/assets/js (added)
-
tags/1.4.1/assets/js/notices.js (added)
-
tags/1.4.1/pantheon-sessions.php (modified) (10 diffs)
-
tags/1.4.1/readme.txt (modified) (3 diffs)
-
trunk/assets (added)
-
trunk/assets/js (added)
-
trunk/assets/js/notices.js (added)
-
trunk/pantheon-sessions.php (modified) (10 diffs)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-native-php-sessions/tags/1.4.1/pantheon-sessions.php
r2980355 r2982749 2 2 /** 3 3 * Plugin Name: Native PHP Sessions for WordPress 4 * Version: 1.4. 04 * Version: 1.4.1 5 5 * Description: Offload PHP's native sessions to your database for multi-server compatibility. 6 6 * Author: Pantheon … … 14 14 use Pantheon_Sessions\Session; 15 15 16 define( 'PANTHEON_SESSIONS_VERSION', '1.4. 0' );16 define( 'PANTHEON_SESSIONS_VERSION', '1.4.1' ); 17 17 18 18 /** … … 73 73 add_action( 'clear_auth_cookie', [ __CLASS__, 'action_clear_auth_cookie' ] ); 74 74 } 75 76 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); 77 add_action( 'wp_ajax_dismiss_notice', [ $this, 'dismiss_notice' ] ); 78 } 79 80 /** 81 * Enqueue scripts 82 */ 83 public function enqueue_scripts() { 84 wp_enqueue_script( 'notices', plugins_url( '/assets/js/notices.js', __FILE__ ), [ 'jquery' ], PANTHEON_SESSIONS_VERSION, true ); 85 } 86 87 /** 88 * Dismiss the notice when the button is clicked. 89 */ 90 public function dismiss_notice() { 91 $user_id = get_current_user_id(); 92 update_user_meta( $user_id, 'notice_dismissed', true ); 75 93 } 76 94 … … 268 286 public static function check_native_primary_keys() { 269 287 global $wpdb; 270 $table_name = $wpdb->base_prefix . 'pantheon_sessions'; 271 $old_table = $wpdb->base_prefix . 'bak_pantheon_sessions'; 272 $query = "SHOW KEYS FROM {$table_name} WHERE key_name = 'PRIMARY';"; 273 288 $table_name = $wpdb->prefix . 'pantheon_sessions'; 289 $old_table = $wpdb->prefix . 'bak_pantheon_sessions'; 290 $query = "SHOW KEYS FROM {$table_name} WHERE key_name = 'PRIMARY';"; 291 $is_pantheon = isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ? true : false; 292 $wp_cli_cmd = $is_pantheon ? 'terminus wp <site>.<env> --' : 'wp'; 293 $cli_add_index = $wp_cli_cmd . 'pantheon session add-index'; 274 294 $key_existence = $wpdb->get_results( $query ); 295 $user_id = get_current_user_id(); 296 $dismissed = get_user_meta( $user_id, 'notice_dismissed', true ); 275 297 276 298 if ( empty( $key_existence ) ) { 277 // If the key doesn't exist, recommend remediation. 278 ?> 279 <div class="notice notice-error is-dismissible"> 280 <p> 299 // TODO: Remove this conditional for multisite. See https://getpantheon.atlassian.net/browse/CMSP-744. 300 if ( is_multisite() || ! $dismissed ) { 301 // If the key doesn't exist, recommend remediation. 302 ?> 303 <div class="notice notice-error is-dismissible"> 304 <p> 305 <?php 306 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' ); 307 ?> 308 </p> 309 <p> 310 <?php 311 // TODO: Integrate the notice into the Health Check page. See https://getpantheon.atlassian.net/browse/CMSP-745. 312 // Translators: %s is the add-index command. 313 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>" ) ); 314 ?> 315 </p> 316 </div> 281 317 <?php 282 print wp_kses_post( __( 'Your PHP Native Sessions table is missing a primary key. Please run <code>wp pantheon session add-index</code> and verify that the process completes successfully and that this message goes away to resolve this issue on your live environment.', 'wp-native-php-sessions' ) ); 283 ?> 284 </p> 285 </div> 286 <?php 318 } 287 319 } 288 320 … … 292 324 // Check for table existence and delete if present. 293 325 if ( $wpdb->get_var( $query ) == $old_table ) { 326 $cli_key_finalize = $wp_cli_cmd . 'pantheon session primary-key-finalize'; 327 $cli_key_revert = $wp_cli_cmd . 'pantheon session primary-key-revert'; 328 294 329 // If an old table exists but has not been removed, suggest doing so. 295 330 ?> 296 331 <div class="notice notice-error"> 297 332 <p> 298 <?php 299 print wp_kses_post( __( 'An old version of the PHP Native Sessions table is detected. When testing is complete, run <code>wp pantheon session primary-key-finalize</code> to clean up old data, or run <code>wp pantheon session primary-key-revert</code> if there were issues.', 'wp-native-php-sessions' ) ); 300 ?> 301 </p> 333 <?php 334 // Translators: 1: the primary-key-finalize command, 2: the primary-key-revert command. 335 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>" ) ); 336 ?> 337 </p> 302 338 </div> 303 339 <?php … … 311 347 global $wpdb; 312 348 $unprefixed_table = 'pantheon_sessions'; 313 $table = $wpdb-> base_prefix . $unprefixed_table;314 $temp_clone_table = $wpdb-> base_prefix . 'sessions_temp_clone';349 $table = $wpdb->prefix . $unprefixed_table; 350 $temp_clone_table = $wpdb->prefix . 'sessions_temp_clone'; 315 351 316 352 // If the command has been run multiple times and there is already a … … 359 395 $offset = $i * $batch_size; 360 396 361 $query = sprintf( "INSERT INTO {$temp_clone_table} 362 (user_id, session_id, secure_session_id, ip_address, datetime, data) 363 SELECT user_id,session_id,secure_session_id,ip_address,datetime,data 397 $query = sprintf( "INSERT INTO {$temp_clone_table} 398 (user_id, session_id, secure_session_id, ip_address, datetime, data) 399 SELECT user_id,session_id,secure_session_id,ip_address,datetime,data 364 400 FROM %s ORDER BY user_id LIMIT %d OFFSET %d", $table, $batch_size, $offset ); 365 401 $results = $wpdb->query( $query ); … … 372 408 // Hot swap the old table and the new table, deleting a previous old 373 409 // table if necessary. 374 $old_table = $wpdb-> base_prefix . 'bak_' . $unprefixed_table;410 $old_table = $wpdb->prefix . 'bak_' . $unprefixed_table; 375 411 $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $old_table ) ); 376 412 … … 393 429 public function primary_key_finalize() { 394 430 global $wpdb; 395 $table = $wpdb-> base_prefix . 'bak_pantheon_sessions';431 $table = $wpdb->prefix . 'bak_pantheon_sessions'; 396 432 397 433 $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table ) ); … … 414 450 public function primary_key_revert() { 415 451 global $wpdb; 416 $old_clone_table = $wpdb-> base_prefix . 'bak_pantheon_sessions';417 $temp_clone_table = $wpdb-> base_prefix . 'temp_pantheon_sessions';418 $table = $wpdb-> base_prefix . 'pantheon_sessions';452 $old_clone_table = $wpdb->prefix . 'bak_pantheon_sessions'; 453 $temp_clone_table = $wpdb->prefix . 'temp_pantheon_sessions'; 454 $table = $wpdb->prefix . 'pantheon_sessions'; 419 455 420 456 // If there is no old table to roll back to, error. -
wp-native-php-sessions/tags/1.4.1/readme.txt
r2980355 r2982749 4 4 Requires at least: 4.7 5 5 Tested up to: 6.3 6 Stable tag: 1.4. 06 Stable tag: 1.4.1 7 7 Requires PHP: 5.4 8 8 License: GPLv2 or later … … 44 44 == CLI Commands == 45 45 46 = `wp pantheon session add-index` = 46 **wp pantheon session add-index** 47 47 48 48 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. 49 49 50 = `wp pantheon session primary-key-finalize` = 50 **wp pantheon session primary-key-finalize** 51 51 52 52 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. 53 53 54 = `wp pantheon session primary-key-revert` = 54 **wp pantheon session primary-key-revert** 55 55 56 56 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. 57 58 = WordPress Multisite = 59 As of 1.4.1 the `add-index`, `primary-key-add` and `primary-key-revert` commands only apply to a single site. This means that to run on a WordPress multisite, for sites beyond the main site, you would need to pass the `--url=` flag for each subsite. 60 61 However, you can script this process in bash by getting a list of sites and looping over them: 62 63 for site in $(wp site list --field=url); do 64 wp pantheon session add-index --url=$site 65 done 66 67 This can be applied to any of the other commands as needed to do them all in one go. We will be updating the command to iterate over all the sites in a multisite in a forthcoming release. 57 68 58 69 == Contributing == … … 94 105 == Changelog == 95 106 96 = 1.4.0 = 107 = 1.4.1 (October 23, 2023) = 108 * 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)] 109 * 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)] 110 111 112 = 1.4.0 (October 17, 2023) = 97 113 * 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)] 98 114 * Adds alert to dashboard for users who need to run the command. 99 115 * 8.3 compatibility and code quality updates 100 101 = 1.3.7-dev =102 116 * Updates Pantheon WP Coding Standards to 2.0 [[#264](https://github.com/pantheon-systems/wp-native-php-sessions/pull/264)] 103 117 -
wp-native-php-sessions/trunk/pantheon-sessions.php
r2980355 r2982749 2 2 /** 3 3 * Plugin Name: Native PHP Sessions for WordPress 4 * Version: 1.4. 04 * Version: 1.4.1 5 5 * Description: Offload PHP's native sessions to your database for multi-server compatibility. 6 6 * Author: Pantheon … … 14 14 use Pantheon_Sessions\Session; 15 15 16 define( 'PANTHEON_SESSIONS_VERSION', '1.4. 0' );16 define( 'PANTHEON_SESSIONS_VERSION', '1.4.1' ); 17 17 18 18 /** … … 73 73 add_action( 'clear_auth_cookie', [ __CLASS__, 'action_clear_auth_cookie' ] ); 74 74 } 75 76 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); 77 add_action( 'wp_ajax_dismiss_notice', [ $this, 'dismiss_notice' ] ); 78 } 79 80 /** 81 * Enqueue scripts 82 */ 83 public function enqueue_scripts() { 84 wp_enqueue_script( 'notices', plugins_url( '/assets/js/notices.js', __FILE__ ), [ 'jquery' ], PANTHEON_SESSIONS_VERSION, true ); 85 } 86 87 /** 88 * Dismiss the notice when the button is clicked. 89 */ 90 public function dismiss_notice() { 91 $user_id = get_current_user_id(); 92 update_user_meta( $user_id, 'notice_dismissed', true ); 75 93 } 76 94 … … 268 286 public static function check_native_primary_keys() { 269 287 global $wpdb; 270 $table_name = $wpdb->base_prefix . 'pantheon_sessions'; 271 $old_table = $wpdb->base_prefix . 'bak_pantheon_sessions'; 272 $query = "SHOW KEYS FROM {$table_name} WHERE key_name = 'PRIMARY';"; 273 288 $table_name = $wpdb->prefix . 'pantheon_sessions'; 289 $old_table = $wpdb->prefix . 'bak_pantheon_sessions'; 290 $query = "SHOW KEYS FROM {$table_name} WHERE key_name = 'PRIMARY';"; 291 $is_pantheon = isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ? true : false; 292 $wp_cli_cmd = $is_pantheon ? 'terminus wp <site>.<env> --' : 'wp'; 293 $cli_add_index = $wp_cli_cmd . 'pantheon session add-index'; 274 294 $key_existence = $wpdb->get_results( $query ); 295 $user_id = get_current_user_id(); 296 $dismissed = get_user_meta( $user_id, 'notice_dismissed', true ); 275 297 276 298 if ( empty( $key_existence ) ) { 277 // If the key doesn't exist, recommend remediation. 278 ?> 279 <div class="notice notice-error is-dismissible"> 280 <p> 299 // TODO: Remove this conditional for multisite. See https://getpantheon.atlassian.net/browse/CMSP-744. 300 if ( is_multisite() || ! $dismissed ) { 301 // If the key doesn't exist, recommend remediation. 302 ?> 303 <div class="notice notice-error is-dismissible"> 304 <p> 305 <?php 306 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' ); 307 ?> 308 </p> 309 <p> 310 <?php 311 // TODO: Integrate the notice into the Health Check page. See https://getpantheon.atlassian.net/browse/CMSP-745. 312 // Translators: %s is the add-index command. 313 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>" ) ); 314 ?> 315 </p> 316 </div> 281 317 <?php 282 print wp_kses_post( __( 'Your PHP Native Sessions table is missing a primary key. Please run <code>wp pantheon session add-index</code> and verify that the process completes successfully and that this message goes away to resolve this issue on your live environment.', 'wp-native-php-sessions' ) ); 283 ?> 284 </p> 285 </div> 286 <?php 318 } 287 319 } 288 320 … … 292 324 // Check for table existence and delete if present. 293 325 if ( $wpdb->get_var( $query ) == $old_table ) { 326 $cli_key_finalize = $wp_cli_cmd . 'pantheon session primary-key-finalize'; 327 $cli_key_revert = $wp_cli_cmd . 'pantheon session primary-key-revert'; 328 294 329 // If an old table exists but has not been removed, suggest doing so. 295 330 ?> 296 331 <div class="notice notice-error"> 297 332 <p> 298 <?php 299 print wp_kses_post( __( 'An old version of the PHP Native Sessions table is detected. When testing is complete, run <code>wp pantheon session primary-key-finalize</code> to clean up old data, or run <code>wp pantheon session primary-key-revert</code> if there were issues.', 'wp-native-php-sessions' ) ); 300 ?> 301 </p> 333 <?php 334 // Translators: 1: the primary-key-finalize command, 2: the primary-key-revert command. 335 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>" ) ); 336 ?> 337 </p> 302 338 </div> 303 339 <?php … … 311 347 global $wpdb; 312 348 $unprefixed_table = 'pantheon_sessions'; 313 $table = $wpdb-> base_prefix . $unprefixed_table;314 $temp_clone_table = $wpdb-> base_prefix . 'sessions_temp_clone';349 $table = $wpdb->prefix . $unprefixed_table; 350 $temp_clone_table = $wpdb->prefix . 'sessions_temp_clone'; 315 351 316 352 // If the command has been run multiple times and there is already a … … 359 395 $offset = $i * $batch_size; 360 396 361 $query = sprintf( "INSERT INTO {$temp_clone_table} 362 (user_id, session_id, secure_session_id, ip_address, datetime, data) 363 SELECT user_id,session_id,secure_session_id,ip_address,datetime,data 397 $query = sprintf( "INSERT INTO {$temp_clone_table} 398 (user_id, session_id, secure_session_id, ip_address, datetime, data) 399 SELECT user_id,session_id,secure_session_id,ip_address,datetime,data 364 400 FROM %s ORDER BY user_id LIMIT %d OFFSET %d", $table, $batch_size, $offset ); 365 401 $results = $wpdb->query( $query ); … … 372 408 // Hot swap the old table and the new table, deleting a previous old 373 409 // table if necessary. 374 $old_table = $wpdb-> base_prefix . 'bak_' . $unprefixed_table;410 $old_table = $wpdb->prefix . 'bak_' . $unprefixed_table; 375 411 $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $old_table ) ); 376 412 … … 393 429 public function primary_key_finalize() { 394 430 global $wpdb; 395 $table = $wpdb-> base_prefix . 'bak_pantheon_sessions';431 $table = $wpdb->prefix . 'bak_pantheon_sessions'; 396 432 397 433 $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table ) ); … … 414 450 public function primary_key_revert() { 415 451 global $wpdb; 416 $old_clone_table = $wpdb-> base_prefix . 'bak_pantheon_sessions';417 $temp_clone_table = $wpdb-> base_prefix . 'temp_pantheon_sessions';418 $table = $wpdb-> base_prefix . 'pantheon_sessions';452 $old_clone_table = $wpdb->prefix . 'bak_pantheon_sessions'; 453 $temp_clone_table = $wpdb->prefix . 'temp_pantheon_sessions'; 454 $table = $wpdb->prefix . 'pantheon_sessions'; 419 455 420 456 // If there is no old table to roll back to, error. -
wp-native-php-sessions/trunk/readme.txt
r2980355 r2982749 4 4 Requires at least: 4.7 5 5 Tested up to: 6.3 6 Stable tag: 1.4. 06 Stable tag: 1.4.1 7 7 Requires PHP: 5.4 8 8 License: GPLv2 or later … … 44 44 == CLI Commands == 45 45 46 = `wp pantheon session add-index` = 46 **wp pantheon session add-index** 47 47 48 48 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. 49 49 50 = `wp pantheon session primary-key-finalize` = 50 **wp pantheon session primary-key-finalize** 51 51 52 52 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. 53 53 54 = `wp pantheon session primary-key-revert` = 54 **wp pantheon session primary-key-revert** 55 55 56 56 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. 57 58 = WordPress Multisite = 59 As of 1.4.1 the `add-index`, `primary-key-add` and `primary-key-revert` commands only apply to a single site. This means that to run on a WordPress multisite, for sites beyond the main site, you would need to pass the `--url=` flag for each subsite. 60 61 However, you can script this process in bash by getting a list of sites and looping over them: 62 63 for site in $(wp site list --field=url); do 64 wp pantheon session add-index --url=$site 65 done 66 67 This can be applied to any of the other commands as needed to do them all in one go. We will be updating the command to iterate over all the sites in a multisite in a forthcoming release. 57 68 58 69 == Contributing == … … 94 105 == Changelog == 95 106 96 = 1.4.0 = 107 = 1.4.1 (October 23, 2023) = 108 * 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)] 109 * 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)] 110 111 112 = 1.4.0 (October 17, 2023) = 97 113 * 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)] 98 114 * Adds alert to dashboard for users who need to run the command. 99 115 * 8.3 compatibility and code quality updates 100 101 = 1.3.7-dev =102 116 * Updates Pantheon WP Coding Standards to 2.0 [[#264](https://github.com/pantheon-systems/wp-native-php-sessions/pull/264)] 103 117
Note: See TracChangeset
for help on using the changeset viewer.