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() ); if( $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, $wp_rewrite; // For Homepage add_rewrite_rule( 'amp/?$', 'index.php?amp', 'top' ); // For Homepage with Pagination add_rewrite_rule( 'amp/'.$wp_rewrite->pagination_base.'/([0-9]{1,})/?$', 'index.php?amp=1&paged=$matches[1]', 'top' ); // For /Blog page with Pagination if( ampforwp_name_blog_page() ) { add_rewrite_rule( 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(), 'top' ); // Pagination to work with Extensions like.hml add_rewrite_rule( 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(), 'top' ); } // For Author pages add_rewrite_rule( 'author\/([^/]+)\/amp\/?$', 'index.php?amp=1&author_name=$matches[1]', 'top' ); add_rewrite_rule( 'author\/([^/]+)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$', 'index.php?amp=1&author_name=$matches[1]&paged=$matches[2]', 'top' ); // For category pages $rewrite_category = ''; $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); } add_rewrite_rule( $rewrite_category.'\/(.+?)\/amp/?$', 'index.php?amp=1&category_name=$matches[1]', 'top' ); // For category pages with Pagination add_rewrite_rule( $rewrite_category.'/(.+?)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$', 'index.php?amp=1&category_name=$matches[1]&paged=$matches[2]', 'top' ); // 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 ) { add_rewrite_rule( $permalink_structure.'\/'.$rewrite_category.'\/(.+?)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$', 'index.php?amp=1&category_name=$matches[1]&paged=$matches[2]', 'top' ); } // For tag pages $rewrite_tag = ''; $rewrite_tag = get_transient('ampforwp_tag_base'); if ( false == $rewrite_tag ) { $rewrite_tag = get_option('tag_base'); if ( empty($rewrite_tag) ) { $rewrite_tag = 'tag'; } set_transient('ampforwp_tag_base',$rewrite_tag); } add_rewrite_rule( $rewrite_tag.'\/(.+?)\/amp/?$', 'index.php?amp=1&tag=$matches[1]', 'top' ); // For tag pages with Pagination add_rewrite_rule( $rewrite_tag.'\/(.+?)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$', 'index.php?amp=1&tag=$matches[1]&paged=$matches[2]', 'top' ); // For tag pages with Pagination (Custom Permalink Structure) if ( $permalink_structure ) { add_rewrite_rule( $permalink_structure.'\/'.$rewrite_tag.'\/(.+?)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$', 'index.php?amp=1&tag=$matches[1]&paged=$matches[2]', 'top' ); } // Rewrite rule for date archive add_rewrite_rule( '([0-9]{4})/([0-9]{1,2})\/amp\/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&=1', 'top' ); // Rewrite rule for date archive with pagination #2289 add_rewrite_rule( '([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]', 'top' ); //Rewrite rule for custom Taxonomies $taxonomies = ''; $taxonomies = get_transient('ampforwp_get_taxonomies'); if ( false == $taxonomies ) { $args = array( 'public' => true, '_builtin' => false, ); $output = 'names'; // or objects $operator = 'and'; // 'and' or 'or' $taxonomies = get_taxonomies( $args, $output, $operator ); set_transient('ampforwp_get_taxonomies',$taxonomies); } if(!function_exists('amp_woocommerce_pro_add_woocommerce_support') ) { if( class_exists( 'WooCommerce' ) ) { $wc_permalinks = ''; $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 ) { $taxonomies = array_merge($taxonomies, $wc_permalinks); } } } $post_types = ampforwp_get_all_post_types(); if ( $post_types ) { foreach ($post_types as $post_type ) { if ( 'post' != $post_type && 'page' != $post_type ){ add_rewrite_rule( $post_type.'\/amp/?$', 'index.php?amp&post_type='.$post_type, 'top' ); add_rewrite_rule( $post_type.'\/(.+?)\/amp\/?$', 'index.php?amp&'.$post_type.'=$matches[1]', 'top' ); add_rewrite_rule( $post_type.'\/amp/'.$wp_rewrite->pagination_base.'/([0-9]{1,})/?$', 'index.php?amp=1&post_type='.$post_type.'&paged=$matches[1]', 'top' ); } } } $taxonomies = apply_filters( 'ampforwp_modify_rewrite_tax', $taxonomies ); if ( $taxonomies ) { foreach ( $taxonomies as $key => $taxonomy ) { if ( ! empty( $taxonomy ) ) { add_rewrite_rule( $taxonomy.'\/(.+?)\/amp/?$', 'index.php?amp&'.$key.'=$matches[1]', 'top' ); // For Custom Taxonomies with pages add_rewrite_rule( $taxonomy.'\/(.+?)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$', 'index.php?amp&'.$taxonomy.'=$matches[1]&paged=$matches[2]', 'top' ); } } } } 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(){ if ( class_exists('WooCommerce') ) { $permalinks = wp_parse_args( (array) get_option( 'woocommerce_permalinks', array() ), array( 'product_base' => '', 'category_base' => '', 'tag_base' => '', 'attribute_base' => '', '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'] ); add_rewrite_rule( $permalinks['product_rewrite_slug']."\/amp\/page\/([0-9]{1,})/?$", 'index.php?post_type=product&paged=$matches[1]&=1', 'top' ); add_rewrite_rule( $permalinks['category_rewrite_slug'].'\/(.+?)\/amp\/page\/?([0-9]{1,})/?$', 'index.php?product_cat=$matches[1]&paged=$matches[2]&=1', 'top' ); add_rewrite_rule( $permalinks['category_rewrite_slug'].'\/(.+?)\/amp\/?$', 'index.php?amp&product_cat=$matches[1]', 'top' ); add_rewrite_rule( $permalinks['tag_rewrite_slug'].'\/(.+?)\/amp\/page\/?([0-9]{1,})/?$', 'index.php?product_tag=$matches[1]&paged=$matches[2]&=1', 'top' ); add_rewrite_rule( $permalinks['tag_rewrite_slug'].'\/(.+?)\/amp\/?$', 'index.php?amp&product_tag=$matches[1]', 'top' ); } } } function ampforwp_plugin_info(){ $data = array(); $date = new DateTime(); $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_init(); } flush_rewrite_rules(); ampforwp_add_custom_post_support(); ampforwp_add_custom_rewrite_rules(); ampforwp_plugin_info(); // 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( 'admin_init', 'ampforwp_flush_after_update'); function ampforwp_flush_after_update() { // Flushing rewrite urls ONLY on after Update is installed $older_version = ""; $older_version = get_transient('ampforwp_current_version_check'); if ( empty($older_version) || ( $older_version < AMPFORWP_VERSION ) ) { flush_rewrite_rules(); global $wp_rewrite; $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(){ 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'); } if( !function_exists('ampforwp_upcomming_layouts_demo') ){ function ampforwp_upcomming_layouts_demo(){ return array( array( "name"=>'Creative Services', "image"=>''.AMPFORWP_IMAGE_DIR . '/layouts-9.png', "link"=>'https://ampforwp.com/layouts-9/', ), array( "name"=>'App', "image"=>''.AMPFORWP_IMAGE_DIR . '/layouts-8.png', "link"=>'https://ampforwp.com/layouts-8/', ), array( "name"=>'Business Blog', "image"=>''.AMPFORWP_IMAGE_DIR . '/layouts-7.png', "link"=>'https://ampforwp.com/layouts-7/', ), array( "name"=>'Journal', "image"=>''.AMPFORWP_IMAGE_DIR . '/layouts-6.png', "link"=>'https://ampforwp.com/layouts-6/', ), array( "name"=>'Studio', "image"=>''.AMPFORWP_IMAGE_DIR . '/layouts-5.png', "link"=>'https://ampforwp.com/layouts-5/', ), array( "name"=>'Agency', "image"=>''.AMPFORWP_IMAGE_DIR . '/layouts-4.png', "link"=>'https://ampforwp.com/layouts-4/', ), array( "name"=>'Elegance', "image"=>''.AMPFORWP_IMAGE_DIR . '/layouts-3.png', "link"=>'https://ampforwp.com/layouts-3/', ), array( "name"=>'Weekly Magazine', "image"=>''.AMPFORWP_IMAGE_DIR . '/layouts-2.png', "link"=>'https://ampforwp.com/layouts-2/', ), array( "name"=>'News', "image"=>''.AMPFORWP_IMAGE_DIR . '/layouts-1.png', "link"=>'https://ampforwp.com/layouts-1/', ), ); } } require_once dirname( __FILE__ ).'/includes/options/redux-core/framework.php'; require_once dirname( __FILE__ ).'/includes/options/extensions/loader.php'; add_action('after_setup_theme', 'ampforwp_include_options_file' ); function ampforwp_include_options_file(){ if ( is_admin() ) { // 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() ) { add_action( 'plugins_loaded', 'amp_update_db_check' ); // Include Welcome page only on Admin pages require AMPFORWP_PLUGIN_DIR .'/includes/welcome.php'; // Add Settings Button in Plugin backend if ( ! function_exists( 'ampforwp_plugin_settings_link' ) ) { // Deactivate Parent Plugin notice add_filter( 'plugin_action_links', 'ampforwp_plugin_settings_link', 10, 5 ); function ampforwp_plugin_settings_link( $actions, $plugin_file ) { static $plugin; if ( ! isset($plugin)) $plugin = plugin_basename(__FILE__); if ( $plugin === $plugin_file ) { $amp_activate = ''; if ( function_exists('amp_activate') ) { $amp_activate = ' | Status: Addon Mode'; } $settings = array( 'settings' => '' . esc_html__('Settings', 'accelerated-mobile-pages') . ' | ' . esc_html__('Premium Features', 'accelerated-mobile-pages') . ' | ' . esc_html__('Pro', 'accelerated-mobile-pages') . ''. $amp_activate ); include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); $actions = array_merge( $actions, $settings ); } return $actions; } } } // is_admin() closing // Fallback for file exists #3156 if( ! function_exists('ampforwp_require_file') ){ function ampforwp_require_file($path){ if(file_exists($path)){ return require_once $path; } else{ return false; } } } // AMP endpoint Verifier function ampforwp_is_amp_endpoint() { if ( ampforwp_is_non_amp() && ! is_admin()) { return apply_filters('ampforwp_is_amp_endpoint_takeover', ampforwp_is_non_amp() ); } else { return apply_filters('ampforwp_is_amp_endpoint', false !== get_query_var( 'amp', false ) ); } } include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); if ( ! class_exists( 'Ampforwp_Init', false ) ) { class Ampforwp_Init { public function __construct(){ require AMPFORWP_PLUGIN_DIR .'/includes/features/functions.php'; // Load Files required for the plugin to run if( function_exists('amp_activate') ){ require_once AMPFORWP_PLUGIN_DIR."includes/features/amp_bridge.php"; } else{ 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(); } //Other Features require_once AMPFORWP_PLUGIN_DIR."includes/features/advertisement/ads-functions.php"; require_once AMPFORWP_PLUGIN_DIR."includes/features/performance/performance-functions.php"; require_once AMPFORWP_PLUGIN_DIR."includes/features/analytics/analytics-functions.php"; require_once AMPFORWP_PLUGIN_DIR."includes/features/structure-data/structured-data-functions.php"; require_once AMPFORWP_PLUGIN_DIR."includes/features/notice-bar/notice-bar-functions.php"; require_once AMPFORWP_PLUGIN_DIR."includes/features/push-notification/push-notification-functions.php"; } } } /* * Start the plugin. * Gentlemen start your engines */ function ampforwp_plugin_init() { if ( defined( 'AMPFORWP__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 */ ampforwp_require_file( AMPFORWP_PLUGIN_DIR.'/templates/category-widget.php' ); ampforwp_require_file( 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( 'AMPFORWP__FILE__', __FILE__ ); if ( ! defined('AMP__VENDOR__DIR__') ) { define( 'AMP__VENDOR__DIR__', plugin_dir_path(__FILE__) . 'includes/vendor/amp/' ); } if ( ! defined('AMP_QUERY_VAR') ){ define('AMP_QUERY_VAR', 'amp'); } define( 'AMP__VENDOR__VERSION', '0.4.2' ); require_once( AMP__VENDOR__DIR__ . '/back-compat/back-compat.php' ); require_once( AMP__VENDOR__DIR__ . '/includes/amp-helper-functions.php' ); require_once( AMP__VENDOR__DIR__ . '/includes/admin/functions.php' ); require_once( AMP__VENDOR__DIR__ . '/includes/settings/class-amp-customizer-settings.php' ); require_once( AMP__VENDOR__DIR__ . '/includes/settings/class-amp-customizer-design-settings.php' ); // Widgets require_once ( AMP__VENDOR__DIR__ . '/includes/widgets/class-amp-widget-categories.php' ); require_once ( AMP__VENDOR__DIR__ . '/includes/widgets/class-amp-widget-archives.php' ); require_once ( AMP__VENDOR__DIR__ . '/includes/widgets/class-amp-widget-media-video.php' ); require_once ( AMP__VENDOR__DIR__ . '/includes/widgets/class-amp-widget-recent-comments.php' ); require_once ( AMP__VENDOR__DIR__ . '/includes/widgets/class-amp-widget-text.php' ); } add_action('plugins_loaded','ampforwp_bundle_core_amp_files', 8); if ( ! function_exists('ampforwp_init') ) { add_action( 'init', 'ampforwp_init' ); function ampforwp_init() { if ( false === apply_filters( 'amp_is_enabled', true ) ) { return; } if( ! defined('AMP_QUERY_VAR')){ define( 'AMP_QUERY_VAR', apply_filters( 'amp_query_var', 'amp' ) ); } if ( ! defined('AMP__VENDOR__DIR__') ) { define( 'AMP__VENDOR__DIR__', plugin_dir_path(__FILE__) . 'includes/vendor/amp/' ); } do_action( 'amp_init' ); load_plugin_textdomain( 'accelerated-mobile-pages', false, trailingslashit(AMPFORWP_PLUGIN_DIR) . 'languages' ); add_rewrite_endpoint( AMP_QUERY_VAR, EP_PERMALINK ); add_post_type_support( 'post', AMP_QUERY_VAR ); add_filter( 'request', 'AMPforWP\\AMPVendor\\amp_force_query_var_value' ); add_action( 'wp', 'AMPforWP\\AMPVendor\\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) && ( defined('JETPACK__VERSION') && JETPACK__VERSION < 6.9 ) ) { require_once( AMP__VENDOR__DIR__ . '/jetpack-helper.php' ); } // AMP by Automattic Compatibility #2287 // Remove the FrontPage query added by AMP to make our FrontPage/Homepage works if ( function_exists('amp_activate') ) { remove_action( 'parse_query', 'amp_correct_query_when_is_front_page' ); remove_action( 'wp', 'amp_maybe_add_actions' ); } } } function amp_update_db_check() { global $redux_builder_amp; $ampforwp_current_version = AMPFORWP_VERSION; if ( isset( $_GET['ampforwp-dismiss-theme'] ) && trim( $_GET['ampforwp-dismiss-theme']) === "ampforwp_dismiss_admin_notices" && wp_verify_nonce($_GET['ampforwp_notice'], 'ampforwp_notice') ) { update_option( 'ampforwp_theme_notice', true ); wp_redirect("admin.php?page=amp_options"); } if ( get_option( 'AMPforwp_db_version' ) !== $ampforwp_current_version ) { if ( isset( $_GET['ampforwp-dismiss'] ) && trim( $_GET['ampforwp-dismiss']) === "ampforwp_dismiss_admin_notices" && wp_verify_nonce($_GET['ampforwp_notice'], 'ampforwp_notice') ) { update_option( 'AMPforwp_db_version', $ampforwp_current_version ); 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'); } } } // Admin notice for AMP WordPress Theme add_action('admin_notices', 'ampforwp_ampwptheme_notice'); function ampforwp_ampwptheme_notice() { $theme = ''; $theme = wp_get_theme(); // gets the current theme if ( ('AMP WordPress Theme' == $theme->name || 'AMP WordPress Theme' == $theme->parent_theme) && true != get_option('ampforwp_theme_notice') ) { add_thickbox(); ?>
base) { ?> base ) { ?> widgets as $registered_widget ) { $registered_widget_class_name = get_class( $registered_widget ); if ( ! preg_match( '/^WP_Widget_(.+)$/', $registered_widget_class_name, $matches ) ) { continue; } $amp_class_name = 'AMP_Widget_' . $matches[1]; if ( ! class_exists( $amp_class_name ) || is_a( $amp_class_name, $registered_widget_class_name ) ) { continue; } unregister_widget( $registered_widget_class_name ); register_widget( $amp_class_name ); } } // Post Types function ampforwp_get_all_post_types(){ global $redux_builder_amp; $post_types = array(); $selected_post_types = array(); if( ampforwp_get_setting('amp-on-off-for-all-posts') ){ $post_types['post'] = 'post'; } if( ampforwp_get_setting('amp-on-off-for-all-pages') ){ $post_types['page'] = 'page'; } if( ampforwp_get_setting('ampforwp-archive-support') && ampforwp_get_setting('ampforwp-archive-support-cat') ){ $post_types['category'] = 'category'; } if ( ampforwp_get_setting('ampforwp-custom-type')) { foreach (ampforwp_get_setting('ampforwp-custom-type') as $key) { $selected_post_types[$key] = $key; } $post_types = array_merge($post_types, $selected_post_types); } return $post_types; } // is_search_enabled_in_ampforwp function ( Design 1,2 and 3 ) #2681 if( !function_exists( 'is_search_enabled_in_ampforwp' ) ) { function is_search_enabled_in_ampforwp() { if( ( ampforwp_get_setting('amp-design-selector')==1 && ampforwp_get_setting('amp-design-1-search-feature') ) || ( ampforwp_get_setting('amp-design-selector')==2 && ampforwp_get_setting('amp-design-2-search-feature') ) || ( ampforwp_get_setting('amp-design-selector')==3 && ampforwp_get_setting('amp-design-3-search-feature') ) ) { return true; } return false; } } // Fallback for Redux class #2377 add_action('after_setup_theme', 'ampforwp_redux_class' ); function ampforwp_redux_class(){ if ( !class_exists('Redux') && class_exists('ReduxCore\\ReduxFramework\\Redux') ) { class Redux extends ReduxCore\ReduxFramework\Redux { # Do nothing, it will inherit all the methods } } } add_filter('plugin_row_meta' , 'ampforwp_add_plugin_meta_links', 10, 2); if ( ! function_exists('ampforwp_add_plugin_meta_links') ) { function ampforwp_add_plugin_meta_links($meta_fields, $file) { if ( plugin_basename(__FILE__) == $file ) { $plugin_url = "https://wordpress.org/support/plugin/accelerated-mobile-pages/reviews/?rate=5#new-post"; $meta_fields[] = " " . "" . "" . "" . "" . "" . ""; } return $meta_fields; } } // AMPforWP Global Data variable $ampforwp_data = array(); // color sanitizer function ampforwp_sanitize_color( $color ) { if ( empty( $color ) || is_array( $color ) ) return 'rgba(0,0,0,0)'; // If string does not start with 'rgba', then treat as hex // sanitize the hex color and finally convert hex to rgba if ( false === strpos( $color, 'rgba' ) ) { return sanitize_hex_color( $color ); } // By now we know the string is formatted as an rgba color so we need to further sanitize it. $color = str_replace( ' ', '', $color ); sscanf( $color, 'rgba(%d,%d,%d,%f)', $red, $green, $blue, $alpha ); return 'rgba('.$red.','.$green.','.$blue.','.$alpha.')'; } // AMP Plugins Manager compatibility #2976 if ( false == get_transient('ampforwp-pm-disabler') ) { $ampforwp_active_plugins = array_flip(get_option('active_plugins')); if (isset($ampforwp_active_plugins['amp-plugin-manager/ampforwp-3rd-party-plugin-creator.php'] ) ){ $plugin_data = get_plugin_data(AMPFORWP_MAIN_PLUGIN_DIR . 'amp-plugin-manager/ampforwp-3rd-party-plugin-creator.php' ); if ( version_compare( floatval( $plugin_data['Version'] ), '1.1', '<' ) ){ unset($ampforwp_active_plugins['amp-plugin-manager/ampforwp-3rd-party-plugin-creator.php']); update_option('active_plugins', array_flip($ampforwp_active_plugins)); set_transient('ampforwp-pm-disabler', true); include_once( ABSPATH . 'wp-includes/pluggable.php' ); wp_redirect(admin_url('plugins.php')); } } elseif(isset($ampforwp_active_plugins['amp-plugin-manager-master/ampforwp-3rd-party-plugin-creator.php'] )){ $plugin_data = get_plugin_data(AMPFORWP_MAIN_PLUGIN_DIR . 'amp-plugin-manager-master/ampforwp-3rd-party-plugin-creator.php' ); if ( version_compare( floatval( $plugin_data['Version'] ), '1.1', '<' ) ){ unset($ampforwp_active_plugins['amp-plugin-manager-master/ampforwp-3rd-party-plugin-creator.php']); update_option('active_plugins', array_flip($ampforwp_active_plugins)); set_transient('ampforwp-pm-disabler', true); include_once( ABSPATH . 'wp-includes/pluggable.php' ); wp_redirect(admin_url('plugins.php')); } } } add_action('admin_notices', 'ampforwp_plugins_manager_notice'); function ampforwp_plugins_manager_notice(){ if ( true == get_transient('ampforwp-pm-disabler') ) { ?> $section_value) { if(count($section_value['fields'])>0){ foreach ($section_value['fields'] as $fieldkey => $field_value) { if(isset($field_value['required']) && in_array($field_value['id'], $redux_enabled_options) ){ unset($sections[$key]['fields'][$fieldkey]['required']); } } } } } return $sections; } // Redux Options Remover #2939 add_filter( 'redux/options/redux_builder_amp/sections', 'ampforwp_redux_options_remover',7,1 ); function ampforwp_redux_options_remover($sections){ $redux_enabled_options = array(); // apply_filters to get the options to remove them $redux_enabled_options = apply_filters('ampforwp_options_remover', $redux_enabled_options); if(is_array($redux_enabled_options) ) { foreach ($sections as $key => $section_value) { if(count($section_value['fields'])>0){ foreach ($section_value['fields'] as $fieldkey => $field_value) { if(isset($field_value['required']) && in_array($field_value['id'], $redux_enabled_options) ){ unset($sections[$key]['fields'][$fieldkey]); } } } } } return $sections; }