Index: src/wp-includes/rewrite.php
===================================================================
--- src/wp-includes/rewrite.php	(revision 43298)
+++ src/wp-includes/rewrite.php	(working copy)
@@ -273,6 +273,11 @@
  */
 function flush_rewrite_rules( $hard = true ) {
 	global $wp_rewrite;
+
+	if ( ! is_admin() ) {
+		_doing_it_wrong( __FUNCTION__, __( 'Rewrite rules should only be updated in wp-admin context.' ), '5.0' );
+	}
+
 	$wp_rewrite->flush_rules( $hard );
 }
 
