Skip to content

Instantly share code, notes, and snippets.

@westonruter
Last active September 6, 2022 18:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save westonruter/3bad77db53496c7103dd64ca1a0e1cf1 to your computer and use it in GitHub Desktop.
Save westonruter/3bad77db53496c7103dd64ca1a0e1cf1 to your computer and use it in GitHub Desktop.
<?php
/**
* AMP Wordfence Compat plugin bootstrap.
*
* @package Google\AMP_Wordfence_Compat
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2020 Google Inc.
*
* @wordpress-plugin
* Plugin Name: AMP Wordfence Compat
* Plugin URI: https://gist.github.com/westonruter/3bad77db53496c7103dd64ca1a0e1cf1
* Description: Compatibility plugin to prevent Wordfence from causing AMP validation errors. In particular, this ensures the Ajax watcher logic is included in AMP Dev Mode.
* Version: 0.2
* 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
*/
namespace Google\AMP_Wordfence_Compat;
add_filter(
'amp_dev_mode_element_xpaths',
function ( $xpaths ) {
// @todo The following can be revised once ampdevmode flags can be added to enqueued scripts and styles. See <https://github.com/ampproject/amp-wp/issues/4598>.
$xpaths[] = '//script[ contains( text(), "var WFAJAXWatcherVars" ) ]';
$xpaths[] = '//script[ contains( @src, "wp-includes/js/jquery/jquery.js" ) ]';
$xpaths[] = '//script[ contains( @src, "wp-includes/js/jquery/jquery.min.js" ) ]'; // As of WordPress 5.6.
$xpaths[] = '//script[ contains( @src, "wp-includes/js/jquery/jquery-migrate.js" ) ]';
$xpaths[] = '//script[ contains( @src, "wp-includes/js/jquery/jquery-migrate.min.js" ) ]';
$xpaths[] = '//script[ contains( @src, "wordfence/js/admin.ajaxWatcher." ) ]';
$xpaths[] = '//link[ contains( @href, "wordfence/css/wordfenceBox." ) ]';
return $xpaths;
}
);
@westonruter
Copy link
Author

Copy link

ghost commented Sep 5, 2022

@westonruter Hello. I was directed to your mini plugin by WordFence after asking WordFence for help with a validation error that the official Google AMP plugin is flagging. The plugin (WordFence Compatibility) did not resolve the error. I can provide the raw validation data to you directly, if helpful. I have asked WordFence on the chain linked above to continue to look into the issue, and would appreciate your help, too. Thank you.

@westonruter
Copy link
Author

@Marguerite-star Please open a topic on our support forum: https://wordpress.org/support/plugin/amp/

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