= 1) :
remove_action( 'wp_head', 'ampforwp_home_archive_rel_canonical', 1 );
endif;
}
function ampforwp_amphtml_generator(){
global $redux_builder_amp;
global $wp, $post;
$post_id = '';
$endpoint_check = false;
$endpoint_check = $redux_builder_amp['amp-core-end-point'];
if( is_attachment() ) {
return;
}
if( is_home() && is_front_page() && !$redux_builder_amp['ampforwp-homepage-on-off-support'] ) {
return;
}
if( is_front_page() && ! $redux_builder_amp['ampforwp-homepage-on-off-support'] ) {
return;
}
if ( is_archive() ) {
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;
}
}
// no-amphtml for search
if(is_search()){
return;
}
// #872 no-amphtml if selected as hide from settings
if ( is_category_amp_disabled() ) {
return;
}
if ( is_page() && ! $redux_builder_amp['amp-on-off-for-all-pages'] && ! is_home() && ! is_front_page() ) {
return;
}
if ( is_home() && ! ampforwp_is_blog() && !$redux_builder_amp['ampforwp-homepage-on-off-support'] ) {
return;
}
if ( ampforwp_is_blog() && ! $redux_builder_amp['amp-on-off-for-all-pages'] ) {
return;
}
$query_arg_array = $wp->query_vars;
if( in_array( "cpage" , $query_arg_array ) ) {
if( is_front_page() && $wp->query_vars['cpage'] >= '2' ) {
return;
}
if( is_singular() && $wp->query_vars['cpage'] >= '2' ) {
return;
}
}
if ( is_home() || is_front_page() || is_archive() ){
global $wp;
$current_archive_url = home_url( $wp->request );
$amp_url = trailingslashit($current_archive_url);
} else {
$amp_url = 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();
$supported_types = apply_filters('get_amp_supported_post_types',$supported_types);
$type = get_post_type();
if(is_home() || is_front_page()){
if(isset($redux_builder_amp['ampforwp-homepage-on-off-support'])
&& $redux_builder_amp['ampforwp-homepage-on-off-support'] == 1
&& isset($redux_builder_amp['amp-on-off-for-all-posts'])
&& $redux_builder_amp['amp-on-off-for-all-posts'] == 0
&& isset($redux_builder_amp['amp-on-off-for-all-pages'])
&& $redux_builder_amp['amp-on-off-for-all-pages'] == 0 ){
$supported_types['post'] = 'post';
}
}
$supported_amp_post_types = in_array( $type , $supported_types );
$query_arg_array = $wp->query_vars;
if( array_key_exists( 'paged' , $query_arg_array ) ) {
if ( (is_home() || is_archive()) && $wp->query_vars['paged'] >= '2' ) {
$new_url = home_url('/');
$category_path = $wp->request;
if ( null != $category_path && true != $endpoint_check) {
$explode_path = explode("/",$category_path);
$inserted = array(AMPFORWP_AMP_QUERY_VAR);
array_splice( $explode_path, -2, 0, $inserted );
$impode_url = implode('/', $explode_path);
$amp_url = $new_url . $impode_url ;
}
}
if( is_search() && $wp->query_vars['paged'] >= '2' ) {
$current_search_url =trailingslashit(get_home_url()) . $wp->request .'/'."?amp=1&s=".get_search_query();
}
}
$amp_url = user_trailingslashit($amp_url);
if( is_search() ) {
$current_search_url =trailingslashit(get_home_url())."?amp=1&s=".get_search_query();
$amp_url = untrailingslashit($current_search_url);
}
if( class_exists('SitePress') ){
if( get_option('permalink_structure') ){
global $sitepress_settings, $wp;
if($sitepress_settings[ 'language_negotiation_type' ] == 3){
if( is_singular() ){
$active_langs = $sitepress_settings['active_languages'];
$found = '';
$wpml_url =get_permalink( get_queried_object_id() );
$untrail_wpml_url = untrailingslashit($wpml_url);
$explode_url = explode('/', $untrail_wpml_url);
$append_amp = AMPFORWP_AMP_QUERY_VAR;
foreach ($active_langs as $active_lang) {
foreach($explode_url as $a) {
if (stripos('?lang='.$active_lang ,$a) !== false){
$amp_url = add_query_arg('amp','1',$wpml_url);
$found = 'found';
break 2;
}
}
}
if($found == ''){
array_splice( $explode_url, count($explode_url), 0, $append_amp );
$impode_url = implode('/', $explode_url);
$amp_url = untrailingslashit($impode_url);
}
}
if ( is_home() || is_archive() ){
global $wp;
$current_archive_url = home_url( $wp->request );
$explode_path = explode("/",$current_archive_url);
$inserted = array(AMPFORWP_AMP_QUERY_VAR);
$query_arg_array = $wp->query_vars;
if( array_key_exists( 'paged' , $query_arg_array ) ) {
$active_langs = $sitepress_settings['active_languages'];
$found = '';
foreach ($active_langs as $active_lang) {
foreach($explode_path as $a) {
if (stripos('?lang='.$active_lang ,$a) !== false){
$amp_url = add_query_arg('amp','1',$current_archive_url);
$found = 'found';
break 2;
}
}
}
if($found == ''){
array_splice( $explode_path, count($explode_path), 0, $inserted );
$impode_url = implode('/', $explode_path);
$amp_url = $impode_url;
}
}
else{
$active_langs = $sitepress_settings['active_languages'];
$found = '';
foreach ($active_langs as $active_lang) {
foreach($explode_path as $a) {
if (stripos('?lang='.$active_lang ,$a) !== false){
$amp_url = add_query_arg('amp','1',$current_archive_url);
$found = 'found';
break 2;
}
}
}
if($found == ''){
array_splice( $explode_path, count($explode_path), 0, $inserted );
$impode_url = implode('/', $explode_path);
$amp_url = $impode_url;
}
}
}
}
}
}
if( !class_exists('SitePress') ){
// URL Purifier
$amp_url = ampforwp_url_purifier($amp_url);
}
$amp_url = apply_filters('ampforwp_modify_rel_canonical',$amp_url);
if( $supported_amp_post_types) {
return $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() {
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() ) {
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));
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';
}
if ( ampforwp_is_front_page() || ( true == $redux_builder_amp['ampforwp-amp-takeover'] && is_front_page() && $redux_builder_amp['amp-frontpage-select-option']) ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/frontpage.php';
}
// Archive Pages
if ( is_archive() && $redux_builder_amp['ampforwp-archive-support'] && 'single' === $type ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/archive.php';
}
// Search pages
if ( is_search() ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/search.php';
}
// 404 Pages #2042
if ( is_404() && 'single' === $type ) {
add_filter('ampforwp_modify_rel_url','ampforwp_404_canonical');
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/404.php';
}
}
// 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' === $redux_builder_amp['amp-design-selector'] ) {
$social_check = true;
}
if ( '4' !== $redux_builder_amp['amp-design-selector'] && defined('AMPFORWP_DM_SOCIAL_CHECK') && 'true' === AMPFORWP_DM_SOCIAL_CHECK ) {
$social_check = true;
}
if( $redux_builder_amp['enable-single-social-icons'] == true || defined('AMPFORWP_DM_SOCIAL_CHECK') && AMPFORWP_DM_SOCIAL_CHECK === 'true' ) {
if( (is_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') || ( $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 == $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('/(<[^>]+) value=[^>]*/', '$1', $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('/for=[^>]*/', '', $content);
$content = preg_replace('/nowrap="nowrap"/', '', $content);
$content = preg_replace('#(.*?)#i', '', $content);
$content = preg_replace('#(.*?)#i', '', $content);
$content = preg_replace('#(.*?)#i', '', $content);
$content = preg_replace('##i', '', $content);
//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('/
';
}
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' );
}
}
function ampforwp_remove_ahref_lightbox_in_amp( $content ) {
$updated_content = preg_replace("/]+\>(
]+\>)<\/a>/i", '$1', $content);
return $updated_content;
}
// amp-image-lightbox #1892
if ( ! function_exists('ampforwp_amp_img_lightbox') ) {
function ampforwp_amp_img_lightbox(){
echo '';
}
}
// New Image attributes for amp-image-lightbox #1892
add_filter('amp_img_attributes', 'ampforwp_img_new_attrs');
function ampforwp_img_new_attrs($attributes) {
global $redux_builder_amp;
if ( isset($redux_builder_amp['ampforwp-amp-img-lightbox']) && $redux_builder_amp['ampforwp-amp-img-lightbox'] ) {
$attributes['on'] = 'tap:amp-img-lightbox';
$attributes['role'] = 'button';
$attributes['tabindex'] = '0';
}
return $attributes;
}
// Facebook Comments script for AMP2WP
add_action('ampforwp_body_beginning', 'ampforwp_amp2wp_fb');
if ( ! function_exists('ampforwp_amp2wp_fb') ) {
function ampforwp_amp2wp_fb(){
global $redux_builder_amp;
if( ampforwp_is_non_amp() && isset($redux_builder_amp['ampforwp-amp-convert-to-wp']) && $redux_builder_amp['ampforwp-amp-convert-to-wp'] && ($redux_builder_amp['ampforwp-facebook-comments-support'] || $redux_builder_amp['ampforwp-facebook-like-button']) ) {
echo '
';
}
}
}
// Removing AMPHTML Added by Facebook's Instant Article's Plugin #2043
add_action( 'wp', 'ampforwp_remove_instant_articles_amp_markup' );
function ampforwp_remove_instant_articles_amp_markup(){
if(class_exists('Instant_Articles_AMP_Markup')){
remove_action( 'wp_head', array('Instant_Articles_AMP_Markup', 'inject_link_rel') );
}
}
// #2042
function ampforwp_404_canonical(){
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
// #1696
add_action('wp','ampforwp_remove_squirly_js');
function ampforwp_remove_squirly_js(){
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');
}
}
}
// 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 ( isset($redux_builder_amp['ampforwp-seo-yoast-canonical']) && true == $redux_builder_amp['ampforwp-seo-yoast-canonical'] && class_exists('WPSEO_Frontend') ) {
$WPSEO_Frontend = WPSEO_Frontend::get_instance();
$canonical = $WPSEO_Frontend->canonical(false);
}
elseif ( isset($redux_builder_amp['ampforwp-seo-aioseo-canonical']) && true == $redux_builder_amp['ampforwp-seo-aioseo-canonical'] && class_exists('All_in_One_SEO_Pack') ) {
$All_in_One_SEO_Pack = new All_in_One_SEO_Pack();
$opts = $All_in_One_SEO_Pack->get_current_options( array(), 'aiosp' );
$canonical = $opts['aiosp_custom_link'];
}
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;
}
// #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 ( 4 != $redux_builder_amp['amp-design-selector']
&& isset($redux_builder_amp['ampforwp-vuukle-comments-support'])
&& $redux_builder_amp['ampforwp-vuukle-comments-support']==1
&& comments_open()
) {
echo ampforwp_vuukle_comments_markup();
}
}
function ampforwp_vuukle_comments_markup() {
global $redux_builder_amp,$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);
$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);
$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, $redux_builder_amp;
$display_comments_on = false;
$display_comments_on = ampforwp_get_comments_status();
if (! $display_comments_on ) {
return '';
}
$spotId ='';
if( isset($redux_builder_amp['ampforwp-spotim-comments-apiKey']) && $redux_builder_amp['ampforwp-spotim-comments-apiKey'] !== ""){
$spotId = $redux_builder_amp['ampforwp-spotim-comments-apiKey'];
}
$srcUrl = 'https://amp.spot.im/production.html?';
$srcUrl = add_query_arg('spotId' ,get_permalink(), $srcUrl);
$srcUrl = add_query_arg('postId' , $post->ID, $srcUrl);
$spotim_html = '
Load more...
';
return $spotim_html;
}
//spotim script
add_filter( 'amp_post_template_data', 'ampforwp_add_spotim_scripts' );
function ampforwp_add_spotim_scripts( $data ) {
global $redux_builder_amp;
$display_comments_on = "";
$display_comments_on = ampforwp_get_comments_status();
if ( 4 != $redux_builder_amp['amp-design-selector']
&& isset($redux_builder_amp['ampforwp-spotim-comments-support'])
&& $redux_builder_amp['ampforwp-spotim-comments-support']
&& $display_comments_on && comments_open()
) {
if ( empty( $data['amp_component_scripts']['amp-iframe'] ) ) {
$data['amp_component_scripts']['amp-iframe'] = 'https://cdn.ampproject.org/v0/amp-iframe-0.1.js';
}
}
return $data;
}
//spotim css
add_action('amp_post_template_css','ampforwp_spotim_vuukle_styling',60);
function ampforwp_spotim_vuukle_styling(){
global $redux_builder_amp;
$display_comments_on = "";
$display_comments_on = ampforwp_get_comments_status();
if ( isset($redux_builder_amp['ampforwp-spotim-comments-support'])
&& $redux_builder_amp['ampforwp-spotim-comments-support']
&& $display_comments_on && comments_open() ) {
?>.spot-im-amp-overflow {
background: white;
font-size: 15px;
padding: 15px 0;
text-align: center;
font-family: Helvetica, Arial, sans-serif;
color: #307fe2;
}
.afwp-vuukle-support{
display: block;text-align: center;background: #1f87e5;color: #fff;border-radius: 4px;
}
';
}
}
// Function to check if the query and the post name are same #2361
function ampforwp_is_query_post_same($haystack = '' , $needle = ''){
$result = '';
if(!empty($haystack) && !empty($needle)){
$result = strpos($haystack ,$needle);
}
if( ($result != false || is_int($result)) && !empty($result) ){
return true;
}
return false;
}
// 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 ( 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 {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 $redux_builder_amp, $post;
$user_level = '';
$user_level = current_user_can( 'manage_options' );
if ( isset( $redux_builder_amp['amp-meta-permissions'] ) && $redux_builder_amp['amp-meta-permissions'] == 'all' ) {
$user_level = true;
}
if ( $user_level ) {
if( true == $redux_builder_amp['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( $post->ID );
if ( ! 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( $post->ID, $exclude_post_value ) ) {
$exclude_post_value[] = $post->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( $post->ID, $exclude_post_value ) ) {
$exclude_ids = array_diff($exclude_post_value, array($post->ID) );
update_option('ampforwp_ia_exclude_post', $exclude_ids);
}
}
} ?>
base ) {
remove_action('admin_enqueue_scripts', 'total_plus_admin_scripts', 100);
}
}
// 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(){
if(!wp_verify_nonce($_GET['security'],'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));
$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(){
if(!wp_verify_nonce($_GET['security'],'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')){
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 ( 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: #32373c;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;}
$postID,
'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_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' => 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') ) ) ) {
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.1.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' );
}
do_action( 'rank_math/head' );
}
}
#1160 Embedly Sanitizer
add_filter( 'amp_content_sanitizers', 'ampforwp_embedly_sanitizer', 10, 1 );
function ampforwp_embedly_sanitizer( $sanitizer_classes ) {
if ( class_exists('WP_Embedly') ) {
require_once( AMPFORWP_PLUGIN_DIR. 'classes/class-ampforwp-embedly-sanitizer.php' );
$sanitizer_classes[ 'AMPforWP_Embedly_Sanitizer' ] = array();
}
return $sanitizer_classes;
}
add_filter('ampforwp_is_amp_endpoint_takeover', "ampforwp_bulktool_takeover");
if (! function_exists('ampforwp_bulktool_takeover') ) {
function ampforwp_bulktool_takeover($data){
$bulk_option = ampforwp_get_setting('amp-pages-meta-default');
if(is_page() && $bulk_option == "hide" && ( true == ampforwp_get_setting('ampforwp-amp-takeover') || true == ampforwp_get_setting('ampforwp-amp-convert-to-wp'))){
remove_action( 'wp_head', 'ampforwp_home_archive_rel_canonical', 1 );
return false;
}
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;
}
.fvp-onload{display:none}
.amp-featured-image amp-iframe, .amp-wp-article-featured-image amp-iframe { margin:auto; height:100%; }
.f_vid { background: #000; }
";?>