do_action( 'update_option', string $option, mixed $old_value, mixed $value )

Fires immediately before an option value is updated.


$option string
Name of the option to update.
$old_value mixed
The old option value.
$value mixed
The new option value.

Top ↑


File: wp-includes/option.php. View all references

do_action( 'update_option', $option, $old_value, $value );

Top ↑


Version Description
2.9.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by XtraTheme

    Check if an specific option updated then run my code

    function wpdocs_updated_option( $option_name, $old_value, $value ) {
    	if ( 'wpdocs_custom_option_name' === $option_name ) {
    		// You can run your code here if option name is what I wanted ...
    		// Another check if value is what I want, then run code.
    		if ( 'yes' === $value ) {
    			// Run my code here ...
    add_action( 'updated_option', 'wpdocs_updated_option', 10, 3 );

You must log in before being able to contribute a note or feedback.