'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;
$number_of_comments = '';
if(isset($redux_builder_amp['ampforwp-number-of-comments'])){
$number_of_comments = $redux_builder_amp['ampforwp-number-of-comments'];
}
return $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', 1 );
}
$cpage_var = get_query_var('cpage');
if ( $cpage_var >= 1) :
remove_action( 'wp_head', 'ampforwp_home_archive_rel_canonical', 1 );
endif;
}
function ampforwp_amphtml_generator(){
global $redux_builder_amp;
global $wp, $post;
$post_id = '';
$endpoint_check = false;
$endpoint_check = $redux_builder_amp['amp-core-end-point'];
if( is_attachment() ) {
return;
}
if( is_home() && is_front_page() && !$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;
}
// #1192 Password Protected posts exclusion
if(post_password_required( $post )){
return;
}
// #2018 404 exclusion
if(is_404()){
return;
}
// #1443 AMP should be skip on the check out page
if(class_exists( 'WooCommerce' )){
if(function_exists('is_checkout') && is_checkout()){
return;
}
}
// no-amphtml for search
if(is_search()){
return;
}
// #872 no-amphtml if selected as hide from settings
if(is_archive() && $redux_builder_amp['ampforwp-archive-support']){
if(is_tag() && is_array($redux_builder_amp['hide-amp-tags-bulk-option'])) {
$all_tags = get_the_tags();
$tagsOnPost = array();
foreach ($all_tags as $tagskey => $tagsvalue) {
$tagsOnPost[] = $tagsvalue->term_id;
}
$get_tags_checkbox = array_keys(array_filter($redux_builder_amp['hide-amp-tags-bulk-option']));
if( count(array_intersect($get_tags_checkbox,$tagsOnPost))>0 ){
return;
}
}//tags area closed
$selected_cats = array();
$categories = get_the_category();
if ( $categories ) {
$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'] && ! is_home() && ! is_front_page() ) {
return;
}
if ( is_home() && ! ampforwp_is_blog() && !$redux_builder_amp['ampforwp-homepage-on-off-support'] ) {
return;
}
if ( ampforwp_is_blog() && ! $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($current_archive_url);
} else {
$amp_url = amp_get_permalink( get_queried_object_id() );
}
global $post;
if ( is_singular() ) {
$post_id = get_the_ID();
}
if ( ampforwp_is_blog() ) {
$post_id = ampforwp_get_blog_details('id');
}
$ampforwp_amp_post_on_off_meta = get_post_meta( $post_id,'ampforwp-amp-on-off',true);
if ( ( is_singular() || ampforwp_is_blog() ) && $ampforwp_amp_post_on_off_meta === 'hide-amp' ) {
//dont Echo anything
} else {
$supported_types = ampforwp_get_all_post_types();
$supported_types = apply_filters('get_amp_supported_post_types',$supported_types);
$type = get_post_type();
if(is_home() || is_front_page()){
if(isset($redux_builder_amp['ampforwp-homepage-on-off-support'])
&& $redux_builder_amp['ampforwp-homepage-on-off-support'] == 1
&& isset($redux_builder_amp['amp-on-off-for-all-posts'])
&& $redux_builder_amp['amp-on-off-for-all-posts'] == 0
&& isset($redux_builder_amp['amp-on-off-for-all-pages'])
&& $redux_builder_amp['amp-on-off-for-all-pages'] == 0 ){
$supported_types['post'] = 'post';
}
}
$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;
if ( null != $category_path && true != $endpoint_check) {
$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();
}
}
$amp_url = user_trailingslashit($amp_url);
if( is_search() ) {
$current_search_url =trailingslashit(get_home_url())."?amp=1&s=".get_search_query();
$amp_url = untrailingslashit($current_search_url);
}
$amp_url = ampforwp_url_purifier($amp_url);
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if( get_option('permalink_structure') && is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' )){
global $sitepress_settings, $wp;
if($sitepress_settings[ 'language_negotiation_type' ] == 3){
if( is_singular() ){
$wpml_url =get_permalink( get_queried_object_id() );
$explode_url = explode('/', $wpml_url);
$append_amp = 'amp';
array_splice( $explode_url, 5, 0, $append_amp );
$impode_url = implode('/', $explode_url);
$amp_url = untrailingslashit($impode_url);
}
if ( is_home() || is_archive() ){
global $wp;
$current_archive_url = home_url( $wp->request );
$explode_path = explode("/",$current_archive_url);
$inserted = array(AMPFORWP_AMP_QUERY_VAR);
$query_arg_array = $wp->query_vars;
if( array_key_exists( 'paged' , $query_arg_array ) ) {
array_splice( $explode_path, -3, 0, $inserted );
}
else{
array_splice( $explode_path, -1, 0, $inserted );
}
$impode_url = implode('/', $explode_path);
$amp_url = $impode_url;
}
}
}
$amp_url = apply_filters('ampforwp_modify_rel_canonical',$amp_url);
if( $supported_amp_post_types) {
return $amp_url;
}
}
return;
}
function ampforwp_home_archive_rel_canonical() {
$amp_url = "";
$amp_url = ampforwp_amphtml_generator();
if ( $amp_url ) {
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 ) {
global $redux_builder_amp;
// Custom Homepage and Archive file
$slug = array();
$current_url_in_pieces = array();
$ampforwp_custom_post_page = ampforwp_custom_post_page();
if ( 'single' === $type ) {
// Homepage and FrontPage
if ( is_home() || ( true == $redux_builder_amp['ampforwp-amp-takeover'] && is_front_page() ) ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/index.php';
}
if ( ampforwp_is_blog() ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/index.php';
}
if ( ampforwp_is_front_page() || ( true == $redux_builder_amp['ampforwp-amp-takeover'] && is_front_page() && $redux_builder_amp['amp-frontpage-select-option']) ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/frontpage.php';
}
// Archive Pages
if ( is_archive() && $redux_builder_amp['ampforwp-archive-support'] && 'single' === $type ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/archive.php';
}
// Search pages
if ( is_search() ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/search.php';
}
// 404 Pages #2042
if ( is_404() && 'single' === $type ) {
add_filter('ampforwp_modify_rel_url','ampforwp_404_canonical');
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/404.php';
}
}
// Custom Single file
/*if ( is_single() || is_page() ) {
if('single' === $type ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/single.php';
}
}*/
// Polylang compatibility
// For Frontpage
if ( 'single' === $type && ampforwp_polylang_front_page() && true == $redux_builder_amp['amp-frontpage-select-option'] ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/frontpage.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;
}
add_filter('amp_post_template_dir','ampforwp_new_dir');
function ampforwp_new_dir( $dir ) {
global $redux_builder_amp;
if ( 1 == $redux_builder_amp['amp-design-selector'] || 2 == $redux_builder_amp['amp-design-selector'] || 3 == $redux_builder_amp['amp-design-selector'] ) {
$dir = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector();
}
else {
$dir = AMPFORWP_CUSTOM_THEME;
}
return $dir;
}
//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
// Code updated and added the JS proper way #336
add_filter('amp_post_template_data','ampforwp_add_amp_social_share_script', 20);
function ampforwp_add_amp_social_share_script( $data ){
global $redux_builder_amp;
$social_check = $social_check_page = false;
if ( is_page() && isset($redux_builder_amp['ampforwp-page-social']) && $redux_builder_amp['ampforwp-page-social'] ) {
$social_check_page = true;
}
if ( '4' === $redux_builder_amp['amp-design-selector'] ) {
$social_check = true;
}
if ( '4' !== $redux_builder_amp['amp-design-selector'] && defined('AMPFORWP_DM_SOCIAL_CHECK') && 'true' === AMPFORWP_DM_SOCIAL_CHECK ) {
$social_check = true;
}
if( $redux_builder_amp['enable-single-social-icons'] == true || defined('AMPFORWP_DM_SOCIAL_CHECK') && AMPFORWP_DM_SOCIAL_CHECK === 'true' ) {
if( (is_single() || $social_check_page ) && is_socialshare_or_socialsticky_enabled_in_ampforwp() ) {
if ( empty( $data['amp_component_scripts']['amp-social-share'] ) ) {
$data['amp_component_scripts']['amp-social-share'] = 'https://cdn.ampproject.org/v0/amp-social-share-0.1.js';
}
}
}
// Facebook Like Script
if( true == $redux_builder_amp['ampforwp-facebook-like-button'] && (is_single() || $social_check_page ) && $social_check && (! checkAMPforPageBuilderStatus( get_the_ID() ) ) ){
if(empty($data['amp_component_scripts']['amp-facebook-like'])){
$data['amp_component_scripts']['amp-facebook-like'] = 'https://cdn.ampproject.org/v0/amp-facebook-like-0.1.js';
}
}
return $data;
}
// 6.1 Adding Analytics Scripts
add_filter('amp_post_template_data','ampforwp_register_analytics_script', 20);
function ampforwp_register_analytics_script( $data ){
global $redux_builder_amp;
if( true == $redux_builder_amp['ampforwp-ga-switch'] || true == $redux_builder_amp['ampforwp-Segment-switch'] || true == $redux_builder_amp['ampforwp-Quantcast-switch'] || true == $redux_builder_amp['ampforwp-comScore-switch'] || true == $redux_builder_amp['ampforwp-Yandex-switch'] || true == $redux_builder_amp['ampforwp-Chartbeat-switch']|| true == $redux_builder_amp['ampforwp-Alexa-switch'] || true == $redux_builder_amp['ampforwp-afs-analytics-switch'] ) {
if ( empty( $data['amp_component_scripts']['amp-analytics'] ) ) {
$data['amp_component_scripts']['amp-analytics'] = 'https://cdn.ampproject.org/v0/amp-analytics-0.1.js';
}
}
return $data;
}
add_filter( 'amp_post_template_data', 'ampforwp_add_amp_related_scripts', 20 );
function ampforwp_add_amp_related_scripts( $data ) {
global $redux_builder_amp;
// Adding Sidebar Script
if ( isset($redux_builder_amp['ampforwp-amp-menu']) && $redux_builder_amp['ampforwp-amp-menu'] && 4 != $redux_builder_amp['amp-design-selector'] ) {
if ( empty( $data['amp_component_scripts']['amp-sidebar'] ) ) {
$data['amp_component_scripts']['amp-sidebar'] = 'https://cdn.ampproject.org/v0/amp-sidebar-0.1.js';
}
}
return $data;
}
// 7. Footer for AMP Pages
//add_filter( 'amp_post_template_file', 'ampforwp_custom_footer', 10, 3 );
function ampforwp_custom_footer( $file, $type, $post ) {
if ( 'footer' === $type ) {
if ( 1 == $redux_builder_amp['amp-design-selector'] || 2 == $redux_builder_amp['amp-design-selector'] || 3 == $redux_builder_amp['amp-design-selector'] ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/footer.php';
}
else {
$file = AMPFORWP_CUSTOM_THEME .'/footer.php';
}
//$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/footer.php';
}
return $file;
}
add_action('ampforwp_global_after_footer','ampforwp_footer');
function ampforwp_footer() {
global $redux_builder_amp; ?>
';
$output .= '';
$output .= '';
$output .= '';
$output .= '';
$output .= '';
$output .= ''.$redux_builder_amp['ampforwp-ads-sponsorship-label'].'';
}
}
// Ads Optimize For Viewability
if( !function_exists('ampforwp_ad_optimize')){
function ampforwp_ad_optimize(){
global $redux_builder_amp;
$optimized_code = '';
if( isset( $redux_builder_amp['ampforwp-ads-data-loading-strategy'] ) && true == $redux_builder_amp['ampforwp-ads-data-loading-strategy']){
$optimized_code = 'data-loading-strategy="prefer-viewability-over-views"';
}
return $optimized_code;
}
}
// 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( false == $redux_builder_amp['amp-use-gtm-option'] ) {
if ( true == $redux_builder_amp['ampforwp-ga-switch'] ){
$ga_fields = array();
$ampforwp_ga_fields = array();
$ga_account = '';
$ga_account = $redux_builder_amp['ga-feild'];
$ga_account = str_replace(' ', '', $ga_account);
$ga_fields = array(
'vars'=>array(
'account'=>$ga_account,
),
'triggers'=> array(
'trackPageview'=> array(
'on'=>'visible',
'request'=>'pageview'
)
)
);
if ( isset($redux_builder_amp['ampforwp-ga-field-anonymizeIP']) && true == $redux_builder_amp['ampforwp-ga-field-anonymizeIP'] ) {
$ga_fields['vars']['anonymizeIP'] = 'true';
}
$ampforwp_ga_fields = json_encode( $ga_fields);
$ampforwp_ga_fields = apply_filters('ampforwp_advance_google_analytics', $ampforwp_ga_fields ); ?>
data-block-on-consent type="googleanalytics" id="analytics1">
data-block-on-consent type="segment">
data-block-on-consent src="">
data-block-on-consent type="quantcast">
data-block-on-consent type="comscore">
data-block-on-consent src="" />
data-block-on-consent src="" >
data-block-on-consent src="//sstatic1.histats.com/0.gif?&101" >
data-block-on-consent type="metrika">
data-block-on-consent type="chartbeat">
data-block-on-consent type="alexametrics">
99999)
$afs_server = 'www1';
if ($afs_account > 199999)
$afs_server = 'www2';
if ($afs_account > 299999)
$afs_server = 'www3';
if ($afs_account > 399999)
$afs_server = 'www4';
if ($afs_account > 499999)
$afs_server = 'www5';
if ($afs_account > 599999)
$afs_server = 'www6';
if ($afs_account > 699999)
$afs_server = 'www7';
if ($afs_account > 799999)
$afs_server = 'www8';
if ($afs_account > 899999)
$afs_server = 'www9';
if ($afs_account > 999999)
$afs_server = 'www10'; ?>
data-block-on-consent type="afsanalytics">
]*/', '', $content);
$content = preg_replace('/vocab=[^>]*/', '', $content);
// $content = preg_replace('/type=[^>]*/', '', $content);
$content = preg_replace('/(<[^>]+) value=[^>]*/', '$1', $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);
// Convert the Wistia embed into URL to build amp-wistia-player and remove unnecesarry wistia code
$content = preg_replace('/
';
}
return $output;
}
}
//AMP to WP Theme Analytics
add_action('wp_footer','ampforwp_nonamp_analytics');
if ( ! function_exists('ampforwp_nonamp_analytics') ) {
function ampforwp_nonamp_analytics() {
global $redux_builder_amp;
$ga_account = $redux_builder_amp['ga-feild'];
if ( ampforwp_is_non_amp("non_amp_check_convert") ) {
echo "
";
}
}
}
// Coauthors Compatibility #1895
add_filter('coauthors_posts_link', 'ampforwp_coauthors_links');
function ampforwp_coauthors_links($args){
global $redux_builder_amp;
if ( function_exists('ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() && true == $redux_builder_amp['ampforwp-archive-support']) {
$args['href'] = ampforwp_url_controller($args['href']);
}
return $args;
}
// amp-image-lightbox #1892
if ( ! function_exists('ampforwp_amp_img_lightbox') ) {
function ampforwp_amp_img_lightbox(){
echo '';
}
}
// New Image attributes for amp-image-lightbox #1892
add_filter('amp_img_attributes', 'ampforwp_img_new_attrs');
function ampforwp_img_new_attrs($attributes) {
global $redux_builder_amp;
if ( isset($redux_builder_amp['ampforwp-amp-img-lightbox']) && $redux_builder_amp['ampforwp-amp-img-lightbox'] ) {
$attributes['on'] = 'tap:amp-img-lightbox';
$attributes['role'] = 'button';
$attributes['tabindex'] = '0';
}
return $attributes;
}
// Facebook Comments script for AMP2WP
add_action('ampforwp_body_beginning', 'ampforwp_amp2wp_fb');
if ( ! function_exists('ampforwp_amp2wp_fb') ) {
function ampforwp_amp2wp_fb(){
global $redux_builder_amp;
if( ampforwp_is_non_amp() && isset($redux_builder_amp['ampforwp-amp-convert-to-wp']) && $redux_builder_amp['ampforwp-amp-convert-to-wp'] && ($redux_builder_amp['ampforwp-facebook-comments-support'] || $redux_builder_amp['ampforwp-facebook-like-button']) ) {
echo '
';
}
}
}
// Backward Compatibility
function ampforwp_correct_frontpage() {
return ampforwp_get_frontpage_id();
}
//Common function to get frontpageID
function ampforwp_get_frontpage_id() {
global $redux_builder_amp;
$post_id = '';
//$post_id = get_the_ID();
if ( ampforwp_is_front_page() && $redux_builder_amp['amp-frontpage-select-option']==1
&& isset( $redux_builder_amp['amp-frontpage-select-option-pages'] )
) {
$post_id = $redux_builder_amp['amp-frontpage-select-option-pages'];
}
$post_id = apply_filters('ampforwp_modify_frontpage_id', $post_id);
return $post_id;
}
// Removing AMPHTML Added by Facebook's Instant Article's Plugin #2043
add_action( 'wp', 'ampforwp_remove_instant_articles_amp_markup' );
function ampforwp_remove_instant_articles_amp_markup(){
if(class_exists('Instant_Articles_AMP_Markup')){
remove_action( 'wp_head', array('Instant_Articles_AMP_Markup', 'inject_link_rel') );
}
}
// #2042
function ampforwp_404_canonical(){
return home_url( $wp->request );
}
// #2001 removing unused JS from the Paginated Posts
add_filter('ampforwp_post_content_filter', 'ampforwp_paginated_post_content');
function ampforwp_paginated_post_content($content){
global $numpages;
if(is_single()){
if ( get_query_var( 'paged' ) ) {
$paged = get_query_var('paged');
} elseif ( get_query_var( 'page' ) ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}
if( $numpages >= 2 ){
return get_the_content();
}
}
return $content;
}
// GDPR Compliancy #2040
add_action('amp_init', 'ampforwp_gdpr_init');
if ( ! function_exists('ampforwp_gdpr_init') ) {
function ampforwp_gdpr_init() {
global $redux_builder_amp;
if ( isset($redux_builder_amp['amp-gdpr-compliance-switch']) && $redux_builder_amp['amp-gdpr-compliance-switch'] && ! is_admin() ) {
// Scripts
add_filter('amp_post_template_data' , 'ampforwp_gdpr_data');
// amp-consent
add_action('amp_footer_link' , 'ampforwp_gdpr_amp_consent' );
// CSS
add_action('amp_post_template_css' , 'ampforwp_gdpr_css');
}
}
}
// AMP GDPR compliancy Scripts
if ( ! function_exists('ampforwp_gdpr_data') ) {
function ampforwp_gdpr_data( $data ) {
global $redux_builder_amp;
if ( empty( $data['amp_component_scripts']['amp-consent'] ) ) {
$data['amp_component_scripts']['amp-consent'] = 'https://cdn.ampproject.org/v0/amp-consent-0.1.js';
}
if ( empty( $data['amp_component_scripts']['amp-form'] ) ) {
$data['amp_component_scripts']['amp-form'] = 'https://cdn.ampproject.org/v0/amp-form-0.1.js';
}
if ( empty( $data['amp_component_scripts']['amp-geo'] ) ) {
$data['amp_component_scripts']['amp-geo'] = 'https://cdn.ampproject.org/v0/amp-geo-0.1.js';
}
return $data;
}
}
// AMP GDPR compliancy amp-consent
if ( ! function_exists('ampforwp_gdpr_amp_consent') ) {
function ampforwp_gdpr_amp_consent() {
global $redux_builder_amp;
$headline = $accept = $reject = $settings = $user_data = $form_url = '';
$headline = $redux_builder_amp['amp-gdpr-compliance-headline-text'];
$accept = $redux_builder_amp['amp-gdpr-compliance-accept-text'];
$reject = $redux_builder_amp['amp-gdpr-compliance-reject-text'];
$settings = $redux_builder_amp['amp-gdpr-compliance-settings-text'];
$user_data = $redux_builder_amp['amp-gdpr-compliance-textarea'];
$form_url = admin_url('admin-ajax.php?action=amp_consent_submission');
$form_url = preg_replace('#^https?:#', '', $form_url);
$more_info = $redux_builder_amp['amp-gdpr-compliance-for-more-privacy-info'];
$privacy_page = '';
$privacy_button_text = '';
if(isset($redux_builder_amp['amp-gdpr-compliance-select-privacy-page']) && $redux_builder_amp['amp-gdpr-compliance-select-privacy-page']){
$privacy_page = get_permalink($redux_builder_amp['amp-gdpr-compliance-select-privacy-page']);}
if(isset($redux_builder_amp['amp-gdpr-compliance-privacy-page-button-text']) && $redux_builder_amp['amp-gdpr-compliance-privacy-page-button-text']){
$privacy_button_text = $redux_builder_amp['amp-gdpr-compliance-privacy-page-button-text'];
}
$gdpr_countries = array("AT","BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", "HU", "IS", "IE", "IT", "LV", "LI", "LT", "LU", "MT", "NL", "NO", "PL", "PT", "RO", "SK", "SI", "ES", "SE", "GB", "AX", "IC", "EA", "GF", "PF", "TF", "GI", "GP", "GG", "JE", "MQ", "YT", "NC", "RE", "BL", "MF", "PM", "SJ", "VA", "WF", "EZ", "CH");
$gdpr_countries = apply_filters( 'ampforwp_gdpr_country_list' , $gdpr_countries );
?>
.gdpr{position: fixed; top: 0; bottom: 0; left: 0; right: 0; background: rgba(0, 0, 0, 0.7);color: #333;z-index:9999999;line-height:1.3}
.gdpr_w{padding: 2rem;background: #fff;max-width: 700px;width: 95%;position: relative;margin: 5% auto;text-align: center;}
.gdpr_t{margin-bottom:15px;}
.gdpr_t h3{font-size: 30px;margin:0px 0 10px 0;}
.gdpr_t p{font-size: 16px;line-height: 1.45;margin:0;}
.gdpr_x {position: absolute; right: 24px; top: 16px; cursor:pointer;}
.gdpr_yn{margin-top:10px;}
.gdpr_yn form{display: inline;}
.gdpr_yn button{background: #37474F;border: none;color: #fff;padding: 8px 30px;font-size: 13px;margin: 0 3px;}
.gdpr_yn .gdpr_n{background: #fff;color: #222;border: 1px solid #999;}
amp-consent{position: relative;margin-left: 10px;top: 2px;width: auto;background: transparent;}
.gdpr_fmi{
width:100%;
font-size: 15px;
line-height: 1.45;
margin: 0;
}
#footer .gdpr_fmi span, .gdpr_fmi span {
display: inline-block;
}
#footer .gdpr_fmi a{
color: ;
}
@media(max-width:768px){
.gdpr_w{width: 85%;margin:0 auto;padding:1.5rem;}
}
.gdpr{position: fixed; top: 0; bottom: 0; left: 0; right: 0;}
.gdpr_w{padding:20px 40px;background: #383B75;width: 95%;position: relative;margin: 0% auto;display: inline-flex;}
.gdpr_t h3, .gdpr_fmi{
font-size: 16px;
color:#fff;
margin: 0;
font-weight: 400;
}
.gdpr_fmi a{
text-decoration:underline;
margin-left: 10px;
color:#fff;
opacity: .8;
}
.gdpr_fmi a:hover{
opacity: 1;
color:#fff;
}
.gdpr-l{
display: flex;
flex-direction: row;
align-items: center;
order: 0;
}
.gdpr_t, .gdpr_fmi{
display:inline-block;
}
.gdpr_t p{display:none;}
.gdpr_x {position: absolute;right: 18px;top: 6px; cursor:pointer;color: #fff;visibility: hidden;}
.gdpr_yn{
text-align: right;
order: 0;
flex-grow: 1;
}
.gdpr_yn form{display: inline;}
.gdpr_yn button{background: #FFFC26;border: none;color: #333;padding: 8px 40px;font-size: 15px;margin: 0 3px;font-weight: 600;cursor: pointer;}
.gdpr_yn .gdpr_n{background: transparent;}
amp-consent{position: relative;margin-left: 10px;top: 2px;width: auto;background: transparent;}
.gdpr_fmi span, .gdpr_fmi a:before{
display:none;
}
.gdpr-btns{
display:inline-flex;
align-items: center;
}
.gdpr_yn .acp{
order: 1;
}
.rej button{
font-size: 15px;
padding: 0;
font-weight: 500;
margin-right: 20px;
cursor: pointer;
color:#fff;
}
.rej button:hover{
text-decoration:underline;
}
@media(max-width:768px){
.gdpr-l{display:inline-block;}
.gdpr_fmi a{margin:0;}
.gdpr_t, .gdpr_fmi {
display: block;
line-height: 1.4;
}
.gdpr_w{padding:10px 15px;
display:inline-block;text-align:left;
}
.gdpr_yn {
margin-top: 10px;
text-align: center;
}
}
#ampforwpConsent{
left: 50%;
font-size: 13px;
top: -15px;
}
#ampforwpConsent a{
text-decoration:none;
}
amp-consent{background:none}
@media(max-width:425px){
#footer amp-consent a{font-size:12px;margin-top:7px;display:inline-block;}
}
.gdpr_fmi a:before{
display:none;
}
.gdpr_w{width:100%;}
.f-w-f2 {
padding: 50px 0px;
}
canonical(false);
}
elseif ( isset($redux_builder_amp['ampforwp-seo-aioseo-canonical']) && true == $redux_builder_amp['ampforwp-seo-aioseo-canonical'] && class_exists('All_in_One_SEO_Pack') ) {
$All_in_One_SEO_Pack = new All_in_One_SEO_Pack();
$opts = $All_in_One_SEO_Pack->get_current_options( array(), 'aiosp' );
$canonical = $opts['aiosp_custom_link'];
}
return $canonical;
}
add_filter('amp_post_template_data', 'ampforwp_modified_canonical', 85);
function ampforwp_modified_canonical( $data ) {
$canonical = '';
$canonical = ampforwp_generate_canonical();
if ( !empty($canonical) ) {
$data['canonical_url'] = $canonical;
}
return $data;
}
function ampforwp_get_data_consent(){
global $redux_builder_amp;
$dboc = false;
$is_dboc = '';
if(isset($redux_builder_amp['amp-gdpr-compliance-switch']) && $redux_builder_amp['amp-gdpr-compliance-switch'] ){
$dboc = true;
}
return $dboc;
}
function ampforwp_amp_consent_check($attrs){
if( ampforwp_get_data_consent() ){
$attrs['data-block-on-consent'] = '';
}
$attrs = apply_filters( 'ampforwp_embedd_attrs_handler', $attrs );
return $attrs;
}
// #2220 Remove Space Shortcode by Pro Theme from THEMCO
add_action('pre_amp_render_post','ampforwp_remove_space_shortcodes');
function ampforwp_remove_space_shortcodes(){
add_filter('the_content','ampforwp_remove_pro_theme_space_shortcodes');
}
function ampforwp_remove_pro_theme_space_shortcodes($content){
if(has_shortcode( $content, 'gap' )){
remove_shortcode( 'gap' );
// to remove the useless shortcode from the AMP Content
add_shortcode( 'gap', 'ampforwp_return_no_gap' );
}
return $content;
}
function ampforwp_return_no_gap(){
return;
}
/*
#2229 Function to check the option for comments to display on post, page or both.
*/
function ampforwp_get_comments_status(){
global $redux_builder_amp;
$display_comments_on = "";
if ( (isset($redux_builder_amp['ampforwp-display-on-pages']) && $redux_builder_amp['ampforwp-display-on-pages']==false ) && (isset($redux_builder_amp['ampforwp-display-on-posts']) && $redux_builder_amp['ampforwp-display-on-posts']==true ) ) {
$display_comments_on = is_single();
}
if ( (isset($redux_builder_amp['ampforwp-display-on-pages']) && $redux_builder_amp['ampforwp-display-on-pages']==true ) && (isset($redux_builder_amp['ampforwp-display-on-posts']) && $redux_builder_amp['ampforwp-display-on-posts']==false ) ) {
$display_comments_on = is_page();
}
if ( (isset($redux_builder_amp['ampforwp-display-on-pages']) && $redux_builder_amp['ampforwp-display-on-pages']==true ) && (isset($redux_builder_amp['ampforwp-display-on-posts']) && $redux_builder_amp['ampforwp-display-on-posts']==true ) ) {
$display_comments_on = is_singular();
}
$display_comments_on = apply_filters('ampforwp_comments_visibility', $display_comments_on);
return $display_comments_on;
}
// Vuukle Comments Support #2075
add_action('ampforwp_post_after_design_elements','ampforwp_vuukle_comments_support');
function ampforwp_vuukle_comments_support() {
global $redux_builder_amp;
if ( 4 != $redux_builder_amp['amp-design-selector']
&& isset($redux_builder_amp['ampforwp-vuukle-comments-support'])
&& $redux_builder_amp['ampforwp-vuukle-comments-support']==1
&& comments_open()
) {
echo ampforwp_vuukle_comments_markup();
}
}
function ampforwp_vuukle_comments_markup() {
global $redux_builder_amp;
$apiKey = $locale = '';
if( isset($redux_builder_amp['ampforwp-vuukle-comments-apiKey']) && $redux_builder_amp['ampforwp-vuukle-comments-apiKey'] !== ""){
$apiKey = $redux_builder_amp['ampforwp-vuukle-comments-apiKey'];
}
$display_comments_on = false;
$display_comments_on = ampforwp_get_comments_status();
$srcUrl = 'https://cdn.vuukle.com/amp.html?';
$srcUrl = add_query_arg('url' ,get_permalink(), $srcUrl);
$srcUrl = add_query_arg('host' ,site_url(), $srcUrl);
$srcUrl = add_query_arg('id' , $post->ID, $srcUrl);
$srcUrl = add_query_arg('apiKey' , $apiKey, $srcUrl);
$srcUrl = add_query_arg('title' , $post->post_title, $srcUrl);
$vuukle_html ='';
if ( $display_comments_on ) {
$vuukle_html .= '
Show comments
';
}
return $vuukle_html;
}
add_filter( 'amp_post_template_data', 'ampforwp_add_vuukle_scripts' );
function ampforwp_add_vuukle_scripts( $data ) {
global $redux_builder_amp;
$display_comments_on = "";
$display_comments_on = ampforwp_get_comments_status();
if ( 4 != $redux_builder_amp['amp-design-selector']
&& isset($redux_builder_amp['ampforwp-vuukle-comments-support'])
&& $redux_builder_amp['ampforwp-vuukle-comments-support']
&& $display_comments_on && comments_open()
) {
if ( empty( $data['amp_component_scripts']['amp-iframe'] ) ) {
$data['amp_component_scripts']['amp-iframe'] = 'https://cdn.ampproject.org/v0/amp-iframe-0.1.js';
}
if ($redux_builder_amp['ampforwp-vuukle-Ads-before-comments']==1
&& empty( $data['amp_component_scripts']['amp-ad'] ) ) {
$data['amp_component_scripts']['amp-ad'] = 'https://cdn.ampproject.org/v0/amp-ad-0.1.js';
}
}
return $data;
}
//spotim #2076
add_action('ampforwp_post_after_design_elements','ampforwp_spotim_comments_support');
function ampforwp_spotim_comments_support() {
global $redux_builder_amp;
if ( 4 != $redux_builder_amp['amp-design-selector']
&& isset($redux_builder_amp['ampforwp-spotim-comments-support'])
&& $redux_builder_amp['ampforwp-spotim-comments-support']==1
) {
echo ampforwp_spotim_comments_markup();
echo "called";die;
}
}
function ampforwp_spotim_comments_markup() {
global $post, $redux_builder_amp;
$display_comments_on = false;
$display_comments_on = ampforwp_get_comments_status();
if (! $display_comments_on ) {
return '';
}
$spotId ='';
if( isset($redux_builder_amp['ampforwp-spotim-comments-apiKey']) && $redux_builder_amp['ampforwp-spotim-comments-apiKey'] !== ""){
$spotId = $redux_builder_amp['ampforwp-spotim-comments-apiKey'];
}
$srcUrl = 'https://amp.spot.im/production.html?';
$srcUrl = add_query_arg('spotId' ,get_permalink(), $srcUrl);
$srcUrl = add_query_arg('postId' , $post->ID, $srcUrl);
$spotim_html = '
Load more...
';
return $spotim_html;
}
//spotim script
add_filter( 'amp_post_template_data', 'ampforwp_add_spotim_scripts' );
function ampforwp_add_spotim_scripts( $data ) {
global $redux_builder_amp;
$display_comments_on = "";
$display_comments_on = ampforwp_get_comments_status();
if ( 4 != $redux_builder_amp['amp-design-selector']
&& isset($redux_builder_amp['ampforwp-spotim-comments-support'])
&& $redux_builder_amp['ampforwp-spotim-comments-support']
&& $display_comments_on && comments_open()
) {
if ( empty( $data['amp_component_scripts']['amp-iframe'] ) ) {
$data['amp_component_scripts']['amp-iframe'] = 'https://cdn.ampproject.org/v0/amp-iframe-0.1.js';
}
}
return $data;
}
//spotim css
add_action('amp_post_template_css','ampforwp_spotim_vuukle_styling',60);
function ampforwp_spotim_vuukle_styling(){
global $redux_builder_amp;
$display_comments_on = "";
$display_comments_on = ampforwp_get_comments_status();
if ( isset($redux_builder_amp['ampforwp-spotim-comments-support'])
&& $redux_builder_amp['ampforwp-spotim-comments-support']
&& $display_comments_on && comments_open() ) {
?>.spot-im-amp-overflow {
background: white;
font-size: 15px;
padding: 15px 0;
text-align: center;
font-family: Helvetica, Arial, sans-serif;
color: #307fe2;
}
.afwp-vuukle-support{
display: block;text-align: center;background: #1f87e5;color: #fff;border-radius: 4px;
}