* Remove welcome note
* Remove store notice setting note
* Remove review your experience note
* Add tests for delete_notes_with_name
* Add filter support so that other code can add notes to be deleted on upgrade.
This commit is contained in:
Matt Sherman 2020-05-05 15:38:16 -04:00 committed by GitHub
parent 3fc69b9739
commit f639d4a32e
9 changed files with 162 additions and 201 deletions

View File

@ -10,7 +10,6 @@ namespace Automattic\WooCommerce\Admin;
defined( 'ABSPATH' ) || exit;
use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Giving_Feedback_Notes;
use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Mobile_App;
use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_New_Sales_Record;
use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Tracking_Opt_In;
@ -64,7 +63,6 @@ class Events {
*/
public function do_wc_admin_daily() {
WC_Admin_Notes_New_Sales_Record::possibly_add_sales_record_note();
WC_Admin_Notes_Giving_Feedback_Notes::add_notes_for_admin_giving_feedback();
WC_Admin_Notes_Mobile_App::possibly_add_mobile_app_note();
WC_Admin_Notes_Tracking_Opt_In::possibly_add_tracking_opt_in_note();
WC_Admin_Notes_Onboarding_Email_Marketing::possibly_add_onboarding_email_marketing_note();

View File

@ -12,7 +12,6 @@ defined( 'ABSPATH' ) || exit;
use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes;
use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Historical_Data;
use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Order_Milestones;
use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Welcome_Message;
use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Woo_Subscriptions_Notes;
use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Tracking_Opt_In;
use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_WooCommerce_Payments;
@ -184,7 +183,6 @@ class FeaturePlugin {
new WC_Admin_Notes_Woo_Subscriptions_Notes();
new WC_Admin_Notes_Historical_Data();
new WC_Admin_Notes_Order_Milestones();
new WC_Admin_Notes_Welcome_Message();
new WC_Admin_Notes_Tracking_Opt_In();
new WC_Admin_Notes_WooCommerce_Payments();
new WC_Admin_Notes_Install_JP_And_WCS_Plugins();

View File

@ -9,7 +9,6 @@
namespace Automattic\WooCommerce\Admin\Features;
use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes;
use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Settings_Notes;
/**
* Contains backend logic for the activity panel feature.
@ -46,7 +45,6 @@ class ActivityPanels {
add_filter( 'woocommerce_components_settings', array( $this, 'component_settings' ), 20 );
// New settings injection.
add_filter( 'woocommerce_shared_settings', array( $this, 'component_settings' ), 20 );
add_action( 'woocommerce_admin_updated', array( $this, 'woocommerce_updated_note' ) );
add_action( 'woocommerce_update_product', array( __CLASS__, 'clear_low_out_of_stock_count_transient' ) );
}
@ -117,11 +115,4 @@ class ActivityPanels {
$settings['hasLowStock'] = $this->has_low_stock_products();
return $settings;
}
/**
* Things to do after WooCommerce updates.
*/
public function woocommerce_updated_note() {
WC_Admin_Notes_Settings_Notes::add_notes_for_settings_that_have_moved();
}
}

View File

@ -10,8 +10,8 @@ namespace Automattic\WooCommerce\Admin;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Admin\API\Reports\Cache;
use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes;
use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Historical_Data;
use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Welcome_Message;
/**
* Install Class.
@ -40,7 +40,7 @@ class Install {
'wc_admin_update_0251_remove_unsnooze_action',
'wc_admin_update_0251_db_version',
),
'1.1.0' => array(
'1.1.0' => array(
'wc_admin_update_110_remove_facebook_note',
),
);
@ -158,6 +158,7 @@ class Install {
self::create_tables();
self::create_events();
self::delete_obsolete_notes();
self::create_notes();
self::maybe_update_db_version();
@ -448,16 +449,40 @@ class Install {
if ( ! wp_next_scheduled( 'wc_admin_daily' ) ) {
wp_schedule_event( time(), 'daily', 'wc_admin_daily' );
}
// @todo This is potentially redundant when the core package exists.
// Note: this is potentially redundant when the core package exists.
wp_schedule_single_event( time() + 10, 'generate_category_lookup_table' );
}
/**
* Delete obsolete notes.
*/
protected static function delete_obsolete_notes() {
$obsolete_notes_names = array(
'wc-admin-welcome-note',
'wc-admin-store-notice-setting-moved',
'wc-admin-store-notice-giving-feedback',
);
$additional_obsolete_notes_names = apply_filters(
'woocommerce_admin_obsolete_notes_names',
array()
);
if ( is_array( $additional_obsolete_notes_names ) ) {
$obsolete_notes_names = array_merge(
$obsolete_notes_names,
$additional_obsolete_notes_names
);
}
WC_Admin_Notes::delete_notes_with_name( $obsolete_notes_names );
}
/**
* Create notes.
*/
protected static function create_notes() {
WC_Admin_Notes_Historical_Data::add_note();
WC_Admin_Notes_Welcome_Message::add_welcome_note();
}
/**
@ -471,7 +496,9 @@ class Install {
$tables = self::get_tables();
foreach ( $tables as $table ) {
$wpdb->query( "DROP TABLE IF EXISTS {$table}" ); // WPCS: unprepared SQL ok.
/* phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared */
$wpdb->query( "DROP TABLE IF EXISTS {$table}" );
/* phpcs:enable */
}
}
}

View File

@ -89,14 +89,23 @@ class WC_Admin_Notes {
/**
* Deletes admin notes with a given name.
*
* @param string $name Name to search for.
* @param string|array $names Name(s) to search for.
*/
public static function delete_notes_with_name( $name ) {
public static function delete_notes_with_name( $names ) {
if ( is_string( $names ) ) {
$names = array( $names );
} elseif ( ! is_array( $names ) ) {
return;
}
$data_store = \WC_Data_Store::load( 'admin-note' );
$note_ids = $data_store->get_notes_with_name( $name );
foreach ( (array) $note_ids as $note_id ) {
$note = new WC_Admin_Note( $note_id );
$note->delete();
foreach ( $names as $name ) {
$note_ids = $data_store->get_notes_with_name( $name );
foreach ( (array) $note_ids as $note_id ) {
$note = new WC_Admin_Note( $note_id );
$note->delete();
}
}
}

View File

@ -1,66 +0,0 @@
<?php
/**
* WooCommerce Admin (Dashboard) Giving feedback notes provider.
*
* Adds notes to the merchant's inbox about giving feedback.
*
* @package WooCommerce Admin
*/
namespace Automattic\WooCommerce\Admin\Notes;
defined( 'ABSPATH' ) || exit;
/**
* WC_Admin_Notes_Giving_Feedback_Notes
*/
class WC_Admin_Notes_Giving_Feedback_Notes {
/**
* Note traits.
*/
use NoteTraits;
/**
* Add notes for admin giving feedback.
*/
public static function add_notes_for_admin_giving_feedback() {
self::possibly_add_admin_giving_feedback_note();
}
/**
* Possibly add a notice setting moved note.
*/
protected static function possibly_add_admin_giving_feedback_note() {
$name = 'wc-admin-store-notice-giving-feedback';
$data_store = \WC_Data_Store::load( 'admin-note' );
// We already have this note? Then exit, we're done.
$note_ids = $data_store->get_notes_with_name( $name );
if ( ! empty( $note_ids ) ) {
return;
}
// We need to show Admin Giving feeback notification after 3 days of install.
$three_days_in_seconds = 3 * DAY_IN_SECONDS;
if ( ! self::wc_admin_active_for( $three_days_in_seconds ) ) {
return;
}
// Otherwise, create our new note.
$note = new WC_Admin_Note();
$note->set_title( __( 'Review your experience', 'woocommerce-admin' ) );
$note->set_content( __( 'If you like WooCommerce Admin please leave us a 5 star rating. A huge thanks in advance!', 'woocommerce-admin' ) );
$note->set_content_data( (object) array() );
$note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
$note->set_icon( 'info' );
$note->set_name( $name );
$note->set_source( 'woocommerce-admin' );
$note->add_action(
'share-feedback',
__( 'Review', 'woocommerce-admin' ),
'https://wordpress.org/support/plugin/woocommerce-admin/reviews/?rate=5#new-post'
);
$note->save();
}
}

View File

@ -1,55 +0,0 @@
<?php
/**
* WooCommerce Admin (Dashboard) Settings Moved Note Provider.
*
* Adds notes to the merchant's inbox concerning settings that have moved.
*
* @package WooCommerce Admin
*/
namespace Automattic\WooCommerce\Admin\Notes;
defined( 'ABSPATH' ) || exit;
/**
* WC_Admin_Notes_Settings_Notes
*/
class WC_Admin_Notes_Settings_Notes {
/**
* Add notes for each setting that has moved.
*/
public static function add_notes_for_settings_that_have_moved() {
self::possibly_add_notice_setting_moved_note();
}
/**
* Possibly add a notice setting moved note.
*/
protected static function possibly_add_notice_setting_moved_note() {
$name = 'wc-admin-store-notice-setting-moved';
$data_store = \WC_Data_Store::load( 'admin-note' );
// We already have this note? Then exit, we're done.
$note_ids = $data_store->get_notes_with_name( $name );
if ( ! empty( $note_ids ) ) {
return;
}
// Otherwise, create our new note.
$note = new WC_Admin_Note();
$note->set_title( __( 'Looking for the Store Notice setting?', 'woocommerce-admin' ) );
$note->set_content( __( 'It can now be found in the Customizer.', 'woocommerce-admin' ) );
$note->set_content_data( (object) array() );
$note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
$note->set_icon( 'info' );
$note->set_name( $name );
$note->set_source( 'woocommerce-admin' );
$note->add_action(
'open-customizer',
__( 'Open Customizer', 'woocommerce-admin' ),
'customize.php'
);
$note->save();
}
}

View File

@ -1,55 +0,0 @@
<?php
/**
* WooCommerce Admin: Welcome to WooCommerce Admin Note
*
* Adds welcome notes to store alerts area.
*
* @package WooCommerce Admin
*/
namespace Automattic\WooCommerce\Admin\Notes;
defined( 'ABSPATH' ) || exit;
use \Automattic\WooCommerce\Admin\Install;
/**
* WC_Admin_Notes_Welcome_Message.
*/
class WC_Admin_Notes_Welcome_Message {
const NOTE_NAME = 'wc-admin-welcome-note';
/**
* Creates a note for welcome message.
*/
public static function add_welcome_note() {
// Check if plugin is upgrading if yes then don't create this note.
$is_upgrading = get_option( Install::VERSION_OPTION );
if ( $is_upgrading ) {
return;
}
// See if we've already created this kind of note so we don't do it again.
$data_store = \WC_Data_Store::load( 'admin-note' );
$note_ids = $data_store->get_notes_with_name( self::NOTE_NAME );
if ( ! empty( $note_ids ) ) {
return;
}
$note = new WC_Admin_Note();
$note->set_title( __( 'New feature(s)', 'woocommerce-admin' ) );
$note->set_content( __( 'Welcome to the new WooCommerce experience! In this new release you\'ll be able to have a glimpse of how your store is doing in the Dashboard, manage important aspects of your business (such as managing orders, stock, reviews) from anywhere in the interface, dive into your store data with a completely new Analytics section and more!', 'woocommerce-admin' ) );
$note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
$note->set_icon( 'info' );
$note->set_name( self::NOTE_NAME );
$note->set_content_data( (object) array() );
$note->set_source( 'woocommerce-admin' );
$note->add_action(
'learn-more',
__( 'Learn more', 'woocommerce-admin' ),
'https://woocommerce.wordpress.com/'
);
$note->save();
}
}

View File

@ -5,7 +5,8 @@
* @package WooCommerce\Tests\Notes
*/
use Automattic\WooCommerce\Admin\Notes\WC_Admin_Note;
use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes;
use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Note;
/**
* Class WC_Tests_Notes_Data_Store
@ -84,4 +85,117 @@ class WC_Tests_Notes_Data_Store extends WC_Unit_Test_Case {
$this->assertEquals( 'PHPUNIT_TEST_NOTE', $note->get_title() );
$this->assertEquals( 'PHPUNIT_TEST_NOTE_CONTENT', $note->get_content() );
}
/**
* Tests that the delete_notes_with_name method works when a single name is
* passed in.
*/
public function test_delete_notes_with_single_name() {
$note_name_to_delete = 'PHPUNIT_TEST_NOTE_TO_DELETE_' . gmdate( 'U' );
$note_name_to_keep = 'PHPUNIT_TEST_NOTE_TO_KEEP_' . gmdate( 'U' );
$note_names = array(
$note_name_to_delete,
$note_name_to_keep,
);
$data_store = WC_Data_Store::load( 'admin-note' );
// Create notes.
foreach ( $note_names as $note_name ) {
for ( $i = 0; $i < 3; $i++ ) {
$note = new WC_Admin_Note();
$note->set_name( $note_name );
$note->set_title( 'PHPUNIT_TEST_NOTE' );
$note->set_content( 'PHPUNIT_TEST_NOTE_CONTENT' );
$note->save();
}
}
// Make sure that we know that the notes were added properly.
$this->assertEquals(
3,
count( $data_store->get_notes_with_name( $note_name_to_delete ) )
);
$this->assertEquals(
3,
count( $data_store->get_notes_with_name( $note_name_to_keep ) )
);
// Delete the notes.
WC_Admin_Notes::delete_notes_with_name( $note_name_to_delete );
// Make sure the notes were deleted.
$this->assertEquals(
0,
count( $data_store->get_notes_with_name( $note_name_to_delete ) )
);
$this->assertEquals(
3,
count( $data_store->get_notes_with_name( $note_name_to_keep ) )
);
}
/**
* Tests that the delete_notes_with_name method works when multiple names
* are passed in.
*/
public function test_delete_notes_with_multiple_names() {
$note_name_to_delete_1 = 'PHPUNIT_TEST_NOTE_TO_DELETE_1_' . gmdate( 'U' );
$note_name_to_delete_2 = 'PHPUNIT_TEST_NOTE_TO_DELETE_2_' . gmdate( 'U' );
$note_name_to_keep = 'PHPUNIT_TEST_NOTE_TO_KEEP_' . gmdate( 'U' );
$note_names = array(
$note_name_to_delete_1,
$note_name_to_delete_2,
$note_name_to_keep,
);
$data_store = WC_Data_Store::load( 'admin-note' );
// Create notes.
foreach ( $note_names as $note_name ) {
for ( $i = 0; $i < 3; $i++ ) {
$note = new WC_Admin_Note();
$note->set_name( $note_name );
$note->set_title( 'PHPUNIT_TEST_NOTE' );
$note->set_content( 'PHPUNIT_TEST_NOTE_CONTENT' );
$note->save();
}
}
// Make sure that we know that the notes were added properly.
$this->assertEquals(
3,
count( $data_store->get_notes_with_name( $note_name_to_delete_1 ) )
);
$this->assertEquals(
3,
count( $data_store->get_notes_with_name( $note_name_to_delete_2 ) )
);
$this->assertEquals(
3,
count( $data_store->get_notes_with_name( $note_name_to_keep ) )
);
// Delete the notes.
WC_Admin_Notes::delete_notes_with_name(
array(
$note_name_to_delete_1,
$note_name_to_delete_2,
)
);
// Make sure the notes were deleted.
$this->assertEquals(
0,
count( $data_store->get_notes_with_name( $note_name_to_delete_1 ) )
);
$this->assertEquals(
0,
count( $data_store->get_notes_with_name( $note_name_to_delete_2 ) )
);
$this->assertEquals(
3,
count( $data_store->get_notes_with_name( $note_name_to_keep ) )
);
}
}