-
Notifications
You must be signed in to change notification settings - Fork 212
Nag store admin to check store settings after upgrade #1273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?php | ||
| /** | ||
| * Control database upgrade to version 14 | ||
| * | ||
| * @access private | ||
| * @since 3.8.14.1 | ||
| * | ||
| */ | ||
| function _wpsc_db_upgrade_14() { | ||
| _wpsc_nag_user_to_verify_checkout_state_fields(); | ||
| } | ||
|
|
||
| /** | ||
| * add the county region label to the uk | ||
| * | ||
| * @access private | ||
| * @since 3.8.14.1 | ||
| */ | ||
| function _wpsc_nag_user_to_verify_checkout_state_fields() { | ||
| wpsc_admin_nag( | ||
| __( | ||
| 'WP-e-Commerce has been updated, please confirm the checkout field display | ||
| settings are correct for your store.<br><br><i>The visibility of the checkout billing and shipping | ||
| drop downs that show states and provinces is now controlled by the "billingstate" and "shippingstate" | ||
| options set in the <b>Store Settings</b> on the <b>Checkout</b> tab. Prior versions used | ||
| the "billingcountry" and "shippingcountry" settings to control the visibility of the drop downs.</i>', | ||
| 'wpsc' | ||
| ) | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Show WPeC admin notifications, a.k.a. Nags | ||
| * | ||
| * an admin notifications class is defined here in core includes so that notifications | ||
| * can be queued by logic running on the user facing side that will be visisble to | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/visisble/visible |
||
| * store administrators when they are on the admin pages | ||
| * | ||
| * @access public | ||
| * | ||
| * @since 3.8.14.1 | ||
| * | ||
| */ | ||
| class WPSC_Admin_Notifications { | ||
|
|
||
| static $instance = null; | ||
|
|
||
| function __construct() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're making this a singleton, let's follow the standard core convention we have of using a |
||
|
|
||
| if ( ! self::$instance ) { | ||
| self::$instance = $this; | ||
| if ( is_admin() ) { | ||
| add_action( 'admin_notices', array( $this, 'show_messages' ) ); | ||
| add_action( 'wp_ajax_wpsc_dismiss_admin_msg', array( $this, 'dismiss_msg' ) ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * add one or more new messages to be shown to the administrator | ||
| * @param string|array[string] $new_messages to show to the admin | ||
| */ | ||
| function new_message( $new_messages ) { | ||
|
|
||
| if ( empty ( $new_messages ) ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs proper brackets. |
||
| return; | ||
|
|
||
| if ( is_string( $new_messages ) ) { | ||
| $new_messages = array( $new_messages ); | ||
| } | ||
|
|
||
| $messages = get_option( __CLASS__ , array() ); | ||
| $save_admin_messages = false; | ||
|
|
||
| foreach ( $new_messages as $new_message ) { | ||
| // using the hash key is an easy way of preventing duplicate messages | ||
| $id = md5( $new_message ); | ||
|
|
||
| if ( ! isset($messages[$id] ) ) { | ||
| $messages[$id] = $new_message; | ||
| $save_admin_messages = true; | ||
| } | ||
| } | ||
|
|
||
| // only save the admin messages if they have been updated | ||
| if ( $save_admin_messages ) { | ||
| update_option( __CLASS__ , $messages ); | ||
| } | ||
|
|
||
| if ( did_action( 'admin_notices' ) ) { | ||
| $wpsc_admin_notifications = new WPSC_Admin_Notifications(); | ||
| $wpsc_admin_notifications->show_messages(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * display admin messages(nags) | ||
| * | ||
| * @since 3.8.14.1 | ||
| */ | ||
| function show_messages() { | ||
| $messages = get_option( __CLASS__ , array() ); | ||
|
|
||
| static $script_already_sent = false; | ||
| static $already_displayed = array(); | ||
|
|
||
| // first time though this function and we should add the admin nag script to the page | ||
| if ( ! $script_already_sent ) { | ||
| ?> | ||
| <script type="text/javascript"> | ||
| // WPeC Admin nag handler | ||
| jQuery(document).ready(function ($) { | ||
| function wpsc_dismiss_admin_msg(id) { | ||
| jQuery( "#wpsc-admin-message-"+id ).hide(); | ||
| jQuery.ajax({ | ||
| type : "post", | ||
| dataType : "text", | ||
| url : "<?php echo admin_url( 'admin-ajax.php' );?>", | ||
| data : {action: "wpsc_dismiss_admin_msg", id : id}, | ||
| success: function (response) { | ||
| }, | ||
| error: function (response) { | ||
| ; | ||
| }, | ||
| }); | ||
| } | ||
| jQuery(".wpsc-admin-message-dismiss").click(function(event) { | ||
| wpsc_dismiss_admin_msg(event.target.id); | ||
| return false; | ||
| }); | ||
| }); | ||
| </script> | ||
| <?php | ||
| $script_already_sent = true; | ||
| } | ||
|
|
||
| foreach ( $messages as $id => $message ) { | ||
| if ( in_array( $id, $already_displayed ) ) | ||
| continue; | ||
|
|
||
| $already_displayed[] = $id; | ||
|
|
||
|
|
||
| ?> | ||
| <div class="updated wpsc-admin-message" id="wpsc-admin-message-<?php echo esc_attr( $id );?>"> | ||
| <div class="message-text"> | ||
| <p> | ||
| <?php echo $message; ?> | ||
| </p> | ||
| </div> | ||
| <div class="wpsc-admin-message-action" style="width: 100%; text-align: right;"> | ||
| <a class="wpsc-admin-message-dismiss" id="<?php echo esc_attr( $id );?>"><?php _e( 'Dismiss', 'wpec' )?></a> | ||
| </div> | ||
| </div> | ||
| <?php | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Dismiss an admin message | ||
| * | ||
| * @param string $message_id the unqiue message id to be dismissed | ||
| */ | ||
| function dismiss_msg( $message_id = false ) { | ||
| if ( ! $message_id ) { | ||
| if ( isset( $_REQUEST['id'] ) ) { | ||
| $message_id = $_REQUEST['id']; | ||
| } | ||
| } | ||
|
|
||
| $messages = get_option( __CLASS__ , array() ); | ||
|
|
||
| if ( isset($messages[$message_id] ) ) { | ||
| unset( $messages[$message_id] ); | ||
| update_option( __CLASS__, $messages ); | ||
| } | ||
|
|
||
| wp_send_json_success( true ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why true is being set here? |
||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Show one or more admin notification(s) that must be acknowledged | ||
| * | ||
| * @param string|array[string] $messages admin the messages(nags) to show | ||
| */ | ||
| function wpsc_admin_nag( $messages ) { | ||
| static $wpsc_admin_notifications = null; | ||
|
|
||
| if ( empty( $wpsc_admin_notifications ) ) { | ||
| $wpsc_admin_notifications = new WPSC_Admin_Notifications(); | ||
| } | ||
|
|
||
| $wpsc_admin_notifications->new_message( $messages ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Properties should be nouns, methods should be verbs. I'd change |
||
| } | ||
|
|
||
|
|
||
|
|
||
| // If we are showing an admin page we want to show the admin nags | ||
| if ( is_admin() ) { | ||
| $wpsc_admin_notifications = new WPSC_Admin_Notifications(); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do a class like this, let's extend WPSC_Message_Collection and use that as a data store, using this sub-class for the bits directly related to admin_notices.
Also, let's remove any terminology referring to them as Nags or Notifications - let's call them notices.