Skip to content

Commit

Permalink
Greatly simplify thread_comments handling in comment sanitizer
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Sep 2, 2021
1 parent bdefef0 commit aa06a75
Show file tree
Hide file tree
Showing 6 changed files with 242 additions and 195 deletions.
12 changes: 7 additions & 5 deletions includes/amp-helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,11 @@ function amp_get_content_sanitizers( $post = null ) {
'native_img_used' => $native_img_used,
],

AMP_Comments_Sanitizer::class => [
'thread_comments' => (bool) get_option( 'thread_comments' ),
'comments_live_list' => ! empty( $theme_support_args['comments_live_list'] ),
],

// The AMP_Script_Sanitizer runs here because based on whether it allows custom scripts
// to be kept, it may impact the behavior of other sanitizers. For example, if custom
// scripts are kept then this is a signal that tree shaking in AMP_Style_Sanitizer cannot be
Expand All @@ -1514,9 +1519,6 @@ function amp_get_content_sanitizers( $post = null ) {
AMP_Form_Sanitizer::class => [
'native_post_forms_allowed' => $native_post_forms_allowed,
],
AMP_Comments_Sanitizer::class => [
'comments_live_list' => ! empty( $theme_support_args['comments_live_list'] ),
],
AMP_Video_Sanitizer::class => [],
AMP_Audio_Sanitizer::class => [],
AMP_Object_Sanitizer::class => [],
Expand Down Expand Up @@ -1598,7 +1600,7 @@ function amp_get_content_sanitizers( $post = null ) {

// Prevent removal of script output by wp_comment_form_unfiltered_html_nonce().
if ( current_user_can( 'unfiltered_html' ) ) {
$dev_mode_xpaths[] = '//script[ preceding-sibling::input[ @name = "_wp_unfiltered_html_comment_disabled" ] and contains( text(), "_wp_unfiltered_html_comment_disabled" ) ]';
$dev_mode_xpaths[] = AMP_Comments_Sanitizer::UNFILTERED_HTML_COMMENT_SCRIPT_XPATH;
}

if ( is_admin_bar_showing() ) {
Expand Down Expand Up @@ -1644,11 +1646,11 @@ function amp_get_content_sanitizers( $post = null ) {
// Force core essential sanitizers to appear at the end at the end, with non-essential and third-party sanitizers appearing before.
$expected_final_sanitizer_order = [
AMP_Core_Theme_Sanitizer::class, // Must come before script sanitizer since onclick attributes are removed.
AMP_Comments_Sanitizer::class, // Must come before AMP_Script_Sanitizer since it removes comment-rely.js.
AMP_Script_Sanitizer::class, // Must come before sanitizers for image, video, audio, form, and style.
AMP_Srcset_Sanitizer::class,
AMP_Img_Sanitizer::class,
AMP_Form_Sanitizer::class,
AMP_Comments_Sanitizer::class,
AMP_Video_Sanitizer::class,
AMP_Audio_Sanitizer::class,
AMP_Object_Sanitizer::class,
Expand Down
13 changes: 13 additions & 0 deletions includes/sanitizers/class-amp-base-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,24 @@ public function get_selector_conversion_mapping() {
return [];
}

/**
* Get args.
*
* @since 2.2
*
* @return array Args.
*/
public function get_args() {
return $this->args;
}

/**
* Update args.
*
* Merges the supplied args with the existing args.
*
* @since 2.2
*
* @param array $args Args.
*/
public function update_args( $args ) {
Expand Down
Loading

0 comments on commit aa06a75

Please sign in to comment.