Skip to content
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

Add AMP icon if AMP is enabled on single error page #1473

Merged
merged 11 commits into from Sep 27, 2018

Conversation

jacobschweitzer
Copy link
Contributor

No description provided.

@westonruter
Copy link
Member

@jacobschweitzer Could you please add before/after screenshots in PRs like this?

@jacobschweitzer
Copy link
Contributor Author

@westonruter Of course. Here we are:

Before:
screen shot 2018-09-27 at 2 18 06 pm

After:
screen shot 2018-09-27 at 2 18 17 pm

*
* @return bool|void
*/
public static function is_amp_enabled_on_post( $post, $validation_errors = array(), $counts = array() ) {
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better to eliminate the $validation_errors and $counts params. This simplifies the API. Any previously-obtained terms will already be stored in the object cache, so there is not really much concern about duplicated work.

$counts['ack_rejected']++;
break;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This foreach loop is duplicated with display_invalid_url_validation_error_counts_summary. I suggest adding a protected method for count_invalid_url_validation_errors() which you pass the $validation_errors array both here and in display_invalid_url_validation_error_counts_summary.

component.showAMPIconIfEnabled = function() {
const heading = document.getElementsByClassName( 'wp-heading-inline' );
if ( heading[ 0 ] && true === component.data.l10n.amp_enabled ) {
let ampIcon = document.createElement( 'span' );
Copy link
Member

Choose a reason for hiding this comment

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

This should use const not let.

* Adds the AMP icon to the page heading if AMP is enabled on this URL.
*/
component.showAMPIconIfEnabled = function() {
const heading = document.getElementsByClassName( 'wp-heading-inline' );
Copy link
Member

Choose a reason for hiding this comment

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

This can use querySelector instead of getElementsByClassName. So:

const heading = document.querySelector( '.wp-heading-inline' );

Then below just check to see if heading is truthy as opposed to heading[0]

return;
}

$post = get_post( intval( $_GET['post'] ) ); // WPCS: CSRF OK.
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is necessary because the $post global will already be populated on the edit post screen. So instead of $post this you can just use get_post() below.

@@ -2007,7 +2008,7 @@ public static function get_single_url_page_heading() {
}

/* translators: %s is the name of the page with the the validation error(s) */
return esc_html( sprintf( __( 'Errors for: %s', 'amp' ), $name ) );
return esc_html( sprintf( __( 'Errors for: %1$s', 'amp' ), $name ) );
Copy link
Member

Choose a reason for hiding this comment

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

This can remain just %s because there is only one placeholder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh good catch, I tried adding the icon in here before but realized it was added as text via JS so it didn't work that way.

$pagenow = 'post.php';
$pagenow = 'post.php';
$amp_invalid_url_post = $this->factory()->post->create_and_get( array( 'post_type' => AMP_Invalid_URL_Post_Type::POST_TYPE_SLUG ) );
$post = $this->factory()->post->create_and_get();
Copy link
Member

Choose a reason for hiding this comment

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

Make this global here.

@westonruter westonruter added this to the v1.0 milestone Sep 27, 2018
@westonruter westonruter merged commit b83c6fe into develop Sep 27, 2018
@westonruter westonruter deleted the add/amp-icon-if-enabled-single-url branch September 27, 2018 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants