: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
// Moved to structured-data-functions.php
// schema.org/SiteNavigationElement missing from menus #1229 & #2952
// Moved to structured-data-functions.php
// WP Subtitle Support #2831
add_action('ampforwp_below_the_title','ampforwp_wpsubtitle_support');
if (! function_exists('ampforwp_wpsubtitle_support') ) {
function ampforwp_wpsubtitle_support(){
if(class_exists('WPSubtitle')){?>
<h2 class="amp-wp-content"><?php the_subtitle(); ?></h2>
// Fallbacks for Vendor AMP #2287
// Class AMP_Base_Sanitizer
if ( ! class_exists('AMP_Base_Sanitizer') && class_exists('AMPforWP\\AMPVendor\\AMP_Base_Sanitizer') ) {
abstract class AMP_Base_Sanitizer extends AMPforWP\AMPVendor\AMP_Base_Sanitizer
// Class AMP_Base_Embed_Handler
if ( ! class_exists('AMP_Base_Embed_Handler') && class_exists('AMPforWP\\AMPVendor\\AMP_Base_Embed_Handler') ) {
abstract class AMP_Base_Embed_Handler extends AMPforWP\AMPVendor\AMP_Base_Embed_Handler
if ( ! class_exists('AMP_HTML_Utils') && class_exists('AMPforWP\\AMPVendor\\AMP_HTML_Utils') ) {
class AMP_HTML_Utils extends AMPforWP\AMPVendor\AMP_HTML_Utils{}
if ( ! class_exists('AMP_DOM_Utils') && class_exists('AMPforWP\\AMPVendor\\AMP_DOM_Utils') ) {
class AMP_DOM_Utils extends AMPforWP\AMPVendor\AMP_DOM_Utils{}
// Function is_amp_endpoint
add_action('pre_amp_render_post', 'ampforwp_is_amp_endpoint_old');
if ( !function_exists('ampforwp_is_amp_endpoint_old') ) {
function ampforwp_is_amp_endpoint_old(){
if ( !function_exists('amp_activate') && ! function_exists('is_amp_endpoint') ){
function is_amp_endpoint(){
return ampforwp_is_amp_endpoint();
// Class AMP_Post_Template
if ( ! class_exists('AMP_Post_Template') && class_exists('AMPforWP\\AMPVendor\\AMP_Post_Template') ) {
class AMP_Post_Template extends AMPforWP\AMPVendor\AMP_Post_Template{}
// End Fallbacks for Vendor AMP
// ampforwp_post_template_data filter #2287
add_filter('amp_post_template_data', 'ampforwp_post_template_data');
function ampforwp_post_template_data( $data ) {
// Run through our filter
$data = apply_filters('ampforwp_post_template_data', $data );
if(false==ampforwp_get_setting('hide-amp-version-from-source')){
add_action('amp_meta','ampforwp_generator');
if ( ! function_exists('ampforwp_generator') ) {
function ampforwp_generator(){
if(true == ampforwp_get_setting('ampforwp-amp-convert-to-wp')){
<meta name="generator" content="AMP for WP <?php echo esc_attr(AMPFORWP_VERSION)?>" />
// #2497 Ivory Search Compatibility Added
add_filter('ampforwp_menu_content','ampforwp_modify_ivory_search');
if( ! function_exists(' ampforwp_modify_ivory_search ') ){
function ampforwp_modify_ivory_search($menu){
if(!class_exists('Ivory_Search')){
$dom = new DOMDocument();
if( function_exists( 'mb_convert_encoding' ) ){
$menu = mb_convert_encoding($menu, 'HTML-ENTITIES', 'UTF-8');
$menu = preg_replace( '/&.*?;/', 'x', $menu ); // multi-byte characters converted to X
libxml_use_internal_errors(true);
libxml_use_internal_errors(false);
$nodes = $dom->getElementsByTagName( 'form' );
$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( 'target' ) ) {
$node->setAttribute('target', '_top');
if ( $node->getAttribute('action')){
$action_url = $node->getAttribute('action');
$action_url = preg_replace('#^http?:#', '', $action_url);
$node->setAttribute('action', $action_url);
$menu = $dom->saveHTML();
add_action('amp_post_template_css','ampforwp_ivory_search_css');
function ampforwp_ivory_search_css(){
if(class_exists('Ivory_Search')){?>
// Font Awesome Icons added for Swift
add_action('amp_post_template_head', 'ampforwp_fontawesome_canonical_link');
function ampforwp_fontawesome_canonical_link(){
if ( ampforwp_get_setting('ampforwp_font_icon') == 'fontawesome-icons' ){ ?>
<link rel="preconnect dns-prefetch" href="//use.fontawesome.com" crossorigin>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
add_action('amp_post_template_head', 'ampforwp_set_dns_preload_urls');
function ampforwp_set_dns_preload_urls(){
// Open graph tag is not loading from the SEO framework #4399
if (function_exists('the_seo_framework') && 'seo_framework' == ampforwp_get_setting('ampforwp-seo-selection')) {
$og_tsf = \the_seo_framework();
echo $og_tsf->og_image();
echo $og_tsf->og_locale();
echo $og_tsf->og_title();
echo $og_tsf->og_image();
echo $og_tsf->og_description();
echo $og_tsf->og_sitename();
$prefetch = ampforwp_get_setting('amp-prefetch-options');
foreach ( $prefetch as $k => $value ) {
foreach ($value as $tk => $tval) {
$temp_arr['name'][] = $k;
$temp_arr['type'][] = $tk;
foreach ($tval as $ck => $cval) {
$temp_arr['value'][] = $cval;
if(isset($data_arr[0]) && !empty($data_arr)){
$val_count = count($data_arr[0]['value']);
for($i=0;$i<$val_count;$i++){
for($j=0;$j<count($data_arr);$j++){
if(isset($data_arr[$j]['value'][$i])){
$key = $data_arr[$j]['value'][$i];
if(isset($data_arr[$j+1])){
$key = $data_arr[$j]['value'][$i];
if(isset($data_arr[$j]['value'][$i])){
$value = $data_arr[$j+1]['value'][$i];
if (preg_match('/(\.jpg|\.png|\.webp)$/', $value)) {
<link rel="<?php echo esc_attr($key)?>" <?php echo $type; // XXS ok, escaped above ?> href="<?php echo esc_url($value);?>" crossorigin>
// Yoast BreadCrumbs #1473
add_action('pre_amp_render_post', 'ampforwp_yoast_breadcrumbs');
if ( ! function_exists('ampforwp_yoast_breadcrumbs') ) {
function ampforwp_yoast_breadcrumbs(){
if ( ampforwp_get_setting('ampforwp-yoast-bread-crumb') ) {
// Remove the separator of Yoast
add_filter('wpseo_breadcrumb_separator','ampforwp_yoast_breadcrumbs_sep');
function ampforwp_yoast_breadcrumbs_sep($sep) {
// Remove xmlns:v to avoid validation error
add_filter('wpseo_breadcrumb_output','ampforwp_yoast_breadcrumbs_modified_output');
function ampforwp_yoast_breadcrumbs_modified_output($output){
$output = str_replace('xmlns:v="http://rdf.data-vocabulary.org/#"', '', $output);
// Change the wrapper to div
add_filter('wpseo_breadcrumb_output_wrapper', 'ampforwp_yoast_breadcrumbs_wrapper');
function ampforwp_yoast_breadcrumbs_wrapper($wrap) {
// Add the Breadcrumbs class to wrapper
add_filter('wpseo_breadcrumb_output_class','ampforwp_yoast_breadcrumbs_wrapper_class');
function ampforwp_yoast_breadcrumbs_wrapper_class($class) {
function ampforwp_yoast_breadcrumbs_output(){
if ( class_exists('WPSEO_Options') && method_exists('WPSEO_Options', 'get') ){
if ( true == ampforwp_get_setting('ampforwp-yoast-bread-crumb') && true === WPSEO_Options::get( 'breadcrumbs-enable' ) && function_exists('yoast_breadcrumb')) {
$breadcrumb = yoast_breadcrumb('','', false);
if( true == ampforwp_get_setting('convert-internal-nonamplinks-to-amp') && preg_match('/<a\s+href="(.*?)">(.*?)<\/a>/', $breadcrumb)){
$breadcrumb = preg_replace('/<a\s+href="(.*?)\/">(.*?)<\/a>/', '<a href="$1/'.user_trailingslashit(AMPFORWP_AMP_QUERY_VAR).'">$2</a>', $breadcrumb);
// Slide Anything compatibility #2891
add_filter('amp_content_embed_handlers','ampforwp_slide_anything_embed');
function ampforwp_slide_anything_embed($data) {
if ( function_exists('cpt_slider_plugin_activation') ) {
require_once( AMPFORWP_PLUGIN_DIR. 'classes/class-ampforwp-slide-anything-embed.php' );
$data['AMPFORWP_Slide_Anything_Embed_Handler'] = array();
// Revolution Slider compatibility #1464
add_action('pre_amp_render_post', 'ampforwp_initialise_rev_slider');
if ( ! function_exists('ampforwp_initialise_rev_slider') ) {
function ampforwp_initialise_rev_slider(){
if ( class_exists('RevSliderOutput') ){
require AMPFORWP_PLUGIN_DIR .'/classes/class-ampforwp-rev-slider.php';
add_filter('amp_content_embed_handlers','ampforwp_rev_slider_embed');
function ampforwp_rev_slider_embed($data) {
if ( class_exists('RevSliderOutput') ){
$data['AMP_Rev_Slider_Embed_Handler'] = array();
// Photo Gallery by 10Web Compatibility #1811
add_action('pre_amp_render_post', 'ampforwp_initialise_photo_gallery');
if ( ! function_exists('ampforwp_initialise_photo_gallery') ) {
function ampforwp_initialise_photo_gallery(){
if ( class_exists('BWG') ) {
require AMPFORWP_PLUGIN_DIR .'/classes/class-ampforwp-photo-gallery-embed.php';
add_filter('amp_content_embed_handlers','ampforwp_photo_gallery_embed');
function ampforwp_photo_gallery_embed($data) {
if ( class_exists('BWG') ) {
$data['AMPforWP_Photo_Gallery_Embed_Handler'] = array();
function ampforwp_rel_attributes_social_links(){
$rel_attributes = array();
if (true == ampforwp_get_setting('ampforwp-social-no-follow')) {
$rel_attributes[] = 'nofollow';
if (true == ampforwp_get_setting('ampforwp-social-no-referrer')) {
$rel_attributes[] = 'noreferrer';
if (true == ampforwp_get_setting('ampforwp-social-no-opener')) {
$rel_attributes[] = 'noopener';
$rel_attributes = apply_filters('ampforwp_rel_attributes_social_links', $rel_attributes);
$rel_attributes = array_map('esc_attr', $rel_attributes);
echo 'rel="' . implode(" ",$rel_attributes).'"';
function ampforwp_nofollow_social_links(){
ampforwp_rel_attributes_social_links();
function ampforwp_nofollow_notification(){
if(true == ampforwp_get_setting('ampforwp-notifications-nofollow')){
// Featured Video SmartMag theme Compatibility CSS #2559
add_action('amp_post_template_css', 'ampforwp_featured_video_plus_css');
function ampforwp_featured_video_plus_css(){
if( function_exists('get_the_post_video') ) {?>
.fvp-onload{display:none}
if(class_exists('Bunyad')){ ?>
.amp-featured-image amp-iframe, .amp-wp-article-featured-image amp-iframe { margin:auto; height:100%; }
.f_vid { background: #000; }
function ampforwp_webp_featured_image() {
$post_id = ampforwp_get_the_ID();
if ( ! has_post_thumbnail( $post_id )) {
$thumb_id = get_post_thumbnail_id($post_id);
$image_size = apply_filters( 'ampforwp_featured_image', 'full' );
$image = wp_get_attachment_image_src( $thumb_id, $image_size );
$thumb_alt = get_post_meta( $thumb_id, '_wp_attachment_image_alt', true);
$alt = get_the_title( $post_id );
$alt = convert_chars( stripslashes( $alt ) );
$image_output = "<amp-img src='".esc_url($image[0])."' width='".esc_attr($image[1])."' height='".esc_attr($image[2])."' layout='responsive' alt='".esc_attr($alt)."' ></amp-img>";?>
if(1 == ampforwp_get_setting('amp-design-selector') || 2 == ampforwp_get_setting('amp-design-selector') || 3 == ampforwp_get_setting('amp-design-selector')){?>
<figure class="amp-wp-article-featured-image">
<?php echo $image_output; // escaped above
// Keep the default WordPress form for AMP #3000
add_filter('get_search_form', 'ampforwp_search_form');
if ( ! function_exists('ampforwp_search_form') ) {
function ampforwp_search_form($form){
if ( ampforwp_is_amp_endpoint() ) {
$placeholder = ampforwp_translation(ampforwp_get_setting('ampforwp-search-placeholder'), 'Type Here' );
if (function_exists('pll__')) {
$placeholder = pll__(esc_html__( ampforwp_get_setting('ampforwp-search-placeholder'), 'accelerated-mobile-pages'));
$widgetlabel = ampforwp_translation(ampforwp_get_setting('ampforwp-search-widget-label'), 'Search for:' );
$form = '<form role="search" method="get" id="searchform" class="search-form" action="' . esc_url( home_url( '/' ) ) . '" target="_top">
<span class="screen-reader-text">' . esc_html__( $widgetlabel, 'accelerated-mobile-pages' ) . '</span>
<input type="text" value="" placeholder="' . esc_html__( $placeholder, 'accelerated-mobile-pages' ) . '" name="s" class="search-field">
<input type="text" placeholder="' . esc_html__( $placeholder, 'accelerated-mobile-pages' ) . '" value="1" name="amp" class="hide" id="ampforwp_search_query_item">
//Saving all taxonomies in Transient
add_action('init','ampforwp_generate_taxonomies_transient');
function ampforwp_generate_taxonomies_transient(){
$taxonomies = get_transient('ampforwp_get_taxonomies');
$output = 'objects'; // or objects
$operator = 'and'; // 'and' or 'or'
$alltaxonomies = get_taxonomies( $args, $output, $operator );
foreach ($alltaxonomies as $taxKey => $taxVal) {
$tax_arr[$taxVal->name] = $taxVal->labels->singular_name;
if ( false == $taxonomies ) {
set_transient('ampforwp_get_taxonomies',$tax_arr);
if(count($tax_arr) > count($taxonomies)){
$result = array_diff_assoc($tax_arr,$taxonomies);
}elseif( count($taxonomies) > count($tax_arr)){
$result = array_diff_assoc($taxonomies,$tax_arr);
delete_transient('ampforwp_get_taxonomies');
// Include Opengraph.php #3261
add_action('pre_amp_render_post', 'ampforwp_include_opengraph');
if ( ! function_exists('ampforwp_include_opengraph') ) {
function ampforwp_include_opengraph(){
if ( true == ampforwp_get_setting('ampforwp-seo-og-meta-tags') && '' == ampforwp_get_setting('ampforwp-seo-selection') ) {
require_once AMPFORWP_PLUGIN_DIR."includes/features/opengraph.php";
add_action('wp_ajax_ampforwp_import_file_from_file','ampforwp_import_settings_from_file');
function ampforwp_import_settings_from_file(){
$security = $_POST['security'];
if ( wp_verify_nonce( $security, 'ampforwp_import_file' ) && current_user_can( 'manage_options' ) ) {
if(isset($_FILES["file"]["tmp_name"])){
$content = file_get_contents($_FILES["file"]["tmp_name"]);
if ( ! empty ( $content ) ) {
$imported_options = json_decode( $content, true );
$plugin_options = get_option('redux_builder_amp');
if ( ! empty ( $imported_options ) && is_array( $imported_options ) && isset ( $imported_options['redux-backup'] ) && $imported_options['redux-backup'] == '1' ) {
add_filter('ampforwp_loop_image_update','ampforwp_recentpost_link_to_nonamp');
function ampforwp_recentpost_link_to_nonamp($image_link_data){
if( true == ampforwp_get_setting('ampforwp-recentpost-posts-link') ){
$image_link_data['image_link'] = get_permalink();
$image_link_data['image_link'] = ampforwp_url_controller( get_permalink() ) ;
#3596 link to nonamp option on title for recent posts
add_filter('ampforwp_loop_permalink_update','ampforwp_recentpost_title_link_to_nonamp');
function ampforwp_recentpost_title_link_to_nonamp($title_link){
if( true == ampforwp_get_setting('ampforwp-recentpost-posts-link') ){
$title_link = get_permalink();
$title_link = ampforwp_url_controller( get_permalink() ) ;
// Post Meta Revisions #3548 -- start here --
add_filter( '_wp_post_revision_field_amp_page_builder', 'ampforwp_meta_revi_pb_field', 22, 2 );
add_action( 'save_post', 'ampforwp_meta_revi_save_post', 10, 2 );
add_action( 'wp_restore_post_revision', 'ampforwp_meta_restore_revision', 10, 2 );
add_filter( '_wp_post_revision_fields', 'ampforwp_meta_revi_fields' );
// Displaying the meta field on the revisions screen
function ampforwp_meta_revi_fields( $fields ) {
$fields['post_title'] = 'Title';
$fields['post_content'] = 'Content';
$fields['post_excerpt'] = 'Excerpt';
$fields['amp-page-builder'] = 'AMP Page Builder';
// Displaying the meta field on the revisions screen
function ampforwp_meta_revi_pb_field( $value, $field ) {
return get_metadata( 'post', $revision->ID, $field, true );
// Reverting to the correct revision of the meta field when a post is reverted
function ampforwp_meta_restore_revision( $post_id, $revision_id ) {
if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) {
$post = get_post( $post_id );
$revision = get_post( $revision_id );
$meta = get_metadata( 'post', $revision->ID, 'amp-page-builder', true );
delete_post_meta( $post_id, 'amp-page-builder' );