Skip to content

Instantly share code, notes, and snippets.

@westonruter
Last active January 21, 2021 19:27
Show Gist options
  • Save westonruter/b6691407af1648b402b09371a9faf7f0 to your computer and use it in GitHub Desktop.
Save westonruter/b6691407af1648b402b09371a9faf7f0 to your computer and use it in GitHub Desktop.
<?php
/**
* AMP Auto-Lightbox Disable plugin bootstrap.
*
* @package Google\AMP_Auto_Lightbox_Disable
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2021 Google Inc.
*
* @wordpress-plugin
* Plugin Name: AMP Auto-Lightbox Disable
* Plugin URI: https://gist.github.com/westonruter/b6691407af1648b402b09371a9faf7f0
* Description: Addresses <a href="https://github.com/ampproject/amp-wp/issues/5122">amp-wp#5122</a> by adding the <code>data-amp-auto-lightbox-disable</code> attribute to the <code>body</code>.
* 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/b6691407af1648b402b09371a9faf7f0
*/
namespace Google\AMP_Auto_Lightbox_Disable;
add_filter(
'amp_content_sanitizers',
function ( $sanitizers ) {
require_once __DIR__ . '/Sanitizer.php';
$sanitizers[ __NAMESPACE__ . '\Sanitizer' ] = [];
return $sanitizers;
}
);
<?php
/**
* Sanitizer file.
*
* @package Google\AMP_Auto_Lightbox_Disable
*/
namespace Google\AMP_Auto_Lightbox_Disable;
use AMP_Base_Sanitizer;
/**
* Class Sanitizer
*/
class Sanitizer extends AMP_Base_Sanitizer {
/**
* Add the data-amp-auto-lightbox-disable attribute to the body.
*/
public function sanitize() {
$this->dom->body->setAttributeNode( $this->dom->createAttribute( 'data-amp-auto-lightbox-disable' ) );
}
}
@westonruter
Copy link
Author

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