Plugin Directory

Changeset 2982749


Ignore:
Timestamp:
10/23/2023 06:53:44 PM (2 years ago)
Author:
getpantheon
Message:

Update to version 1.4.1 from GitHub

Location:
wp-native-php-sessions
Files:
6 added
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • wp-native-php-sessions/tags/1.4.1/pantheon-sessions.php

    r2980355 r2982749  
    22/**
    33 * Plugin Name: Native PHP Sessions for WordPress
    4  * Version: 1.4.0
     4 * Version: 1.4.1
    55 * Description: Offload PHP's native sessions to your database for multi-server compatibility.
    66 * Author: Pantheon
     
    1414use Pantheon_Sessions\Session;
    1515
    16 define( 'PANTHEON_SESSIONS_VERSION', '1.4.0' );
     16define( 'PANTHEON_SESSIONS_VERSION', '1.4.1' );
    1717
    1818/**
     
    7373            add_action( 'clear_auth_cookie', [ __CLASS__, 'action_clear_auth_cookie' ] );
    7474        }
     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 );
    7593    }
    7694
     
    268286    public static function check_native_primary_keys() {
    269287        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';
    274294        $key_existence = $wpdb->get_results( $query );
     295        $user_id = get_current_user_id();
     296        $dismissed = get_user_meta( $user_id, 'notice_dismissed', true );
    275297
    276298        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>
    281317                <?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            }
    287319        }
    288320
     
    292324        // Check for table existence and delete if present.
    293325        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
    294329            // If an old table exists but has not been removed, suggest doing so.
    295330            ?>
    296331            <div class="notice notice-error">
    297332                <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>
    302338            </div>
    303339            <?php
     
    311347        global $wpdb;
    312348        $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';
    315351
    316352        // If the command has been run multiple times and there is already a
     
    359395            $offset = $i * $batch_size;
    360396
    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)
     399SELECT user_id,session_id,secure_session_id,ip_address,datetime,data
    364400FROM %s ORDER BY user_id LIMIT %d OFFSET %d", $table, $batch_size, $offset );
    365401            $results         = $wpdb->query( $query );
     
    372408        // Hot swap the old table and the new table, deleting a previous old
    373409        // table if necessary.
    374         $old_table = $wpdb->base_prefix . 'bak_' . $unprefixed_table;
     410        $old_table = $wpdb->prefix . 'bak_' . $unprefixed_table;
    375411        $query     = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $old_table ) );
    376412
     
    393429    public function primary_key_finalize() {
    394430        global $wpdb;
    395         $table = $wpdb->base_prefix . 'bak_pantheon_sessions';
     431        $table = $wpdb->prefix . 'bak_pantheon_sessions';
    396432
    397433        $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table ) );
     
    414450    public function primary_key_revert() {
    415451        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';
    419455
    420456        // If there is no old table to roll back to, error.
  • wp-native-php-sessions/tags/1.4.1/readme.txt

    r2980355 r2982749  
    44Requires at least: 4.7
    55Tested up to: 6.3
    6 Stable tag: 1.4.0
     6Stable tag: 1.4.1
    77Requires PHP: 5.4
    88License: GPLv2 or later
     
    4444== CLI Commands ==
    4545
    46 = `wp pantheon session add-index` =
     46**wp pantheon session add-index**
    4747
    4848Added 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.
    4949
    50 = `wp pantheon session primary-key-finalize` =
     50**wp pantheon session primary-key-finalize**
    5151
    5252Added 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.
    5353
    54 = `wp pantheon session primary-key-revert` =
     54**wp pantheon session primary-key-revert**
    5555
    5656Added 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 =
     59As 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
     61However, 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
     67This 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.
    5768
    5869== Contributing ==
     
    94105== Changelog ==
    95106
    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) =
    97113* 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)]
    98114* Adds alert to dashboard for users who need to run the command.
    99115* 8.3 compatibility and code quality updates
    100 
    101 = 1.3.7-dev =
    102116* Updates Pantheon WP Coding Standards to 2.0 [[#264](https://github.com/pantheon-systems/wp-native-php-sessions/pull/264)]
    103117
  • wp-native-php-sessions/trunk/pantheon-sessions.php

    r2980355 r2982749  
    22/**
    33 * Plugin Name: Native PHP Sessions for WordPress
    4  * Version: 1.4.0
     4 * Version: 1.4.1
    55 * Description: Offload PHP's native sessions to your database for multi-server compatibility.
    66 * Author: Pantheon
     
    1414use Pantheon_Sessions\Session;
    1515
    16 define( 'PANTHEON_SESSIONS_VERSION', '1.4.0' );
     16define( 'PANTHEON_SESSIONS_VERSION', '1.4.1' );
    1717
    1818/**
     
    7373            add_action( 'clear_auth_cookie', [ __CLASS__, 'action_clear_auth_cookie' ] );
    7474        }
     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 );
    7593    }
    7694
     
    268286    public static function check_native_primary_keys() {
    269287        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 &lt;site&gt;.&lt;env&gt; --' : 'wp';
     293        $cli_add_index = $wp_cli_cmd . 'pantheon session add-index';
    274294        $key_existence = $wpdb->get_results( $query );
     295        $user_id = get_current_user_id();
     296        $dismissed = get_user_meta( $user_id, 'notice_dismissed', true );
    275297
    276298        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>
    281317                <?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            }
    287319        }
    288320
     
    292324        // Check for table existence and delete if present.
    293325        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
    294329            // If an old table exists but has not been removed, suggest doing so.
    295330            ?>
    296331            <div class="notice notice-error">
    297332                <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>
    302338            </div>
    303339            <?php
     
    311347        global $wpdb;
    312348        $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';
    315351
    316352        // If the command has been run multiple times and there is already a
     
    359395            $offset = $i * $batch_size;
    360396
    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)
     399SELECT user_id,session_id,secure_session_id,ip_address,datetime,data
    364400FROM %s ORDER BY user_id LIMIT %d OFFSET %d", $table, $batch_size, $offset );
    365401            $results         = $wpdb->query( $query );
     
    372408        // Hot swap the old table and the new table, deleting a previous old
    373409        // table if necessary.
    374         $old_table = $wpdb->base_prefix . 'bak_' . $unprefixed_table;
     410        $old_table = $wpdb->prefix . 'bak_' . $unprefixed_table;
    375411        $query     = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $old_table ) );
    376412
     
    393429    public function primary_key_finalize() {
    394430        global $wpdb;
    395         $table = $wpdb->base_prefix . 'bak_pantheon_sessions';
     431        $table = $wpdb->prefix . 'bak_pantheon_sessions';
    396432
    397433        $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table ) );
     
    414450    public function primary_key_revert() {
    415451        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';
    419455
    420456        // If there is no old table to roll back to, error.
  • wp-native-php-sessions/trunk/readme.txt

    r2980355 r2982749  
    44Requires at least: 4.7
    55Tested up to: 6.3
    6 Stable tag: 1.4.0
     6Stable tag: 1.4.1
    77Requires PHP: 5.4
    88License: GPLv2 or later
     
    4444== CLI Commands ==
    4545
    46 = `wp pantheon session add-index` =
     46**wp pantheon session add-index**
    4747
    4848Added 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.
    4949
    50 = `wp pantheon session primary-key-finalize` =
     50**wp pantheon session primary-key-finalize**
    5151
    5252Added 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.
    5353
    54 = `wp pantheon session primary-key-revert` =
     54**wp pantheon session primary-key-revert**
    5555
    5656Added 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 =
     59As 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
     61However, 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
     67This 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.
    5768
    5869== Contributing ==
     
    94105== Changelog ==
    95106
    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) =
    97113* 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)]
    98114* Adds alert to dashboard for users who need to run the command.
    99115* 8.3 compatibility and code quality updates
    100 
    101 = 1.3.7-dev =
    102116* Updates Pantheon WP Coding Standards to 2.0 [[#264](https://github.com/pantheon-systems/wp-native-php-sessions/pull/264)]
    103117
Note: See TracChangeset for help on using the changeset viewer.