Forked from westonruter/amp-wordfence-compat.php
Last active
December 27, 2021 14:29
-
-
Save milindmore22/e3ed535dc10d5962d8030b3f0031d3b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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[] = '//script[ contains( @src, "wordfence/js/wfi18n." ) ]'; | |
$xpaths[] = '//script[ contains( ., "WordfenceI18nStrings" ) ]'; | |
$xpaths[] = '//link[ contains( @href, "wordfence/css/wordfenceBox." ) ]'; | |
return $xpaths; | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment