Index: src/wp-includes/plugin.php
===================================================================
--- src/wp-includes/plugin.php	(revision 51039)
+++ src/wp-includes/plugin.php	(working copy)
@@ -30,6 +30,9 @@
 /** @var int[] $wp_actions */
 global $wp_actions;
 
+/** @var int[] $wp_filters */
+global $wp_filters;
+
 /** @var string[] $wp_current_filter */
 global $wp_current_filter;
 
@@ -43,6 +46,10 @@
 	$wp_actions = array();
 }
 
+if ( ! isset( $wp_filters ) ) {
+	$wp_filters = array();
+}
+
 if ( ! isset( $wp_current_filter ) ) {
 	$wp_current_filter = array();
 }
@@ -161,8 +168,14 @@
  * @return mixed The filtered value after all hooked functions are applied to it.
  */
 function apply_filters( $hook_name, $value ) {
-	global $wp_filter, $wp_current_filter;
+	global $wp_filter, $wp_current_filter, $wp_filters;
 
+	if ( ! isset( $wp_filters[ $tag ] ) ) {
+		$wp_filters[ $tag ] = 1;
+	} else {
+		++$wp_filters[ $tag ];
+	}
+
 	$args = func_get_args();
 
 	// Do 'all' actions first.
@@ -209,8 +222,14 @@
  * @return mixed The filtered value after all hooked functions are applied to it.
  */
 function apply_filters_ref_array( $hook_name, $args ) {
-	global $wp_filter, $wp_current_filter;
+	global $wp_filter, $wp_current_filter, $wp_filters;
 
+	if ( ! isset( $wp_filters[ $tag ] ) ) {
+		$wp_filters[ $tag ] = 1;
+	} else {
+		++$wp_filters[ $tag ];
+	}
+
 	// Do 'all' actions first.
 	if ( isset( $wp_filter['all'] ) ) {
 		$wp_current_filter[] = $hook_name;
@@ -238,6 +257,25 @@
 }
 
 /**
+ * Retrieve the number of times a filter has been fired.
+ *
+ * @param string $tag The name of the filter hook.
+ * @return int The number of times filter hook $tag is fired.
+ *
+ * @global int[] $wp_filters Stores the number of times each filter was triggered.
+ *
+ */
+function did_filter( $tag ) {
+	global $wp_filters;
+
+	if ( ! isset( $wp_filters[ $tag ] ) ) {
+		return 0;
+	}
+
+	return $wp_filters[ $tag ];
+}
+
+/**
  * Checks if any filter has been registered for a hook.
  *
  * When using the `$callback` argument, this function may return a non-boolean value
