Support

Account

Home Forums Backend Issues (wp-admin) PHP Unrequire Field Reply To: PHP Unrequire Field

  • So the validation is run on admin-ajax.php which invalidate the $pagenow. Maybe there’s a better way to do this but I just made 2 arrays to check against both the global and the referrer.

    Open to way to make the below and above better

    /**
     * Ensure our particular fields pass validation
     * 
     * @param Boolean $valid
     * 
     * @return Boolean $valid
     */
    function theme_acf_nonrequired_fields_validate( $valid ) {
    	
    	global $pagenow;
    	
    	$acceptable_pagenows = array( 'user-new.php', 'user-edit.php', 'profile.php' );
    	$acceptable_referers = array( '/wp-admin/user-new.php', '/wp-admin/user-edit.php', '/wp-admin/profile.php' );
    	
    	if( ! is_admin() || ! current_user_can( 'edit_posts' ) ) {
    		return $valid;
    	}
    	
    	if( ! ( in_array( $pagenow, $acceptable_pagenows ) ||
    		  ( isset( $_REQUEST, $_REQUEST['_wp_http_referer'] ) && in_array( $_REQUEST['_wp_http_referer'], $acceptable_referers ) ) )
    	) {
    		return $valid;
    	}
    	
    	return true;
    	
    }
    add_filter( 'acf/validate_value/name=cust_name', 		'theme_acf_nonrequired_fields_validate' );