diff --git a/src/wp-includes/class-wp-hook.php b/src/wp-includes/class-wp-hook.php
index 432a01600f..03119724f1 100644
--- a/src/wp-includes/class-wp-hook.php
+++ b/src/wp-includes/class-wp-hook.php
@@ -71,6 +71,9 @@ final class WP_Hook implements Iterator, ArrayAccess {
         * @param int      $accepted_args The number of arguments the function accepts.
         */
        public function add_filter( $hook_name, $callback, $priority, $accepted_args ) {
+
+               $hook_name = trim( $hook_name );
+
                $idx = _wp_filter_build_unique_id( $hook_name, $callback, $priority );
 
                $priority_existed = isset( $this->callbacks[ $priority ] );
diff --git a/src/wp-includes/plugin.php b/src/wp-includes/plugin.php
index 5f4fa15986..4f6988be74 100644
--- a/src/wp-includes/plugin.php
+++ b/src/wp-includes/plugin.php
@@ -114,6 +114,8 @@ if ( ! isset( $wp_current_filter ) ) {
 function add_filter( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) {
        global $wp_filter;
 
+       $hook_name = trim( $hook_name );
+
        if ( ! isset( $wp_filter[ $hook_name ] ) ) {
                $wp_filter[ $hook_name ] = new WP_Hook();
        }