Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/accelera...
File: accelerated-moblie-pages.php
<?php
[0] Fix | Delete
/*
[1] Fix | Delete
Plugin Name: Accelerated Mobile Pages
[2] Fix | Delete
Plugin URI: https://wordpress.org/plugins/accelerated-mobile-pages/
[3] Fix | Delete
Description: AMP for WP - Accelerated Mobile Pages for WordPress
[4] Fix | Delete
Version: 1.0.96.1
[5] Fix | Delete
Author: Ahmed Kaludi, Mohammed Kaludi
[6] Fix | Delete
Author URI: https://ampforwp.com/
[7] Fix | Delete
Donate link: https://www.paypal.me/Kaludi/25
[8] Fix | Delete
License: GPL2+
[9] Fix | Delete
Text Domain: accelerated-mobile-pages
[10] Fix | Delete
Domain Path: /languages/
[11] Fix | Delete
*/
[12] Fix | Delete
[13] Fix | Delete
// Exit if accessed directly.
[14] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) exit;
[15] Fix | Delete
[16] Fix | Delete
define('AMPFORWP_PLUGIN_DIR', plugin_dir_path( __FILE__ ));
[17] Fix | Delete
define('AMPFORWP_PLUGIN_DIR_URI', plugin_dir_url(__FILE__));
[18] Fix | Delete
define('AMPFORWP_DISQUS_URL',plugin_dir_url(__FILE__).'includes/disqus.html');
[19] Fix | Delete
define('AMPFORWP_IMAGE_DIR',plugin_dir_url(__FILE__).'images');
[20] Fix | Delete
define('AMPFORWP_MAIN_PLUGIN_DIR', plugin_dir_path( __DIR__ ) );
[21] Fix | Delete
define('AMPFORWP_VERSION','1.0.96.1');
[22] Fix | Delete
define('AMPFORWP_EXTENSION_DIR',plugin_dir_path(__FILE__).'includes/options/extensions');
[23] Fix | Delete
define('AMPFORWP_ANALYTICS_URL',plugin_dir_url(__FILE__).'includes/features/analytics');
[24] Fix | Delete
if(!defined('AMPFROWP_HOST_NAME')){
[25] Fix | Delete
$urlinfo = get_bloginfo('url');
[26] Fix | Delete
$url = parse_url($urlinfo);
[27] Fix | Delete
$host = $url['host'];
[28] Fix | Delete
define('AMPFROWP_HOST_NAME', esc_attr($host));
[29] Fix | Delete
}
[30] Fix | Delete
// any changes to AMP_QUERY_VAR should be refelected here
[31] Fix | Delete
function ampforwp_generate_endpoint(){
[32] Fix | Delete
$ampforwp_slug = '';
[33] Fix | Delete
$get_permalink_structure = '';
[34] Fix | Delete
[35] Fix | Delete
$ampforwp_slug = "amp";
[36] Fix | Delete
[37] Fix | Delete
return $ampforwp_slug;
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
define('AMPFORWP_AMP_QUERY_VAR', apply_filters( 'amp_query_var', ampforwp_generate_endpoint() ) );
[41] Fix | Delete
[42] Fix | Delete
// Rewrite the Endpoints after the plugin is activate, as priority is set to 11
[43] Fix | Delete
function ampforwp_add_custom_post_support() {
[44] Fix | Delete
// Adding rewrite rules only when we are in standard mode
[45] Fix | Delete
if (is_amp_plugin_active()) {
[46] Fix | Delete
return;
[47] Fix | Delete
}
[48] Fix | Delete
global $redux_builder_amp;
[49] Fix | Delete
add_rewrite_endpoint( AMPFORWP_AMP_QUERY_VAR, EP_PAGES | EP_PERMALINK | EP_AUTHORS | EP_ALL_ARCHIVES | EP_ROOT );
[50] Fix | Delete
// Pages
[51] Fix | Delete
if ( isset($redux_builder_amp['amp-on-off-for-all-pages']) && $redux_builder_amp['amp-on-off-for-all-pages'] ) {
[52] Fix | Delete
add_post_type_support( 'page', AMPFORWP_AMP_QUERY_VAR );
[53] Fix | Delete
}
[54] Fix | Delete
// Custom Post Types
[55] Fix | Delete
if ( isset($redux_builder_amp['ampforwp-custom-type'] ) && $redux_builder_amp['ampforwp-custom-type'] ) {
[56] Fix | Delete
foreach ( $redux_builder_amp['ampforwp-custom-type'] as $custom_post ) {
[57] Fix | Delete
add_post_type_support( $custom_post, AMP_QUERY_VAR );
[58] Fix | Delete
}
[59] Fix | Delete
}
[60] Fix | Delete
}
[61] Fix | Delete
add_action( 'init', 'ampforwp_add_custom_post_support',11);
[62] Fix | Delete
[63] Fix | Delete
// Frontpage and Blog page check from reading settings.
[64] Fix | Delete
function ampforwp_name_blog_page() {
[65] Fix | Delete
if ( ! $page_for_posts = get_option('page_for_posts')) return;
[66] Fix | Delete
$page_for_posts = get_option( 'page_for_posts' );
[67] Fix | Delete
$post = get_post($page_for_posts);
[68] Fix | Delete
if ( $post ) {
[69] Fix | Delete
$slug = $post->post_name;
[70] Fix | Delete
return $slug;
[71] Fix | Delete
}
[72] Fix | Delete
}
[73] Fix | Delete
function ampforwp_custom_post_page() {
[74] Fix | Delete
$front_page_type = get_option( 'show_on_front' );
[75] Fix | Delete
if ( $front_page_type ) {
[76] Fix | Delete
return $front_page_type;
[77] Fix | Delete
}
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
function ampforwp_get_the_page_id_blog_page(){
[81] Fix | Delete
$page = "";
[82] Fix | Delete
$output = "";
[83] Fix | Delete
if ( ampforwp_name_blog_page() ) {
[84] Fix | Delete
$page = get_page_by_path( ampforwp_name_blog_page() );
[85] Fix | Delete
if( $page )
[86] Fix | Delete
$output = $page->ID;
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
return $output;
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
/**
[93] Fix | Delete
* All in One SEO Plugin Conflict
[94] Fix | Delete
* for stopping redirecting
[95] Fix | Delete
* on amp query string
[96] Fix | Delete
* @since 1.0.82
[97] Fix | Delete
*/
[98] Fix | Delete
if( in_array( 'all-in-one-seo-pack/all_in_one_seo_pack.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
[99] Fix | Delete
add_filter( 'aioseo_unrecognized_allowed_query_args', 'AMP_for_WP_QueryStringAllowed_for_AIOSEO_Plugin', -1 );
[100] Fix | Delete
function AMP_for_WP_QueryStringAllowed_for_AIOSEO_Plugin($allowedQueryArgs) {
[101] Fix | Delete
return array_merge($allowedQueryArgs, array(
[102] Fix | Delete
'nonamp',
[103] Fix | Delete
'namp',
[104] Fix | Delete
'nonamphead',
[105] Fix | Delete
));
[106] Fix | Delete
}
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
// Add Custom Rewrite Rule to make sure pagination & redirection is working correctly
[110] Fix | Delete
function ampforwp_add_custom_rewrite_rules() {
[111] Fix | Delete
[112] Fix | Delete
// Adding rewrite rules only when we are in standard mode
[113] Fix | Delete
if (is_amp_plugin_active()) {
[114] Fix | Delete
return;
[115] Fix | Delete
}
[116] Fix | Delete
global $redux_builder_amp, $wp_rewrite;
[117] Fix | Delete
// For Homepage
[118] Fix | Delete
add_rewrite_rule(
[119] Fix | Delete
'amp/?$',
[120] Fix | Delete
'index.php?amp',
[121] Fix | Delete
'top'
[122] Fix | Delete
);
[123] Fix | Delete
do_action('ampforwp_rewrite_rules_hook');
[124] Fix | Delete
// For Homepage with Pagination
[125] Fix | Delete
add_rewrite_rule(
[126] Fix | Delete
'amp/'.$wp_rewrite->pagination_base.'/([0-9]{1,})/?$',
[127] Fix | Delete
'index.php?amp=1&paged=$matches[1]',
[128] Fix | Delete
'top'
[129] Fix | Delete
);
[130] Fix | Delete
// For Pagination with index.php
[131] Fix | Delete
add_rewrite_rule(
[132] Fix | Delete
'index.php/amp/'.$wp_rewrite->pagination_base.'/([0-9]{1,})/?$',
[133] Fix | Delete
'index.php?amp=1&paged=$matches[1]',
[134] Fix | Delete
'top'
[135] Fix | Delete
);
[136] Fix | Delete
// For /Blog page with Pagination
[137] Fix | Delete
if( ampforwp_name_blog_page() ) {
[138] Fix | Delete
add_rewrite_rule(
[139] Fix | Delete
ampforwp_name_blog_page(). '/amp/'.$wp_rewrite->pagination_base.'/([0-9]{1,})/?$',
[140] Fix | Delete
'index.php?amp=1&paged=$matches[1]&page_id=' .ampforwp_get_the_page_id_blog_page(),
[141] Fix | Delete
'top'
[142] Fix | Delete
);
[143] Fix | Delete
// Pagination to work with Extensions like.hml
[144] Fix | Delete
add_rewrite_rule(
[145] Fix | Delete
ampforwp_name_blog_page(). '(.+?)/amp/'.$wp_rewrite->pagination_base.'/([0-9]{1,})/?$',
[146] Fix | Delete
'index.php?amp=1&paged=$matches[2]&page_id=' .ampforwp_get_the_page_id_blog_page(),
[147] Fix | Delete
'top'
[148] Fix | Delete
);
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
// For Author pages
[152] Fix | Delete
add_rewrite_rule(
[153] Fix | Delete
'author\/([^/]+)\/amp\/?$',
[154] Fix | Delete
'index.php?amp=1&author_name=$matches[1]',
[155] Fix | Delete
'top'
[156] Fix | Delete
);
[157] Fix | Delete
add_rewrite_rule(
[158] Fix | Delete
'author\/([^/]+)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$',
[159] Fix | Delete
'index.php?amp=1&author_name=$matches[1]&paged=$matches[2]',
[160] Fix | Delete
'top'
[161] Fix | Delete
);
[162] Fix | Delete
[163] Fix | Delete
// For category pages
[164] Fix | Delete
$rewrite_category = '';
[165] Fix | Delete
$rewrite_category = get_transient('ampforwp_category_base');
[166] Fix | Delete
[167] Fix | Delete
if ( false == $rewrite_category ) {
[168] Fix | Delete
$rewrite_category = get_option('category_base');
[169] Fix | Delete
if ( empty($rewrite_category) ) {
[170] Fix | Delete
$rewrite_category = 'category';
[171] Fix | Delete
}
[172] Fix | Delete
set_transient('ampforwp_category_base', $rewrite_category);
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
add_rewrite_rule(
[176] Fix | Delete
$rewrite_category.'\/(.+?)\/amp/?$',
[177] Fix | Delete
'index.php?amp=1&category_name=$matches[1]',
[178] Fix | Delete
'top'
[179] Fix | Delete
);
[180] Fix | Delete
// For category pages with Pagination
[181] Fix | Delete
add_rewrite_rule(
[182] Fix | Delete
$rewrite_category.'/(.+?)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$',
[183] Fix | Delete
'index.php?amp=1&category_name=$matches[1]&paged=$matches[2]',
[184] Fix | Delete
'top'
[185] Fix | Delete
);
[186] Fix | Delete
[187] Fix | Delete
// For category pages with Pagination (Custom Permalink Structure)
[188] Fix | Delete
$permalink_structure = '';
[189] Fix | Delete
$permalink_structure = get_transient('ampforwp_permalink_structure');
[190] Fix | Delete
if ( false == $permalink_structure ) {
[191] Fix | Delete
$permalink_structure = get_option('permalink_structure');
[192] Fix | Delete
set_transient('ampforwp_permalink_structure', $permalink_structure );
[193] Fix | Delete
}
[194] Fix | Delete
$permalink_structure = preg_replace('/(%.*%)/', '', $permalink_structure);
[195] Fix | Delete
$permalink_structure = preg_replace('/\//', '', $permalink_structure);
[196] Fix | Delete
if ( $permalink_structure ) {
[197] Fix | Delete
add_rewrite_rule(
[198] Fix | Delete
$permalink_structure.'\/'.$rewrite_category.'\/(.+?)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$',
[199] Fix | Delete
'index.php?amp=1&category_name=$matches[1]&paged=$matches[2]',
[200] Fix | Delete
'top'
[201] Fix | Delete
);
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
// For tag pages
[205] Fix | Delete
$rewrite_tag = '';
[206] Fix | Delete
$rewrite_tag = get_transient('ampforwp_tag_base');
[207] Fix | Delete
if ( false == $rewrite_tag ) {
[208] Fix | Delete
$rewrite_tag = get_option('tag_base');
[209] Fix | Delete
if ( empty($rewrite_tag) ) {
[210] Fix | Delete
$rewrite_tag = 'tag';
[211] Fix | Delete
}
[212] Fix | Delete
set_transient('ampforwp_tag_base',$rewrite_tag);
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
add_rewrite_rule(
[216] Fix | Delete
$rewrite_tag.'\/(.+?)\/amp/?$',
[217] Fix | Delete
'index.php?amp=1&tag=$matches[1]',
[218] Fix | Delete
'top'
[219] Fix | Delete
);
[220] Fix | Delete
// For tag pages with Pagination
[221] Fix | Delete
add_rewrite_rule(
[222] Fix | Delete
$rewrite_tag.'\/(.+?)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$',
[223] Fix | Delete
'index.php?amp=1&tag=$matches[1]&paged=$matches[2]',
[224] Fix | Delete
'top'
[225] Fix | Delete
);
[226] Fix | Delete
// For tag pages with Pagination (Custom Permalink Structure)
[227] Fix | Delete
if ( $permalink_structure ) {
[228] Fix | Delete
add_rewrite_rule(
[229] Fix | Delete
$permalink_structure.'\/'.$rewrite_tag.'\/(.+?)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$',
[230] Fix | Delete
'index.php?amp=1&tag=$matches[1]&paged=$matches[2]',
[231] Fix | Delete
'top'
[232] Fix | Delete
);
[233] Fix | Delete
}
[234] Fix | Delete
// Rewrite rule for date archive
[235] Fix | Delete
add_rewrite_rule(
[236] Fix | Delete
'([0-9]{4})/([0-9]{1,2})\/amp\/?$',
[237] Fix | Delete
'index.php?year=$matches[1]&monthnum=$matches[2]&amp=1',
[238] Fix | Delete
'top'
[239] Fix | Delete
);
[240] Fix | Delete
// Rewrite rule for date archive with pagination #2289
[241] Fix | Delete
add_rewrite_rule(
[242] Fix | Delete
'([0-9]{4})/([0-9]{1,2})/amp/'.$wp_rewrite->pagination_base.'/?([0-9]{1,})/?$',
[243] Fix | Delete
'index.php?year=$matches[1]&monthnum=$matches[2]&amp=1&paged=$matches[3]',
[244] Fix | Delete
'top'
[245] Fix | Delete
);
[246] Fix | Delete
//Rewrite rule for custom Taxonomies
[247] Fix | Delete
$taxonomies = array();
[248] Fix | Delete
if( function_exists('ampforwp_generate_taxonomies_transient')){
[249] Fix | Delete
//Rewrite rule for custom Taxonomies
[250] Fix | Delete
$taxonomies = ampforwp_generate_taxonomies_transient();
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
if(!function_exists('amp_woocommerce_pro_add_woocommerce_support') ) {
[254] Fix | Delete
if( class_exists( 'WooCommerce' ) ) {
[255] Fix | Delete
$wc_permalinks = '';
[256] Fix | Delete
$wc_permalinks = get_transient('ampforwp_woocommerce_permalinks');
[257] Fix | Delete
if( false == $wc_permalinks ) {
[258] Fix | Delete
$wc_permalinks = get_option( 'woocommerce_permalinks' );
[259] Fix | Delete
set_transient('ampforwp_woocommerce_permalinks', $wc_permalinks);
[260] Fix | Delete
}
[261] Fix | Delete
if ( $wc_permalinks && !empty( $taxonomies) ) {
[262] Fix | Delete
$taxonomies = array_merge($taxonomies, $wc_permalinks);
[263] Fix | Delete
}
[264] Fix | Delete
}
[265] Fix | Delete
}
[266] Fix | Delete
$post_types = ampforwp_get_all_post_types();
[267] Fix | Delete
if ( $post_types ) {
[268] Fix | Delete
foreach ($post_types as $post_type ) {
[269] Fix | Delete
if ( 'post' != $post_type && 'page' != $post_type ){
[270] Fix | Delete
add_rewrite_rule(
[271] Fix | Delete
$post_type.'\/amp/?$',
[272] Fix | Delete
'index.php?amp&post_type='.$post_type,
[273] Fix | Delete
'top'
[274] Fix | Delete
);
[275] Fix | Delete
if ( class_exists( 'Lsvr_Permalink_Settings_Knowledge_Base' ) ) {
[276] Fix | Delete
$lsvr_value = get_post_type_archive_link( 'lsvr_kba' );
[277] Fix | Delete
$lsvr_value = explode("/",$lsvr_value);
[278] Fix | Delete
$lsvr_value = array_filter($lsvr_value);
[279] Fix | Delete
$lsvr_value = end($lsvr_value);
[280] Fix | Delete
add_rewrite_rule(
[281] Fix | Delete
$lsvr_value.'\/amp/?$',
[282] Fix | Delete
'index.php?amp&post_type='.$post_type,
[283] Fix | Delete
'top'
[284] Fix | Delete
);
[285] Fix | Delete
}
[286] Fix | Delete
add_rewrite_rule(
[287] Fix | Delete
$post_type.'\/(.+?)\/amp\/?$',
[288] Fix | Delete
'index.php?amp&'.$post_type.'=$matches[1]',
[289] Fix | Delete
'top'
[290] Fix | Delete
);
[291] Fix | Delete
add_rewrite_rule(
[292] Fix | Delete
$post_type.'\/(.+?)\/amp\/?$',
[293] Fix | Delete
'index.php?amp&'.$post_type.'=$matches[1]',
[294] Fix | Delete
'top'
[295] Fix | Delete
);
[296] Fix | Delete
add_rewrite_rule(
[297] Fix | Delete
$post_type.'\/amp/'.$wp_rewrite->pagination_base.'/([0-9]{1,})/?$',
[298] Fix | Delete
'index.php?amp=1&post_type='.$post_type.'&paged=$matches[1]',
[299] Fix | Delete
'top'
[300] Fix | Delete
);
[301] Fix | Delete
}
[302] Fix | Delete
}
[303] Fix | Delete
}
[304] Fix | Delete
[305] Fix | Delete
$taxonomies = apply_filters( 'ampforwp_modify_rewrite_tax', $taxonomies );
[306] Fix | Delete
if ( $taxonomies ) {
[307] Fix | Delete
$taxonomySlug = '';
[308] Fix | Delete
foreach ( $taxonomies as $taxonomyName => $taxonomyLabel ) {
[309] Fix | Delete
$taxonomies = get_taxonomy( $taxonomyName );
[310] Fix | Delete
if(isset($taxonomies->rewrite['slug']) && !empty($taxonomies->rewrite['slug']) ){
[311] Fix | Delete
$taxonomySlug = $taxonomies->rewrite['slug'];
[312] Fix | Delete
}else{
[313] Fix | Delete
$taxonomySlug = $taxonomyName;
[314] Fix | Delete
}
[315] Fix | Delete
if ( ! empty( $taxonomySlug ) ) {
[316] Fix | Delete
add_rewrite_rule(
[317] Fix | Delete
$taxonomySlug.'\/([^/]+)\/amp/?$',
[318] Fix | Delete
'index.php?amp&'.$taxonomyName.'=$matches[1]',
[319] Fix | Delete
'top'
[320] Fix | Delete
);
[321] Fix | Delete
// For Custom Taxonomies with pages
[322] Fix | Delete
add_rewrite_rule(
[323] Fix | Delete
$taxonomySlug.'\/([^/]+)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$',
[324] Fix | Delete
'index.php?amp&'.$taxonomyName.'=$matches[1]&paged=$matches[2]',
[325] Fix | Delete
'top'
[326] Fix | Delete
);
[327] Fix | Delete
}
[328] Fix | Delete
}
[329] Fix | Delete
}
[330] Fix | Delete
if (ampforwp_get_setting('ampforwp-pagination-link-type')) {
[331] Fix | Delete
add_rewrite_rule(
[332] Fix | Delete
'(.+?)-[0-9]+\/([0-9]{1,})\/amp$',
[333] Fix | Delete
'index.php?amp=1&name=$matches[1]&paged=$matches[2]',
[334] Fix | Delete
'top'
[335] Fix | Delete
);
[336] Fix | Delete
add_rewrite_rule(
[337] Fix | Delete
'(.+?)\/([0-9]{1,})\/amp$',
[338] Fix | Delete
'index.php?amp=1&name=$matches[1]&paged=$matches[2]',
[339] Fix | Delete
'top'
[340] Fix | Delete
);
[341] Fix | Delete
}
[342] Fix | Delete
}
[343] Fix | Delete
add_action( 'init', 'ampforwp_add_custom_rewrite_rules', 25 );
[344] Fix | Delete
// Delete category_base transient when it is updated #2924
[345] Fix | Delete
add_action('update_option_category_base', 'ampforwp_update_option_category_base');
[346] Fix | Delete
function ampforwp_update_option_category_base(){
[347] Fix | Delete
delete_transient('ampforwp_category_base');
[348] Fix | Delete
}
[349] Fix | Delete
// Delete category_base transient when it is updated #2924
[350] Fix | Delete
add_action('update_option_tag_base', 'ampforwp_update_option_tag_base');
[351] Fix | Delete
function ampforwp_update_option_tag_base(){
[352] Fix | Delete
delete_transient('ampforwp_tag_base');
[353] Fix | Delete
}
[354] Fix | Delete
// Delete permalink_structure transient when it is updated #2924
[355] Fix | Delete
add_action('update_option_permalink_structure', 'ampforwp_update_option_permalink_structure');
[356] Fix | Delete
function ampforwp_update_option_permalink_structure(){
[357] Fix | Delete
delete_transient('ampforwp_permalink_structure');
[358] Fix | Delete
// Delete ampforwp_woocommerce_permalinks transient when it is updated #2924
[359] Fix | Delete
if( class_exists( 'WooCommerce' ) ) {
[360] Fix | Delete
delete_transient('ampforwp_woocommerce_permalinks');
[361] Fix | Delete
}
[362] Fix | Delete
}
[363] Fix | Delete
// add re-write rule for Products
[364] Fix | Delete
add_action( 'init', 'ampforwp_custom_rewrite_rules_for_product_category' );
[365] Fix | Delete
if ( ! function_exists('ampforwp_custom_rewrite_rules_for_product_category') ) {
[366] Fix | Delete
function ampforwp_custom_rewrite_rules_for_product_category(){
[367] Fix | Delete
[368] Fix | Delete
// Adding rewrite rules only when we are in standard mode
[369] Fix | Delete
if (is_amp_plugin_active()) {
[370] Fix | Delete
return;
[371] Fix | Delete
}
[372] Fix | Delete
if ( class_exists('WooCommerce') ) {
[373] Fix | Delete
$permalinks = wp_parse_args( (array) get_option( 'woocommerce_permalinks', array() ), array(
[374] Fix | Delete
'product_base' => '',
[375] Fix | Delete
'category_base' => '',
[376] Fix | Delete
'tag_base' => '',
[377] Fix | Delete
'attribute_base' => '',
[378] Fix | Delete
'use_verbose_page_rules' => false,
[379] Fix | Delete
) );
[380] Fix | Delete
// Ensure rewrite slugs are set.
[381] Fix | Delete
$permalinks['product_rewrite_slug'] = untrailingslashit( empty( $permalinks['product_base'] ) ? _x( 'product', 'slug', 'accelerated-mobile-pages' ) : $permalinks['product_base'] );
[382] Fix | Delete
$permalinks['category_rewrite_slug'] = untrailingslashit( empty( $permalinks['category_base'] ) ? _x( 'product-category', 'slug', 'accelerated-mobile-pages' ) : $permalinks['category_base'] );
[383] Fix | Delete
$permalinks['tag_rewrite_slug'] = untrailingslashit( empty( $permalinks['tag_base'] ) ? _x( 'product-tag', 'slug', 'accelerated-mobile-pages' ) : $permalinks['tag_base'] );
[384] Fix | Delete
$permalinks['attribute_rewrite_slug'] = untrailingslashit( empty( $permalinks['attribute_base'] ) ? '' : $permalinks['attribute_base'] );
[385] Fix | Delete
[386] Fix | Delete
[387] Fix | Delete
[388] Fix | Delete
add_rewrite_rule(
[389] Fix | Delete
$permalinks['product_rewrite_slug']."\/amp\/page\/([0-9]{1,})/?$",
[390] Fix | Delete
'index.php?post_type=product&paged=$matches[1]&amp=1',
[391] Fix | Delete
'top'
[392] Fix | Delete
);
[393] Fix | Delete
add_rewrite_rule(
[394] Fix | Delete
$permalinks['category_rewrite_slug'].'\/(.+?)\/amp\/page\/?([0-9]{1,})/?$',
[395] Fix | Delete
'index.php?product_cat=$matches[1]&paged=$matches[2]&amp=1',
[396] Fix | Delete
'top'
[397] Fix | Delete
);
[398] Fix | Delete
add_rewrite_rule(
[399] Fix | Delete
$permalinks['category_rewrite_slug'].'\/(.+?)\/amp\/?$',
[400] Fix | Delete
'index.php?amp&product_cat=$matches[1]',
[401] Fix | Delete
'top'
[402] Fix | Delete
);
[403] Fix | Delete
add_rewrite_rule(
[404] Fix | Delete
'^'.$permalinks['category_rewrite_slug'].'\/(.+?)\/([^\/]+)\/amp\/?$',
[405] Fix | Delete
'index.php?amp&product_cat=$matches[2]',
[406] Fix | Delete
'top'
[407] Fix | Delete
);
[408] Fix | Delete
[409] Fix | Delete
[410] Fix | Delete
add_rewrite_rule(
[411] Fix | Delete
$permalinks['tag_rewrite_slug'].'\/(.+?)\/amp\/page\/?([0-9]{1,})/?$',
[412] Fix | Delete
'index.php?product_tag=$matches[1]&paged=$matches[2]&amp=1',
[413] Fix | Delete
'top'
[414] Fix | Delete
);
[415] Fix | Delete
add_rewrite_rule(
[416] Fix | Delete
$permalinks['tag_rewrite_slug'].'\/(.+?)\/amp\/?$',
[417] Fix | Delete
'index.php?amp&product_tag=$matches[1]',
[418] Fix | Delete
'top'
[419] Fix | Delete
);
[420] Fix | Delete
}
[421] Fix | Delete
}
[422] Fix | Delete
}
[423] Fix | Delete
[424] Fix | Delete
function ampforwp_plugin_info(){
[425] Fix | Delete
$data = array();
[426] Fix | Delete
$date = new DateTime();
[427] Fix | Delete
$data = array('activation_data' => $date->getTimestamp() );
[428] Fix | Delete
add_option( 'ampforwp_plugin_info', $data );
[429] Fix | Delete
}
[430] Fix | Delete
add_action('upgrader_process_complete','ampforwp_plugin_info' );
[431] Fix | Delete
[432] Fix | Delete
register_activation_hook( __FILE__, 'ampforwp_rewrite_activation', 20 );
[433] Fix | Delete
function ampforwp_rewrite_activation() {
[434] Fix | Delete
[435] Fix | Delete
if ( ! did_action( 'ampforwp_init' ) ) {
[436] Fix | Delete
ampforwp_init();
[437] Fix | Delete
}
[438] Fix | Delete
[439] Fix | Delete
flush_rewrite_rules();
[440] Fix | Delete
[441] Fix | Delete
ampforwp_add_custom_post_support();
[442] Fix | Delete
ampforwp_add_custom_rewrite_rules();
[443] Fix | Delete
ampforwp_plugin_info();
[444] Fix | Delete
[445] Fix | Delete
// Flushing rewrite urls ONLY on activation
[446] Fix | Delete
global $wp_rewrite;
[447] Fix | Delete
$wp_rewrite->flush_rules();
[448] Fix | Delete
[449] Fix | Delete
delete_option('ampforwp_rewrite_flush_option');
[450] Fix | Delete
[451] Fix | Delete
// Set transient for Welcome page
[452] Fix | Delete
set_transient( 'ampforwp_welcome_screen_activation_redirect', true, 30 );
[453] Fix | Delete
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
add_action( 'admin_init', 'ampforwp_flush_after_update');
[457] Fix | Delete
function ampforwp_flush_after_update() {
[458] Fix | Delete
// Flushing rewrite urls ONLY on after Update is installed
[459] Fix | Delete
$older_version = "";
[460] Fix | Delete
$older_version = get_transient('ampforwp_current_version_check');
[461] Fix | Delete
if ( empty($older_version) || ( $older_version < AMPFORWP_VERSION ) ) {
[462] Fix | Delete
flush_rewrite_rules();
[463] Fix | Delete
global $wp_rewrite;
[464] Fix | Delete
$wp_rewrite->flush_rules();
[465] Fix | Delete
set_transient('ampforwp_current_version_check', AMPFORWP_VERSION);
[466] Fix | Delete
}
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
[470] Fix | Delete
add_action('init', 'ampforwp_flush_rewrite_by_option', 20);
[471] Fix | Delete
[472] Fix | Delete
function ampforwp_flush_rewrite_by_option(){
[473] Fix | Delete
[474] Fix | Delete
global $wp_rewrite;
[475] Fix | Delete
$get_current_permalink_settings = "";
[476] Fix | Delete
[477] Fix | Delete
$get_current_permalink_settings = get_option('ampforwp_rewrite_flush_option');
[478] Fix | Delete
[479] Fix | Delete
if ( $get_current_permalink_settings ) {
[480] Fix | Delete
return;
[481] Fix | Delete
}
[482] Fix | Delete
// Adding double check to make sure, we are not updating and calling database unnecessarily
[483] Fix | Delete
if ( empty( $get_current_permalink_settings ) ) {
[484] Fix | Delete
$wp_rewrite->flush_rules();
[485] Fix | Delete
update_option('ampforwp_rewrite_flush_option', 'true', false);
[486] Fix | Delete
}
[487] Fix | Delete
[488] Fix | Delete
}
[489] Fix | Delete
[490] Fix | Delete
register_deactivation_hook( __FILE__, 'ampforwp_rewrite_deactivate', 20 );
[491] Fix | Delete
function ampforwp_rewrite_deactivate() {
[492] Fix | Delete
// Flushing rewrite urls ONLY on deactivation
[493] Fix | Delete
global $wp_rewrite;
[494] Fix | Delete
[495] Fix | Delete
foreach ( $wp_rewrite->endpoints as $index => $endpoint ) {
[496] Fix | Delete
if ( AMP_QUERY_VAR === $endpoint[1] ) {
[497] Fix | Delete
unset( $wp_rewrite->endpoints[ $index ] );
[498] Fix | Delete
break;
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function