[wp-hackers] Settings pages
Ptah Dunbar
pt at ptahd.com
Fri Jun 12 17:45:05 GMT 2009
Thanks for the tips NR. I was already afraid of that after snooping around
the core a little bit more. And yes, everything's going into one fat array
(you wouldnt catch me dead adding options all over the place).
Although I'm still curious as to what add_option_whitelist() does... Haven't
played with it yet.
In the meantime, I've been cooking up a function to address the non-having
theme activation hook problem:
add_action( 'admin_init', 'framework_activation_hook' );
/**
* Set the activation hook for the theme
*
* @internal not bulletproof, but it'll due until this patch gets applied:
* @link http://core.trac.wordpress.org/ticket/7795
*
* @since 0.4
*/
function framework_activation_hook() {
global $theme_data;
$current_theme = get_option( 'current_theme' ); // variable stores the
current theme
$target_theme = $theme_data['Title']; // variable stores the theme we want
to target
if ( isset($_GET['activated']) && $current_theme == $target_theme ) {
do_action( 'theme_activation_hook' ); // Available action:
theme_activation_hook
}
}
So when the user clicks to activate the theme, developers can hook
into theme_activation_hook and call an install function.
Of course this only works when the user activates the theme via the admin
panel, so it's not bulletproof yet. Plus if the page gets refreshed, the
hook gets called again. Lots of holes, but I'm still working on a better
implementation.
Ptah Dunbar — pt at ptahd.com
http://ptahdunbar.com
On Fri, Jun 12, 2009 at 11:33 AM, Nathan Rice <ncrice at gmail.com> wrote:
> Ptah,
> Using add_option is probably your best bet, as there is no theme activation
> hook you'd be able to hook to (that I know of). And if you do it in such a
> way that add_option is called only when the plugin/theme settings page is
> loaded, you won't be adding any extra overhead to regular page loads.
>
> Also, I'm not sure if you're serializing all your options into a single db
> field, but if you are (and you should be) then you can do some magic with
> wp_parse_args, or (like simon said) use the default parameter with
> get_option to use defaults initially, until you can load the defaults into
> the database.
>
> Nathan
>
> My Website
> http://www.nathanrice.net/
>
> My Twitter
> http://twitter.com/nathanrice
>
>
> On Thu, Jun 11, 2009 at 11:03 PM, Ptah Dunbar <pt at ptahd.com> wrote:
>
> > If i'm creating an option using the register_setting API, is there a
> > mechanism for giving it an initial value or should I just keep using
> > add_option();?
> >
> > Ptah Dunbar — pt at ptahd.com
> > http://ptahdunbar.com
> >
> >
> > On Thu, Jun 11, 2009 at 9:59 AM, Simon Wheatley
> > <simon at sweetinteraction.com>wrote:
> >
> > > On Thu, Jun 11, 2009 at 1:53 PM, scribu<scribu at gmail.com> wrote:
> > > >
> > > > Check the function add_settings_field()
> > > >
> > >
> > > Between this and the register_settings function (Andrew describes it
> > > here:
> > >
> >
> http://planetozh.com/blog/2009/05/handling-plugins-options-in-wordpress-28-with-register_setting/
> > > )
> > > I am absolutely made up. SO much easier to add and deal with settings!
> > >
> > > S
> > >
> > >
> > > ---
> > > Sweet Interaction Ltd is Registered in England/Wales, no. 6610741
> > > Registered office: 7 Malton Av, Manchester, M21 8AT
> > > _______________________________________________
> > > 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