Skip to content

Instantly share code, notes, and snippets.

@westonruter
Last active July 25, 2021 04:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonruter/b14c95d5e8531dbc1167ebfc80c74562 to your computer and use it in GitHub Desktop.
Save westonruter/b14c95d5e8531dbc1167ebfc80c74562 to your computer and use it in GitHub Desktop.
<?php
/**
* AMP Reader Mode Comments plugin initialization file.
*
* @package AMP_Reader_Mode_Comments
* @author Weston Ruter, Google
* @link https://gist.github.com/westonruter/b14c95d5e8531dbc1167ebfc80c74562
* @license GPL-2.0-or-later
* @copyright 2019 Google Inc.
*
* @wordpress-plugin
* Plugin Name: AMP Reader Mode Comments
* Plugin URI: https://gist.github.com/westonruter/b14c95d5e8531dbc1167ebfc80c74562
* Description: Demonstration of adding comments to Reader mode templates. This requires AMP plugin v1.5 or greater.
* Version: 0.1
* Author: Weston Ruter, Google
* Author URI: https://weston.ruter.net/
* License: GNU General Public License v2 (or later)
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Gist Plugin URI: https://gist.github.com/westonruter/b14c95d5e8531dbc1167ebfc80c74562
*/
add_filter(
'amp_post_template_file',
function ( $file, $template_type ) {
// Abort if AMP plugin is older than v1.5.
if ( ! defined( 'AMP__VERSION' ) || version_compare( AMP__VERSION, '1.5', '<' ) ) {
return $file;
}
// Replace a comments link with the comments list and comments form.
if ( 'meta-comments-link' === $template_type ) {
$file = __DIR__ . '/comments.php';
}
return $file;
},
10,
2
);
<?php
wp_register_style( 'amp-reader-mode-comments', plugin_dir_url( __FILE__ ) . 'style.css', [], '0.1' );
wp_print_styles( [ 'amp-reader-mode-comments' ] );
comments_template();
/* CSS here is copied from Twenty Eleven */
/* @todo The CSS is not complete. It needs to be fleshed out. */
/* =Comments
----------------------------------------------- */
#comments-title {
color: #666;
font-size: 10px;
font-weight: 500;
line-height: 2.6em;
padding: 0 0 2.6em;
text-transform: uppercase;
}
.nopassword,
.nocomments {
color: #aaa;
font-size: 24px;
font-weight: 100;
margin: 26px 0;
text-align: center;
}
.commentlist {
list-style: none;
margin: 0 auto;
width: 68.9%;
}
.content .commentlist,
.page-template-sidebar-page-php .commentlist {
width: 100%; /* reset the width for the one-column and sidebar page layout */
}
.commentlist > li.comment {
background: #f6f6f6;
border: 1px solid #ddd;
-moz-border-radius: 3px;
border-radius: 3px;
margin: 0 0 1.625em;
padding: 1.625em;
position: relative;
}
.commentlist .pingback {
margin: 0 0 1.625em;
padding: 0 1.625em;
}
.commentlist .children {
list-style: none;
margin: 0;
}
.commentlist .children li.comment {
background: #fff;
border-left: 1px solid #ddd;
-moz-border-radius: 0 3px 3px 0;
border-radius: 0 3px 3px 0;
margin: 1.625em 0 0;
padding: 1.625em;
position: relative;
}
.commentlist .children li.comment .fn {
display: block;
}
.comment-meta .fn {
font-style: normal;
}
.comment-meta {
color: #666;
font-size: 12px;
line-height: 2.2em;
}
.commentlist .children li.comment .comment-meta {
line-height: 1.625em;
margin-left: 50px;
}
.commentlist .children li.comment .comment-content {
margin: 1.625em 0 0;
word-wrap: break-word;
-webkit-hyphens: auto;
-moz-hyphens: auto;
hyphens: auto;
}
.comment-meta a {
font-weight: bold;
}
.comment-meta a:focus,
.comment-meta a:active,
.comment-meta a:hover {
}
.commentlist .avatar {
-moz-border-radius: 3px;
border-radius: 3px;
-webkit-box-shadow: 0 1px 2px #ccc;
-moz-box-shadow: 0 1px 2px #ccc;
box-shadow: 0 1px 2px #ccc;
left: -102px;
padding: 0;
position: absolute;
top: 0;
}
.commentlist > li:before {
content: url(images/comment-arrow.png);
left: -21px;
position: absolute;
}
.commentlist > li.pingback:before {
content: '';
}
.commentlist .children .avatar {
background: none;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
left: 2.2em;
padding: 0;
top: 2.2em;
}
a.comment-reply-link {
background: #eee;
-moz-border-radius: 3px;
border-radius: 3px;
color: #666;
display: inline-block;
font-size: 12px;
padding: 0 8px;
text-decoration: none;
}
a.comment-reply-link:hover,
a.comment-reply-link:focus,
a.comment-reply-link:active {
background: #888;
color: #fff;
}
a.comment-reply-link > span {
display: inline-block;
position: relative;
top: -1px;
}
/* Post author highlighting */
.commentlist > li.bypostauthor {
background: #ddd;
border-color: #d3d3d3;
}
.commentlist > li.bypostauthor .comment-meta {
color: #575757;
}
.commentlist > li.bypostauthor .comment-meta a:focus,
.commentlist > li.bypostauthor .comment-meta a:active,
.commentlist > li.bypostauthor .comment-meta a:hover {
}
.commentlist > li.bypostauthor:before {
content: url(images/comment-arrow-bypostauthor.png);
}
/* Post Author threaded comments */
.commentlist .children > li.bypostauthor {
background: #ddd;
border-color: #d3d3d3;
}
/* Comment Form */
#respond {
background: #ddd;
border: 1px solid #d3d3d3;
-moz-border-radius: 3px;
border-radius: 3px;
margin: 0 auto 1.625em;
padding: 1.625em;
position: relative;
width: 68.9%;
}
#respond input[type="text"],
#respond textarea {
background: #fff;
border: 4px solid #eee;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: inset 0 1px 3px rgba(204,204,204,0.95);
-moz-box-shadow: inset 0 1px 3px rgba(204,204,204,0.95);
box-shadow: inset 0 1px 3px rgba(204,204,204,0.95);
position: relative;
padding: 10px;
text-indent: 80px;
}
#respond .comment-form-author,
#respond .comment-form-email,
#respond .comment-form-url,
#respond .comment-form-comment {
position: relative;
}
#respond .comment-form-author label,
#respond .comment-form-email label,
#respond .comment-form-url label,
#respond .comment-form-comment label {
background: #eee;
-webkit-box-shadow: 1px 2px 2px rgba(204,204,204,0.8);
-moz-box-shadow: 1px 2px 2px rgba(204,204,204,0.8);
box-shadow: 1px 2px 2px rgba(204,204,204,0.8);
color: #555;
display: inline-block;
font-size: 13px;
left: 4px;
min-width: 60px;
padding: 4px 10px;
position: relative;
top: 40px;
z-index: 1;
}
#respond input[type="text"]:focus,
#respond textarea:focus {
text-indent: 0;
z-index: 1;
}
#respond textarea {
resize: vertical;
width: 95%;
}
#respond .comment-form-author .required,
#respond .comment-form-email .required {
color: #bd3500;
font-size: 22px;
font-weight: bold;
left: 75%;
position: absolute;
z-index: 1;
}
#respond .comment-notes,
#respond .logged-in-as {
font-size: 13px;
}
#respond p {
margin: 10px 0;
}
#respond .form-submit {
float: right;
margin: -20px 0 10px;
}
#respond input#submit {
background: #222;
border: none;
-moz-border-radius: 3px;
border-radius: 3px;
-webkit-box-shadow: 0px 1px 2px rgba(0,0,0,0.3);
-moz-box-shadow: 0px 1px 2px rgba(0,0,0,0.3);
box-shadow: 0px 1px 2px rgba(0,0,0,0.3);
color: #eee;
cursor: pointer;
font-size: 15px;
margin: 20px 0;
padding: 5px 42px 5px 22px;
position: relative;
left: 30px;
text-shadow: 0 -1px 0 rgba(0,0,0,0.3);
}
#respond input#submit:active {
background: #1982d1;
color: #bfddf3;
}
#respond #cancel-comment-reply-link {
color: #666;
margin-left: 10px;
text-decoration: none;
}
#respond .logged-in-as a:hover,
#respond #cancel-comment-reply-link:hover {
text-decoration: underline;
}
.commentlist #respond {
margin: 1.625em 0 0;
width: auto;
}
#reply-title {
color: #373737;
font-size: 24px;
font-weight: bold;
line-height: 30px;
}
#cancel-comment-reply-link {
color: #888;
display: block;
font-size: 10px;
font-weight: normal;
line-height: 2.2em;
letter-spacing: 0.05em;
position: absolute;
right: 1.625em;
text-decoration: none;
text-transform: uppercase;
top: 1.1em;
}
#cancel-comment-reply-link:focus,
#cancel-comment-reply-link:active,
#cancel-comment-reply-link:hover {
color: #ff4b33;
}
#respond label {
line-height: 2.2em;
}
#respond input[type=text] {
display: block;
height: 24px;
width: 75%;
}
#respond p {
font-size: 12px;
}
#respond #wp-comment-cookies-consent {
margin: 0 10px 0 0;
}
p.comment-form-comment {
margin: 0;
}
.form-allowed-tags {
display: none;
}
@westonruter
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment