: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$jarr = json_decode($previousData);
if(isset($jarr->settingdata->scripts_data)){
$script_data = $jarr->settingdata->scripts_data;
$content = $data['post_amp_content'];
$allscripts = $script_data;
preg_match_all('/<script(.*?)custom-element=\"(.*?)\"(.*?)src=\"(.*?)\"(.*?)><\/script>/', $allscripts, $matches);
$script_slug = $matches[2];
foreach ($script_slug as $key => $slug) {
if(!preg_match('/'.$slug.'/', $content)){
global $pb_remove_script;
$pb_remove_script[]= esc_attr($slug);
add_filter( 'ampforwp_the_content_last_filter','ampforwp_remove_unused_pb_amp_script',12);
function ampforwp_remove_unused_pb_amp_script($data){
global $pb_remove_script;
for($i=0;$i<count($pb_remove_script);$i++){
$data = preg_replace('/<script(.*?)custom-element=\"'.esc_attr($pb_remove_script[$i]).'\"(.*?)src=\"(.*?)\"(.*?)><\/script>/', '', $data);
if(class_exists('RankMath')){
add_filter('ampforwp_modify_the_content','ampforwp_rank_math_nofollow_to_external_link');
function ampforwp_rank_math_nofollow_to_external_link($content){
$rank_math_external_link = RankMath\Helper::get_settings( 'general.nofollow_external_links' );
if($rank_math_external_link){
preg_match_all('/<a href="(.*?)">(.*?)<\/a>/', $content, $matches);
for($i=0;$i<count($matches[1]);$i++){
$is_external = ampforwp_isexternal($url);
$url = str_replace("/", "\/", $url);
$content = preg_replace('/(<a href="'.$url.'.*")/', '$1 rel="nofollow"', $content);
if(class_exists('transposh_plugin')){
add_action('amp_post_template_css','ampforwp_transposh_plugin_rtl_css');
if(!function_exists('ampforwp_transposh_plugin_rtl_css')){
function ampforwp_transposh_plugin_rtl_css() {
$rtl_lang_arr = array('ar', 'he', 'fa', 'ur', 'yi');
if(isset($_GET['lang'])){
if(in_array(esc_attr($_GET['lang']), $rtl_lang_arr)){
if(ampforwp_get_setting('header-position-type') == '1'){?>
.tg:checked + .hamb-mnu > .m-ctr {
<?php } if(ampforwp_get_setting('header-position-type') == '2'){?>
.tg:checked + .hamb-mnu > .m-ctr {
margin-right: calc(100% - <?php echo esc_html(ampforwp_get_setting('header-overlay-width'))?>);
add_filter('ampforwp_the_content_last_filter','ampforwp_remove_unwanted_code',10);
function ampforwp_remove_unwanted_code($content){
// Mediavine validation issue with form and amp-consent #4206
if(preg_match('/<amp-consent id="mv-consent" layout="nodisplay">(.*?)<\/amp-consent>/s', $content)){
$content = preg_replace('/<amp-consent id="mv-consent" layout="nodisplay">(.*?)<\/amp-consent>/s', '', $content);
if(preg_match('/<form class="mv-create-print-form">(.*?)<\/form>/s', $content)){
$content = preg_replace('/<form class="mv-create-print-form">(.*?)<\/form>/s', '', $content);
if(function_exists('orbital_setup')){
if(preg_match('/<script>function orbital_expand_navbar(.*?)<\/script>/', $content)){
$content = preg_replace('/<script>function orbital_expand_navbar(.*?)<\/script>/', '', $content);
//Remove label from anchor
if(preg_match('/<a(.*?)\slabel\s(.*?)>/', $content)){
$content = preg_replace('/<a(.*?)\slabel\s(.*?)>/', '<a $1$2>', $content);
add_filter('ampforwp_the_content_last_filter','ampforwp_include_required_scripts',12);
function ampforwp_include_required_scripts($content){
$allscripts = $is_script = '';
$comp_to_remove_arr = array();
preg_match_all('/<\/amp-(.*?)>/', $content, $matches);
if(isset($matches[1][0])){
$comp_to_remove_json = get_transient('ampforwp_amp_exclude_custom_element');
$comp_to_include_json = get_transient('ampforwp_amp_included_custom_element');
if($comp_to_remove_json){
$comp_to_remove_arr = json_decode($comp_to_remove_json, true);
$comp_to_include_arr = array();
if($comp_to_include_json){
$comp_to_include_arr = json_decode($comp_to_include_json, true);
for($i=0;$i<count($amp_comp);$i++){
if(!preg_match('/story/', $comp)){
if($comp == 'auto-ads' || $comp == 'ad'){
if($comp=='state' || $comp=='img'){
$comp_url = "https://cdn.ampproject.org/v0/amp-bind-latest.js";
$comp_url = 'https://cdn.ampproject.org/v0/amp-'.esc_attr($comp).'-'.esc_attr($script_ver).'.js';
$check_comp = 'amp-'.esc_attr($comp);
if(!in_array($comp, $comp_to_remove_arr) && !in_array($comp, $comp_to_include_arr) ){
$ce_valid_scripts = ampforwp_valid_amp_componet_script();
$is_script = in_array($check_comp, $ce_valid_scripts);
if ( ini_get( 'allow_url_fopen' ) ) {
$headers = get_headers($comp_url);
$is_script = stripos($headers[0], "200 OK") ? TRUE : FALSE;
$comp_to_include_arr[] = $comp;
$inc_json = wp_json_encode($comp_to_include_arr);
set_transient('ampforwp_amp_included_custom_element',$inc_json, 30 * DAY_IN_SECONDS);
$comp_to_remove_arr[] = $comp;
$ex_json = wp_json_encode($comp_to_remove_arr);
set_transient('ampforwp_amp_exclude_custom_element',$ex_json, 30 * DAY_IN_SECONDS);
$comp_to_include_arr = apply_filters('ampforwp_amp_custom_element_to_include',$comp_to_include_arr);
if(in_array($comp, $comp_to_include_arr) && $comp_url != ''){
if(!preg_match('/<script(\s|\sasync\s)custom-element="amp-'.esc_attr($comp).'"(.*?)>(.*?)<\/script>/s', $content, $matches)){
$script_tag = '<head><script custom-element="amp-'.esc_attr($comp).'" src="'.esc_url($comp_url).'" async></script>';
$content = str_replace('<head>', $script_tag, $content);
$comp_dom = new DOMDocument();
@$comp_dom->loadHTML($content);
$xpath = new DOMXPath( $comp_dom );
$elements = $xpath->query("*/script[@custom-element]");
$component_arr = array();
if (!is_null($elements)) {
foreach ($elements as $element) {
$component_arr[]= $element->getAttribute('custom-element');
$elements_arr[] = $comp_dom->saveHTML($element);
if (!is_null($elements)) {
if(!empty($component_arr)){
$excl_arr = array('amp-bind','amp-access','amp-analytics','amp-access-laterpay','amp-access-poool','amp-dynamic-css-classes','amp-fx-collection','amp-inputmask','amp-lightbox-gallery','amp-inputmask','amp-mustache','amp-subscriptions-google','amp-subscriptions','amp-video-docking','amp-story');
for($r=0;$r<count($comp_to_remove_arr);$r++){
$inc_elem_arr[] = 'amp-'.$comp_to_remove_arr[$r];
for($i=0;$i<count($component_arr);$i++){
if(isset($component_arr[$i])){
$component = $component_arr[$i];
if(!in_array($component,$excl_arr)){
if(!preg_match("/<\/$component>/", $content) && !$is_script){
$remove_comp = $elements_arr[$i];
$content = str_replace($remove_comp, '', $content);
}else if(in_array($component, $inc_elem_arr )){
for($rc=0;$rc<count($inc_elem_arr);$rc++){
$rcomp = $inc_elem_arr[$rc];
if(preg_match('/<script(\s|\sasync\s)custom-element="'.esc_attr($rcomp).'"(.*?)>(.*?)<\/script>/s', $content,$rmc)){
$content = str_replace($remove_comp, '', $content);
// REMOVING DUPLICATE SCRIPT.
$count_elem = array_count_values($component_arr)[$component];
$content = preg_replace('/<script(\s|\sasync\s)custom-element="'.esc_attr($component).'"(.*?)>(.*?)<\/script>/s','',$content,1,$component_arr[$i]);
$other_comp_arr = array('amp-mustache'=>'amp-mustache','amp-embed'=>'amp-ad','form'=>'amp-form','amp-access'=>'amp-access','amp-fx'=>'amp-fx-collection');
if (preg_match('/<amp-carousel(.*?)lightbox(.*?)>/', $content)) {
$other_comp_arr['amp-carousel'] = 'amp-lightbox-gallery';
foreach ($other_comp_arr as $key => $value) {
if($ocomp=='amp-mustache'){
if(preg_match('/(type|template|id)="('.$ocomp.')"/', $content) || preg_match("/<\/$key>/", $content) || preg_match("/amp-fx/", $content)){
if(!preg_match('/<script(\s|\sasync\s)custom-'.esc_attr($celem).'="'.esc_attr($ocomp).'"(.*?)>(.*?)<\/script>/s', $content)){
$o_comp_url = 'https://cdn.ampproject.org/v0/'.esc_attr($ocomp).'-'.esc_attr($script_ver).'.js';
$script_tag = '<head><script custom-'.esc_attr($celem).'="'.esc_attr($ocomp).'" src="'.esc_url($o_comp_url).'" async></script>';
$content = str_replace('<head>', $script_tag, $content);
$amp_video = $xpath->query("//amp-video");
foreach($amp_video as $node) {
if($node->hasAttribute('dock')){
if(ampforwp_get_setting('ampforwp-amp-video-docking') || ampforwp_get_setting('amp-theme-video-docking')){
$ocomp = 'amp-video-docking';
if(!preg_match('/<script(\s|\sasync\s)custom-'.esc_attr($celem).'="'.esc_attr($ocomp).'"(.*?)>(.*?)<\/script>/s', $content)){
$o_comp_url = 'https://cdn.ampproject.org/v0/'.esc_attr($ocomp).'-'.esc_attr($script_ver).'.js';
$script_tag = '<head><script custom-'.esc_attr($celem).'="'.esc_attr($ocomp).'" src="'.esc_url($o_comp_url).'" async></script>';
$content = str_replace('<head>', $script_tag, $content);
if(preg_match('/<amp-video(.*?) dock|dock=">/', $content)){
$content = preg_replace('/<amp-video(.*?) dock|dock=">/','<amp-video $1>', $content);
$amp_video_iframe = $xpath->query("//amp-video-iframe");
foreach($amp_video_iframe as $node) {
if($node->hasAttribute('dock')){
if(ampforwp_get_setting('ampforwp-amp-video-docking') || ampforwp_get_setting('amp-theme-video-docking')){
$ocomp = 'amp-video-docking';
if(!preg_match('/<script(\s|\sasync\s)custom-'.esc_attr($celem).'="'.esc_attr($ocomp).'"(.*?)>(.*?)<\/script>/s', $content)){
$o_comp_url = 'https://cdn.ampproject.org/v0/'.esc_attr($ocomp).'-'.esc_attr($script_ver).'.js';
$script_tag = '<head><script custom-'.esc_attr($celem).'="'.esc_attr($ocomp).'" src="'.esc_url($o_comp_url).'" async></script>';
$content = str_replace('<head>', $script_tag, $content);
if(preg_match('/<amp-video-iframe(.*?) (dock|dock=")>/', $content)){
$content = preg_replace('/<amp-video-iframe(.*?) (dock|dock=")>/','<amp-video-iframe $1>', $content);
$amp_youtube = $xpath->query("//amp-youtube");
foreach($amp_youtube as $node) {
if($node->hasAttribute('dock')){
if(ampforwp_get_setting('ampforwp-amp-video-docking') || ampforwp_get_setting('amp-theme-video-docking')){
$ocomp = 'amp-video-docking';
if(!preg_match('/<script(\s|\sasync\s)custom-'.esc_attr($celem).'="'.esc_attr($ocomp).'"(.*?)>(.*?)<\/script>/s', $content)){
$o_comp_url = 'https://cdn.ampproject.org/v0/'.esc_attr($ocomp).'-'.esc_attr($script_ver).'.js';
$script_tag = '<head><script custom-'.esc_attr($celem).'="'.esc_attr($ocomp).'" src="'.esc_url($o_comp_url).'" async></script>';
$content = str_replace('<head>', $script_tag, $content);
if(preg_match('/<amp-youtube(.*?) dock|dock=">/', $content)){
$content = preg_replace('/<amp-youtube(.*?) dock|dock=">/','<amp-youtube $1>', $content);
$amp_brid_player = $xpath->query("//amp-brid-player");
foreach($amp_brid_player as $node) {
if($node->hasAttribute('dock')){
if(ampforwp_get_setting('ampforwp-amp-video-docking') || ampforwp_get_setting('amp-theme-video-docking')){
$ocomp = 'amp-video-docking';
if(!preg_match('/<script(\s|\sasync\s)custom-'.esc_attr($celem).'="'.esc_attr($ocomp).'"(.*?)>(.*?)<\/script>/s', $content)){
$o_comp_url = 'https://cdn.ampproject.org/v0/'.esc_attr($ocomp).'-'.esc_attr($script_ver).'.js';
$script_tag = '<head><script custom-'.esc_attr($celem).'="'.esc_attr($ocomp).'" src="'.esc_url($o_comp_url).'" async></script>';
$content = str_replace('<head>', $script_tag, $content);
if(preg_match('/<amp-brid-player(.*?) dock|dock=">/', $content)){
$content = preg_replace('/<amp-brid-player(.*?) dock|dock=">/','<amp-brid-player $1>', $content);
$amp_brightcove = $xpath->query("//amp-brightcove");
foreach($amp_brightcove as $node) {
if($node->hasAttribute('dock')){
if(ampforwp_get_setting('ampforwp-amp-video-docking') || ampforwp_get_setting('amp-theme-video-docking')){
$ocomp = 'amp-video-docking';
if(!preg_match('/<script(\s|\sasync\s)custom-'.esc_attr($celem).'="'.esc_attr($ocomp).'"(.*?)>(.*?)<\/script>/s', $content)){
$o_comp_url = 'https://cdn.ampproject.org/v0/'.esc_attr($ocomp).'-'.esc_attr($script_ver).'.js';
$script_tag = '<head><script custom-'.esc_attr($celem).'="'.esc_attr($ocomp).'" src="'.esc_url($o_comp_url).'" async></script>';
$content = str_replace('<head>', $script_tag, $content);
if(preg_match('/<amp-brightcove(.*?) dock|dock=">/', $content)){
$content = preg_replace('/<amp-brightcove(.*?) dock|dock=">/','<amp-brightcove $1>', $content);
$allscripts = apply_filters( 'ampforwp_modify_scripts', $allscripts);
// Scripts added from Options panel should have higher priority #4064
if( $allscripts || (ampforwp_get_setting('amp-header-text-area-for-html') && ampforwp_get_setting('amp-header-text-area-for-html')!="")) {
$allscripts .= ampforwp_get_setting('amp-header-text-area-for-html');
preg_match_all('/<script(.*?)custom-element=\"(.*?)\"(.*?)src=\"(.*?)\"(.*?)>(.*?)<\/script>/s', $allscripts, $rep);
if(isset($rep[2]) && isset($rep[4])){
for($s=0;$s<count($script_slug);$s++){
$slug = $script_slug[$s];
if(preg_match('/amp/', $slug) && preg_match('/https/', $surl)){
if(preg_match('/<script(.*?)custom-element=\"'.esc_attr($slug).'\"(.*?)src=\"(.*?)\"(.*?)>(.*?)<\/script>/', $content, $conmatch)){
if(isset($conmatch[3]) && $conmatch[3]!=""){
if(preg_match('/https/', $rep_url)){
$content = str_replace($rep_url, $surl, $content);
if(!function_exists('ampforwp_get_retina_image_settings')){
function ampforwp_get_retina_image_settings($width,$height){
$data['width'] = intval($width);
$data['height'] = intval($height);
if ( 1 == ampforwp_get_setting('ampforwp-retina-images') ) {
if (ampforwp_get_setting('ampforwp-retina-images-res')) {
$resolution = ampforwp_get_setting('ampforwp-retina-images-res');
$width = $width * $resolution;
$height = $height * $resolution;
$data['width'] = intval($width);
$data['height'] = intval($height);
if(!function_exists('ampforwp_add_fallback_element')){
function ampforwp_add_fallback_element($content='',$tag=''){
preg_match_all('/<'.$tag.' (.*?)<\/'.$tag.'>/', $content, $matches);
if(!empty($matches) && false == ampforwp_get_setting('ampforwp-amp-convert-to-wp')){
for($i=0;$i<count($matches[0]);$i++){
$match = $matches[0][$i];
$m_content = $matches[1][$i];
$m_content = ampforwp_imagify_webp_compatibility($m_content);
$m_content = ampforwp_ewww_webp_compatibility($m_content);
$m_content = ampforwp_webp_express_compatibility($m_content);
$m_content = ampforwp_litespeed_webp_compatibility($m_content);
$m1_content = ampforwp_set_default_fallback_image($matches[1][$i]);
preg_match_all('/src="(.*?)"/', $m1_content,$fimgsrc);
preg_match_all('/width="(.*?)"/', $m1_content,$fimgwidth);
preg_match_all('/height="(.*?)"/', $m1_content,$fimgheight);
preg_match_all('/alt="(.*?)"/', $m1_content,$fimgalt);
if((isset($fimgsrc[1][0]) && preg_match_all('/http/', $fimgsrc[1][0],$fbi)) && isset($fimgwidth[1][0]) && isset($fimgheight[1][0])){
$data['src'] = $fimgsrc[1][0];
$data['width'] = $fimgwidth[1][0];
$data['height'] = $fimgheight[1][0];
if(isset($fimgalt[1][0])){
$data['alt'] = $fimgalt[1][0];
$fallback_data = apply_filters('ampforwp_fallback_image_params',$data);
$fsrc = $fallback_data['src'];
$fwidth = $fallback_data['width'];
$fheight= $fallback_data['height'];
$falt = $fallback_data['alt'];
$swidth = $fimgwidth[0][0];
$sheight = $fimgheight[0][0];
if(isset($fimgalt[0][0])){
$src_rep = 'src="'.esc_url($fsrc).'"';
$width_rep = 'width="'.intval($fwidth).'"';
$height_rep = 'height="'.intval($fheight).'"';
$alt_rep = 'alt="'.esc_attr($falt).'"';
$m1_content = str_replace($ssrc, $src_rep, $m1_content);
$m1_content = str_replace($swidth, $width_rep, $m1_content);
$m1_content = str_replace($sheight, $height_rep, $m1_content);
$m1_content = str_replace($salt, $alt_rep, $m1_content);
if(function_exists('rocket_activation')){
$m1_content = preg_replace('/srcset="(.*?)"/', '', $m1_content);
if(has_action('penci_loop_product_image')){
$fallback_img = "<amp-img data-hero ".$m_content."</amp-img>";
$fallback_img = "<amp-img data-hero ".$m_content."<amp-img fallback data-hero ".$m1_content."</amp-img></amp-img>";//$m_content, $m1_content escaped above.
$content = str_replace("$match", $fallback_img, $content);
// added fix for youtube video not displaying on AMP using Elementor #5322
add_filter('ampforwp_modify_the_content','amp_youtube_the_content');
function amp_youtube_the_content($content){
/* Check if youtube embed plugin is active
This is the solution for facade mode issue
if facade mode is enabled in embed youtube plugin then video was not working so this is the
if(is_plugin_active('youtube-embed-plus/youtube.php')){
$youtube_all_opts = get_option('youtubeprefs_alloptions');
if(!empty($youtube_all_opts) && isset($youtube_all_opts['facade_mode'])){
if($youtube_all_opts['facade_mode'] == 1){
preg_match_all('#<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\">(.*?)<\/figure>#is', $content, $video_matches);
if(!empty($video_matches) && is_array($video_matches)){
foreach ($video_matches as $vmkey => $vmvalue) {
foreach ($vmvalue as $vmkey1 => $vmvalue1) {
$dochtml = new DOMDocument();
$dochtml->loadHTML($vmvalue1);
$div_tags = $dochtml->getElementsByTagName('div');
foreach($div_tags as $div_tag) {
$facade_src = $div_tag->getAttribute('data-facadesrc');
$get_id = get_video_id_from_url($facade_src);
$content_html = '<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<amp-iframe width="800" height="450" src="'.$facade_src.'" class="__youtube_prefs__ epyt-is-override no-lazyload amp-wp-enforced-sizes" sandbox="allow-scripts allow-same-origin allow-popups allow-forms allow-top-navigation" sizes="(min-width: 800px) 800px, 100vw"><div placeholder="" class="amp-wp-iframe-placeholder"></div></amp-iframe>
$content = str_replace($vmvalue1, $content_html, $content);
} // div_tags foreach end
} // video_matches foreach end
} // video_matches if end
} // youtube_all_opts if end
} // is_plugin_active if end
// checking is Elementor is installed and activated
if ( did_action( 'elementor/loaded' ) ) {
preg_match_all('/<div\s+class="(.*?)elementor-widget-video"(.*?)data-settings=\'(.*?)\'\sdata-widget_type="video.default">/', $content, $matches);