: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$element = $video_nodes->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') ));
$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);
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 ( $textarea ) { unset($tags[$textarea]); }
if ( $select ) { unset($tags[$select]); }
if ( $option ) { unset($tags[$option]); }
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 = '';
$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 ) {
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;
$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';
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 ) {
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;
$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';
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 ) {
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;
$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';
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 ) {
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;
$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';
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 ) {
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;
$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';
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 ) {
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;
$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';
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;
// 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()) ){
if($item->type=='taxonomy' && !in_array($item->object, ampforwp_get_all_post_types()) ){
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){
$is_external = ampforwp_isexternal($url);
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']);
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);
// 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'] ) {
// 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 ) {
// Remove all unwanted scripts on search pages
unset( $data['amp_component_scripts']);
// 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;
$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']
// 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 ) {
$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,
if ( $amp_custom_content ) {
$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();
//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;}
// 54. Change the default values of post meta for AMP pages. #746
add_action('admin_head','ampforwp_change_default_amp_page_meta');
function ampforwp_change_default_amp_page_meta() {
if ( ! current_user_can('manage_options') ) {
global $redux_builder_amp;
$check_meta = get_option('ampforwp_default_pages_to');
$control = $redux_builder_amp['amp-pages-meta-default'];
$meta_value_to_upate = 'default';
if ( $control === 'hide' ) {
$meta_value_to_upate = 'hide-amp';
// Check and Run only if the value has been changed, else return
if ( $check_meta === $checker ) {
// Get all the pages and update the post meta
$pages = get_pages(array());
foreach($pages as $page){
update_post_meta($page->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);
// 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() )) {
if (function_exists('aioseo_pro_just_activated') && 'aioseo' == ampforwp_get_setting('ampforwp-seo-selection') ) {
$desc = ampforwp_generate_meta_desc();
if ( $desc && !class_exists('Yoast\\WP\\SEO\\Integrations\\Front_End_Integration')) {
echo '<meta name="description" content="'. esc_attr( convert_chars( stripslashes( $desc ) ) ) .'"/>';
}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'];
$yoast_desc = $yoast_desc_meta;
if ($yoast_desc && ampforwp_is_front_page()) {
echo '<meta name="description" content="'. esc_attr( convert_chars( stripslashes( $yoast_desc ) ) ) .'"/>';
elseif ($desc && ampforwp_is_home() && 'page' == get_option( 'show_on_front') && empty(get_option( 'page_for_posts')) ){
echo '<meta name="description" content="'. esc_attr( convert_chars( stripslashes( $desc ) ) ) .'"/>';
// 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'] ) { ?>
<a href="tel:<?php echo esc_attr($redux_builder_amp['enable-amp-call-numberfield']); ?>"></a>
// 56. Multi Translation Feature #540
// Moved to functions.php
// 57. Adding Updated date at in the Content
add_action('ampforwp_after_post_content','ampforwp_add_modified_date');
function ampforwp_add_modified_date($post_object){
global $redux_builder_amp;
if ( is_single() && $redux_builder_amp['post-modified-date'] == true && ( ! checkAMPforPageBuilderStatus( get_the_ID() ) ) ) { ?>
<div class="ampforwp-last-modified-date">
$date_notice_type = ampforwp_get_setting('ampforwp-post-date-notice-type');
if( $date_notice_type == "modified" && $post_object->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' );
_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' );
_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')){