[wp-hackers] Setting default options for plugin

uberdose wordpress at uberdose.com
Mon Sep 3 16:50:23 GMT 2007


I wouldn't use register_activation_hook() because it won't get
triggered on updates, and if people install in different directories
it's useless too. Instead you could just query an option (get_option)
for a version of your plugin on each invocation and call the
appropriate update function if it's not there or lower than what you
need.

On 9/3/07, Callum Macdonald <lists.automattic.com at callum-macdonald.com> wrote:
> G'day,
>
> I've copied this information onto the codex:
> http://codex.wordpress.org/Plugin_API/Action_Reference/activate_%28plugin_file_name%29
>
> Just for the record, I read the documentation on that link and couldn't
> figure out what it meant. It also links to an as-yet-uncreated page on
> redalt.com. Likewise, there is no documentation for the
> register_activation_hook($file,$function) plugin on the codex. Would
> anyone who knows what it does like to add it?
> http://codex.wordpress.org/index.php?title=Function_Reference/register_activation_hook&action=edit
>
> Cheers,
>
>
> Callum.
>
> John Blackbourn wrote:
> > Stephen,
> >
> > You should use the register_activation_hook function instead of
> > calling the activate_xxx action directly. Unfortunately this isn't a
> > well documented function.
> >
> > Brief explanation here:
> > http://wphooks.flatearth.org/hooks/activate_plugin-filename/
> >
> > John.
> >
> > On 8/31/07, Callum Macdonald <lists.automattic.com at callum-macdonald.com> wrote:
> >
> >> Hey Stephen,
> >>
> >> I think you want to use the activate_ action. See these pages for more info:
> >> http://codex.wordpress.org/Plugin_API/Action_Reference
> >> http://codex.wordpress.org/Creating_Tables_with_Plugins
> >>
> >> I've just created a plugin which does exactly that which you're welcome
> >> to copy. See lines 21-46 and 165 for the relevant code. The plugin is
> >> available here:
> >> http://www.callum-macdonald.com/code/wp-mail-smtp/
> >>
> >> Cheers,
> >>
> >>
> >> Callum.
> >>
> >> Stephen Rider wrote:
> >>
> >>> Is there an official or "best" method for setting default options for
> >>> a plugin when it is first activated? Currently I use something like this:
> >>>
> >>> if (!get_option('my_plugin')){
> >>> // set default options
> >>> delete_option('my_plugin_options');
> >>> add_option ( 'my_plugin_options',array( 'work_properly' => true ) );
> >>> }
> >>>
> >>> This is just "raw" inside the php file (not in a function) so it runs
> >>> every time the PHP file is called. Is there a better way of doing this
> >>> or am I doing things right?
> >>>
> >>> Stephen
> >>> _______________________________________________
> >>> wp-hackers mailing list
> >>> wp-hackers at lists.automattic.com
> >>> http://lists.automattic.com/mailman/listinfo/wp-hackers
> >>>
> >>>
> >>>
> >> _______________________________________________
> >> wp-hackers mailing list
> >> wp-hackers at lists.automattic.com
> >> http://lists.automattic.com/mailman/listinfo/wp-hackers
> >>
> >>
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> >
> >
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list