do_action( 'add_option', string $option, mixed $value )

Fires before an option is added.


$option string
Name of the option to add.
$value mixed
Value of the option.

Top ↑


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

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

Top ↑


Version Description
2.9.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 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.