: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$current_url_in_pieces = array();
if(is_home() && get_option('show_on_front') == 'page' ) {
$current_url = home_url( $GLOBALS['wp']->request );
$current_url_in_pieces = explode( '/', $current_url );
$page_for_posts = get_option( 'page_for_posts' );
$post = get_post($page_for_posts);
$slug = $post->post_name;
$title = $post->post_title;
if( in_array( $slug , $current_url_in_pieces , true ) || get_query_var('page_id') == $blog_id ) {
// 56. Multi Translation Feature #540
function ampforwp_translation( $redux_style_translation , $pot_style_translation ) {
$single_translation_enabled = ampforwp_get_setting('amp-use-pot');
if ( !$single_translation_enabled ) {
return $redux_style_translation;
if(!empty($redux_style_translation)){
$pot_style_translation = $redux_style_translation;
return __($pot_style_translation,'accelerated-mobile-pages');
function ampforwp_end_point_controller( $url, $check='' ) {
global $redux_builder_amp;
$endpoint = AMPFORWP_AMP_QUERY_VAR;
$endpoint = '?' . $endpoint;
if ( isset($redux_builder_amp['amp-core-end-point']) && true == $redux_builder_amp['amp-core-end-point'] ) {
$url = untrailingslashit($url.$endpoint);
$url = $url . user_trailingslashit( AMP_QUERY_VAR, 'single_amp' );
if ( ! function_exists( 'ampforwp_isexternal ') ) {
function ampforwp_isexternal($url) {
$components = parse_url($url);
// we will treat url like '/relative.php' as relative
if ( empty($components['host']) ) return false;
// url host looks exactly like the local host
if ( strcasecmp($components['host'], AMPFROWP_HOST_NAME) === 0 ) return false;
// check if the url host is a subdomain
$check = strrpos(strtolower($components['host']), $_SERVER['HTTP_HOST']) !== strlen($components['host']) - strlen($_SERVER['HTTP_HOST']);// #3561 - it's returing empty that is why it's creating broken link. So checking empty condition and returning 1 to not create amp link.
} // end ampforwp_isexternal
if(!function_exists('ampforwp_findInternalUrl')){
function ampforwp_findInternalUrl($url){
if(function_exists('googlesitekit_activate_plugin')){
if(strpos($url, '_gl') !== false){
$url = remove_query_arg( '_gl', $url);
//remove ? from jump links.
if(strpos($url, '?#') === 0){
$url = str_replace('?#', '#', $url);
global $redux_builder_amp;
if(isset($redux_builder_amp['convert-internal-nonamplinks-to-amp']) && ! $redux_builder_amp['convert-internal-nonamplinks-to-amp']){
$get_skip_media_path = array();
$skip_media_extensions = array();
$get_skip_media_path = pathinfo($url);
$skip_media_extensions = array('jpg','jpeg','gif','png');
if ( isset( $get_skip_media_path['extension'] ) && !empty($get_skip_media_path['extension'])){
if (! in_array( $get_skip_media_path['extension'], $skip_media_extensions ) && !strpos(get_option( 'permalink_structure' ), $get_skip_media_path['extension'])){
$skip_media_extensions[] = $get_skip_media_path['extension'];
$skip_media_extensions = apply_filters( 'ampforwp_internal_links_skip_media', $skip_media_extensions );
if ( isset( $get_skip_media_path['extension'] ) ){
if( in_array( $get_skip_media_path['extension'], $skip_media_extensions ) ) {
if ( false !== strpos($url, '#') && false === ampforwp_is_amp_inURL($url) && !ampforwp_isexternal($url) ) {
$url_array = explode('#', $url);
if ( !empty($url_array) && '' !== $url_array[0]) {
$url = ampforwp_url_controller($url_array[0]).'#'.$url_array[1];
if( false === wp_http_validate_url($url) ) {
if(!ampforwp_isexternal($url) && ampforwp_is_amp_inURL($url)===false){
// Skip the URL's that have edit link to it
$parts = parse_url($url);
if ( isset($parts['query']) && $parts['query']) {
parse_str($parts['query'], $query);
if ( (isset( $query['action'] ) && $query['action']) || (isset( $query['amp'] ) && $query['amp'] ) ) {
$qmarkAmp = (isset($redux_builder_amp['amp-core-end-point']) ? $redux_builder_amp['amp-core-end-point']: false );//amp-core-end-point
$url = add_query_arg( 'amp', '1', $url);
if ( get_option('permalink_structure') ) {
if ( strpos($url, "?") && strpos($url, "=") ){
$url = explode('?', $url);
$url = ampforwp_url_controller($url[0]).'?'.$url[1];
$url = ampforwp_url_controller($url);
$url = add_query_arg( 'amp', '1', $url );
} // end ampforwp_findInternalUrl
/* AMPforWP allowed html tags #1950
* ampforwp_wp_kses_allowed_html()
* This fucntion can be heavy for sanitizing items.
* As it scans though all the generated AMP tags and attributes.
function ampforwp_wp_kses_allowed_html(){
$allowed_html = $allowed_normal_html = $allowed_amp_tags = array();
$allowed_normal_html = wp_kses_allowed_html( 'post' );
if ( class_exists('AMP_Allowed_Tags_Generated') ) {
$allowed_amp_tags = AMP_Allowed_Tags_Generated::get_allowed_tags();
$allowed_atts = AMP_Allowed_Tags_Generated::get_allowed_attributes();
foreach ($allowed_atts as $att => $value) {
$allowed_atts[$att] = true;
foreach ($allowed_amp_tags as $amp_tag => $values ) {
$allowed_amp_tags[$amp_tag] = $allowed_atts;
$allowed_html = array_merge_recursive($allowed_normal_html, $allowed_amp_tags);
foreach ( $allowed_html as $tag => $atts ) {
unset($allowed_html[$tag]['style']);
$allowed_html[$tag]['data-toggle'] = true;
$allowed_html[$tag]['aria-label'] = true;
if ( 'amp-img' == $tag ) {
$allowed_html[$tag] = array('width'=>true,'height'=>true,'src'=>true,'layout'=>true,'alt'=>true,'on'=>true,'role'=>true,'tabindex'=>true);
$allowed_html['input'] = array('class'=>true,'type'=>true,'id'=>true,'placeholder'=>true,'value'=>true,'name'=>true);
function ampforwp_wp_kses($data){
$allowed_html = ampforwp_wp_kses_allowed_html();
$data = wp_kses( stripslashes( $data ), $allowed_html );
//93. added AMP url purifire for amphtml
function ampforwp_url_purifier($url){
global $wp_query,$wp,$redux_builder_amp;
$get_permalink_structure = "";
$wpml_lang_checker = true;
$endpoint = AMPFORWP_AMP_QUERY_VAR;
$get_permalink_structure = get_option('permalink_structure');
$checker = isset($redux_builder_amp['amp-core-end-point']) ? $redux_builder_amp['amp-core-end-point'] : false;
$endpointq = '?' . $endpoint;
if ( empty( $get_permalink_structure ) ) {
if ( is_home() || is_archive() || is_front_page() ) {
$url = add_query_arg(AMPFORWP_AMP_QUERY_VAR,'1', $url);
if ( is_home() && get_query_var('page_id') == ampforwp_get_blog_details('id') ) {
$quried_value = get_query_var('page_id');
if ( '' != $quried_value)
$url = add_query_arg('page_id',$quried_value, $url);
if ( get_query_var('paged') >= 2 ) {
$quried_value = get_query_var('paged');
$url = add_query_arg('paged',$quried_value, $url);
$quried_value = get_query_var($queried_var);
$url = add_query_arg($queried_var,$quried_value, $url);
if ( is_singular() && true == $checker ) {
$url = untrailingslashit($url);
if( class_exists('SitePress') ){
if( get_option('permalink_structure') ){
global $sitepress_settings, $wp;
$wpml_lang_checker = false;
if($sitepress_settings[ 'language_negotiation_type' ] == 3){
$active_langs = $sitepress_settings['active_languages'];
$wpml_url =get_permalink( get_queried_object_id() );
$untrail_wpml_url = untrailingslashit($wpml_url);
$explode_url = explode('/', $untrail_wpml_url);
$append_amp = AMPFORWP_AMP_QUERY_VAR;
foreach ($active_langs as $active_lang) {
foreach($explode_url as $a) {
if (stripos('?lang='.$active_lang ,$a) !== false){
$url = add_query_arg('amp','1',$wpml_url);
array_splice( $explode_url, count($explode_url), 0, $append_amp );
$impode_url = implode('/', $explode_url);
$url = user_trailingslashit($impode_url);
if ( is_home() || is_archive() ){
$current_archive_url = home_url( $wp->request );
$explode_path = explode("/",$current_archive_url);
$inserted = array(AMPFORWP_AMP_QUERY_VAR);
$query_arg_array = $wp->query_vars;
if( array_key_exists( 'paged' , $query_arg_array ) ) {
$active_langs = $sitepress_settings['active_languages'];
foreach ($active_langs as $active_lang) {
foreach($explode_path as $a) {
if (stripos('?lang='.$active_lang ,$a) !== false){
$url = add_query_arg('amp','1',$current_archive_url);
array_splice( $explode_path, count($explode_path), 0, $inserted );
$impode_url = implode('/', $explode_path);
$url = user_trailingslashit($impode_url);
$active_langs = $sitepress_settings['active_languages'];
foreach ($active_langs as $active_lang) {
foreach($explode_path as $a) {
if (stripos('?lang='.$active_lang ,$a) !== false){
$url = add_query_arg('amp','1',$current_archive_url);
array_splice( $explode_path, count($explode_path), 0, $inserted );
$impode_url = implode('/', $explode_path);
$wpml_lang_checker = true;
$active_langs = $sitepress_settings['active_languages'];
foreach ($active_langs as $active_lang) {
if (preg_match('/\?lang='.$active_lang.'/', $url)){
$url = str_replace('&amp=1', '', $url);
if(false == ampforwp_get_setting('amp-core-end-point')){
$url = str_replace('?lang='.$active_lang, 'amp/', $url);
$url = str_replace('?lang='.$active_lang, '?amp=1', $url);
$url = add_query_arg( 'lang',$active_lang, $url);
if ( true == $wpml_lang_checker && ( is_home() || is_archive() || is_front_page() ) ) {
if ( ( is_archive() || is_home() ) && get_query_var('paged') > 1 ) {
$url = trailingslashit($url).$endpointq;
$url = user_trailingslashit( trailingslashit($url) );
if ( true == $checker && false == strpos($url, $endpointq) )
$url = trailingslashit($url) . $endpointq;
$checker = explode('/', $url);
$amp_check = in_array($endpoint, $checker);
if ( false == $amp_check ) {
$url = user_trailingslashit( trailingslashit($url) . $endpoint );
if ( true == $amp_check ) {
$url = user_trailingslashit( trailingslashit($url) . $endpoint);
if ( is_singular() && !empty($_SERVER['QUERY_STRING']) ) {
$query_arg = wp_parse_args($_SERVER['QUERY_STRING']);
$query_name = isset($wp_query->query['name'])?$wp_query->query['name']:'';
$query_name = isset($wp_query->query['pagename'])?$wp_query->query['pagename']:'';
if ( $query_name && isset( $query_arg['q'] ) ){
$url = add_query_arg( $query_arg, $url);
return apply_filters( 'ampforwp_url_purifier', $url );
// 98. Create Dynamic url of amp according to the permalink structure #1318
function ampforwp_url_controller( $url, $nonamp = '' ) {
global $redux_builder_amp;
$non_amp = apply_filters( 'ampforwp_non_amp_links', $non_amp );
$get_permalink_structure = "";
if(function_exists('ampforwp_mobile_redirect_preseve_link')){
$mob_pres_link = ampforwp_mobile_redirect_preseve_link();
if ( ampforwp_amp_nonamp_convert("", "check") || ($mob_pres_link == true || true == ampforwp_get_setting('ampforwp-amp-takeover'))) {
if ( isset($nonamp) && 'nonamp' == $nonamp ) {
$get_permalink_structure = get_option('permalink_structure');
if ( $get_permalink_structure ) {
if(true == ampforwp_get_setting('amp-core-end-point')){
$new_url = user_trailingslashit($url);
$new_url = add_query_arg( 'amp', '', $new_url );
$new_url = user_trailingslashit( trailingslashit( $url ) . AMPFORWP_AMP_QUERY_VAR);
// WPML COMPATIBILITY FOR LOOP
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' )){
global $sitepress_settings,$wp;
if($sitepress_settings[ 'language_negotiation_type' ] == 3){
$current_archive_url = untrailingslashit($url);
$explode_path = explode("/",$current_archive_url);
$inserted = array(AMPFORWP_AMP_QUERY_VAR);
$query_arg_array = $wp->query_vars;
$active_langs = $sitepress_settings['active_languages'];
foreach ($active_langs as $active_lang) {
foreach($explode_path as $a) {
if (stripos('?lang='.$active_lang ,$a) !== false){
$new_url = add_query_arg('amp','1',$current_archive_url);
array_splice( $explode_path, count($explode_path), 0, $inserted );
$impode_url = implode('/', $explode_path);
$new_url = add_query_arg( 'amp', '1', $url );
return esc_url( apply_filters( 'ampforwp_url_controller', $new_url ) );
// Function ampforwp_amp_nonamp_convert
if(!function_exists('ampforwp_amp_nonamp_convert')){
function ampforwp_amp_nonamp_convert($ampData, $type=""){
return ampforwp_is_non_amp('non_amp_check_convert');
if(!ampforwp_is_non_amp('non_amp_check_convert')){
$returnData = str_replace(array(
'on="tap:ampforwpConsent.dismiss"',
'<div id="post-consent-ui"',
'on="tap:ampforwpConsent.reject"',
'on="tap:ampforwpConsent.accept"'
"<style type=\"text/css\">",
'onClick="ampforwp_gdrp_set()"',
function ampforwp_gdpr_getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
function ampforwp_gdpr(){
if(ampforwp_gdpr_getCookie(\'ampforwpcookie\') == \'1\'){document.getElementById(\'gdpr_c\').remove();}
function ampforwp_gdrp_set(){document.getElementById(\'ampforwpConsent\').remove(); document.cookie = \'ampforwpcookie=1;expires;path=/\';}
</script><div id="post-consent-ui"',
'onClick="ampforwp_gdrp_set()"',
'onClick="ampforwp_gdrp_set()"',
if( false !== strpos($returnData, 'amp-carousel') ) {
$galleryCss = '* {box-sizing: border-box}.mySlides{display: none}
/* Slideshow container */
/* Next & previous buttons */
.nonamp-prev, .nonamp-next {