Support

Account

Home Forums ACF PRO acf_form front-end validation conflict using wp_redirect() to restrict back end Reply To: acf_form front-end validation conflict using wp_redirect() to restrict back end

  • acf/validate_save_post fires twice, the first is during an AJAX request to validate fields. During AJAX requests is_admin() is always true. You need to add a test for this

    
    add_action( 'init', 'blockusers_init' ); 
     function blockusers_init() { 
     	if ( is_admin() && check_role('mycustomrole') && 
                 (!defined(DOING_AJAX) || !DOING_AJAX)) { 
     		wp_redirect( home_url() ); 
     		exit; 
     		} 
    }