<commit_before><?php
function ampforwp_page_template_redirect() {
	global $redux_builder_amp;
	if($redux_builder_amp['amp-mobile-redirection']){

    if( wp_is_mobile() && $_SESSION['isAMPforWPmobileRedirectON']=='mobile-on' && $_GET['isAMPforWPmobileRedirectLogout']==1){
      if ( ampforwp_is_amp_endpoint() ) {
        //do nothing
        session_destroy();
      }
    }

		if ( wp_is_mobile()) {
      session_start();
      $_SESSION['isAMPforWPmobileRedirectON']='mobile-on';
			if ( ampforwp_is_amp_endpoint() ) {
				return;
			} else {
        if( !isset($_SESSION['isAMPforWPmobileRedirectON']) || !isset($_GET['isAMPforWPmobileRedirectLogout']) ){
        session_start();
        $_SESSION['isAMPforWPmobileRedirectON']='mobile-on';
        if ( is_home() ) {
					wp_redirect( trailingslashit( esc_url( home_url() ) ) . AMP_QUERY_VAR ,  301 );
					exit();
				}
        elseif ( is_archive() ) {
          global $wp;
          $current_archive_url = home_url( $wp->request );
          wp_redirect( trailingslashit( esc_url( $current_archive_url ) ) . AMP_QUERY_VAR , 301 );
          exit();
				} else {
					wp_redirect( trailingslashit( esc_url( ( get_permalink( $id ) ) ) ) . AMP_QUERY_VAR , 301 );
					exit();
				}
			}
      }
		}
	}
}

add_action( 'template_redirect', 'ampforwp_page_template_redirect', 30 );<commit_msg>redirection loop fixed finally :)<commit_after><?php
function ampforwp_page_template_redirect() {
	global $redux_builder_amp;
	if($redux_builder_amp['amp-mobile-redirection']){


if( $_SESSION['isAMPforWPmobileRedirectON']=='mobile-on' && $_SESSION['ampforwp_mobile']=='exit'){
  return;
}
    if( wp_is_mobile() && $_SESSION['isAMPforWPmobileRedirectON']=='mobile-on' && $_GET['isAMPforWPmobileRedirectLogout']==1){
      // non mobile session variable creation
      session_start();
      $_SESSION['ampforwp_mobile']='exit';
      if ( ampforwp_is_amp_endpoint() ) {
        session_destroy();
      }
    }

		if ( wp_is_mobile()) {

      $_SESSION['isAMPforWPmobileRedirectON']='mobile-on';
			if ( ampforwp_is_amp_endpoint() ) {
				return;
			} else {
        if( !isset($_SESSION['isAMPforWPmobileRedirectON']) || !isset($_GET['isAMPforWPmobileRedirectLogout']) ){
        $_SESSION['isAMPforWPmobileRedirectON']='mobile-on';
        if ( is_home() ) {
					wp_redirect( trailingslashit( esc_url( home_url() ) ) . AMP_QUERY_VAR ,  301 );
					exit();
				}
        elseif ( is_archive() ) {
          global $wp;
          $current_archive_url = home_url( $wp->request );
          wp_redirect( trailingslashit( esc_url( $current_archive_url ) ) . AMP_QUERY_VAR , 301 );
          exit();
				} else {
					wp_redirect( trailingslashit( esc_url( ( get_permalink( $id ) ) ) ) . AMP_QUERY_VAR , 301 );
					exit();
				}
			}
      }
		} 
	}
}

add_action( 'template_redirect', 'ampforwp_page_template_redirect', 30 );
{'fraction_non_alphanumeric': 0.15095652173913043, 'fraction_numerical': 0.008347826086956521, 'mean_word_length': 3.4178187403993854, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '76083', 'n_tokens_mistral': 1083, 'n_tokens_neox': 966, 'n_words': 139}