'0.4.2' ) { return require AMPFORWP_PLUGIN_DIR .'templates/customizer/customizer-new.php' ; } else { return require AMPFORWP_PLUGIN_DIR .'templates/customizer/customizer.php' ; } } else { return require AMPFORWP_PLUGIN_DIR .'templates/customizer/customizer.php' ; } } ampforwp_include_customizer_files(); //0. define('AMPFORWP_COMMENTS_PER_PAGE', ampforwp_define_comments_number() ); // Define number of comments function ampforwp_define_comments_number(){ global $redux_builder_amp; return $redux_builder_amp['ampforwp-number-of-comments']; } // 1. Add Home REL canonical // Add AMP rel-canonical for home and archive pages add_action('amp_init','ampforwp_allow_homepage'); function ampforwp_allow_homepage() { add_action( 'wp', 'ampforwp_add_endpoint_actions' ); } function ampforwp_add_endpoint_actions() { $ampforwp_is_amp_endpoint = ampforwp_is_amp_endpoint(); if ( $ampforwp_is_amp_endpoint ) { amp_prepare_render(); } else { add_action( 'wp_head', 'ampforwp_home_archive_rel_canonical' ); } $cpage_var = get_query_var('cpage'); if ( $cpage_var >= 1) : remove_action( 'wp_head', 'ampforwp_home_archive_rel_canonical' ); endif; } function ampforwp_home_archive_rel_canonical() { global $redux_builder_amp; global $wp; if( is_attachment() ) { return; } if( is_home() && !$redux_builder_amp['ampforwp-homepage-on-off-support'] ) { return; } if( is_front_page() && ! $redux_builder_amp['ampforwp-homepage-on-off-support'] ) { return; } if ( is_archive() && !$redux_builder_amp['ampforwp-archive-support'] ) { return; } // #872 no-amphtml if selected as hide from settings if(is_archive() && $redux_builder_amp['ampforwp-archive-support']){ $categories = get_the_category(); $category_id = $categories[0]->cat_ID; $get_categories_from_checkbox = $redux_builder_amp['hide-amp-categories']; // Check if $get_categories_from_checkbox has some cats then only show if ( $get_categories_from_checkbox ) { $get_selected_cats = array_filter($get_categories_from_checkbox); foreach ($get_selected_cats as $key => $value) { $selected_cats[] = $key; } if($selected_cats && $category_id){ if(in_array($category_id, $selected_cats)){ return; } } } } if( is_page() && !$redux_builder_amp['amp-on-off-for-all-pages'] ) { return; } $query_arg_array = $wp->query_vars; if( in_array( "cpage" , $query_arg_array ) ) { if( is_front_page() && $wp->query_vars['cpage'] >= '2' ) { return; } if( is_singular() && $wp->query_vars['cpage'] >= '2' ) { return; } } if ( is_home() || is_front_page() || is_archive() ){ global $wp; $current_archive_url = home_url( $wp->request ); $amp_url = trailingslashit(trailingslashit($current_archive_url).'amp'); } else { $amp_url = amp_get_permalink( get_queried_object_id() ); } global $post; $ampforwp_amp_post_on_off_meta = get_post_meta( get_the_ID(),'ampforwp-amp-on-off',true); if( is_singular() && $ampforwp_amp_post_on_off_meta === 'hide-amp' ) { //dont Echo anything } else { $supported_types = array('post','page'); $supported_types = apply_filters('get_amp_supported_post_types',$supported_types); $type = get_post_type(); $supported_amp_post_types = in_array( $type , $supported_types ); $query_arg_array = $wp->query_vars; if( array_key_exists( 'paged' , $query_arg_array ) ) { if ( (is_home() || is_archive()) && $wp->query_vars['paged'] >= '2' ) { $new_url = home_url('/'); $category_path = $wp->request; $explode_path = explode("/",$category_path); $inserted = array(AMPFORWP_AMP_QUERY_VAR); array_splice( $explode_path, -2, 0, $inserted ); $impode_url = implode('/', $explode_path); $amp_url = $new_url . $impode_url ; } if( is_search() && $wp->query_vars['paged'] >= '2' ) { $current_search_url =trailingslashit(get_home_url()) . $wp->request .'/'."?amp=1&s=".get_search_query(); } } if( is_search() ) { $current_search_url =trailingslashit(get_home_url())."?amp=1&s=".get_search_query(); $amp_url = untrailingslashit($current_search_url); } $amp_url = user_trailingslashit($amp_url); $amp_url = apply_filters('ampforwp_modify_rel_canonical',$amp_url); if( $supported_amp_post_types) { printf('', esc_url($amp_url)); } } } //end of ampforwp_home_archive_rel_canonical() // Remove default wordpress rel canonical add_filter('amp_frontend_show_canonical','ampforwp_remove_default_canonical'); if (! function_exists('ampforwp_remove_default_canonical') ) { function ampforwp_remove_default_canonical() { return false; } } // 2. Custom Design // Add Homepage AMP file code add_filter( 'amp_post_template_file', 'ampforwp_custom_template', 10, 3 ); function ampforwp_custom_template( $file, $type, $post ) { // Custom Homepage and Archive file global $redux_builder_amp; $slug = array(); $current_url_in_pieces = array(); $ampforwp_custom_post_page = ampforwp_custom_post_page(); // Homepage and FrontPage if ( is_home() ) { if ( 'single' === $type ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/index.php'; if ($redux_builder_amp['amp-frontpage-select-option'] == 1) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/frontpage.php'; } if ( $ampforwp_custom_post_page == "page" && ampforwp_name_blog_page() ) { $current_url = home_url( $GLOBALS['wp']->request ); $current_url_in_pieces = explode( '/', $current_url ); if( in_array( ampforwp_name_blog_page() , $current_url_in_pieces ) ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/index.php'; } } } } // Archive Pages if ( is_archive() && $redux_builder_amp['ampforwp-archive-support'] ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/archive.php'; } // Search pages if ( is_search() && ( $redux_builder_amp['amp-design-1-search-feature'] || $redux_builder_amp['amp-design-2-search-feature'] || $redux_builder_amp['amp-design-3-search-feature'] ) ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/search.php'; } // Custom Single file if ( is_single() || is_page() ) { if('single' === $type && !('product' === $post->post_type )) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/single.php'; } } return $file; } // 3. Custom Style files add_filter( 'amp_post_template_file', 'ampforwp_set_custom_style', 10, 3 ); function ampforwp_set_custom_style( $file, $type, $post ) { if ( 'style' === $type ) { $file = ''; } return $file; } //3.5 add_filter( 'amp_post_template_file', 'ampforwp_empty_filter', 10, 3 ); function ampforwp_empty_filter( $file, $type, $post ) { if ( 'empty-filter' === $type ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/empty-filter.php'; } return $file; } // 4. Custom Header files add_filter( 'amp_post_template_file', 'ampforwp_custom_header', 10, 3 ); function ampforwp_custom_header( $file, $type, $post ) { if ( 'header-bar' === $type ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/header-bar.php'; } return $file; } // 4.1 Custom Meta-Author files add_filter( 'amp_post_template_file', 'ampforwp_set_custom_meta_author', 10, 3 ); function ampforwp_set_custom_meta_author( $file, $type, $post ) { if ( 'meta-author' === $type ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/empty-filter.php'; } return $file; } // 4.2 Custom Meta-Taxonomy files add_filter( 'amp_post_template_file', 'ampforwp_set_custom_meta_taxonomy', 10, 3 ); function ampforwp_set_custom_meta_taxonomy( $file, $type, $post ) { if ( 'meta-taxonomy' === $type ) { $file = AMPFORWP_PLUGIN_DIR . 'templates/design-manager/empty-filter.php'; } return $file; } // 4.5 Added hook to add more layout. do_action('ampforwp_after_features_include'); // 5. Customize with Width of the site add_filter( 'amp_content_max_width', 'ampforwp_change_content_width' ); function ampforwp_change_content_width( $content_max_width ) { return 1000; } // 6. Add required Javascripts for extra AMP features add_action('amp_post_template_head','ampforwp_register_additional_scripts', 20); function ampforwp_register_additional_scripts() { global $redux_builder_amp; if( $redux_builder_amp['enable-single-social-icons'] == true || AMPFORWP_DM_SOCIAL_CHECK === 'true' ) { ?>

'; $output .= ''; $output .= ''; $output .= ' '; echo $output; } } // Above Footer Global add_action('amp_post_template_above_footer','ampforwp_footer_advert',10); function ampforwp_footer_advert() { global $redux_builder_amp; if($redux_builder_amp['enable-amp-ads-2'] == true) { if($redux_builder_amp['enable-amp-ads-select-2'] == 1) { $advert_width = '300'; $advert_height = '250'; } elseif ($redux_builder_amp['enable-amp-ads-select-2'] == 2) { $advert_width = '336'; $advert_height = '280'; } elseif ($redux_builder_amp['enable-amp-ads-select-2'] == 3) { $advert_width = '728'; $advert_height = '90'; } elseif ($redux_builder_amp['enable-amp-ads-select-2'] == 4) { $advert_width = '300'; $advert_height = '600'; } elseif ($redux_builder_amp['enable-amp-ads-select-2'] == 5) { $advert_width = '320'; $advert_height = '100'; } elseif ($redux_builder_amp['enable-amp-ads-select-2'] == 6) { $advert_width = '200'; $advert_height = '50'; } elseif ($redux_builder_amp['enable-amp-ads-select-2'] == 7) { $advert_width = '320'; $advert_height = '50'; } $output = '
'; $output .= ''; $output .= ''; $output .= '
'; echo $output; } } // Below Title Single add_action('ampforwp_before_post_content','ampforwp_before_post_content_advert'); add_action('ampforwp_inside_post_content_before','ampforwp_before_post_content_advert'); function ampforwp_before_post_content_advert() { global $redux_builder_amp; if($redux_builder_amp['enable-amp-ads-3'] == true) { if($redux_builder_amp['enable-amp-ads-select-3'] == 1) { $advert_width = '300'; $advert_height = '250'; } elseif ($redux_builder_amp['enable-amp-ads-select-3'] == 2) { $advert_width = '336'; $advert_height = '280'; } elseif ($redux_builder_amp['enable-amp-ads-select-3'] == 3) { $advert_width = '728'; $advert_height = '90'; } elseif ($redux_builder_amp['enable-amp-ads-select-3'] == 4) { $advert_width = '300'; $advert_height = '600'; } elseif ($redux_builder_amp['enable-amp-ads-select-3'] == 5) { $advert_width = '320'; $advert_height = '100'; } elseif ($redux_builder_amp['enable-amp-ads-select-3'] == 6) { $advert_width = '200'; $advert_height = '50'; } elseif ($redux_builder_amp['enable-amp-ads-select-3'] == 7) { $advert_width = '320'; $advert_height = '50'; } $output = '
'; $output .= ''; $output .= ''; $output .= '
'; echo $output; } } // Below Content Single add_action('ampforwp_after_post_content','ampforwp_after_post_content_advert'); // Hook updated // add_action('ampforwp_inside_post_content_after','ampforwp_after_post_content_advert'); function ampforwp_after_post_content_advert() { global $redux_builder_amp; if($redux_builder_amp['enable-amp-ads-4'] == true) { if($redux_builder_amp['enable-amp-ads-select-4'] == 1) { $advert_width = '300'; $advert_height = '250'; } elseif ($redux_builder_amp['enable-amp-ads-select-4'] == 2) { $advert_width = '336'; $advert_height = '280'; } elseif ($redux_builder_amp['enable-amp-ads-select-4'] == 3) { $advert_width = '728'; $advert_height = '90'; } elseif ($redux_builder_amp['enable-amp-ads-select-4'] == 4) { $advert_width = '300'; $advert_height = '600'; } elseif ($redux_builder_amp['enable-amp-ads-select-4'] == 5) { $advert_width = '320'; $advert_height = '100'; } elseif ($redux_builder_amp['enable-amp-ads-select-4'] == 6) { $advert_width = '200'; $advert_height = '50'; } elseif ($redux_builder_amp['enable-amp-ads-select-4'] == 7) { $advert_width = '320'; $advert_height = '50'; } $output = '
'; $output .= ''; $output .= ''; $output .= '
'; echo $output; } } // Below The Title add_action('ampforwp_below_the_title','ampforwp_below_the_title_advert'); function ampforwp_below_the_title_advert() { global $redux_builder_amp; if($redux_builder_amp['enable-amp-ads-5'] == true) { if($redux_builder_amp['enable-amp-ads-select-5'] == 1) { $advert_width = '300'; $advert_height = '250'; } elseif ($redux_builder_amp['enable-amp-ads-select-5'] == 2) { $advert_width = '336'; $advert_height = '280'; } elseif ($redux_builder_amp['enable-amp-ads-select-5'] == 3) { $advert_width = '728'; $advert_height = '90'; } elseif ($redux_builder_amp['enable-amp-ads-select-5'] == 4) { $advert_width = '300'; $advert_height = '600'; } elseif ($redux_builder_amp['enable-amp-ads-select-5'] == 5) { $advert_width = '320'; $advert_height = '100'; } elseif ($redux_builder_amp['enable-amp-ads-select-5'] == 6) { $advert_width = '200'; $advert_height = '50'; } elseif ($redux_builder_amp['enable-amp-ads-select-5'] == 7) { $advert_width = '320'; $advert_height = '50'; } $output = '
'; $output .= ''; $output .= ''; $output .= '
'; echo $output; } } // Above Related post add_action('ampforwp_above_related_post','ampforwp_above_related_post_advert'); function ampforwp_above_related_post_advert() { global $redux_builder_amp; if($redux_builder_amp['enable-amp-ads-6'] == true) { if($redux_builder_amp['enable-amp-ads-select-6'] == 1) { $advert_width = '300'; $advert_height = '250'; } elseif ($redux_builder_amp['enable-amp-ads-select-6'] == 2) { $advert_width = '336'; $advert_height = '280'; } elseif ($redux_builder_amp['enable-amp-ads-select-6'] == 3) { $advert_width = '728'; $advert_height = '90'; } elseif ($redux_builder_amp['enable-amp-ads-select-6'] == 4) { $advert_width = '300'; $advert_height = '600'; } elseif ($redux_builder_amp['enable-amp-ads-select-6'] == 5) { $advert_width = '320'; $advert_height = '100'; } elseif ($redux_builder_amp['enable-amp-ads-select-6'] == 6) { $advert_width = '200'; $advert_height = '50'; } elseif ($redux_builder_amp['enable-amp-ads-select-6'] == 7) { $advert_width = '320'; $advert_height = '50'; } $output = '
'; $output .= ''; $output .= ''; $output .= '
'; echo $output; } } // 10. Analytics Area add_action('amp_post_template_footer','ampforwp_analytics',11); function ampforwp_analytics() { // 10.1 Analytics Support added for Google Analytics global $redux_builder_amp; if ( $redux_builder_amp['amp-analytics-select-option']=='1' ){ ?>
]*/', '', $content); $content = preg_replace('/vocab=[^>]*/', '', $content); // $content = preg_replace('/type=[^>]*/', '', $content); $content = preg_replace('/value=[^>]*/', '', $content); // $content = preg_replace('/date=[^>]*/', '', $content); $content = preg_replace('/noshade=[^>]*/', '', $content); $content = preg_replace('/contenteditable=[^>]*/', '', $content); // $content = preg_replace('/time=[^>]*/', '', $content); $content = preg_replace('/non-refundable=[^>]*/', '', $content); $content = preg_replace('/security=[^>]*/', '', $content); $content = preg_replace('/deposit=[^>]*/', '', $content); $content = preg_replace('/for=[^>]*/', '', $content); $content = preg_replace('/nowrap="nowrap"/', '', $content); $content = preg_replace('#(.*?)#i', '', $content); /*$content = preg_replace('#(.*?)#i', '', $content);*/ $content = preg_replace('#(.*?)#i', '', $content); $content = preg_replace('#(.*?)#i', '', $content); $content = preg_replace('##i', '', $content); $content = preg_replace('##i', '', $content); /* Removed So Inline style can work $content = preg_replace('##i', '', $content); */ $content = preg_replace('/href="javascript:void*/', ' ', $content); $content = preg_replace('/]*>.*?<\/script>/i', '', $content); //for removing attributes within html tags $content = preg_replace('/(<[^>]+) onclick=".*?"/', '$1', $content); /* Removed So Inline style can work $content = preg_replace('/(<[^>]+) style=".*?"/', '$1', $content); */ $content = preg_replace('/(<[^>]+) rel="(.*?) noopener(.*?)"/', '$1 rel="$2$3"', $content); $content = preg_replace('/]+) ref=".*?"/', '$1', $content); /*$content = preg_replace('/(<[^>]+) date=".*?"/', '$1', $content); $content = preg_replace('/(<[^>]+) time=".*?"/', '$1', $content); $content = preg_replace('/(<[^>]+) date/', '$1', $content);*/ $content = preg_replace('/(<[^>]+) imap=".*?"/', '$1', $content); $content = preg_replace('/(<[^>]+) spellcheck/', '$1', $content); $content = preg_replace('/(.*?)<\/font>/', '$2', $content); //removing scripts and rel="nofollow" from Body and from divs //issue #268 //$content = str_replace(' rel="nofollow"',"",$content); $content = preg_replace('/]*>.*?<\/script>/i', '', $content); /// simpy add more elements to simply strip tag but not the content as so /// Array ("p","font"); $tags_to_strip = Array("thrive_headline","type","place","state","city" ); $tags_to_strip = apply_filters('ampforwp_strip_bad_tags', $tags_to_strip); foreach ($tags_to_strip as $tag) { $content = preg_replace("/<\\/?" . $tag . "(.|\\s)*?>/",'',$content); } // regex on steroids from here on // issue #420 $content = preg_replace("/(.*)<\/div>/i", '
$11
', $content); $content = preg_replace('/(.*)<\/like>/i', '', $content); $content = preg_replace('/(.*)<\/g:plusone>/i', '', $content); $content = preg_replace('/imageanchor="1"/i', '', $content); $content = preg_replace('/(.*?)<\/plusone>/', '', $content); $content = preg_replace('/xml:lang=[^>]*/', '', $content); // $content = preg_replace('/ $content = preg_replace('/)<\/blockquote>/s', "$1", $content); return $content; } // 11.1 Strip unwanted codes and tags from wp_footer for better compatibility with Plugins if ( ! is_customize_preview() ) { add_action( 'pre_amp_render_post','ampforwp_strip_invalid_content_footer'); } function ampforwp_strip_invalid_content_footer() { add_filter( 'wp_footer', 'ampforwp_the_content_filter_footer', 1 ); } function ampforwp_the_content_filter_footer( $content ) { remove_all_actions('wp_footer'); return $content; } // 11.5 Strip unwanted codes the_content of Frontpage add_action( 'pre_amp_render_post','ampforwp_strip_invalid_content_frontpage'); function ampforwp_strip_invalid_content_frontpage(){ if ( is_front_page() || is_home() ) { add_filter( 'the_content', 'ampforwp_the_content_filter_frontpage', 20 ); } } function ampforwp_the_content_filter_frontpage( $content ) { $content = preg_replace('/ 'ImageObject', 'url' => $structured_data_logo , 'height' => $ampforwp_sd_height, 'width' => $ampforwp_sd_width, ); //code for adding 'description' meta from Yoast SEO if($redux_builder_amp['ampforwp-seo-yoast-description']){ if ( class_exists('WPSEO_Frontend') ) { $front = WPSEO_Frontend::get_instance(); $desc = $front->metadesc( false ); if ( $desc ) { $metadata['description'] = $desc; } // Code for Custom Frontpage Yoast SEO Description $post_id = $redux_builder_amp['amp-frontpage-select-option-pages']; if ( class_exists('WPSEO_Meta') ) { $custom_fp_desc = WPSEO_Meta::get_value('metadesc', $post_id ); if ( is_home() && $redux_builder_amp['amp-frontpage-select-option'] ) { if ( $custom_fp_desc ) { $metadata['description'] = $custom_fp_desc; } else { unset( $metadata['description'] ); } } } } } //End of code for adding 'description' meta from Yoast SEO return $metadata; } // 13. Add Custom Placeholder Image for Structured Data. // if there is no image in the post, then use this image to validate Structured Data. add_filter( 'amp_post_template_metadata', 'ampforwp_update_metadata_featured_image', 10, 2 ); function ampforwp_update_metadata_featured_image( $metadata, $post ) { global $redux_builder_amp; global $post; $post_id = get_the_ID() ; $post_image_id = get_post_thumbnail_id( $post_id ); $structured_data_image = wp_get_attachment_image_src( $post_image_id, 'full' ); $post_image_check = $structured_data_image; $structured_data_image_url = ''; if ( $post_image_check == false) { if (! empty( $redux_builder_amp['amp-structured-data-placeholder-image']['url'] ) ) { $structured_data_image_url = $redux_builder_amp['amp-structured-data-placeholder-image']['url']; } $structured_data_image = $structured_data_image_url; $structured_data_height = intval($redux_builder_amp['amp-structured-data-placeholder-image-height']); $structured_data_width = intval($redux_builder_amp['amp-structured-data-placeholder-image-width']); $metadata['image'] = array( '@type' => 'ImageObject', 'url' => $structured_data_image , 'height' => $structured_data_height, 'width' => $structured_data_width, ); } // Custom Structured Data information for Archive, Categories and tag pages. if ( is_archive() ) { $structured_data_image = $redux_builder_amp['amp-structured-data-placeholder-image']['url']; $structured_data_height = intval($redux_builder_amp['amp-structured-data-placeholder-image-height']); $structured_data_width = intval($redux_builder_amp['amp-structured-data-placeholder-image-width']); $structured_data_archive_title = "Archived Posts"; $structured_data_author = get_userdata( 1 ); if ( $structured_data_author ) { $structured_data_author = $structured_data_author->display_name ; } else { $structured_data_author = "admin"; } $metadata['image'] = array( '@type' => 'ImageObject', 'url' => $structured_data_image , 'height' => $structured_data_height, 'width' => $structured_data_width, ); $metadata['author'] = array( '@type' => 'Person', 'name' => $structured_data_author , ); $metadata['headline'] = $structured_data_archive_title; } if( in_array( "image" , $metadata ) ) { if ( $metadata['image']['width'] < 696 ) { $metadata['image']['width'] = 700 ; } } return $metadata; } // 14. Adds a meta box to the post editing screen for AMP on-off on specific pages. /** * Adds a meta box to the post editing screen for AMP on-off on specific pages */ function ampforwp_get_all_post_types(){ global $redux_builder_amp; $post_types = array('post' => 'post', 'page' => 'page'); if ( isset($redux_builder_amp['ampforwp-custom-type']) && $redux_builder_amp['ampforwp-custom-type'] ) { $post_types = array_merge($post_types, $redux_builder_amp['ampforwp-custom-type']); } return $post_types; } function ampforwp_title_custom_meta() { global $redux_builder_amp; $post_types = ampforwp_get_all_post_types(); if ( $post_types ) { // If there are any custom public post types. foreach ( $post_types as $post_type ) { if( $post_type == 'amp-cta' || $post_type == 'amp-optin' ) { continue; } if( $post_type !== 'page' ) { add_meta_box( 'ampforwp_title_meta', __( 'Show AMP for Current Page?','accelerated-mobile-pages' ), 'ampforwp_title_callback', $post_type,'side' ); } if( $redux_builder_amp['amp-on-off-for-all-pages'] && $post_type == 'page' ) { add_meta_box( 'ampforwp_title_meta', __( 'Show AMP for Current Page?' ,'accelerated-mobile-pages'), 'ampforwp_title_callback','page','side' ); } } } } add_action( 'add_meta_boxes', 'ampforwp_title_custom_meta' ); /** * Outputs the content of the meta box for AMP on-off on specific pages */ function ampforwp_title_callback( $post ) { wp_nonce_field( basename( __FILE__ ), 'ampforwp_title_nonce' ); $ampforwp_stored_meta = get_post_meta( $post->ID ); // TODO: Move the data storage code, to Save meta Box area as it is not a good idea to update an option everytime, try adding this code inside ampforwp_title_meta_save() // This code needs a rewrite. if ( ! isset($ampforwp_stored_meta['ampforwp-amp-on-off'][0]) || $ampforwp_stored_meta['ampforwp-amp-on-off'][0] == 'hide-amp') { $exclude_post_value = get_option('ampforwp_exclude_post'); if ( $exclude_post_value == null ) { $exclude_post_value[] = 0; } if ( $exclude_post_value ) { if ( ! in_array( $post->ID, $exclude_post_value ) ) { $exclude_post_value[] = $post->ID; update_option('ampforwp_exclude_post', $exclude_post_value); } } } else { $exclude_post_value = get_option('ampforwp_exclude_post'); if ( $exclude_post_value == null ) { $exclude_post_value[] = 0; } if ( $exclude_post_value ) { if ( in_array( $post->ID, $exclude_post_value ) ) { $exclude_ids = array_diff($exclude_post_value, array($post->ID) ); update_option('ampforwp_exclude_post', $exclude_ids); } } } ?>

ID ); // TODO: Move the data storage code, to Save meta Box area as it is not a good idea to update an option everytime, try adding this code inside ampforwp_title_meta_save() // This code needs a rewrite. if ( !isset($ampforwp_redirection_stored_meta['ampforwp-redirection-on-off'][0]) || $ampforwp_redirection_stored_meta['ampforwp-redirection-on-off'][0] == 'disable') { $exclude_post_value = get_option('ampforwp_exclude_post'); if ( $exclude_post_value == null ) { $exclude_post_value[] = 0; } if ( $exclude_post_value ) { if ( ! in_array( $post->ID, $exclude_post_value ) ) { $exclude_post_value[] = $post->ID; update_option('ampforwp_exclude_post', $exclude_post_value); } } } else { $exclude_post_value = get_option('ampforwp_exclude_post'); if ( $exclude_post_value == null ) { $exclude_post_value[] = 0; } if ( $exclude_post_value ) { if ( in_array( $post->ID, $exclude_post_value ) ) { $exclude_ids = array_diff($exclude_post_value, array($post->ID) ); update_option('ampforwp_exclude_post', $exclude_ids); } } } ?>

ID,'ampforwp-redirection-on-off',true); if ( empty( $ampforwp_redirection_post_on_off_meta ) ) { $ampforwp_redirection_post_on_off_meta = 'enable'; } return $ampforwp_redirection_post_on_off_meta; } /** * Saves the custom meta input for AMP on-off on specific pages */ function ampforwp_title_meta_save( $post_id ) { $ampforwp_amp_status = ''; // Checks save status $is_autosave = wp_is_post_autosave( $post_id ); $is_revision = wp_is_post_revision( $post_id ); $is_valid_nonce = ( isset( $_POST[ 'ampforwp_title_nonce' ] ) && wp_verify_nonce( $_POST[ 'ampforwp_title_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false'; // Exits script depending on save status if ( $is_autosave || $is_revision || !$is_valid_nonce ) { return; } // Checks for radio buttons and saves if needed if( isset( $_POST[ 'ampforwp-amp-on-off' ] ) ) { $ampforwp_amp_status = sanitize_text_field( $_POST[ 'ampforwp-amp-on-off' ] ); update_post_meta( $post_id, 'ampforwp-amp-on-off', $ampforwp_amp_status ); } if( isset( $_POST[ 'ampforwp-redirection-on-off' ] ) ) { $ampforwp_redirection_status = sanitize_text_field( $_POST[ 'ampforwp-redirection-on-off' ] ); update_post_meta( $post_id, 'ampforwp-redirection-on-off', $ampforwp_redirection_status ); } } add_action( 'save_post', 'ampforwp_title_meta_save' ); add_filter('amp_frontend_show_canonical','ampforwp_hide_amp_for_specific_pages'); function ampforwp_hide_amp_for_specific_pages($input){ global $post; $ampforwp_amp_status = get_post_meta($post->ID, 'ampforwp-amp-on-off', true); if ( $ampforwp_amp_status == 'hide-amp' ) { $input = false; } return $input; } // 15. Disable New Relic's extra script that its adds in AMP pages. add_action( 'amp_post_template_data', 'ampforwp_disable_new_relic_scripts' ); if ( ! function_exists('ampforwp_disable_new_relic_scripts') ) { function ampforwp_disable_new_relic_scripts( $data ) { if ( ! function_exists( 'newrelic_disable_autorum' ) ) { return $data; } if ( function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() ) { newrelic_disable_autorum(); } return $data; } } // 16. Remove Unwanted Scripts if ( function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() ) { add_action( 'wp_enqueue_scripts', 'ampforwp_remove_unwanted_scripts',20 ); } function ampforwp_remove_unwanted_scripts() { wp_dequeue_script('jquery'); } // Remove Print Scripts and styles function ampforwp_remove_print_scripts() { if ( ampforwp_is_amp_endpoint() ) { function ampforwp_remove_all_scripts() { global $wp_scripts; $wp_scripts->queue = array(); } add_action('wp_print_scripts', 'ampforwp_remove_all_scripts', 100); function ampforwp_remove_all_styles() { global $wp_styles; $wp_styles->queue = array(); } add_action('wp_print_styles', 'ampforwp_remove_all_styles', 100); // Remove Print Emoji for Nextgen Gallery support remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'wp_print_styles', 'print_emoji_styles' ); } } add_action( 'template_redirect', 'ampforwp_remove_print_scripts' ); // 17. Archives Canonical in AMP version // function ampforwp_rel_canonical_archive() { // // // $archivelink = esc_url( get_permalink( $id ) . AMPFORWP_AMP_QUERY_VAR . '/' ); // echo "\n"; // } // add_action( 'amp_post_template_head', 'ampforwp_rel_canonical_archive' ); // 18. Custom Canonical for Homepage // function ampforwp_rel_canonical() { // if ( !is_home() ) // return; // // $link = esc_url( get_permalink( $id ) . AMPFORWP_AMP_QUERY_VAR . '/' ); // $homelink = get_home_url(); // echo "\n"; // } // add_action( 'amp_post_template_head', 'ampforwp_rel_canonical' ); // 18.5. Custom Canonical for Frontpage // function ampforwp_rel_canonical_frontpage() { // if ( is_home() || is_front_page() ) // return; // // $link = esc_url( get_permalink( $id ) . AMPFORWP_AMP_QUERY_VAR . '/' ); // $homelink = get_home_url(); // echo "\n"; // } // add_action( 'amp_post_template_head', 'ampforwp_rel_canonical_frontpage' ); // 19. Remove Canonical tags function ampforwp_amp_remove_actions() { if ( is_home() || is_front_page() || is_archive() || is_search() ) { remove_action( 'amp_post_template_head', 'amp_post_template_add_canonical' ); } } add_action( 'amp_post_template_head', 'ampforwp_amp_remove_actions', 9 ); // 20. Remove the default Google font for performance // add_action( 'amp_post_template_head', function() { // remove_action( 'amp_post_template_head', 'amp_post_template_add_fonts' ); // }, 9 ); // 21. Remove Schema data from All In One Schema.org Rich Snippets Plugin add_action( 'pre_amp_render_post', 'ampforwp_remove_schema_data' ); function ampforwp_remove_schema_data() { remove_filter('the_content','display_rich_snippet'); // Ultimate Social Media PLUS Compatiblity Added remove_filter('the_content','sfsi_plus_beforaftereposts'); remove_filter('the_content','sfsi_plus_beforeafterblogposts'); // Thrive Content Builder $amp_custom_content_enable = get_post_meta( get_the_ID() , 'ampforwp_custom_content_editor_checkbox', true); if ($amp_custom_content_enable == 'yes') { remove_filter( 'the_content', 'tve_editor_content', 10 ); } // Removed GTranslate Flags from AMP pages #819 remove_filter('wp_nav_menu_items', 'gtranslate_menu_item', 10, 2); // Remove elements of WP Like Button plugin #841 remove_filter('the_content', 'fb_like_button'); remove_filter('the_excerpt', 'fb_like_button'); // Compatibility issue with the rocket lazy load #907 remove_filter( 'the_content' , 'rocket_lazyload_images', PHP_INT_MAX ); remove_filter( 'the_content', 'rocket_lazyload_iframes', PHP_INT_MAX ); add_filter( 'do_rocket_lazyload', '__return_false' ); // Remove Popups and other elements added by Slider-in Plugin define('WDSI_BOX_RENDERED', true, true); // Remove Filters added by third party plugin through class if ( function_exists('ampforwp_remove_filters_for_class')) { //Remove Disallowed 'like' tag from facebook Like button by Ultimate Facebook ampforwp_remove_filters_for_class( 'the_content', 'Wdfb_UniversalWorker', 'inject_facebook_button', 10 ); //Compatibility with Sassy Social Share Plugin ampforwp_remove_filters_for_class( 'the_content', 'Sassy_Social_Share_Public', 'render_sharing', 10 ); ampforwp_remove_filters_for_class( 'amp_post_template_head', 'Sassy_Social_Share_Public', 'frontend_scripts', 10 ); ampforwp_remove_filters_for_class( 'amp_post_template_css', 'Sassy_Social_Share_Public', 'frontend_inline_style', 10 ); ampforwp_remove_filters_for_class( 'amp_post_template_css', 'Sassy_Social_Share_Public', 'frontend_amp_css', 10 ); //Removing the Monarch social share icons from AMP ampforwp_remove_filters_for_class( 'the_content', 'ET_Monarch', 'display_inline', 10 ); ampforwp_remove_filters_for_class( 'the_content', 'ET_Monarch', 'display_media', 9999 ); //Compatibility with wordpress twitter bootstrap #525 ampforwp_remove_filters_for_class( 'the_content', 'ICWP_WPTB_CssProcessor_V1', 'run', 10 ); //Perfect SEO url + Yoast SEO Compatibility #982 ampforwp_remove_filters_for_class( 'wpseo_canonical', 'PSU', 'canonical', 10 ); //SiteOrigin Page builder compatibilty //Neglect SOPB If Custom AMP Editor is checked if ( $amp_custom_content_enable === 'yes') { ampforwp_remove_filters_for_class( 'the_content', 'SiteOrigin_Panels', 'generate_post_content', 10 ); } } //Removing the WPTouch Pro social share links from AMP remove_filter( 'the_content', 'foundation_handle_share_links_bottom', 100 ); //Removing the space added by the Google adsense #967 remove_filter( 'the_content', 'ga_strikable_add_optimized_adsense_code'); } // 22. Removing author links from comments Issue #180 if( ! function_exists( 'ampforwp_disable_comment_author_links' ) ) { function ampforwp_disable_comment_author_links( $author_link ){ $ampforwp_is_amp_endpoint = ampforwp_is_amp_endpoint(); if ( $ampforwp_is_amp_endpoint ) { return strip_tags( $author_link ); } else { return $author_link; } } add_filter( 'get_comment_author_link', 'ampforwp_disable_comment_author_links' ); } // 23. The analytics tag appears more than once in the document. This will soon be an error remove_action( 'amp_post_template_head', 'quads_amp_add_amp_ad_js'); // 24. Seperate Sticky Single Social Icons // TO DO: we can directly call social-icons.php instead of below code add_action('amp_post_template_footer','ampforwp_sticky_social_icons'); function ampforwp_sticky_social_icons(){ global $redux_builder_amp; include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); if( !is_plugin_active( 'amp-cta/amp-cta.php' ) ) { if($redux_builder_amp['enable-single-social-icons'] == true && is_single() ) { ?> ' ); } } else { if(isset($redux_builder_amp['ampforwp-seo-custom-additional-meta']) && $redux_builder_amp['ampforwp-seo-custom-additional-meta']){ echo strip_tags($redux_builder_amp['ampforwp-seo-custom-additional-meta'], '' ); } } } function ampforwp_custom_yoast_meta_homepage(){ global $redux_builder_amp; if ($redux_builder_amp['ampforwp-seo-yoast-meta']) { if(! class_exists('YoastSEO_AMP') ) { if ( class_exists('WPSEO_Options')) { if( method_exists('WPSEO_Options', 'get_option')){ $options = WPSEO_Options::get_option( 'wpseo_social' ); if ( $options['twitter'] === true ) { WPSEO_Twitter::get_instance(); } if ( $options['opengraph'] === true ) { $GLOBALS['wpseo_og'] = new WPSEO_OpenGraph; } } } do_action( 'wpseo_opengraph' ); }//execute only if Glue is deactive echo strip_tags($redux_builder_amp['ampforwp-seo-custom-additional-meta'], '' ); } } function ampforwp_add_proper_post_meta(){ $check_custom_front_page = get_option('show_on_front'); if ( $check_custom_front_page == 'page' ) { add_action( 'amp_post_template_head', 'ampforwp_custom_yoast_meta_homepage' ); if(is_home()){ add_filter('wpseo_opengraph_title', 'custom_twitter_title_homepage'); add_filter('wpseo_twitter_title', 'custom_twitter_title_homepage'); add_filter('wpseo_opengraph_desc', 'custom_twitter_description_homepage'); add_filter('wpseo_twitter_description', 'custom_twitter_description_homepage'); add_filter('wpseo_opengraph_url', 'custom_og_url_homepage'); // This is causing the 2nd debug issue reported in #740 // add_filter('wpseo_twitter_image', 'custom_og_image_homepage'); add_filter('wpseo_opengraph_image', 'custom_og_image_homepage'); } } else { add_action( 'amp_post_template_head', 'ampforwp_custom_yoast_meta' ); } } add_action('pre_amp_render_post','ampforwp_add_proper_post_meta'); function custom_twitter_title_homepage() { return esc_attr( get_bloginfo( 'name' ) ); } function custom_twitter_description_homepage() { return esc_attr( get_bloginfo( 'description' ) ); } function custom_og_url_homepage() { return esc_url( get_bloginfo( 'url' ) ); } function custom_og_image_homepage() { if ( class_exists('WPSEO_Options') ) { $options = WPSEO_Options::get_option( 'wpseo_social' ); return $options['og_default_image'] ; } } /** * PR by Sybre Waaijer: * @link https://github.com/ahmedkaludi/accelerated-mobile-pages/pull/761 * * @since version 0.9.48 : * 1. Removes unused code. * 2. Cleaned up code. * 3. Keeps legacy action in place. * 4. No longer replaces the title tag. * 5. Instead, filters the title tag. * 6. Therefore, it works with all SEO plugins. * 7. Removed direct Yoast SEO compat -- It's no longer needed. * 8. Removed unwanted spaces. * 9. Improved performance. * 10. Improved security. * 11. Added support for CPT and attachment pages. */ //26. Extending Title Tagand De-Hooking the Standard one from AMP add_action( 'pre_amp_render_post', 'ampforwp_remove_title_tags'); function ampforwp_remove_title_tags() { return ampforwp_replace_title_tags(); } function ampforwp_replace_title_tags() { add_filter( 'pre_get_document_title', 'ampforwp_add_custom_title_tag', 10 ); add_filter( 'wp_title', 'ampforwp_add_custom_title_tag', 10, 3 ); function ampforwp_add_custom_title_tag( $title = '', $sep = '', $seplocation = '' ) { global $redux_builder_amp; $site_title = ''; $genesis_title = ''; //* We can filter this later if needed: $sep = ' | '; if ( is_singular() ) { global $post; $title = ! empty( $post->post_title ) ? $post->post_title : $title; $site_title = $title . $sep . get_option( 'blogname' ); } elseif ( is_archive() && $redux_builder_amp['ampforwp-archive-support'] ) { $site_title = strip_tags( get_the_archive_title( '' ) . $sep . get_the_archive_description( '' ) ); } if ( is_home() ) { // Custom frontpage $site_title = get_bloginfo( 'name' ) . $sep . get_option( 'blogdescription' ); if( get_option( 'page_on_front' ) && $redux_builder_amp['amp-frontpage-select-option'] ){ $ID = $redux_builder_amp['amp-frontpage-select-option-pages']; $site_title = get_the_title( $ID ) . $sep . get_option( 'blogname' ); } // Blog page if ( get_option( 'page_for_posts' ) && get_queried_object_id() ) { $ID = get_option( 'page_for_posts' ); $site_title = get_the_title( $ID ) . $sep . get_option( 'blogname' ); } } if ( is_search() ) { $site_title = $redux_builder_amp['amp-translator-search-text'] . ' ' . get_search_query(); } //Genesis #1013 if(function_exists('genesis_title')){ if(is_home() && is_front_page() && !$redux_builder_amp['amp-frontpage-select-option']){ // Determine the doctitle. $genesis_title = genesis_get_seo_option( 'home_doctitle' ) ? genesis_get_seo_option( 'home_doctitle' ) : get_bloginfo( 'name' ); // Append site description, if necessary. $genesis_title = genesis_get_seo_option( 'append_description_home' ) ? $genesis_title . " $sep " . get_bloginfo( 'description' ) : $genesis_title; } elseif ( is_home() && get_option( 'page_for_posts' ) && get_queried_object_id() ) { $post_id = get_option( 'page_for_posts' ); if ( null !== $post_id || is_singular() ) { if ( genesis_get_custom_field( '_genesis_title', $post_id ) ) { $genesis_title = genesis_get_custom_field( '_genesis_title', $post_id ); } } } elseif( is_home() && get_option( 'page_on_front' ) && $redux_builder_amp['amp-frontpage-select-option'] ){ $post_id = get_option('page_on_front'); if ( null !== $post_id || is_singular() ) { if ( genesis_get_custom_field( '_genesis_title', $post_id ) ) { $genesis_title = genesis_get_custom_field( '_genesis_title', $post_id ); } } } else { $genesis_title = genesis_default_title( $title ); } if( $genesis_title ){ $site_title = $genesis_title; } } return esc_html( convert_chars( wptexturize( trim( $site_title ) ) ) ); } } add_action('amp_post_template_include_single','ampforwp_update_title_for_frontpage'); function ampforwp_update_title_for_frontpage() { $check_custom_front_page = get_option('show_on_front'); if ( $check_custom_front_page == 'page' && is_home() ) { remove_action( 'amp_post_template_head', 'amp_post_template_add_title' ); add_action('amp_post_template_head','ampforwp_frontpage_title_markup'); add_filter('aioseop_title','ampforwp_aioseop_front_page_title'); } } // Custom Frontpage title for ALL in one SEO. function ampforwp_aioseop_front_page_title() { $sep = ' | '; return $site_title = get_bloginfo( 'name' ) . $sep . get_option( 'blogdescription' ); } function ampforwp_frontpage_title_markup () { $front_page_title = ampforwp_add_custom_title_tag(); $front_page_title = apply_filters('ampforwp_frontpage_title_filter', $front_page_title); ?> <?php echo esc_html( $front_page_title ); ?> ]*/", "", $content_buffer); $content_buffer = preg_replace("/<\\/?thrive_headline(.|\\s)*?>/",'',$content_buffer); // Remove Extra styling added by other Themes/ Plugins $content_buffer = preg_replace('/((.*?)<\/style>)/','',$content_buffer); $content_buffer = preg_replace('/((.*?)<\/style>)(\/\*)/','$4',$content_buffer); $content_buffer = preg_replace("/<\\/?g(.|\\s)*?>/",'',$content_buffer); $content_buffer = preg_replace('/(<[^>]+) spellcheck="false"/', '$1', $content_buffer); $content_buffer = preg_replace('/(<[^>]+) spellcheck="true"/', '$1', $content_buffer); $content_buffer = preg_replace("/about:blank/", "#", $content_buffer); $content_buffer = preg_replace("/ '; echo apply_filters('ampforwp_modify_meta_viewport_filter',$output); } // 63. Frontpage Comments #682 function ampforwp_frontpage_comments() { global $redux_builder_amp; $data = get_option( 'ampforwp_design' ); $enable_comments = false; $post_id = ""; $post_id = $redux_builder_amp['amp-frontpage-select-option-pages']; if ($data['elements'] == '') { $data['elements'] = "meta_info:1,title:1,featured_image:1,content:1,meta_taxonomy:1,social_icons:1,comments:1,related_posts:1"; } if( isset( $data['elements'] ) || ! empty( $data['elements'] ) ){ $options = explode( ',', $data['elements'] ); }; if ($options): foreach ($options as $key=>$value) { switch ($value) { case 'comments:1': $enable_comments = true; break; } } endif; if ( $enable_comments ) { ?>
$postID, 'status' => 'approve' //Change this to the type of comments to be displayed )); $comment_button_url = get_permalink( $post_id ); $comment_button_url = apply_filters('ampforwp_frontpage_comments_url',$comment_button_url ); if ( $comments ) { ?>

    'post_date' , 'order' => 'DESC', 'post_id' => $postID, 'status' => 'approve', 'parent' =>0 ) ); $pages = ceil(count($total_comments)/AMPFORWP_COMMENTS_PER_PAGE); $pagination_args = array( 'base' => @add_query_arg('page','%#%'), 'format' => '?page=%#%', 'total' => $pages, 'current' => $page, 'show_all' => False, 'end_size' => 1, 'mid_size' => 2, 'prev_next' => True, 'prev_text' => ampforwp_translation($redux_builder_amp['amp-translator-previous-text'], 'Previous'), 'next_text' => ampforwp_translation( $redux_builder_amp['amp-translator-next-text'], 'Next'), 'type' => 'plain' ); // Display the list of comments function ampforwp_custom_translated_comment($comment, $args, $depth){ $GLOBALS['comment'] = $comment; global $redux_builder_amp; ?>
  • >
    %s '.ampforwp_translation($redux_builder_amp['amp-translator-says-text'],'says').':'), get_comment_author_link()) ?>
    \"'+.,:?=-]~"; $emoji_content = get_comment_text(); // $emoji_free_comments = preg_replace($pattern,'',$emoji_content); $emoji_content = wpautop( $emoji_content ); $sanitizer = new AMPFORWP_Content( $emoji_content, array(), apply_filters( 'ampforwp_content_sanitizers', array( 'AMP_Img_Sanitizer' => array(), 'AMP_Video_Sanitizer' => array() ) ) ); $sanitized_comment_content = $sanitizer->get_amp_content(); echo make_clickable( $sanitized_comment_content ); ?>
  • AMPFORWP_COMMENTS_PER_PAGE, //Allow comment pagination 'page' => $page, 'style' => 'li', 'type' => 'comment', 'max_depth' => 5, 'avatar_size' => 0, 'callback' => 'ampforwp_custom_translated_comment', 'reverse_top_level' => false //Show the latest comments at the top of the list ), $comments); echo paginate_links( $pagination_args );?>
.amp_cb_module{font-size:14px;line-height:1.5;margin-top:30px;margin-bottom:10px;padding:0 20px;} .amp_cb_module h4{margin:17px 0 6px 0;} .amp_cb_module p{margin: 8px 0px 10px 0px;} .amp_cb_blurb{text-align: center} .amp_cb_blurb amp-img{margin:0 auto;} .flex-grid {display:flex;justify-content: space-between;} .amp_module_title{text-align: center;font-size: 14px;margin-bottom: 12px;padding-bottom: 4px;text-transform: uppercase;letter-spacing: 1px;border-bottom: 1px solid #f1f1f1;} .clmn {flex: 1;padding: 5px} .amp_cb_btn{margin-top: 20px;text-align: center;margin-bottom: 30px;} .amp_cb_btn a{background: #f92c8b;color: #fff;font-size: 14px;padding: 9px 20px;border-radius: 3px;box-shadow: 1px 1px 4px #ccc;margin:6px;} .amp_cb_btn .m_btn{font-size: 16px; padding: 10px 20px;} .amp_cb_btn .l_btn{font-size: 18px; padding: 15px 48px;font-weight:bold;} @media (max-width: 430px) { .flex-grid {display: block;} } array(), 'AMP_YouTube_Embed_Handler' => array(), 'AMP_Instagram_Embed_Handler' => array(), 'AMP_Vine_Embed_Handler' => array(), 'AMP_Facebook_Embed_Handler' => array(), 'AMP_Gallery_Embed_Handler' => array(), ) ), apply_filters( 'amp_content_sanitizers', array( 'AMP_Style_Sanitizer' => array(), 'AMP_Blacklist_Sanitizer' => array(), 'AMP_Img_Sanitizer' => array(), 'AMP_Video_Sanitizer' => array(), 'AMP_Audio_Sanitizer' => array(), 'AMP_Iframe_Sanitizer' => array( 'add_placeholder' => true, ), ) ) ); $sidebar_data['content'] = $sanitized_sidebar->get_amp_content(); $sidebar_data['script'] = $sanitized_sidebar->get_amp_scripts(); $sidebar_data['style'] = $sanitized_sidebar->get_amp_styles(); return $sidebar_data; } function ampforwp_builder_checker() { global $post, $redux_builder_amp; $pagebuilder_check = ''; $post_id = ''; $post_id = $post->ID; if ( is_home() ) { $post_id = $redux_builder_amp['amp-frontpage-select-option-pages']; } $pagebuilder_check = get_post_meta( $post_id,'ampforwp_custom_sidebar_select',true); if ( $pagebuilder_check === 'layout-builder' ) { return ampforwp_generate_pagebuilder_data(); } return; } add_filter( 'amp_post_template_data', 'ampforwp_add_pagebuilder_data' ); function ampforwp_add_pagebuilder_data( $data ) { $sanitized_data = ''; $sanitized_data = ampforwp_builder_checker(); if ( $sanitized_data ) { $data[ 'post_amp_content' ] = $sanitized_data['content']; $data[ 'amp_component_scripts' ] = $sanitized_data['script']; $data[ 'post_amp_styles' ] = $sanitized_data['style']; } return $data; } /** * 65. Remove Filters code added through Class by other plugins * * Allow to remove method for an hook when, it's a class method used and class don't have variable, but you know the class name :) * Code from https://github.com/herewithme/wp-filters-extras */ function ampforwp_remove_filters_for_class( $hook_name = '', $class_name ='', $method_name = '', $priority = 0 ) { global $wp_filter; // Take only filters on right hook name and priority if ( !isset($wp_filter[$hook_name][$priority]) || !is_array($wp_filter[$hook_name][$priority]) ) return false; // Loop on filters registered foreach( (array) $wp_filter[$hook_name][$priority] as $unique_id => $filter_array ) { // Test if filter is an array ! (always for class/method) if ( isset($filter_array['function']) && is_array($filter_array['function']) ) { // Test if object is a class, class and method is equal to param ! if ( is_object($filter_array['function'][0]) && get_class($filter_array['function'][0]) && get_class($filter_array['function'][0]) == $class_name && $filter_array['function'][1] == $method_name ) { // Test for WordPress >= 4.7 WP_Hook class (https://make.wordpress.org/core/2016/09/08/wp_hook-next-generation-actions-and-filters/) if( is_a( $wp_filter[$hook_name], 'WP_Hook' ) ) { unset( $wp_filter[$hook_name]->callbacks[$priority][$unique_id] ); } else { unset($wp_filter[$hook_name][$priority][$unique_id]); } } } } return false; } // BuddyPress Compatibility add_action('amp_init','ampforwp_allow_homepage_bp'); function ampforwp_allow_homepage_bp() { add_action( 'wp', 'ampforwp_remove_rel_on_bp' ); } function ampforwp_remove_rel_on_bp(){ if(function_exists('bp_is_activity_component')||function_exists('bp_is_members_component')||function_exists('bp_is_groups_component')) { if(bp_is_activity_component()|| bp_is_members_component() || bp_is_groups_component()){ remove_action( 'wp_head', 'amp_frontend_add_canonical'); remove_action( 'wp_head', 'ampforwp_home_archive_rel_canonical' ); } } } // Removing AMP from WPForo Forums Pages #592 add_action('amp_init','remove_rel_amp_from_forum'); function remove_rel_amp_from_forum(){ add_action('wp','ampforwp_remove_rel_on_forum'); } function ampforwp_remove_rel_on_forum(){ if(class_exists('wpForo')){ Global $post, $wpdb,$wpforo; $foid = $post->ID; $fid = $wpforo->pageid; if($foid==$fid){ remove_action( 'wp_head', 'amp_frontend_add_canonical'); remove_action( 'wp_head', 'ampforwp_home_archive_rel_canonical' ); } } } // 66. Make AMP compatible with Squirrly SEO add_action('pre_amp_render_post','ampforwp_remove_sq_seo'); function ampforwp_remove_sq_seo() { $ampforwp_sq_google_analytics = ''; $ampforwp_sq_amp_analytics = ''; if ( class_exists( 'SQ_Tools' ) ) { $ampforwp_sq_google_analytics = SQ_Tools::$options['sq_google_analytics']; $ampforwp_sq_amp_analytics = SQ_Tools::$options['sq_auto_amp']; } if ( $ampforwp_sq_google_analytics && $ampforwp_sq_amp_analytics ) { remove_action('amp_post_template_head','ampforwp_register_analytics_script', 20); } } //67 View Non AMP function ampforwp_view_nonamp(){ global $redux_builder_amp; global $post; $ampforwp_backto_nonamp = ''; if ( is_home() && get_option( 'page_for_posts' ) && get_queried_object_id() ) { $post_id = get_option('page_for_posts'); if($redux_builder_amp['amp-mobile-redirection']==1) $ampforwp_backto_nonamp = trailingslashit(get_permalink( $post_id )).'?nonamp=1'; else $ampforwp_backto_nonamp = trailingslashit(get_permalink( $post_id )); } elseif ( is_home() ) { if($redux_builder_amp['amp-mobile-redirection']==1) $ampforwp_backto_nonamp = trailingslashit(home_url()).'?nonamp=1' ; else $ampforwp_backto_nonamp = trailingslashit(home_url()) ; } if ( is_single() ){ if($redux_builder_amp['amp-mobile-redirection']==1) $ampforwp_backto_nonamp = trailingslashit(get_permalink( $post->ID )).'?nonamp=1' ; else $ampforwp_backto_nonamp = trailingslashit(get_permalink( $post->ID )) ; } if ( is_page() ){ if($redux_builder_amp['amp-mobile-redirection']==1) $ampforwp_backto_nonamp = trailingslashit(get_permalink( $post->ID )).'?nonamp=1'; else $ampforwp_backto_nonamp = trailingslashit(get_permalink( $post->ID )); } if( is_archive() ) { global $wp; if($redux_builder_amp['amp-mobile-redirection']==1){ $ampforwp_backto_nonamp = esc_url( untrailingslashit(home_url( $wp->request )).'?nonamp=1' ); $ampforwp_backto_nonamp = preg_replace('/\/amp\?nonamp=1/','/?nonamp=1',$ampforwp_backto_nonamp); } else{ $ampforwp_backto_nonamp = esc_url( untrailingslashit(home_url( $wp->request )) ); $ampforwp_backto_nonamp = preg_replace('/amp/','',$ampforwp_backto_nonamp); } } ?> '

' . __( 'Page:' ), 'after' => '

', 'link_before' => '', 'link_after' => '', 'next_or_number' => 'number', 'separator' => ' ', 'nextpagelink' => __( 'Next page' ), 'previouspagelink' => __( 'Previous page' ), 'pagelink' => '%', 'echo' => 1 ); $params = wp_parse_args( $args, $defaults ); /** * Filters the arguments used in retrieving page links for paginated posts. * @param array $params An array of arguments for page links for paginated posts. */ $r = apply_filters( 'ampforwp_post_pagination_args', $params ); $output = ''; if ( $multipage ) { if ( 'number' == $r['next_or_number'] ) { $output .= $r['before']; for ( $i = 1; $i <= $numpages; $i++ ) { $link = $r['link_before'] . str_replace( '%', $i, $r['pagelink'] ) . $r['link_after']; if ( $i != $page || ! $more && 1 == $page ) { $link = ampforwp_post_paginated_link_generator( $i ) . $link . ''; } /** * Filters the HTML output of individual page number links. * @param string $link The page number HTML output. * @param int $i Page number for paginated posts' page links. */ $link = apply_filters( 'ampforwp_post_pagination_link', $link, $i ); // Use the custom links separator beginning with the second link. $output .= ( 1 === $i ) ? ' ' : $r['separator']; $output .= $link; } $output .= $r['after']; } elseif ( $more ) { $output .= $r['before']; $prev = $page - 1; if ( $prev > 0 ) { $link = ampforwp_post_paginated_link_generator( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . ''; $output .= apply_filters( 'ampforwp_post_pagination_link', $link, $prev ); } $next = $page + 1; if ( $next <= $numpages ) { if ( $prev ) { $output .= $r['separator']; } $link = ampforwp_post_paginated_link_generator( $next ) . $r['link_before'] . $r['nextpagelink'] . $r['link_after'] . ''; $output .= apply_filters( 'ampforwp_post_pagination_link', $link, $next ); } $output .= $r['after']; } } /** * Filters the HTML output of page links for paginated posts. * @param string $output HTML output of paginated posts' page links. * @param array $args An array of arguments. */ $html = apply_filters( 'ampforwp_post_pagination', $output, $args ); if($redux_builder_amp['amp-pagination']) { if ( $r['echo'] ) { echo $html; } return $html; } } /** * Helper function for ampforwp_post_pagination(). * @access private * * @global WP_Rewrite $wp_rewrite * * @param int $i Page number. * @return string Link. */ function ampforwp_post_paginated_link_generator( $i ) { global $wp_rewrite; $post = get_post(); $query_args = array(); if ( 1 == $i ) { $url = get_permalink(); } else { if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) ) $url = add_query_arg( 'page', $i, get_permalink() ); elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID ) $url = trailingslashit(get_permalink()) . user_trailingslashit("$wp_rewrite->pagination_base/" . $i, 'single_paged'); else $url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged'); } if ( is_preview() ) { if ( ( 'draft' !== $post->post_status ) && isset( $_GET['preview_id'], $_GET['preview_nonce'] ) ) { $query_args['preview_id'] = wp_unslash( $_GET['preview_id'] ); $query_args['preview_nonce'] = wp_unslash( $_GET['preview_nonce'] ); } $url = get_preview_post_link( $post, $query_args, $url ); } return ''; } add_filter('ampforwp_modify_rel_canonical','ampforwp_modify_rel_amphtml_paginated_post'); function ampforwp_modify_rel_amphtml_paginated_post($url) { if(is_single()){ $post_paginated_page=''; $post_paginated_page = get_query_var('page'); if($post_paginated_page){ $url = get_permalink(); $new_url = $url."$post_paginated_page/?amp"; return $new_url; } } return $url; } add_action('amp_post_template_head','ampforwp_modify_rel_canonical_paginated_post',9); function ampforwp_modify_rel_canonical_paginated_post(){ if(is_single()){ $post_paginated_page=''; $post_paginated_page = get_query_var('page'); if($post_paginated_page){ remove_action( 'amp_post_template_head', 'amp_post_template_add_canonical' ); add_action('amp_post_template_head','ampforwp_rel_canonical_paginated_post'); } } } function ampforwp_rel_canonical_paginated_post(){ $post_paginated_page=''; $new_canonical_url = ''; global $post; $current_post_id = $post->ID; $new_canonical_url = get_permalink($current_post_id); $new_canonical_url = trailingslashit($new_canonical_url); $post_paginated_page = get_query_var('page'); if($post_paginated_page){?> 'post', ); $get_categories_from_checkbox = $redux_builder_amp['hide-amp-categories']; if($get_categories_from_checkbox){ $get_selected_cats = array_filter($get_categories_from_checkbox); foreach ($get_selected_cats as $key => $value) { $selected_cats[] = $key; } } if ( ! empty($get_selected_cats)) { $posts = get_posts( array( 'category' => $selected_cats, 'numberposts' => '-1', 'post_type' => $args, 'post_status' => 'publish', 'suppress_filters' => false ) ); } if ( $posts ) { foreach ($posts as $post) { $post_id_array[] = $post->ID; } } return $post_id_array; } add_filter( 'amp_skip_post', 'ampforwp_cat_specific_skip_amp_post', 10, 3 ); function ampforwp_cat_specific_skip_amp_post( $skip, $post_id, $post ) { $list_of_posts = ''; $skip_this_post = ''; $list_of_posts = ampforwp_posts_to_remove(); $skip_this_post = in_array($post_id, $list_of_posts); if( $skip_this_post ) { $skip = true; remove_action( 'wp_head', 'ampforwp_home_archive_rel_canonical' ); // #999 Disable mobile redirection remove_action( 'template_redirect', 'ampforwp_page_template_redirect', 30 ); } return $skip; } add_action('amp_post_template_head','ampforwp_rel_canonical_home_archive'); function ampforwp_rel_canonical_home_archive(){ global $redux_builder_amp; global $wp; $current_archive_url = ''; $amp_url = ''; $remove = ''; $query_arg_array = ''; $page = '' ; if ( is_home() || is_front_page() || is_archive() && $redux_builder_amp['ampforwp-archive-support'] ) { $current_archive_url = home_url( $wp->request ); $amp_url = trailingslashit($current_archive_url); $remove = '/'. AMPFORWP_AMP_QUERY_VAR; $amp_url = str_replace($remove, '', $amp_url); $query_arg_array = $wp->query_vars; if( array_key_exists( "page" , $query_arg_array ) ) { $page = $wp->query_vars['page']; } if ( $page >= '2') { $amp_url = trailingslashit( $amp_url . '?page=' . $page); } ?> ID; } if ( $redux_builder_amp['amp-frontpage-select-option']) { if ( is_home() && is_front_page() ) { $post_id = $redux_builder_amp['amp-frontpage-select-option-pages']; } elseif ( is_home() ){ $post_id = $redux_builder_amp['amp-frontpage-select-option-pages']; } } return $post_id; } function ampforwp_the_body_class(){ echo 'post-id-' . ampforwp_get_body_class(); } // 72. Blacklist Sanitizer Added back #1024 add_filter('amp_content_sanitizers', 'ampforwp_add_blacklist_sanitizer'); function ampforwp_add_blacklist_sanitizer($data){ // Blacklist Sanitizer Added back until we find a better solution to replace it $data['AMP_Blacklist_Sanitizer'] = array(); return $data; } //Meta description #1013 function ampforwp_generate_meta_desc(){ global $post; global $redux_builder_amp; $front = ''; $desc = ''; $post_id = ''; $genesis_description = ''; if($redux_builder_amp['ampforwp-seo-yoast-description']){ if ( class_exists('WPSEO_Frontend') ) { // general Description of everywhere $front = WPSEO_Frontend::get_instance(); $desc = addslashes( strip_tags( $front->metadesc( false ) ) ); // Static front page // Code for Custom Frontpage Yoast SEO Description $post_id = $redux_builder_amp['amp-frontpage-select-option-pages']; if ( class_exists('WPSEO_Meta') ) { if ( is_home() && $redux_builder_amp['amp-frontpage-select-option'] ) { $desc = addslashes( strip_tags( WPSEO_Meta::get_value('metadesc', $post_id ) ) ); } } } // for search if( is_search() ) { $desc = addslashes( ampforwp_translation($redux_builder_amp['amp-translator-search-text'], 'You searched for:') . ' ' . get_search_query() ); } } else { if( is_home() ) { // normal home page $desc= addslashes( strip_tags( get_bloginfo( 'description' ) ) ); } if( is_archive() ) { $desc= addslashes( strip_tags( get_the_archive_description() ) ); } if( is_single() || is_page() ) { if( has_excerpt() ){ $desc = get_the_excerpt(); } else { global $post; $id = $post->ID; $desc = get_post($id)->post_content; } $desc = addslashes( wp_trim_words( strip_tags( $desc ) , '15' ) ); } if( is_search() ) { $desc = addslashes( ampforwp_translation($redux_builder_amp['amp-translator-search-text'], 'You searched for:') . ' ' . get_search_query() ); } if( is_home() && $redux_builder_amp['amp-frontpage-select-option'] ) { $post_id = $redux_builder_amp['amp-frontpage-select-option-pages'] ; $desc = addslashes( wp_trim_words( strip_tags( get_post_field('post_content', $post_id) ) , '15' ) ); } } //Genesis #1013 if(function_exists('genesis_meta')){ if(is_home() && is_front_page() && !$redux_builder_amp['amp-frontpage-select-option']){ $genesis_description = genesis_get_seo_option( 'home_description' ) ? genesis_get_seo_option( 'home_description' ) : get_bloginfo( 'description' ); } elseif ( is_home() && get_option( 'page_for_posts' ) && get_queried_object_id() ) { $post_id = get_option( 'page_for_posts' ); if ( null !== $post_id || is_singular() ) { if ( genesis_get_custom_field( '_genesis_description', $post_id ) ) { $genesis_description = genesis_get_custom_field( '_genesis_description', $post_id ); if($genesis_description){ $desc = $genesis_description; } } } } elseif(is_home() && $redux_builder_amp['amp-frontpage-select-option'] && get_option( 'page_on_front' )){ $post_id = get_option('page_on_front'); if ( null !== $post_id || is_singular() ) { if ( genesis_get_custom_field( '_genesis_description', $post_id ) ) { $genesis_description = genesis_get_custom_field( '_genesis_description', $post_id ); } } } else{ $genesis_description = genesis_get_seo_meta_description(); } if($genesis_description){ $desc = $genesis_description; } } return $desc; } //Compatibility with WP User Avatar #975 function ampforwp_get_wp_user_avatar(){ include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); if(is_plugin_active( 'wp-user-avatar/wp-user-avatar.php' )){ if(class_exists('WP_User_Avatar_Functions')){ $user_avatar_url = ''; $user_avatar_url = get_wp_user_avatar_src(); return $user_avatar_url; } } } add_filter('get_amp_supported_post_types','ampforwp_supported_post_types'); function ampforwp_supported_post_types($supported_types){ global $redux_builder_amp; include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); if( is_plugin_active( 'amp-custom-post-type/amp-custom-post-type.php' ) ) { if ( $redux_builder_amp['ampforwp-custom-type'] ) { foreach($redux_builder_amp['ampforwp-custom-type'] as $custom_post){ $supported_types[] = $custom_post; } } } if( is_plugin_active( 'amp-woocommerce/amp-woocommerce.php' ) ) { if( !in_array("product", $supported_types) ){ $supported_types[]= 'product'; } } return $supported_types; } function is_category_amp_disabled(){ global $redux_builder_amp; if(is_archive() && $redux_builder_amp['ampforwp-archive-support']==1){ $categories = get_the_category(); $category_id = $categories[0]->cat_ID; $get_categories_from_checkbox = $redux_builder_amp['hide-amp-categories']; // Check if $get_categories_from_checkbox has some cats then only show if ( $get_categories_from_checkbox ) { $get_selected_cats = array_filter($get_categories_from_checkbox); foreach ($get_selected_cats as $key => $value) { $selected_cats[] = $key; } if($selected_cats && $category_id){ if(in_array($category_id, $selected_cats)){ return true; } else return false; } } } }