= 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 = ampforwp_get_setting('amp-core-end-point'); if( is_attachment() ) { return; } if(get_query_var('paged') && true == ampforwp_get_setting('amp-paginated-pages-indexing')) { return; } if( is_home() && is_front_page() && !ampforwp_get_setting('ampforwp-homepage-on-off-support') ) { return; } if( is_front_page() && ! ampforwp_get_setting('ampforwp-homepage-on-off-support') ) { return; } // HIDE/SHOW TAG AND CATEGORY #4326 if(is_tag() || is_category() || is_tax()){ $term_id = get_queried_object()->term_id; $tax_status = ampforwp_get_taxonomy_meta($term_id,'status'); if($tax_status==false){ return; } }else if(is_single()){ $tax_status = ampforwp_get_taxonomy_meta('','post_status'); if($tax_status==false){ return; } } // Skip this condition for woocommerce product archive and shop pages. if( function_exists('amp_woocommerce_pro_add_woocommerce_support') && (function_exists('is_product_category') && !is_product_category()) && (function_exists('is_product_tag') && !is_product_tag()) && (function_exists('is_shop') && !is_shop() ) ){ if( is_archive() && ( !ampforwp_get_setting('ampforwp-archive-support') || ( is_category() && !ampforwp_get_setting('ampforwp-archive-support-cat') ) || ( is_tag() && !ampforwp_get_setting('ampforwp-archive-support-tag') ))){ return; } } // When amp woocommerce pro plugin is not active. if ( is_archive() && !function_exists('amp_woocommerce_pro_add_woocommerce_support') ) { if(!ampforwp_get_setting('ampforwp-archive-support')){ return; } if( is_category() && !ampforwp_get_setting('ampforwp-archive-support-cat') ){ return; } if( is_tag() && !ampforwp_get_setting('ampforwp-archive-support-tag') ){ 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; } if(function_exists('is_account_page') && is_account_page()){ return; } } // Search results on/off option #3786 if(is_search() && 0 == ampforwp_get_setting('amp-redirection-search')){ return; } if(function_exists('yith_wishlist_constructor')){ $class = get_body_class(); if(in_array("woocommerce-wishlist", $class)){ return; } } // #872 no-amphtml if selected as hide from settings if ( is_category_amp_disabled() ) { return; } if ( is_page() && ! ampforwp_get_setting('amp-on-off-for-all-pages') && ! is_home() && ! is_front_page() ) { return; } if ( is_home() && ! ampforwp_is_blog() && !ampforwp_get_setting('ampforwp-homepage-on-off-support') ) { return; } if (!ampforwp_is_home() && !ampforwp_is_front_page() && !ampforwp_is_blog() && !is_category() && !is_tag() && !is_singular( array('page', 'attachment', 'post')) && !function_exists('amp_woocommerce_pro_add_woocommerce_support')){ global $post_type; if (empty(ampforwp_get_setting('ampforwp-custom-type'))) { return; } } $page_for_posts = intval(get_option( 'page_for_posts' )); $post_id = ampforwp_get_the_ID(); if ( ampforwp_is_blog() && ! ampforwp_get_setting('amp-on-off-for-all-pages') && ($page_for_posts != $post_id ) ) { 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 ); // If its custom permalink with /index.php/ #3279 if ( is_archive() && false !== strpos($wp->matched_rule, 'index.php') && false === strpos($current_archive_url, 'index.php') ) { $current_archive_url = home_url( 'index.php/' . $wp->request ); } $amp_url = trailingslashit($current_archive_url); if ($endpoint_check && (is_tax() || is_post_type_archive())) { $amp_url = ampforwp_url_controller($amp_url); } } else { $amp_url = AMPforWP\AMPVendor\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(); if(isset($supported_types['web-story'])){ $supported_types['web-story'] = ''; } $supported_types = apply_filters('get_amp_supported_post_types',$supported_types); $type = get_post_type(); if(is_home() || is_front_page()){ if( ampforwp_get_setting('ampforwp-homepage-on-off-support') == 1 && ampforwp_get_setting('amp-on-off-for-all-posts') == 0 && ampforwp_get_setting('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('/'); // If its custom permalink with /index.php/ #3537 if ( (is_home() || is_archive()) && false !== strpos($wp->matched_rule, 'index.php') && false === strpos( home_url( $wp->request ), 'index.php') ) { $new_url = home_url( 'index.php' ); $o_url = home_url(); $new_url = str_replace($o_url, $new_url, $amp_url); $new_url = user_trailingslashit($new_url); $amp_url = $new_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(); } } if (!$endpoint_check) { $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); } // URL Purifier if(!ampforwp_get_setting('amp-core-end-point') && !ampforwp_get_setting('ampforwp-amp-takeover')){ $amp_url = ampforwp_url_purifier($amp_url); } if(true == ampforwp_get_setting('amp-core-end-point') && (!is_home() && !is_front_page() && !is_archive())){ $amp_url = add_query_arg( 'amp', '', get_the_permalink() ); } $amp_url = apply_filters('ampforwp_modify_rel_canonical',$amp_url); if( $supported_amp_post_types || ampforwp_is_front_page() ) { if(true == ampforwp_get_setting('amp-core-end-point')){ if( class_exists('SitePress') ){ if( get_option('permalink_structure') ){ global $sitepress_settings, $wp; $wpml_lang_checker = false; if($sitepress_settings[ 'language_negotiation_type' ] == 3){ $amp_url = esc_url($amp_url); $active_langs = $sitepress_settings['active_languages']; foreach ($active_langs as $active_lang) { if (preg_match('/\?lang='.$active_lang.'/', $amp_url)){ $amp_url = preg_replace('/&amp=1/', '', $amp_url); $amp_url = preg_replace('/#038;amp/', '', $amp_url); $amp_url = str_replace('?lang='.$active_lang, '?amp=1', $amp_url); $amp_url = add_query_arg( 'lang',$active_lang, $amp_url); } } } } } } if (is_category() && class_exists('WPSEO_Options') && method_exists('WPSEO_Options', 'get') && WPSEO_Options::get( 'stripcategorybase' ) == true && false == ampforwp_get_setting('ampforwp-category-base-removel-link')) { return; } if (is_category() && class_exists('RankMath') && RankMath\Helper::get_settings( 'general.strip_category_base' ) == true && false == ampforwp_get_setting('ampforwp-category-base-removel-link')) { return; } if (is_preview()) { $amp_url = preg_replace('/(.*?)&(.*?)/', '$1&&$2', $amp_url); } if(ampforwp_get_setting('amp-core-end-point') && ampforwp_get_setting('ampforwp-amp-takeover') && is_singular()){ $amp_url = get_the_permalink(); }else if(ampforwp_get_setting('amp-core-end-point') && (ampforwp_is_home() || ampforwp_is_front_page() || ampforwp_is_blog() || is_category() || is_tag() || is_front_page())){ $amp_url = ampforwp_url_controller($amp_url); } return esc_url_raw($amp_url); } } return; } // AMPHTML when using custom page and then creating a blog page add_action('amp_init','ampforwp_allow_homepage_as_blog'); function ampforwp_allow_homepage_as_blog() { if(function_exists('mfn_opts_setup')){ remove_action( 'pre_get_posts', 'mfn_search' ); } add_action( 'wp', 'ampforwp_static_blog' , 11 ); } function ampforwp_static_blog(){ global $page; $modify_canonical = ampforwp_is_front_page(); $get_front_page_reading_settings = get_option('page_on_front'); // Homepage support on $get_amp_homepage_support = ampforwp_get_setting('ampforwp-homepage-on-off-support'); if ( 'page' == get_option( 'show_on_front') && is_front_page() && $get_front_page_reading_settings && $get_amp_homepage_support ){ $modify_canonical = true; } if ( true == $modify_canonical && $page >= 2 && is_page() && false == ampforwp_get_setting('amp-core-end-point') ) { add_filter('ampforwp_modify_rel_canonical','ampforwp_modify_amphtml_static_blog'); } } function ampforwp_modify_amphtml_static_blog($amp_url) { $explode_url = $amp_endpoint = $offset = ""; $explode_url = explode('/', $amp_url); $explode_url = array_flip($explode_url); unset($explode_url[AMPFORWP_AMP_QUERY_VAR]); $explode_url = array_flip($explode_url); $amp_endpoint = array(AMPFORWP_AMP_QUERY_VAR); $offset = count($explode_url) - 2; array_splice( $explode_url, $offset, 0, $amp_endpoint ); $amp_url = implode('/', $explode_url); return $amp_url; } function ampforwp_home_archive_rel_canonical() { $amp_url = ""; $amp_url = ampforwp_amphtml_generator(); if ( $amp_url ) { printf('', esc_url($amp_url)); if(false==ampforwp_get_setting('hide-amp-version-from-source')){ printf('', esc_html__('AMP for WP'), esc_attr(AMPFORWP_VERSION) ); } } } //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'; } $mob_pres_link = false; if(function_exists('ampforwp_mobile_redirect_preseve_link')){ $mob_pres_link = ampforwp_mobile_redirect_preseve_link(); } if ( ampforwp_is_front_page() || ( (true == ampforwp_get_setting('ampforwp-amp-takeover') || $mob_pres_link == true) && is_front_page() && ampforwp_get_setting('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'; } } // 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; } 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; } // 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 == ampforwp_get_setting('amp-design-selector') ) { $social_check = true; } if ( '4' !== ampforwp_get_setting('amp-design-selector') && defined('AMPFORWP_DM_SOCIAL_CHECK') && 'true' === AMPFORWP_DM_SOCIAL_CHECK ) { $social_check = true; } if( ampforwp_get_setting('enable-single-social-icons') == true || defined('AMPFORWP_DM_SOCIAL_CHECK') && AMPFORWP_DM_SOCIAL_CHECK === 'true' ) { if( (is_singular() || $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 $fb_like = false; $isBBPress = (function_exists('is_bbpress') ? is_bbpress() : false ); if ( true == ampforwp_get_setting('ampforwp-facebook-like-button') ){ if ( is_single() && ( true == ampforwp_get_setting('enable-single-social-icons') || (true == ampforwp_get_setting('ampforwp-social-share') && $social_check) ) && !checkAMPforPageBuilderStatus(ampforwp_get_the_ID()) && !$isBBPress) { $fb_like = true; } if ( is_page() && ( true == ampforwp_get_setting('ampforwp-page-sticky-social') || ( $social_check_page && !checkAMPforPageBuilderStatus(ampforwp_get_the_ID()) ) ) ) { $fb_like = true; } if ( true == ampforwp_get_setting('enable-single-social-icons') && checkAMPforPageBuilderStatus(ampforwp_get_the_ID()) && is_singular()) { $fb_like = true; } } if ( true == $fb_like ) { 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; } 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; } // 8. Add Main tag as a Wrapper // Removed this code after moving to design manager // 9. Advertisement code // Moved to ads-functions.php // 10. Analytics Area // Moved to analytics-functions.php // 11. Strip unwanted codes and tags from the_content add_action( 'pre_amp_render_post','ampforwp_strip_invalid_content'); function ampforwp_strip_invalid_content() { add_filter( 'the_content', 'ampforwp_the_content_filter', 2 ); } function ampforwp_the_content_filter( $content ) { $content = preg_replace('/property=[^>]*/', '', $content); $content = preg_replace('/vocab=[^>]*/', '', $content); $content = preg_replace('/noshade=[^>]*/', '', $content); $content = preg_replace('/contenteditable=[^>]*/', '', $content); $content = preg_replace('/non-refundable=[^>]*/', '', $content); $content = preg_replace('/security=[^>]*/', '', $content); $content = preg_replace('/deposit=[^>]*/', '', $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); //Removed because class is being removed from table #2699 $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('/
<\/script>/', $allscripts, $matches); $script_slug = $matches[2]; $script_url = $matches[4]; if($matches){ foreach ($script_slug as $key => $slug) { if(preg_match('/<\/'.$slug.'>/', $content)){ if ( empty( $data['amp_component_scripts'][$slug] ) ) { $data['amp_component_scripts'][$slug] = $script_url[$key]; } } } } } return $data; } add_action('amp_post_template_head','ampforwp_header_html_output',11); function ampforwp_header_html_output() { if( ampforwp_get_setting('ampforwp-seo-custom-additional-meta') ){ echo strip_tags( ampforwp_get_setting('ampforwp-seo-custom-additional-meta'), '' ); } if( ampforwp_get_setting('amp-header-text-area-for-html') ) { $allhtml = ampforwp_get_setting('amp-header-text-area-for-html'); $allhtml = preg_replace('/<\/script>/','', $allhtml); echo $allhtml; } $mob_pres_link = false; if(function_exists('ampforwp_mobile_redirect_preseve_link')){ $mob_pres_link = ampforwp_mobile_redirect_preseve_link(); } } add_filter('amp_post_template_data','ampforwp_set_body_content_script', 20); function ampforwp_set_body_content_script($data){ if( ampforwp_get_setting('amp-body-text-area') || ampforwp_get_setting('amp-footer-text-area-for-html') ) { $head_content = ampforwp_get_setting('amp-header-text-area-for-html'); preg_match_all('/"amp-(.*?)"/', $head_content, $matches1); $body_content = ampforwp_get_setting('amp-body-text-area'); preg_match_all('/<\/amp-(.*?)>/', $body_content, $matches); if(ampforwp_get_setting('amp-footer-text-area-for-html') ) { $footer_content = ampforwp_get_setting('amp-footer-text-area-for-html'); preg_match_all('/<\/amp-(.*?)>/', $footer_content, $matches); } if(isset($matches[1][0])){ $amp_comp = $matches[1]; for($i=0;$i= 2 && !$redux_builder_amp['ampforwp-robots-archive-sub-pages-sitewide'] ) { $talk_to_robots = true; } } $query_array = $wp->query_vars; if( array_key_exists( 'page' , $query_array ) ) { $page = $wp->query_vars['page']; if ( $redux_builder_amp['amp-frontpage-select-option'] && $page >= '2') { $talk_to_robots = true; } } if( $talk_to_robots ) { $meta_content = "noindex,noarchive"; } // Genesis if ( function_exists('genesis_get_robots_meta_content') && 'genesis' == ampforwp_get_setting('ampforwp-seo-selection') ) { $meta_content = genesis_get_robots_meta_content(); } // All in One SEO #1720 if ( class_exists('All_in_One_SEO_Pack') ) { $aios_class = $page = $opts = $aios_meta = $aiosp_noindex = $aiosp_nofollow = ''; $noindex = 'index'; $nofollow = 'follow'; $aios_class = new All_in_One_SEO_Pack(); if (property_exists($aios_class,'get_page_number')) { $page = $aios_class->get_page_number(); } if (property_exists($aios_class,'get_current_options')) { $opts = $aios_class->get_current_options( array(), 'aiosp' ); } if (property_exists($aios_class,'get_robots_meta')) { $aios_meta = $aios_class->get_robots_meta(); } if ( ( is_category() && ! empty( $aioseop_options['aiosp_category_noindex'] ) ) || ( ! is_category() && is_archive() && ! is_tag() && ! is_tax() || ( is_tag() && ! empty( $aioseop_options['aiosp_tags_noindex'] ) ) || ( is_search() && ! empty( $aioseop_options['aiosp_search_noindex'] ) ) ) ){ $noindex = 'noindex'; } elseif ( is_single() || is_page() || $aios_class->is_static_posts_page() || is_attachment() || is_category() || is_tag() || is_tax() || ( $page > 1 ) ) { $post_type = get_post_type(); if ( ! empty( $opts ) ) { $aiosp_noindex = htmlspecialchars( stripslashes( $opts['aiosp_noindex'] ) ); $aiosp_nofollow = htmlspecialchars( stripslashes( $opts['aiosp_nofollow'] ) ); } if ( $aiosp_noindex || $aiosp_nofollow || ! empty( $aioseop_options['aiosp_cpostnoindex'] ) || ! empty( $aioseop_options['aiosp_cpostnofollow'] ) || ! empty( $aioseop_options['aiosp_paginated_noindex'] ) || ! empty( $aioseop_options['aiosp_paginated_nofollow'] ) ) { if ( ( $aiosp_noindex == 'on' ) || ( ( ! empty( $aioseop_options['aiosp_paginated_noindex'] ) ) && $page > 1 ) || ( ( $aiosp_noindex == '' ) && ( ! empty( $aioseop_options['aiosp_cpostnoindex'] ) ) && in_array( $post_type, $aioseop_options['aiosp_cpostnoindex'] ) ) ) { $noindex = 'noindex'; } if ( ( $aiosp_nofollow == 'on' ) || ( ( ! empty( $aioseop_options['aiosp_paginated_nofollow'] ) ) && $page > 1 ) || ( ( $aiosp_nofollow == '' ) && ( ! empty( $aioseop_options['aiosp_cpostnofollow'] ) ) && in_array( $post_type, $aioseop_options['aiosp_cpostnofollow'] ) ) ) { $nofollow = 'nofollow'; } } } if ( is_singular() && property_exists($aios_class,'is_password_protected') && $aios_class->is_password_protected() && apply_filters( 'aiosp_noindex_password_posts', false ) ) { $noindex = 'noindex'; } $robots_meta = $noindex . ',' . $nofollow; if ( $robots_meta == 'index,follow' ) { $robots_meta = ''; } if ( !empty($robots_meta) ) { $meta_content = $robots_meta; } } // Meta Robots Tag From Yoast #1563 if ( class_exists('WPSEO_Frontend') && 'yoast' == ampforwp_get_setting('ampforwp-seo-selection') && is_singular() && !class_exists('Yoast\\WP\\SEO\\Integrations\\Front_End_Integration')) { $class_instance = ''; $class_instance = WPSEO_Frontend::get_instance(); // robots() will return and print the meta robots tag $class_instance->robots(); // Empty the above meta content to avoid duplicate meta robot tags $meta_content = ''; } $meta_content = apply_filters('ampforwp_robots_meta', $meta_content); if ( isset($redux_builder_amp['amp-inspection-tool']) && true == $redux_builder_amp['amp-inspection-tool'] ) { $talk_to_robots = $meta_content = ''; } if ( $meta_content ) { if ( ( is_archive() && $talk_to_robots ) || is_singular() || is_home() ) { echo ''; } } } // 41. Rewrite URL only on save #511 function ampforwp_auto_flush_on_save($redux_builder_amp) { if ( $redux_builder_amp['amp-on-off-for-all-pages'] == 1 || $redux_builder_amp['ampforwp-archive-support'] == 1 || $redux_builder_amp['fb-instant-article-switch'] == 1 ) { global $wp_rewrite; $wp_rewrite->flush_rules(); } $options = $new_options = array(); if ( is_array(ampforwp_get_setting('hide-amp-categories')) && !is_array(ampforwp_get_setting('hide-amp-categories2'))) { $options = array_keys(array_filter($redux_builder_amp['hide-amp-categories'] ) ); foreach ($options as $option ) { $new_options[] = $option; } $redux_builder_amp['hide-amp-categories2'] = $new_options; $redux_builder_amp['hide-amp-categories'] = ''; update_option('redux_builder_amp',$redux_builder_amp); } } add_action("redux/options/redux_builder_amp/saved",'ampforwp_auto_flush_on_save', 10, 1); // 42. registeing AMP sidebars add_action('init', 'ampforwp_add_widget_support'); function ampforwp_add_widget_support() { if (function_exists('register_sidebar')) { global $redux_builder_amp; register_sidebar(array( 'name' => 'AMP Above Loop [HomePage]', 'id' => 'ampforwp-above-loop', 'description' => 'This Widget will be display on AMP HomePage Above the loop ', 'before_widget' => '', 'after_widget' => '', 'before_title' => '

', 'after_title' => '

' )); register_sidebar(array( 'name' => 'AMP Below Loop [HomePage]', 'id' => 'ampforwp-below-loop', 'description' => 'This Widget will be display on AMP HomePage Below the loop', 'before_widget' => '', 'after_widget' => '', 'before_title' => '

', 'after_title' => '

' )); register_sidebar(array( 'name' => 'AMP Below the Header [Site Wide]', 'id' => 'ampforwp-below-header', 'description' => 'This Widget will be display after the header bar', 'before_widget' => '', 'after_widget' => '', 'before_title' => '

', 'after_title' => '

' )); register_sidebar(array( 'name' => 'AMP Above the Footer [Site Wide]', 'id' => 'ampforwp-above-footer', 'description' => 'This Widget display Above the Footer', 'before_widget' => '', 'after_widget' => '', 'before_title' => '

', 'after_title' => '

' )); if ( function_exists('ampforwp_custom_theme_files_register') ) { $desc = "Update: Introducing PageBuilder 2.0
Drag and Drop the AMP Modules in this Widget Area and then assign this widget area to a page (Need Help?)"; $placeholder = 'PLACEHOLDER'; register_sidebar(array( 'name' => 'Page Builder (AMP) [Legacy]', 'id' => 'layout-builder', 'description' => $placeholder, 'before_widget' => '', 'after_widget' => '', 'before_title' => '

', 'after_title' => '

' )); add_action( 'widgets_admin_page', function() use ( $desc, $placeholder ) { add_filter( 'esc_html', function( $safe_text, $text ) use ( $desc, $placeholder ) { if ( $text !== $placeholder ) return $safe_text; remove_filter( current_filter(), __FUNCTION__ ); return $desc; }, 10, 2 ); }); } } } // 43. custom actions for widgets output add_action( 'ampforwp_home_above_loop' , 'ampforwp_output_widget_content_above_loop' ); add_action( 'ampforwp_frontpage_above_loop' , 'ampforwp_output_widget_content_above_loop' ); function ampforwp_output_widget_content_above_loop() { $sanitized_sidebar = ""; $sidebar_output = ""; $sanitized_sidebar = ampforwp_sidebar_content_sanitizer('ampforwp-above-loop'); if ( $sanitized_sidebar) { $sidebar_output = $sanitized_sidebar->get_amp_content(); $sidebar_output = apply_filters('ampforwp_modify_sidebars_content',do_shortcode($sidebar_output)); } if ( $sidebar_output ) { ?>
get_amp_content(); $sidebar_output = apply_filters('ampforwp_modify_sidebars_content',do_shortcode($sidebar_output)); } if ( $sidebar_output ) { ?>
get_amp_content(); $sidebar_output = apply_filters('ampforwp_modify_sidebars_content',do_shortcode($sidebar_output)); } if ( $sidebar_output ) { ?>
get_amp_content(); $sidebar_output = apply_filters('ampforwp_modify_sidebars_content',do_shortcode($sidebar_output)); } if ( $sidebar_output ) { ?>
array(), 'AMP_Twitter_Embed_Handler' => array(), 'AMP_YouTube_Embed_Handler' => array(), 'AMP_DailyMotion_Embed_Handler' => array(), 'AMP_Vimeo_Embed_Handler' => array(), 'AMP_SoundCloud_Embed_Handler' => array(), 'AMP_Instagram_Embed_Handler' => array(), 'AMP_Vine_Embed_Handler' => array(), 'AMP_Facebook_Embed_Handler' => array(), 'AMP_Pinterest_Embed_Handler' => array(), 'AMP_Gallery_Embed_Handler' => array(), ) ), apply_filters( 'amp_sidebar_sanitizers', array( 'AMP_Style_Sanitizer' => array(), 'AMP_Blacklist_Sanitizer' => $blacklist_array, 'AMP_Img_Sanitizer' => array(), 'AMP_Video_Sanitizer' => array(), 'AMP_Audio_Sanitizer' => array(), 'AMP_Playbuzz_Sanitizer' => array(), 'AMP_Iframe_Sanitizer' => array( 'add_placeholder' => true, ), 'AMP_Tag_And_Attribute_Sanitizer' => array(), ) ), array('non-content'=>'non-content') ); } if ( is_active_widget(false,false,'search') && $sanitized_sidebar) { // Allow some blacklisted tags #1400 add_filter('ampforwp_modify_sidebars_content','ampforwp_modified_search_sidebar'); } return $sanitized_sidebar; } function ampforwp_modified_search_sidebar( $content ) { global $redux_builder_amp; $mob_pres_link = false; if(function_exists('ampforwp_mobile_redirect_preseve_link')){ $mob_pres_link = ampforwp_mobile_redirect_preseve_link(); } $mob_pres_link = false; if(function_exists('ampforwp_mobile_redirect_preseve_link')){ $mob_pres_link = ampforwp_mobile_redirect_preseve_link(); } $dom = ''; $dom = AMP_DOM_Utils::get_dom_from_content($content); $nodes = $dom->getElementsByTagName( 'form' ); $num_nodes = $nodes->length; if ( 0 !== $num_nodes ) { for ( $i = 0; $i < $nodes->length; ++$i ) { $element = $nodes->item( $i ); if (ampforwp_get_setting('ampforwp-amp-takeover') == false && $mob_pres_link == false ) { $amp_query_variable = 'amp'; $amp_query_variable_val = '1'; } if ( ! $element->hasAttribute('action-xhr') ){ $action_url = $element->getAttribute('action'); $action_url = preg_replace('#^http?:#', '', $action_url); $element->setAttribute('action', $action_url); } $element->setAttribute('target', '_top'); $input_nodes = $element->getElementsByTagName('input'); if ( 0 !== $input_nodes->length ) { for ( $i = 0; $i < $input_nodes->length; ++$i ) { $input_node = $input_nodes->item( $i ); if ( 'submit' !== $input_node->getAttribute('type') ) { $input_submit = $dom->createElement('input'); $input_submit->setAttribute('type', 'submit'); $input_submit->setAttribute('class', 'search-submit'); } } if ( $input_submit ) { $element->appendChild($input_submit); } } } } // Remove http/https from Audio and Video URLs #1400 $video_nodes = $dom->getElementsByTagName( 'amp-video' ); $num_nodes = $video_nodes->length; if ( 0 !== $num_nodes ) { for ( $i = 0; $i < $video_nodes->length; ++$i ) { $element = $video_nodes->item( $i ); $source = $element->childNodes->item(0); $source->setAttribute('src',preg_replace('#^http?:#', '', $source->getAttribute('src') )); $source = $element->childNodes->item(1); if($source) $source->setAttribute('src',preg_replace('#^http?:#', '', $source->getAttribute('src') )); } } $audio = $dom->getElementsByTagName( 'amp-audio' ); $num_nodes = $audio->length; if ( 0 !== $num_nodes ) { for ( $i = 0; $i < $audio->length; ++$i ) { $element = $audio->item( $i ); $source = $element->childNodes->item(0); $source->setAttribute('src',preg_replace('#^http?:#', '', $source->getAttribute('src') )); $source = $element->childNodes->item(1); $source->setAttribute('src',preg_replace('#^http?:#', '', $source->getAttribute('src') )); } } $content = AMP_DOM_Utils::get_content_from_dom($dom); return $content; } function ampforwp_sidebar_blacklist_tags($tags) { $form = array_search('form', $tags); $input = array_search('input', $tags); $label = array_search('label', $tags); $textarea = array_search('textarea', $tags); $select = array_search('select', $tags); $option = array_search('option', $tags); if ( $input ) { unset($tags[$input]); } if ( $label ) { unset($tags[$label]); } if ( $textarea ) { unset($tags[$textarea]); } if ( $select ) { unset($tags[$select]); } if ( $option ) { unset($tags[$option]); } return $tags; } // Sidebar Scripts add_filter( 'amp_post_template_data', 'ampforwp_add_sidebar_data', 85 ); function ampforwp_add_sidebar_data( $data ) { $sanitized_data_above_loop = ''; $sanitized_data_below_loop = ''; $sanitized_data_below_header = ''; $sanitized_data_above_footer = ''; $sanitized_data_swift_sidebar = ''; $sanitized_data_swift_footer = ''; // Get the Data $sanitized_data_above_loop = ampforwp_sidebar_content_sanitizer('ampforwp-above-loop'); $sanitized_data_below_loop = ampforwp_sidebar_content_sanitizer('ampforwp-below-loop'); $sanitized_data_below_header = ampforwp_sidebar_content_sanitizer('ampforwp-below-header'); $sanitized_data_above_footer = ampforwp_sidebar_content_sanitizer('ampforwp-above-footer'); $sanitized_data_swift_sidebar = ampforwp_sidebar_content_sanitizer('swift-sidebar'); $sanitized_data_swift_footer = ampforwp_sidebar_content_sanitizer('swift-footer-widget-area'); if ( $sanitized_data_above_loop ) { // Add Scripts if ( $sanitized_data_above_loop->get_amp_scripts() ) { foreach ($sanitized_data_above_loop->get_amp_scripts() as $key => $value ) { if( empty( $data['amp_component_scripts'][$key] ) ){ $data['amp_component_scripts'][$key] = $value; } } } // Form script #1400 $dom = AMP_DOM_Utils::get_dom_from_content($sanitized_data_above_loop->get_amp_content()); if ( 0 !== $dom->getElementsByTagName( 'form' )->length ) { if( empty( $data['amp_component_scripts']['amp-form'] ) ){ $data['amp_component_scripts']['amp-form'] = 'https://cdn.ampproject.org/v0/amp-form-0.1.js'; } } // Add Styles if ( $sanitized_data_above_loop->get_amp_styles() ) { foreach ($sanitized_data_above_loop->get_amp_styles() as $key => $value ) { if( empty( $data['post_amp_styles'][$key] ) ){ $data['post_amp_styles'][$key] = $value; } } } } if ( $sanitized_data_below_loop ) { // Add Scripts if ( $sanitized_data_below_loop->get_amp_scripts() ) { foreach ($sanitized_data_below_loop->get_amp_scripts() as $key => $value ) { if( empty( $data['amp_component_scripts'][$key] ) ){ $data['amp_component_scripts'][$key] = $value; } } } // Form script #1400 $dom = AMP_DOM_Utils::get_dom_from_content($sanitized_data_below_loop->get_amp_content()); if ( 0 !== $dom->getElementsByTagName( 'form' )->length ) { if( empty( $data['amp_component_scripts']['amp-form'] ) ){ $data['amp_component_scripts']['amp-form'] = 'https://cdn.ampproject.org/v0/amp-form-0.1.js'; } } // Add Styles if ( $sanitized_data_below_loop->get_amp_styles() ) { foreach ($sanitized_data_below_loop->get_amp_styles() as $key => $value ) { if( empty( $data['post_amp_styles'][$key] ) ){ $data['post_amp_styles'][$key] = $value; } } } } if ( $sanitized_data_below_header ) { // Add Scripts if ( $sanitized_data_below_header->get_amp_scripts() ) { foreach ($sanitized_data_below_header->get_amp_scripts() as $key => $value ) { if( empty( $data['amp_component_scripts'][$key] ) ){ $data['amp_component_scripts'][$key] = $value; } } } // Form script #1400 $dom = AMP_DOM_Utils::get_dom_from_content($sanitized_data_below_header->get_amp_content()); if ( 0 !== $dom->getElementsByTagName( 'form' )->length ) { if( empty( $data['amp_component_scripts']['amp-form'] ) ){ $data['amp_component_scripts']['amp-form'] = 'https://cdn.ampproject.org/v0/amp-form-0.1.js'; } } // Add Styles if ( $sanitized_data_below_header->get_amp_styles() ) { foreach ($sanitized_data_below_header->get_amp_styles() as $key => $value ) { if( empty( $data['post_amp_styles'][$key] ) ){ $data['post_amp_styles'][$key] = $value; } } } } if ( $sanitized_data_above_footer ) { // Add Scripts if ( $sanitized_data_above_footer->get_amp_scripts() ) { foreach ($sanitized_data_above_footer->get_amp_scripts() as $key => $value ) { if( empty( $data['amp_component_scripts'][$key] ) ){ $data['amp_component_scripts'][$key] = $value; } } } // Form script #1400 $dom = AMP_DOM_Utils::get_dom_from_content($sanitized_data_above_footer->get_amp_content()); if ( 0 !== $dom->getElementsByTagName( 'form' )->length ) { if( empty( $data['amp_component_scripts']['amp-form'] ) ){ $data['amp_component_scripts']['amp-form'] = 'https://cdn.ampproject.org/v0/amp-form-0.1.js'; } } // Add Styles if ( $sanitized_data_above_footer->get_amp_styles() ) { foreach ($sanitized_data_above_footer->get_amp_styles() as $key => $value ) { if( empty( $data['post_amp_styles'][$key] ) ){ $data['post_amp_styles'][$key] = $value; } } } } if ( $sanitized_data_swift_sidebar ) { // Add Scripts if ( $sanitized_data_swift_sidebar->get_amp_scripts() ) { foreach ($sanitized_data_swift_sidebar->get_amp_scripts() as $key => $value ) { if( empty( $data['amp_component_scripts'][$key] ) ){ $data['amp_component_scripts'][$key] = $value; } } } // Form script #1400 $dom = AMP_DOM_Utils::get_dom_from_content($sanitized_data_swift_sidebar->get_amp_content()); if ( 0 !== $dom->getElementsByTagName( 'form' )->length ) { if( empty( $data['amp_component_scripts']['amp-form'] ) ){ $data['amp_component_scripts']['amp-form'] = 'https://cdn.ampproject.org/v0/amp-form-0.1.js'; } } // Add Styles if ( $sanitized_data_swift_sidebar->get_amp_styles() ) { foreach ($sanitized_data_swift_sidebar->get_amp_styles() as $key => $value ) { if( empty( $data['post_amp_styles'][$key] ) ){ $data['post_amp_styles'][$key] = $value; } } } } if ( $sanitized_data_swift_footer ) { // Add Scripts if ( $sanitized_data_swift_footer->get_amp_scripts() ) { foreach ($sanitized_data_swift_footer->get_amp_scripts() as $key => $value ) { if( empty( $data['amp_component_scripts'][$key] ) ){ $data['amp_component_scripts'][$key] = $value; } } } // Form script #1400 $dom = AMP_DOM_Utils::get_dom_from_content($sanitized_data_swift_footer->get_amp_content()); if ( 0 !== $dom->getElementsByTagName( 'form' )->length ) { if( empty( $data['amp_component_scripts']['amp-form'] ) ){ $data['amp_component_scripts']['amp-form'] = 'https://cdn.ampproject.org/v0/amp-form-0.1.js'; } } // Add Styles if ( $sanitized_data_swift_footer->get_amp_styles() ) { foreach ($sanitized_data_swift_footer->get_amp_styles() as $key => $value ) { if( empty( $data['post_amp_styles'][$key] ) ){ $data['post_amp_styles'][$key] = $value; } } } } return $data; } // 44. auto adding /amp for the menu add_action('amp_init','ampforwp_auto_add_amp_menu_link_insert'); function ampforwp_auto_add_amp_menu_link_insert() { add_action( 'pre_amp_render_post', 'ampforwp_auto_add_amp_in_link_check', 99 ); } function ampforwp_auto_add_amp_in_link_check() { $ampforwp_is_amp_endpoint = ampforwp_is_amp_endpoint(); $add_amp_menu = get_transient('ampforwp_auto_add_amp_in_menu_link'); if ( false == $add_amp_menu || ( 'on' && 0 == ampforwp_get_setting('ampforwp-auto-amp-menu-link') ) ) { delete_transient('ampforwp_header_menu'); delete_transient('ampforwp_footer_menu'); set_transient('ampforwp_auto_add_amp_in_menu_link', 'off'); } if ( $ampforwp_is_amp_endpoint && ampforwp_get_setting('ampforwp-auto-amp-menu-link') == 1 ) { if( 'off' == $add_amp_menu ) { delete_transient('ampforwp_header_menu'); delete_transient('ampforwp_footer_menu'); set_transient('ampforwp_auto_add_amp_in_menu_link', 'on'); } add_filter( 'nav_menu_link_attributes', 'ampforwp_auto_add_amp_in_menu_link', 10, 3 ); } } function ampforwp_auto_add_amp_in_menu_link( $atts, $item, $args ) { if($item->type=='post_type' && !in_array($item->object, ampforwp_get_all_post_types()) ){ return $atts; } if($item->type=='taxonomy' && !in_array($item->object, ampforwp_get_all_post_types()) ){ return $atts; } $mob_pres_link = false; if(function_exists('ampforwp_mobile_redirect_preseve_link')){ $mob_pres_link = ampforwp_mobile_redirect_preseve_link(); } if(ampforwp_get_setting('ampforwp-amp-takeover') || $mob_pres_link == true){ return $atts; } $url = $atts['href']; if($url){ $is_external = ampforwp_isexternal($url); } if($is_external){ return $atts; } if(ampforwp_get_setting('amp-core-end-point') == 1 ){ $atts['href'] = user_trailingslashit(trailingslashit( $atts['href'] ) ); $atts['href'] = add_query_arg(AMPFORWP_AMP_QUERY_VAR,'1', $atts['href']); } else{ if(false === strpos($atts['href'], "#")){ $atts['href'] = user_trailingslashit(trailingslashit( $atts['href'] ) . AMPFORWP_AMP_QUERY_VAR); } } $atts = apply_filters('ampforwp_auto_add_amp_menu_url',$atts); return $atts; } // 45. searchpage, frontpage, homepage structured data // Moved to structured-data-functions.php // 46. search search search everywhere #615 require 'search-functions.php'; // 47. social js properly adding when required if( !function_exists( 'is_socialshare_or_socialsticky_enabled_in_ampforwp' ) ) { function is_socialshare_or_socialsticky_enabled_in_ampforwp() { global $redux_builder_amp; if( $redux_builder_amp['enable-single-facebook-share'] || $redux_builder_amp['enable-single-twitter-share'] || $redux_builder_amp['enable-single-email-share'] || $redux_builder_amp['enable-single-pinterest-share'] || $redux_builder_amp['enable-single-linkedin-share'] ) { return true; } return false; } } // 48. Remove all unwanted scripts on search pages add_filter( 'amp_post_template_data', 'ampforwp_remove_scripts_search_page' ); function ampforwp_remove_scripts_search_page( $data ) { if( is_search() ) { // Remove all unwanted scripts on search pages unset( $data['amp_component_scripts']); } return $data; } // 49. Properly adding ad Script the AMP way // Moved to ads-functions.php // internal function for checing if social profiles have been set if( !function_exists('ampforwp_checking_any_social_profiles') ) { function ampforwp_checking_any_social_profiles() { global $redux_builder_amp; if( $redux_builder_amp['enable-single-twittter-profile'] || $redux_builder_amp['enable-single-facebook-profile'] || $redux_builder_amp['enable-single-pintrest-profile'] || $redux_builder_amp['enable-single-google-plus-profile'] || $redux_builder_amp['enable-single-linkdin-profile'] || $redux_builder_amp['enable-single-youtube-profile'] || $redux_builder_amp['enable-single-instagram-profile'] || $redux_builder_amp['enable-single-VKontakte-profile'] || $redux_builder_amp['enable-single-reddit-profile'] || $redux_builder_amp['enable-single-snapchat-profile'] || $redux_builder_amp['enable-single-Tumblr-profile'] ) { return true; } return false; } } // 50. Properly adding noditification Scritps the AMP way // Moved to notice-bar-functions.php //52. Adding a generalized sanitizer function for purifiying normal html to amp-html function ampforwp_content_sanitizer( $content ) { global $post; $amp_custom_post_content_input = $content; if ( !empty( $amp_custom_post_content_input ) ) { $amp_custom_content = new AMPFORWP_Content( $amp_custom_post_content_input, apply_filters( 'amp_content_embed_handlers', array( 'AMP_Reddit_Embed_Handler' => array(), 'AMP_Twitter_Embed_Handler' => 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(), 'AMP_Tiktok_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, ), ),$post ) ); if ( $amp_custom_content ) { global $data; $data = (array) $data; $data['amp_component_scripts'] = $amp_custom_content->get_amp_scripts(); $data['post_amp_styles'] = $amp_custom_content->get_amp_styles(); return $amp_custom_content->get_amp_content(); } return ''; } } //53. Removed AMP-WooCommerce Code and added it in AMP-WooCommerce #929 // Adding the styling for AMP Woocommerce latest Products(AMP-WooCommerce Widgets) add_action('amp_post_template_css','amp_latest_products_styling',PHP_INT_MAX); function amp_latest_products_styling() { if ( class_exists( 'woocommerce' ) ) { ?> .ampforwp_wc_shortcode{margin-top: 0;padding:0;display:inline-block;width: 100%;} .ampforwp_wc_shortcode li{position: relative;width:29%; font-size:12px; line-height: 1; float: left;list-style-type: none;margin:2%;} .ampforwp_wc_shortcode .onsale{position: absolute;top: 0;right: 0;background: #ddd;padding: 7px;font-size: 12px;} .single-post .ampforwp_wc_shortcode li amp-img{margin:0} .ampforwp-wc-title{margin: 8px 0px 10px 0px;font-size: 13px;} .ampforwp-wc-price{color:#444} .wc_widgettitle{text-align:center;margin-bottom: 0px;} .ampforwp-wc-price, .ampforwp_wc_star_rating{float:left;margin-right: 10px;} ID,'ampforwp-amp-on-off', $meta_value_to_upate); } // Update the option as the process has been done and update an option update_option('ampforwp_default_pages_to', $checker); return ; } // Adding the meta="description" from yoast or from the content add_action('amp_post_template_head','ampforwp_meta_description'); function ampforwp_meta_description() { global $redux_builder_amp; if ( false == ampforwp_get_setting('ampforwp-seo-meta-desc') || ('rank_math' == ampforwp_get_setting('ampforwp-seo-selection') && is_singular() )) { return; } if (function_exists('aioseo_pro_just_activated') && 'aioseo' == ampforwp_get_setting('ampforwp-seo-selection') ) { return; } $desc = ampforwp_generate_meta_desc(); if ( $desc && !class_exists('Yoast\\WP\\SEO\\Integrations\\Front_End_Integration')) { echo ''; }else if(class_exists('Yoast\\WP\\SEO\\Integrations\\Front_End_Integration')){ $yoast_desc = addslashes( strip_tags( WPSEO_Meta::get_value('metadesc', ampforwp_get_the_ID() ) ) ); $yoast_desc_meta = get_option( 'wpseo_titles' ); if(isset($yoast_desc_meta['metadesc-page'])){ $yoast_desc_meta = $yoast_desc_meta['metadesc-page']; } if(empty($yoast_desc)){ $yoast_desc = $yoast_desc_meta; } if ($yoast_desc && ampforwp_is_front_page()) { echo ''; } elseif ($desc && ampforwp_is_home() && 'page' == get_option( 'show_on_front') && empty(get_option( 'page_for_posts')) ){ echo ''; } } } // All in One Seo Compatibility #1557 if(defined( 'AIOSEO_VERSION' ) && version_compare(AIOSEO_VERSION,'4.0.0', '<')){ add_filter('aioseop_amp_description', '__return_false'); } // 55. Call Now Button Feature added add_action('ampforwp_call_button','ampforwp_call_button_html_output'); function ampforwp_call_button_html_output(){ global $redux_builder_amp; if ( $redux_builder_amp['ampforwp-callnow-button'] ) { ?>

get( 'post_modified_timestamp' ) !== $post_object->get( 'post_publish_timestamp' ) ){ $date_notice_text = ampforwp_get_setting('amp-translator-modified-date-text'); $date = $post_object->get( 'post_modified_timestamp' ); echo esc_html( sprintf( _x( ampforwp_translation( $date_notice_text ,'This article was last modified on ' ) . ' %s ' , '%s = human-readable time difference', 'accelerated-mobile-pages' ), date_i18n( get_option( 'date_format' ) , $date ) ) ); if(true == ampforwp_get_setting('ampforwp-post-date-notice-time')){ echo get_the_modified_time(); } }elseif($date_notice_type == "published"){ $date_notice_text = ampforwp_get_setting('amp-translator-published-date-text'); $date = $post_object->get( 'post_publish_timestamp' ); echo esc_html( sprintf( _x( ampforwp_translation( $date_notice_text ,'This article was last modified on ' ) . ' %s ' , '%s = human-readable time difference', 'accelerated-mobile-pages' ), date_i18n( get_option( 'date_format' ) , $date ) ) ); if(true == ampforwp_get_setting('ampforwp-post-date-notice-time')){ echo get_the_time(); } } ?>

'1' ), get_permalink() ); $button_url = $button_url. '#commentform'; } elseif ( ampforwp_get_setting('ampforwp-amp-takeover') ) { $button_url = user_trailingslashit(get_the_permalink()).'#comments'; } else{ $button_url = get_permalink(). '#commentform'; } return esc_url( apply_filters( 'ampforwp_comment_button_url', $button_url ) ); } // 60. Remove Category Layout modification code added by TagDiv #842 and #796 // #1683 add_action('pre_amp_render_post', 'ampforwp_remove_tagdiv_category_layout'); function ampforwp_remove_tagdiv_category_layout(){ if ( function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() ) { remove_action('pre_get_posts', 'td_modify_main_query_for_category_page',9); } } // 61. Add Gist Support add_shortcode('amp-gist', 'ampforwp_gist_shortcode_generator'); function ampforwp_gist_shortcode_generator($atts) { extract(shortcode_atts(array( 'id' =>'' , 'layout' => 'fixed-height', 'height' => 200, ), $atts)); if ( empty ( $height ) ) { $height = '250'; } return ' '; } // Code updated and added the JS proper way #336 add_filter('amp_post_template_data','ampforwp_add_amp_gist_script', 100); function ampforwp_add_amp_gist_script( $data ){ global $redux_builder_amp; $content = ""; $content = $data['post']; if( $content ){ $content = $content->post_content; if( is_single() ) { if( has_shortcode( $content, 'amp-gist' ) ){ if ( empty( $data['amp_component_scripts']['amp-gist'] ) ) { $data['amp_component_scripts']['amp-gist'] = 'https://cdn.ampproject.org/v0/amp-gist-0.1.js'; } } } } return $data; } // 62. Adding Meta viewport via hook instead of direct #878 add_action( 'amp_post_template_head','ampforwp_add_meta_viewport', 9); function ampforwp_add_meta_viewport() { $output = ''; $output = ' '; if (ampforwp_get_setting('ampforwp-meta-viewport') == false) { $output = ''; } if(!class_exists( 'AMPforWP_Mobile_Detect') && !ampforwp_get_setting('amp-mobile-redirection')){ ampforwp_require_file( AMPFORWP_PLUGIN_DIR.'/includes/vendor/Mobile_Detect.php '); } if(class_exists('AMPforWP_Mobile_Detect')){ $mobile_detect = new AMPforWP_Mobile_Detect; $isMobile = $mobile_detect->isMobile(); $isTablet = $mobile_detect->isTablet(); if( $isMobile || $isTablet ){ $output = ''; } } global $is_safari; if ($is_safari) { $output .= ''; } 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',array()); $enable_comments = false; $post_id = ""; $post_id = ampforwp_get_frontpage_id(); if (empty($data)) { $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, 'order' => esc_attr($comment_order), '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 '.esc_html(ampforwp_translation(ampforwp_get_setting('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 );//amphtml content, no kses ?>
  • 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 );?>
'1' ), $comment_button_url );?>
.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_Twitter_Embed_Handler' => 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(), 'AMP_Tiktok_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 = ''; $is_legacy_enabled = ''; $is_legacy_enabled = function_exists('ampforwp_custom_theme_files_register'); if ( $post ) { $post_id = $post->ID; } if ( ampforwp_is_front_page() ) { $post_id = ampforwp_get_frontpage_id(); } if ( $post_id && $is_legacy_enabled ) { $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', 1 ); } } // Removing AMP from WPForo Forums Pages #592 if(class_exists('wpForo')){ global $wpdb,$wpforo; $foid = ampforwp_get_the_ID(); $fid = $wpforo->pageid; if($foid==$fid){ remove_action( 'wp_head', 'amp_frontend_add_canonical'); remove_action( 'wp_head', 'ampforwp_home_archive_rel_canonical', 1 ); } } } // 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, $post, $wp; $nofollow = $page = $amp_url = $non_amp_url = ''; if( true == ampforwp_get_setting('ampforwp-nofollow-view-nonamp') ){ $nofollow = 'rel=nofollow'; } $amp_url = ampforwp_amphtml_generator(); $amp_url = explode('/', $amp_url); $amp_url = array_flip($amp_url); $endpoint = AMPFORWP_AMP_QUERY_VAR; if (ampforwp_get_setting('amp-core-end-point')) { $endpoint = '?'. $endpoint; } unset($amp_url[$endpoint]); $non_amp_url = array_flip($amp_url); $non_amp_url = implode('/', $non_amp_url); $query_arg_array = $wp->query_vars; if( array_key_exists( "page" , $query_arg_array ) ) { $page = $wp->query_vars['page']; } if ( $page >= '2') { $non_amp_url = trailingslashit( $non_amp_url . '?page=' . $page); } if ( ampforwp_get_setting('amp-mobile-redirection')==true && ampforwp_get_setting('amp-mob-redirection-pres-link')==false) { $non_amp_url = user_trailingslashit($non_amp_url); $non_amp_url = add_query_arg('nonamp','1',$non_amp_url); } else $mob_pres_link = false; if(function_exists('ampforwp_mobile_redirect_preseve_link')){ $mob_pres_link = ampforwp_mobile_redirect_preseve_link(); } $non_amp_url = user_trailingslashit($non_amp_url); if ( true == ampforwp_get_setting('ampforwp-amp-takeover') || $mob_pres_link == true) { $non_amp_url = ''; } $permalink = get_option('permalink_structure'); if(strpos($permalink, '/%year%/%monthnum%/%day%/%postname%/') !== false){ $non_amp_url = get_permalink(ampforwp_get_the_ID()); } if ( $non_amp_url ) { ?> title=""> post_content; $checker = preg_match('//', $content); if ( 1 === $checker ) { $multipage = $more = 1; $ampforwp_new_content = explode('', $content); $queried_var = get_query_var('paged'); if ( $queried_var > 1 ) { $page = $queried_var; } $numpages = count($ampforwp_new_content); } }else{ $amp_current_post_id =ampforwp_get_the_ID(); $amp_custom_content_enable = get_post_meta( $amp_current_post_id , 'ampforwp_custom_content_editor_checkbox', true); if($amp_custom_content_enable=='yes'){ $content = get_post_meta ( $amp_current_post_id, 'ampforwp_custom_content_editor', true ); $content = html_entity_decode($content); $checker = preg_match('//', $content); if ( 1 === $checker ) { $multipage = $more = 1; $ampforwp_new_content = explode('', $content); $queried_var = get_query_var('paged'); if ( $queried_var > 1 ) { $page = $queried_var; } $numpages = count($ampforwp_new_content); } }else if(ampforwp_get_setting('ampforwp-pagination-link-type')==true && is_singular() && !checkAMPforPageBuilderStatus(ampforwp_get_the_ID())){ $id = ampforwp_get_the_ID(); $content = get_post_field( 'post_content', $id); if ($content) { $sanitizer_obj = new AMPFORWP_Content( $content, apply_filters( 'amp_content_embed_handlers', array( 'AMP_Reddit_Embed_Handler' => array(), 'AMP_Twitter_Embed_Handler' => array(), 'AMP_YouTube_Embed_Handler' => array(), 'AMP_DailyMotion_Embed_Handler' => array(), 'AMP_Vimeo_Embed_Handler' => array(), 'AMP_SoundCloud_Embed_Handler' => array(), 'AMP_Instagram_Embed_Handler' => array(), 'AMP_Vine_Embed_Handler' => array(), 'AMP_Facebook_Embed_Handler' => array(), 'AMP_Pinterest_Embed_Handler' => array(), 'AMP_Gallery_Embed_Handler' => array(), 'AMP_Playlist_Embed_Handler' => array(), 'AMP_Tiktok_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_Playbuzz_Sanitizer' => array(), 'AMP_Iframe_Sanitizer' => array( 'add_placeholder' => true, ), ) ) ); $content = $sanitizer_obj->get_amp_content(); $checker = preg_match('//', $content); if ( 1 === $checker ) { $multipage = $more = 1; $ampforwp_new_content = explode('', $content); $queried_var = get_query_var('paged'); if ( $queried_var > 1 ) { $page = $queried_var; } $numpages = count($ampforwp_new_content); } } } } $defaults = array( 'before' => '

' . '' . ampforwp_translation($redux_builder_amp['amp-translator-page-text'], 'Page') . ':', 'after' => '

', 'link_before' => '', 'link_after' => '', 'next_or_number' => 'number', 'separator' => ' ', 'nextpagelink' => ampforwp_translation($redux_builder_amp['amp-translator-next-text'], 'Next'), 'previouspagelink' => ampforwp_translation($redux_builder_amp['amp-translator-previous-text'], 'Previous'), '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 ); if ( isset($redux_builder_amp['ampforwp-pagination-select']) && 2 == $redux_builder_amp['ampforwp-pagination-select'] ) { $r['next_or_number'] = 'next'; $r['before'] = '

'; $r['after'] = '

'; } $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 ); } $output .= $r['separator']; $text = $page . ' of ' . $numpages; $output .= apply_filters( 'ampforwp_post_pagination_page', $text, $page, $numpages); $next = $page + 1; if ( $next <= $numpages ) { $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(); if ( ampforwp_is_front_page() ) { $id = ampforwp_get_frontpage_id(); $post = get_post($id); } $query_args = array(); if ( 1 == $i ) { $url = get_permalink(); if(ampforwp_is_front_page()){ $url = get_home_url(); } } else { if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) ) { $url = add_query_arg( 'page', $i, get_permalink() ); if(ampforwp_is_front_page()){ $url = add_query_arg( 'page', $i, get_home_url() ); } } elseif ( ampforwp_is_front_page() ) $url = trailingslashit(get_home_url()) . 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 ); } $mob_pres_link = false; if(function_exists('ampforwp_mobile_redirect_preseve_link')){ $mob_pres_link = ampforwp_mobile_redirect_preseve_link(); } if ( false == ampforwp_get_setting('ampforwp-amp-takeover') && $mob_pres_link == false) { if(ampforwp_get_setting('ampforwp-pagination-link-type')==true && is_singular() && !checkAMPforPageBuilderStatus(ampforwp_get_the_ID())){ $url = ampforwp_url_controller($url); }else{ $url = add_query_arg(AMPFORWP_AMP_QUERY_VAR,'1',$url); } } return ''; } // Modify the content to make Pagination work on Pages and FrontPage #2253 add_filter('ampforwp_modify_the_content','ampforwp_post_paginated_content'); function ampforwp_post_paginated_content($content){ //Embed pinterest images to the amp #4361 if(preg_match('/<\/a>/', $content)){ $content = preg_replace('/<\/a>/', '', $content); } if ( is_singular() || ampforwp_is_front_page() ){ global $redux_builder_amp, $page, $multipage; $ampforwp_new_content = $ampforwp_the_content = $checker = ''; if(ampforwp_get_setting('ampforwp-pagination-link-type')==true && is_singular() && !checkAMPforPageBuilderStatus(ampforwp_get_the_ID())){ if (get_query_var('paged') > 1) { $id = ampforwp_get_the_ID(); $content = get_post_field( 'post_content', $id); } if ($content) { $sanitizer_obj = new AMPFORWP_Content( $content, apply_filters( 'amp_content_embed_handlers', array( 'AMP_Reddit_Embed_Handler' => array(), 'AMP_Twitter_Embed_Handler' => array(), 'AMP_YouTube_Embed_Handler' => array(), 'AMP_DailyMotion_Embed_Handler' => array(), 'AMP_Vimeo_Embed_Handler' => array(), 'AMP_SoundCloud_Embed_Handler' => array(), 'AMP_Instagram_Embed_Handler' => array(), 'AMP_Vine_Embed_Handler' => array(), 'AMP_Facebook_Embed_Handler' => array(), 'AMP_Pinterest_Embed_Handler' => array(), 'AMP_Gallery_Embed_Handler' => array(), 'AMP_Playlist_Embed_Handler' => array(), 'AMP_Tiktok_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_Playbuzz_Sanitizer' => array(), 'AMP_Iframe_Sanitizer' => array( 'add_placeholder' => true, ), ) ) ); $content = $sanitizer_obj->get_amp_content(); $queried_var = get_query_var('paged'); $con = explode("", $content); if($queried_var>=2){ if(isset($con[$queried_var-1])){ $content = $con[$queried_var-1]; } } } $ampforwp_the_content = $content; $checker = preg_match('//', $ampforwp_the_content); if ( 1 === $checker && true == ampforwp_get_setting('amp-pagination') ) { $multipage = 1; $ampforwp_new_content = explode('', $ampforwp_the_content); $queried_var = get_query_var('page'); if ( ampforwp_is_front_page() ) { $queried_var = get_query_var('paged'); } if ( $queried_var > 1 ) { $queried_var = $queried_var -1 ; } else { $queried_var = 0; } return $ampforwp_new_content[$queried_var]; } else { return $ampforwp_the_content; } } } return $content; } 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'); $permalink_structure = ''; $permalink_structure = get_option('permalink_structure'); if($post_paginated_page){ $url = get_permalink(); if('' == $permalink_structure){ $new_url = add_query_arg('page',$post_paginated_page,$url); } else{ $new_url = trailingslashit($url) . user_trailingslashit($post_paginated_page); } if(ampforwp_get_setting('ampforwp-pagination-link-type')==true ){ $new_url = ampforwp_url_controller($new_url); }else{ $new_url = add_query_arg(AMPFORWP_AMP_QUERY_VAR,'1',$new_url); } 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 && !class_exists('Yoast\\WP\\SEO\\Integrations\\Front_End_Integration')){ remove_action( 'amp_post_template_head', 'AMPforWP\\AMPVendor\\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 = ''; $permalink_structure = ''; $permalink_structure = get_option('permalink_structure'); 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){ if('' == $permalink_structure){ $new_canonical_url = add_query_arg('page',$post_paginated_page,$new_canonical_url); } else{ $new_canonical_url = $new_canonical_url.$post_paginated_page; } ?> model->permalink; add_action( 'amp_post_template_head', 'ampforwp_generate_yoast_no_index_canonical_url' ); } return $robots; } function ampforwp_generate_yoast_no_index_canonical_url(){ global $yoast_data; if(isset($yoast_data['canonical'])){ $canonical_url = $yoast_data['canonical']; if(ampforwp_is_home() || ampforwp_is_front_page()){ $canonical_url = user_trailingslashit(get_home_url()); } ?> pro && (version_compare(AIOSEO_VERSION,'4.2.6')>=0)) || (!aioseo()->pro && (version_compare(AIOSEO_VERSION,'4.2.4')>0)))) { return; } global $redux_builder_amp; global $wp; $current_archive_url = ''; $amp_url = ''; $remove = ''; $query_arg_array = ''; $page = '' ; if ( is_home() || is_front_page() || (is_archive() && ampforwp_get_setting('ampforwp-archive-support')) ) { $current_archive_url = home_url( $wp->request ); $amp_url = trailingslashit($current_archive_url); $amp_url = explode('/', $amp_url); $amp_url = array_flip($amp_url); if(isset($amp_url['amp'])){ unset($amp_url['amp']); } $amp_url = array_flip($amp_url); $amp_url = implode('/', $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); } ?> 1 ) { global $wp; $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) ; $amp_url = $amp_url ."?s=".get_search_query(); } ?> 'site-name', 'id' => 'view-amp', 'title' => 'Visit AMP', 'href' => ampforwp_url_controller( get_home_url() ), 'meta' => array('target' => '_blank') ); $admin_bar->add_node( $args ); } } // Things to be added in the Body Tag #1064 add_action('ampforwp_body_beginning','ampforwp_body_beginning_html_output',11); function ampforwp_body_beginning_html_output(){ if( ampforwp_get_setting('amp-body-text-area') ) { echo ampforwp_get_setting('amp-body-text-area') ; } } add_filter('get_amp_supported_post_types','is_amp_post_support_enabled'); function is_amp_post_support_enabled($supportedTypes){ global $redux_builder_amp; if( isset( $redux_builder_amp['amp-on-off-for-all-posts'] ) ) { if($redux_builder_amp['amp-on-off-for-all-posts']!='1'){ $index = array_search('post',$supportedTypes); unset($supportedTypes[$index]); }elseif($redux_builder_amp['amp-on-off-for-all-posts']==1){ $supportedTypes[] = 'post'; $supportedTypes = array_unique($supportedTypes); } } return $supportedTypes; } // 74. Featured Image check from Custom Fields // Moved to functions.php function ampforwp_cf_featured_image_src($param=""){ global $redux_builder_amp, $post; if($redux_builder_amp['ampforwp-custom-fields-featured-image-switch']){ $post_id = ''; $custom_fields = ''; $featured_image_field = ''; $output = ''; $custom_fields_name = array(); $post_id = get_the_ID(); $custom_fields = get_post_custom($post_id); foreach ($custom_fields as $key => $value) { $custom_fields_name[] = $key; } $featured_image_field = $redux_builder_amp['ampforwp-custom-fields-featured-image']; if(in_array($featured_image_field, $custom_fields_name)){ $amp_img_src = $custom_fields[$featured_image_field][0]; $image = @getimagesize($amp_img_src); if(empty($image) || $image==false){ $img_id = attachment_url_to_postid($amp_img_src); $imageDetail = wp_get_attachment_image_src( $img_id , 'full'); $image[0] = $imageDetail[1]; $image[1] = $imageDetail[2]; } switch ($param) { case 'url': $output = $amp_img_src; break; case 'width': $output = $image[0]; break; case 'height': $output = $image[1]; break; default: $output = $amp_img_src; break; } return $output; } } } // 75. Dev Mode in AMP add_action('amp_init','ampforwp_dev_mode'); function ampforwp_dev_mode(){ global $redux_builder_amp; if(isset($redux_builder_amp['ampforwp-development-mode']) && $redux_builder_amp['ampforwp-development-mode']){ add_action( 'wp', 'ampforwp_dev_mode_remove_amphtml' ); add_action( 'amp_post_template_head', 'ampforwp_dev_mode_add_noindex' ); } } // Remove amphtml from non-AMP function ampforwp_dev_mode_remove_amphtml(){ remove_action( 'wp_head', 'ampforwp_home_archive_rel_canonical', 1 ); } // Add noindex,nofollow in the AMP if ( ! function_exists('ampforwp_dev_mode_add_noindex') ) { function ampforwp_dev_mode_add_noindex() { global $redux_builder_amp; if ( isset( $redux_builder_amp['amp-inspection-tool'] ) && false == $redux_builder_amp['amp-inspection-tool'] ){ echo ''; } } } // 76. Body Class for AMP pages if (! function_exists( 'ampforwp_body_class' ) ) { function ampforwp_body_class( $class = '' ) { // Separates classes with a single space, collates classes for body element echo 'class="' . esc_attr(join( ' ', ampforwp_get_body_class( $class ) )) . '"'; } } if (! function_exists( 'ampforwp_get_body_class' ) ) { function ampforwp_get_body_class( $class = '' ){ global $wp_query, $redux_builder_amp, $post; $classes = array(); $post_id = ''; $post_type = ''; $classes[] = 'body'; if ( is_singular() ) { $post_id = $post->ID; $classes[] = 'single-post'; } if ( ampforwp_is_front_page() ) { $post_id = ampforwp_get_frontpage_id(); } if ( ampforwp_is_front_page() ) { $classes[] = 'amp-frontpage'; } if(true == ampforwp_get_setting('amp-rtl-select-option')){ $classes[] = 'rtl'; } $classes[] = $post_id; if ( $post_id ) { $classes[] = 'post-id-' . $post_id; $classes[] = 'singular-' . $post_id; } if ( is_page() ) { $classes[] = 'amp-single-page'; } if ( is_post_type_archive() ) { $post_type = get_queried_object(); $classes[] = 'type-'. $post_type->rewrite['slug']; } if ( is_archive() ) { $page_id = get_queried_object_id(); $classes[] = 'archives_body archive-'. $page_id; } if ( ! empty( $class ) ) { if ( !is_array( $class ) ) $class = preg_split( '#\s+#', $class ); $classes = array_merge( $classes, $class ); } else { // Ensure that we always coerce class to being an array. $class = array(); } if(is_tax()){ $term = get_queried_object(); if ( isset( $term->term_id ) ) { $term_class = sanitize_html_class( $term->slug, $term->term_id ); if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) { $term_class = $term->term_id; } $classes[] = 'tax-' . sanitize_html_class( $term->taxonomy ); $classes[] = 'term-' . $term_class; $classes[] = 'term-' . $term->term_id; } }else{ $classes[] = get_post_type(); } $classes[] = AMPFORWP_VERSION; $classes = array_map( 'esc_attr', $classes ); $classes = apply_filters( 'ampforwp_body_class', $classes, $class ); return array_unique( $classes ); } } // Fallback for ticket #1006 function ampforwp_the_body_class(){ return ;} // 77. AMP Blog Details // Moved to functions.php // 78. Saved Custom Post Types for AMP in Options for Structured Data add_action("redux/options/redux_builder_amp/saved",'ampforwp_save_custom_post_types_sd', 10, 1); if(! function_exists('ampforwp_save_custom_post_types_sd') ) { function ampforwp_save_custom_post_types_sd( $redux_builder_amp ){ global $redux_builder_amp; $post_types = array(); $saved_custom_posts = array(); $count_current_pt = ""; $count_saved_pt = ""; $array_1 = ""; $array_2 = ""; $saved_custom_posts = get_option('ampforwp_custom_post_types'); $post_types = ampforwp_get_all_post_types(); if (empty($post_types)) { $post_types = array(); } if (empty($saved_custom_posts)) { update_option('ampforwp_custom_post_types', $post_types); } if ( empty( $saved_custom_posts ) ) { $saved_custom_posts = array(); } $count_current_pt = count( $post_types ); $count_saved_pt = count( $saved_custom_posts ); if ( $count_current_pt > $count_saved_pt) { $array_1 = $post_types; $array_2 = $saved_custom_posts; } else { $array_1 = $saved_custom_posts; $array_2 = $post_types; } if( array_diff( $array_1, $array_2 ) ){ update_option('ampforwp_custom_post_types', $post_types); } } } // 79. Favicon for AMP add_action('amp_post_template_head','wp_site_icon'); // 81. Duplicate Featured Image Support add_filter('ampforwp_allow_featured_image', 'ampforwp_enable_post_and_featured_image'); function ampforwp_enable_post_and_featured_image($show_image){ global $redux_builder_amp; if ( isset($redux_builder_amp['ampforwp-duplicate-featured-image']) && $redux_builder_amp['ampforwp-duplicate-featured-image'] == 1 ) { $show_image = true; } return $show_image; } // 82. Grab Featured Image from The Content function ampforwp_get_featured_image_from_content( $featured_image = "", $size="") { if(get_the_post_thumbnail_url()){ return; } global $post, $posts; $image_url = $image_width = $image_height = $output = $matches = $output_fig = $amp_html_sanitizer = $amp_html = $image_html = $featured_image_output = $matches_fig = $figure = $output_fig_image = $matches_fig_img = ''; ob_start(); ob_end_clean(); // Match all the images from the content if(is_object($post)){ $output = preg_match_all('//i', $post->post_content, $matches); // Match all the figure tags from the content $output_fig = preg_match_all('/\[caption.+id=[\'"]([^\'"]+).*]/i', $post->post_content, $matches_fig); if ( $output_fig && $matches_fig[0][0] ) { $output_fig_image = preg_match_all('/(.*)\[/i', $matches_fig[0][0], $matches_fig_img); // Check if the first image is inside the figure and it got caption if ( $matches_fig_img[1][0] == $matches[1][0] && $matches_fig_img[4][0]) { $figure = true; } } } //Grab the First Image if ((is_array($matches) && $matches[0]) || $output==0 ) { if($output==1){ $image_url = $matches[1][0]; $image_html = $matches[0][0]; $image_width = $matches[2][0]; $image_height = $matches[3][0]; } if($output==0){ if(preg_match('/()<\/figure>/', $post->post_content, $fm)){ if(isset( $fm[2])){ $dom = new DOMDocument(); preg_match('//', $fm[2],$fmatch); if(isset($fmatch[0])){ $image_html = $fmatch[0]; $dom->loadHTML($image_html); $x = new DOMXPath($dom); foreach($x->query("//img") as $node){ $node->setAttribute("width","1366"); $node->setAttribute("height","600"); } $image_html = $dom->saveHtml(); preg_match_all('//', $image_html, $fimg); if(isset($fimg[0][0])){ $image_html ='
'.$fimg[0][0].'
'; if(isset($fmatch[1])){ $image_url = $fmatch[1]; $image_width = 1366; $image_height = 600; } } } } }else{ preg_match_all('//i', $post->post_content, $matches); if(isset($matches[2][0])){ $image_html = $matches[0][0]; $image_url = $matches[2][0]; $image_width = 1366; $image_height = 600; } } } // Sanitize it $amp_html_sanitizer = new AMPFORWP_Content( $image_html, array(), apply_filters( 'ampforwp_content_sanitizers', array( 'AMP_Img_Sanitizer' => array(), 'AMP_Style_Sanitizer' => array() ) ) ); $amp_html = $amp_html_sanitizer->get_amp_content(); // If its figure then add the figcaption inside the figure if ( $figure ) { $amp_html = $amp_html . '
' . esc_attr($matches_fig_img[4][0]) . '
'; } // Filter to remove that image from the content add_filter('ampforwp_modify_the_content','featured_image_content_filter'); if ( isset( $size ) && '' !== $size) { $image_id = attachment_url_to_postid( $image_url ); if ($image_id) { $image_array = wp_get_attachment_image_src($image_id, $size, true); $image_url = $image_array[0]; $image_width = $image_array[1]; $image_height = $image_array[2]; } } } switch ($featured_image) { case 'image': $featured_image_output = $amp_html; break; case 'url': $featured_image_output = $image_url; break; case 'width': $featured_image_output = $image_width; break; case 'height': $featured_image_output = $image_height; break; default: $featured_image_output = $amp_html; break; } return $featured_image_output; } // Remove 1st image from the content if Featured image from the content option is enabled if( ! function_exists( 'featured_image_content_filter' ) ){ function featured_image_content_filter($content){ global $redux_builder_amp; $featured_image = ""; $featured_image = ampforwp_get_featured_image_from_content('url'); if( $featured_image && false == $redux_builder_amp['ampforwp-duplicate-featured-image']){ // Change the src to use it in the pattern $featured_image = str_replace('/', '\/', $featured_image); // Remove the figure (due to caption) $content = preg_replace('//', '', $content); // Remove the amp-img if(false == has_post_thumbnail()){ $content = preg_replace('//', '', $content); } } return $content; } } // 84. Inline Related Posts function ampforwp_inline_related_posts(){ global $post, $redux_builder_amp; $string_number_of_related_posts = $redux_builder_amp['ampforwp-number-of-inline-related-posts']; $int_number_of_related_posts = round(abs(floatval($string_number_of_related_posts))); // declaring this variable here to prevent debug errors $args = null; $orderby = 'ID'; if( isset( $redux_builder_amp['ampforwp-inline-related-posts-order'] ) && $redux_builder_amp['ampforwp-inline-related-posts-order'] ){ $orderby = 'rand'; } // Custom Post types if( $current_post_type = get_post_type( $post )) { // The query arguments //#1263 if($current_post_type != 'page'){ $args = array( 'posts_per_page'=> $int_number_of_related_posts, 'order' => 'DESC', 'orderby' => $orderby, 'post_type' => $current_post_type, 'no_found_rows' => true, 'post__not_in' => array( $post->ID ) ); } }//end of block for custom Post types if($redux_builder_amp['ampforwp-inline-related-posts-type']==2){ $categories = get_the_category($post->ID); if ($categories) { $category_ids = array(); foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id; $args=array( 'category__in' => $category_ids, 'post__not_in' => array($post->ID), 'posts_per_page'=> $int_number_of_related_posts, 'ignore_sticky_posts'=>1, 'has_password' => false , 'post_status'=> 'publish', 'no_found_rows' => true, 'orderby' => $orderby ); } } //end of block for categories //code block for tags if($redux_builder_amp['ampforwp-inline-related-posts-type']==1) { $ampforwp_tags = get_the_tags($post->ID); if ($ampforwp_tags) { $tag_ids = array(); foreach($ampforwp_tags as $individual_tag) $tag_ids[] = $individual_tag->term_id; $args=array( 'tag__in' => $tag_ids, 'post__not_in' => array($post->ID), 'posts_per_page'=> $int_number_of_related_posts, 'ignore_sticky_posts'=>1, 'has_password' => false , 'post_status'=> 'publish', 'no_found_rows' => true, 'orderby' => $orderby ); } }//end of block for tags if(true == ampforwp_get_setting('ampforwp-in-content-related-posts-days-switch')){ $date_range = strtotime ( '-' . ampforwp_get_setting('ampforwp-in-content-related-posts-days-text') .' day' ); $args['date_query'] = array( array( 'after' => array( 'year' => date('Y', esc_html($date_range) ), 'month' => date('m', esc_html($date_range) ), 'day' => date('d', esc_html($date_range)), ), ) ); } $args = apply_filters('ampforwp_inlne_related_posts_query_args', $args); $inline_related_posts = ''; $my_query = new wp_query( $args ); if( $my_query->have_posts() ) { $inline_related_posts_img = ''; $inline_related_posts = '
'.esc_html(ampforwp_translation( ampforwp_get_setting('amp-translator-incontent-related-text'), 'Related Post' )).'
    '; while( $my_query->have_posts() ) { $my_query->the_post(); $related_post_permalink = get_permalink(); $related_post_permalink = trailingslashit($related_post_permalink); $related_post_permalink = ampforwp_url_controller( $related_post_permalink ); $related_post_permalink = ampforwp_modify_url_utm_params($related_post_permalink); if ( ampforwp_has_post_thumbnail() ) { $title_class = 'has_related_thumbnail'; } else { $title_class = 'no_related_thumbnail'; } $inline_related_posts .= '
  1. '; if ( true == $redux_builder_amp['ampforwp-single-related-posts-image'] ) { $inline_related_posts .= ''; $thumb_url_2 = ampforwp_get_post_thumbnail('url'); if ( ampforwp_has_post_thumbnail() ) { if( 4 == $redux_builder_amp['amp-design-selector'] ){ $r_width = 220; $r_height = 134; if(function_exists('ampforwp_get_retina_image_settings')){ $ret_config = ampforwp_get_retina_image_settings($r_width,$r_height); $r_width = intval($ret_config['width']); $r_height = intval($ret_config['height']); } $thumb_url_2 = ampforwp_aq_resize( $thumb_url_2, $r_width , $r_height , true, false, true ); $inline_related_posts_img = ''; if(!isset($thumb_url_2[0]) && is_null($thumb_url_2[0]) || wp_check_filetype(ampforwp_get_post_thumbnail('url') == 'svg')){ $thumb_url = ampforwp_get_post_thumbnail('url'); $inline_related_posts_img = ''; } } else{ $r_width = 150; $r_height = 150; if(function_exists('ampforwp_get_retina_image_settings')){ $ret_config = ampforwp_get_retina_image_settings($r_width,$r_height); $r_width = intval($ret_config['width']); $r_height = intval($ret_config['height']); } $thumb_url_2 = ampforwp_aq_resize( $thumb_url_2, $r_width , $r_height , true, false,true ); $thumb_url = $thumb_url_2[0]; $thumb_width = $thumb_url_2[1]; $thumb_height = $thumb_url_2[2]; $inline_related_posts_img = ''; if(!isset($thumb_url_2[0]) && is_null($thumb_url_2[0]) || wp_check_filetype(ampforwp_get_post_thumbnail('url') == 'svg')){ $thumb_url = ampforwp_get_post_thumbnail('url'); $inline_related_posts_img = ''; } } $inline_related_posts_img = apply_filters("ampforwp_modify_inline_rp_loop_image",$inline_related_posts_img); $inline_related_posts .= $inline_related_posts_img; } $inline_related_posts .=''; } $inline_related_posts .='
  2. '; } $inline_related_posts .= '
'; } wp_reset_postdata(); return $inline_related_posts; //related posts code ends here } add_action('pre_amp_render_post','ampforwp_add_inline_related_posts'); function ampforwp_add_inline_related_posts(){ global $redux_builder_amp; if($redux_builder_amp['ampforwp-inline-related-posts'] == 1 && is_single() && ampforwp_inline_related_posts() ){ if( isset($redux_builder_amp['ampforwp-inline-related-posts-display-type']) && $redux_builder_amp['ampforwp-inline-related-posts-display-type']=='middle' ){ add_filter('ampforwp_modify_the_content','ampforwp_generate_inline_related_posts'); }else{ add_filter('ampforwp_modify_the_content','ampforwp_generate_inline_related_posts_by_paragraph'); } } } function ampforwp_generate_inline_related_posts($content){ global $post; $break_point = '

'; $content_parts = explode($break_point, $content); array_walk($content_parts, function(&$value, $key) { $value = trim($value); if( !empty($value) && (strpos($value, "

")!==false || strpos($value, "

")!==false)){ $value .= '

'; $value .= '
'; } } ); if(count($content_parts)>1){ $no_of_parts = count($content_parts); $half_index = floor($no_of_parts / 2); $half_content = array_chunk($content_parts, $half_index); $html ='
'.ampforwp_inline_related_posts().'
'; $half_content[0][] = $html; $final_content =''; foreach ($half_content as $key => $value) { $final_content .= implode("", $value); } $content = $final_content; } return $content; } function ampforwp_generate_inline_related_posts_by_paragraph($content){ global $redux_builder_amp; $total_count = ''; $int_number_of_paragraphs = (integer) ampforwp_get_setting('ampforwp-related-posts-after-number-of-paragraphs'); if(isset($int_number_of_paragraphs) && $int_number_of_paragraphs!=''){ if($int_number_of_paragraphs == 0){ $content = '
'.ampforwp_inline_related_posts().'
'.$content; }else{ $total_count = explode("

", $content); $total_count = count($total_count); // call count() only once, it's faster if($total_count < $int_number_of_paragraphs){ $content = $content.'
'.ampforwp_inline_related_posts().'
'; }else{ $content = preg_replace_callback('#(

.*?

)#', 'ampforwp_add_related_post_after_paragraph', $content); } } }else{ $content = $content.'
'.ampforwp_inline_related_posts().'
'; } return $content; } function ampforwp_add_related_post_after_paragraph($matches) { global $redux_builder_amp; static $count = 0; $ret = ''; $int_number_of_paragraphs = (integer) ampforwp_get_setting('ampforwp-related-posts-after-number-of-paragraphs'); $ret = $matches[1]; if (++$count == $int_number_of_paragraphs){ $ret .= '
'.ampforwp_inline_related_posts().'
'; } return $ret; } // 85. Caption for Gallery Images // Add extra key=>value pair into the attachment array add_filter('amp_gallery_image_params','ampforwp_gallery_new_params', 10, 2); function ampforwp_gallery_new_params($urls, $attachment_id ){ $img_caption = $captext = ''; $new_urls = $caption = array(); if(isset($urls['caption']) && $urls['caption'] ){ $img_caption = $urls['caption']; } $captext = $img_caption; if($captext==""){ $captext = get_post( $attachment_id)->post_excerpt; } if($captext){ // Append only when caption is present $caption = array('caption'=>$captext); $new_urls = array_merge($urls,$caption); return $new_urls; } else{ //If there's No caption return $urls; } } if( !function_exists( 'ampforwp_carousel_class_magic' ) ){ function ampforwp_carousel_class_magic($content){ $content = str_replace(array(':openbrack:',':closebrack:'), array('[',']'), $content); return $content; } } // 86. minify the content of pages // Moved to performance-functions.php // 87. Post Thumbnail // Checker for Post Thumbnail if( !function_exists('ampforwp_has_post_thumbnail')){ function ampforwp_has_post_thumbnail(){ global $post, $redux_builder_amp; if(class_exists('Bunyad') && Bunyad::posts()->meta('featured_video') ){ return true; }elseif(function_exists('has_post_video') && has_post_video($post->ID)){ return true; }elseif(has_post_thumbnail()){ return true; } elseif(ampforwp_is_custom_field_featured_image() && ampforwp_cf_featured_image_src()){ return true; } elseif(isset($redux_builder_amp['ampforwp-featured-image-from-content']) && $redux_builder_amp['ampforwp-featured-image-from-content'] == true){ if( ampforwp_get_featured_image_from_content() || ampforwp_get_featured_image_from_content('url') ){ return true; } } else return false; } } // Get Post Thumbnail URL if( !function_exists('ampforwp_get_post_thumbnail')){ function ampforwp_get_post_thumbnail($param="", $size=""){ global $post, $redux_builder_amp; $thumb_url = ''; $thumb_width = ''; $thumb_height = ''; $output = ''; if ( has_post_thumbnail()) { if( empty($size) ) { $size = 'medium'; } $thumb_id = get_post_thumbnail_id(); $thumb_url_array = wp_get_attachment_image_src($thumb_id, $size , true); $thumb_url = $thumb_url_array[0]; $thumb_width = $thumb_url_array[1]; $thumb_height = $thumb_url_array[2]; $thumb_alt = ''; $thumb_alt = get_post_meta ( $thumb_id, '_wp_attachment_image_alt', true ); } if(ampforwp_is_custom_field_featured_image() && ampforwp_cf_featured_image_src()){ $thumb_url = ampforwp_cf_featured_image_src(); $thumb_width = ampforwp_cf_featured_image_src('width'); $thumb_height = ampforwp_cf_featured_image_src('height'); } if( true == $redux_builder_amp['ampforwp-featured-image-from-content'] && ampforwp_get_featured_image_from_content('url') ){ $thumb_url = ampforwp_get_featured_image_from_content('url', $size); $thumb_width = ampforwp_get_featured_image_from_content('width', $size); $thumb_height = ampforwp_get_featured_image_from_content('height', $size); } switch ($param) { case 'url': $output = $thumb_url; break; case 'width': $output = $thumb_width; break; case 'height': $output = $thumb_height; break; case 'alt': $output = $thumb_alt; break; default: $output = $thumb_url; break; } return $output; } } // 88. Author Details // Author Page URL if( ! function_exists( 'ampforwp_get_author_page_url' ) ){ function ampforwp_get_author_page_url(){ global $redux_builder_amp, $post; $author_id = ''; $author_page_url = ''; $author_id = get_the_author_meta( 'ID' ); $author_page_url = get_author_posts_url( $author_id ); // If Archive support is enabled if( isset($redux_builder_amp['ampforwp-archive-support'] ) && $redux_builder_amp['ampforwp-archive-support'] ){ $author_page_url = ampforwp_url_controller( $author_page_url ); } return $author_page_url; } } // Author Meta if( ! function_exists( 'ampforwp_get_author_details' ) ){ function ampforwp_get_author_details( $post_author , $params='' ){ global $redux_builder_amp, $post; $post_author_url = ''; $post_author_name = ''; $post_author_name = $post_author->display_name; $post_author_url = ampforwp_get_author_page_url(); $and_text = ''; $and_text = ampforwp_translation($redux_builder_amp['amp-translator-and-text'], 'and' ); if ( function_exists('coauthors') ) { $post_author_name = coauthors($and_text,$and_text,null,null,false); } if ( function_exists('coauthors_posts_links') ) { $post_author_url = coauthors_posts_links($and_text,$and_text,null,null,false); } switch ($params) { case 'meta-info': if( isset($redux_builder_amp['ampforwp-author-page-url']) && $redux_builder_amp['ampforwp-author-page-url'] ) { if ( function_exists('coauthors_posts_links') ) { return ''. $post_author_url .''; } return ''.esc_html( $post_author_name ).''; } else { return '' .esc_html( $post_author_name ).''; } break; case 'meta-taxonomy': if( isset($redux_builder_amp['ampforwp-author-page-url']) && $redux_builder_amp['ampforwp-author-page-url'] ) { if ( function_exists('coauthors_posts_links') ) { return $post_author_url; } return '' . esc_html( $post_author_name ) . ': '; } else{ return ' ' . esc_html( $post_author_name) . ': '; } break; } } } // 89. Facebook Pixel // Moved to analytics-functions.php // 91. Comment Author Gravatar URL if( ! function_exists('ampforwp_get_comments_gravatar') ){ function ampforwp_get_comments_gravatar( $comment ) { global $redux_builder_amp; if(isset($redux_builder_amp['ampforwp-display-avatar']) && $redux_builder_amp['ampforwp-display-avatar']==0){ return ''; } if (class_exists('FV_Gravatar_Cache')) { $options = get_option('fv_gravatar_cache'); $size = $options['size']; if (empty($size)) { $size = '96'; } $avatar_url = get_avatar_url($comment); $upload_dir = wp_upload_dir(); $upload_dir = $upload_dir['baseurl'] . '/fv-gravatar-cache/'; $avatar_url = preg_replace('/(.*?)avatar\/(.*?)\?s=(.*?)&(.*?)g/', ''.$upload_dir.'$2x$3.png', $avatar_url); preg_match_all('/(.*?)wp-content\/uploads\/fv-gravatar-cache\/(.*?)/U', $avatar_url, $match); $url = $match[0][0]; $headers = get_headers($url, 1); if(isset($headers[0]) && !stripos($headers[0], "200 OK")){ $avatar_url = $upload_dir.'mystery'. esc_html($size) .'.png'; } return $avatar_url; } $gravatar_exists = ''; $gravatar_exists = ampforwp_gravatar_checker($comment->comment_author_email); if ( null !== ampforwp_get_wp_user_avatar($comment, 'comment') ) { return ampforwp_get_wp_user_avatar($comment, 'comment'); } elseif($gravatar_exists == true){ return get_avatar_url( $comment, apply_filters( 'ampforwp_get_comments_gravatar', '60' ), '' ); } else return apply_filters( 'ampforwp_get_comments_gravatar', '' ); } } // Gravatar Checker if ( ! function_exists('ampforwp_gravatar_checker') ) { function ampforwp_gravatar_checker( $email ) { $uri = ""; // Craft a potential url and test its headers $hash = md5(strtolower(trim($email))); $gravatar_server = 0; if ( $hash ) { $gravatar_server = hexdec( $hash[0] ) % 3; } else { $gravatar_server = rand( 0, 2 ); } if ( is_ssl() ) { $uri = 'https://secure.gravatar.com/avatar/' . $hash; } else { $uri = sprintf( 'http://%d.gravatar.com/avatar/%s', $gravatar_server, $hash ); } if($uri){ $response = wp_remote_get(esc_url_raw($uri)); $response_code = wp_remote_retrieve_response_code($response); } //If its 404 if ($response_code!=200) { $has_valid_avatar = FALSE; }else { $has_valid_avatar = TRUE; } return $has_valid_avatar; } } function ampfowp_add_extra_css(){ echo ''; } if ( is_user_logged_in() ) { add_action('wp_head', 'ampfowp_add_extra_css'); } // 92. View AMP in Admin Bar add_action( 'wp_before_admin_bar_render', 'ampforwp_view_amp_admin_bar' ); if( ! function_exists( 'ampforwp_view_amp_admin_bar' ) ) { function ampforwp_view_amp_admin_bar( ) { global $wp_admin_bar, $post, $wp_post_types, $redux_builder_amp; $post_type_title = $current_url = ''; $supported_amp_post_types = array(); // Get all post types supported by AMP $supported_amp_post_types = ampforwp_get_all_post_types(); $current_access = false; // Check for Admin if ( is_admin() ) { $current_screen = get_current_screen(); $current_access = ('post' == $current_screen->base && 'add' != $current_screen->action); }elseif(is_user_logged_in()){ $current_user = wp_get_current_user(); $current_access = current_user_can('edit_posts',$current_user ); } // Check for Screen base, user ability to read and visibility if ($current_access && (isset($post->ID) && $post->ID && current_user_can('read_post', $post->ID )) && ( isset ( $wp_post_types[ $post->post_type ]->public ) && $wp_post_types[$post->post_type]->public ) && ( isset ( $wp_post_types[ $post->post_type ]->show_in_admin_bar ) && $wp_post_types[$post->post_type]->show_in_admin_bar ) ) { // Check if current post type is AMPed or not if( $supported_amp_post_types && in_array($post->post_type, $supported_amp_post_types) ){ // If AMP on Posts or Pages is off then do nothing if($post->post_type == 'post' && !ampforwp_get_setting('amp-on-off-for-all-posts') || $post->post_type == 'page' && !ampforwp_get_setting('amp-on-off-for-all-pages')) { return; } if( is_archive() && is_category() ){ if(!ampforwp_get_setting('ampforwp-archive-support') || !ampforwp_get_setting('ampforwp-archive-support-cat') ){ return ; } }elseif( is_archive() && is_tag() ){ if(!ampforwp_get_setting('ampforwp-archive-support') || !ampforwp_get_setting('ampforwp-archive-support-tag') ){ return ; } }elseif( is_archive() && is_tax()){ $taxonomies = ampforwp_get_setting('ampforwp-custom-taxonomies'); if(empty($taxonomies)){ return ; }else{ $term_id = get_queried_object()->term_id; $termObj = get_term( $term_id); if( in_array($termObj->taxonomy, $taxonomies)){ }else{ return ; } } } if( is_archive() && is_category()){ $term_id = get_queried_object()->term_id; $termObj = get_term( $term_id); $taxonomy_objects = get_object_taxonomies( 'post', 'objects' ); $post_type_title = $taxonomy_objects[$termObj->taxonomy]->labels->singular_name; if(ampforwp_get_setting('ampforwp-archive-support') == true && ampforwp_get_setting('ampforwp-archive-support-cat') == true){ $current_url = get_term_link($term_id); } }elseif( is_archive() && is_tag()){ $term_id = get_queried_object()->term_id; $termObj = get_term( $term_id); $taxonomy_objects = get_object_taxonomies( 'post', 'objects' ); $post_type_title = $taxonomy_objects[$termObj->taxonomy]->labels->singular_name; if(ampforwp_get_setting('ampforwp-archive-support') == true && ampforwp_get_setting('ampforwp-archive-support-tag') == true){ $current_url = get_term_link($term_id); } }elseif(is_archive() && is_tax()){ $term_id = get_queried_object()->term_id; $termObj = get_term( $term_id); $taxonomy_objects = get_taxonomy( $termObj->taxonomy ); $post_type_title = $taxonomy_objects->labels->singular_name; $current_url = get_term_link($term_id); }else{ $post_type_title = ucfirst($post->post_type); $current_url = get_permalink( $post->ID ); if(is_home()){ $current_url = home_url(); } } if (is_preview()) { $current_url = $current_url .'&=1&preview=true'; $wp_admin_bar->add_node(array( 'id' => 'ampforwp-view-amp', 'title' => 'View ' . esc_html($post_type_title) . ' (AMP)' , 'href' => esc_url($current_url) )); }else{ $wp_admin_bar->add_node(array( 'id' => 'ampforwp-view-amp', 'title' => 'View ' . esc_html($post_type_title) . ' (AMP)' , 'href' => ampforwp_url_controller($current_url) )); } } } } } // 94. OneSignal Push Notifications // Moved to push-notification-functions.php // 95. Modify menu link attributes for SiteNavigationElement Schema Markup #1229 #1345 add_filter( 'nav_menu_link_attributes', 'ampforwp_nav_menu_link_attributes', 10, 3 ); if( ! function_exists( 'ampforwp_nav_menu_link_attributes' ) ) { function ampforwp_nav_menu_link_attributes( $atts, $item, $args ) { if ( function_exists('ampforwp_is_amp_endpoint') && ampforwp_is_amp_endpoint() ) { // Manipulate link attributes $atts['itemprop'] = "url"; } return $atts; } } // 96. ampforwp_is_front_page() ampforwp_is_home() and ampforwp_is_blog is created // Moved to functions.php // 97. Change the format of the post date on Loops #1384 add_filter('ampforwp_modify_post_date', 'ampforwp_full_post_date_loops'); if( ! function_exists( 'ampforwp_full_post_date_loops' ) ){ function ampforwp_full_post_date_loops($full_date){ global $redux_builder_amp; if( is_home() || is_archive() ){ if( 2 == $redux_builder_amp['ampforwp-post-date-format'] ){ $full_date = get_the_date(); if( 2 == $redux_builder_amp['ampforwp-post-date-global'] ){ $full_date = get_the_modified_date(); } } if( 1 == $redux_builder_amp['ampforwp-post-date-format'] ){ $time = ampforwp_get_the_time(); $date = human_time_diff( $time, current_time('timestamp') ); if( $redux_builder_amp['ampforwp-post-date-format-text'] ){ $full_date = $redux_builder_amp['ampforwp-post-date-format-text']; // Change the % days into the actual number of days $full_date = str_replace('% days', $date, $full_date); $full_date = str_replace('ago', ampforwp_translation( $redux_builder_amp['amp-translator-ago-date-text'],'ago'), $full_date); } } } if(is_single() && 1 == $redux_builder_amp['ampforwp-post-date-format']){ $time = ampforwp_get_the_time(); $date = human_time_diff( $time, current_time('timestamp') ); $full_date = human_time_diff( $time, current_time('timestamp') ) .' '. ampforwp_translation( $redux_builder_amp['amp-translator-ago-date-text'],'ago'); if( $redux_builder_amp['ampforwp-post-date-format-text'] ){ $full_date = $redux_builder_amp['ampforwp-post-date-format-text']; // Change the % days into the actual number of days $full_date = str_replace('% days', $date, $full_date); $full_date = str_replace('ago', ampforwp_translation( $redux_builder_amp['amp-translator-ago-date-text'],'ago'), $full_date); } } return $full_date; } } if(!function_exists('ampforwp_get_the_time')){ function ampforwp_get_the_time(){ $time = get_the_time('U', get_the_ID()); if( 2 == ampforwp_get_setting('ampforwp-post-date-global') ){ $time = get_the_modified_time('U', get_the_ID() ); } if(defined('ECWD_VERSION')){ global $ecwd_options; $tz = $ecwd_options['time_zone']; $ewwetz = new DateTime( get_the_time('c', get_the_ID()) ); if( 2 == ampforwp_get_setting('ampforwp-post-date-global') ){ $ewwetz = new DateTime( get_the_modified_time('c', get_the_ID()) ); } $ewwetz->setTimezone(new DateTimeZone($tz)); $time = $ewwetz->format('U'); } return $time; } } // 99. Merriweather Font Management add_filter( 'amp_post_template_data', 'ampforwp_merriweather_font_management' ); function ampforwp_merriweather_font_management( $data ) { if ( 1 != ampforwp_get_setting('amp-design-selector') || ( false == ampforwp_get_setting('ampforwp-d1-font') && 1 == ampforwp_get_setting('amp-design-selector') ) ) { unset($data['font_urls']['merriweather']); } return $data; } // 100. Flags compatibility in Menu add_filter('ampforwp_menu_content','ampforwp_modify_menu_content'); if( ! function_exists(' ampforwp_modify_menu_content ') ){ function ampforwp_modify_menu_content($menu){ $dom = ''; $nodes = ''; $num_nodes = ''; if( !empty( $menu ) ){ // Create a new document $dom = new DOMDocument(); if( function_exists( 'mb_convert_encoding' ) ){ $menu = mb_convert_encoding($menu, 'HTML-ENTITIES', 'UTF-8'); } else{ $menu = preg_replace( '/&[^amp|#038].*?;/', 'x', $menu ); // multi-byte characters converted to X } // To Suppress Warnings libxml_use_internal_errors(true); $dom->loadHTML($menu); libxml_use_internal_errors(false); // get all the img's $nodes = $dom->getElementsByTagName( 'img' ); $num_nodes = $nodes->length; for ( $i = $num_nodes - 1; $i >= 0; $i-- ) { $node = $nodes->item( $i ); // Set The Width and Height if there in none if ( '' === $node->getAttribute( 'width' ) ) { $node->setAttribute('width', 15); } if( '' === $node->getAttribute( 'height' ) ){ $node->setAttribute('height', 15); } } $menu = $dom->saveHTML(); } return $menu; } } /* * Fetches the logo data * More details about the fix https://github.com/ahmedkaludi/accelerated-mobile-pages/pull/2317 * Props to: https://github.com/saucal for suggesting the fix. */ function ampforwp_default_logo_data() { global $redux_builder_amp, $ampwforwp_default_logo_data; if( $ampwforwp_default_logo_data ) { return $ampwforwp_default_logo_data; } $logo_id = ''; $image = array(); $value = ''; $logo_alt = ''; $logo_id = get_theme_mod( 'custom_logo' ); if(isset($redux_builder_amp['opt-media']['id']) && empty( $logo_id ) ) { $logo_id = (integer) $redux_builder_amp['opt-media']['id']; } if( empty( $logo_id ) ) { return false; } if( ! wp_attachment_is( 'image', $logo_id ) || ampforwp_get_setting('opt-media','url') ) { $logo_url = ampforwp_get_setting('opt-media','url'); $image[0] = ampforwp_get_setting('opt-media','width'); $image[1] = ampforwp_get_setting('opt-media','height'); if(empty($image)){ $image = @getimagesize( $logo_url ); } if ( empty($image[0]) || empty($image[1]) ) { $image[0] = '190'; $image[1] = '36'; } } else { $imageDetail = wp_get_attachment_image_src( $logo_id , 'full'); $logo_url = $imageDetail[0]; $image[0] = $imageDetail[1]; $image[1] = $imageDetail[2]; if ( 0 === $image[1] ) { $image[0] = '190'; $image[1] = '36'; } } $logo_alt = get_post_meta( $logo_id, '_wp_attachment_image_alt', true); $ampwforwp_default_logo_data = array( 'logo_id' => $logo_id, 'logo_url' => $logo_url, 'logo_alt' => $logo_alt, 'logo_size' => $image ); return $ampwforwp_default_logo_data; } // 101. Function for Logo attributes function ampforwp_default_logo($param=""){ global $redux_builder_amp; $value = ''; $data = ampforwp_default_logo_data(); if( ! $data ) { if($param!="width" && $param!="height"){ return $value; } } switch ($param) { case 'url': $value = $data['logo_url']; break; case 'width': if (true == ampforwp_get_setting('ampforwp-custom-logo-dimensions') && 'prescribed' ==ampforwp_get_setting('ampforwp-custom-logo-dimensions-options')) { $value = trim(ampforwp_get_setting('opt-media-width')); if($value==""){ $value = 190; } } else $value = ''; if(isset($data['logo_size'][0])){ $value = $data['logo_size'][0]; } if($value==""){ $value = 190; } break; case 'height': if (true == ampforwp_get_setting('ampforwp-custom-logo-dimensions') && 'prescribed' == ampforwp_get_setting('ampforwp-custom-logo-dimensions-options')) { $value = trim(ampforwp_get_setting('opt-media-height')); if($value==""){ $value = 36; } } else $value = ''; if(isset($data['logo_size'][1])){ $value = $data['logo_size'][1]; } if($value==""){ $value = 36; } break; case 'alt': if(isset($data['logo_alt'][0])){ $value = $data['logo_alt']; } else $value = get_bloginfo('name'); break; default: $value = $data['logo_url']; break; } return $value; } // Envira Lazy Load compatibility add_filter('envira_gallery_pre_data', 'ampforwp_envira_lazy_load'); if( ! function_exists(' ampforwp_envira_lazy_load ') ){ function ampforwp_envira_lazy_load($data){ if( function_exists('ampforwp_is_amp_endpoint') && ampforwp_is_amp_endpoint() ){ if(function_exists('envira_get_config')){ $checker = envira_get_config( 'lazy_loading', $data); if( 1 === $checker){ $data['config']['lazy_loading'] = 0; } } } return $data; } } #1581 Instagram Sanitizer add_filter( 'amp_content_sanitizers', 'ampforwp_instagram_sanitizer', 10, 1 ); function ampforwp_instagram_sanitizer( $sanitizer_classes ) { require_once( AMPFORWP_PLUGIN_DIR. 'classes/class-ampforwp-instagram-sanitizer.php' ); $sanitizer_classes[ 'AMPFORWP_Instagram_Embed_Sanitizer' ] = array(); return $sanitizer_classes; } // Allowed Tags if ( ! function_exists('ampforwp_allowed_tags') ) { function ampforwp_allowed_tags() { $allowed_tags = ''; $allowed_tags = wp_kses_allowed_html('post'); $allowed_tags['a']['itemprop'] = true; $allowed_tags['span']['itemprop'] = true; return $allowed_tags; } } // List of Subpages/Childpages on Pages add_action('ampforwp_after_post_content', 'ampforwp_list_subpages'); if ( ! function_exists('ampforwp_list_subpages') ) { function ampforwp_list_subpages() { if (class_exists('AddWidgetAfterContent')) { $sanitized_output = ''; $sanitized_output = ampforwp_sidebar_content_sanitizer('add-widget-after-content'); if ( $sanitized_output) { $sanitized_output = $sanitized_output->get_amp_content();?>
0, 'child_of' => $post->ID, 'title_li' => '', ) ); $pages = preg_replace('/href="(.*?)"/', 'href="$1/amp/"', $pages); echo wp_kses($pages, ampforwp_allowed_tags()); } } } // Disable wptextturize #1458 add_action('init','ampforwp_wptexturize_disabler'); if ( ! function_exists('ampforwp_wptexturize_disabler') ) { function ampforwp_wptexturize_disabler(){ global $redux_builder_amp; if ( isset($redux_builder_amp['ampforwp-wptexturize']) && true == $redux_builder_amp['ampforwp-wptexturize'] ) { remove_filter('the_content', 'wptexturize'); remove_filter('the_title', 'wptexturize'); } } } // amp-vimeo proper video id for 3 parameter url add_filter('amp_vimeo_parse_url','amp_vimeo_parse_url_video_id'); function amp_vimeo_parse_url_video_id($tok){ if (in_array("ondemand", $tok) && sizeof($tok)==3){ $tok = ''; return $tok; } if(sizeof($tok)==3){ return $tok[1]; }else{ return end($tok); } } // Cart Page URL if( ! function_exists( 'ampforwp_wc_cart_page_url' ) ){ function ampforwp_wc_cart_page_url(){ if(function_exists('amp_woocommerce_pro_add_woocommerce_support') && (function_exists('wc_get_cart_url') || function_exists('get_cart_url'))){ global $woocommerce; $cart_url = function_exists( 'wc_get_cart_url' ) ? wc_get_cart_url() : $woocommerce->cart->get_cart_url(); $cart_url = ampforwp_url_controller($cart_url); return $cart_url; } else return '#'; } } // Add Google Font support add_action('amp_post_template_css', 'ampforwp_google_fonts_generator'); if ( ! function_exists( 'ampforwp_google_fonts_generator' ) ) { function ampforwp_google_fonts_generator() { global $redux_builder_amp; if( 1!=ampforwp_get_setting('ampforwp-google-font-switch') || true == ampforwp_get_setting('amp_google_font_restrict')){ return; } if(isset($redux_builder_amp['google_current_font_data'])){ $font_data = json_decode(stripslashes($redux_builder_amp['google_current_font_data'])); } $font_weight = ""; $font_output = ""; $font_type = ""; if(isset( $redux_builder_amp['amp_font_type'])){ $font_type = $redux_builder_amp['amp_font_type']; } if ( $font_type && ampforwp_get_setting('amp_font_selector') != 'Segoe UI') { foreach ($font_type as $key => $value) { // Font Weight generator $font_weight = (int) $value; $font_weight = ( $font_weight != 0 ? $font_weight : 400 ); // Font Stlye Generator $font_style = preg_replace('/\d+/u', '', $value); $font_style = ( $font_style == 'italic' ? 'italic' : 'normal' ); // Local Generator // Font Weight $font_local_weight = ''; if ( $font_weight === 100 ) { $font_local_weight = 'Thin'; } if ( $font_weight === 200 ) { $font_local_weight = 'Ultra Light'; } if ( $font_weight === 300 ) { $font_local_weight = 'Light'; } if ( $font_weight === 400 ) { $font_local_weight = 'Regular'; } if ( $font_weight === 500 ) { $font_local_weight = 'Medium'; } if ( $font_weight === 600 ) { $font_local_weight = 'SemiBold'; } if ( $font_weight === 700 ) { $font_local_weight = 'Bold'; } if ( $font_weight === 800 ) { $font_local_weight = 'ExtraBold'; } if ( $font_weight === 900 ) { $font_local_weight = 'Black'; } // Font Style $font_local_type = ''; if ('italic' === $font_style) { $font_local_type = 'Italic'; } $font_output .= "@font-face { "; $font_output .= "font-family: " . $redux_builder_amp['amp_font_selector']. ';' ; $font_output .= "font-display: optional;"; $font_output .= "font-style: " . $font_style . ';'; $font_output .= "font-weight: " . $font_weight . ';' ; $font_output .= "src: local('". $redux_builder_amp['amp_font_selector']." ".$font_local_weight." ".$font_local_type."'), local('". $redux_builder_amp['amp_font_selector']."-".$font_local_weight.$font_local_type."'), url(" .str_replace("http://", "https://", $font_data->files->$value) . ');' ; $font_output .= "}"; } } //for Single content Font Family if(ampforwp_get_setting('content-font-family-enable') && (is_singular() || (ampforwp_get_setting('amp-design-selector')!=4) ) ){ if(ampforwp_get_setting('google_current_font_data_content_single')){ $font_data = json_decode(stripslashes(ampforwp_get_setting('google_current_font_data_content_single'))); } $font_output .= "\n"; if( ampforwp_get_setting('amp_font_type_content_single') ){ $font_type = ampforwp_get_setting('amp_font_type_content_single'); } if ( $font_type && ampforwp_get_setting('amp_font_selector_content_single') != 'Segoe UI') { foreach ($font_type as $key => $value) { // Font Weight generator $font_weight = (int) $value; $font_weight = ( $font_weight != 0 ? $font_weight : 400 ); // Font Stlye Generator $font_style = preg_replace('/\d+/u', '', $value); $font_style = ( $font_style == 'italic' ? 'italic' : 'normal' ); // Local Generator // Font Weight $font_local_weight = ''; if ( $font_weight === 100 ) { $font_local_weight = 'Thin'; } if ( $font_weight === 200 ) { $font_local_weight = 'Ultra Light'; } if ( $font_weight === 300 ) { $font_local_weight = 'Light'; } if ( $font_weight === 400 ) { $font_local_weight = 'Regular'; } if ( $font_weight === 500 ) { $font_local_weight = 'Medium'; } if ( $font_weight === 600 ) { $font_local_weight = 'SemiBold'; } if ( $font_weight === 700 ) { $font_local_weight = 'Bold'; } if ( $font_weight === 800 ) { $font_local_weight = 'ExtraBold'; } if ( $font_weight === 900 ) { $font_local_weight = 'Black'; } // Font Style $font_local_type = ''; if ('italic' === $font_style) { $font_local_type = 'Italic'; } $font_output .= "@font-face { "; $font_output .= "font-family: " . esc_attr(ampforwp_get_setting('amp_font_selector_content_single')). ';' ; if (ampforwp_get_setting('ampforwp_font_display') == 'optional') { $font_output .= "font-display: optional".';'; }else{ $font_output .= "font-display: swap".';'; } $font_output .= "font-style: " . esc_attr($font_style) . ';'; $font_output .= "font-weight: " . esc_attr($font_weight) . ';' ; $font_output .= "src: local('". esc_attr(ampforwp_get_setting('amp_font_selector_content_single'))." ".esc_attr($font_local_weight)." ".esc_attr($font_local_type)."'), local('". esc_attr(ampforwp_get_setting('amp_font_selector_content_single'))."-".esc_attr($font_local_weight).$font_local_type."'), url(" .esc_url(str_replace("http://", "https://", $font_data->files->$value)) . ');' ; $font_output .= "}"; } } } echo $font_output; // escaped above } } function swifttheme_footer_widgets_init() { register_sidebar( array( 'name' => esc_html__( 'AMP Widget Below Header', 'accelerated-mobile-pages' ), 'id' => 'ampforwp-below-header', 'description' => esc_html__( 'This Widget will be display on Below Header area', 'accelerated-mobile-pages' ), 'class'=>'w-bl', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => esc_html__( 'AMP Widget Above Loop', 'accelerated-mobile-pages' ), 'id' => 'ampforwp-above-loop', 'description' => esc_html__( 'This Widget will be display on Above Loop area', 'accelerated-mobile-pages' ), 'class'=>'w-bl', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => esc_html__( 'AMP Widget Below loop', 'accelerated-mobile-pages' ), 'id' => 'ampforwp-below-loop', 'description' => esc_html__( 'This Widget will be display on Below loop area', 'accelerated-mobile-pages' ), 'class'=>'w-bl', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => esc_html__( 'AMP Widget Above Footer', 'accelerated-mobile-pages' ), 'id' => 'ampforwp-above-footer', 'description' => esc_html__( 'This Widget will be display on Above Footer area', 'accelerated-mobile-pages' ), 'class'=>'w-bl', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); if(ampforwp_design_selector()==4 || ampforwp_design_selector()==3 || ampforwp_design_selector()==2 || ampforwp_design_selector()==1){ register_sidebar( array( 'name' => esc_html__( 'AMP Footer', 'accelerated-mobile-pages' ), 'id' => 'swift-footer-widget-area', 'description' => esc_html__( 'The Footer widget area', 'accelerated-mobile-pages' ), 'class'=>'w-bl', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); if(true == ampforwp_get_setting('gnrl-sidebar')){ register_sidebar( array( 'name' => esc_html__( 'AMP Sidebar', 'accelerated-mobile-pages' ), 'id' => 'swift-sidebar', 'description' => esc_html__( 'The Swift Sidebar', 'accelerated-mobile-pages' ), 'class'=>'amp-sidebar', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); } } } add_action( 'init', 'swifttheme_footer_widgets_init' ); // AMP Takeover function ampforwp_is_non_amp( $type="" ) { global $redux_builder_amp; $non_amp = false; $ampforwp_amp_post_on_off_meta = $post_id = ''; $post_id = get_the_ID(); if ( ampforwp_is_front_page() ) { $post_id = ampforwp_get_frontpage_id(); } if ( false !== get_query_var( 'amp', false ) ) { return false; } $mob_pres_link = ampforwp_mobile_redirect_preseve_link(); if (""===$type && (ampforwp_get_setting('ampforwp-amp-takeover') || $mob_pres_link == true) ) { $non_amp = true; // Check for Posts if ( is_single() && false == ampforwp_get_setting('amp-on-off-for-all-posts') ) { return false; } // Archives if ( is_archive() && false == ampforwp_get_setting('ampforwp-archive-support') ) { return false; } // Pages if ( is_page() && false == ampforwp_get_setting('amp-on-off-for-all-pages') ) { return false; } //Blogpage $page_for_posts = intval(get_option( 'page_for_posts' )); if ( $page_for_posts == ampforwp_get_the_ID() ) { return true; } // Homepage if ( is_home() && false == ampforwp_get_setting('ampforwp-homepage-on-off-support') ) { return false; } // Search #2681 if ( is_search() && ( (4 == ampforwp_get_setting('amp-design-selector') && false == ampforwp_get_setting('amp-swift-search-feature') ) ) ){ return false; } //Removed AMP Takeover when custom 404 Page is selected in enfold theme #4723 if ( function_exists('avia_preload_screen') && !empty(avia_get_option('error404_page')) && is_404() ) { return false; } // Enabling AMP Takeover only when selected in Custom Post Type $supported_types_for_takeover = array(); $supported_types_for_takeover = ampforwp_get_all_post_types(); if( $supported_types_for_takeover ){ $current_type = get_post_type(get_the_ID()); if( $current_type==false){ $non_amp = true; }else{ if(!in_array($current_type, $supported_types_for_takeover) && !is_404() && !is_search()){ return ; } } } if ( is_front_page() && false == ampforwp_get_setting('ampforwp-homepage-on-off-support') ) { return false; } if ( is_feed() ) { return false; } if(get_query_var( 'robots' )){ return; } if ( function_exists('is_embed') && is_embed() ){ return; } if(is_search() && 0 == ampforwp_get_setting('amp-redirection-search')){ return false; } }elseif( ( ampforwp_get_setting('amp-design-selector') == 4) && ( true == ampforwp_get_setting('ampforwp-amp-convert-to-wp') ) || ( 'non_amp_check_convert' === $type && true == ampforwp_get_setting('ampforwp-amp-convert-to-wp') ) ) { $non_amp = true; } // Convert AMP to WP issues fixed #2493 //Blogposts if ( is_home() && ampforwp_get_setting('ampforwp-homepage-on-off-support') == false ) { return; } // Pages if ( is_page() && false == ampforwp_get_setting('amp-on-off-for-all-pages') ) { return; } if ( is_singular() || ampforwp_is_front_page() || ampforwp_is_blog() ) { $ampforwp_amp_post_on_off_meta = get_post_meta( $post_id,'ampforwp-amp-on-off',true); if($ampforwp_amp_post_on_off_meta == 'hide-amp'){ return false; } } // Removing the AMP on login register etc of Theme My Login plugin if (function_exists('tml_register_default_actions')){ $tml_pages = tml_get_actions(); $pages = array(); if ( isset($tml_pages) && $tml_pages ) { foreach ($tml_pages as $page) { $pages[] = $page->get_slug(); } } if(in_array(get_query_var('action'), $pages) ){ return false; } } return $non_amp; } function ampforwp_mobile_redirect_preseve_link(){ $redirectToAMP = false; if(ampforwp_get_setting('amp-mobile-redirection') == true && ampforwp_get_setting('amp-mob-redirection-pres-link') == true){ require_once AMPFORWP_PLUGIN_DIR.'/includes/vendor/Mobile_Detect.php'; $mobile_detect = new AMPforWP_Mobile_Detect; $isMobile = $mobile_detect->isMobile(); $isTablet = $mobile_detect->isTablet(); $isTabletUserAction = ampforwp_get_setting('amp-tablet-redirection'); if( $isMobile && $isTabletUserAction && $isTablet ){ //Only For tablet $redirectToAMP = true; }else if($isMobile && !$isTablet){ // Only for mobile $redirectToAMP = true; } } return $redirectToAMP; } // Remove wpautop from specific posts which contain amp-components add_action('pre_amp_render_post','ampforwp_custom_wpautop'); function ampforwp_custom_wpautop(){ if ( is_single() ) { if ( get_post_meta(get_the_ID(), 'ampforwp-wpautop', true) == 'false') { remove_filter('the_content', 'wpautop'); } } if(function_exists('ubermenu_get_nav_menu_args')){ add_filter( 'ubermenu_nav_menu_args' ,'ampforwp_modify_ubermenu_nav_menu_args' , 10,2); } } function ampforwp_modify_ubermenu_nav_menu_args($args , $config_id){ $args['menu_class'] = 'amp-menu '.$args['menu_class']; return $args; } // Backward Compatibility for AMP Preview #1529 if ( ! function_exists('get_preview_post_link') ) { function get_preview_post_link( $post = null, $query_args = array(), $preview_link = '' ) { $post = get_post( $post ); if ( ! $post ) { return; } $post_type_object = get_post_type_object( $post->post_type ); if ( is_post_type_viewable( $post_type_object ) ) { if ( ! $preview_link ) { $preview_link = set_url_scheme( get_permalink( $post ) ); } $query_args['preview'] = 'true'; $preview_link = add_query_arg( $query_args, $preview_link ); } return apply_filters( 'preview_post_link', $preview_link, $post ); } } // Homepage Loop Modifier #1701 add_filter('ampforwp_query_args','ampforwp_homepage_loop'); function ampforwp_homepage_loop( $args ) { global $redux_builder_amp; if ( is_home() ) { $post_type = 'post'; // Check if Custom Post Type is selected if ('' != ampforwp_get_setting('ampforwp-homepage-loop-type') ) { $post_type = ampforwp_get_setting('ampforwp-homepage-loop-type'); } $args['post_type'] = $post_type; // Exclude Categories if any selected if ('' != ampforwp_get_setting('ampforwp-homepage-loop-cats') ) { $args['category__not_in'] = ampforwp_get_setting('ampforwp-homepage-loop-cats'); } } return $args; } // To get correct comments count #1662 add_filter('get_comments_number', 'ampforwp_comment_count', 0); function ampforwp_comment_count( $count ) { /* TODO: Allowed memory size exhausted #1865 get_comments() was trying to access by Id and because the ID is not present on amp frontpages. It is getting exhausted. Need to recreate issue and validate the hypothesis */ if ( ! is_admin() && function_exists('ampforwp_is_amp_endpoint') && ampforwp_is_amp_endpoint() && is_single() ) { global $id; $get_comments = get_comments('status=approve&post_id=' . $id); $comments_by_type = separate_comments($get_comments); return count($comments_by_type['comment']); } else { return $count; } } // Glue underline css compatibility #1743 #1932 add_action('amp_post_template_css', 'ampforwp_glue_css_comp', PHP_INT_MAX ); if ( ! function_exists('ampforwp_glue_css_comp') ) { function ampforwp_glue_css_comp() { global $redux_builder_amp; if (class_exists('YoastSEO_AMP_Frontend') ) { ?> a {text-decoration:none;} html {background:none;} .the_content a {text-decoration:underline;} '; } 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; } //remove anchor from the image when lightbox option is enabled #2695 add_action('pre_amp_render_post','ampforwp_remove_ahref_lightbox'); function ampforwp_remove_ahref_lightbox(){ if(true == ampforwp_get_setting('ampforwp-amp-img-lightbox') ){ add_filter( 'the_content', 'ampforwp_remove_ahref_lightbox_in_amp' ); add_filter('tablepress_table_render_data','amforwp_remove_tp_image_href'); } } function ampforwp_remove_ahref_lightbox_in_amp( $content ) { preg_match_all('/((.*?)]*>)/', $content, $matches); if( count($matches[3])){ for( $i=0;$i(]*>)<\/a>/i', '$3', $content); } } } return $content; } function amforwp_remove_tp_image_href( $orig_table){ $tablepressData = array(); $j = 0; foreach ($orig_table['data'] as $cols) { for($i=0;$i< count($cols);$i++){ $tablepressData[$j][$i] = preg_replace("/]+\>(]+\>)<\/a>/i",'$1', $cols[$i]); } $j++; } $orig_table['data'] = $tablepressData; return $orig_table; } // 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 ( ampforwp_get_setting('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 '
'; } } } // 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') ); } // #1696 if(function_exists('ampforwp_is_amp_endpoint') && ampforwp_is_amp_endpoint()){ if(class_exists('SQ_Classes_ObjController')){ $SQ_Classes_ObjController = new SQ_Classes_ObjController(); $sq_analytics_class_obj = $SQ_Classes_ObjController::getClass('SQ_Models_Services_Analytics'); } } } // #2042 function ampforwp_404_canonical(){ global $wp; 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_singular()){ 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 && true == ampforwp_get_setting('amp-pagination') ){ return get_the_content(); } } return $content; } // GDPR Compliancy #2040 // Moved to notice-bar-functions.php // Thrive Leads Compatibility #2067 add_filter('thrive_leads_skip_request', 'ampforwp_skip_thrive_leads'); if ( ! function_exists('ampforwp_skip_thrive_leads') ) { function ampforwp_skip_thrive_leads($skip) { // Skip thrive leads on AMP if ( function_exists('ampforwp_is_amp_endpoint') && ampforwp_is_amp_endpoint() ) { return true; } return $skip; } } // Re-save permalink once the post value changed in Redading Settings #2190 add_action( 'update_option', 'ampforwp_resave_permalink', 10, 3 ); function ampforwp_resave_permalink( $option, $old_value, $value ){ if('posts_per_page' === $option){ if($old_value != $value){ delete_transient( 'ampforwp_current_version_check' ); } } } // Canonical From Yoast #2118 and All in One SEO #1720 and Rank Math #2701 function ampforwp_generate_canonical(){ global $redux_builder_amp; $canonical = ''; $canonical = $WPSEO_Frontend = $All_in_One_SEO_Pack = $opts = ''; if ( 'yoast' == ampforwp_get_setting('ampforwp-seo-selection') && true == ampforwp_get_setting('ampforwp-seo-yoast-canonical') && class_exists('WPSEO_Frontend') && !class_exists('Yoast\\WP\\SEO\\Integrations\\Front_End_Integration')) { $WPSEO_Frontend = WPSEO_Frontend::get_instance(); $canonical = $WPSEO_Frontend->canonical(false); } elseif ( 'aioseo' == ampforwp_get_setting('ampforwp-seo-selection') && true == ampforwp_get_setting('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']; } elseif ( defined( 'RANK_MATH_FILE' ) && 'rank_math' == ampforwp_get_setting('ampforwp-seo-selection') && ampforwp_get_setting( 'ampforwp-seo-rank_math-canonical' ) ) { $canonical = \RankMath\Paper\Paper::get()->get_canonical(); } 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; } if(class_exists('WPSEO_Frontend') && 'yoast' == ampforwp_get_setting('ampforwp-seo-selection') && true == ampforwp_get_setting('ampforwp-seo-yoast-canonical') && !class_exists('Yoast\\WP\\SEO\\Integrations\\Front_End_Integration') ){ add_filter('ampforwp_modify_rel_url','ampforwp_yoast_canonical'); } function ampforwp_yoast_canonical($canonical){ if(ampforwp_is_front_page()){ $canonical = ampforwp_generate_canonical(); } return $canonical; } // #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 ( false == ampforwp_get_setting('ampforwp-display-on-pages') && true == ampforwp_get_setting('ampforwp-display-on-posts') ) { $display_comments_on = is_single(); } if ( true == ampforwp_get_setting('ampforwp-display-on-pages') && false == ampforwp_get_setting('ampforwp-display-on-posts') ) { $display_comments_on = is_page(); } if ( true == ampforwp_get_setting('ampforwp-display-on-pages') && true == ampforwp_get_setting('ampforwp-display-on-posts')) { $display_comments_on = is_singular(); if ( ampforwp_is_front_page() ) { $display_comments_on = ampforwp_is_front_page(); } } $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 ( true == ampforwp_get_setting('ampforwp-vuukle-comments-support') && comments_open() && ampforwp_get_setting('amp-design-selector') != 4) { echo ampforwp_vuukle_comments_markup(); } } function ampforwp_vuukle_comments_markup() { global $redux_builder_amp,$post; $apiKey = $locale = ''; $tag_name =''; $img = get_the_post_thumbnail_url(); $tags = get_the_tags($post->ID); 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(); $siteUrl = trim(site_url(), '/'); if (!preg_match('#^http(s)?://#', $siteUrl)) { $siteUrl = 'http://' . $siteUrl; } if($img == false){ $img = plugins_url('accelerated-mobile-pages/images/150x150.png'); } if($tags){ foreach($tags as $individual_tag) { $tag_name = $individual_tag->name; } } $urlParts = parse_url($siteUrl); $siteUrl = preg_replace('/^www\./', '', $urlParts['host']);// remove www $srcUrl = 'https://cdn.vuukle.com/amp.html?'; $srcUrl = add_query_arg('url' ,get_permalink(), $srcUrl); $srcUrl = add_query_arg('host' ,$siteUrl, $srcUrl); $srcUrl = add_query_arg('id' , $post->ID, $srcUrl); if(!empty($apiKey)){ $srcUrl = add_query_arg('apiKey' , $apiKey, $srcUrl); } $srcUrl = add_query_arg('title' , urlencode($post->post_title), $srcUrl); $srcUrl = add_query_arg('img' , esc_url($img), $srcUrl); $srcUrl = add_query_arg('tags' , urlencode($tag_name), $srcUrl); if(ampforwp_get_setting('ampforwp-vuukle-comments-emoji')==false){ $srcUrl = add_query_arg('emotes' , 'false', $srcUrl); } $consent = ''; if(ampforwp_get_data_consent()){ $consent = 'data-block-on-consent '; } $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 ( ampforwp_get_setting('ampforwp-vuukle-comments-support') && $display_comments_on) { 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 (ampforwp_get_setting('ampforwp-vuukle-Ads-before-comments') && 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(); } } function ampforwp_spotim_comments_markup() { global $post; $display_comments_on = false; $display_comments_on = ampforwp_get_comments_status(); if (! $display_comments_on ) { return ''; } $spotId =''; if( true == ampforwp_get_setting('ampforwp-spotim-comments-apiKey') && ampforwp_get_setting('ampforwp-spotim-comments-apiKey') !== ""){ $spotId = ampforwp_get_setting('ampforwp-spotim-comments-apiKey'); } $srcUrl = 'https://amp.spot.im/production.html?spot_im_highlight_immediate=true'; $srcUrl = add_query_arg('spotId' ,$spotId, $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; } '; } } // rel="next" & rel="prev" pagination meta tags #2343 add_action( 'amp_post_template_head', 'ampforwp_rel_next_prev' ); function ampforwp_rel_next_prev(){ global $paged; if(ampforwp_is_front_page()){ return ; } if ( get_previous_posts_link() ) { ?> = 3000 ) { $content = '
' . $content . '
'; $content = $content . '
'; $content = $content . '
'; } return $content; } // Content Sneak Peek Scripts css function ampforwp_sneak_peek_css(){ global $redux_builder_amp; $height = $txt_color = $btn_color = ''; $height = ampforwp_get_setting('content-sneak-peek-height'); $btn_color = $redux_builder_amp['content-sneak-peek-btn-color']['color']; $txt_color = $redux_builder_amp['content-sneak-peek-txt-color']['color'];?> .fd-h{height: ;overflow: hidden;position: relative;} .fd-b-c{text-align: center;margin: 0px 0px 30px 0px;} .fd-b-c .fd-b:hover{cursor:pointer;} .fd-b-c .fd-b {border:none;border-radius: 5px;color: ;font-size: 16px;font-weight: 700;padding: 12px 32px 12px 32px;background-color: ; } .fd-h:after { content: ""; display: inline-block; position: absolute; background: linear-gradient(to bottom,rgba(255,255,255,0) 0,rgba(255,255,255,1) 100%); width:100%; bottom: 0; top:auto; height:230px; } array(), 'AMP_Blacklist_Sanitizer' => array(), 'AMP_Style_Sanitizer' => array(), 'AMP_Video_Sanitizer' => array(), 'AMP_Audio_Sanitizer' => array(), 'AMP_Iframe_Sanitizer' => array( 'add_placeholder' => true, ), ) ) ); $content = $sanitizer_obj->get_amp_content(); return $content; } // Instant Articles Meta Box add_action( 'add_meta_boxes', 'ampforwp_ia_meta_box' ); if ( ! function_exists('ampforwp_ia_meta_box') ) { function ampforwp_ia_meta_box() { global $post; if ( ampforwp_role_based_access_options() == true ) { if( ampforwp_get_setting('fb-instant-article-switch') && $post->post_type == 'post' ) { add_meta_box( 'ampforwp_ia_meta', esc_html__( 'Show Instant Article for Current Post?','accelerated-mobile-pages' ), 'ampforwp_ia_meta_callback', 'post','side' ); } } } } // Callback function for Instant Articles Meta Box. function ampforwp_ia_meta_callback( $post ) { global $redux_builder_amp; wp_nonce_field( basename( __FILE__ ), 'ampforwp_ia_nonce' ); $ampforwp_stored_meta = get_post_meta( ampforwp_get_the_ID() ); if ( ! isset($ampforwp_stored_meta['ampforwp-ia-on-off']) && ! isset($ampforwp_stored_meta['ampforwp-ia-on-off'][0]) && $ampforwp_stored_meta['ampforwp-ia-on-off'][0] == 'hide-ia') { $exclude_post_value = get_option('ampforwp_ia_exclude_post'); if ( $exclude_post_value == null ) { $exclude_post_value[] = 0; } if ( $exclude_post_value ) { if ( ! in_array( ampforwp_get_the_ID(), $exclude_post_value ) ) { $exclude_post_value[] = ampforwp_get_the_ID(); update_option('ampforwp_ia_exclude_post', $exclude_post_value); } } } else { $exclude_post_value = get_option('ampforwp_ia_exclude_post'); if ( $exclude_post_value == null ) { $exclude_post_value[] = 0; } if ( $exclude_post_value ) { if ( in_array( ampforwp_get_the_ID(), $exclude_post_value ) ) { $exclude_ids = array_diff($exclude_post_value, array(ampforwp_get_the_ID()) ); update_option('ampforwp_ia_exclude_post', $exclude_ids); } } } ?>

base ) { remove_action('admin_enqueue_scripts', 'total_plus_admin_scripts', 100); // Save option is not showing with a basix theme #3366 if(function_exists('addPanelCSS')){ remove_action( 'admin_enqueue_scripts', 'addPanelCSS'); } } } // uploading the images with SVG format #2431 function ampforwp_upload_svg($file_types){ $new_filetypes = array(); $new_filetypes['svg'] = 'image/svg+xml'; $file_types = array_merge($file_types, $new_filetypes ); return $file_types; } add_action('upload_mimes', 'ampforwp_upload_svg'); // Ajax functions add_action( 'wp_ajax_ampforwp_categories', 'ampforwp_ajax_cats' ); function ampforwp_ajax_cats(){ $ampforwp_nonce = wp_create_nonce( 'ampforwp-verify-request' ); if(!wp_verify_nonce($ampforwp_nonce,'ampforwp-verify-request') ){ echo json_encode(array('status'=>403,'message'=>'user request is not allowed')) ; die; } $return = array(); $categories = get_categories(array('search'=> esc_html($_GET['q']),'number'=>500,'hide_empty' => 0)); $categories_array = array(); if ( $categories ) : foreach ($categories as $cat ) { $return[] = array($cat->cat_ID,$cat->name);// array( Cat ID, Cat Name ) } endif; wp_send_json( $return ); } add_action( 'wp_ajax_ampforwp_tags', 'ampforwp_ajax_tags' ); function ampforwp_ajax_tags(){ $ampforwp_nonce = wp_create_nonce( 'ampforwp-verify-request' ); if(!wp_verify_nonce($ampforwp_nonce,'ampforwp-verify-request') ){ echo json_encode(array('status'=>403,'message'=>'user request is not allowed')) ; die; } $return = array(); $tags = get_tags(array('search'=> esc_html($_GET['q']),'number'=>500)); if ( $tags ) : foreach ($tags as $tag ) { $return[] = array($tag->term_id,$tag->name);// array( Tag ID, tag Name ) } endif; wp_send_json( $return ); } add_filter( 'amp_post_template_data', 'ampforwp_backtotop' ); function ampforwp_backtotop( $data ) { global $redux_builder_amp; if(true == ampforwp_get_setting('ampforwp-footer-top')){ $dom = AMP_DOM_Utils::get_dom_from_content($data['post_amp_content']); if ( 0 !== $dom->getElementsByTagName( 'amp-position-observer' )->length ) { if ( empty( $data['amp_component_scripts']['amp-position-observer'] ) ) { $data['amp_component_scripts']['amp-position-observer'] = 'https://cdn.ampproject.org/v0/amp-position-observer-0.1.js'; } } if ( 0 !== $dom->getElementsByTagName( 'amp-animation' )->length ) { if ( empty( $data['amp_component_scripts']['amp-animation'] ) ) { $data['amp_component_scripts']['amp-animation'] = 'https://cdn.ampproject.org/v0/amp-animation-0.1.js'; } } } return $data; } // Jannah Theme Subtitle Support #2732 add_action('ampforwp_below_the_title','ampforwp_jannah_subtitle'); function ampforwp_jannah_subtitle(){ if (function_exists('jannah_theme_name') && function_exists('tie_get_postdata')){?>

.wp-block-button { color: #fff} .wp-block-button a {background-color: ;border-radius: 28px;color: inherit;display: inline-block;padding: 12px 24px;} .wp-block-cover{position:relative;background-color: #000;background-size: cover;background-position: center center;min-height: 430px;width: 100%;margin: 1.5em 0 1.5em 0;display: flex;justify-content: center;align-items: center;overflow: hidden;} .wp-block-cover-text{color: #fff;font-size: 2em;line-height: 1.25;z-index: 1;} .wp-block-cover-image.has-background-dim::before, .wp-block-cover.has-background-dim::before {content: "";position: absolute;top: 0;left: 0;bottom: 0;right: 0;background-color: inherit;opacity: .5;z-index: 1;} .has--color { color: ;} .has--background-color { background-color: }

$postID, 'order' => esc_attr($comment_order), 'status' => 'approve' //Change this to the type of comments to be displayed ) ); foreach ($comments as $comment) { $comment_data = get_comment( $comment->comment_ID ); $comment_text = $comment_data->comment_content; $comment_text = wpautop( $comment_text ); $sanitizer = new AMPforWP_Content( $comment_text, apply_filters( 'amp_content_embed_handlers', array( 'AMP_Reddit_Embed_Handler' => array(), 'AMP_Twitter_Embed_Handler' => array(), 'AMP_YouTube_Embed_Handler' => array(), 'AMP_DailyMotion_Embed_Handler' => array(), 'AMP_Vimeo_Embed_Handler' => array(), 'AMP_SoundCloud_Embed_Handler' => array(), 'AMP_Instagram_Embed_Handler' => array(), 'AMP_Vine_Embed_Handler' => array(), 'AMP_Facebook_Embed_Handler' => array(), 'AMP_Pinterest_Embed_Handler' => array(), 'AMP_Gallery_Embed_Handler' => array(), 'AMP_Tiktok_Embed_Handler'=>array(), ) ), apply_filters( 'amp_sidebar_sanitizers', array( 'AMP_Style_Sanitizer' => array(), 'AMP_Blacklist_Sanitizer' => array(), 'AMP_Img_Sanitizer' => array(), 'AMP_Video_Sanitizer' => array(), 'AMP_Audio_Sanitizer' => array(), 'AMP_Playbuzz_Sanitizer' => array(), 'AMP_Iframe_Sanitizer' => array( 'add_placeholder' => true, ), ) ) ); if ( $sanitizer ) { $sanitizer_scripts = $sanitizer->get_amp_scripts(); if ( $sanitizer_scripts ){ $comments_scripts = array_merge($comments_scripts, $sanitizer_scripts); } } } if ( $comments_scripts ) { $ampforwp_data['comments']['scripts'] = $comments_scripts; } } } // AMPforWP Global Scripts add_filter('amp_post_template_data','ampforwp_add_global_scripts'); function ampforwp_add_global_scripts($data){ global $ampforwp_data; $comments_scripts = array(); // Add Comments Scripts #2827 if ( $comments_scripts ) { $comments_scripts = $ampforwp_data['comments']['scripts']; } if ( !empty($comments_scripts) ) { foreach ($comments_scripts as $key => $value ) { if( empty( $data['amp_component_scripts'][$key] ) ){ $data['amp_component_scripts'][$key] = $value; } } } // AddThis Support #3068 if ( ampforwp_get_setting('enable-add-this-option') && ( is_single() || (is_page() && ampforwp_get_setting('ampforwp-page-social') ) ) && !ampforwp_woocommerce_conditional_check() && !checkAMPforPageBuilderStatus(ampforwp_get_the_ID()) && ( ampforwp_get_setting('addthis-floating-share') == true || ampforwp_get_setting('addthis-inline-share') == true)) { if ( empty( $data['amp_component_scripts']['amp-addthis'] ) ) { $data['amp_component_scripts']['amp-addthis'] = 'https://cdn.ampproject.org/v0/amp-addthis-0.1.js'; } } // Featured video SmartMag theme Compatibility #2559: if( function_exists('get_the_post_video') || class_exists('Bunyad') ) { if ( empty( $data['amp_component_scripts']['amp-iframe'] ) ) { $data['amp_component_scripts']['amp-iframe'] = 'https://cdn.ampproject.org/v0/amp-iframe-0.1.js'; } } //Appearance option for Related Posts #1545 if ( true == ampforwp_get_setting('ampforwp-single-related-posts-switch') && ampforwp_get_setting('rp_design_type') == '3') { if ( empty( $data['amp_component_scripts']['amp-carousel'] ) ) { $data['amp_component_scripts']['amp-carousel'] = 'https://cdn.ampproject.org/v0/amp-carousel-0.2.js'; } } return $data; } if ( ! function_exists('ampforwp_get_weglot_url') ) { function ampforwp_get_weglot_url(){ $url = weglot_get_full_url_no_language(); $current_lang = weglot_get_current_and_original_language(); $original_lang = $current_lang['original']; $current_lang = $current_lang['current']; if($current_lang == $original_lang ){ return $url; }else{ $url = trailingslashit($url) . $current_lang; return esc_url(user_trailingslashit($url)); } } } // Rank Math SEO Compatibility #2701 // og tags and Schema add_action('amp_post_template_head','ampforwp_rank_math'); if ( ! function_exists('ampforwp_rank_math') ) { function ampforwp_rank_math(){ // Early Bail if Rank Math is not selected in SEO Plugin Integration. if ( 'rank_math' !== ampforwp_get_setting('ampforwp-seo-selection') ) { return; } // Remove Canonical & Title Tag added by the Rank Math plugin. remove_all_actions( 'rank_math/head', 20 ); remove_all_actions( 'rank_math/head', 1 ); // Remove meta tags added by the Rank Math plugin. if ( ! ampforwp_get_setting( 'ampforwp-seo-rank_math-meta' ) ) { $json_ld_data = isset( $wp_filter['rank_math/json_ld'] ) ? $wp_filter['rank_math/json_ld'] : ''; remove_all_actions( 'rank_math/opengraph/facebook' ); remove_all_actions( 'rank_math/opengraph/twitter' ); add_filter( 'rank_math/frontend/robots', function() { return []; }); }else if(ampforwp_is_front_page()){ add_filter( 'rank_math/frontend/robots', function() { return []; }); } // Remove ld+json data added by the Rank math plugin. if ( ! ampforwp_get_setting( 'ampforwp-seo-rank_math-schema' ) ) { remove_all_actions( 'rank_math/json_ld' ); } if(class_exists('RankMath') && true == ampforwp_get_setting('ampforwp-amp-takeover') && ( ampforwp_is_home() || ampforwp_is_front_page())){ $google = RankMath\Helper::get_settings( 'general.google_verify' ); $bing = RankMath\Helper::get_settings( 'general.bing_verify' ); $baidu = RankMath\Helper::get_settings( 'general.baidu_verify' ); $alexa = RankMath\Helper::get_settings( 'general.alexa_verify' ); $yandex = RankMath\Helper::get_settings( 'general.yandex_verify' ); $pinterest = RankMath\Helper::get_settings( 'general.pinterest_verify' ); $norton = RankMath\Helper::get_settings( 'general.norton_verify' ); if(!empty($google)){?> preview->is_preview_mode() ){ return false; }else{ return $data; } } return $data; } // Multiple Images #2259 // Moved to structured-data-functions.php // schema.org/SiteNavigationElement missing from menus #1229 & #2952 // Moved to structured-data-functions.php // WP Subtitle Support #2831 add_action('ampforwp_below_the_title','ampforwp_wpsubtitle_support'); if (! function_exists('ampforwp_wpsubtitle_support') ) { function ampforwp_wpsubtitle_support(){ if(class_exists('WPSubtitle')){?>

loadHTML($menu); libxml_use_internal_errors(false); // get all the forms $nodes = $dom->getElementsByTagName( 'form' ); $num_nodes = $nodes->length; for ( $i = $num_nodes - 1; $i >= 0; $i-- ) { $node = $nodes->item( $i ); // Set The Width and Height if there in none if ( '' === $node->getAttribute( 'target' ) ) { $node->setAttribute('target', '_top'); } if ( $node->getAttribute('action')){ $action_url = ''; $action_url = $node->getAttribute('action'); $action_url = preg_replace('#^http?:#', '', $action_url); $node->setAttribute('action', $action_url); } } $menu = $dom->saveHTML(); } return $menu; } } add_action('amp_post_template_css','ampforwp_ivory_search_css'); function ampforwp_ivory_search_css(){ if(class_exists('Ivory_Search')){?> svg.icon.icon-search { display: none; } input.search-field { display: inline-block; } svg.search-icon { display: none; } og_image(); echo $og_tsf->og_locale(); echo $og_tsf->og_type(); echo $og_tsf->og_title(); echo $og_tsf->og_image(); echo $og_tsf->og_description(); echo $og_tsf->og_sitename(); } } $prefetch = ampforwp_get_setting('amp-prefetch-options'); $data_arr = array(); if(is_array($prefetch)){ foreach ( $prefetch as $k => $value ) { if(is_array($value)){ foreach ($value as $tk => $tval) { $temp_arr = array(); $temp_arr['name'][] = $k; $temp_arr['type'][] = $tk; foreach ($tval as $ck => $cval) { $temp_arr['value'][] = $cval; } $data_arr[] = $temp_arr; } } } if(isset($data_arr[0]) && !empty($data_arr)){ $val_count = count($data_arr[0]['value']); for($i=0;$i<$val_count;$i++){ for($j=0;$j href="" crossorigin> (.*?)<\/a>/', $breadcrumb)){ $breadcrumb = preg_replace('/(.*?)<\/a>/', '$2', $breadcrumb); } return $breadcrumb; } } } // Slide Anything compatibility #2891 add_filter('amp_content_embed_handlers','ampforwp_slide_anything_embed'); function ampforwp_slide_anything_embed($data) { if ( function_exists('cpt_slider_plugin_activation') ) { require_once( AMPFORWP_PLUGIN_DIR. 'classes/class-ampforwp-slide-anything-embed.php' ); $data['AMPFORWP_Slide_Anything_Embed_Handler'] = array(); } return $data; } // Revolution Slider compatibility #1464 add_action('pre_amp_render_post', 'ampforwp_initialise_rev_slider'); if ( ! function_exists('ampforwp_initialise_rev_slider') ) { function ampforwp_initialise_rev_slider(){ if ( class_exists('RevSliderOutput') ){ require AMPFORWP_PLUGIN_DIR .'/classes/class-ampforwp-rev-slider.php'; } } } add_filter('amp_content_embed_handlers','ampforwp_rev_slider_embed'); function ampforwp_rev_slider_embed($data) { if ( class_exists('RevSliderOutput') ){ $data['AMP_Rev_Slider_Embed_Handler'] = array(); } return $data; } // Photo Gallery by 10Web Compatibility #1811 add_action('pre_amp_render_post', 'ampforwp_initialise_photo_gallery'); if ( ! function_exists('ampforwp_initialise_photo_gallery') ) { function ampforwp_initialise_photo_gallery(){ if ( class_exists('BWG') ) { require AMPFORWP_PLUGIN_DIR .'/classes/class-ampforwp-photo-gallery-embed.php'; } } } add_filter('amp_content_embed_handlers','ampforwp_photo_gallery_embed'); function ampforwp_photo_gallery_embed($data) { if ( class_exists('BWG') ) { $data['AMPforWP_Photo_Gallery_Embed_Handler'] = array(); } return $data; } function ampforwp_rel_attributes_social_links(){ $rel_attributes = array(); if (true == ampforwp_get_setting('ampforwp-social-no-follow')) { $rel_attributes[] = 'nofollow'; } if (true == ampforwp_get_setting('ampforwp-social-no-referrer')) { $rel_attributes[] = 'noreferrer'; } if (true == ampforwp_get_setting('ampforwp-social-no-opener')) { $rel_attributes[] = 'noopener'; } $rel_attributes = apply_filters('ampforwp_rel_attributes_social_links', $rel_attributes); $rel_attributes = array_map('esc_attr', $rel_attributes); if ( $rel_attributes ) { echo 'rel="' . implode(" ",$rel_attributes).'"'; } return; } // Fallback added function ampforwp_nofollow_social_links(){ ampforwp_rel_attributes_social_links(); return ; } function ampforwp_nofollow_notification(){ if(true == ampforwp_get_setting('ampforwp-notifications-nofollow')){ echo 'rel=nofollow'; return; } return false; } // Featured Video SmartMag theme Compatibility CSS #2559 add_action('amp_post_template_css', 'ampforwp_featured_video_plus_css'); function ampforwp_featured_video_plus_css(){ if( function_exists('get_the_post_video') ) {?> .fvp-onload{display:none} .amp-featured-image amp-iframe, .amp-wp-article-featured-image amp-iframe { margin:auto; height:100%; } .f_vid { background: #000; } ";?>
'; } return $form; } } //Saving all taxonomies in Transient add_action('init','ampforwp_generate_taxonomies_transient'); function ampforwp_generate_taxonomies_transient(){ $taxonomies = get_transient('ampforwp_get_taxonomies'); $tax_arr = array(); $args = array( 'public' => true, '_builtin' => false, ); $output = 'objects'; // or objects $operator = 'and'; // 'and' or 'or' $alltaxonomies = get_taxonomies( $args, $output, $operator ); if ($alltaxonomies) { foreach ($alltaxonomies as $taxKey => $taxVal) { $tax_arr[$taxVal->name] = $taxVal->labels->singular_name; } } if ( false == $taxonomies ) { set_transient('ampforwp_get_taxonomies',$tax_arr); }else{ if(count($tax_arr) > count($taxonomies)){ $result = array_diff_assoc($tax_arr,$taxonomies); }elseif( count($taxonomies) > count($tax_arr)){ $result = array_diff_assoc($taxonomies,$tax_arr); } if( !empty($result)){ delete_transient('ampforwp_get_taxonomies'); } } return $taxonomies; } // Include Opengraph.php #3261 add_action('pre_amp_render_post', 'ampforwp_include_opengraph'); if ( ! function_exists('ampforwp_include_opengraph') ) { function ampforwp_include_opengraph(){ if ( true == ampforwp_get_setting('ampforwp-seo-og-meta-tags') && '' == ampforwp_get_setting('ampforwp-seo-selection') ) { require_once AMPFORWP_PLUGIN_DIR."includes/features/opengraph.php"; } } } add_action('wp_ajax_ampforwp_import_file_from_file','ampforwp_import_settings_from_file'); function ampforwp_import_settings_from_file(){ $security = $_POST['security']; if ( wp_verify_nonce( $security, 'ampforwp_import_file' ) && current_user_can( 'manage_options' ) ) { if(isset($_FILES["file"]["tmp_name"])){ $content = file_get_contents($_FILES["file"]["tmp_name"]); if ( ! empty ( $content ) ) { $imported_options = json_decode( $content, true ); } $plugin_options = get_option('redux_builder_amp'); if ( ! empty ( $imported_options ) && is_array( $imported_options ) && isset ( $imported_options['redux-backup'] ) && $imported_options['redux-backup'] == '1' ) { echo $content; } } } } add_filter('ampforwp_loop_image_update','ampforwp_recentpost_link_to_nonamp'); function ampforwp_recentpost_link_to_nonamp($image_link_data){ if( true == ampforwp_get_setting('ampforwp-recentpost-posts-link') ){ $image_link_data['image_link'] = get_permalink(); }else{ $image_link_data['image_link'] = ampforwp_url_controller( get_permalink() ) ; } return $image_link_data; } #3596 link to nonamp option on title for recent posts add_filter('ampforwp_loop_permalink_update','ampforwp_recentpost_title_link_to_nonamp'); function ampforwp_recentpost_title_link_to_nonamp($title_link){ if( true == ampforwp_get_setting('ampforwp-recentpost-posts-link') ){ $title_link = get_permalink(); }else{ $title_link = ampforwp_url_controller( get_permalink() ) ; } return $title_link; } // Post Meta Revisions #3548 -- start here -- add_filter( '_wp_post_revision_field_amp_page_builder', 'ampforwp_meta_revi_pb_field', 22, 2 ); add_action( 'save_post', 'ampforwp_meta_revi_save_post', 10, 2 ); add_action( 'wp_restore_post_revision', 'ampforwp_meta_restore_revision', 10, 2 ); add_filter( '_wp_post_revision_fields', 'ampforwp_meta_revi_fields' ); // Displaying the meta field on the revisions screen function ampforwp_meta_revi_fields( $fields ) { $fields['post_title'] = 'Title'; $fields['post_content'] = 'Content'; $fields['post_excerpt'] = 'Excerpt'; $fields['amp-page-builder'] = 'AMP Page Builder'; return $fields; } // Displaying the meta field on the revisions screen function ampforwp_meta_revi_pb_field( $value, $field ) { global $revision; return get_metadata( 'post', $revision->ID, $field, true ); } // Reverting to the correct revision of the meta field when a post is reverted function ampforwp_meta_restore_revision( $post_id, $revision_id ) { if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) { return; } $post = get_post( $post_id ); $revision = get_post( $revision_id ); $meta = get_metadata( 'post', $revision->ID, 'amp-page-builder', true ); if ( false === $meta ) { delete_post_meta( $post_id, 'amp-page-builder' ); } else{ update_post_meta( $post_id, 'amp-page-builder', $meta ); } } // Storing a revision of the meta field when a post is saved function ampforwp_meta_revi_save_post( $post_id, $post ) { if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) { return; } if ( $parent_id = wp_is_post_revision( $post_id ) ) { $parent = get_post( $parent_id ); $pb_meta = get_post_meta( $parent->ID, 'amp-page-builder', true ); if ( false !== $pb_meta ){ add_metadata( 'post', $post_id, 'amp-page-builder', $pb_meta ); } } } // Post Meta Revisions #3548 -- end here -- // FOR ADMIN MENU BAR add_action( 'pre_amp_render_post', 'ampforwp_front_admin_menu_bar' ); function ampforwp_front_admin_menu_bar(){ if( is_user_logged_in() ){ $pref = get_user_option( "show_admin_bar_front", get_current_user_id() ); if($pref==="true"){ if(class_exists('QM_Plugin') && class_exists('QM_Dispatchers') && ampforwp_get_setting('ampforwp-query-monitor')){ $dis = QM_Dispatchers::get( 'html' ); if($dis->did_footer==false){ $dis->did_footer = true; add_action( 'amp_post_template_head', 'ampforwp_query_monitor_script' ); add_action( 'amp_post_template_head', 'ampforwp_manual_qm_script', 11 ); } } add_action("ampforwp_admin_menu_bar_front", function(){ add_action('wp_before_admin_bar_render','ampforwp_add_admin_menu_front'); wp_admin_bar_render(); }); add_action( 'admin_bar_init', 'ampforwp_init_admin_bar'); add_action( 'wp_before_admin_bar_render','ampforwp_remove_before_admin_bar_redner',9); add_action( 'admin_bar_menu', 'ampforwp_remove_admin_menu_front',999); add_action('amp_post_template_css', 'ampforwp_head_css'); } } } function ampforwp_remove_before_admin_bar_redner(){ remove_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' ); } function ampforwp_init_admin_bar(){ remove_action( 'wp_head', '_admin_bar_bump_cb' ); remove_action( 'wp_head', 'wp_admin_bar_header' ); } global $wp_filesystem; function ampforwp_head_css(){ global $ampforwpTemplate, $redux_builder_amp, $wp_filesystem; $css = ""; if( is_user_logged_in() ){ $pref = get_user_option( "show_admin_bar_front", get_current_user_id() ); if($pref==="true"){ require_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php'; require_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php'; $wp_filesystem = new WP_Filesystem_Direct( array() ); if(ampforwp_get_setting('ampforwp_css_tree_shaking')==1){ if(ampforwp_is_home()){ $tscss = "home"; }elseif(ampforwp_is_blog()){ $tscss = "blog"; }elseif(ampforwp_is_front_page()){ $tscss = "post-".ampforwp_get_frontpage_id(); }elseif(is_singular()){ $tscss = "post-".ampforwp_get_the_ID(); }elseif(is_archive()){ $page_id = get_queried_object_id(); $tscss = "archive-".intval($page_id); } $tscss = $tscss.'-admin'; $upload_dir = wp_upload_dir(); $ts_file = esc_attr($upload_dir['basedir']) . '/' . 'ampforwp-tree-shaking/_transient_'.esc_attr($tscss).".css"; if(file_exists($ts_file)){ $css = $wp_filesystem->get_contents($ts_file); if(preg_match("/#wpadminbar/", $css)==0){ $user_dirname = $upload_dir['basedir'] . '/' . 'ampforwp-tree-shaking'; if(file_exists($user_dirname)){ $files = glob($user_dirname . '/*'); foreach($files as $file){ if(is_file($file) && strpos($file, '_transient')!==false ){ unlink($file); } } } } } } $css = $wp_filesystem->get_contents(AMPFORWP_PLUGIN_DIR."/templates/template-mode/admin-bar.css"); $incurl = includes_url(); $incurl = trailingslashit($incurl) .'fonts/dashicons.ttf?50db0456fde2a241f005968eede3f987'; $css.='@font-face{font-family:dashicons;src:url('.$incurl.'/fonts/dashicons.ttf?50db0456fde2a241f005968eede3f987) format("truetype"); font-weight:400;font-style:normal} #wp-admin-bar-my-account .avatar{float:right;margin-top:7px;margin-left:5px;height:18px;width:18px;border:1px solid #82878c}#wp-admin-bar-wpseo-notifications .yoast-issue-counter{float:right}@media(max-width:782px){#wpadminbar~header #headerwrap{top:46px}}'; if(ampforwp_get_setting('amp-design-selector')!=3){ $css.='#wpadminbar~header{margin-top:32px}@media(max-width:782px){#wpadminbar~header{margin-top:46px}}'; }else{ $css.='#wpadminbar~header #headerwrap{top:32px}@media(max-width:782px){#wpadminbar~header #headerwrap{margin-top:46px}}'; } echo ampforwp_css_sanitizer($css); } } } function ampforwp_css_sanitizer($css){ $css = preg_replace( '/\s*!important/', '', $css, -1, $important_count ); $css = preg_replace( '/overflow(-[xy])?\s*:\s*(auto|scroll)\s*;?\s*/', '', $css, -1, $overlow_count ); $css = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css); $css = str_replace(array (chr(10), ' {', '{ ', ' }', '} ', '( ', ' )', ' :', ': ', ' ;', '; ', ' ,', ', ', ';}', '::-' ), array('', '{', '{', '}', '}', '(', ')', ':', ':', ';', ';', ',', ', ', '}', ' ::-'), $css); return $css; } function ampforwp_get_remote_content($src){ if($src){ $arg = array( "sslverify" => false, "timeout" => 60 ) ; $response = wp_remote_get( $src, $arg ); if ( wp_remote_retrieve_response_code($response) == 200 && is_array( $response ) ) { $header = wp_remote_retrieve_headers($response); // array of http header lines $contentData = wp_remote_retrieve_body($response); // use the content return $contentData; } }else{ return $contentData = file_get_contents( $src ); } return ''; } function ampforwp_add_admin_menu_front(){ global $wp_admin_bar; $dom = new DOMDocument(); $my_account = $wp_admin_bar->get_node('my-account'); $title = ''; if(is_object($my_account)){ $title = ampforwp_content_sanitizer($my_account->title); } $wp_admin_bar->add_menu( array( 'id' => 'my-account', 'title' => $title ) ); $user_info = $wp_admin_bar->get_node('user-info'); if(is_object($user_info)){ $title = $user_info->title; } if($title){ // To Suppress Warnings libxml_use_internal_errors(true); $dom->loadHTML($title); libxml_use_internal_errors(false); $anchors = $dom -> getElementsByTagName('img'); $src=""; foreach($anchors as $im){ $src = $im->getAttribute('src'); } $authname = get_the_author_meta('nickname'); $title = ''.esc_html__($authname,'accelerated-mobile-pages').''; $wp_admin_bar->add_menu( array( 'id' => 'user-info', 'title' => $title ) ); if(class_exists('WPSEO_Options')){ $wp_admin_bar->add_menu( array( 'id' => 'wpseo-menu', 'title' => "SEO" ) ); } $wp_admin_bar->remove_menu( 'ampforwp-view-amp' ); if(function_exists('autoptimize_autoload')){ $wp_admin_bar->remove_menu( 'autoptimize' ); } if (is_preview()) { $url = get_preview_post_link(); $wp_admin_bar->add_node(array( 'id' => 'ampforwp-view-non-amp', 'title' => 'View Non-AMP', 'href' => esc_url($url) )); } else{ $url = ampforwp_get_non_amp_url(); $wp_admin_bar->add_node(array( 'id' => 'ampforwp-view-non-amp', 'title' => 'View Non-AMP' , 'href' => esc_url($url) )); } } } function ampforwp_remove_admin_menu_front($wp){ $node_arr = ['search','admin-bar-likes-widget']; for($i=0;$iremove_node($node_arr[$i]); } } function ampforwp_manual_qm_script() { wp_print_scripts( array( 'query-monitor', ) ); wp_print_styles( array( 'query-monitor', ) ); } function ampforwp_query_monitor_script() { global $wp_locale; $qm = plugins_url(); $deps = array( 'jquery', ); if ( defined( 'QM_NO_JQUERY' ) && QM_NO_JQUERY ) { $deps = array(); } $css = 'query-monitor'; if ( method_exists( 'Dark_Mode', 'is_using_dark_mode' ) && is_user_logged_in() ) { if ( Dark_Mode::is_using_dark_mode() ) { $css .= '-dark'; } } elseif ( defined( 'QM_DARK_MODE' ) && QM_DARK_MODE ) { $css .= '-dark'; } wp_enqueue_style( 'query-monitor', esc_attr($qm)."/query-monitor/assets/{$css}.css", array( 'dashicons' ) ); wp_enqueue_script( 'query-monitor', esc_attr($qm).'/query-monitor/assets/query-monitor.js', $deps, false ); wp_localize_script( 'query-monitor', 'qm_number_format', $wp_locale->number_format ); wp_localize_script( 'query-monitor', 'qm_l10n', array( 'ajax_error' => __( 'PHP Errors in Ajax Response', 'query-monitor' ), 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'auth_nonce' => array( 'on' => wp_create_nonce( 'qm-auth-on' ), 'off' => wp_create_nonce( 'qm-auth-off' ), 'editor-set' => wp_create_nonce( 'qm-editor-set' ), ), ) ); } function ampforwp_get_non_amp_url(){ global $post, $wp; $nofollow = $page = $amp_url = $non_amp_url = ''; if( true == ampforwp_get_setting('ampforwp-nofollow-view-nonamp') ){ $nofollow = 'rel=nofollow'; } $amp_url = untrailingslashit( home_url( $wp->request ) ); $amp_url = explode('/', $amp_url); $amp_url = array_flip($amp_url); unset($amp_url[AMPFORWP_AMP_QUERY_VAR]); $non_amp_url = array_flip($amp_url); $non_amp_url = implode('/', $non_amp_url); $query_arg_array = $wp->query_vars; if( array_key_exists( "page" , $query_arg_array ) ) { $page = $wp->query_vars['page']; } if ( $page >= '2') { $non_amp_url = trailingslashit( $non_amp_url . '?page=' . $page); } if ( ampforwp_get_setting('amp-mobile-redirection') == true && ampforwp_get_setting('amp-mob-redirection-pres-link') == false) { $non_amp_url = add_query_arg('nonamp','1',$non_amp_url); } else $non_amp_url = user_trailingslashit($non_amp_url); $mob_pres_link = false; if(function_exists('ampforwp_mobile_redirect_preseve_link')){ $mob_pres_link = ampforwp_mobile_redirect_preseve_link(); } if ( true == ampforwp_get_setting('ampforwp-amp-takeover') || $mob_pres_link == true) { $non_amp_url = ''; } if ( $non_amp_url ) { return apply_filters('ampforwp_view_nonamp_url', $non_amp_url); } } add_action( 'wp_ajax_ampforwp_set_option_panel_view', 'ampforwp_set_option_panel_view' ); function ampforwp_set_option_panel_view(){ if(!is_admin() && !current_user_can('manage_options')){ return ; } if(!wp_verify_nonce($_POST['verify_nonce'],'ampforwp-verify-request') ){ echo json_encode(array('status'=>403,'message'=>'user request is not allowed')) ; die; } $opt_type = intval($_POST['option_type']); if($opt_type==1 || $opt_type==2){ $opt = get_option("ampforwp_option_panel_view_type"); if($opt){ update_option("ampforwp_option_panel_view_type", $opt_type); }else{ add_option("ampforwp_option_panel_view_type", $opt_type); } } } add_action('admin_head', 'ampforwp_remove_admin_help'); if(!function_exists('ampforwp_remove_admin_help')){ function ampforwp_remove_admin_help(){ if(!is_admin() && !current_user_can('manage_options')){ return ; } $screen = get_current_screen(); if ( 'toplevel_page_amp_options' == $screen->base ) { $screen->remove_help_tabs(); } } } if(!function_exists('ampforwp_sassy_icon_style')){ function ampforwp_sassy_icon_style(){ global $wp_filesystem; $css = get_transient('ampforwp_sassy_css'); if($css == false){ if(!is_object($wp_filesystem)){ require_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php'; require_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php'; $wp_filesystem = new WP_Filesystem_Direct( array() ); } $css = $wp_filesystem->get_contents(AMPFORWP_PLUGIN_DIR."/includes/sassy-style.css"); set_transient('ampforwp_sassy_css', $css); } echo ampforwp_css_sanitizer($css); } } if(function_exists('heateor_sss_run')){ add_action('amp_post_template_css', 'ampforwp_sassy_icon_style'); } function ampforwp_nofollow_cta_header_link(){ if(true == ampforwp_get_setting('ampforwp-header-cta-link-nofollow')){ echo 'rel=nofollow'; return; } return false; } // Generating canonical url when FlexMLS plugin is active. if(class_exists('flexmlsConnectPageSearchResults')){ add_action('pre_amp_render_post','ampforwp_flexmls_canonical'); } function ampforwp_flexmls_canonical(){ add_filter('wpseo_canonical','ampforwp_flexmls_generate_canonical_url',99,2); } function ampforwp_flexmls_generate_canonical_url($canonical,$object){ $canonical = $object->model->permalink; return esc_url($canonical); } // Font Selector if( ! function_exists('ampforwp_font_selector') ) { function ampforwp_font_selector( $container ) { global $redux_builder_amp; $fontFamily = ''; if(1==ampforwp_get_setting('ampforwp-google-font-switch')){ return sanitize_text_field($fontFamily); } if(empty($container)) { $container = 'body'; } if ( 'content' == $container && ampforwp_get_setting('amp_font_selector_content_single') && 1 != ampforwp_get_setting('amp_font_selector_content_single') ) { $fontFamily = "font-family: '".ampforwp_get_setting('amp_font_selector_content_single')."';"; } if ( 'body' == $container && ampforwp_get_setting('amp_font_selector') && 1 != ampforwp_get_setting('amp_font_selector') ) { $fontFamily = "font-family: '".ampforwp_get_setting('amp_font_selector')."'"; } return sanitize_text_field($fontFamily); } } if(class_exists('WPSEO_Options')){ add_filter('ampforwp_the_content_last_filter','ampforwp_remove_duplicate_canonical',25); } function ampforwp_remove_duplicate_canonical($content){ if( class_exists( 'DOMDocument' ) && ! empty( $content ) && is_string( $content ) ){ $comp_dom = new DOMDocument(); @$comp_dom->loadHTML($content); $xpath = new DOMXPath( $comp_dom ); $count = 0; $nodes = $xpath->query('//link[@rel="canonical"]'); $con = ''; foreach ($nodes as $node) { $count++; } if($count>1){ if(preg_match("/]*?\brel=[\'\"]canonical[\'\"][^>]*>/", $content, $matches, PREG_OFFSET_CAPTURE)){ $content = preg_replace("/]*?\brel=[\'\"]canonical[\'\"][^>]*>/", "", $content); $content = substr_replace($content, $matches[0][0], $matches[0][1], 0); } } } return $content; } // Font URL controller if ( ! function_exists('ampforwp_font_url') ) { function ampforwp_font_url($font_url){ return apply_filters('ampforwp_font_url', $font_url); } } //Need to add full short pixel plugin compatibility #3782 if(class_exists('ShortPixelAPI')){ add_filter( 'ampforwp_the_content_last_filter','ampforwp_short_pixel_cdn'); } function ampforwp_short_pixel_cdn($content){ $api_url = get_option('spai_settings_api_url'); $compress_level = get_option('spai_settings_compress_level'); if('0'== $compress_level){ $compress_level = '+q_lossless'; } if('1'== $compress_level){ $compress_level = '+q_lossy'; } if('2'== $compress_level){ $compress_level = '+q_glossy'; } $compress_level .= '+ret_img+to_webp/'; if(!empty($api_url)){ $content = preg_replace('/]*)>/','',$content); } return $content; } if(ampforwp_get_setting('ampforwp_css_tree_shaking') == true && ampforwp_is_gutenberg_active()){ add_action('amp_post_template_css','ampforwp_gutenberg_block_styles'); } if(!function_exists('ampforwp_gutenberg_block_styles')){ function ampforwp_gutenberg_block_styles(){ $gutenberg_styles = $block_css = ''; ob_start(); wp_print_styles('wp-block-library'); $block_css .= ob_get_contents(); ob_end_clean(); preg_match("/href='(.*?)'/", $block_css, $matches); $style_path = explode('?', $matches[1]); $gutenberg_styles = get_transient('ampforwp_gutenberg_styles'); if($gutenberg_styles == false){ $response = wp_remote_get( $style_path[0] ); if( is_array( $response ) && ! is_wp_error( $response ) ){ set_transient('ampforwp_gutenberg_styles', $response['body'], 24 * HOUR_IN_SECONDS ); } } echo ampforwp_css_sanitizer($gutenberg_styles); } } function ampforwp_is_gutenberg_active() { $gutenberg = false; $block_editor = false; $use_block_editor = ''; if ( has_filter( 'replace_editor', 'gutenberg_init' ) ) { $gutenberg = true; } if ( version_compare( $GLOBALS['wp_version'], '5.0-beta', '>' ) ) { $block_editor = true; } if ( ! $gutenberg && ! $block_editor ) { return false; } if ( !class_exists('Classic_Editor') ) { return true; } $use_block_editor = ( get_option( 'classic-editor-replace' ) === 'no-replace' ); return $use_block_editor; } add_filter( 'amp_post_template_data', 'ampforwp_pblayout_head_scripts'); $pb_remove_script = array(); function ampforwp_pblayout_head_scripts($data){ $postId = ampforwp_get_the_ID(); $ampforwp_pagebuilder_enable = get_post_meta($postId,'ampforwp_page_builder_enable', true); if(isset($ampforwp_pagebuilder_enable) && $ampforwp_pagebuilder_enable=="yes"){ $previousData = get_post_meta($postId,'amp-page-builder'); $previousData = isset($previousData[0])? $previousData[0]: null; $previousData = (str_replace("'", "'", $previousData)); $totalRows = 1; $totalmodules = 1; if(!empty($previousData)){ $jsonData = json_decode($previousData,true); if(count($jsonData['rows'])>0){ $totalRows = $jsonData['totalrows']; $totalmodules = $jsonData['totalmodules']; $previousData = json_encode($jsonData); }else{ $jsonData['rows'] = array(); $jsonData['totalrows']=1; $jsonData['totalmodules'] = 1; $previousData = json_encode($jsonData); } } $jarr = json_decode($previousData); if(isset($jarr->settingdata->scripts_data)){ $script_data = $jarr->settingdata->scripts_data; $content = $data['post_amp_content']; $script_slug = ''; $allscripts = $script_data; preg_match_all('/<\/script>/', $allscripts, $matches); if($matches){ if(isset($matches[2])){ $script_slug = $matches[2]; foreach ($script_slug as $key => $slug) { if(!preg_match('/'.$slug.'/', $content)){ global $pb_remove_script; $pb_remove_script[]= esc_attr($slug); } } } add_filter( 'ampforwp_the_content_last_filter','ampforwp_remove_unused_pb_amp_script',12); } } } return $data; } function ampforwp_remove_unused_pb_amp_script($data){ global $pb_remove_script; for($i=0;$i<\/script>/', '', $data); } return $data; } if(class_exists('RankMath')){ add_filter('ampforwp_modify_the_content','ampforwp_rank_math_nofollow_to_external_link'); } function ampforwp_rank_math_nofollow_to_external_link($content){ $rank_math_external_link = RankMath\Helper::get_settings( 'general.nofollow_external_links' ); if($rank_math_external_link){ preg_match_all('/(.*?)<\/a>/', $content, $matches); for($i=0;$i .tg:checked + .hamb-mnu > .m-ctr { margin-right: 0%; } .m-ctr{ margin-right: -100%; float: left; } .tg:checked + .hamb-mnu > .m-ctr { margin-right: calc(100% - ); } .m-ctr{ margin-right: 100%; float: right; } (.*?)<\/amp-consent>/s', $content)){ $content = preg_replace('/(.*?)<\/amp-consent>/s', '', $content); } if(preg_match('/
(.*?)<\/form>/s', $content)){ $content = preg_replace('/(.*?)<\/form>/s', '', $content); } // close #4206 // Ticket #4539 if(function_exists('orbital_setup')){ if(preg_match('/'; $content = str_replace('', $script_tag, $content); } } } } } if (empty($content)) { return ''; } $comp_dom = new DOMDocument(); @$comp_dom->loadHTML($content); $xpath = new DOMXPath( $comp_dom ); $elements = $xpath->query("*/script[@custom-element]"); $component_arr = array(); $elements_arr = array(); if (!is_null($elements)) { foreach ($elements as $element) { $component_arr[]= $element->getAttribute('custom-element'); $elements_arr[] = $comp_dom->saveHTML($element); } } if (!is_null($elements)) { if(!empty($component_arr)){ $excl_arr = array('amp-bind','amp-access','amp-analytics','amp-access-laterpay','amp-access-poool','amp-dynamic-css-classes','amp-fx-collection','amp-inputmask','amp-lightbox-gallery','amp-inputmask','amp-mustache','amp-subscriptions-google','amp-subscriptions','amp-video-docking','amp-story'); $inc_elem_arr = array(); for($r=0;$r/", $content) && !$is_script){ $remove_comp = $elements_arr[$i]; $content = str_replace($remove_comp, '', $content); }else if(in_array($component, $inc_elem_arr )){ for($rc=0;$rc(.*?)<\/script>/s', $content,$rmc)){ if(isset($rmc[0])){ $remove_comp = $rmc[0]; $content = str_replace($remove_comp, '', $content); } } } } } // REMOVING DUPLICATE SCRIPT. $count_elem = array_count_values($component_arr)[$component]; if($count_elem>1){ $content = preg_replace('/(.*?)<\/script>/s','',$content,1,$component_arr[$i]); } } } } } //OTHER COMPONENT CHECK $other_comp_arr = array('amp-mustache'=>'amp-mustache','amp-embed'=>'amp-ad','form'=>'amp-form','amp-access'=>'amp-access','amp-fx'=>'amp-fx-collection'); if (preg_match('//', $content)) { $other_comp_arr['amp-carousel'] = 'amp-lightbox-gallery'; } foreach ($other_comp_arr as $key => $value) { $ocomp = $value; $celem = 'element'; if($ocomp=='amp-mustache'){ $celem = 'template'; } if(preg_match('/(type|template|id)="('.$ocomp.')"/', $content) || preg_match("/<\/$key>/", $content) || preg_match("/amp-fx/", $content)){ if(!preg_match('/(.*?)<\/script>/s', $content)){ $o_comp_url = 'https://cdn.ampproject.org/v0/'.esc_attr($ocomp).'-'.esc_attr($script_ver).'.js'; $script_tag = ''; $content = str_replace('', $script_tag, $content); } } } $amp_video = $xpath->query("//amp-video"); foreach($amp_video as $node) { if($node->hasAttribute('dock')){ if(ampforwp_get_setting('ampforwp-amp-video-docking')){ $celem = 'element'; $ocomp = 'amp-video-docking'; if(!preg_match('/(.*?)<\/script>/s', $content)){ $o_comp_url = 'https://cdn.ampproject.org/v0/'.esc_attr($ocomp).'-'.esc_attr($script_ver).'.js'; $script_tag = ''; $content = str_replace('', $script_tag, $content); } }else{ if(preg_match('//','', $content); } } } } $amp_video_iframe = $xpath->query("//amp-video-iframe"); foreach($amp_video_iframe as $node) { if($node->hasAttribute('dock')){ if(ampforwp_get_setting('ampforwp-amp-video-docking')){ $celem = 'element'; $ocomp = 'amp-video-docking'; if(!preg_match('/(.*?)<\/script>/s', $content)){ $o_comp_url = 'https://cdn.ampproject.org/v0/'.esc_attr($ocomp).'-'.esc_attr($script_ver).'.js'; $script_tag = ''; $content = str_replace('', $script_tag, $content); } }else{ if(preg_match('//','', $content); } } } } $amp_youtube = $xpath->query("//amp-youtube"); foreach($amp_youtube as $node) { if($node->hasAttribute('dock')){ if(ampforwp_get_setting('ampforwp-amp-video-docking')){ $celem = 'element'; $ocomp = 'amp-video-docking'; if(!preg_match('/(.*?)<\/script>/s', $content)){ $o_comp_url = 'https://cdn.ampproject.org/v0/'.esc_attr($ocomp).'-'.esc_attr($script_ver).'.js'; $script_tag = ''; $content = str_replace('', $script_tag, $content); } }else{ if(preg_match('//','', $content); } } } } $amp_brid_player = $xpath->query("//amp-brid-player"); foreach($amp_brid_player as $node) { if($node->hasAttribute('dock')){ if(ampforwp_get_setting('ampforwp-amp-video-docking')){ $celem = 'element'; $ocomp = 'amp-video-docking'; if(!preg_match('/(.*?)<\/script>/s', $content)){ $o_comp_url = 'https://cdn.ampproject.org/v0/'.esc_attr($ocomp).'-'.esc_attr($script_ver).'.js'; $script_tag = ''; $content = str_replace('', $script_tag, $content); } }else{ if(preg_match('//','', $content); } } } } $amp_brightcove = $xpath->query("//amp-brightcove"); foreach($amp_brightcove as $node) { if($node->hasAttribute('dock')){ if(ampforwp_get_setting('ampforwp-amp-video-docking')){ $celem = 'element'; $ocomp = 'amp-video-docking'; if(!preg_match('/(.*?)<\/script>/s', $content)){ $o_comp_url = 'https://cdn.ampproject.org/v0/'.esc_attr($ocomp).'-'.esc_attr($script_ver).'.js'; $script_tag = ''; $content = str_replace('', $script_tag, $content); } }else{ if(preg_match('//','', $content); } } } } $allscripts = apply_filters( 'ampforwp_modify_scripts', $allscripts); // Scripts added from Options panel should have higher priority #4064 if( $allscripts || (ampforwp_get_setting('amp-header-text-area-for-html') && ampforwp_get_setting('amp-header-text-area-for-html')!="")) { $allscripts .= ampforwp_get_setting('amp-header-text-area-for-html'); preg_match_all('/(.*?)<\/script>/s', $allscripts, $rep); if($rep){ if(isset($rep[2]) && isset($rep[4])){ $script_slug = $rep[2]; $script_url = $rep[4]; for($s=0;$s(.*?)<\/script>/', $content, $conmatch)){ if(isset($conmatch[3]) && $conmatch[3]!=""){ $rep_url = $conmatch[3]; if(preg_match('/https/', $rep_url)){ $content = str_replace($rep_url, $surl, $content); } } } } } } } } return $content; } if(!function_exists('ampforwp_get_retina_image_settings')){ function ampforwp_get_retina_image_settings($width,$height){ $data['width'] = intval($width); $data['height'] = intval($height); if ( 1 == ampforwp_get_setting('ampforwp-retina-images') ) { $resolution = 2; if (ampforwp_get_setting('ampforwp-retina-images-res')) { $resolution = ampforwp_get_setting('ampforwp-retina-images-res'); } $width = $width * $resolution; $height = $height * $resolution; $data['width'] = intval($width); $data['height'] = intval($height); } return $data; } } if(!function_exists('ampforwp_add_fallback_element')){ function ampforwp_add_fallback_element($content='',$tag=''){ preg_match_all('/<'.$tag.' (.*?)<\/'.$tag.'>/', $content, $matches); if(!empty($matches) && false == ampforwp_get_setting('ampforwp-amp-convert-to-wp')){ if(isset($matches[0])){ $con = ""; for($i=0;$i";//$m_content, $m1_content escaped above. $content = str_replace("$match", $fallback_img, $content); } } } } return $content; } } // added fix for youtube video not displaying on AMP using Elementor #5322 add_filter('ampforwp_modify_the_content','amp_youtube_the_content'); function amp_youtube_the_content($content){ // checking is Elementor is installed and activated if ( did_action( 'elementor/loaded' ) ) { preg_match_all('//', $content, $matches); foreach($matches[3] as $video){ $video_attr = json_decode($video); $get_url = $video_attr->youtube_url; $get_id = get_video_id_from_url($get_url); if(ampforwp_get_setting('ampforwp-amp-video-lightbox')==true) { $content_html=preg_replace('//','
', $content); } else { $content_html = preg_replace('//','', $content); } return $content_html; } } return $content; } function get_video_id_from_url( $url ) { $short_url_host = 'youtu.be'; $video_id = false; $parsed_url = parse_url( $url ); if(!isset($parsed_url['host'])){ $parsed_url['host'] = ''; } if ($short_url_host === substr( $parsed_url['host'], -strlen($short_url_host ) ) ) { // youtu.be/{id} $parts = explode( '/', $parsed_url['path'] ); if ( ! empty( $parts ) ) { $video_id = $parts[1]; } } else { // ?v={id} or ?list={id} if(isset($parsed_url['query'])){ parse_str( $parsed_url['query'], $query_args ); } if ( isset( $query_args['v'] ) ) { if ( false !== strpos( $query_args['v'], '?' ) ) { $video_id = strtok( $query_args['v'], '?' ); } else{ $video_id = $query_args['v']; } } } if ( empty( $video_id ) ) { // /(v|e|embed)/{id} $parts = explode( '/', $parsed_url['path'] ); if ( in_array( $parts[1], array( 'v', 'e', 'embed' ) ) ) { $video_id = $parts[2]; } } return $video_id; } if(!function_exists('ampforwp_imagify_webp_compatibility')){ function ampforwp_imagify_webp_compatibility($content){ if(function_exists('_imagify_init')){ preg_match_all('/src="(.*?)"/', $content,$src); $imageify_opt = get_option( 'imagify_settings' ); $convert_to_webp = false; if(isset($imageify_opt['convert_to_webp'])){ $convert_to_webp = $imageify_opt['convert_to_webp']; } $display_webp = false; if(isset($imageify_opt['display_webp'])){ $display_webp = $imageify_opt['display_webp']; } if($convert_to_webp && $display_webp){ $img_url = esc_url($src[1][0]); if(!preg_match('/\.webp/', $img_url)){ $rep_url = esc_url($src[1][0]).".webp"; if(preg_match('/http(.*)\/wp-content\/uploads/', $rep_url)){ $upload_dir = wp_upload_dir()['basedir']; $img_file = preg_replace('/http(.*)\/wp-content\/uploads/', $upload_dir, $rep_url); if(file_exists($img_file)){ $content = str_replace($img_url, $rep_url, $content); } } } } } $content = str_replace('.webp.webp','.webp',$content); return $content; } } if(!function_exists('ampforwp_set_default_fallback_image')){ function ampforwp_set_default_fallback_image($content){ if(!function_exists('_imagify_init') && !function_exists('ewww_image_optimizer_webp_initialize')){ preg_match_all('/src="(.*?)"/', $content,$cc); // need to check extenstion for fallback. if(isset($cc[1][0])){ $img = $cc[1][0]; $defaul_fallback_img = ampforwp_get_setting('ampforwp_default_fallback_image'); if(isset($defaul_fallback_img['url']) && $defaul_fallback_img['url']!=''){ $defaul_fallback_img = esc_url($defaul_fallback_img['url']); $content = str_replace($img, $defaul_fallback_img, $content); // need to change fallback extenstion. } } } return $content; } } if(!function_exists('ampforwp_ewww_webp_compatibility')){ function ampforwp_ewww_webp_compatibility($content){ if(defined( 'EWWW_IO_CLOUD_PLUGIN' )){ preg_match_all('/src="(.*?)"/', $content,$src); if(isset($src[1][0])){ $img_url = esc_url($src[1][0]); if(!preg_match('/\.webp/', $img_url)){ $rep_url = esc_url($src[1][0]).".webp"; if(preg_match('/http(.*)\/wp-content\/uploads/', $rep_url)){ $upload_dir = wp_upload_dir()['basedir']; $img_file = preg_replace('/http(.*)\/wp-content\/uploads/', $upload_dir, $rep_url); if(file_exists($img_file)){ $content = str_replace($img_url, $rep_url, $content); } } } } } $content = str_replace('.webp.webp','.webp',$content); return $content; } } if(!function_exists('ampforwp_check_image_existance')){ function ampforwp_check_image_existance($image){ if(preg_match('/wp-content\/uploads/', $image)){ $img_arr = explode('wp-content', $image); if(!empty($img_arr) && isset($img_arr[1])){ $img = WP_CONTENT_DIR.$img_arr[1]; if(!file_exists($img)){ if(preg_match('/\d+x\d+/', $image,$ma)){ $t_sizes = explode('x', $ma[0]); $width = $t_sizes[0]; $height = $t_sizes[1]; $image = preg_replace('/-\d+x\d+/','', $image); $resize = ampforwp_aq_resize( $image, $width , $height , true, false, true ); if(isset($resize[0])){ $image = $resize[0]; } } } } } return $image; } } if (function_exists('themify_builder_activate')) { add_filter('ampforwp_modify_the_content','ampforwp_themify_compatibility'); } function ampforwp_themify_compatibility($content){ $get_data = get_post_meta(ampforwp_get_the_ID(),'_themify_builder_settings_json',true); if($get_data){ $decode = json_decode($get_data,true); $cols = ''; for($i=0;$i $value) { foreach ($value['mod_settings'] as $key => $val) { $content.=$val; } } } } } } } return $content; } add_action( 'wp_ajax_ampforwp_referesh_related_post', 'ampforwp_referesh_related_post' ); function ampforwp_referesh_related_post(){ if(!wp_verify_nonce($_POST['verify_nonce'],'ampforwp_refresh_related_poost') ){ echo json_encode(array('status'=>403,'message'=>'user request is not allowed')) ; die; } $orderby = 'ID'; $args=array( 'fields' => 'ids', 'post_type' => 'post', 'posts_per_page'=> 30, 'orderby' => $orderby, 'ignore_sticky_posts'=>1, 'has_password' => false , 'post_status'=> 'publish', 'no_found_rows' => true, 'meta_query' => array( array( 'key' => 'ampforwp-amp-on-off', 'compare' => 'NOT EXISTS', ) ) ); $my_query = new wp_query( $args ); while( $my_query->have_posts() ) { $my_query->the_post(); update_post_meta(get_the_ID(),'ampforwp-amp-on-off','default'); } /*$args=array( 'fields' => 'ids', 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'posts_per_page' => 50, 'no_found_rows' => true, 'meta_query' => array( array( 'key' => 'ampforwp-ia-on-off', 'compare' => 'NOT EXISTS', ) ) ); $my_query = new wp_query( $args ); while( $my_query->have_posts() ) { $my_query->the_post(); update_post_meta(get_the_ID(),'ampforwp-ia-on-off','default'); }*/ $data['response'] = ampforwp_get_post_percent(); echo json_encode($data); } // HIDE/SHOW TAG AND CATEGORY #4326 function ampforwp_save_taxonomy_meta($term_id){ if(isset($_POST['amp_taxonomy'])){ $cat_status = sanitize_text_field($_POST['amp_taxonomy']); $hide_tax = sanitize_text_field($_POST['hide_tax']); add_term_meta($term_id, 'amp_taxonomy', $cat_status ); add_term_meta( $term_id,'amp_hide_tax', $hide_tax); } } function ampforwp_update_taxonomy_meta($term_id, $term_id1){ if(isset($_POST['amp_taxonomy'])){ $cat_status = sanitize_text_field($_POST['amp_taxonomy']); $hide_tax = sanitize_text_field($_POST['hide_tax']); update_term_meta( $term_id,'amp_taxonomy', $cat_status); update_term_meta( $term_id,'amp_hide_tax', $hide_tax); } } if ( isset( $_REQUEST['taxonomy'] )) { $taxonomy = $_REQUEST['taxonomy']; add_action('edited_'.esc_attr($taxonomy), 'ampforwp_update_taxonomy_meta',10,2); add_action('create_'.esc_attr($taxonomy), 'ampforwp_save_taxonomy_meta', 10); add_action('edited_'.esc_attr($taxonomy), 'ampforwp_update_taxonomy_meta',10,2); add_action('create_'.esc_attr($taxonomy), 'ampforwp_save_taxonomy_meta', 10); add_action (esc_attr($taxonomy).'_edit_form_fields', 'ampforwp_extra_category_fields'); add_action (esc_attr($taxonomy).'_add_form_fields', 'ampforwp_extra_category_fields'); } function ampforwp_extra_category_fields( $tag ) { $label = 'Category'; if(is_object($tag)){ if($tag->taxonomy=="post_tag"){ $label = 'Tag'; }else if($tag->taxonomy!='category'){ $label = $tag->taxonomy; } }else{ if($tag=='post_tag'){ $label = 'Tag'; } } ?> term_id)){?>

You can enable or disable AMP on this category. Learn More.


term_id); $visible = ''; $visible_status = ''; if(isset($term_data['visible']) && !empty($term_data['visible'])){ $visible = $term_data['visible'][0]; $visible_status = $term_data['visible_status'][0]; } ?>
You can enable or disable AMP on this category. Learn More.
style="display: none;" class="edit_hide_tax mrtop-10">
checked > : Hide from Archive Page.
checked > & Posts: Hide from Archive Page and all it's posts
$element) { if(isset($cdn_url['cdn_cnames'][$key]) && $cdn_url['cdn_cnames'][$key]!=''){ $cnds_arr[$element] = $cdn_url['cdn_cnames'][$key]; } } } if(isset($cnds_arr['images'])){ $img_cdn_url = $cnds_arr['images']; $img_cdn_url = apply_filters( 'ampforwp_modify_wp_rocket_cdn_url', $img_cdn_url ); }else if(isset($cnds_arr['all'])){ $img_cdn_url = $cnds_arr['all']; } if($img_cdn_url!=''){ $parse_url = parse_url($img_cdn_url); if(!isset($parse_url['scheme'])){ if(!preg_match('/\/\//', $img_cdn_url)){ $img_cdn_url = '//'.$img_cdn_url; } } $comp_dom = new DOMDocument(); @$comp_dom->loadHTML($content); $xpath = new DOMXPath( $comp_dom ); $nodes = $xpath->query('//amp-img[@src]'); $home_url = home_url(); foreach ($nodes as $node) { $url = $node->getAttribute('src'); $srcset = $node->getAttribute('srcset'); $is_external = ampforwp_isexternal($url); if(!$is_external && !$node->hasAttribute('fallback')){ $img_src = str_replace($home_url, $img_cdn_url, $url); $content = str_replace($url, $img_src, $content); $srcset_arr = explode(",", $srcset); for($i=0;$i /i", $content,$matches)){ $content = preg_replace( "//i", ' $url, 1 => $width, 2 => $height); } } add_filter('ampforwp_post_template_data','ampforwp_amp_bind_script'); function ampforwp_amp_bind_script($data) { if ( empty( $data['amp_component_scripts']['amp-bind'] ) ) { $data['amp_component_scripts']['amp-bind'] = 'https://cdn.ampproject.org/v0/amp-bind-latest.js'; } return $data; } add_filter('ampforwp_post_template_data','ampforwp_amp_story_player_script',12); function ampforwp_amp_story_player_script($data) { if ( isset($data['post'])) { $post_content = $data['post']->post_content; if ( (preg_match('//s', $post_content) || preg_match('/web-stories/', $post_content )) && empty( $data['amp_component_scripts']['amp-story-player'] ) ) { $data['amp_component_scripts']['amp-story-player'] = 'https://cdn.ampproject.org/v0/amp-story-player-latest.js'; } } return $data; } if(!function_exists('ampforwp_video_lightbox')){ function ampforwp_video_lightbox($content){ $video_tags_arr = array('amp-youtube'); add_action('amp_post_template_css','ampforwp_video_lightbox_css',30); for($i=0;$i/', $content, $matches); if(!empty($matches)){ if(isset($matches[0])){ $con = ""; for($i=0;$igetElementsByTagName( 'amp-youtube' ); $video_id =''; $width = 800; $height = 450; foreach ($nodes as $key => $node) { $video_id = $node->getAttribute('data-videoid'); $width =$node->getAttribute('width'); $height =$node->getAttribute('height'); } $amp_light_box = '
'.$match.'
'; $content = str_replace("$match", $amp_light_box, $content); } } } } return $content; } } function ampforwp_video_lightbox_css(){ echo '.amp-video-box,.amp-video-img{width:100%;margin:0 auto;text-align:center} .amp-lightbox-video{background:rgba(0,0,0,.8);width:100%;height:100%;position:absolute;display:flex;align-items:center;justify-content:center} .amp-video-box{max-width:800px} .amp-video-img{max-width:600px;position:relative} .amp-lightbox-video .lb-x { top: 100px; right: 5%; } .amp-video-play-on-image{cursor:pointer;margin:auto;width:56px;height:56px;-webkit-border-radius:50%;border-radius:50%;background-color:rgba(0,0,0,.2);background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAMAAADVRocKAAAAY1BMVEVHcEz///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////80LMUcAAAAIHRSTlMA1d4MSXeg9glf6yEq4hfnnr7Z8qm5U/3Jm1pwFJcmBYTgJ9QAAAIjSURBVGje7VnJdoMwDFSMHVMSQljCklX//5U99NQHGEm22gtz9tPAWNYKsGPHDiou1h3rpvDD4Iumvjp7SWg86yeDM5ipz5KYt53HFfjORn+8KzEI88iizLe4icLlUvtfFZJQ3kXmTzWScTsJPr9FBtovpvn8iExMrJu4jMjGyHh67xIFMOSLOFcoQnUmfr/QPmL1JulfohiGcA/5iBEYt33piFG4br4vjMTGizu1sQRt2FlrjMZNVSBExEBszaoUBOW6JzlMArf6A0XIOzyZoMgkPwDnA5nhsWz/E4wRnBxhVuoTDBMAkGVarma6TQKyTN3iFfttAqJMg1/y1B4JBFSZ+gWCiUZAk+m1QGCIBCSZmoVEhlQCkkxPppP+JiDIZNlxiFmYOXaqnEX2sEwTO9XMq6egTPXsfMMlCMt0mB0v2ARBmYrZYS8gCMjkZ2cHCcG6TMPfE6hLpH7J6m6a+KHN67urdqhQD3bq4Vo94ainTP2kn7RssbqFF7a5buk4dP9T/Ib9KEH5Dg/lBkS/hVJvAiEvU9gPtLFwT0HQh1r9m/IoQX8YEj+t2JwCX+PsT7ojtWH8EIaCJmIo+FQeaxJHs9LBbPkGIt4ilQxjxi8ajj+BgZztra8P8MBcUAi2LCdGXJKsWADgTozeppeuoXJXEPKXfM0FANnDaC7qtlaNbfyq8Uep/rXQYDUvm0M6XKyb6sPPuvdwm5x9wo4dO6j4BoilN6H4pmTiAAAAAElFTkSuQmCC);background-position:center;-webkit-background-size:48px 48px;background-size:48px 48px;position:absolute;top:0;bottom:0;left:0;right:0}'; } if (class_exists('WPSEO_Options')) { add_filter('yoast_seo_development_mode','ampforwp_yoast_seo_development'); add_filter('wpseo_debug_json_data','ampforwp_remove_homepage_breadcrumb'); } function ampforwp_yoast_seo_development($dev){ $url_path = trim(parse_url(add_query_arg(array()), PHP_URL_PATH),'/' ); if (ampforwp_get_setting('ampforwp-seo-selection') == 'yoast' && ampforwp_get_setting('ampforwp-seo-yoast-schema') && ampforwp_is_home() && function_exists('ampforwp_is_amp_inURL') && ampforwp_is_amp_inURL($url_path)) { $dev = true; } return $dev; } function ampforwp_remove_homepage_breadcrumb($data){ $url_path = trim(parse_url(add_query_arg(array()), PHP_URL_PATH),'/' ); if (ampforwp_get_setting('ampforwp-seo-selection') == 'yoast' && ampforwp_get_setting('ampforwp-seo-yoast-schema') && ampforwp_is_home() && function_exists('ampforwp_is_amp_inURL') && ampforwp_is_amp_inURL($url_path)) { if (isset($data["@graph"][2]["breadcrumb"])) { unset($data["@graph"][2]["breadcrumb"]); } if(array_key_exists(3, $data["@graph"])) { if (!empty($data["@graph"][3]["@type"]) && $data["@graph"][3]["@type"] == 'BreadcrumbList') { unset($data["@graph"][3]); } } } return $data; } //Twitter title #2744 function ampforwp_sanitize_twitter_title($post_title){ $post_title = html_entity_decode( $post_title, ENT_QUOTES, 'UTF-8' ); $post_title = rawurlencode( $post_title ); $post_title = esc_html( $post_title ); return $post_title; } if (function_exists('i2_pros_cons_setup')) { add_action('amp_post_template_css','ampforwp_i2prosandcons'); } function ampforwp_i2prosandcons(){ $options = get_option( 'i2_pros_and_cons'); $prosHeadingBackground = $options['pros_heading_background']; $consHeadingBackground = $options['cons_heading_background']; $prosBackground = $options['pros_background']; $consBackground = $options['cons_background']; $headingFontSize = $options['heading_font_size']; $sectionFontSize = $options['body_font_size']; $headingColor = $options['heading_color']; $sectionColor = $options['body_color'];?> .i2-pros-cons-main-wrapper .i2-pros-cons-wrapper { display: table; width: 100%; } .i2-pros-cons-main-wrapper .i2-pros-cons-wrapper .i2-pros, .i2-pros-cons-main-wrapper .i2-pros-cons-wrapper .i2-cons { display: table-cell; width: 50%; margin-bottom: 15px; position: relative; } .i2-pros-cons-main-wrapper .i2-pros-cons-wrapper .i2-pros .i2-pros-title, .i2-pros-cons-main-wrapper .i2-pros-cons-wrapper .i2-pros .i2-cons-title, .i2-pros-cons-main-wrapper .i2-pros-cons-wrapper .i2-cons .i2-pros-title, .i2-pros-cons-main-wrapper .i2-pros-cons-wrapper .i2-cons .i2-cons-title { padding: 5px 15px 5px; margin: 0px; display: block; } .i2-pros-cons-wrapper .i2-pros-title { background-color:; font-size:px; } .i2-pros-cons-wrapper .i2-cons-title, .i2-pros-cons-wrapper .i2-pros-title { color: #ffffff!important; font-size:px; } .i2-pros { background-color: ; } .i2-cons{ background-color: ; } .i2-pros-cons-wrapper ul li{ font-size:px; } .artl-cnt ul li:before { content: "\e315"; display: inline-block; width: 0; background: #333; position: absolute; top: 0px; left: 0px; font-family: 'icomoon'; } .i2-pros-cons-wrapper .i2-cons-title { background-color: ; } .i2-pros-cons-wrapper .i2-pros, .i2-pros-cons-wrapper .i2-cons{ color: ; } .i2-pros-cons-wrapper .i2-cons-title, .i2-pros-cons-wrapper .i2-pros-title { color: ; } (.*?)<\/(.*?)>(.*?)class="wpsp-faq-content">

(.*?)<\/p>/', $content_buffer, $matches); if(is_array($matches)){ $schema = array(); $schema['@context'] = 'https://schema.org'; $schema['type'] = 'FAQPage'; for($i=0;$i $question ) { $schema['mainEntity'][ $key ]['@type'] = 'Question'; $schema['mainEntity'][ $key ]['name'] = $question; } foreach ( $answers as $key => $answer ) { $schema['mainEntity'][ $key ]['acceptedAnswer']['@type'] = 'Answer'; $schema['mainEntity'][ $key ]['acceptedAnswer']['text'] = $answer; } } $schema = ''; $content_buffer = preg_replace('/(

Embed from Getty Images<\/a>/', $content, $matches)){ if(isset($matches[0])){ for($i=0;$i'; $description = get_the_archive_description(); $sanitizer = new AMPFORWP_Content( $iframe, array(), apply_filters( 'ampforwp_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, ) ) ) ); $iframe_content = $sanitizer->get_amp_content(); $content = str_replace($full_content, $iframe_content, $content ); } } } } } } } return $content; } if(function_exists('vp_pfui_admin_init') && function_exists('penci_setup')){ add_action('ampforwp_before_post_content','ampforwp_pennews_audio_embed'); } function ampforwp_pennews_audio_embed(){ $audio = get_post_meta(ampforwp_get_the_ID(), '_format_audio_embed', true); if(empty($audio)){ return; } $audio = preg_replace('//', '', $audio); $audio_str = substr( $audio, -4 ); $html ='
'; if ( wp_oembed_get( $audio ) ) { $html .= wp_oembed_get( $audio ); }elseif( $audio_str == '.mp3' ) { $html .= do_shortcode('[audio src="'. esc_url( $audio ) .'"]'); }else{ $html .= do_shortcode( $audio ); } $html .= '
'; $sanitizer = new AMPFORWP_Content( $html, array(), apply_filters( 'ampforwp_content_sanitizers', array( 'AMP_Audio_Sanitizer' => array(), 'AMP_Iframe_Sanitizer' => array( 'add_placeholder' => true, ) ) ) ); $sanitized_html = $sanitizer->get_amp_content(); echo $sanitized_html; } //Alignment issue with Gutenberg image block #4997 add_filter('ampforwp_modify_the_content','ampforwp_wp_block_cover_image'); function ampforwp_wp_block_cover_image($content_buffer){ if(ampforwp_get_setting('ampforwp_css_tree_shaking') && ampforwp_is_gutenberg_active()){ preg_match_all('//', $content_buffer, $matches); if(is_array($matches) && isset($matches[4][0])){ $img_url = $matches[4][0]; if (!empty($img_url)) { $content_buffer = preg_replace('//', '', $content_buffer); $content_buffer = preg_replace('//', '', $content_buffer); return $content_buffer; } } } return $content_buffer; } function ampforwp_mobile_redirection_js() { $url_to_redirect = ampforwp_amphtml_generator();?> '; $paragraphs = explode( $closing_p, $content ); foreach ($paragraphs as $index => $paragraph) { if ( trim( $paragraph ) ) { $paragraphs[$index] .= $closing_p; } $n = $index + 1; if ( isset( $ads[ $n ] ) ) { $paragraphs[$index] .= $ads[ $n ]; } } return implode( '', $paragraphs ); } add_filter( 'ampforwp_modify_the_content', 'ampforwp_publisher_desk_ads' ); function ampforwp_publisher_desk_ads( $content ) { if (!ampforwp_get_setting('ampforwp-ads-publisherdesk')) { return $content; } $pub_id = $url = ''; $pub_id = ampforwp_get_setting('ampforwp-publisherdesk-id'); if (!empty($pub_id)) { $url = 'https://cdn.tpdads.com/json/amp-tags/'.esc_html($pub_id).'.json'; } $data_api = wp_remote_get($url); if (is_array($data_api) && !empty($data_api['body'])) { $json_data_api = json_decode( $data_api['body'] ); $addList = array(); if(!empty($json_data_api->customHTMLAboveContentAd)){ $content = $json_data_api->customHTMLAboveContentAd[0]." ".$content; } if(!empty($json_data_api->customHTMLBelowContentAd)){ $content .= $json_data_api->customHTMLBelowContentAd[0]; } if ( is_single() && !empty($pub_id) && !empty($json_data_api) ) { if($json_data_api->inContentPlacementMethod=='Auto'){ $addList[3] = $json_data_api->customHTMLInContentAds[0]; $addList[6] = $json_data_api->customHTMLInContentAds[1]; $addList[9] = $json_data_api->customHTMLInContentAds[2]; } else{ for ($i=0; $i < count($json_data_api->afterParagraphNumbers); $i++) { $addList[$json_data_api->afterParagraphNumbers[$i]] = $json_data_api->customHTMLInContentAds[$i]; } } $content = ampforwp_publisher_desk_ads_insert( $addList, $content ); $content .= $json_data_api->stickyCustomHTMLAd[0]; $content = preg_replace('/json="/', 'json=\"' , $content); $content = preg_replace('/rtc-config="/', 'rtc-config=\"' , $content); } } return $content; } // #5274 AMP Take over conflict with WPML add_filter('ampforwp_is_amp_endpoint_takeover', 'ampforwp_wpml_takeover_compatibility'); function ampforwp_wpml_takeover_compatibility($return) { if (is_user_logged_in() && !empty($_GET['wpml-app'])) { return false; } return $return; }; if(class_exists('SuperRelatedPosts')){ add_action('amp_post_template_css', 'ampforwp_super_related_posts_style'); } function ampforwp_super_related_posts_style(){ global $wp_filesystem; $css = get_transient('ampforwp_super_related_posts'); if($css == false){ if(!is_object($wp_filesystem)){ require_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php'; require_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php'; $wp_filesystem = new WP_Filesystem_Direct( array() ); } $css = $wp_filesystem->get_contents(AMPFORWP_PLUGIN_DIR."/includes/super-related-posts.css"); set_transient('ampforwp_super_related_posts', $css); } echo ampforwp_css_sanitizer($css); }