: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
foreach($matches[3] as $video){
$video_attr = json_decode($video);
$get_url = $video_attr->youtube_url;
$get_id = get_video_id_from_url($get_url);
if(ampforwp_get_setting('ampforwp-amp-video-lightbox')==true)
$content_html=preg_replace('/<div\s+class="(.*?)elementor-widget-video"(.*?)data-settings=\'(.*?)\'\sdata-widget_type="video.default">/','<amp-lightbox id="open-video'.esc_attr($get_id).'" layout="nodisplay">
<div class="amp-lightbox-video" on="tap:open-video'.esc_attr($get_id).'.close,btn-play'.esc_attr($get_id).'.show" role="button" tabindex=0 aria-label="Close Video">
<a title="close" class="lb-x" href="#" on="tap:open-video'.esc_attr($get_id).'.close,btn-play'.esc_attr($get_id).'.show" role="button" tabindex=0></a>
<div class="amp-video-box"><amp-youtube data-videoid="'.esc_attr($get_id).'" layout="responsive" width="480" height="270"></amp-youtube></div></div></amp-lightbox>
<div class="amp-video-img" id="btn-play'.esc_attr($get_id).'" on="tap:video.show, video.play, btn-play'.esc_attr($get_id).'.hide,open-video'.esc_attr($get_id).'" role="button" aria-label="Play Video">
<amp-img alt="Video" src="http://i3.ytimg.com/vi/'.esc_attr($get_id).'/hqdefault.jpg" width="480" height="270" layout="responsive"></amp-img>
<div class="amp-video-play-on-image"></div>
$content_html = preg_replace('/<div\s+class="(.*?)elementor-widget-video"(.*?)data-settings=\'(.*?)\'\sdata-widget_type="video.default">/','<amp-youtube
data-videoid="'.esc_attr($get_id).'"
width="480" height="270"></amp-youtube>', $content);
function get_video_id_from_url( $url ) {
$short_url_host = 'youtu.be';
$parsed_url = parse_url( $url );
if(!isset($parsed_url['host'])){
$parsed_url['host'] = '';
if ($short_url_host === substr( $parsed_url['host'], -strlen($short_url_host ) ) ) {
$parts = explode( '/', $parsed_url['path'] );
if ( ! empty( $parts ) ) {
if(isset($parsed_url['query'])){
parse_str( $parsed_url['query'], $query_args );
if ( isset( $query_args['v'] ) ) {
if ( false !== strpos( $query_args['v'], '?' ) ) {
$video_id = strtok( $query_args['v'], '?' );
$video_id = $query_args['v'];
if ( empty( $video_id ) ) {
$parts = explode( '/', $parsed_url['path'] );
if ( in_array( $parts[1], array( 'v', 'e', 'embed' ) ) ) {
if(!function_exists('ampforwp_imagify_webp_compatibility')){
function ampforwp_imagify_webp_compatibility($content){
if(function_exists('_imagify_init')){
preg_match_all('/src="(.*?)"/', $content,$src);
$imageify_opt = get_option( 'imagify_settings' );
$convert_to_webp = false;
if(isset($imageify_opt['convert_to_webp'])){
$convert_to_webp = $imageify_opt['convert_to_webp'];
if(isset($imageify_opt['display_webp'])){
$display_webp = $imageify_opt['display_webp'];
if($convert_to_webp && $display_webp){
$img_url = esc_url($src[1][0]);
if(!preg_match('/\.webp/', $img_url)){
$rep_url = esc_url($src[1][0]).".webp";
if(preg_match('/http(.*)\/wp-content\/uploads/', $rep_url)){
$upload_dir = wp_upload_dir()['basedir'];
$img_file = preg_replace('/http(.*)\/wp-content\/uploads/', $upload_dir, $rep_url);
if(file_exists($img_file)){
$content = str_replace($img_url, $rep_url, $content);
$content = str_replace('.webp.webp','.webp',$content);
if(!function_exists('ampforwp_set_default_fallback_image')){
function ampforwp_set_default_fallback_image($content){
if(!function_exists('_imagify_init') && !function_exists('ewww_image_optimizer_webp_initialize') && !has_action('penci_loop_product_image')){
preg_match_all('/src="(.*?)"/', $content,$cc); // need to check extenstion for fallback.
$defaul_fallback_img = ampforwp_get_setting('ampforwp_default_fallback_image');
if(isset($defaul_fallback_img['url']) && $defaul_fallback_img['url']!=''){
$defaul_fallback_img = esc_url($defaul_fallback_img['url']);
$content = str_replace($img, $defaul_fallback_img, $content); // need to change fallback extenstion.
if(!function_exists('ampforwp_ewww_webp_compatibility')){
function ampforwp_ewww_webp_compatibility($content){
if(defined( 'EWWW_IO_CLOUD_PLUGIN' )){
preg_match_all('/src="(.*?)"/', $content,$src);
$img_url = esc_url($src[1][0]);
if(!preg_match('/\.webp/', $img_url)){
$rep_url = esc_url($src[1][0]).".webp";
if(preg_match('/http(.*)\/wp-content\/uploads/', $rep_url)){
$upload_dir = wp_upload_dir()['basedir'];
$img_file = preg_replace('/http(.*)\/wp-content\/uploads/', $upload_dir, $rep_url);
if(file_exists($img_file)){
$content = str_replace($img_url, $rep_url, $content);
$content = str_replace('.webp.webp','.webp',$content);
if(!function_exists('ampforwp_check_image_existance')){
function ampforwp_check_image_existance($image){
if(preg_match('/wp-content\/uploads/', $image)){
$img_arr = explode('wp-content', $image);
if(!empty($img_arr) && isset($img_arr[1])){
$img = WP_CONTENT_DIR.$img_arr[1];
if(preg_match('/\d+x\d+/', $image,$ma)){
$t_sizes = explode('x', $ma[0]);
$image = preg_replace('/-\d+x\d+/','', $image);
$resize = ampforwp_aq_resize( $image, $width , $height , true, false, true );
if (function_exists('themify_builder_activate')) {
add_filter('ampforwp_modify_the_content','ampforwp_themify_compatibility');
function ampforwp_themify_compatibility($content){
$get_data = get_post_meta(ampforwp_get_the_ID(),'_themify_builder_settings_json',true);
$decode = json_decode($get_data,true);
for($i=0;$i<count($decode);$i++){
if(isset($decode[$i]['cols'])){
$cols = $decode[$i]['cols'];
for($j=0;$j<count($cols);$j++){
if (isset($cols[$j]['modules'])) {
$modules = $cols[$j]['modules'];
for($k=0;$k<count($modules);$k++){
foreach ($modules as $key => $value) {
foreach ($value['mod_settings'] as $key => $val) {
add_action( 'wp_ajax_ampforwp_referesh_related_post', 'ampforwp_referesh_related_post' );
function ampforwp_referesh_related_post(){
if(!wp_verify_nonce($_POST['verify_nonce'],'ampforwp_refresh_related_poost') ){
echo wp_json_encode(array('status'=>403,'message'=>esc_html__('user request is not allowed','accelerated-mobile-pages'))) ;
'ignore_sticky_posts'=>1,
'has_password' => false ,
'post_status'=> 'publish',
'key' => 'ampforwp-amp-on-off',
'compare' => 'NOT EXISTS',
$my_query = new wp_query( $args );
while( $my_query->have_posts() ) {
update_post_meta(get_the_ID(),'ampforwp-amp-on-off','default');
'post_status' => 'publish',
'ignore_sticky_posts' => true,
'key' => 'ampforwp-ia-on-off',
'compare' => 'NOT EXISTS',
$my_query = new wp_query( $args );
while( $my_query->have_posts() ) {
update_post_meta(get_the_ID(),'ampforwp-ia-on-off','default');
$data['response'] = ampforwp_get_post_percent();
echo wp_json_encode($data);
// HIDE/SHOW TAG AND CATEGORY #4326
function ampforwp_save_taxonomy_meta($term_id){
if(isset($_POST['amp_taxonomy'])){
$cat_status = sanitize_text_field($_POST['amp_taxonomy']);
$hide_tax = sanitize_text_field($_POST['hide_tax']);
add_term_meta($term_id, 'amp_taxonomy', $cat_status );
add_term_meta( $term_id,'amp_hide_tax', $hide_tax);
function ampforwp_update_taxonomy_meta($term_id, $term_id1){
if(isset($_POST['amp_taxonomy'])){
$cat_status = sanitize_text_field($_POST['amp_taxonomy']);
$hide_tax = sanitize_text_field($_POST['hide_tax']);
update_term_meta( $term_id,'amp_taxonomy', $cat_status);
update_term_meta( $term_id,'amp_hide_tax', $hide_tax);
if ( isset( $_REQUEST['taxonomy'] )) {
$taxonomy = $_REQUEST['taxonomy'];
add_action('edited_'.esc_attr($taxonomy), 'ampforwp_update_taxonomy_meta',10,2);
add_action('create_'.esc_attr($taxonomy), 'ampforwp_save_taxonomy_meta', 10);
add_action('edited_'.esc_attr($taxonomy), 'ampforwp_update_taxonomy_meta',10,2);
add_action('create_'.esc_attr($taxonomy), 'ampforwp_save_taxonomy_meta', 10);
add_action (esc_attr($taxonomy).'_edit_form_fields', 'ampforwp_extra_category_fields');
add_action (esc_attr($taxonomy).'_add_form_fields', 'ampforwp_extra_category_fields');
function ampforwp_extra_category_fields( $tag ) {
if($tag->taxonomy=="post_tag"){
}else if($tag->taxonomy!='category'){
<?php if(!isset($tag->term_id)){?>
<th scope="row" valign="top"></th>
<div class="form-field term-parent-wrap">
<label for="show_amp_taxonomy">AMP</label>
<select name="amp_taxonomy" id="show_amp_taxonomy" class="postform">
<option class="level-0" value="show">Show</option>
<option class="level-0" value="hide">Hide</option>
<p>You can enable or disable AMP on this category. <a href="https://ampforwp.com/tutorials/article/how-to-show-hide-the-amp-from-the-categories-or-product-pages-or-any-custom-taxonomy-in-amp/" target="_blank">Learn More</a>.</p>
<div id="amp-show-hide-tax" class="mrtop-10" style="display: none">
<div class="hide-show-amp-tax">
<input type="radio" value="hide-cat" name="hide_tax" checked="">
<strong><?php echo esc_attr($label);?>:</strong>
Hide from <?php echo esc_attr($label);?> Archive Page.
<div class="mrtop-10 hide-show-amp-tax">
<input type="radio" value="hide-tax-post" name="hide_tax">
<strong><?php echo esc_attr($label);?> & Posts: </strong>
Hide from <?php echo esc_attr($label);?> Archive Page and all it's posts
$term_data = ampforwp_get_taxonomy_meta($tag->term_id);
if(isset($term_data['visible']) && !empty($term_data['visible'])){
$visible = $term_data['visible'][0];
$visible_status = $term_data['visible_status'][0];
<th scope="row"><label for="show_amp_taxonomy">AMP</label></th>
<select name="amp_taxonomy" id="show_amp_taxonomy" class="postform">
<option class="level-0" value="show" <?php if($visible=='show'){ echo "selected"; }?>>Show</option>
<option class="level-0" value="hide" <?php if($visible=='hide'){ echo "selected";} ?>>Hide</option>
<span class="description">You can enable or disable AMP on this category. <a href="https://ampforwp.com/tutorials/article/how-to-show-hide-the-amp-from-the-categories-or-product-pages-or-any-custom-taxonomy-in-amp/" target="_blank">Learn More</a>.</span>
<div id="amp-show-hide-tax" <?php if($visible=='show' || $visible==''){?>style="display: none;"<?php }?> class="edit_hide_tax mrtop-10">
<div class="hide-show-amp-tax">
<input type="radio" value="hide-cat" name="hide_tax" <?php if($visible_status=='hide-cat' || $visible_status==''){?> checked <?php }?>>
<strong><?php echo esc_attr($label);?>:</strong>
Hide from <?php echo esc_attr($label);?> Archive Page.
<div class="mrtop-10 hide-show-amp-tax">
<input type="radio" value="hide-tax-post" name="hide_tax" <?php if($visible_status=='hide-tax-post'){?> checked <?php }?>>
<strong><?php echo esc_attr($label);?> & Posts: </strong>
Hide from <?php echo esc_attr($label);?> Archive Page and all it's posts
//4710 Added support to load featured image for lazy load option of Dues theme.
if(function_exists('wpg_lazyload_image_attributes')){
add_action('wp','ampforwp_dues_theme_load_featured_image');
function ampforwp_dues_theme_load_featured_image(){
if(ampforwp_is_amp_endpoint()){
remove_filter( 'wp_get_attachment_image_attributes', 'wpg_lazyload_image_attributes', 8, 3 );
if(function_exists('rocket_activation')){
add_filter("ampforwp_the_content_last_filter",'ampforwp_wp_rocket_compatibility',25);
function ampforwp_wp_rocket_compatibility($content){
$cdn_url = get_option('wp_rocket_settings');
if($cdn_url['cdn'] == 1){
if(!empty($cdn_url['cdn_zone']) && !empty($cdn_url['cdn_cnames'])){
foreach ($cdn_url['cdn_zone'] as $key => $element) {
if(isset($cdn_url['cdn_cnames'][$key]) && $cdn_url['cdn_cnames'][$key]!=''){
$cnds_arr[$element] = $cdn_url['cdn_cnames'][$key];
if(isset($cnds_arr['images'])){
$img_cdn_url = $cnds_arr['images'];
$img_cdn_url = apply_filters( 'ampforwp_modify_wp_rocket_cdn_url', $img_cdn_url );
}else if(isset($cnds_arr['all'])){
$img_cdn_url = $cnds_arr['all'];
$parse_url = parse_url($img_cdn_url);
if(!isset($parse_url['scheme'])){
if(!preg_match('/\/\//', $img_cdn_url)){
$img_cdn_url = '//'.$img_cdn_url;
$comp_dom = new DOMDocument();
@$comp_dom->loadHTML($content);
$xpath = new DOMXPath( $comp_dom );
$nodes = $xpath->query('//amp-img[@src]');
foreach ($nodes as $node) {
$url = $node->getAttribute('src');
$srcset = $node->getAttribute('srcset');
$is_external = ampforwp_isexternal($url);
if(!$is_external && !$node->hasAttribute('fallback')){
$img_src = str_replace($home_url, $img_cdn_url, $url);
$content = str_replace($url, $img_src, $content);
$srcset_arr = explode(",", $srcset);
for($i=0;$i<count($srcset_arr);$i++){
$original = $srcset_arr[$i];
$new = str_replace($home_url, $img_cdn_url, $original);
if(preg_match('/'.preg_quote($original,'/').'/', $content)){
$content = preg_replace('/'.preg_quote($original,'/').'/', $new, $content);
// Adding Mobile theme color meta data in header
if(true == ampforwp_get_setting('mobile-theme-color')){
add_action( 'amp_post_template_head', 'ampforwp_mobile_theme_color');
function ampforwp_mobile_theme_color(){
$content_code = ampforwp_get_setting('mobile-theme-color-picker','color');
if(empty($content_code)){
$content_code = '#ffffff';
<meta name="theme-color" content="<?php echo ampforwp_sanitize_color($content_code); ?>"/>
if(function_exists('herald_theme_setup')){
add_filter('the_content', 'ampforwp_herald_popup_media_in_content', 100, 1 );
add_filter('bbp_get_topic_content','herald_popup_media_in_content');
add_filter('bbp_get_reply_content','herald_popup_media_in_content');
function ampforwp_herald_popup_media_in_content( $content ) {
if(ampforwp_is_amp_endpoint()){
if (function_exists('herald_get_option') && herald_get_option( 'on_single_img_popup' ) ) {
if(preg_match("/<a class=\"herald-popup-img\" href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")><img(.*?)<\/a>/i", $content,$matches)){
$content = preg_replace( "/<a class=\"herald-popup-img\" href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")><img(.*?)<\/a>/i", '<img on="tap:amp-img-lightbox" role="button" tabindex="0" $5', $content );
// Added TravelTour theme page builder content support.#4540
function ampforwp_gdlr_core_page_builder_content($content){
do_action('gdlr_core_print_page_builder');
$content_gdlr = ob_get_contents();
$content = $content . $content_gdlr ;
add_filter('wpseo_robots', 'ampforwp_yoast_home_robots');
function ampforwp_yoast_home_robots($string) {
if (ampforwp_is_home() || ampforwp_is_front_page() && method_exists('WPSEO_Meta', 'get_value') && '1' == WPSEO_Meta::get_value( 'meta-robots-noindex', get_option( 'page_for_posts' )) && '0' == WPSEO_Meta::get_value( 'meta-robots-noindex', ampforwp_get_the_ID())) {
if( function_exists('fifu_activate') && !function_exists( 'fifu_amp_url' ) ) {
function fifu_amp_url($url, $width, $height) {
$size = get_post_meta(ampforwp_get_the_ID(), 'fifu_image_dimension');
$size = explode(';', $size[0]);
return array(0 => $url, 1 => $width, 2 => $height);
add_filter('ampforwp_post_template_data','ampforwp_amp_bind_script');
function ampforwp_amp_bind_script($data) {
if ( empty( $data['amp_component_scripts']['amp-bind'] ) ) {
$data['amp_component_scripts']['amp-bind'] = 'https://cdn.ampproject.org/v0/amp-bind-latest.js';
add_filter('ampforwp_post_template_data','ampforwp_amp_story_player_script',12);
function ampforwp_amp_story_player_script($data) {
if ( isset($data['post'])) {
$post_content = $data['post']->post_content;
if ( (preg_match('/<amp-story-player(.*?)<\/amp-story-player>/s', $post_content) || preg_match('/web-stories/', $post_content )) && empty( $data['amp_component_scripts']['amp-story-player'] ) ) {
$data['amp_component_scripts']['amp-story-player'] = 'https://cdn.ampproject.org/v0/amp-story-player-latest.js';
if(!function_exists('ampforwp_video_lightbox')){
function ampforwp_video_lightbox($content){
$video_tags_arr = array('amp-youtube');
add_action('amp_post_template_css','ampforwp_video_lightbox_css',30);
for($i=0;$i<count($video_tags_arr);$i++){
$tag = $video_tags_arr[$i];
preg_match_all('/<'.$tag.' (.*?)<\/'.$tag.'>/', $content, $matches);
for($i=0;$i<count($matches[0]);$i++){
$match = $matches[0][$i];
$dom = AMP_DOM_Utils::get_dom_from_content($match);
$nodes = $dom->getElementsByTagName( 'amp-youtube' );