: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
Plugin Name: Accelerated Mobile Pages
Plugin URI: https://wordpress.org/plugins/accelerated-mobile-pages/
Description: AMP for WP - Accelerated Mobile Pages for WordPress
Author: Ahmed Kaludi, Mohammed Kaludi
Author URI: https://ampforwp.com/
Donate link: https://www.paypal.me/Kaludi/25
Text Domain: accelerated-mobile-pages
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
define('AMPFORWP_PLUGIN_DIR', plugin_dir_path( __FILE__ ));
define('AMPFORWP_PLUGIN_DIR_URI', plugin_dir_url(__FILE__));
define('AMPFORWP_DISQUS_URL',plugin_dir_url(__FILE__).'includes/disqus.html');
define('AMPFORWP_IMAGE_DIR',plugin_dir_url(__FILE__).'images');
define('AMPFORWP_MAIN_PLUGIN_DIR', plugin_dir_path( __DIR__ ) );
define('AMPFORWP_VERSION','1.0.96.1');
define('AMPFORWP_EXTENSION_DIR',plugin_dir_path(__FILE__).'includes/options/extensions');
define('AMPFORWP_ANALYTICS_URL',plugin_dir_url(__FILE__).'includes/features/analytics');
if(!defined('AMPFROWP_HOST_NAME')){
$urlinfo = get_bloginfo('url');
$url = parse_url($urlinfo);
define('AMPFROWP_HOST_NAME', esc_attr($host));
// any changes to AMP_QUERY_VAR should be refelected here
function ampforwp_generate_endpoint(){
$get_permalink_structure = '';
define('AMPFORWP_AMP_QUERY_VAR', apply_filters( 'amp_query_var', ampforwp_generate_endpoint() ) );
// Rewrite the Endpoints after the plugin is activate, as priority is set to 11
function ampforwp_add_custom_post_support() {
// Adding rewrite rules only when we are in standard mode
if (is_amp_plugin_active()) {
global $redux_builder_amp;
add_rewrite_endpoint( AMPFORWP_AMP_QUERY_VAR, EP_PAGES | EP_PERMALINK | EP_AUTHORS | EP_ALL_ARCHIVES | EP_ROOT );
if ( isset($redux_builder_amp['amp-on-off-for-all-pages']) && $redux_builder_amp['amp-on-off-for-all-pages'] ) {
add_post_type_support( 'page', AMPFORWP_AMP_QUERY_VAR );
if ( isset($redux_builder_amp['ampforwp-custom-type'] ) && $redux_builder_amp['ampforwp-custom-type'] ) {
foreach ( $redux_builder_amp['ampforwp-custom-type'] as $custom_post ) {
add_post_type_support( $custom_post, AMP_QUERY_VAR );
add_action( 'init', 'ampforwp_add_custom_post_support',11);
// Frontpage and Blog page check from reading settings.
function ampforwp_name_blog_page() {
if ( ! $page_for_posts = get_option('page_for_posts')) return;
$page_for_posts = get_option( 'page_for_posts' );
$post = get_post($page_for_posts);
$slug = $post->post_name;
function ampforwp_custom_post_page() {
$front_page_type = get_option( 'show_on_front' );
if ( $front_page_type ) {
function ampforwp_get_the_page_id_blog_page(){
if ( ampforwp_name_blog_page() ) {
$page = get_page_by_path( ampforwp_name_blog_page() );
* All in One SEO Plugin Conflict
* for stopping redirecting
if( in_array( 'all-in-one-seo-pack/all_in_one_seo_pack.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
add_filter( 'aioseo_unrecognized_allowed_query_args', 'AMP_for_WP_QueryStringAllowed_for_AIOSEO_Plugin', -1 );
function AMP_for_WP_QueryStringAllowed_for_AIOSEO_Plugin($allowedQueryArgs) {
return array_merge($allowedQueryArgs, array(
// Add Custom Rewrite Rule to make sure pagination & redirection is working correctly
function ampforwp_add_custom_rewrite_rules() {
// Adding rewrite rules only when we are in standard mode
if (is_amp_plugin_active()) {
global $redux_builder_amp, $wp_rewrite;
do_action('ampforwp_rewrite_rules_hook');
// For Homepage with Pagination
'amp/'.$wp_rewrite->pagination_base.'/([0-9]{1,})/?$',
'index.php?amp=1&paged=$matches[1]',
// For Pagination with index.php
'index.php/amp/'.$wp_rewrite->pagination_base.'/([0-9]{1,})/?$',
'index.php?amp=1&paged=$matches[1]',
// For /Blog page with Pagination
if( ampforwp_name_blog_page() ) {
ampforwp_name_blog_page(). '/amp/'.$wp_rewrite->pagination_base.'/([0-9]{1,})/?$',
'index.php?amp=1&paged=$matches[1]&page_id=' .ampforwp_get_the_page_id_blog_page(),
// Pagination to work with Extensions like.hml
ampforwp_name_blog_page(). '(.+?)/amp/'.$wp_rewrite->pagination_base.'/([0-9]{1,})/?$',
'index.php?amp=1&paged=$matches[2]&page_id=' .ampforwp_get_the_page_id_blog_page(),
'author\/([^/]+)\/amp\/?$',
'index.php?amp=1&author_name=$matches[1]',
'author\/([^/]+)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$',
'index.php?amp=1&author_name=$matches[1]&paged=$matches[2]',
$rewrite_category = get_transient('ampforwp_category_base');
if ( false == $rewrite_category ) {
$rewrite_category = get_option('category_base');
if ( empty($rewrite_category) ) {
$rewrite_category = 'category';
set_transient('ampforwp_category_base', $rewrite_category);
$rewrite_category.'\/(.+?)\/amp/?$',
'index.php?amp=1&category_name=$matches[1]',
// For category pages with Pagination
$rewrite_category.'/(.+?)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$',
'index.php?amp=1&category_name=$matches[1]&paged=$matches[2]',
// For category pages with Pagination (Custom Permalink Structure)
$permalink_structure = '';
$permalink_structure = get_transient('ampforwp_permalink_structure');
if ( false == $permalink_structure ) {
$permalink_structure = get_option('permalink_structure');
set_transient('ampforwp_permalink_structure', $permalink_structure );
$permalink_structure = preg_replace('/(%.*%)/', '', $permalink_structure);
$permalink_structure = preg_replace('/\//', '', $permalink_structure);
if ( $permalink_structure ) {
$permalink_structure.'\/'.$rewrite_category.'\/(.+?)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$',
'index.php?amp=1&category_name=$matches[1]&paged=$matches[2]',
$rewrite_tag = get_transient('ampforwp_tag_base');
if ( false == $rewrite_tag ) {
$rewrite_tag = get_option('tag_base');
if ( empty($rewrite_tag) ) {
set_transient('ampforwp_tag_base',$rewrite_tag);
$rewrite_tag.'\/(.+?)\/amp/?$',
'index.php?amp=1&tag=$matches[1]',
// For tag pages with Pagination
$rewrite_tag.'\/(.+?)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$',
'index.php?amp=1&tag=$matches[1]&paged=$matches[2]',
// For tag pages with Pagination (Custom Permalink Structure)
if ( $permalink_structure ) {
$permalink_structure.'\/'.$rewrite_tag.'\/(.+?)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$',
'index.php?amp=1&tag=$matches[1]&paged=$matches[2]',
// Rewrite rule for date archive
'([0-9]{4})/([0-9]{1,2})\/amp\/?$',
'index.php?year=$matches[1]&monthnum=$matches[2]&=1',
// Rewrite rule for date archive with pagination #2289
'([0-9]{4})/([0-9]{1,2})/amp/'.$wp_rewrite->pagination_base.'/?([0-9]{1,})/?$',
'index.php?year=$matches[1]&monthnum=$matches[2]&=1&paged=$matches[3]',
//Rewrite rule for custom Taxonomies
if( function_exists('ampforwp_generate_taxonomies_transient')){
//Rewrite rule for custom Taxonomies
$taxonomies = ampforwp_generate_taxonomies_transient();
if(!function_exists('amp_woocommerce_pro_add_woocommerce_support') ) {
if( class_exists( 'WooCommerce' ) ) {
$wc_permalinks = get_transient('ampforwp_woocommerce_permalinks');
if( false == $wc_permalinks ) {
$wc_permalinks = get_option( 'woocommerce_permalinks' );
set_transient('ampforwp_woocommerce_permalinks', $wc_permalinks);
if ( $wc_permalinks && !empty( $taxonomies) ) {
$taxonomies = array_merge($taxonomies, $wc_permalinks);
$post_types = ampforwp_get_all_post_types();
foreach ($post_types as $post_type ) {
if ( 'post' != $post_type && 'page' != $post_type ){
'index.php?amp&post_type='.$post_type,
if ( class_exists( 'Lsvr_Permalink_Settings_Knowledge_Base' ) ) {
$lsvr_value = get_post_type_archive_link( 'lsvr_kba' );
$lsvr_value = explode("/",$lsvr_value);
$lsvr_value = array_filter($lsvr_value);
$lsvr_value = end($lsvr_value);
'index.php?amp&post_type='.$post_type,
$post_type.'\/(.+?)\/amp\/?$',
'index.php?amp&'.$post_type.'=$matches[1]',
$post_type.'\/(.+?)\/amp\/?$',
'index.php?amp&'.$post_type.'=$matches[1]',
$post_type.'\/amp/'.$wp_rewrite->pagination_base.'/([0-9]{1,})/?$',
'index.php?amp=1&post_type='.$post_type.'&paged=$matches[1]',
$taxonomies = apply_filters( 'ampforwp_modify_rewrite_tax', $taxonomies );
foreach ( $taxonomies as $taxonomyName => $taxonomyLabel ) {
$taxonomies = get_taxonomy( $taxonomyName );
if(isset($taxonomies->rewrite['slug']) && !empty($taxonomies->rewrite['slug']) ){
$taxonomySlug = $taxonomies->rewrite['slug'];
$taxonomySlug = $taxonomyName;
if ( ! empty( $taxonomySlug ) ) {
$taxonomySlug.'\/([^/]+)\/amp/?$',
'index.php?amp&'.$taxonomyName.'=$matches[1]',
// For Custom Taxonomies with pages
$taxonomySlug.'\/([^/]+)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$',
'index.php?amp&'.$taxonomyName.'=$matches[1]&paged=$matches[2]',
if (ampforwp_get_setting('ampforwp-pagination-link-type')) {
'(.+?)-[0-9]+\/([0-9]{1,})\/amp$',
'index.php?amp=1&name=$matches[1]&paged=$matches[2]',
'(.+?)\/([0-9]{1,})\/amp$',
'index.php?amp=1&name=$matches[1]&paged=$matches[2]',
add_action( 'init', 'ampforwp_add_custom_rewrite_rules', 25 );
// Delete category_base transient when it is updated #2924
add_action('update_option_category_base', 'ampforwp_update_option_category_base');
function ampforwp_update_option_category_base(){
delete_transient('ampforwp_category_base');
// Delete category_base transient when it is updated #2924
add_action('update_option_tag_base', 'ampforwp_update_option_tag_base');
function ampforwp_update_option_tag_base(){
delete_transient('ampforwp_tag_base');
// Delete permalink_structure transient when it is updated #2924
add_action('update_option_permalink_structure', 'ampforwp_update_option_permalink_structure');
function ampforwp_update_option_permalink_structure(){
delete_transient('ampforwp_permalink_structure');
// Delete ampforwp_woocommerce_permalinks transient when it is updated #2924
if( class_exists( 'WooCommerce' ) ) {
delete_transient('ampforwp_woocommerce_permalinks');
// add re-write rule for Products
add_action( 'init', 'ampforwp_custom_rewrite_rules_for_product_category' );
if ( ! function_exists('ampforwp_custom_rewrite_rules_for_product_category') ) {
function ampforwp_custom_rewrite_rules_for_product_category(){
// Adding rewrite rules only when we are in standard mode
if (is_amp_plugin_active()) {
if ( class_exists('WooCommerce') ) {
$permalinks = wp_parse_args( (array) get_option( 'woocommerce_permalinks', array() ), array(
'use_verbose_page_rules' => false,
// Ensure rewrite slugs are set.
$permalinks['product_rewrite_slug'] = untrailingslashit( empty( $permalinks['product_base'] ) ? _x( 'product', 'slug', 'accelerated-mobile-pages' ) : $permalinks['product_base'] );
$permalinks['category_rewrite_slug'] = untrailingslashit( empty( $permalinks['category_base'] ) ? _x( 'product-category', 'slug', 'accelerated-mobile-pages' ) : $permalinks['category_base'] );
$permalinks['tag_rewrite_slug'] = untrailingslashit( empty( $permalinks['tag_base'] ) ? _x( 'product-tag', 'slug', 'accelerated-mobile-pages' ) : $permalinks['tag_base'] );
$permalinks['attribute_rewrite_slug'] = untrailingslashit( empty( $permalinks['attribute_base'] ) ? '' : $permalinks['attribute_base'] );
$permalinks['product_rewrite_slug']."\/amp\/page\/([0-9]{1,})/?$",
'index.php?post_type=product&paged=$matches[1]&=1',
$permalinks['category_rewrite_slug'].'\/(.+?)\/amp\/page\/?([0-9]{1,})/?$',
'index.php?product_cat=$matches[1]&paged=$matches[2]&=1',
$permalinks['category_rewrite_slug'].'\/(.+?)\/amp\/?$',
'index.php?amp&product_cat=$matches[1]',
'^'.$permalinks['category_rewrite_slug'].'\/(.+?)\/([^\/]+)\/amp\/?$',
'index.php?amp&product_cat=$matches[2]',
$permalinks['tag_rewrite_slug'].'\/(.+?)\/amp\/page\/?([0-9]{1,})/?$',
'index.php?product_tag=$matches[1]&paged=$matches[2]&=1',
$permalinks['tag_rewrite_slug'].'\/(.+?)\/amp\/?$',
'index.php?amp&product_tag=$matches[1]',
function ampforwp_plugin_info(){
$data = array('activation_data' => $date->getTimestamp() );
add_option( 'ampforwp_plugin_info', $data );
add_action('upgrader_process_complete','ampforwp_plugin_info' );
register_activation_hook( __FILE__, 'ampforwp_rewrite_activation', 20 );
function ampforwp_rewrite_activation() {
if ( ! did_action( 'ampforwp_init' ) ) {
ampforwp_add_custom_post_support();
ampforwp_add_custom_rewrite_rules();
// Flushing rewrite urls ONLY on activation
$wp_rewrite->flush_rules();
delete_option('ampforwp_rewrite_flush_option');
// Set transient for Welcome page
set_transient( 'ampforwp_welcome_screen_activation_redirect', true, 30 );
add_action( 'admin_init', 'ampforwp_flush_after_update');
function ampforwp_flush_after_update() {
// Flushing rewrite urls ONLY on after Update is installed
$older_version = get_transient('ampforwp_current_version_check');
if ( empty($older_version) || ( $older_version < AMPFORWP_VERSION ) ) {
$wp_rewrite->flush_rules();
set_transient('ampforwp_current_version_check', AMPFORWP_VERSION);
add_action('init', 'ampforwp_flush_rewrite_by_option', 20);
function ampforwp_flush_rewrite_by_option(){
$get_current_permalink_settings = "";
$get_current_permalink_settings = get_option('ampforwp_rewrite_flush_option');
if ( $get_current_permalink_settings ) {
// Adding double check to make sure, we are not updating and calling database unnecessarily
if ( empty( $get_current_permalink_settings ) ) {
$wp_rewrite->flush_rules();
update_option('ampforwp_rewrite_flush_option', 'true', false);
register_deactivation_hook( __FILE__, 'ampforwp_rewrite_deactivate', 20 );
function ampforwp_rewrite_deactivate() {
// Flushing rewrite urls ONLY on deactivation
foreach ( $wp_rewrite->endpoints as $index => $endpoint ) {
if ( AMP_QUERY_VAR === $endpoint[1] ) {
unset( $wp_rewrite->endpoints[ $index ] );