: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
update_post_meta( $post_id, 'amp-page-builder', $meta );
// Storing a revision of the meta field when a post is saved
function ampforwp_meta_revi_save_post( $post_id, $post ) {
if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) {
if ( $parent_id = wp_is_post_revision( $post_id ) ) {
$parent = get_post( $parent_id );
$pb_meta = get_post_meta( $parent->ID, 'amp-page-builder', true );
if ( false !== $pb_meta ){
add_metadata( 'post', $post_id, 'amp-page-builder', $pb_meta );
// Post Meta Revisions #3548 -- end here --
add_action( 'pre_amp_render_post', 'ampforwp_front_admin_menu_bar' );
function ampforwp_front_admin_menu_bar(){
if( is_user_logged_in() ){
$pref = get_user_option( "show_admin_bar_front", get_current_user_id() );
if(class_exists('QM_Plugin') && class_exists('QM_Dispatchers') && ampforwp_get_setting('ampforwp-query-monitor')){
$dis = QM_Dispatchers::get( 'html' );
if(is_object($dis) && $dis->did_footer==false){
add_action( 'amp_post_template_head', 'ampforwp_query_monitor_script' );
add_action( 'amp_post_template_head', 'ampforwp_manual_qm_script', 11 );
add_action("ampforwp_admin_menu_bar_front", function(){
add_action('wp_before_admin_bar_render','ampforwp_add_admin_menu_front');
add_action( 'admin_bar_init', 'ampforwp_init_admin_bar');
add_action( 'wp_before_admin_bar_render','ampforwp_remove_before_admin_bar_redner',9);
add_action( 'admin_bar_menu', 'ampforwp_remove_admin_menu_front',999);
add_action('amp_post_template_css', 'ampforwp_head_css');
function ampforwp_remove_before_admin_bar_redner(){
remove_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' );
function ampforwp_init_admin_bar(){
remove_action( 'wp_head', '_admin_bar_bump_cb' );
remove_action( 'wp_head', 'wp_admin_bar_header' );
function ampforwp_head_css(){
global $ampforwpTemplate, $redux_builder_amp, $wp_filesystem;
if( is_user_logged_in() ){
$pref = get_user_option( "show_admin_bar_front", get_current_user_id() );
require_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php';
require_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php';
$wp_filesystem = new WP_Filesystem_Direct( array() );
if(ampforwp_get_setting('ampforwp_css_tree_shaking')==1){
}elseif(ampforwp_is_blog()){
}elseif(ampforwp_is_front_page()){
$tscss = "post-".ampforwp_get_frontpage_id();
$tscss = "post-".ampforwp_get_the_ID();
$page_id = get_queried_object_id();
$tscss = "archive-".intval($page_id);
$tscss = $tscss.'-admin';
$upload_dir = wp_upload_dir();
$ts_file = esc_attr($upload_dir['basedir']) . '/' . 'ampforwp-tree-shaking/_transient_'.esc_attr($tscss).".css";
if(file_exists($ts_file)){
$css = $wp_filesystem->get_contents($ts_file);
if(preg_match("/#wpadminbar/", $css)==0){
$user_dirname = $upload_dir['basedir'] . '/' . 'ampforwp-tree-shaking';
if(file_exists($user_dirname)){
$files = glob($user_dirname . '/*');
foreach($files as $file){
if(is_file($file) && strpos($file, '_transient')!==false ){
$css = $wp_filesystem->get_contents(AMPFORWP_PLUGIN_DIR."/templates/template-mode/admin-bar.css");
$incurl = includes_url();
$incurl = trailingslashit($incurl) .'fonts/dashicons.ttf?50db0456fde2a241f005968eede3f987';
$css.='@font-face{font-family:dashicons;src:url('.$incurl.'/fonts/dashicons.ttf?50db0456fde2a241f005968eede3f987) format("truetype");
font-weight:400;font-style:normal}
#wp-admin-bar-my-account .avatar{float:right;margin-top:7px;margin-left:5px;height:18px;width:18px;border:1px solid #82878c}#wp-admin-bar-wpseo-notifications .yoast-issue-counter{float:right}@media(max-width:782px){#wpadminbar~header #headerwrap{top:46px}}';
if(ampforwp_get_setting('amp-design-selector')!=3){
$css.='#wpadminbar~header{margin-top:32px}@media(max-width:782px){#wpadminbar~header{margin-top:46px}}';
$css.='#wpadminbar~header #headerwrap{top:32px}@media(max-width:782px){#wpadminbar~header #headerwrap{margin-top:46px}}';
echo ampforwp_css_sanitizer($css);
function ampforwp_css_sanitizer($css){
$css = preg_replace( '/\s*!important/', '', $css, -1, $important_count );
$css = preg_replace( '/overflow(-[xy])?\s*:\s*(auto|scroll)\s*;?\s*/', '', $css, -1, $overlow_count );
$css = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css);
$css = str_replace(array (chr(10), ' {', '{ ', ' }', '} ', '( ', ' )', ' :', ': ', ' ;', '; ', ' ,', ', ', ';}', '::-' ), array('', '{', '{', '}', '}', '(', ')', ':', ':', ';', ';', ',', ', ', '}', ' ::-'), $css);
function ampforwp_get_remote_content($src){
$arg = array( "sslverify" => false, "timeout" => 60 ) ;
$response = wp_remote_get( $src, $arg );
if ( wp_remote_retrieve_response_code($response) == 200 && is_array( $response ) ) {
$header = wp_remote_retrieve_headers($response); // array of http header lines
$contentData = wp_remote_retrieve_body($response); // use the content
return $contentData = file_get_contents( $src );
function ampforwp_add_admin_menu_front(){
$dom = new DOMDocument();
$my_account = $wp_admin_bar->get_node('my-account');
if(is_object($my_account)){
$title = ampforwp_content_sanitizer($my_account->title);
$wp_admin_bar->add_menu( array(
$user_info = $wp_admin_bar->get_node('user-info');
if(is_object($user_info)){
$title = $user_info->title;
libxml_use_internal_errors(true);
libxml_use_internal_errors(false);
$anchors = $dom -> getElementsByTagName('img');
foreach($anchors as $im){
$src = $im->getAttribute('src');
$authname = get_the_author_meta('nickname');
$title = '<span style="background: url('.esc_url($src).');background-repeat: no-repeat;height: 64px;position: absolute;width: 100px;top: 13px;left: -70px;" class="display-name"></span><span class="display-name">'.esc_html__($authname,'accelerated-mobile-pages').'<span>';
$wp_admin_bar->add_menu( array(
if(class_exists('WPSEO_Options')){
$wp_admin_bar->add_menu( array(
$wp_admin_bar->remove_menu( 'ampforwp-view-amp' );
if(function_exists('autoptimize_autoload')){
$wp_admin_bar->remove_menu( 'autoptimize' );
$url = get_preview_post_link();
$wp_admin_bar->add_node(array(
'id' => 'ampforwp-view-non-amp',
'title' => 'View Non-AMP',
$url = ampforwp_get_non_amp_url();
$wp_admin_bar->add_node(array(
'id' => 'ampforwp-view-non-amp',
'title' => 'View Non-AMP' ,
function ampforwp_remove_admin_menu_front($wp){
$node_arr = ['search','admin-bar-likes-widget'];
for($i=0;$i<count($node_arr);$i++){
$wp->remove_node($node_arr[$i]);
function ampforwp_manual_qm_script() {
function ampforwp_query_monitor_script() {
if ( defined( 'QM_NO_JQUERY' ) && QM_NO_JQUERY ) {
if ( method_exists( 'Dark_Mode', 'is_using_dark_mode' ) && is_user_logged_in() ) {
if ( Dark_Mode::is_using_dark_mode() ) {
} elseif ( defined( 'QM_DARK_MODE' ) && QM_DARK_MODE ) {
esc_attr($qm)."/query-monitor/assets/{$css}.css",
esc_attr($qm).'/query-monitor/assets/query-monitor.js',
$wp_locale->number_format
'ajax_error' => __( 'PHP Errors in Ajax Response', 'query-monitor' ),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'on' => wp_create_nonce( 'qm-auth-on' ),
'off' => wp_create_nonce( 'qm-auth-off' ),
'editor-set' => wp_create_nonce( 'qm-editor-set' ),
function ampforwp_get_non_amp_url(){
$nofollow = $page = $amp_url = $non_amp_url = '';
if( true == ampforwp_get_setting('ampforwp-nofollow-view-nonamp') ){
$nofollow = 'rel=nofollow';
$amp_url = untrailingslashit( home_url( $wp->request ) );
$amp_url = explode('/', $amp_url);
$amp_url = array_flip($amp_url);
unset($amp_url[AMPFORWP_AMP_QUERY_VAR]);
$non_amp_url = array_flip($amp_url);
$non_amp_url = implode('/', $non_amp_url);
$query_arg_array = $wp->query_vars;
if( array_key_exists( "page" , $query_arg_array ) ) {
$page = $wp->query_vars['page'];
$non_amp_url = trailingslashit( $non_amp_url . '?page=' . $page);
if ( ampforwp_get_setting('amp-mobile-redirection') == true && ampforwp_get_setting('amp-mob-redirection-pres-link') == false) {
$non_amp_url = add_query_arg('nonamp','1',$non_amp_url);
$non_amp_url = user_trailingslashit($non_amp_url);
if(function_exists('ampforwp_mobile_redirect_preseve_link')){
$mob_pres_link = ampforwp_mobile_redirect_preseve_link();
if ( true == ampforwp_get_setting('ampforwp-amp-takeover') || $mob_pres_link == true) {
return apply_filters('ampforwp_view_nonamp_url', $non_amp_url);
add_action( 'wp_ajax_ampforwp_set_option_panel_view', 'ampforwp_set_option_panel_view' );
function ampforwp_set_option_panel_view(){
if(!is_admin() && !current_user_can('manage_options')){
if(!wp_verify_nonce($_POST['verify_nonce'],'ampforwp-verify-request') ){
echo wp_json_encode(array('status'=>403,'message'=>esc_html__('user request is not allowed','accelerated-mobile-pages'))) ;
$opt_type = intval($_POST['option_type']);
if($opt_type==1 || $opt_type==2){
$opt = get_option("ampforwp_option_panel_view_type");
update_option("ampforwp_option_panel_view_type", $opt_type, false);
add_option("ampforwp_option_panel_view_type", $opt_type);
add_action('admin_head', 'ampforwp_remove_admin_help');
if(!function_exists('ampforwp_remove_admin_help')){
function ampforwp_remove_admin_help(){
if(!is_admin() && !current_user_can('manage_options')){
$screen = get_current_screen();
if ( 'toplevel_page_amp_options' == $screen->base ) {
$screen->remove_help_tabs();
if(!function_exists('ampforwp_sassy_icon_style')){
function ampforwp_sassy_icon_style(){
$css = get_transient('ampforwp_sassy_css');
if(!is_object($wp_filesystem)){
require_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php';
require_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php';
$wp_filesystem = new WP_Filesystem_Direct( array() );
$css = $wp_filesystem->get_contents(AMPFORWP_PLUGIN_DIR."/includes/sassy-style.css");
set_transient('ampforwp_sassy_css', $css);
echo ampforwp_css_sanitizer($css);
if(function_exists('heateor_sss_run')){
add_action('amp_post_template_css', 'ampforwp_sassy_icon_style');
function ampforwp_nofollow_cta_header_link(){
if(true == ampforwp_get_setting('ampforwp-header-cta-link-nofollow')){
// Generating canonical url when FlexMLS plugin is active.
if(class_exists('flexmlsConnectPageSearchResults')){
add_action('pre_amp_render_post','ampforwp_flexmls_canonical');
function ampforwp_flexmls_canonical(){
add_filter('wpseo_canonical','ampforwp_flexmls_generate_canonical_url',99,2);
function ampforwp_flexmls_generate_canonical_url($canonical,$object){
$canonical = $object->model->permalink;
return esc_url($canonical);
if( ! function_exists('ampforwp_font_selector') ) {
function ampforwp_font_selector( $container ) {
global $redux_builder_amp;
if(1==ampforwp_get_setting('ampforwp-google-font-switch')){
return sanitize_text_field($fontFamily);
if ( 'content' == $container && ampforwp_get_setting('amp_font_selector_content_single') && 1 != ampforwp_get_setting('amp_font_selector_content_single') ) {
$fontFamily = "font-family: '".ampforwp_get_setting('amp_font_selector_content_single')."';";
if ( 'body' == $container && ampforwp_get_setting('amp_font_selector') && 1 != ampforwp_get_setting('amp_font_selector') ) {
$fontFamily = "font-family: '".ampforwp_get_setting('amp_font_selector')."'";
return sanitize_text_field($fontFamily);
if(class_exists('WPSEO_Options')){
add_filter('ampforwp_the_content_last_filter','ampforwp_remove_duplicate_canonical',25);
function ampforwp_remove_duplicate_canonical($content){
if( class_exists( 'DOMDocument' ) && ! empty( $content ) && is_string( $content ) ){
$comp_dom = new DOMDocument();
@$comp_dom->loadHTML($content);
$xpath = new DOMXPath( $comp_dom );
$nodes = $xpath->query('//link[@rel="canonical"]');
foreach ($nodes as $node) {
if(preg_match("/<link\b[^>]*?\brel=[\'\"]canonical[\'\"][^>]*>/", $content, $matches, PREG_OFFSET_CAPTURE)){
$content = preg_replace("/<link\b[^>]*?\brel=[\'\"]canonical[\'\"][^>]*>/", "", $content);
$content = substr_replace($content, $matches[0][0], $matches[0][1], 0);
if ( ! function_exists('ampforwp_font_url') ) {
function ampforwp_font_url($font_url){
return apply_filters('ampforwp_font_url', $font_url);
//Need to add full short pixel plugin compatibility #3782
if(class_exists('ShortPixelAPI')){
add_filter( 'ampforwp_the_content_last_filter','ampforwp_short_pixel_cdn');
function ampforwp_short_pixel_cdn($content){
$api_url = get_option('spai_settings_api_url');
$compress_level = get_option('spai_settings_compress_level');
if('0'== $compress_level){
$compress_level = '+q_lossless';
if('1'== $compress_level){
$compress_level = '+q_lossy';
if('2'== $compress_level){
$compress_level = '+q_glossy';
$compress_level .= '+ret_img+to_webp/';
$content = preg_replace('/<amp-img(.*?)src="([^"]*)"(.*?)width="([^"]*)" height="([^"]*)"([^>]*)>/','<amp-img$1 src="'.$api_url.'/w_$4'.$compress_level.'$2"$3 width="$4" height="$5"$6>',$content);
if(ampforwp_get_setting('ampforwp_css_tree_shaking') == true && ampforwp_is_gutenberg_active()){
add_action('amp_post_template_css','ampforwp_gutenberg_block_styles');
if(!function_exists('ampforwp_gutenberg_block_styles')){
function ampforwp_gutenberg_block_styles(){
$gutenberg_styles = $block_css = '';
wp_print_styles('wp-block-library');
$block_css .= ob_get_contents();
preg_match("/href='(.*?)'/", $block_css, $matches);
$style_path = explode('?', $matches[1]);
$gutenberg_styles = get_transient('ampforwp_gutenberg_styles');
if($gutenberg_styles == false){
$response = wp_remote_get( $style_path[0] );
if( is_array( $response ) && ! is_wp_error( $response ) ){
set_transient('ampforwp_gutenberg_styles', $response['body'], 24 * HOUR_IN_SECONDS );
echo ampforwp_css_sanitizer($gutenberg_styles);
function ampforwp_is_gutenberg_active() {
if ( has_filter( 'replace_editor', 'gutenberg_init' ) ) {
if ( version_compare( $GLOBALS['wp_version'], '5.0-beta', '>' ) ) {
if ( ! $gutenberg && ! $block_editor ) {
if ( !class_exists('Classic_Editor') ) {
$use_block_editor = ( get_option( 'classic-editor-replace' ) === 'no-replace' );
return $use_block_editor;
add_filter( 'amp_post_template_data', 'ampforwp_pblayout_head_scripts');
$pb_remove_script = array();
function ampforwp_pblayout_head_scripts($data){
$postId = ampforwp_get_the_ID();
$ampforwp_pagebuilder_enable = get_post_meta($postId,'ampforwp_page_builder_enable', true);
if(isset($ampforwp_pagebuilder_enable) && $ampforwp_pagebuilder_enable=="yes"){
$previousData = get_post_meta($postId,'amp-page-builder');
$previousData = isset($previousData[0])? $previousData[0]: null;
$previousData = (str_replace("'", "'", $previousData));
if(!empty($previousData)){
$jsonData = json_decode($previousData,true);
if(isset($jsonData['rows']) && count($jsonData['rows'])>0){
$totalRows = $jsonData['totalrows'];
$totalmodules = $jsonData['totalmodules'];
$previousData = wp_json_encode($jsonData);
$jsonData['rows'] = array();
$jsonData['totalrows']=1;
$jsonData['totalmodules'] = 1;
$previousData = wp_json_encode($jsonData);