ID; } if ( get_option( 'page_for_posts') == $current_page ) { return false ; } return true; } return false ; } function ampforwp_is_home(){ global $redux_builder_amp; $output = false; if ( ampforwp_is_front_page() == false && ampforwp_is_blog () == false && is_home() ) { $output = true; } return $output; } function ampforwp_is_blog(){ $get_blog_details = ""; $get_blog_details = ampforwp_get_blog_details(); return $get_blog_details ; } // Polylang frontpage function ampforwp_polylang_front_page() { include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); if( is_plugin_active( 'polylang/polylang.php' ) || is_plugin_active( 'polylang-pro/polylang.php' ) ){ global $polylang; $page_id = $polylang->curlang->page_on_front; $frontpage_id = get_option('page_on_front'); // is_front_page is not working here so had to do this way // Check current page id with translated page id if ( function_exists('pll_get_post') && $page_id == pll_get_post($frontpage_id) && ! is_page() && ! is_single() && ! is_archive() && ! is_search() && ! ampforwp_is_blog() ){ return true; } } return false; } // Get The ID for AMP #2867 function ampforwp_get_the_ID($post_id=''){ $post_id = get_the_ID(); if(ampforwp_is_front_page()){ $post_id = ampforwp_get_frontpage_id(); } if(ampforwp_is_blog()){ $post_id = ampforwp_get_blog_details('id'); } return $post_id; } // Backward Compatibility function ampforwp_correct_frontpage() { return ampforwp_get_frontpage_id(); } //Common function to get frontpageID function ampforwp_get_frontpage_id() { $post_id = ''; if ( ampforwp_is_front_page() ) { $post_id = ampforwp_get_setting('amp-frontpage-select-option-pages'); } $post_id = apply_filters('ampforwp_modify_frontpage_id', $post_id); return $post_id; } // 27. Clean the Defer issue // TODO : Get back to this issue. #407 function ampforwp_the_content_filter_full( $content_buffer ) { if ((!is_plugin_active('amp/amp.php') && function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() ) || (function_exists('amp_activate') && function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() )) { $content_buffer = preg_replace("/' defer='defer/", "", $content_buffer); $content_buffer = preg_replace("/' defer onload='/", "", $content_buffer); $content_buffer = preg_replace("/' defer /", "", $content_buffer); $content_buffer = preg_replace("/onclick=[^>]*/", "", $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("/
$1 ".$nonampCss.""; $returnData = preg_replace($re, $subst, $returnData); $returnData = preg_replace( '/<\/amp-youtube>/', '', $returnData); $returnData = preg_replace_callback( '/<\/amp-iframe>/', function($matches){ return ''; }, $returnData); break; } return $returnData; } } // wp_update_nav_menu #3052 add_action('wp_update_nav_menu', 'ampforwp_wp_update_nav_menu', 10 , 1 ); if ( ! function_exists('ampforwp_wp_update_nav_menu') ) { function ampforwp_wp_update_nav_menu( $menu_id ) { if ( false != get_transient('ampforwp_header_menu') ) { delete_transient('ampforwp_header_menu'); } if ( false != get_transient('ampforwp_footer_menu') ) { delete_transient('ampforwp_footer_menu'); } } } // Delete Menu Transients on Saving AMP Settings #3052 if ( function_exists('ampforwp_menu_transient_on_save') ){ function ampforwp_menu_transient_on_save($redux_builder_amp, $this_transients_changed_values) { if ( isset($this_transients_changed_values['amp-design-selector']) ) { if ( false != get_transient('ampforwp_header_menu') ) { delete_transient('ampforwp_header_menu'); } if ( false != get_transient('ampforwp_footer_menu') ) { delete_transient('ampforwp_footer_menu'); } } } } add_action("redux/options/redux_builder_amp/saved",'ampforwp_menu_transient_on_save', 10, 2); // Protocol Remover if ( ! function_exists('ampforwp_remove_protocol') ) { function ampforwp_remove_protocol($url){ $url = preg_replace('#^https?://#', '', $url); return $url; } } // #3009 if ( ! function_exists('ampforwp_sanitize_i_amphtml') ) { function ampforwp_sanitize_i_amphtml($data){ if(empty($data)){ return $data; } $data = preg_replace_callback('/.i-amphtml-(.*?){(.*?)}/s',function($matches){ if(!empty($matched)){ return ''; } }, $data); return $data; } } function checkAMPforPageBuilderStatus($postId){ global $post; $postId = (is_object($post)? $post->ID: ''); if( ampforwp_is_front_page() ){ $postId = ampforwp_get_frontpage_id(); } if ( empty( $postId ) ) { $response = false; }else{ $ampforwp_pagebuilder_enable = get_post_meta($postId,'ampforwp_page_builder_enable', true); if( $ampforwp_pagebuilder_enable=='yes' && true == ampforwp_get_setting('ampforwp-pagebuilder')){ $response = true; }else{ $response = false; } $response = apply_filters( 'ampforwp_pagebuilder_status_modify', $response, $postId ); } return $response; } // Gallery Code #3296 function ampforwp_new_gallery_images($images_markup, $image, $markup_arr){ add_action('amp_post_template_css', 'ampforwp_additional_gallery_style'); add_filter('amp_post_template_data','ampforwp_carousel_bind_script'); add_action('amp_post_template_css', 'ampforwp_additional_style_carousel_caption'); return $images_markup; } if( ! function_exists( 'ampforwp_additional_gallery_style' ) ){ function ampforwp_additional_gallery_style(){ global $redux_builder_amp,$carousel_markup_all; $design_type = ''; $design_type = $redux_builder_amp['ampforwp-gallery-design-type']; if(isset($design_type) && $design_type!==''){ echo $carousel_markup_all[$design_type]['gallery_css']; } } } // amp-bind for carousel with captions function ampforwp_carousel_bind_script($data){ if( 1 == ampforwp_get_setting('ampforwp-gallery-design-type') || 2 == ampforwp_get_setting('ampforwp-gallery-design-type') ){ if ( empty( $data['amp_component_scripts']['amp-bind'] ) ) { $data['amp_component_scripts']['amp-bind'] = 'https://cdn.ampproject.org/v0/amp-bind-0.1.js'; } } if( 3 == ampforwp_get_setting('ampforwp-gallery-design-type') || true == ampforwp_get_setting('ampforwp-gallery-lightbox') ){ if ( empty( $data['amp_component_scripts']['amp-image-lightbox'] ) ) { $data['amp_component_scripts']['amp-image-lightbox'] = 'https://cdn.ampproject.org/v0/amp-image-lightbox-0.1.js'; } } return $data; } function ampforwp_new_thumbnail_images($amp_images, $uniqueid, $markup_arr){ if(!isset($markup_arr['carousel_with_thumbnail_html'])){return '';} $amp_thumb_image_buttons = ''; foreach ($amp_images as $key => $value) { $returnHtml = $markup_arr['carousel_with_thumbnail_html']; $returnHtml = str_replace('{{thumbnail}}', $value , $returnHtml); $returnHtml = str_replace('{{unique_id}}', $uniqueid , $returnHtml); $returnHtml = str_replace('{{unique_index}}', $key , $returnHtml); $amp_thumb_image_buttons[$key] = $returnHtml; } return $amp_thumb_image_buttons; } // Gallery Styling if( ! function_exists( 'ampforwp_additional_style_carousel_caption' ) ){ function ampforwp_additional_style_carousel_caption(){ ?> .collapsible-captions {--caption-height: 32px; --image-height: 100%; --caption-padding:1rem; --button-size: 28px; --caption-color: #f5f5f5;; --caption-bg-color: #111;} .collapsible-captions * { -webkit-tap-highlight-color: rgba(255, 255, 255, 0); box-sizing: border-box; } .collapsible-captions .amp-carousel-container {position: relative; width: 100%;} .collapsible-captions amp-img img {object-fit: contain; } .collapsible-captions figure { margin: 0; padding: 0; } .collapsible-captions figcaption { position: absolute; bottom: 0;width: 100%; max-height: var(--caption-height);margin-bottom:0; line-height: var(--caption-height); padding: 0 var(--button-size) 0 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: max-height 200ms cubic-bezier(0.4, 0, 0.2, 1); z-index: 1000; color: var(--caption-color); background: rgba(0, 0, 0, 0.6); } .collapsible-captions figcaption.expanded { line-height: inherit; white-space: normal; text-overflow: auto; max-height: 100px; overflow: auto; } .collapsible-captions figcaption:focus { outline: none; border: none; } .collapsible-captions figcaption span { display: block; position: absolute; top: calc((var(--caption-height) - var(--button-size)) / 2); right: 2px; width: var(--button-size); height: var(--button-size); line-height: var(--button-size); text-align: center; font-size: 12px; color: inherit; cursor: pointer; } figcaption{ margin-bottom: 20px; }