-
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
Add page support #825
Merged
Merged
Add page support #825
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6b4de15
176: add page support
ThierryA c5231b0
Fix amp_get_permalink() for permalinks containing query params (e.g. …
westonruter dcf7eb1
Always use amp query var in permalinks for hierarchical post types
westonruter 3a76316
Restore Schema.org properties for WebPage entity
westonruter 2ae58d2
Show AMP as disabled without UI to make enabled if post is password p…
westonruter e7221f4
Return false from post_supports_amp() for homepage and page for posts…
westonruter 51c5b17
Update readme
westonruter 5dd2bc6
Refactor header/footer template parts to extract html-start/html-end …
westonruter 57f5849
Always display AMP status + notice where applicable
ThierryA 269b937
Improve post status notice
ThierryA cff791e
Include link to AMP post type settings screen in notice; use alt style
westonruter 9630709
Refactor amp_post_supports_error() into AMP_Post_Type_Support::get_su…
westonruter 34a0e9e
Include fallback error message for when all known reasons for unavail…
westonruter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,32 @@ | ||
<?php | ||
/** | ||
* Footer template. | ||
* | ||
* @package AMP | ||
*/ | ||
|
||
/** | ||
* Context. | ||
* | ||
* @var AMP_Post_Template $this | ||
*/ | ||
?> | ||
<footer class="amp-wp-footer"> | ||
<div> | ||
<h2><?php echo esc_html( $this->get( 'blog_name' ) ); ?></h2> | ||
<p> | ||
<a href="<?php echo esc_url( esc_html__( 'https://wordpress.org/', 'amp' ) ); ?>"><?php echo esc_html( sprintf( __( 'Powered by %s', 'amp' ), 'WordPress' ) ); ?></a> | ||
<a href="<?php echo esc_url( esc_html__( 'https://wordpress.org/', 'amp' ) ); ?>"> | ||
<?php | ||
// translators: %1$s is WordPress. | ||
echo esc_html( sprintf( __( 'Powered by %s', 'amp' ), 'WordPress' ) ); | ||
?> | ||
</a> | ||
</p> | ||
<a href="#top" class="back-to-top"><?php esc_html_e( 'Back to top', 'amp' ); ?></a> | ||
</div> | ||
</footer> | ||
|
||
<?php do_action( 'amp_post_template_footer', $this ); ?> | ||
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. Putting this inside of 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. Great thoughts! |
||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
* Header template. | ||
* | ||
* @package AMP | ||
*/ | ||
|
||
/** | ||
* Context. | ||
* | ||
* @var AMP_Post_Template $this | ||
*/ | ||
?> | ||
<!doctype html> | ||
<html amp <?php echo AMP_HTML_Utils::build_attributes_string( $this->get( 'html_tag_attributes' ) ); // WPCS: XSS ok. ?>> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"> | ||
<?php do_action( 'amp_post_template_head', $this ); ?> | ||
<style amp-custom> | ||
<?php $this->load_parts( array( 'style' ) ); ?> | ||
<?php do_action( 'amp_post_template_css', $this ); ?> | ||
</style> | ||
</head> | ||
|
||
<body class="<?php echo esc_attr( $this->get( 'body_class' ) ); ?>"> | ||
|
||
<?php $this->load_parts( array( 'header-bar' ) ); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
* Page view template. | ||
* | ||
* @package AMP | ||
*/ | ||
|
||
/** | ||
* Context. | ||
* | ||
* @var AMP_Post_Template $this | ||
*/ | ||
?> | ||
<?php $this->load_parts( array( 'header' ) ); ?> | ||
|
||
<article class="amp-wp-article"> | ||
<header class="amp-wp-article-header"> | ||
<h1 class="amp-wp-title"><?php echo esc_html( $this->get( 'post_title' ) ); ?></h1> | ||
</header> | ||
|
||
<?php $this->load_parts( array( 'featured-image' ) ); ?> | ||
|
||
<div class="amp-wp-article-content"> | ||
<?php echo $this->get( 'post_amp_content' ); // WPCS: XSS ok. Handled in AMP_Content::transform(). ?> | ||
</div> | ||
</article> | ||
|
||
<?php $this->load_parts( array( 'footer' ) ); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,33 @@ | ||
<!doctype html> | ||
<html amp <?php echo AMP_HTML_Utils::build_attributes_string( $this->get( 'html_tag_attributes' ) ); ?>> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"> | ||
<?php do_action( 'amp_post_template_head', $this ); ?> | ||
<style amp-custom> | ||
<?php $this->load_parts( array( 'style' ) ); ?> | ||
<?php do_action( 'amp_post_template_css', $this ); ?> | ||
</style> | ||
</head> | ||
|
||
<body class="<?php echo esc_attr( $this->get( 'body_class' ) ); ?>"> | ||
|
||
<?php $this->load_parts( array( 'header-bar' ) ); ?> | ||
<?php | ||
/** | ||
* Single view template. | ||
* | ||
* @package AMP | ||
*/ | ||
|
||
/** | ||
* Context. | ||
* | ||
* @var AMP_Post_Template $this | ||
*/ | ||
?> | ||
<?php $this->load_parts( array( 'header' ) ); ?> | ||
|
||
<article class="amp-wp-article"> | ||
|
||
<header class="amp-wp-article-header"> | ||
<h1 class="amp-wp-title"><?php echo wp_kses_data( $this->get( 'post_title' ) ); ?></h1> | ||
<h1 class="amp-wp-title"><?php echo esc_html( $this->get( 'post_title' ) ); ?></h1> | ||
<?php $this->load_parts( apply_filters( 'amp_post_article_header_meta', array( 'meta-author', 'meta-time' ) ) ); ?> | ||
</header> | ||
|
||
<?php $this->load_parts( array( 'featured-image' ) ); ?> | ||
|
||
<div class="amp-wp-article-content"> | ||
<?php echo $this->get( 'post_amp_content' ); // amphtml content; no kses ?> | ||
<?php echo $this->get( 'post_amp_content' ); // WPCS: XSS ok. Handled in AMP_Content::transform(). ?> | ||
</div> | ||
|
||
<footer class="amp-wp-article-footer"> | ||
<?php $this->load_parts( apply_filters( 'amp_post_article_footer_meta', array( 'meta-taxonomy', 'meta-comments-link' ) ) ); ?> | ||
</footer> | ||
|
||
</article> | ||
|
||
<?php $this->load_parts( array( 'footer' ) ); ?> | ||
|
||
<?php do_action( 'amp_post_template_footer', $this ); ?> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
/** | ||
* Test AMP helper functions. | ||
* | ||
* @package AMP | ||
*/ | ||
|
||
/** | ||
* Class Test_AMP_Helper_Functions | ||
*/ | ||
class Test_AMP_Helper_Functions extends WP_UnitTestCase { | ||
|
||
/** | ||
* Filter for amp_pre_get_permalink and amp_get_permalink. | ||
* | ||
* @param string $url URL. | ||
* @param int $post_id Post ID. | ||
* @return string URL. | ||
*/ | ||
public function return_example_url( $url, $post_id ) { | ||
$current_filter = current_filter(); | ||
return 'http://overridden.example.com/?' . build_query( compact( 'url', 'post_id', 'current_filter' ) ); | ||
} | ||
|
||
/** | ||
* Test amp_get_permalink() without pretty permalinks. | ||
* | ||
* @covers amp_get_permalink() | ||
*/ | ||
public function test_amp_get_permalink_without_pretty_permalinks() { | ||
delete_option( 'permalink_structure' ); | ||
flush_rewrite_rules(); | ||
|
||
$drafted_post = $this->factory()->post->create( array( | ||
'post_name' => 'draft', | ||
'post_status' => 'draft', | ||
'post_type' => 'post', | ||
) ); | ||
$published_post = $this->factory()->post->create( array( | ||
'post_name' => 'publish', | ||
'post_status' => 'publish', | ||
'post_type' => 'post', | ||
) ); | ||
$published_page = $this->factory()->post->create( array( | ||
'post_name' => 'publish', | ||
'post_status' => 'publish', | ||
'post_type' => 'page', | ||
) ); | ||
|
||
$this->assertStringEndsWith( '&', amp_get_permalink( $published_post ) ); | ||
$this->assertStringEndsWith( '&', amp_get_permalink( $drafted_post ) ); | ||
$this->assertStringEndsWith( '&', amp_get_permalink( $published_page ) ); | ||
|
||
add_filter( 'amp_pre_get_permalink', array( $this, 'return_example_url' ), 10, 2 ); | ||
add_filter( 'amp_get_permalink', array( $this, 'return_example_url' ), 10, 2 ); | ||
$url = amp_get_permalink( $published_post ); | ||
$this->assertContains( 'current_filter=amp_pre_get_permalink', $url ); | ||
$this->assertContains( 'url=0', $url ); | ||
|
||
remove_filter( 'amp_pre_get_permalink', array( $this, 'return_example_url' ), 10 ); | ||
$url = amp_get_permalink( $published_post ); | ||
$this->assertContains( 'current_filter=amp_get_permalink', $url ); | ||
} | ||
|
||
/** | ||
* Test amp_get_permalink() with pretty permalinks. | ||
* | ||
* @covers amp_get_permalink() | ||
*/ | ||
public function test_amp_get_permalink_with_pretty_permalinks() { | ||
global $wp_rewrite; | ||
update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' ); | ||
$wp_rewrite->use_trailing_slashes = true; | ||
$wp_rewrite->init(); | ||
$wp_rewrite->flush_rules(); | ||
|
||
$drafted_post = $this->factory()->post->create( array( | ||
'post_name' => 'draft', | ||
'post_status' => 'draft', | ||
) ); | ||
$published_post = $this->factory()->post->create( array( | ||
'post_name' => 'publish', | ||
'post_status' => 'publish', | ||
) ); | ||
$published_page = $this->factory()->post->create( array( | ||
'post_name' => 'publish', | ||
'post_status' => 'publish', | ||
'post_type' => 'page', | ||
) ); | ||
|
||
$this->assertStringEndsWith( '&', amp_get_permalink( $drafted_post ) ); | ||
$this->assertStringEndsWith( '/amp/', amp_get_permalink( $published_post ) ); | ||
$this->assertStringEndsWith( '?amp', amp_get_permalink( $published_page ) ); | ||
|
||
add_filter( 'amp_pre_get_permalink', array( $this, 'return_example_url' ), 10, 2 ); | ||
add_filter( 'amp_get_permalink', array( $this, 'return_example_url' ), 10, 2 ); | ||
$url = amp_get_permalink( $published_post ); | ||
$this->assertContains( 'current_filter=amp_pre_get_permalink', $url ); | ||
$this->assertContains( 'url=0', $url ); | ||
|
||
remove_filter( 'amp_pre_get_permalink', array( $this, 'return_example_url' ), 10 ); | ||
$url = amp_get_permalink( $published_post ); | ||
$this->assertContains( 'current_filter=amp_get_permalink', $url ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
These Schema.org properties are also relevant to
WebPage
entities: http://schema.org/WebPageSo I don't see why we need to limit them just to posts.
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.
@westonruter I would argue that. This really depends on the use cases but in most cases pages published/modified date are not relevant, or even inconvenient. It is a very common use case not to include the
datePublished
anddatePublished
. If we take Apple for example, we can see thatdatePublished
is used on news article but not on pages.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.
True, but this is just in regards to the template rendering of the data. We're talking about metadata here. It should be up to the application to decide whether or not to show the
datePublished
if thetype
isWebPage
. In other words, the WP REST API for pages includes the published date, and that I think is a better parallel to the Schema.org metadata here.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.
Sounds good, I am on board 😄