Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions wpsc-admin/db-upgrades/routines/14.php
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'
)
);
}
1 change: 1 addition & 0 deletions wpsc-core/wpsc-includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-deprecated.php' );

// Start including the rest of the plugin here
require_once( WPSC_FILE_PATH . '/wpsc-includes/wpsc-admin-notifications.class.php' );
require_once( WPSC_FILE_PATH . '/wpsc-includes/wpsc-meta-util.php' );
require_once( WPSC_FILE_PATH . '/wpsc-includes/wpsc-checkout-localization.php' );
require_once( WPSC_FILE_PATH . '/wpsc-includes/wpsc-checkout-ajax.php' );
Expand Down
174 changes: 174 additions & 0 deletions wpsc-includes/wpsc-admin-notifications.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<?php

/**
* Show WPeC admin notifications, a.k.a. Nags
Copy link
Member

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.

*
* 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
Copy link
Member

Choose a reason for hiding this comment

The 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() {
Copy link
Member

Choose a reason for hiding this comment

The 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 get_instance() method.


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 ) )
Copy link
Member

Choose a reason for hiding this comment

The 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 );
Copy link
Member

Choose a reason for hiding this comment

The 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 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Properties should be nouns, methods should be verbs. I'd change new_message to add_message, but again, this would be done via the WPSC_Message_Collection class.

}



// If we are showing an admin page we want to show the admin nags
if ( is_admin() ) {
$wpsc_admin_notifications = new WPSC_Admin_Notifications();
}