Use AJAX request and usermeta rather than user settings for dismissing admin bar pointers. see #18693.

git-svn-id: http://svn.automattic.com/wordpress/trunk@18937 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2011-10-10 23:31:36 +00:00
parent 8306f943dd
commit 24d7c61eb5
2 changed files with 28 additions and 6 deletions

View File

@ -1573,7 +1573,24 @@ case 'wp-remove-post-lock' :
$new_lock = ( time() - apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2 ) + 5 ) . ':' . $active_lock[1]; $new_lock = ( time() - apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2 ) + 5 ) . ':' . $active_lock[1];
update_post_meta( $post_id, '_edit_lock', $new_lock, implode( ':', $active_lock ) ); update_post_meta( $post_id, '_edit_lock', $new_lock, implode( ':', $active_lock ) );
die( '1' ); die( '1' );
case 'dismiss-wp-pointer' :
$pointer = $_POST['pointer'];
if ( $pointer != sanitize_key( $pointer ) )
die( '0' );
// check_ajax_referer( 'dismiss-pointer_' . $pointer );
$dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
if ( in_array( $pointer, $dismissed ) )
die( '0' );
$dismissed[] = $pointer;
$dismissed = implode( ',', $dismissed );
update_user_meta( get_current_user_id(), 'dismissed_wp_pointers', $dismissed );
die( '1' );
break;
default : default :
do_action( 'wp_ajax_' . $_POST['action'] ); do_action( 'wp_ajax_' . $_POST['action'] );
die('0'); die('0');

View File

@ -1640,8 +1640,9 @@ function get_submit_button( $text = NULL, $type = 'primary', $name = 'submit', $
function wp_pointer_enqueue( $hook_suffix ) { function wp_pointer_enqueue( $hook_suffix ) {
$enqueue = false; $enqueue = false;
$admin_bar = get_user_setting( 'p0', 0 ); $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
if ( ! $admin_bar && apply_filters( 'show_wp_pointer_admin_bar', true ) ) {
if ( ! in_array( 'wp330-admin-bar', $dismissed ) && apply_filters( 'show_wp_pointer_admin_bar', true ) ) {
$enqueue = true; $enqueue = true;
add_action( 'admin_print_footer_scripts', '_wp_pointer_print_admin_bar' ); add_action( 'admin_print_footer_scripts', '_wp_pointer_print_admin_bar' );
} }
@ -1655,9 +1656,9 @@ function wp_pointer_enqueue( $hook_suffix ) {
add_action( 'admin_enqueue_scripts', 'wp_pointer_enqueue' ); add_action( 'admin_enqueue_scripts', 'wp_pointer_enqueue' );
function _wp_pointer_print_admin_bar() { function _wp_pointer_print_admin_bar() {
$pointer_content = '<h3>' . ('The admin bar has been updated in WordPress 3.3.') . '</h3>'; $pointer_content = '<h3>' . 'The admin bar has been updated in WordPress 3.3.' . '</h3>';
$pointer_content .= '<p>' . sprintf( ('Have some feedback? Visit this <a href="%s">ticket</a>.'), 'http://core.trac.wordpress.org/ticket/18197' ) . '</p>'; $pointer_content .= '<p>' . sprintf( 'Have some feedback? Visit the <a href="%s">forum</a>.', 'http://wordpress.org/support/forum/alphabeta' ) . '</p>';
$pointer_content .= '<p>' . sprintf( ('P.S. You are looking at a new admin pointer. Chime in <a href="%s">here</a>.'), 'http://core.trac.wordpress.org/ticket/18693' ) . '</p>'; $pointer_content .= '<p>' . 'P.S. You are looking at a new admin pointer.' . '</p>';
?> ?>
<script type="text/javascript"> <script type="text/javascript">
@ -1671,7 +1672,11 @@ jQuery(document).ready( function($) {
offset: '-25 0' offset: '-25 0'
}, },
close: function() { close: function() {
setUserSetting( 'p0', '1' ); $.post( ajaxurl, {
pointer: 'wp330-admin-bar',
// _ajax_nonce: $('#_ajax_nonce').val(),
action: 'dismiss-wp-pointer'
});
} }
}).pointer('open'); }).pointer('open');
}); });