[wp-hackers] Setting default options for plugin

Jamie Holly hovercrafter at earthlink.net
Fri Aug 31 21:13:28 GMT 2007


Do it via an activation hook. Say your plugin file is xyz.php then you add a
hook

Add_action('activate_xyz.php','function name here');

It also works with folders, so if it was xyz/xyz.php your hook would be:
Add_action('activate_xyz/xyz.php','function name here');

That way it isn't called every time the file is called, only on activation.

Jamie Holly
http://www.intoxination.net
1.513.252.2919 | Skype:intoxination


>-----Original Message-----
>From: wp-hackers-bounces at lists.automattic.com [mailto:wp-hackers-
>bounces at lists.automattic.com] On Behalf Of Stephen Rider
>Sent: Friday, August 31, 2007 5:01 PM
>To: wp-hackers at lists.automattic.com
>Subject: [wp-hackers] Setting default options for plugin
>
>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



More information about the wp-hackers mailing list