WordPress functions.php: how to apply update_option()?

I’m trying to set the default Image Link URL for my WP users so that it doesn’t include the url link as a default. I’ve done some research, and I know the function is in the wp-admin/options.php:

update_option('image_default_link_type','file');

Rather than mess with the core files, I’d like to put this into the functions.php, but never know the proper way to implement stuff like this! This is what I have so far in my functions.php:

Read More
<?php
    update_option('image_default_link_type','none');
?>

This obviously doesn’t work: it needs the proper setup! What is the correct way to implement this in functions.php?

Also: I’d like to know the strategy for figuring out how to implement functions like this in the future by myself? For example, I never know whether or not I’m supposed to use add_filter or do_action, and how I need to pass the parameters. I’ve yet to find a book or post out there that explains this very well, and can show me by example. Any good leads on this would be awesome too!

Related posts

Leave a Reply

1 comment

  1. Start with the WordPress codex. Visit the plugin API (which is really what you are doing) that explains Hooks, Actions and Filters. Then see the Action Reference which provides your list of hooks.

    Here you will find the hook update_option_OPTIONNAME. Description from codex:

    Runs after a WordPress option has been update by the update_option
    function. Action function arguments: old option value, new option
    value. You must add an action for the specific options that you want
    to respond to, such as update_option_foo to respond when option “foo”
    has been updated.

    Adding code from asker’s comment:

    function inventory_linkurl_setting() { 
       update_option('image_default_link_type','none'); 
    } 
    add_action('admin_init', 'inventory_linkurl_setting'); ?>