: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
add_filter( 'amp_post_template_data', 'ampforwp_global_head_scripts');
function ampforwp_global_head_scripts($data){
$content = $data['post_amp_content'];
if( 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>/', $allscripts, $matches);
$script_slug = $matches[2];
$script_url = $matches[4];
foreach ($script_slug as $key => $slug) {
if(preg_match('/<\/'.$slug.'>/', $content)){
if ( empty( $data['amp_component_scripts'][$slug] ) ) {
$data['amp_component_scripts'][$slug] = $script_url[$key];
add_action('amp_post_template_head','ampforwp_header_html_output',11);
function ampforwp_header_html_output() {
if( ampforwp_get_setting('ampforwp-seo-custom-additional-meta') ){
echo strip_tags( ampforwp_get_setting('ampforwp-seo-custom-additional-meta'), '<link><meta>' );
if( ampforwp_get_setting('amp-header-text-area-for-html') ) {
$allhtml = ampforwp_get_setting('amp-header-text-area-for-html');
$allhtml = preg_replace('/<script(.*?)custom-element=\"(.*?)\"(.*?)src=\"(.*?)\"(.*?)><\/script>/','', $allhtml);
if(function_exists('ampforwp_mobile_redirect_preseve_link')){
$mob_pres_link = ampforwp_mobile_redirect_preseve_link();
add_filter('amp_post_template_data','ampforwp_set_body_content_script', 20);
function ampforwp_set_body_content_script($data){
if( ampforwp_get_setting('amp-body-text-area') || ampforwp_get_setting('amp-footer-text-area-for-html') ) {
$head_content = ampforwp_get_setting('amp-header-text-area-for-html');
preg_match_all('/"amp-(.*?)"/', $head_content, $matches1);
$body_content = ampforwp_get_setting('amp-body-text-area');
preg_match_all('/<\/amp-(.*?)>/', $body_content, $matches);
if(ampforwp_get_setting('amp-footer-text-area-for-html') ) {
$footer_content = ampforwp_get_setting('amp-footer-text-area-for-html');
preg_match_all('/<\/amp-(.*?)>/', $footer_content, $matches);
if(isset($matches[1][0])){
for($i=0;$i<count($amp_comp);$i++){
if($comp == 'auto-ads' || $comp == 'ad'){
$component_url = "https://cdn.ampproject.org/v0/amp-".esc_attr($comp)."-".esc_attr($script_ver).".js";
if(isset($matches[1][0])){
if(!in_array($comp, $thtml)){
$data['amp_component_scripts']["amp-".esc_attr($comp)] = esc_url($component_url);
$data['amp_component_scripts']["amp-".esc_attr($comp)] = esc_url($component_url);
$data['amp_component_scripts']["amp-".esc_attr($comp)] = esc_url($component_url);
add_action('amp_post_template_head' , 'ampforwp_talking_to_robots');
function ampforwp_talking_to_robots() {
global $redux_builder_amp;
//author archives index/noindex
if( is_author() && !$redux_builder_amp['ampforwp-robots-archive-author-pages'] ) {
//date archives index/noindex
if( is_date() && !$redux_builder_amp['ampforwp-robots-archive-date-pages'] ) {
//Search pages noindexing by default
//categorys index/noindex
if( is_category() && !$redux_builder_amp['ampforwp-robots-archive-category-pages'] ) {
//categorys index/noindex
if( is_tag() && !$redux_builder_amp['ampforwp-robots-archive-tag-pages'] ) {
if( is_archive() || is_home() ) {
if ( get_query_var( 'paged' ) ) {
$paged = get_query_var('paged');
} elseif ( get_query_var( 'page' ) ) {
$paged = get_query_var('page');
//sitewide archives sub pages index/noindex ie page 2 onwards
if( $paged >= 2 && !$redux_builder_amp['ampforwp-robots-archive-sub-pages-sitewide'] ) {
$query_array = $wp->query_vars;
if( array_key_exists( 'page' , $query_array ) ) {
$page = $wp->query_vars['page'];
if ( $redux_builder_amp['amp-frontpage-select-option'] && $page >= '2') {
$meta_content = "noindex,noarchive";
if ( function_exists('genesis_get_robots_meta_content') && 'genesis' == ampforwp_get_setting('ampforwp-seo-selection') ) {
$meta_content = genesis_get_robots_meta_content();
if ( class_exists('All_in_One_SEO_Pack') ) {
$aios_class = $page = $opts = $aios_meta = $aiosp_noindex = $aiosp_nofollow = '';
$aios_class = new All_in_One_SEO_Pack();
if (is_object($aios_class) && property_exists($aios_class,'get_page_number')) {
$page = $aios_class->get_page_number();
if (is_object($aios_class) && property_exists($aios_class,'get_current_options')) {
$opts = $aios_class->get_current_options( array(), 'aiosp' );
if (is_object($aios_class) && property_exists($aios_class,'get_robots_meta')) {
$aios_meta = $aios_class->get_robots_meta();
if ( ( is_category() && ! empty( $aioseop_options['aiosp_category_noindex'] ) ) || ( ! is_category() && is_archive() && ! is_tag() && ! is_tax() || ( is_tag() && ! empty( $aioseop_options['aiosp_tags_noindex'] ) ) || ( is_search() && ! empty( $aioseop_options['aiosp_search_noindex'] ) )
} elseif ( is_single() || is_page() || $aios_class->is_static_posts_page() || is_attachment() || is_category() || is_tag() || is_tax() || ( $page > 1 ) ) {
$post_type = get_post_type();
if ( ! empty( $opts ) ) {
$aiosp_noindex = htmlspecialchars( stripslashes( $opts['aiosp_noindex'] ) );
$aiosp_nofollow = htmlspecialchars( stripslashes( $opts['aiosp_nofollow'] ) );
if ( $aiosp_noindex || $aiosp_nofollow || ! empty( $aioseop_options['aiosp_cpostnoindex'] )
|| ! empty( $aioseop_options['aiosp_cpostnofollow'] ) || ! empty( $aioseop_options['aiosp_paginated_noindex'] ) || ! empty( $aioseop_options['aiosp_paginated_nofollow'] )
if ( ( $aiosp_noindex == 'on' ) || ( ( ! empty( $aioseop_options['aiosp_paginated_noindex'] ) ) && $page > 1 ) ||
( ( $aiosp_noindex == '' ) && ( ! empty( $aioseop_options['aiosp_cpostnoindex'] ) ) && in_array( $post_type, $aioseop_options['aiosp_cpostnoindex'] ) )
if ( ( $aiosp_nofollow == 'on' ) || ( ( ! empty( $aioseop_options['aiosp_paginated_nofollow'] ) ) && $page > 1 ) ||
( ( $aiosp_nofollow == '' ) && ( ! empty( $aioseop_options['aiosp_cpostnofollow'] ) ) && in_array( $post_type, $aioseop_options['aiosp_cpostnofollow'] ) )
if ( is_singular() && is_object($aios_class) && property_exists($aios_class,'is_password_protected') && $aios_class->is_password_protected() && apply_filters( 'aiosp_noindex_password_posts', false ) ) {
$robots_meta = $noindex . ',' . $nofollow;
if ( $robots_meta == 'index,follow' ) {
if ( !empty($robots_meta) ) {
$meta_content = $robots_meta;
// Meta Robots Tag From Yoast #1563
if ( class_exists('WPSEO_Frontend') && 'yoast' == ampforwp_get_setting('ampforwp-seo-selection') && is_singular() && !class_exists('Yoast\\WP\\SEO\\Integrations\\Front_End_Integration')) {
$class_instance = WPSEO_Frontend::get_instance();
// robots() will return and print the meta robots tag
$class_instance->robots();
// Empty the above meta content to avoid duplicate meta robot tags
$meta_content = apply_filters('ampforwp_robots_meta', $meta_content);
if ( isset($redux_builder_amp['amp-inspection-tool']) && true == $redux_builder_amp['amp-inspection-tool'] ) {
$talk_to_robots = $meta_content = '';
if ( ( is_archive() && $talk_to_robots ) || is_singular() || is_home() ) {
echo '<meta name="robots" content="' . esc_attr($meta_content) . '"/>';
// 41. Rewrite URL only on save #511
function ampforwp_auto_flush_on_save($redux_builder_amp) {
if ( $redux_builder_amp['amp-on-off-for-all-pages'] == 1 || $redux_builder_amp['ampforwp-archive-support'] == 1 || $redux_builder_amp['fb-instant-article-switch'] == 1 ) {
$wp_rewrite->flush_rules();
$options = $new_options = array();
if ( is_array(ampforwp_get_setting('hide-amp-categories')) && !is_array(ampforwp_get_setting('hide-amp-categories2'))) {
$options = array_keys(array_filter($redux_builder_amp['hide-amp-categories'] ) );
foreach ($options as $option ) {
$new_options[] = $option;
$redux_builder_amp['hide-amp-categories2'] = $new_options;
$redux_builder_amp['hide-amp-categories'] = '';
update_option('redux_builder_amp',$redux_builder_amp);
add_action("redux/options/redux_builder_amp/saved",'ampforwp_auto_flush_on_save', 10, 1);
// 42. registeing AMP sidebars
add_action('init', 'ampforwp_add_widget_support');
function ampforwp_add_widget_support() {
if (function_exists('register_sidebar')) {
global $redux_builder_amp;
'name' => 'AMP Above Loop [HomePage]',
'id' => 'ampforwp-above-loop',
'description' => 'This Widget will be display on AMP HomePage Above the loop ',
'before_title' => '<h4>',
'name' => 'AMP Below Loop [HomePage]',
'id' => 'ampforwp-below-loop',
'description' => 'This Widget will be display on AMP HomePage Below the loop',
'before_title' => '<h4>',
'name' => 'AMP Below the Header [Site Wide]',
'id' => 'ampforwp-below-header',
'description' => 'This Widget will be display after the header bar',
'before_title' => '<h4><span>',
'after_title' => '</h4></span>'
'name' => 'AMP Above the Footer [Site Wide]',
'id' => 'ampforwp-above-footer',
'description' => 'This Widget display Above the Footer',
'before_title' => '<h4><span>',
'after_title' => '</h4></span>'
if ( function_exists('ampforwp_custom_theme_files_register') ) {
$desc = "<b>Update: <a target='_blank' href='https://ampforwp.com/tutorials/article/amp-page-builder-installation/'>Introducing PageBuilder 2.0</a></b><br />Drag and Drop the AMP Modules in this Widget Area and then assign this widget area to a page <a href=http://ampforwp.com/tutorials/page-builder>(Need Help?)</a>";
$placeholder = 'PLACEHOLDER';
'name' => 'Page Builder (AMP) [Legacy]',
'id' => 'layout-builder',
'description' => $placeholder,
'before_title' => '<h4>',
add_action( 'widgets_admin_page', function() use ( $desc, $placeholder ) {
add_filter( 'esc_html', function( $safe_text, $text ) use ( $desc, $placeholder ) {
if ( $text !== $placeholder )
remove_filter( current_filter(), __FUNCTION__ );
// 43. custom actions for widgets output
add_action( 'ampforwp_home_above_loop' , 'ampforwp_output_widget_content_above_loop' );
add_action( 'ampforwp_frontpage_above_loop' , 'ampforwp_output_widget_content_above_loop' );
function ampforwp_output_widget_content_above_loop() {
$sanitized_sidebar = ampforwp_sidebar_content_sanitizer('ampforwp-above-loop');
if ( $sanitized_sidebar) {
$sidebar_output = $sanitized_sidebar->get_amp_content();
$sidebar_output = apply_filters('ampforwp_modify_sidebars_content',do_shortcode($sidebar_output));
if ( $sidebar_output ) { ?>
<div class="amp-wp-content widget-wrapper amp_widget_above_loop">
<?php echo do_shortcode($sidebar_output); ?>
add_action( 'ampforwp_home_below_loop' , 'ampforwp_output_widget_content_below_loop' );
add_action( 'ampforwp_frontpage_below_loop' , 'ampforwp_output_widget_content_below_loop' );
function ampforwp_output_widget_content_below_loop() {
$sanitized_sidebar = ampforwp_sidebar_content_sanitizer('ampforwp-below-loop');
if ( $sanitized_sidebar) {
$sidebar_output = $sanitized_sidebar->get_amp_content();
$sidebar_output = apply_filters('ampforwp_modify_sidebars_content',do_shortcode($sidebar_output));
if ( $sidebar_output ) { ?>
<div class="amp-wp-content widget-wrapper">
<div class="amp_widget_below_loop f-w">
<?php echo do_shortcode($sidebar_output); ?>
add_action( 'ampforwp_after_header' , 'ampforwp_output_widget_content_below_the_header' );
add_action('below_the_header_design_1','ampforwp_output_widget_content_below_the_header');
function ampforwp_output_widget_content_below_the_header() {
$sanitized_sidebar = ampforwp_sidebar_content_sanitizer('ampforwp-below-header');
if ( $sanitized_sidebar) {
$sidebar_output = $sanitized_sidebar->get_amp_content();
$sidebar_output = apply_filters('ampforwp_modify_sidebars_content',do_shortcode($sidebar_output));
if ( $sidebar_output ) { ?>
<div class="amp-wp-content widget-wrapper">
<div class="amp_widget_below_the_header f-w">
<?php echo do_shortcode($sidebar_output); ?>
add_action( 'amp_post_template_above_footer' , 'ampforwp_output_widget_content_above_the_footer' );
function ampforwp_output_widget_content_above_the_footer() {
$sanitized_sidebar = ampforwp_sidebar_content_sanitizer('ampforwp-above-footer');
if ( $sanitized_sidebar) {
$sidebar_output = $sanitized_sidebar->get_amp_content();
$sidebar_output = apply_filters('ampforwp_modify_sidebars_content',do_shortcode($sidebar_output));
if ( $sidebar_output ) { ?>
<div class="amp-wp-content widget-wrapper">
<div class="amp_widget_above_the_footer f-w">
<?php echo do_shortcode($sidebar_output); ?>
// Filter the sidebars content to make it work properly with carousels
add_filter('ampforwp_modify_sidebars_content','ampforwp_sidebars_carousel_content');
function ampforwp_sidebars_carousel_content($content){
$content = str_replace(array(':openbrack:',':closebrack:'), array('[',']'), $content);
// Sidebar Content Sanitizer
function ampforwp_sidebar_content_sanitizer($sidebar){
global $redux_builder_amp;
$non_sanitized_sidebar = "";
$blacklist_array = array();
// Remove some blacklist tags from sidebars only when search,archives and categories widgets are active #2835
if ( is_active_widget(false,false,'search') || is_active_widget(false,false,'archives') || is_active_widget(false,false,'categories') ) {
$blacklist_array['non-content'] = 'non-content';
dynamic_sidebar( $sidebar );
$non_sanitized_sidebar = ob_get_contents();
if ( $non_sanitized_sidebar ) {
$sanitized_sidebar = new AMPforWP_Content( $non_sanitized_sidebar,
apply_filters( 'amp_content_embed_handlers', array(
'AMP_Reddit_Embed_Handler' => 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' => $blacklist_array,
'AMP_Img_Sanitizer' => array(),
'AMP_Video_Sanitizer' => array(),
'AMP_Audio_Sanitizer' => array(),
'AMP_Playbuzz_Sanitizer' => array(),
'AMP_Iframe_Sanitizer' => array(
'add_placeholder' => true,
'AMP_Tag_And_Attribute_Sanitizer' => array(),
) ), array('non-content'=>'non-content')
if ( is_active_widget(false,false,'search') && $sanitized_sidebar) {
// Allow some blacklisted tags #1400
add_filter('ampforwp_modify_sidebars_content','ampforwp_modified_search_sidebar');
return $sanitized_sidebar;
function ampforwp_modified_search_sidebar( $content ) {
global $redux_builder_amp;
if(function_exists('ampforwp_mobile_redirect_preseve_link')){
$mob_pres_link = ampforwp_mobile_redirect_preseve_link();
if(function_exists('ampforwp_mobile_redirect_preseve_link')){
$mob_pres_link = ampforwp_mobile_redirect_preseve_link();
$dom = AMP_DOM_Utils::get_dom_from_content($content);
$nodes = $dom->getElementsByTagName( 'form' );
$num_nodes = $nodes->length;
if ( 0 !== $num_nodes ) {
for ( $i = 0; $i < $nodes->length; ++$i ) {
$element = $nodes->item( $i );
if (ampforwp_get_setting('ampforwp-amp-takeover') == false && $mob_pres_link == false ) {
$amp_query_variable = 'amp';
$amp_query_variable_val = '1';
if ( ! $element->hasAttribute('action-xhr') ){
$action_url = $element->getAttribute('action');
$action_url = preg_replace('#^http?:#', '', $action_url);
$element->setAttribute('action', $action_url);
$element->setAttribute('target', '_top');
$input_nodes = $element->getElementsByTagName('input');
if ( 0 !== $input_nodes->length ) {
for ( $i = 0; $i < $input_nodes->length; ++$i ) {
$input_node = $input_nodes->item( $i );
if ( 'submit' !== $input_node->getAttribute('type') ) {
$input_submit = $dom->createElement('input');
$input_submit->setAttribute('type', 'submit');
$input_submit->setAttribute('class', 'search-submit');
$element->appendChild($input_submit);
// Remove http/https from Audio and Video URLs #1400
$video_nodes = $dom->getElementsByTagName( 'amp-video' );
$num_nodes = $video_nodes->length;
if ( 0 !== $num_nodes ) {
for ( $i = 0; $i < $video_nodes->length; ++$i ) {