Skip to content

Commit

Permalink
Issue #842: Use the constant CALLBACK_KEY.
Browse files Browse the repository at this point in the history
Substitute all uses of 'remove_invalid_callback'
With AMP_Validation_Utils::CALLBACK_KEY.
  • Loading branch information
Ryan Kienstra committed Feb 20, 2018
1 parent afdefdf commit 6c587e2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions includes/class-amp-theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -783,9 +783,9 @@ public static function prepare_response( $response, $args = array() ) {

$args = array_merge(
array(
'content_max_width' => ! empty( $content_width ) ? $content_width : AMP_Post_Template::CONTENT_MAX_WIDTH, // Back-compat.
'use_document_element' => true,
'remove_invalid_callback' => null,
'content_max_width' => ! empty( $content_width ) ? $content_width : AMP_Post_Template::CONTENT_MAX_WIDTH, // Back-compat.
'use_document_element' => true,
AMP_Validation_Utils::CALLBACK_KEY => null,
),
$args
);
Expand Down
8 changes: 4 additions & 4 deletions includes/sanitizers/class-amp-base-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ public function maybe_enforce_https_src( $src, $force_https = false ) {
*/
public function remove_invalid_child( $child ) {
$child->parentNode->removeChild( $child );
if ( isset( $this->args['remove_invalid_callback'] ) ) {
call_user_func( $this->args['remove_invalid_callback'], $child, $this->current_plugin_output );
if ( isset( $this->args[ AMP_Validation_Utils::CALLBACK_KEY ] ) ) {
call_user_func( $this->args[ AMP_Validation_Utils::CALLBACK_KEY ], $child, $this->current_plugin_output );
}
}

Expand All @@ -343,13 +343,13 @@ public function remove_invalid_child( $child ) {
* @return void
*/
public function remove_invalid_attribute( $element, $attribute ) {
if ( isset( $this->args['remove_invalid_callback'] ) ) {
if ( isset( $this->args[ AMP_Validation_Utils::CALLBACK_KEY ] ) ) {
if ( is_string( $attribute ) ) {
$attribute = $element->getAttributeNode( $attribute );
}
if ( $attribute ) {
$element->removeAttributeNode( $attribute );
call_user_func( $this->args['remove_invalid_callback'], $attribute, $this->current_plugin_output );
call_user_func( $this->args[ AMP_Validation_Utils::CALLBACK_KEY ], $attribute, $this->current_plugin_output );
}
} elseif ( is_string( $attribute ) ) {
$element->removeAttribute( $attribute );
Expand Down
4 changes: 2 additions & 2 deletions includes/utils/class-amp-validation-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ public static function process_markup( $markup ) {
/** This filter is documented in wp-includes/post-template.php */
$markup = apply_filters( 'the_content', $markup );
$args = array(
'content_max_width' => ! empty( $content_width ) ? $content_width : AMP_Post_Template::CONTENT_MAX_WIDTH,
'remove_invalid_callback' => 'AMP_Validation_Utils::track_removed',
'content_max_width' => ! empty( $content_width ) ? $content_width : AMP_Post_Template::CONTENT_MAX_WIDTH,
self::CALLBACK_KEY => 'AMP_Validation_Utils::track_removed',
);
AMP_Content_Sanitizer::sanitize( $markup, amp_get_content_sanitizers(), $args );
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test-class-amp-base-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public function test_remove_child() {

$this->assertEquals( $child, $parent->firstChild );
$sanitizer = new AMP_Iframe_Sanitizer( $dom_document, array(
'remove_invalid_callback' => 'AMP_Validation_Utils::track_removed',
AMP_Validation_Utils::CALLBACK_KEY => 'AMP_Validation_Utils::track_removed',
) );
$sanitizer->remove_invalid_child( $child );
$this->assertEquals( null, $parent->firstChild );
Expand Down Expand Up @@ -286,7 +286,7 @@ public function test_remove_attribute() {
$video->setAttribute( $attribute, 'someFunction()' );
$attr_node = $video->getAttributeNode( $attribute );
$args = array(
'remove_invalid_callback' => 'AMP_Validation_Utils::track_removed',
AMP_Validation_Utils::CALLBACK_KEY => 'AMP_Validation_Utils::track_removed',
);
$sanitizer = new AMP_Video_Sanitizer( $dom_document, $args );
$sanitizer->remove_invalid_attribute( $video, $attribute );
Expand Down
2 changes: 1 addition & 1 deletion tests/test-class-amp-theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function test_prepare_response() {
$original_html = trim( ob_get_clean() );
$removed_nodes = array();
$sanitized_html = AMP_Theme_Support::prepare_response( $original_html, array(
'remove_invalid_callback' => function( $node ) use ( &$removed_nodes ) {
AMP_Validation_Utils::CALLBACK_KEY => function( $node ) use ( &$removed_nodes ) {
$removed_nodes[ $node->nodeName ] = $node;
},
) );
Expand Down

0 comments on commit 6c587e2

Please sign in to comment.