Where should I use get_option in a plugin

Both ways are almost equal, the first will be slightly faster, because the callback is called only if the check equals to TRUE.

Note you cannot test an option like this, unless the option name is really 'my_option[option_1]'. What you probably want is:

if ( $test = get_option('my_option') and 1 === $test['option_1'] )
    add_action();

An extended example:

$my_options = get_option('my_option');

if ( 1 === $my_options['test_1'] )
    add_action( 'init', 'my_init' );

if ( 1 === $my_options['test_2'] )
    add_action( 'shutdown', 'my_shutdown' );

// clean up
unset( $my_options );

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)