post_name; return $slug; } } function ampforwp_custom_post_page() { $front_page_type = get_option( 'show_on_front' ); if ( $front_page_type ) { return $front_page_type; } } function ampforwp_get_the_page_id_blog_page(){ $page = ""; $output = ""; if ( ampforwp_name_blog_page() ) { $page = get_page_by_path( ampforwp_name_blog_page() ); $output = $page->ID; } return $output; } // Add Custom Rewrite Rule to make sure pagination & redirection is working correctly function ampforwp_add_custom_rewrite_rules() { global $redux_builder_amp; // For Homepage add_rewrite_rule( 'amp/?$', 'index.php?amp', 'top' ); // For Homepage with Pagination add_rewrite_rule( 'amp/page/([0-9]{1,})/?$', 'index.php?amp&paged=$matches[1]', 'top' ); // For /Blog page with Pagination //if ( ampforwp_custom_post_page() && ampforwp_name_blog_page() ) { add_rewrite_rule( ampforwp_name_blog_page(). '/amp/page/([0-9]{1,})/?$', 'index.php?amp&paged=$matches[1]&page_id=' .ampforwp_get_the_page_id_blog_page(), 'top' ); //} // For Author pages add_rewrite_rule( 'author\/([^/]+)\/amp\/?$', 'index.php?amp&author_name=$matches[1]', 'top' ); add_rewrite_rule( 'author\/([^/]+)\/amp\/page\/?([0-9]{1,})\/?$', 'index.php?amp=1&author_name=$matches[1]&paged=$matches[2]', 'top' ); // For category pages $rewrite_category = get_option('category_base'); if (! empty($rewrite_category)) { $rewrite_category = get_option('category_base'); } else { $rewrite_category = 'category'; } add_rewrite_rule( $rewrite_category.'\/(.+?)\/amp/?$', 'index.php?amp&category_name=$matches[1]', 'top' ); // For category pages with Pagination add_rewrite_rule( $rewrite_category.'\/(.+?)\/amp\/page\/?([0-9]{1,})\/?$', 'index.php?amp&category_name=$matches[1]&paged=$matches[2]', 'top' ); // For tag pages $rewrite_tag = get_option('tag_base'); if (! empty($rewrite_tag)) { $rewrite_tag = get_option('tag_base'); } else { $rewrite_tag = 'tag'; } add_rewrite_rule( $rewrite_tag.'\/(.+?)\/amp/?$', 'index.php?amp&tag=$matches[1]', 'top' ); // For tag pages with Pagination add_rewrite_rule( $rewrite_tag.'\/(.+?)\/amp\/page\/?([0-9]{1,})\/?$', 'index.php?amp&tag=$matches[1]&paged=$matches[2]', 'top' ); //Rewrite rule for custom Taxonomies $args = array( 'public' => true, '_builtin' => false ); $output = 'names'; // or objects $operator = 'and'; // 'and' or 'or' $taxonomies = get_taxonomies( $args, $output, $operator ); if ( $taxonomies ) { foreach ( $taxonomies as $taxonomy ) { add_rewrite_rule( $taxonomy.'\/(.+?)\/amp/?$', 'index.php?amp&'.$taxonomy.'=$matches[1]', 'top' ); // For Custom Taxonomies with pages add_rewrite_rule( $taxonomy.'\/(.+?)\/amp\/page\/?([0-9]{1,})\/?$', 'index.php?amp&'.$taxonomy.'=$matches[1]&paged=$matches[2]', 'top' ); } } // For OneSignal if(isset($redux_builder_amp['ampforwp-web-push-onesignal']) && $redux_builder_amp['ampforwp-web-push-onesignal'] ){ add_rewrite_rule('OneSignalSDKWorker.js','wp-content/plugins/accelerated-mobile-pages/includes/onesignal-integration/OneSignalSDKWorker.js','top'); } } add_action( 'init', 'ampforwp_add_custom_rewrite_rules' ); register_activation_hook( __FILE__, 'ampforwp_rewrite_activation', 20 ); function ampforwp_rewrite_activation() { // Run AMP deactivation code while activation ampforwp_deactivate_amp_plugin(); if ( ! did_action( 'ampforwp_init' ) ) { ampforwp_init(); } flush_rewrite_rules(); ampforwp_add_custom_post_support(); ampforwp_add_custom_rewrite_rules(); // Flushing rewrite urls ONLY on activation global $wp_rewrite; $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('init', 'ampforwp_flush_rewrite_by_option', 20); function ampforwp_flush_rewrite_by_option(){ global $wp_rewrite; $get_current_permalink_settings = ""; $get_current_permalink_settings = get_option('ampforwp_rewrite_flush_option'); if ( $get_current_permalink_settings ) { return; } // 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'); } } register_deactivation_hook( __FILE__, 'ampforwp_rewrite_deactivate', 20 ); function ampforwp_rewrite_deactivate() { // Flushing rewrite urls ONLY on deactivation global $wp_rewrite; foreach ( $wp_rewrite->endpoints as $index => $endpoint ) { if ( AMP_QUERY_VAR === $endpoint[1] ) { unset( $wp_rewrite->endpoints[ $index ] ); break; } } flush_rewrite_rules(); $wp_rewrite->flush_rules(); // Remove transient for Welcome page delete_transient( 'ampforwp_welcome_screen_activation_redirect'); } add_action( 'admin_init','ampforwp_parent_plugin_check'); function ampforwp_parent_plugin_check() { include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); $amp_plugin_activation_check = is_plugin_active( 'amp/amp.php' ); if ( $amp_plugin_activation_check ) { // set_transient( 'ampforwp_parent_plugin_check', true, 30 ); } else { delete_option( 'ampforwp_parent_plugin_check'); } } // Redux panel inclusion code if ( !class_exists( 'ReduxFramework' ) ) { require_once dirname( __FILE__ ).'/includes/options/extensions/loader.php'; require_once dirname( __FILE__ ).'/includes/options/redux-core/framework.php'; } // Register all the main options require_once dirname( __FILE__ ).'/includes/options/admin-config.php'; require_once dirname( __FILE__ ).'/templates/report-bugs.php'; // Modules add_action('after_setup_theme','ampforwp_add_module_files'); function ampforwp_add_module_files() { global $redux_builder_amp; if ( isset($redux_builder_amp['ampforwp-content-builder']) && $redux_builder_amp['ampforwp-content-builder'] ) { if ( ! function_exists( 'bstw' ) ) { require_once AMPFORWP_PLUGIN_DIR .'/includes/vendor/tinymce-widget/tinymce-widget.php'; } require_once AMPFORWP_PLUGIN_DIR .'/includes/modules/ampforwp-blurb.php'; require_once AMPFORWP_PLUGIN_DIR .'/includes/modules/ampforwp-button.php'; } } /* * Load Files only in the backend * As we don't need plugin activation code to run everytime the site loads */ if ( is_admin() ) { // Include Welcome page only on Admin pages require AMPFORWP_PLUGIN_DIR .'/includes/welcome.php'; // Deactivate Parent Plugin notice // add_action('init','ampforwp_plugin_notice'); function ampforwp_plugin_notice() { if ( ! defined( 'AMP__FILE__' ) ) { add_action( 'admin_notices', 'ampforwp_plugin_not_found_notice' ); function ampforwp_plugin_not_found_notice() { $current_screen = get_current_screen(); if( $current_screen ->id == "plugin-install" || $current_screen ->id == "dashboard_page_ampforwp-welcome-page" || $current_screen ->id == "ampforwp-welcome-page" ) { return; } ?>

'' . __('Settings', 'accelerated-mobile-pages') . ' | ' . __('Premium Support', 'accelerated-mobile-pages') . ''); include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); $actions = array_merge( $actions, $settings ); /*if ( is_plugin_active( 'amp/amp.php' ) ) { //if parent plugin is activated $actions = array_merge( $actions, $settings ); } else{ if(is_plugin_active( 'amp/amp.php' )){ $actions = array_merge( $actions, $settings ); }else{ $please_activate_parent_plugin = array(__('Please Activate Parent plugin','accelerated-mobile-pages') => '' . __(''.__('Action Required: Continue Installation','accelerated-mobile-pages').'', 'accelerated-mobile-pages') . ''); $actions = array_merge( $please_activate_parent_plugin,$actions ); } }*/ } return $actions; } } } // is_admin() closing // AMP endpoint Verifier function ampforwp_is_amp_endpoint() { return false !== get_query_var( 'amp', false ); } if ( ! class_exists( 'Ampforwp_Init', false ) ) { class Ampforwp_Init { public function __construct(){ // Load Files required for the plugin to run require AMPFORWP_PLUGIN_DIR .'/includes/includes.php'; // Redirection Code added require AMPFORWP_PLUGIN_DIR.'/includes/redirect.php'; require AMPFORWP_PLUGIN_DIR .'/classes/class-init.php'; new Ampforwp_Loader; } } } /* * Start the plugin. * Gentlemen start your engines */ function ampforwp_plugin_init() { if ( defined( 'AMP__FILE__' ) && defined('AMPFORWP_PLUGIN_DIR') ) { new Ampforwp_Init; } } add_action('init','ampforwp_plugin_init',9); /* * customized output widget * to be used be used in before or after Loop */ require AMPFORWP_PLUGIN_DIR.'/templates/category-widget.php'; require AMPFORWP_PLUGIN_DIR.'/templates/woo-widget.php'; /* * Including core AMP plugin files and removing any other things if necessary */ function ampforwp_bundle_core_amp_files(){ // Bundling Default plugin require_once AMPFORWP_PLUGIN_DIR .'/includes/vendor/amp/amp.php'; define( 'AMP__FILE__', __FILE__ ); if ( ! defined('AMP__DIR__') ) { define( 'AMP__DIR__', plugin_dir_path(__FILE__) . 'includes/vendor/amp/' ); } define( 'AMP__VERSION', '0.4.2' ); require_once( AMP__DIR__ . '/back-compat/back-compat.php' ); require_once( AMP__DIR__ . '/includes/amp-helper-functions.php' ); require_once( AMP__DIR__ . '/includes/admin/functions.php' ); require_once( AMP__DIR__ . '/includes/settings/class-amp-customizer-settings.php' ); require_once( AMP__DIR__ . '/includes/settings/class-amp-customizer-design-settings.php' ); } add_action('plugins_loaded','ampforwp_bundle_core_amp_files', 8); function ampforwp_deactivate_amp_plugin() { if ( version_compare( floatval( get_bloginfo( 'version' ) ), '3.5', '>=' ) ) { if ( current_user_can( 'activate_plugins' ) ) { add_action( 'admin_init', 'ampforwp_deactivate_amp' ); function ampforwp_deactivate_amp() { deactivate_plugins( AMPFORWP_MAIN_PLUGIN_DIR . 'amp/amp.php' ); } } } } add_action( 'plugins_loaded', 'ampforwp_deactivate_amp_plugin' ); function ampforwp_modify_amp_activatation_link( $actions, $plugin_file ) { $plugin = ''; $plugin = 'amp/amp.php'; if ( $plugin == $plugin_file ) { add_thickbox(); unset($actions['activate']); $a = 'Activate'; array_unshift ($actions,$a); } return $actions; } add_filter( 'plugin_action_links', 'ampforwp_modify_amp_activatation_link', 10, 2 ); if ( ! function_exists('ampforwp_init') ) { add_action( 'init', 'ampforwp_init' ); function ampforwp_init() { if ( false === apply_filters( 'amp_is_enabled', true ) ) { return; } define( 'AMP_QUERY_VAR', apply_filters( 'amp_query_var', 'amp' ) ); if ( ! defined('AMP__DIR__') ) { define( 'AMP__DIR__', plugin_dir_path(__FILE__) . 'includes/vendor/amp/' ); } do_action( 'amp_init' ); load_plugin_textdomain( 'amp', false, plugin_basename( AMP__DIR__ ) . '/languages' ); add_rewrite_endpoint( AMP_QUERY_VAR, EP_PERMALINK ); add_post_type_support( 'post', AMP_QUERY_VAR ); add_filter( 'request', 'amp_force_query_var_value' ); add_action( 'wp', 'amp_maybe_add_actions' ); // Redirect the old url of amp page to the updated url. #1033 (Vendor Update) add_filter( 'old_slug_redirect_url', 'ampforwp_redirect_old_slug_to_new_url' ); if ( class_exists( 'Jetpack' ) && ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ) { require_once( AMP__DIR__ . '/jetpack-helper.php' ); } } } function AMP_update_db_check() { global $redux_builder_amp; $ampforWPCurrentVersion = AMPFORWP_VERSION; if (get_option( 'AMPforwp_db_version' ) != $ampforWPCurrentVersion) { if ( isset( $_GET['ampforwp-dismiss'] ) && trim($_GET['ampforwp-dismiss'])=="ampforwp_dismiss_admin_notices" ) { update_option( 'AMPforwp_db_version', $ampforWPCurrentVersion ); wp_redirect(remove_query_arg('ampforwp-dismiss'), 301); } if( isset($redux_builder_amp['ampforwp-update-notification-bar'] ) && $redux_builder_amp['ampforwp-update-notification-bar'] && current_user_can( 'manage_options' ) ){ add_action('admin_notices', 'ampforwp_update_notice'); } } } add_action( 'plugins_loaded', 'AMP_update_db_check' ); function ampforwp_update_notice() { $ampforWPCurrentVersion = AMPFORWP_VERSION; ?>
What's New?
X
Appreciate it?
Leave a Review →