: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if(isset($redux_builder_amp['ampforwp-display-avatar']) && $redux_builder_amp['ampforwp-display-avatar']==0){
if (class_exists('FV_Gravatar_Cache')) {
$options = get_option('fv_gravatar_cache');
$size = $options['size'];
$avatar_url = get_avatar_url($comment);
$upload_dir = wp_upload_dir();
$upload_dir = $upload_dir['baseurl'] . '/fv-gravatar-cache/';
$avatar_url = preg_replace('/(.*?)avatar\/(.*?)\?s=(.*?)&(.*?)g/', ''.$upload_dir.'$2x$3.png', $avatar_url);
preg_match_all('/(.*?)wp-content\/uploads\/fv-gravatar-cache\/(.*?)/U', $avatar_url, $match);
$headers = get_headers($url, 1);
if(isset($headers[0]) && !stripos($headers[0], "200 OK")){
$avatar_url = $upload_dir.'mystery'. esc_html($size) .'.png';
$gravatar_exists = ampforwp_gravatar_checker($comment->comment_author_email);
if ( null !== ampforwp_get_wp_user_avatar($comment, 'comment') ) {
return ampforwp_get_wp_user_avatar($comment, 'comment');
elseif($gravatar_exists == true){
return get_avatar_url( $comment, apply_filters( 'ampforwp_get_comments_gravatar', '60' ), '' );
return apply_filters( 'ampforwp_get_comments_gravatar', '' );
if ( ! function_exists('ampforwp_gravatar_checker') ) {
function ampforwp_gravatar_checker( $email ) {
// Craft a potential url and test its headers
$hash = md5(strtolower(trim($email)));
$gravatar_server = hexdec( $hash[0] ) % 3;
$gravatar_server = rand( 0, 2 );
$uri = 'https://secure.gravatar.com/avatar/' . $hash;
$uri = sprintf( 'http://%d.gravatar.com/avatar/%s', $gravatar_server, $hash );
$response = wp_remote_get(esc_url_raw($uri));
$response_code = wp_remote_retrieve_response_code($response);
if ($response_code!=200) {
$has_valid_avatar = FALSE;
$has_valid_avatar = TRUE;
return $has_valid_avatar;
function ampfowp_add_extra_css(){
#wp-admin-bar-ampforwp-view-amp a{
background:url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU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DMxLjQwMiAxNTcuMDA3LDMxLjQwMiBDMjI2LjM3MSwzMS40MDIgMjgyLjYxMSw4Ny42MzQgMjgyLjYxMSwxNTcuMDA3IEMyODIuNjEyLDIyNi4zNzIgMjI2LjM3MiwyODIuNjEyIDE1Ny4wMDcsMjgyLjYxMiBaIE0yMDQuMTExLDE0MS4zNjggTDE2My40NzksMTQxLjUzMyBDMTU5LjEzOSwxNDEuNTUzIDE1Ny41NDQsMTM4LjYyMyAxNTkuOTA1LDEzNC45NzkgTDIwMy4zOTcsNjguMTA5IEMyMDguMTI2LDYwLjg0MSAyMDYuOTg0LDU5LjkyMiAyMDAuODYxLDY2LjA1MyBMMTA1LjMwNSwxNjEuNiBDOTkuMTcyLDE2Ny43MzIgMTAxLjIzMiwxNzIuNjc2IDEwOS45MDYsMTcyLjY0MSBMMTQyLjY3OSwxNzIuNTA4IEMxNTEuMzQ3LDE3Mi40NzIgMTU0LjU1MiwxNzguMzM1IDE0OS44MjQsMTg1LjYwNSBMMTA2LjMzNCwyNTIuNDc3IEMxMDMuOTcyLDI1Ni4xMTIgMTA0LjU0MiwyNTYuNTgxIDEwNy42MiwyNTMuNTI3IEwxNzUuOTE1LDE4NS43MTcgQzE3OC45ODgsMTgyLjY1OSAxODMuOTUsMTc3LjY4NiAxODYuOTgzLDE3NC41OTYgTDIwOC43ODgsMTUyLjQ4NSBDMjE0Ljg3NSwxNDYuMzE3IDIxMi43NzUsMTQxLjMzIDIwNC4xMTEsMTQxLjM2OCBaIiBpZD0iU2hhcGUiPjwvcGF0aD4KICAgICAgICAgICAgICAgIDwvZz4KICAgICAgICAgICAgPC9nPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+) !important;
background-size: 18px !important;
background-repeat: no-repeat !important;
background-position: 4px 7px !important;
if ( is_user_logged_in() ) {
add_action('wp_head', 'ampfowp_add_extra_css');
// 92. View AMP in Admin Bar
add_action( 'wp_before_admin_bar_render', 'ampforwp_view_amp_admin_bar' );
if( ! function_exists( 'ampforwp_view_amp_admin_bar' ) ) {
function ampforwp_view_amp_admin_bar( ) {
global $wp_admin_bar, $post, $wp_post_types, $redux_builder_amp;
$post_type_title = $current_url = '';
$supported_amp_post_types = array();
// Get all post types supported by AMP
$supported_amp_post_types = ampforwp_get_all_post_types();
$current_screen = get_current_screen();
$current_access = ('post' == $current_screen->base && 'add' != $current_screen->action);
}elseif(is_user_logged_in()){
$current_user = wp_get_current_user();
$current_access = current_user_can('edit_posts',$current_user );
// Check for Screen base, user ability to read and visibility
if ($current_access && (isset($post->ID) && $post->ID && current_user_can('read_post', $post->ID ))
&& ( isset ( $wp_post_types[ $post->post_type ]->public ) && $wp_post_types[$post->post_type]->public )
&& ( isset ( $wp_post_types[ $post->post_type ]->show_in_admin_bar ) && $wp_post_types[$post->post_type]->show_in_admin_bar ) ) {
// Check if current post type is AMPed or not
if( $supported_amp_post_types && in_array($post->post_type, $supported_amp_post_types) ){
// If AMP on Posts or Pages is off then do nothing
if($post->post_type == 'post' && !ampforwp_get_setting('amp-on-off-for-all-posts') || $post->post_type == 'page' && !ampforwp_get_setting('amp-on-off-for-all-pages')) {
if( is_archive() && is_category() ){
if(!ampforwp_get_setting('ampforwp-archive-support') || !ampforwp_get_setting('ampforwp-archive-support-cat') ){
}elseif( is_archive() && is_tag() ){
if(!ampforwp_get_setting('ampforwp-archive-support') || !ampforwp_get_setting('ampforwp-archive-support-tag') ){
}elseif( is_archive() && is_tax()){
$taxonomies = ampforwp_get_setting('ampforwp-custom-taxonomies');
$term_id = get_queried_object()->term_id;
$termObj = get_term( $term_id);
if( in_array($termObj->taxonomy, $taxonomies)){
if( is_archive() && is_category()){
$term_id = get_queried_object()->term_id;
$termObj = get_term( $term_id);
$taxonomy_objects = get_object_taxonomies( 'post', 'objects' );
$post_type_title = $taxonomy_objects[$termObj->taxonomy]->labels->singular_name;
if(ampforwp_get_setting('ampforwp-archive-support') == true && ampforwp_get_setting('ampforwp-archive-support-cat') == true){
$current_url = get_term_link($term_id);
}elseif( is_archive() && is_tag()){
$term_id = get_queried_object()->term_id;
$termObj = get_term( $term_id);
$taxonomy_objects = get_object_taxonomies( 'post', 'objects' );
$post_type_title = $taxonomy_objects[$termObj->taxonomy]->labels->singular_name;
if(ampforwp_get_setting('ampforwp-archive-support') == true && ampforwp_get_setting('ampforwp-archive-support-tag') == true){
$current_url = get_term_link($term_id);
}elseif(is_archive() && is_tax()){
$term_id = get_queried_object()->term_id;
$termObj = get_term( $term_id);
$taxonomy_objects = get_taxonomy( $termObj->taxonomy );
$post_type_title = $taxonomy_objects->labels->singular_name;
$current_url = get_term_link($term_id);
$post_type_title = ucfirst($post->post_type);
$current_url = get_permalink( $post->ID );
$current_url = home_url();
$current_url = $current_url .'&=1&preview=true';
$wp_admin_bar->add_node(array(
'id' => 'ampforwp-view-amp',
'title' => 'View ' . esc_html($post_type_title) . ' (AMP)' ,
'href' => esc_url($current_url)
$wp_admin_bar->add_node(array(
'id' => 'ampforwp-view-amp',
'title' => 'View ' . esc_html($post_type_title) . ' (AMP)' ,
'href' => ampforwp_url_controller($current_url)
// 94. OneSignal Push Notifications
// Moved to push-notification-functions.php
// 95. Modify menu link attributes for SiteNavigationElement Schema Markup #1229 #1345
add_filter( 'nav_menu_link_attributes', 'ampforwp_nav_menu_link_attributes', 10, 3 );
if( ! function_exists( 'ampforwp_nav_menu_link_attributes' ) ) {
function ampforwp_nav_menu_link_attributes( $atts, $item, $args ) {
if ( function_exists('ampforwp_is_amp_endpoint') && ampforwp_is_amp_endpoint() ) {
// Manipulate link attributes
$atts['itemprop'] = "url";
// 96. ampforwp_is_front_page() ampforwp_is_home() and ampforwp_is_blog is created
// Moved to functions.php
// 97. Change the format of the post date on Loops #1384
add_filter('ampforwp_modify_post_date', 'ampforwp_full_post_date_loops');
if( ! function_exists( 'ampforwp_full_post_date_loops' ) ){
function ampforwp_full_post_date_loops($full_date){
global $redux_builder_amp;
if( is_home() || is_archive() ){
if( 2 == $redux_builder_amp['ampforwp-post-date-format'] ){
$full_date = get_the_date();
if( 2 == $redux_builder_amp['ampforwp-post-date-global'] ){
$full_date = get_the_modified_date();
if( 1 == $redux_builder_amp['ampforwp-post-date-format'] ){
$time = ampforwp_get_the_time();
$date = human_time_diff( $time, current_time('timestamp') );
if( $redux_builder_amp['ampforwp-post-date-format-text'] ){
$full_date = $redux_builder_amp['ampforwp-post-date-format-text'];
// Change the % days into the actual number of days
$full_date = str_replace('% days', $date, $full_date);
$full_date = str_replace('ago', ampforwp_translation( $redux_builder_amp['amp-translator-ago-date-text'],'ago'), $full_date);
if(is_single() && 1 == $redux_builder_amp['ampforwp-post-date-format']){
$time = ampforwp_get_the_time();
$date = human_time_diff( $time, current_time('timestamp') );
$full_date = human_time_diff( $time, current_time('timestamp') ) .' '. ampforwp_translation( $redux_builder_amp['amp-translator-ago-date-text'],'ago');
if( $redux_builder_amp['ampforwp-post-date-format-text'] ){
$full_date = $redux_builder_amp['ampforwp-post-date-format-text'];
// Change the % days into the actual number of days
$full_date = str_replace('% days', $date, $full_date);
$full_date = str_replace('ago', ampforwp_translation( $redux_builder_amp['amp-translator-ago-date-text'],'ago'), $full_date);
if(!function_exists('ampforwp_get_the_time')){
function ampforwp_get_the_time(){
$time = get_the_time('U', get_the_ID());
if( 2 == ampforwp_get_setting('ampforwp-post-date-global') ){
$time = get_the_modified_time('U', get_the_ID() );
if(defined('ECWD_VERSION')){
$tz = $ecwd_options['time_zone'];
$ewwetz = new DateTime( get_the_time('c', get_the_ID()) );
if( 2 == ampforwp_get_setting('ampforwp-post-date-global') ){
$ewwetz = new DateTime( get_the_modified_time('c', get_the_ID()) );
$ewwetz->setTimezone(new DateTimeZone($tz));
$time = $ewwetz->format('U');
// 99. Merriweather Font Management
add_filter( 'amp_post_template_data', 'ampforwp_merriweather_font_management' );
function ampforwp_merriweather_font_management( $data ) {
if ( 1 != ampforwp_get_setting('amp-design-selector') || ( false == ampforwp_get_setting('ampforwp-d1-font') && 1 == ampforwp_get_setting('amp-design-selector') ) ) {
unset($data['font_urls']['merriweather']);
// 100. Flags compatibility in Menu
add_filter('ampforwp_menu_content','ampforwp_modify_menu_content');
if( ! function_exists(' ampforwp_modify_menu_content ') ){
function ampforwp_modify_menu_content($menu){
// Return $menu If tagDiv Composer plugin is active
if(function_exists('tdc_error_handler')){
$dom = new DOMDocument();
if( function_exists( 'mb_convert_encoding' ) ){
if (version_compare(PHP_VERSION, '8.2.0', '>=')) {
$menu = htmlentities($menu);
$menu = html_entity_decode($menu, ENT_QUOTES | ENT_HTML401, 'UTF-8');
$menu = mb_convert_encoding($menu, 'UTF-8', 'UTF-8');
$menu = mb_convert_encoding($menu, 'HTML-ENTITIES', 'UTF-8');
$menu = preg_replace( '/&[^amp|#038].*?;/', 'x', $menu ); // multi-byte characters converted to X
libxml_use_internal_errors(true);
libxml_use_internal_errors(false);
$nodes = $dom->getElementsByTagName( 'img' );
$num_nodes = $nodes->length;
for ( $i = $num_nodes - 1; $i >= 0; $i-- ) {
$node = $nodes->item( $i );
// Set The Width and Height if there in none
if ( '' === $node->getAttribute( 'width' ) ) {
$node->setAttribute('width', 15);
if( '' === $node->getAttribute( 'height' ) ){
$node->setAttribute('height', 15);
$menu = $dom->saveHTML();
* More details about the fix https://github.com/ahmedkaludi/accelerated-mobile-pages/pull/2317
* Props to: https://github.com/saucal for suggesting the fix.
function ampforwp_default_logo_data() {
global $redux_builder_amp, $ampwforwp_default_logo_data;
if( $ampwforwp_default_logo_data ) {
return $ampwforwp_default_logo_data;
$logo_id = get_theme_mod( 'custom_logo' );
if(isset($redux_builder_amp['opt-media']['id']) && empty( $logo_id ) ) {
$logo_id = (integer) $redux_builder_amp['opt-media']['id'];
if( empty( $logo_id ) ) {
if( ! wp_attachment_is( 'image', $logo_id ) || ampforwp_get_setting('opt-media','url') ) {
$logo_url = ampforwp_get_setting('opt-media','url');
$image[0] = ampforwp_get_setting('opt-media','width');
$image[1] = ampforwp_get_setting('opt-media','height');
$image = @getimagesize( $logo_url );
if ( empty($image[0]) || empty($image[1]) ) {
$imageDetail = wp_get_attachment_image_src( $logo_id , 'full');
$logo_url = $imageDetail[0];
$image[0] = $imageDetail[1];
$image[1] = $imageDetail[2];
$logo_alt = get_post_meta( $logo_id, '_wp_attachment_image_alt', true);
$ampwforwp_default_logo_data = array(
return $ampwforwp_default_logo_data;
// 101. Function for Logo attributes
function ampforwp_default_logo($param=""){
global $redux_builder_amp;
$data = ampforwp_default_logo_data();
if($param!="width" && $param!="height"){
$value = $data['logo_url'];
if (true == ampforwp_get_setting('ampforwp-custom-logo-dimensions') && 'prescribed' ==ampforwp_get_setting('ampforwp-custom-logo-dimensions-options')) {
$value = trim(ampforwp_get_setting('opt-media-width'));
if(isset($data['logo_size'][0])){
$value = $data['logo_size'][0];
if (true == ampforwp_get_setting('ampforwp-custom-logo-dimensions') && 'prescribed' == ampforwp_get_setting('ampforwp-custom-logo-dimensions-options')) {
$value = trim(ampforwp_get_setting('opt-media-height'));
if(isset($data['logo_size'][1])){
$value = $data['logo_size'][1];
if(isset($data['logo_alt'][0])){
$value = $data['logo_alt'];
$value = get_bloginfo('name');
$value = $data['logo_url'];
// Envira Lazy Load compatibility
add_filter('envira_gallery_pre_data', 'ampforwp_envira_lazy_load');
if( ! function_exists(' ampforwp_envira_lazy_load ') ){
function ampforwp_envira_lazy_load($data){
if( function_exists('ampforwp_is_amp_endpoint') && ampforwp_is_amp_endpoint() ){
if(function_exists('envira_get_config')){
$checker = envira_get_config( 'lazy_loading', $data);
$data['config']['lazy_loading'] = 0;
#1581 Instagram Sanitizer
add_filter( 'amp_content_sanitizers', 'ampforwp_instagram_sanitizer', 10, 1 );
function ampforwp_instagram_sanitizer( $sanitizer_classes ) {
require_once( AMPFORWP_PLUGIN_DIR. 'classes/class-ampforwp-instagram-sanitizer.php' );
$sanitizer_classes[ 'AMPFORWP_Instagram_Embed_Sanitizer' ] = array();
return $sanitizer_classes;
if ( ! function_exists('ampforwp_allowed_tags') ) {
function ampforwp_allowed_tags() {
$allowed_tags = wp_kses_allowed_html('post');
$allowed_tags['a']['itemprop'] = true;
$allowed_tags['span']['itemprop'] = true;
// List of Subpages/Childpages on Pages
add_action('ampforwp_after_post_content', 'ampforwp_list_subpages');
if ( ! function_exists('ampforwp_list_subpages') ) {
function ampforwp_list_subpages() {
if (class_exists('AddWidgetAfterContent')) {
$sanitized_output = ampforwp_sidebar_content_sanitizer('add-widget-after-content');
if ( $sanitized_output) {
$sanitized_output = $sanitized_output->get_amp_content();?>
<div class="amp-add-widget-after-content">
<?php echo do_shortcode($sanitized_output); ?>
global $post, $redux_builder_amp;
if ( is_page() && true == $redux_builder_amp['ampforwp_subpages_list'] ) {
$pages = wp_list_pages( array(
$pages = preg_replace('/href="(.*?)"/', 'href="$1/amp/"', $pages);
echo wp_kses($pages, ampforwp_allowed_tags());