Subject: [PATCH] Updated for WordPress 6.6.0
---
Index: src/wp-includes/option.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php
--- a/src/wp-includes/option.php	(revision 65b74631fc22afbc14ba11f2f543010993095709)
+++ b/src/wp-includes/option.php	(date 1716034510543)
@@ -1083,6 +1083,17 @@
 		$option = trim( $option );
 	}
 
+	/**
+	 * Filters the option name before the option gets deleted.
+	 *
+	 * Returning an empty string short circuits the function.
+	 *
+	 * @since 6.6.0
+	 *
+	 * @param string $option Option name.
+	 */
+	$option = trim( apply_filters( 'pre_delete_option', $option ) );
+
 	if ( empty( $option ) ) {
 		return false;
 	}
Index: tests/phpunit/tests/option/option.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/tests/phpunit/tests/option/option.php b/tests/phpunit/tests/option/option.php
--- a/tests/phpunit/tests/option/option.php	(revision 65b74631fc22afbc14ba11f2f543010993095709)
+++ b/tests/phpunit/tests/option/option.php	(date 1716034065044)
@@ -478,4 +478,41 @@
 		delete_option( 'foo' );
 		$this->assertFalse( get_option( 'foo' ) );
 	}
+
+	/**
+	 * @ticket 44042
+	 */
+	function test_pre_delete_option_filter() {
+		add_filter( 'pre_delete_option', function( $option ) {
+			if ( 'test_option_test' === $option ) {
+				$option = 'test_option';
+			}
+
+			return $option;
+		} );
+
+		add_option( 'test_option', '1' );
+		delete_option( 'test_option_test' );
+
+		$this->assertEquals( false, get_option( 'test_option' ) );
+
+	}
+
+	/**
+	 * Returning an empty string in `pre_delete_option` short circuits `delete_option()`.
+	 *
+	 * @ticket 44042
+	 */
+	function test_pre_delete_option_short_circuit() {
+		add_filter( 'pre_delete_option', function( $option ) {
+			if ( 'test_option' === $option ) {
+				return '';
+			}
+		} );
+
+		add_option( 'test_option', '5' );
+		delete_option( 'test_option' );
+
+		$this->assertEquals( '5', get_option( 'test_option' ) );
+	}
 }
