: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if ( ! defined( 'ABSPATH' ) ) {
if(ampforwp_get_setting('amp-gdpr-compliance-switch')) {
add_amp_theme_support('AMP-gdpr');
require AMPFORWP_PLUGIN_DIR .'templates/custom-amp-content.php';
// Custom AMPFORWP Sanitizers
require AMPFORWP_PLUGIN_DIR .'templates/custom-sanitizer.php';
// Load aq resizer only in AMP mode
add_action('pre_amp_render_post','ampforwp_include_aqresizer');
function ampforwp_include_aqresizer(){
//Removed Jetpack Mobile theme option #2584
remove_action('option_stylesheet', 'jetpack_mobile_stylesheet');
require AMPFORWP_PLUGIN_DIR .'includes/vendor/aq_resizer.php';
if( ampforwp_get_setting('ampforwp_css_tree_shaking') ){
add_filter('ampforwp_the_content_last_filter','ampforwp_tree_shaking_purify_amphtml',11);
// Some Extra Styling for Admin area
add_action( 'admin_enqueue_scripts', 'ampforwp_add_admin_styling_amp' );
function ampforwp_add_admin_styling_amp($hook_suffix){
global $pagenow,$redux_builder_amp;
if ('plugins.php' == $pagenow) {
add_action('admin_notices', 'ampforwp_tpd_notice' );
if($hook_suffix!='toplevel_page_amp_options' ){
$redux_data['frontpage']='';
if( current_user_can("manage_options") && $pagenow == 'options-reading.php' && 0 == $redux_builder_amp['amp-frontpage-select-option']) {
$redux_data['frontpage'] = 'false';
$redux_data['admin_url'] = esc_url(admin_url("admin.php?page=amp_options&tabid=opt-text-subsection#redux_builder_amp-ampforwp-homepage-on-off-support"));
$redux_data['ampforwp-amp-takeover'] = ampforwp_get_setting('ampforwp-amp-takeover');
wp_register_style( 'ampforwp_admin_css', untrailingslashit(AMPFORWP_PLUGIN_DIR_URI) . '/includes/admin-style-global.css', false, AMPFORWP_VERSION );
wp_enqueue_style( 'ampforwp_admin_css' );
wp_register_script( 'ampforwp_admin_js', untrailingslashit(AMPFORWP_PLUGIN_DIR_URI) . '/includes/admin-script-global.js', array('wp-color-picker'), AMPFORWP_VERSION );
wp_localize_script( 'ampforwp_admin_js', 'ampforwp_nonce',
'security' => wp_create_nonce( 'ampforwp-verify-request' )
$redux_data = apply_filters("ampforwp_custom_localize_data", $redux_data);
wp_localize_script( 'ampforwp_admin_js', 'redux_data', $redux_data );
wp_enqueue_script( 'wp-color-picker' );
wp_enqueue_script( 'ampforwp_admin_js' );
add_action( 'redux/page/redux_builder_amp/enqueue', 'ampforwp_add_admin_styling' );
function ampforwp_add_admin_styling($hook_suffix){
global $redux_builder_amp, $amp_ux_fields;
// Style file to add or modify css inside admin area
wp_register_style( 'ampforwp_admin_css', untrailingslashit(AMPFORWP_PLUGIN_DIR_URI) . '/includes/admin-style.css', false, AMPFORWP_VERSION );
wp_enqueue_style( 'ampforwp_admin_css' );
// Admin area scripts file
$dep = array('wp-color-picker');
$dep = apply_filters('ampforwp_modify_script_dependency', $dep);
wp_register_script( 'ampforwp_admin_js', untrailingslashit(AMPFORWP_PLUGIN_DIR_URI) . '/includes/admin-script.js', $dep , AMPFORWP_VERSION );
// Localize the script with new data
// if ('plugins.php' == $pagenow) {
// add_action('admin_notices', 'ampforwp_tpd_notice' );
if( current_user_can("manage_options")){
$redux_data = $redux_builder_amp;
wp_dequeue_script( 'insert-post-adschart-admin' );
if(function_exists('brokers_page_template_redirect')){
wp_dequeue_script( 'broker-js' );
wp_dequeue_script( 'broker-min-js' );
if(function_exists('html5blank_header_scripts')){
wp_dequeue_script( 'jquery-js' );
if(function_exists('megashop_setup')){
wp_dequeue_script( 'adminjs' );
remove_all_actions('admin_notices');
remove_all_actions('all_admin_notices');
if(class_exists('WC_Ecpay_Apple_Pay')){
remove_all_actions('admin_footer');
if (function_exists('wps_pf_pr_filter_register')) {
wp_dequeue_script('wpspf-main-js-3');
if (function_exists('aeccglobal_setup')) {
remove_action( 'admin_footer', 'js_update_show_in_slider' );
if (function_exists('appsero_init_tracker_tour_booking_manager')) {
add_action( 'wp_print_scripts', 'ampforwp_dequeue_tour_booking_script', 100 );
add_action('admin_notices', 'ampforwp_dev_mode_notice');
add_action('admin_notices', 'ampforwp_plugins_manager_notice');
add_action('admin_notices', 'ampforwp_ampwptheme_notice');
add_action('admin_notices', 'ampforwp_automattic_activation' );
add_action('admin_notices', 'ampforwp_admin_notices' );
add_action('admin_notices', 'ampforwp_seo_selection_notice' );
add_action('admin_notices', 'ampforwp_mobile_redirection_notice' );
add_action('admin_notices', 'ampforwp_category_base_remove_notice' );
add_action('admin_notices', 'ampforwp_internal_feedback_notice' );
add_action('admin_notices', 'ampforwp_tpd_notice' );
if ( defined('AMPFORWPPRO_PLUGIN_DIR') ) {
$license_info = get_option( 'ampforwppro_license_info');
add_action('admin_notices', 'ampforwp_pro_extension_manager_notice' );
'ampforwp-ux-website-type-section',
'ampforwp-ux-need-type-section',
'ampforwp-ux-analytics-section'
for($sid = 0; $sid < count($setup_ids); $sid++ ){
$check = ampforwp_get_setup_info($setup_ids[$sid]);
add_action('admin_notices', 'ampforwp_incomplate_setup_notice' );
$redux_data['ampforwp-amp-takeover'] = ampforwp_get_setting('ampforwp-amp-takeover');
if( current_user_can("manage_options") && $hook_suffix == 'options-reading.php' && 0 == $redux_builder_amp['amp-frontpage-select-option']) {
$redux_data['frontpage'] = 'false';
$redux_data['admin_url'] = esc_url(admin_url("admin.php?page=amp_options&tabid=opt-text-subsection#redux_builder_amp-ampforwp-homepage-on-off-support"));
$amp_fields = wp_json_encode($amp_ux_fields, true);
$screen = get_current_screen();
if ( 'toplevel_page_amp_options' == $screen->base ) {
$opt = get_option("ampforwp_option_panel_view_type");
wp_localize_script( 'ampforwp_admin_js', 'amp_option_panel_view', array($opt));
$opt = get_option("ampforwp_option_panel_view_type");
wp_localize_script( 'ampforwp_admin_js', 'amp_option_panel_view', array($opt));
wp_localize_script( 'ampforwp_admin_js', 'amp_fields', array($amp_fields));
$redux_data = apply_filters("ampforwp_custom_localize_data", $redux_data);
wp_localize_script( 'ampforwp_admin_js', 'redux_data', $redux_data );
wp_localize_script( 'ampforwp_admin_js', 'ampforwp_nonce',
'security' => wp_create_nonce( 'ampforwp-verify-request' )
wp_enqueue_script( 'wp-color-picker' );
wp_enqueue_script( 'ampforwp_admin_js' );
function ampforwp_dequeue_tour_booking_script() {
wp_dequeue_script( 'ttbm_mp_script' );
// 96. ampforwp_is_front_page() ampforwp_is_home() and ampforwp_is_blog is created
function ampforwp_is_front_page(){
global $redux_builder_amp;
// Reading settings me frontpage set
$get_front_page_reading_settings = get_option('page_on_front');
$get_amp_homepage_settings = ampforwp_get_setting('ampforwp-homepage-on-off-support');
// AMP Custom front page from AMP panel
$get_custom_frontpage_settings = ampforwp_get_setting('amp-frontpage-select-option');
// Frontpage id should be assigned
if ( ampforwp_get_setting('amp-frontpage-select-option-pages') ) {
$get_amp_custom_frontpage_id = $redux_builder_amp['amp-frontpage-select-option-pages'];
// Passing Frontpage id true for polylang static pages
if ( (class_exists('polylang') || class_exists('Polylang_Pro')) && function_exists('poly_archive_url') ) {
if( !ampforwp_get_setting('amp-frontpage-select-option-pages') && $get_custom_frontpage_settings && 'page' === get_option( 'show_on_front' )){
$get_amp_custom_frontpage_id = true;
// TRUE: When we have "Your latest posts" in reading settings and custom frontpage in amp
if ( 'posts' == get_option( 'show_on_front') && is_home() && $get_amp_homepage_settings && $get_custom_frontpage_settings)
// TRUE: When we have " A static page" in reading settings and custom frontpage in amp
if ( 'page' == get_option( 'show_on_front') && (is_home() || is_front_page()) && $get_front_page_reading_settings && $get_amp_homepage_settings && $get_custom_frontpage_settings && !empty($get_amp_custom_frontpage_id)) {
$current_page = get_queried_object();
$current_page = $current_page->ID;
if ( get_option( 'page_for_posts') == $current_page ) {
$front_page = apply_filters('ampforwp_is_front_page', $front_page);
function ampforwp_is_home(){
global $redux_builder_amp;
if ( ampforwp_is_front_page() == false && ampforwp_is_blog () == false && is_home() ) {
function ampforwp_is_blog(){
$get_blog_details = ampforwp_get_blog_details();
return $get_blog_details ;
function ampforwp_polylang_front_page() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if( is_plugin_active( 'polylang/polylang.php' ) || is_plugin_active( 'polylang-pro/polylang.php' ) ){
$page_id = $polylang->curlang->page_on_front;
$frontpage_id = get_option('page_on_front');
// is_front_page is not working here so had to do this way
// Check current page id with translated page id
if ( function_exists('pll_get_post') && $page_id == pll_get_post($frontpage_id) && ! is_page() && ! is_single() && ! is_archive() && ! is_search() && ! ampforwp_is_blog() ){
// Get The ID for AMP #2867
function ampforwp_get_the_ID($post_id=''){
if(ampforwp_is_front_page()){
$post_id = ampforwp_get_frontpage_id();
$post_id = ampforwp_get_blog_details('id');
// Backward Compatibility
function ampforwp_correct_frontpage() {
return ampforwp_get_frontpage_id();
//Common function to get frontpageID
function ampforwp_get_frontpage_id() {
if ( ampforwp_is_front_page() ) {
$post_id = ampforwp_get_setting('amp-frontpage-select-option-pages');
$post_id = apply_filters('ampforwp_modify_frontpage_id', $post_id);
// 27. Clean the Defer issue
// TODO : Get back to this issue. #407
function ampforwp_the_content_filter_full( $content_buffer ) {
if ((!is_plugin_active('amp/amp.php') && function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() )
(function_exists('amp_activate') && function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() )) {
$content_buffer = preg_replace("/' defer='defer/", "", $content_buffer);
$content_buffer = preg_replace("/' defer onload='/", "", $content_buffer);
$content_buffer = preg_replace("/' defer /", "", $content_buffer);
$content_buffer = preg_replace("/onclick=[^>]*/", "", $content_buffer);
$content_buffer = preg_replace("/<\\/?thrive_headline(.|\\s)*?>/",'',$content_buffer);
// Remove Extra styling added by other Themes/ Plugins
preg_match('/(<style(.*?)>(.*?)<\/style>)<!doctype html>/', $content_buffer, $m1);
$content_buffer = preg_replace('/(<style(.*?)>(.*?)<\/style>)<!doctype html>/','<!doctype html>',$content_buffer);
preg_match('/(<style(.*?)>(.*?)<\/style>)(\/\*)/', $content_buffer, $m2);
$content_buffer = preg_replace('/(<style(.*?)>(.*?)<\/style>)(\/\*)/','$4',$content_buffer);
$content_buffer = preg_replace("/<\\/?g(.|\\s)*?>/",'',$content_buffer);
$content_buffer = preg_replace('/(<[^>]+) spellcheck="false"/', '$1', $content_buffer);
$content_buffer = preg_replace('/(<[^>]+) spellcheck="true"/', '$1', $content_buffer);
$content_buffer = preg_replace("/about:blank/", "#", $content_buffer);
$content_buffer = preg_replace("/<script data-cfasync[^>]*>.*?<\/script>/", "", $content_buffer);
$content_buffer = preg_replace('/<font(.*?)>(.*?)<\/font>/', '$2', $content_buffer);
$content_buffer = preg_replace('/<ta([^a-z]*|\s(.*?))>(.*?)<\/ta>/', '$3', $content_buffer);
//$content_buffer = preg_replace('/<style type=(.*?)>|\[.*?\]\s\{(.*)\}|<\/style>(?!(<\/noscript>)|(\n<\/head>)|(<noscript>))/','',$content_buffer);
// xlink attribute causes Validatation Issues #1149
$content_buffer = preg_replace('/xlink="href"/','',$content_buffer);
$content_buffer = preg_replace('/!important/', '' , $content_buffer);
$content_buffer = preg_replace('/<area(.*?)>/', '', $content_buffer);
// Compatibility with the footnotes plugin. #2447
if(class_exists('MCI_Footnotes')){
$footnote_collapse_link = '';
$footnote_collapse = false;
if (method_exists('MCI_Footnotes_Convert', 'toBool')) {
$footnote_collapse = MCI_Footnotes_Convert::toBool(MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_BOOL_REFERENCE_CONTAINER_COLLAPSE));
if( $footnote_collapse == true ){
$footnote_collapse_link = 'on="tap:footnote_references_container.show" role="click" tabindex="1" ';
$content_buffer = preg_replace( '/<div id=(.*?)footnote_references_container(.*?)\s/m','<div id=$1footnote_references_container$2 hidden ',$content_buffer);
$content_buffer = preg_replace( '/<div\s(.*?)<a\s(.*?)\+(.*)/m','<div $1 <a on="tap:footnote_references_container.show" $2 + <span on="tap:footnote_references_container.hide" id="fn_span" role="click" tabindex="2" > - </span> $3',$content_buffer);
$content_buffer = preg_replace( '/<sup(.*?)id="footnote_plugin_tooltip_(.*?)"(.*?)class="footnote_plugin_tooltip_text"(.*?)>(.*?)<\/sup>/m', '
<sup$1id="footnote_plugin_tooltip_$2" '.$footnote_collapse_link.' $3class="footnote_plugin_tooltip_text"$4><a href="#footnote_plugin_reference_$2" id="fn_plugin_refer" >$5</a></sup>', $content_buffer);
$content_buffer = apply_filters('ampforwp_the_content_last_filter', $content_buffer);
if(function_exists('ampforwp_amp_nonamp_convert') && ampforwp_amp_nonamp_convert("", "check")){
$content_buffer = ampforwp_amp_nonamp_convert($content_buffer, "filter");
add_action('wp', function(){ ob_start('ampforwp_the_content_filter_full'); }, 999);
// 74. Featured Image check from Custom Fields
function ampforwp_is_custom_field_featured_image(){
global $redux_builder_amp, $post;
if(isset($redux_builder_amp['ampforwp-custom-fields-featured-image-switch'], $redux_builder_amp['ampforwp-custom-fields-featured-image']) && $redux_builder_amp['ampforwp-custom-fields-featured-image-switch'] && $redux_builder_amp['ampforwp-custom-fields-featured-image']){
function ampforwp_generate_meta_desc($json=""){
global $post, $redux_builder_amp;
$post_id = ampforwp_get_the_ID();
if ( true == ampforwp_get_setting('ampforwp-seo-meta-desc') || !empty($json) ) {
if ( ampforwp_is_home() || ampforwp_is_blog() ) {
$desc = addslashes( strip_tags( get_bloginfo( 'description' ) ) );
$desc = addslashes( strip_tags( get_the_archive_description() ) );
if ( is_single() || is_page() || ampforwp_is_front_page()) {
$desc = get_the_excerpt();
$id = ampforwp_get_the_ID();
$desc = $post->post_content;
$desc = preg_replace('/\[(.*?)\]/',' ', $desc);
$desc = addslashes( wp_trim_words( strip_tags( $desc ) , 15 ) );
$desc = addslashes( ampforwp_translation($redux_builder_amp['amp-translator-search-text'], 'You searched for:') . ' ' . get_search_query() );
if ( class_exists('WPSEO_Frontend') && ('yoast' == ampforwp_get_setting('ampforwp-seo-selection') || 1 == ampforwp_get_setting('ampforwp-seo-selection')) && !class_exists('Yoast\\WP\\SEO\\Integrations\\Front_End_Integration')) {
$front = $yoast_desc = '';
$front = WPSEO_Frontend::get_instance();
$yoast_desc = addslashes( strip_tags( $front->metadesc( false ) ) );
if ( ampforwp_is_front_page() ) {
$post_id = ampforwp_get_frontpage_id();
if ( class_exists('WPSEO_Meta') ) {
$yoast_desc = addslashes( strip_tags( WPSEO_Meta::get_value('metadesc', $post_id ) ) );
$yoast_desc = addslashes( ampforwp_translation($redux_builder_amp['amp-translator-search-text'], 'You searched for:') . ' ' . get_search_query() );
if ( $json && false == $redux_builder_amp['ampforwp-seo-yoast-description'] ) {
if ( class_exists('All_in_One_SEO_Pack') && ( 'aioseo' == ampforwp_get_setting('ampforwp-seo-selection') || 2 == ampforwp_get_setting('ampforwp-seo-selection'))) {
$aisop_class = $aisop_desc = $opts = '';
$aisop_class = new All_in_One_SEO_Pack();
if ( ampforwp_is_home() ) {
$post_id = ampforwp_get_blog_details('id');
$post = get_post($post_id);
$aisop_desc = $aisop_class->get_aioseop_description($post);
$opts = $aisop_class->get_current_options( array(), 'aiosp' );
if ( (is_category() || is_tax() || is_tag()) && $aisop_class->show_page_description() ) {
$aisop_desc = $opts['aiosp_description'];
if ( ampforwp_is_front_page() ) {
$post_id = ampforwp_get_frontpage_id();
$post = get_post($post_id);
$aisop_desc = $aisop_class->get_post_description( $post );
if ( function_exists('genesis_get_seo_meta_description') && 'genesis' == ampforwp_get_setting('ampforwp-seo-selection') ) {
$genesis_description = '';
if ( is_home() && is_front_page() && ! ampforwp_get_setting('amp-frontpage-select-option') ) {
$genesis_description = genesis_get_seo_option( 'home_description' ) ? genesis_get_seo_option( 'home_description' ) : get_bloginfo( 'description' );
elseif(ampforwp_is_front_page()){
$genesis_description = strip_tags(genesis_get_custom_field( '_genesis_description', intval($post_id) ));
elseif ( is_home() && get_option( 'page_for_posts' ) && get_queried_object_id() ) {
$post_id = get_option( 'page_for_posts' );
if ( null !== $post_id || is_singular() ) {
if ( genesis_get_custom_field( '_genesis_description', intval($post_id) ) ) {
$genesis_description = strip_tags(genesis_get_custom_field( '_genesis_description', intval($post_id) ));
if ( $genesis_description ) {
$desc = $genesis_description;
elseif ( is_home() && ampforwp_get_setting('amp-frontpage-select-option') && get_option( 'page_on_front' ) ) {
$post_id = get_option('page_on_front');
if ( null !== $post_id || is_singular() ) {
if ( genesis_get_custom_field( '_genesis_description', intval($post_id) ) ) {
$genesis_description = strip_tags(genesis_get_custom_field( '_genesis_description', intval($post_id) ));
$genesis_description = genesis_get_seo_meta_description();
if ( $genesis_description ) {
$desc = esc_html($genesis_description);
if ( is_plugin_active('wp-seopress/seopress.php') && 'seopress' == ampforwp_get_setting('ampforwp-seo-selection') ) {
$seopress_description = $seopress_options = '';
$seopress_options = get_option("seopress_titles_option_name");
if ( get_post_meta($post_id,'_seopress_titles_desc',true) ) {
$seopress_description = get_post_meta($post_id,'_seopress_titles_desc',true);
if ( ampforwp_is_home() || ampforwp_is_blog() ) {
$seopress_variables_array = array('%%sitetitle%%','%%tagline%%');
$seopress_replace_array = array( get_bloginfo('name'), get_bloginfo('description') );
$seopress_description = $seopress_options['seopress_titles_home_site_desc'];
$seopress_description = str_replace($seopress_variables_array, $seopress_replace_array, $seopress_description);
$seopress_description = get_term_meta(get_queried_object()->{'term_id'},'_seopress_titles_desc',true);
if ( $seopress_description ) {
$desc = $seopress_description;
if ( defined( 'RANK_MATH_FILE' ) && 'rank_math' == ampforwp_get_setting('ampforwp-seo-selection') ) {
$rank_math_desc = RankMath\Post::get_meta( 'description', $post_id );
if (ampforwp_is_home()) {
$desc = $rank_math_desc ? $rank_math_desc : $desc;
//Bridge Qode SEO Compatibility #2538
if ( function_exists('qode_header_meta') && 'bridge' == ampforwp_get_setting('ampforwp-seo-selection')){
$desc = get_post_meta($post_id, "qode_seo_description", true);
if ( function_exists( 'the_seo_framework' ) && 'seo_framework' == ampforwp_get_setting('ampforwp-seo-selection') ) {
$tsf_desc = $ampforwp_tsf = '';
$ampforwp_tsf = \the_seo_framework();
$tsf_desc = $ampforwp_tsf->get_description();
// strip_shortcodes strategy not working here so had to do this way
$desc = preg_replace('/\[(.*?)\]/','', $desc);
if( !function_exists('ampforwp_get_blog_details') ) {
function ampforwp_get_blog_details( $param = "" ) {
global $redux_builder_amp;