Last active
June 2, 2020 06:00
-
-
Save westonruter/99b1ca0d593f44888401a396d991e3a6 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 | |
/* | |
* Plugin Name: AMP NextGEN Gallery Compatibility | |
* Plugin URI: https://gist.github.com/westonruter/99b1ca0d593f44888401a396d991e3a6 | |
* Description: The NextGEN Gallery plugin has a resource manager that makes AMP responses invalid. It needs to be disabled in AMP. | |
* Author Name: Weston Ruter | |
* Gist Plugin URI: https://gist.github.com/westonruter/99b1ca0d593f44888401a396d991e3a6 | |
*/ | |
/* | |
* The following is not bulletproof. In particular it would not work in Native AMP mode, or if you have a page called "amp". | |
* This runs at init priority -2 because -1 is init callback that looks for NGG_DISABLE_RESOURCE_MANAGER constant. | |
*/ | |
add_action( | |
'init', | |
function() { | |
if ( ! function_exists( 'amp_get_slug' ) ) { | |
return; | |
} | |
$is_probably_amp = ( | |
( | |
isset( $_SERVER['REQUEST_URI'] ) | |
&& | |
preg_match( | |
'#/' . preg_quote( amp_get_slug(), '#' ) . '/?$#', | |
wp_parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) | |
) | |
) | |
|| | |
isset( $_GET[ amp_get_slug() ] ) | |
); | |
if ( $is_probably_amp ) { | |
define( 'NGG_DISABLE_RESOURCE_MANAGER', true ); | |
} | |
}, | |
-2 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation instructions: https://gist.github.com/westonruter/6110fbc4bef0c4b8c021a112012f7e9c