Skip to content

Instantly share code, notes, and snippets.

@westonruter
Last active June 2, 2020 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonruter/96ae3cb713051aae867b874196eef910 to your computer and use it in GitHub Desktop.
Save westonruter/96ae3cb713051aae867b874196eef910 to your computer and use it in GitHub Desktop.
<?php
/**
* AMP Sanitize Processing Instructions
*
* @package AMP_Sanitize_PIs
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2019 Google Inc.
*
* @wordpress-plugin
* Plugin Name: AMP Sanitize Processing Instructions
* Description: Quick fix for <a href="https://github.com/ampproject/amp-wp/issues/3409">amp-wp#3409</a>.
* Plugin URI: https://gist.github.com/westonruter/96ae3cb713051aae867b874196eef910
* Version: 0.1.0
* 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/96ae3cb713051aae867b874196eef910
*/
namespace AMP_Sanitize_PIs;
add_filter(
'amp_content_sanitizers',
function ( $sanitizers ) {
class PI_Sanitizer extends \AMP_Base_Sanitizer {
function sanitize() {
$xpath = new \DOMXPath( $this->dom );
foreach ( $xpath->query( '//processing-instruction()' ) as $node ) {
$node->parentNode->removeChild( $node );
}
}
}
$sanitizers[ __NAMESPACE__ . '\PI_Sanitizer' ] = [];
return $sanitizers;
}
);
@westonruter
Copy link
Author

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