disable = true;
amp_wp_remove_class_action( 'init', 'Abovethefold_Optimization', 'html_output_hook', 99999 );
amp_wp_remove_class_action( 'wp_head', 'Abovethefold_Optimization', 'header', 1 );
amp_wp_remove_class_action( 'wp_print_footer_scripts', 'Abovethefold_Optimization', 'footer', 99999 );
}
/**
* WP-Optimize Compatibility
*
* @link https://wordpress.org/plugins/wp-optimize
* @since 1.0.0
*/
if( class_exists('WP_Optimize') ) {
amp_wp_remove_class_action('plugins_loaded', 'WP_Optimize', 'plugins_loaded', 1);
}
/**
* WP Speed Grades Lite Compatibility
*
* @link http://www.wp-speed.com
* @since 1.0.0
*/
if( defined( 'WP_SPEED_GRADES_VERSION' ) ) {
add_action('init', array('Amp_WP_Plugin_Compatibility', 'pre_init'), 0);
}
self::$plugins = null; // Clear memory
add_action('plugins_loaded', 'Amp_WP_Plugin_Compatibility::plugins_loaded');
/**
* WPML - The WordPress Multilingual Plugin Compatibility
*
* @link https://wpml.org
* @since 1.0.0
*/
add_action('template_redirect', array(__CLASS__, 'fix_wpml_template_hooks'));
/**
* Pretty Links Compatibility
*
* @link https://wordpress.org/plugins/pretty-link/
* @since 1.0.0
*/
add_filter( 'prli-check-if-slug', 'Amp_WP_Plugin_Compatibility::pretty_links_compatibility', 2, 2 );
/**
* Polylang Compatibility
*
* @link https://wordpress.org/plugins/polylang/
* @since 1.0.0
*/
add_filter('pll_check_canonical_url', '__return_false');
/**
* New Relic Compatibility
*
* @link https://docs.newrelic.com/docs/agents/php-agent/getting-started/introduction-new-relic-php
* @since 1.0.0
*/
if (extension_loaded('newrelic') && function_exists('newrelic_disable_autorum')) {
newrelic_disable_autorum();
}
/**
* Squirrly SEO Plugin
*
* @since 1.0.4
* @link https://wordpress.org/plugins/squirrly-seo/
*/
add_action( 'template_redirect', array( __CLASS__, 'squirrly_seo' ) );
/**
* Jetpack
*
* @since 1.4.3.1 Added compatibility for Jetpack plugin
*/
add_action( 'template_redirect', array(__CLASS__, 'amp_wp_jetpack_compatibility' ), 9 );
/**
* Disable Multi Rating Plugin
* @link https://wordpress.org/plugins/multi-rating/
*
* @since 1.4.3.1
*/
add_filter('after_setup_theme', 'Amp_WP_Plugin_Compatibility::multi_rating');
/**
* Plugins Compatibility on 'template_redirect' Hook
*
* - All in One SEO Pack
*
* @since 1.4.3.1 Added compatibility for Squirrly SEO Plugin
*/
add_action( 'template_redirect', array(__CLASS__, 'fix_third_party_plugin_compatibilities' ) );
}
/**
* Pre init action
*/
public static function pre_init() {
remove_action('init', 'wpspgrpro_init_minify_html', 1);
}
/**
* Convert Plug plugin
*
* http://convertplug.com/
*/
public static function convert_plug() {
amp_wp_remove_class_filter('the_content', 'Convert_Plug', 'cp_add_content', 10);
}
/**
* WordPress Fastest Cache Plugins Fixes
*
* Disables minify features if WPFC plugin in AMP
*/
public static function wpfc_fix_options() {
if( $wp_fastest_cache_options = get_option( "WpFastestCache" ) ) {
$GLOBALS["wp_fastest_cache_options"] = json_decode( $wp_fastest_cache_options );
unset( $GLOBALS["wp_fastest_cache_options"]->wpFastestCacheRenderBlocking );
unset( $GLOBALS["wp_fastest_cache_options"]->wpFastestCacheCombineJsPowerFul );
unset( $GLOBALS["wp_fastest_cache_options"]->wpFastestCacheMinifyJs );
unset( $GLOBALS["wp_fastest_cache_options"]->wpFastestCacheCombineJs );
unset( $GLOBALS["wp_fastest_cache_options"]->wpFastestCacheCombineCss );
unset( $GLOBALS["wp_fastest_cache_options"]->wpFastestCacheLazyLoad );
unset( $GLOBALS["wp_fastest_cache_options"]->wpFastestCacheGoogleFonts );
} else {
$GLOBALS["wp_fastest_cache_options"] = array();
}
}
/**
* Plugin loaded hook
*/
public static function plugins_loaded() {
/**
* Initialize Custom Permalinks Support
*/
if( function_exists( 'custom_permalinks_request' ) ) { // Guess is custom permalinks installed and active
add_filter( 'request', 'Amp_WP_Plugin_Compatibility::amp_wp_custom_permalinks', 15 );
}
/**
* NextGEN Gallery Compatibility
*/
add_filter( 'run_ngg_resource_manager', '__return_false', 999 );
/**
* WPML Compatibility
*/
if( defined('WPML_PLUGIN_BASENAME') && WPML_PLUGIN_BASENAME ) {
add_action('wpml_is_redirected', '__return_false');
}
}
/**
* Add Custom Permalinks Compatibility
*
* @param array $query_vars
*
* @version 1.0.0
* @since 1.0.0
*
* @return array
*/
public static function amp_wp_custom_permalinks( $query_vars ) {
$amp_qv = defined('AMP_QUERY_VAR') ? AMP_QUERY_VAR : 'amp';
$path = amp_wp_get_wp_installation_slug();
if( !(
preg_match( "#^$path/*$amp_qv/(.*?)/*$#", $_SERVER['REQUEST_URI'], $matched ) ||
preg_match( "#^$path/*(.*?)/$amp_qv/*$#", $_SERVER['REQUEST_URI'], $matched )
) ) {
return $query_vars;
}
if( empty( $matched[1] ) ) {
return $query_vars;
}
remove_filter('request', 'Amp_WP_Plugin_Compatibility::amp_wp_custom_permalinks', 15);
$_SERVER['REQUEST_URI'] = '/' . $matched[1] . '/';
$query_vars ['amp'] = '1';
$_REQUEST['amp'] = '1';
if( $new_qv = custom_permalinks_request( $query_vars ) ) {
$new_qv['amp'] = '1';
// Prevent Redirect amp Post to non-amp Version
remove_filter('template_redirect', 'custom_permalinks_redirect', 5);
return $new_qv;
}
return $query_vars;
}
/**
* WPML plugin compatibility fixes
*/
public static function fix_wpml_template_hooks() {
global $wpml_language_resolution;
/**
* @var SitePress $sitepress
*/
$sitepress = isset($GLOBALS['sitepress']) ? $GLOBALS['sitepress'] : '';
$callback = array($sitepress, 'display_wpml_footer');
if( !$sitepress || !$sitepress instanceof SitePress) {
return;
}
if( has_action('wp_footer', $callback)) {
add_action('amp_wp_template_footer', $callback);
}
if( $sitepress->get_setting('language_negotiation_type') == '1' ) {
add_filter('amp_wp_transformer_exclude_subdir', array(
$wpml_language_resolution,
'get_active_language_codes'
));
}
}
/**
* Drop amp start-point from pretty link slug
*
* @param bool|object $is_pretty_link
* @param string $slug
*
* @since 1.0.0
* @return bool|object
*/
public static function pretty_links_compatibility($is_pretty_link, $slug) {
if( isset( $GLOBALS['prli_link']) && $GLOBALS['prli_link'] instanceof PrliLink ) {
if( preg_match( '#^/*' . Amp_WP_Public::AMP_WP_STARTPOINT . '/+(.+)$#i', $slug, $match ) ) {
/**
* @var PrliLink $instance
*/
$instance = $GLOBALS['prli_link'];
$callback = array($instance, 'getOneFromSlug');
if( is_callable($callback) ) {
return call_user_func($callback, $match[1]);
}
}
}
return $is_pretty_link;
}
/**
* Squirrly SEO Compatibility
*
* @since 1.8.3
*/
public static function squirrly_seo() {
if( !is_callable( 'SQ_Classes_ObjController::getClass' ) ) {
return;
}
$object = SQ_Classes_ObjController::getClass( 'SQ_Models_Services_Canonical' );
remove_filter( 'sq_canonical', array( $object, 'packCanonical' ), 99 );
add_action( 'sq_canonical', array( __class__, 'return_rel_canonical' ), 99 );
}
public static function return_rel_canonical() {
if ( $canonical = amp_wp_rel_canonical_url() ) {
return '';
}
}
/**
* Plugins Compatibility on 'template_redirect' Hook
*
* - All In One SEO Pack
* @since 1.4.3.1
*/
public static function fix_third_party_plugin_compatibilities() {
/**
* All In One SEO Pack
*
* - Print Meta Tags
*
* @since 1.4.3.1
*/
if( class_exists('All_in_One_SEO_Pack') ) {
/**
* Meta Tags
*
* @since 1.4.3.1
*/
add_action('amp_wp_template_head', array( __CLASS__, 'aioseop_metatags') );
}
}
/**
* All In One SEO Pack Meta Tags
*
* @since 1.4.3.1
*/
public static function aioseop_metatags() {
// Remove Canonical URL
add_filter( 'aioseop_canonical_url', '__return_false', 10 );
$aioseop_obj = new All_in_One_SEO_Pack;
$info = $aioseop_obj->get_page_snippet_info();
$desc = $info['description'];
if( $desc ) :
echo ''. "\n";
endif;
// All In One SEO Pack Meta
do_action( 'aioseop_modules_wp_head' );
}
/**
* Jetpack
* Add/Disable Jetpack features that are not compatible with AMP.
* @link https://wordpress.org/plugins/jetpack/
*
* @since 1.4.3.1
*/
public static function amp_wp_jetpack_compatibility() {
if( class_exists( 'Jetpack' ) && !( defined( 'IS_WPCOM' ) && IS_WPCOM ) && version_compare( JETPACK__VERSION, '6.2-alpha', '<' ) ) {
if( Jetpack::is_module_active( 'stats' ) ) {
// Add Jetpack stats pixel.
add_action( 'amp_wp_template_footer', array( __class__, 'jetpack_amp_add_stats_pixel' ) );
}
// Disable Jetpack sharing.
add_filter( 'sharing_show', '__return_false', 100 );
/**
* Remove the Related Posts placeholder and headline that gets hooked into the_content
* That placeholder is useless since we can't ouput, and don't want to output Related Posts in AMP.
*/
if( class_exists( 'Jetpack_RelatedPosts' ) ) {
$jprp = Jetpack_RelatedPosts::init();
remove_filter( 'the_content', array( $jprp, 'filter_add_target_to_dom' ), 40 );
}
// Force videopress to use html5 player
add_filter( 'videopress_shortcode_options', array( __class__, 'amp_wp_videopress_enable_freedom_mode' ) );
}
}
/**
* Multi Rating plugin
* https://wordpress.org/plugins/multi-rating/
*
* @since 1.4.3.1
*/
public static function multi_rating() {
remove_filter( 'the_content', 'mr_filter_the_content', 10 );
remove_filter( 'the_title', 'mr_filter_the_title', 10 );
add_filter( 'mr_can_do_shortcode', '__return_false', 10 );
}
/**
* Add Jetpack stats pixel.
*
* @since 1.4.3.1
*/
public static function jetpack_amp_add_stats_pixel() {
if( !has_action( 'wp_footer', 'stats_footer' ) ) {
return;
}
$f = new self();
?>
tag
* that will be later converted to
*
* @since 1.4.3.1
*
* @param array $options videopress shortcode options.
* @return array videopress shortcode options with `freedom` set to true
*/
public static function amp_wp_videopress_enable_freedom_mode( $options ) {
$options['freedom'] = true;
return $options;
}
}
Amp_WP_Plugin_Compatibility::init();
/**
* Speed Booster Pack
* https://wordpress.org/plugins/speed-booster-pack/
*/
if( is_amp_wp() && !class_exists( 'Speed_Booster_Pack_Core' ) ) {
/**
* Disables plugin fucntionality by overriding "Speed_Booster_Pack_Core" class
*/
class Speed_Booster_Pack_Core{}
}