-
Notifications
You must be signed in to change notification settings - Fork 383
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
Display a welcome notice on the main 'AMP Settings' page #1442
Conversation
@todo: Add the full copy for this notice when it is decided. Once this notice is dismissed, it won't display again.
That notice is important also, but the welcome notice will only appear until it is dismissed.
|
||
$notice_id = 'welcome-notice-1'; | ||
$dismissed = get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ); | ||
if ( in_array( $notice_id, explode( ',', strval( $dismissed ) ), true ) ) { |
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.
Question About Admin Pointer User Meta
Hi @westonruter,
What do you think about how this uses the user meta for admin pointers to keep track of whether this notice was dismissed?
This is very similar to how this admin pointer PR does this.
Of course, this isn't actually an admin pointer, so it's not ideal.
But this is a little simpler, as it can reuse the dismiss-wp-pointer
action handler when the user dismisses it.
Thanks, Weston!
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.
My main concern is what happens over time. If each new version of the plugin will include new information that is shown in this message, then the dismissed_wp_pointers
usermeta will grow endlessly.
You could instead consider what was added for the Try Gutenberg screen:
But maybe this is all overkill. For a one-off, I don't see a reason why to not use the admin-pointers. They're being used for non-pointer things already, including the theme and plugin editor warnings:
So I'd say go ahead with pointers.
When it was called for the second time, it was empty. So simply store it in a variable.
return; | ||
} | ||
|
||
$notice_id = 'welcome-notice-1'; |
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.
This should have some amp
prefix.
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.
Good point. 8f02acf#diff-6dc720c5e5352d31e656ef4973984528R344 makes this amp-welcome-notice-1
( function( $ ) { | ||
$( function() { | ||
// On dismissing the notice, make a POST request to store this notice with the dismissed WP pointers so it doesn't display again. | ||
$( document ).on( 'click', '#<?php echo $notice_id; // WPCS: XSS OK. ?> .notice-dismiss', function() { |
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.
Instead of: '#<?php echo $notice_id; // WPCS: XSS OK. ?> .notice-dismiss'
Do this: <?php echo wp_json_encode( "#$notice_id .notice-dismiss" ); ?>
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.
Thanks, 8f02acf#diff-6dc720c5e5352d31e656ef4973984528R357 applies your suggestion.
$( document ).on( 'click', '#<?php echo $notice_id; // WPCS: XSS OK. ?> .notice-dismiss', function() { | ||
console.log( 'clicked' ); | ||
$.post( ajaxurl, { | ||
pointer: '<?php echo $notice_id; // WPCS: XSS OK. ?>', |
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.
As above, better to do pointer: <?php echo wp_json_encode( $notice_id ); ?>
,
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.
Thanks, 8f02acf#diff-6dc720c5e5352d31e656ef4973984528R360 applies your snippet.
|
||
$notice_id = 'welcome-notice-1'; | ||
$dismissed = get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ); | ||
if ( in_array( $notice_id, explode( ',', strval( $dismissed ) ), true ) ) { |
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.
My main concern is what happens over time. If each new version of the plugin will include new information that is shown in this message, then the dismissed_wp_pointers
usermeta will grow endlessly.
You could instead consider what was added for the Try Gutenberg screen:
But maybe this is all overkill. For a one-off, I don't see a reason why to not use the admin-pointers. They're being used for non-pointer things already, including the theme and plugin editor warnings:
So I'd say go ahead with pointers.
On Weston's suggestion, as this is more secure.
…ething The copy can still change, but this now has Leo's copy for all 3 template modes.
…aves something" This is intended for Issue 1399, and I meant to commit this to a separate branch for that. This reverts commit 3ec5334.
( function( $ ) { | ||
$( function() { | ||
// On dismissing the notice, make a POST request to store this notice with the dismissed WP pointers so it doesn't display again. | ||
$( document ).on( 'click', <?php echo wp_json_encode( "#$notice_id .notice-dismiss" ); ?>, function() { |
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.
Another point, this code is using event delegation when it doesn't need to. It should instead just be:
$( <?php echo wp_json_encode( "#$notice_id .notice-dismiss" ); ?> ).on( 'click', function() {...});
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.
Hi Weston, good point.
But it looks like the button.notice-dismiss
might be created with JS when the is-dismissible
class is present, and might not yet exist at the time the <script>
above runs.
<button type="button" class="notice-dismiss">
So the click
handler with that selector doesn't run.
Maybe if this script ran later, the button.notice-dismiss
would be present.
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.
ok, that makes sense
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.
At least we can do this:
$( <?php echo wp_json_encode( "#$notice_id" ); ?> ).on( 'click', '.notice-dismiss', function() {
That will scope the delegated event to the containing element.
Also, add an icon in the top left. And copy the styling for this icon, slightly modifiying it. Like the margin: 5px;
Notice Copy Applied |
<span class="amp-logo-icon"></span> | ||
<h1><?php esc_html_e( 'Welcome to the AMP for WordPress plugin v1.0', 'amp' ); ?></h1> | ||
<p><?php esc_html_e( 'Thank you for installing! Bring the speed and features of the open source AMP project to your site, the WordPress way, complete with the tools to support content authoring and website development.', 'amp' ); ?></p> | ||
<h2><?php esc_html_e( 'What's New', 'amp' ); ?></h2> |
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.
The '
character here might not be the best way to render the '
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.
That's right. It should be ’
instead.
Request For Another Round Of Review Hi @westonruter, Thanks, Weston! |
'Thank you for installing!' text Ideally, this would display 'Thank you for installing!' only on installing |
* Refactor jQuery ready call. * Remove debug code. * Use regular img element for SVG as opposed to background image. * Use curly quote instead of straight apostrophe. * Improve event delegation.
<span class="amp-logo-icon"></span> | ||
<h1><?php esc_html_e( 'Welcome to the AMP for WordPress plugin v1.0', 'amp' ); ?></h1> | ||
<p><?php esc_html_e( 'Thank you for installing! Bring the speed and features of the open source AMP project to your site, the WordPress way, complete with the tools to support content authoring and website development.', 'amp' ); ?></p> | ||
<h2><?php esc_html_e( 'What's New', 'amp' ); ?></h2> |
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.
That's right. It should be ’
instead.
( function( $ ) { | ||
$( function() { | ||
// On dismissing the notice, make a POST request to store this notice with the dismissed WP pointers so it doesn't display again. | ||
$( document ).on( 'click', <?php echo wp_json_encode( "#$notice_id .notice-dismiss" ); ?>, function() { |
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.
At least we can do this:
$( <?php echo wp_json_encode( "#$notice_id" ); ?> ).on( 'click', '.notice-dismiss', function() {
That will scope the delegated event to the containing element.
|
||
<style> | ||
.amp-logo-icon { | ||
background-image: url( "<?php echo esc_url( amp_get_asset_url( 'images/amp-logo-icon.svg' ) ); ?>" ); |
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.
HTML entities don't render properly inside of CSS. So best to just remove esc_url()
I believe.
$( function() { | ||
// On dismissing the notice, make a POST request to store this notice with the dismissed WP pointers so it doesn't display again. | ||
$( document ).on( 'click', <?php echo wp_json_encode( "#$notice_id .notice-dismiss" ); ?>, function() { | ||
console.log( 'clicked' ); |
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.
Debug code to be removed.
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.
Oh, wow. That shouldn't have been there.
|
||
<script> | ||
( function( $ ) { | ||
$( function() { |
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.
This function should be combined with its parent function:
jQuery( function( $ ) {
/* ... */
} );
|
||
?> | ||
<div class="notice notice-info is-dismissible" id="<?php echo esc_attr( $notice_id ); ?>"> | ||
<span class="amp-logo-icon"></span> |
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.
I think this should just be a regular img
.
I'd like to suggest the following changes to the welcome banner (note that I changed a few lines of text as well). What do you think? And the icon: cc @postphotos |
Going to actually post this to 1381, since that's the real issue :) |
Closes #1381