From bb5d25c0cf8f7a7e7eac88d8cd4c675003aec2a2 Mon Sep 17 00:00:00 2001 From: Sainath Poojary Date: Thu, 10 Jul 2025 15:27:08 +0530 Subject: [PATCH] Options: Add `pre-add-option` filter --- src/wp-includes/option.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php index 3b4f461724fad..d9941d7ac67f2 100644 --- a/src/wp-includes/option.php +++ b/src/wp-includes/option.php @@ -1113,6 +1113,23 @@ function add_option( $option, $value = '', $deprecated = '', $autoload = null ) $value = sanitize_option( $option, $value ); + /** + * Filters whether to short-circuit the process of adding an option. + * + * Returning a value other than null will short-circuit the process, and the value will be + * returned cast as a bool. + * + * @since 4.7.0 + * + * @param null $skip Whether to short-circuit the process. Default null. + * @param string $option Name of the option to add. + * @param mixed $value Option value. + */ + $skip = apply_filters( 'pre_add_option', null, $option, $value ); + if ( ! is_null( $skip ) ) { + return (bool) $skip; + } + /* * Make sure the option doesn't already exist. * We can check the 'notoptions' cache before we ask for a DB query.