Reset "install_timestamp" if it's not numeric to avoid TypeError (https://github.com/woocommerce/woocommerce-admin/pull/8100)

* Reset install_timestamp if it's not numeric to avoid type error

Fix indent

* Add changelogs

* Remove ununnecessary logic
This commit is contained in:
Chi-Hsuan Huang 2022-01-03 15:51:51 +08:00 committed by GitHub
parent aa9f2df07f
commit 2f290d79a9
3 changed files with 14 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: Fix
Reset "install_timestamp" if it's not numeric to avoid TypeError. #8100

View File

@ -48,7 +48,7 @@ class WCAdminHelper {
public static function get_wcadmin_active_for_in_seconds() { public static function get_wcadmin_active_for_in_seconds() {
$install_timestamp = get_option( self::WC_ADMIN_TIMESTAMP_OPTION ); $install_timestamp = get_option( self::WC_ADMIN_TIMESTAMP_OPTION );
if ( false === $install_timestamp ) { if ( ! is_numeric( $install_timestamp ) ) {
$install_timestamp = time(); $install_timestamp = time();
update_option( self::WC_ADMIN_TIMESTAMP_OPTION, $install_timestamp ); update_option( self::WC_ADMIN_TIMESTAMP_OPTION, $install_timestamp );
} }

View File

@ -14,6 +14,15 @@ use \Automattic\WooCommerce\Admin\WCAdminHelper;
*/ */
class WC_Admin_Tests_Admin_Helper extends WP_UnitTestCase { class WC_Admin_Tests_Admin_Helper extends WP_UnitTestCase {
/**
* Test get_wcadmin_active_for_in_seconds_with with invalid timestamp option.
*/
public function test_get_wcadmin_active_for_in_seconds_with_invalid_timestamp_option() {
update_option( WCAdminHelper::WC_ADMIN_TIMESTAMP_OPTION, 'invalid-time' );
$this->assertEquals( is_numeric( WCAdminHelper::get_wcadmin_active_for_in_seconds() ), true );
}
/** /**
* Test wc_admin_active_for one hour * Test wc_admin_active_for one hour
*/ */