diff --git a/pantheon-sessions.php b/pantheon-sessions.php index 172b517..9cab43d 100644 --- a/pantheon-sessions.php +++ b/pantheon-sessions.php @@ -376,7 +376,13 @@ public function add_index() { $count_query = "SELECT COUNT(*) FROM {$table};"; $count_total = $wpdb->get_results( $count_query ); - $count_total = $count_total[0]->{'COUNT(*)'}; + + // 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. diff --git a/readme.txt b/readme.txt index 7125d68..34bb235 100644 --- a/readme.txt +++ b/readme.txt @@ -105,6 +105,7 @@ Adds a WP-CLI command to add an index to the sessions table if one does not exis == Changelog == = 1.4.2-dev = +* Fixed an issue with the `pantheon session add-index` PHP warning. = 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)]