Index: src/wp-includes/functions.php
===================================================================
--- src/wp-includes/functions.php	(revision 45519)
+++ src/wp-includes/functions.php	(working copy)
@@ -195,6 +195,58 @@
 }
 
 /**
+ * Updates _site_state_changed option in database
+ *
+ * Should be called when a theme or plugin has been activated or deactivated.
+ * Used to facilitate tasks like flushing rewrite rules for the registration
+ * and deregistration of post types and taxonomies.
+ *
+ * @since 5.2.2
+ *
+ * @param string|array $arg single function name or list of function names
+ */
+function update_site_state_changed( $arg ) {
+    $value = [];
+
+    if( $state = get_option( '_site_state_changed' ) ) {
+        $value = maybe_unserialize( $state );
+
+        if( !is_array( $value ) ) {
+            $value = [];
+        }
+    }
+
+    if( is_array( $arg ) ) {
+        $value = array_merge( $value, $arg );
+    } else {
+        $value[] = $arg;
+    }
+
+    update_option( '_site_state_changed', $value );
+}
+
+/**
+ * Check site state
+ */
+function check_site_state_change() {
+    if ( $site_state = get_option( '_site_state_changed' ) ) {
+        $site_state = apply_filters( 'site_state_changed', $site_state );
+
+        if( is_array( $site_state ) ) {
+            $site_state = array_unique( $site_state );
+            foreach ( $site_state as $site_state_func ) {
+                if( function_exists( $site_state_func ) ) {
+                    call_user_func( $site_state_func );
+                }
+            }
+        }
+
+        do_action( 'site_state_changed', $site_state );
+        delete_option( '_site_state_changed' );
+    }
+}
+
+/**
  * Determines if the date should be declined.
  *
  * If the locale specifies that month names require a genitive case in certain
Index: src/wp-settings.php
===================================================================
--- src/wp-settings.php	(revision 45519)
+++ src/wp-settings.php	(working copy)
@@ -534,6 +534,9 @@
 	unset( $file );
 }
 
+// Check site state change
+check_site_state_change();
+
 /**
  * This hook is fired once WP, all plugins, and the theme are fully loaded and instantiated.
  *
