= 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( 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;
}
// 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;
}
}
// 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() && ! 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_blog() && ! ampforwp_get_setting('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 );
// 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);
} 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( 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' );
$new_url = trailingslashit($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();
}
}
$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
$amp_url = ampforwp_url_purifier($amp_url);
$amp_url = apply_filters('ampforwp_modify_rel_canonical',$amp_url);
if( $supported_amp_post_types || ampforwp_is_front_page() ) {
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 == 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 == $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' );
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 ( 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 ( 'yoast' == ampforwp_get_setting('ampforwp-seo-selection') && true == ampforwp_get_setting('ampforwp-seo-yoast-canonical') && class_exists('WPSEO_Frontend') ) {
$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;
}
// #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;
$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 {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;
if ( ampforwp_role_based_access_options() == true ) {
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);
// 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(){
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') ) ) && !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.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;
}
}
add_filter('ampforwp_is_amp_endpoint_takeover','ampforwp_disable_takovr_elementor_preview');
function ampforwp_disable_takovr_elementor_preview($data){
if ( did_action( 'elementor/loaded' ) ) {
if( \Elementor\Plugin::$instance->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;
}
.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"){
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' );
}
function ampforwp_head_css(){
global $ampforwpTemplate, $redux_builder_amp;
$css = "";
if( is_user_logged_in() ){
$pref = get_user_option( "show_admin_bar_front", get_current_user_id() );
if($pref==="true"){
$css = ampforwp_get_remote_content(AMPFORWP_PLUGIN_DIR_URI."/templates/template-mode/admin-bar.css");
$incurl = includes_url();
$incurl = trailingslashit($incurl) .'fonts/dashicons.ttf?50db0456fde2a241f005968eede3f987';
$css.='@font-face{font-family:dashicons;src:url('.esc_url( $incurl ).') format("truetype");
font-weight:400;font-style:normal}.amp-wp-header,.design2-header,.design3-header,.header{margin-top:32px}#headerwrap{top:32px}#wp-admin-bar-my-account .avatar{float:right;margin-top:6px}#wp-admin-bar-wpseo-notifications .yoast-issue-counter{float:right}@media(max-width:782px){.amp-wp-header,.design2-header,.design3-header,.header{margin-top:46px}#headerwrap{top:46px}}';
echo css_sanitizer($css);
}
}
}
function 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 = 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');
$title = $user_info->title;
$dom->loadHTML($title);
$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
) );
$wp_admin_bar->add_menu( array(
'id' => 'wpseo-menu',
'title' => "SEO"
) );
$wp_admin_bar->remove_menu( 'ampforwp-view-amp' );
$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'];
for($i=0;$iremove_node($node_arr[$i]);
}
}
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') ) {
$non_amp_url = add_query_arg('nonamp','1',$non_amp_url);
}
else
$non_amp_url = user_trailingslashit($non_amp_url);
if ( true == ampforwp_get_setting('ampforwp-amp-takeover') ) {
$non_amp_url = '';
}
if ( $non_amp_url ) {
return apply_filters('ampforwp_view_nonamp_url', $non_amp_url);
}
}