do_action( ‘add_option’, string $option, mixed $value )

Fires before an option is added.

Parameters

$optionstring
Name of the option to add.
$valuemixed
Value of the option.

Source

do_action( 'add_option', $option, $value );

Changelog

VersionDescription
2.9.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    For adding prefix to the option value
    we can consider below example

    // Define a custom function to be executed when the 'add_option' hook is triggered
    function wpdocs_custom_add_option_action( $option, $value ) {
        // Perform custom logic or modifications to the option or its value
        // For example, let's add a prefix to the option value
        $modified_value = 'prefix_' . $value;
        
        // Save the modified value back to the option
        update_option( $option, $modified_value );
    }
    add_action( 'add_option', 'wpdocs_custom_add_option_action', 10, 2 );

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