Merge pull request woocommerce/woocommerce-admin#649 from woocommerce/add/store-notice-setting-moved

Activity Panel: Inbox: When the user updates WooCommerce, add a note alerting that the store notice setting has moved
This commit is contained in:
Allen Snook 2018-10-25 10:06:30 -07:00 committed by GitHub
commit a8be179ebd
6 changed files with 91 additions and 4 deletions

View File

@ -111,6 +111,10 @@
& > * + * {
margin-left: 0.5em;
}
a.components-button.is-button {
color: $gray-text;
}
}
.woocommerce-activity-card.is-loading {

View File

@ -46,7 +46,7 @@ class InboxPanel extends Component {
return [];
}
return actions.map( action => (
<Button disabled isDefault href={ action.url }>
<Button isDefault href={ action.url }>
{ action.label }
</Button>
) );

View File

@ -152,6 +152,26 @@ class WC_Admin_REST_Admin_Notes_Controller extends WC_REST_CRUD_Controller {
return true;
}
/**
* Prepare a path or query for serialization to the client.
*
* @param string $query The query, path, or URL to transform.
* @return string A fully formed URL.
*/
public function prepare_query_for_response( $query ) {
if ( 'https://' === substr( $query, 0, 8 ) ) {
return $query;
}
if ( 'http://' === substr( $query, 0, 7 ) ) {
return $query;
}
if ( '?' === substr( $query, 0, 1 ) ) {
return admin_url( 'admin.php' . $query );
}
return admin_url( $query );
}
/**
* Prepare a note object for serialization.
*
@ -170,6 +190,7 @@ class WC_Admin_REST_Admin_Notes_Controller extends WC_REST_CRUD_Controller {
$data['content'] = stripslashes( $data['content'] );
foreach ( (array) $data['actions'] as $key => $value ) {
$data['actions'][ $key ]->label = stripslashes( $data['actions'][ $key ]->label );
$data['actions'][ $key ]->url = $this->prepare_query_for_response( $data['actions'][ $key ]->query );
}
$data = $this->filter_response_by_context( $data, $context );

View File

@ -13,6 +13,7 @@ defined( 'ABSPATH' ) || exit;
* WC_Admin_Notes_New_Sales_Record
*/
class WC_Admin_Notes_New_Sales_Record {
const NOTE_NAME = 'wc-admin-new-sales-record';
const RECORD_DATE_OPTION_KEY = 'woocommerce_sales_record_date'; // ISO 8601 (YYYY-MM-DD) date.
const RECORD_AMOUNT_OPTION_KEY = 'woocommerce_sales_record_amount';
@ -82,9 +83,8 @@ class WC_Admin_Notes_New_Sales_Record {
'new_record_amt' => $total,
);
$name = 'wc-admin-new-sales-record';
// We only want one sales record note at any time in the inbox, so we delete any other first.
WC_Admin_Notes::delete_notes_with_name( $name );
WC_Admin_Notes::delete_notes_with_name( self::NOTE_NAME );
// And now, create our new note.
$note = new WC_Admin_Note();
@ -93,7 +93,7 @@ class WC_Admin_Notes_New_Sales_Record {
$note->set_content_data( $content_data );
$note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
$note->set_icon( 'trophy' );
$note->set_name( $name );
$note->set_name( self::NOTE_NAME );
$note->set_source( 'wc-admin' );
$note->add_action( 'view-report', __( 'View report', 'wc-admin' ), '?page=wc-admin#/analytics' );
$note->save();

View File

@ -0,0 +1,53 @@
<?php
/**
* WooCommerce Admin (Dashboard) Settings Moved Note Provider.
*
* Adds notes to the merchant's inbox concerning settings that have moved.
*
* @package WooCommerce Admin
*/
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?', 'wc-admin' ) );
$note->set_content( __( 'It can now be found in the Customizer.', 'wc-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( 'wc-admin' );
$note->add_action(
'open-customizer',
__( 'Open Customizer', 'wc-admin' ),
'customize.php'
);
$note->save();
}
}

View File

@ -115,5 +115,14 @@ function wc_admin_plugins_loaded() {
// Admin note providers.
require_once dirname( __FILE__ ) . '/includes/class-wc-admin-notes-new-sales-record.php';
require_once dirname( __FILE__ ) . '/includes/class-wc-admin-notes-settings-notes.php';
}
add_action( 'plugins_loaded', 'wc_admin_plugins_loaded' );
/**
* Things to do after WooCommerce updates.
*/
function wc_admin_woocommerce_updated() {
WC_Admin_Notes_Settings_Notes::add_notes_for_settings_that_have_moved();
}
add_action( 'woocommerce_updated', 'wc_admin_woocommerce_updated' );