: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
// 58. YouTube Shortcode compatablity with AMP #557 #971
add_filter('amp_content_embed_handlers','ampforwp_youtube_shortcode_embedder');
function ampforwp_youtube_shortcode_embedder($data){
unset($data['AMP_YouTube_Embed_Handler']);
$data[ 'AMPforWP_YouTube_Embed_Handler' ] = array();
if ( ! function_exists( 'ampforwp_youtube_shortcode') ) {
function ampforwp_youtube_shortcode( $params, $old_format_support = false ) {
$youtube_url = 'https://www.youtube.com/watch?v=';
if(isset( $params['id']) ){
$parsed_url = parse_url( $params['id'] );
$server = 'www.youtube.com';
if ( in_array( $server, $parsed_url ) === false ) {
if(isset($params['id']) && $params['id']){
$new_url = $youtube_url . $params['id'] ;
$params['id'] = $new_url;
if ( $old_format_support && isset( $params[0] ) ) {
$str = ltrim( $params[0], '=' );
} elseif ( is_array( $params ) ) {
foreach ( array_keys( $params ) as $key ) {
if ( ! is_numeric( $key ) ) {
$str = $key . '=' . $params[ $key ];
return str_replace( array( '&', '&' ), '&', $str );
// Add extra params in amp-youtube
add_filter('amp_youtube_params', 'ampforwp_youtube_modified_params');
if( ! function_exists(' ampforwp_youtube_modified_params ') ){
function ampforwp_youtube_modified_params($amp_youtube){
// Check for extra params
$check = preg_match('/(.*?)&(.*)/', $amp_youtube['data-videoid']);
$param = preg_replace('/(.*?)&(.*)/', '$2', $amp_youtube['data-videoid']);
// Parse the string into variables
parse_str($param, $query_args);
if(isset($query_args['rel'])){
// Add the rel param in amp-youtube's data-param
$amp_youtube['data-param-rel'] = $query_args['rel'];
// Remove that param from URL
$amp_youtube['data-videoid'] = preg_replace('/&(.*)/', '', $amp_youtube['data-videoid']);
// Plyr Plugin Compatibility #1505
if ( class_exists('Plyr') ) {
$amp_youtube['data-param-rel'] = 0;
$amp_youtube['data-param-autoplay'] = 0;
$amp_youtube['data-param-showinfo'] = 0;
// 59. Comment Button URL
function ampforwp_comment_button_url(){
global $redux_builder_amp;
if(ampforwp_get_setting('amp-mobile-redirection')==1){
$button_url = add_query_arg( array( 'nonamp' => '1' ), get_permalink() );
$button_url = $button_url. '#commentform';
elseif ( ampforwp_get_setting('ampforwp-amp-takeover') ) {
$button_url = user_trailingslashit(get_the_permalink()).'#comments';
$button_url = get_permalink(). '#commentform';
return esc_url( apply_filters( 'ampforwp_comment_button_url', $button_url ) );
// 60. Remove Category Layout modification code added by TagDiv #842 and #796
add_action('pre_amp_render_post', 'ampforwp_remove_tagdiv_category_layout');
function ampforwp_remove_tagdiv_category_layout(){
if ( function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() ) {
remove_action('pre_get_posts', 'td_modify_main_query_for_category_page',9);
add_shortcode('amp-gist', 'ampforwp_gist_shortcode_generator');
function ampforwp_gist_shortcode_generator($atts) {
extract(shortcode_atts(array(
'layout' => 'fixed-height',
if ( empty ( $height ) ) {
// adding sanitization for gist id
$sanitized_id = preg_replace('/[^a-z0-9\-]/', '', $atts['id']);
return '<amp-gist data-gistid='. esc_attr($sanitized_id) .'
height="'. esc_attr($height) .'">
// Code updated and added the JS proper way #336
add_filter('amp_post_template_data','ampforwp_add_amp_gist_script', 100);
function ampforwp_add_amp_gist_script( $data ){
global $redux_builder_amp;
$content = $data['post'];
$content = $content->post_content;
if( has_shortcode( $content, 'amp-gist' ) ){
if ( empty( $data['amp_component_scripts']['amp-gist'] ) ) {
$data['amp_component_scripts']['amp-gist'] = 'https://cdn.ampproject.org/v0/amp-gist-0.1.js';
// 62. Adding Meta viewport via hook instead of direct #878
add_action( 'amp_post_template_head','ampforwp_add_meta_viewport', 9);
function ampforwp_add_meta_viewport() {
$output = '<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=2,user-scalable=yes">
if (ampforwp_get_setting('ampforwp-meta-viewport') == false) {
$output = '<meta name="viewport" content="width=device-width">';
if(!class_exists( 'AMPforWP_Mobile_Detect') && !ampforwp_get_setting('amp-mobile-redirection')){
ampforwp_require_file( AMPFORWP_PLUGIN_DIR.'/includes/vendor/Mobile_Detect.php ');
if(class_exists('AMPforWP_Mobile_Detect')){
$mobile_detect = new AMPforWP_Mobile_Detect;
$isMobile = $mobile_detect->isMobile();
$isTablet = $mobile_detect->isTablet();
if( $isMobile || $isTablet ){
$output = '<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,user-scalable=yes">';
$output .= '<meta name="referrer" content="no-referrer-when-downgrade">';
echo apply_filters('ampforwp_modify_meta_viewport_filter',$output);
// 63. Frontpage Comments #682
function ampforwp_frontpage_comments() {
global $redux_builder_amp;
$data = get_option( 'ampforwp_design',array());
$enable_comments = false;
$post_id = ampforwp_get_frontpage_id();
$data['elements'] = "meta_info:1,title:1,featured_image:1,content:1,meta_taxonomy:1,social_icons:1,comments:1,related_posts:1";
if( isset( $data['elements'] ) || ! empty( $data['elements'] ) ){
$options = explode( ',', $data['elements'] );
if ($options): foreach ($options as $key=>$value) {
if ( $enable_comments ) { ?>
<div class="ampforwp-comment-wrapper">
$comment_button_url = "";
// Gather comments for a Front from post id
$postID = ampforwp_get_frontpage_id();
$comment_order = get_option( 'comment_order' );
$comments = get_comments(array(
'order' => esc_attr($comment_order),
'status' => 'approve' //Change this to the type of comments to be displayed
$comment_button_url = get_permalink( $post_id );
$comment_button_url = apply_filters('ampforwp_frontpage_comments_url',$comment_button_url );
<div class="amp-wp-content comments_list cmts_list">
<h3><?php global $redux_builder_amp; echo esc_html(ampforwp_translation($redux_builder_amp['amp-translator-view-comments-text'] , 'View Comments' ))?></h3>
$page = (get_query_var('page')) ? get_query_var('page') : 1;
$total_comments = get_comments( array(
'orderby' => 'post_date' ,
$pages = ceil(count($total_comments)/AMPFORWP_COMMENTS_PER_PAGE);
$pagination_args = array(
'base' => @add_query_arg('page','%#%'),
'prev_text' => ampforwp_translation($redux_builder_amp['amp-translator-previous-text'], 'Previous'),
'next_text' => ampforwp_translation( $redux_builder_amp['amp-translator-next-text'], 'Next'),
// Display the list of comments
function ampforwp_custom_translated_comment($comment, $args, $depth){
$GLOBALS['comment'] = $comment;
global $redux_builder_amp; ?>
<li id="li-comment-<?php esc_attr(comment_ID()) ?>"
<?php comment_class(); ?> >
<article id="comment-<?php esc_attr(comment_ID()); ?>" class="cmt-body">
<footer class="cmt-meta">
<div class="cmt-author vcard">
printf('<b class="fn">%s</b> <span class="says">'.esc_html(ampforwp_translation(ampforwp_get_setting('amp-translator-says-text'),'says')).':</span>', get_comment_author_link()) ?>
<div class="cmt-metadata">
<a href="<?php echo esc_url(untrailingslashit( htmlspecialchars( get_comment_link( $comment->comment_ID ) ) )) ?>">
<?php printf( esc_html(ampforwp_translation( ('%1$s '. ampforwp_translation($redux_builder_amp['amp-translator-at-text'],'at').' %2$s'), '%1$s at %2$s')) , get_comment_date(), get_comment_time())?>
<?php edit_comment_link( esc_html(ampforwp_translation( $redux_builder_amp['amp-translator-Edit-text'], 'Edit' ) )) ?>
<!-- .comment-metadata -->
<div class="cmt-content">
// $pattern = "~[^a-zA-Z0-9_ !@#$%^&*();\\\/|<>\"'+.,:?=-]~";
$emoji_content = get_comment_text();
// $emoji_free_comments = preg_replace($pattern,'',$emoji_content);
$emoji_content = wpautop( $emoji_content );
$sanitizer = new AMPFORWP_Content( $emoji_content, array(), apply_filters( 'ampforwp_content_sanitizers', array( 'AMP_Img_Sanitizer' => array(),
'AMP_Video_Sanitizer' => array() ) ) );
$sanitized_comment_content = $sanitizer->get_amp_content();
echo make_clickable( $sanitized_comment_content );//amphtml content, no kses
<!-- .comment-content -->
}// end of ampforwp_custom_translated_comment()
'per_page' => AMPFORWP_COMMENTS_PER_PAGE, //Allow comment pagination
'callback' => 'ampforwp_custom_translated_comment',
'reverse_top_level' => false //Show the latest comments at the top of the list
echo paginate_links( $pagination_args );?>
if ( comments_open($postID) ) {
$comment_button_url = add_query_arg( array( 'nonamp' => '1' ), $comment_button_url );?>
<div class="cmt-button-wrapper">
<a href="<?php echo esc_url( $comment_button_url ) . '#commentform' ?>" rel="nofollow"><?php echo esc_html(ampforwp_translation( $redux_builder_amp['amp-translator-leave-a-comment-text'], 'Leave a Comment' )); ?></a>
add_action('pre_amp_render_post','ampforwp_apply_layout_builder_on_pages',20);
function ampforwp_apply_layout_builder_on_pages($post_id) {
global $redux_builder_amp;
if ( ampforwp_is_front_page() ) {
$post_id = ampforwp_get_frontpage_id();
if ( function_exists('ampforwp_custom_theme_files_register') ) {
$sidebar_check = get_post_meta( $post_id,'ampforwp_custom_sidebar_select',true);
// Add Styling Builder Elements
add_action('amp_post_template_css', 'ampforwp_pagebuilder_styling', 20);
if ( 'layout-builder' == $sidebar_check ) {
// Removed Titles for Pagebuilder elements
remove_filter( 'ampforwp_design_elements', 'ampforwp_add_element_the_title' );
remove_action('ampforwp_design_2_frontpage_title','ampforwp_design_2_frontpage_title');
remove_action('ampforwp_design_2_frontpage_title','ampforwp_design_2_frontpage_title');
function ampforwp_remove_post_elements($elements) {
$elements = array('empty-filter');
function ampforwp_pagebuilder_styling() { ?>
.amp_cb_module{font-size:14px;line-height:1.5;margin-top:30px;margin-bottom:10px;padding:0 20px;}
.amp_cb_module h4{margin:17px 0 6px 0;}
.amp_cb_module p{margin: 8px 0px 10px 0px;}
.amp_cb_blurb{text-align: center}
.amp_cb_blurb amp-img{margin:0 auto;}
.flex-grid {display:flex;justify-content: space-between;}
.amp_module_title{text-align: center;font-size: 14px;margin-bottom: 12px;padding-bottom: 4px;text-transform: uppercase;letter-spacing: 1px;border-bottom: 1px solid #f1f1f1;}
.clmn {flex: 1;padding: 5px}
.amp_cb_btn{margin-top: 20px;text-align: center;margin-bottom: 30px;}
.amp_cb_btn a{background: #f92c8b;color: #fff;font-size: 14px;padding: 9px 20px;border-radius: 3px;box-shadow: 1px 1px 4px #ccc;margin:6px;}
.amp_cb_btn .m_btn{font-size: 16px; padding: 10px 20px;}
.amp_cb_btn .l_btn{font-size: 18px; padding: 15px 48px;font-weight:bold;}
@media (max-width: 430px) { .flex-grid {display: block;} }
// Add the scripts and style in header
function ampforwp_generate_pagebuilder_data() {
$non_sanitized_sidebar = "";
dynamic_sidebar( 'layout-builder' );
$non_sanitized_sidebar = ob_get_contents();
$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_Instagram_Embed_Handler' => array(),
'AMP_Vine_Embed_Handler' => array(),
'AMP_Facebook_Embed_Handler' => array(),
'AMP_Gallery_Embed_Handler' => array(),
'AMP_Tiktok_Embed_Handler'=>array(),
apply_filters( 'amp_content_sanitizers', array(
'AMP_Style_Sanitizer' => array(),
'AMP_Blacklist_Sanitizer' => array(),
'AMP_Img_Sanitizer' => array(),
'AMP_Video_Sanitizer' => array(),
'AMP_Audio_Sanitizer' => array(),
'AMP_Iframe_Sanitizer' => array(
'add_placeholder' => true,
$sidebar_data['content'] = $sanitized_sidebar->get_amp_content();
$sidebar_data['script'] = $sanitized_sidebar->get_amp_scripts();
$sidebar_data['style'] = $sanitized_sidebar->get_amp_styles();
function ampforwp_builder_checker() {
global $post, $redux_builder_amp;
$is_legacy_enabled = function_exists('ampforwp_custom_theme_files_register');
if ( ampforwp_is_front_page() ) {
$post_id = ampforwp_get_frontpage_id();
if ( $post_id && $is_legacy_enabled ) {
$pagebuilder_check = get_post_meta( $post_id,'ampforwp_custom_sidebar_select',true);
if ( $pagebuilder_check === 'layout-builder' ) {
return ampforwp_generate_pagebuilder_data();
add_filter( 'amp_post_template_data', 'ampforwp_add_pagebuilder_data' );
function ampforwp_add_pagebuilder_data( $data ) {
$sanitized_data = ampforwp_builder_checker();
$data[ 'post_amp_content' ] = $sanitized_data['content'];
$data[ 'amp_component_scripts' ] = $sanitized_data['script'];
$data[ 'post_amp_styles' ] = $sanitized_data['style'];
* 65. Remove Filters code added through Class by other plugins
* Allow to remove method for an hook when, it's a class method used and class don't have variable, but you know the class name :)
* Code from https://github.com/herewithme/wp-filters-extras
function ampforwp_remove_filters_for_class( $hook_name = '', $class_name ='', $method_name = '', $priority = 0 ) {
// Take only filters on right hook name and priority
if ( !isset($wp_filter[$hook_name][$priority]) || !is_array($wp_filter[$hook_name][$priority]) )
// Loop on filters registered
foreach( (array) $wp_filter[$hook_name][$priority] as $unique_id => $filter_array ) {
// Test if filter is an array ! (always for class/method)
if ( isset($filter_array['function']) && is_array($filter_array['function']) ) {
// Test if object is a class, class and method is equal to param !
if ( is_object($filter_array['function'][0]) && get_class($filter_array['function'][0]) && get_class($filter_array['function'][0]) == $class_name && $filter_array['function'][1] == $method_name ) {
// Test for WordPress >= 4.7 WP_Hook class (https://make.wordpress.org/core/2016/09/08/wp_hook-next-generation-actions-and-filters/)
if( is_a( $wp_filter[$hook_name], 'WP_Hook' ) ) {
unset( $wp_filter[$hook_name]->callbacks[$priority][$unique_id] );
unset($wp_filter[$hook_name][$priority][$unique_id]);
// BuddyPress Compatibility
add_action('amp_init','ampforwp_allow_homepage_bp');
function ampforwp_allow_homepage_bp() {
add_action( 'wp', 'ampforwp_remove_rel_on_bp' );
function ampforwp_remove_rel_on_bp(){
if(function_exists('bp_is_activity_component')||function_exists('bp_is_members_component')||function_exists('bp_is_groups_component'))
if(bp_is_activity_component()|| bp_is_members_component() || bp_is_groups_component()){
remove_action( 'wp_head', 'amp_frontend_add_canonical');
remove_action( 'wp_head', 'ampforwp_home_archive_rel_canonical', 1 );
// Removing AMP from WPForo Forums Pages #592
if(class_exists('wpForo')){
$foid = ampforwp_get_the_ID();
remove_action( 'wp_head', 'amp_frontend_add_canonical');
remove_action( 'wp_head', 'ampforwp_home_archive_rel_canonical', 1 );
// 66. Make AMP compatible with Squirrly SEO
add_action('pre_amp_render_post','ampforwp_remove_sq_seo');
function ampforwp_remove_sq_seo() {
$ampforwp_sq_google_analytics = '';
$ampforwp_sq_amp_analytics = '';
if ( class_exists( 'SQ_Tools' ) ) {
$ampforwp_sq_google_analytics = SQ_Tools::$options['sq_google_analytics'];
$ampforwp_sq_amp_analytics = SQ_Tools::$options['sq_auto_amp'];
if ( $ampforwp_sq_google_analytics && $ampforwp_sq_amp_analytics ) {
remove_action('amp_post_template_head','ampforwp_register_analytics_script', 20);
function ampforwp_view_nonamp(){
global $redux_builder_amp, $post, $wp;