do_action( ‘update_option’, string $option, mixed $old_value, mixed $value )

Fires immediately before an option value is updated.

Parameters

$optionstring
Name of the option to update.
$old_valuemixed
The old option value.
$valuemixed
The new option value.

Source

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

Changelog

VersionDescription
2.9.0Introduced.

User Contributed Notes

  1. Skip to note 4 content

    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.