Fix unsnooze notes not working (#51254)
* Fix saving note timestamp * Fix missing wc_admin_unsnooze_admin_notes action * Add changelog * Update tests
This commit is contained in:
parent
c96f9f38bd
commit
56c04f2bfb
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Fix wc_admin_unsnooze_admin_notes events are being needlessly created
|
|
@ -534,7 +534,7 @@ class Note extends \WC_Data {
|
|||
$this->error( 'admin_note_invalid_data', __( 'The admin note date prop cannot be empty.', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
if ( is_string( $date ) ) {
|
||||
if ( is_string( $date ) && ! is_numeric( $date ) ) {
|
||||
$date = wc_string_to_timestamp( $date );
|
||||
}
|
||||
$this->set_date_prop( 'date_created', $date );
|
||||
|
@ -546,7 +546,7 @@ class Note extends \WC_Data {
|
|||
* @param string|integer|null $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if there is no date.
|
||||
*/
|
||||
public function set_date_reminder( $date ) {
|
||||
if ( is_string( $date ) ) {
|
||||
if ( is_string( $date ) && ! is_numeric( $date ) ) {
|
||||
$date = wc_string_to_timestamp( $date );
|
||||
}
|
||||
$this->set_date_prop( 'date_reminder', $date );
|
||||
|
|
|
@ -24,6 +24,7 @@ class Notes {
|
|||
add_action( 'admin_init', array( __CLASS__, 'schedule_unsnooze_notes' ) );
|
||||
add_action( 'admin_init', array( __CLASS__, 'possibly_delete_survey_notes' ) );
|
||||
add_action( 'update_option_woocommerce_show_marketplace_suggestions', array( __CLASS__, 'possibly_delete_marketing_notes' ), 10, 2 );
|
||||
add_action( self::UNSNOOZE_HOOK, array( __CLASS__, 'unsnooze_notes' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -406,7 +407,6 @@ class Notes {
|
|||
wp_set_current_user( $user_id );
|
||||
self::record_tracks_event_without_cookies( $event_name, $params );
|
||||
wp_set_current_user( $current_user_id );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -53,4 +53,31 @@ class WC_Admin_Tests_Notes_Note extends WC_Unit_Test_Case {
|
|||
$this->assertEquals( $date_created_from_first_save, $date_created_from_second_save );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests setting date_reminder with various input types.
|
||||
*
|
||||
* @dataProvider date_reminder_provider
|
||||
* @param mixed $input Input date value.
|
||||
* @param int $expected_timestamp Expected timestamp.
|
||||
*/
|
||||
public function test_set_date_reminder_with_various_inputs( $input, $expected_timestamp ) {
|
||||
$note = new Note();
|
||||
$note->set_date_reminder( $input );
|
||||
$date_reminder = $note->get_date_reminder();
|
||||
$this->assertEquals( $expected_timestamp, $date_reminder );
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_set_date_reminder_with_various_inputs.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function date_reminder_provider() {
|
||||
return array(
|
||||
'timestamp' => array( 1609459200, '2021-01-01T00:00:00+00:00' ),
|
||||
'timestamp string' => array( '1609459200', '2021-01-01T00:00:00+00:00' ),
|
||||
'date string' => array( '2021-01-01', '2021-01-01T00:00:00+00:00' ),
|
||||
'WC_DateTime object' => array( new WC_DateTime( '2021-01-01' ), '2021-01-01T00:00:00+00:00' ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue