[wp-hackers] programmatically activate widgets

Ptah Dunbar pt at ptahd.com
Wed Apr 22 05:48:00 GMT 2009


http://ptahdunbar.com/wordpress/droppin-knowledge-on-wordpress-how-to-preset-widgets-to-widget-areas/

<?php
// Debug: Makes sure no widgets are registered already. If so, be gone.
//update_option( 'sidebars_widgets', NULL );

$current_theme = get_option( 'template' ); // variable stores the current
theme
$target_theme = 'wpframework'; // variable stores the theme we want to
target
$debug = false; // skip the ladie, da.

/**
 * $preset_widgets:
 * A two-dimensional array that stores all active sidebars and their active
widgets
 *
 * Qiktip: Sidebars and widgets are identified by their unique ID
 */
$preset_widgets = array ( 'sidebar-1'  => array( 'search', 'pages' ) );

// this checks to see if the user is trying to change themes, if so,
// compare that theme with our target theme.
if ( isset( $_GET['activated'] ) && $current_theme == $target_theme ||
$debug ) {
    update_option( 'sidebars_widgets', $preset_widgets );
}

// Debug: What widgets/widget areas are active?
// Uncomment the next line and find out for yourself buddy ;P
//var_dump( get_option( 'sidebars_widgets' ) );
?>

Ptah Dunbar — pt at ptahd.com
http://ptahdunbar.com


On Mon, Apr 20, 2009 at 10:41 AM, John Turner <TurnerJD at cofc.edu> wrote:

> I'll trace it tonight and see if I can find anything and report back
>
> John Turner
> @johnturner
>
>
>
> > From: "Ibrahim A. Mohamed" <bingorabbit at gmail.com>
> > Reply-To: <wp-hackers at lists.automattic.com>
> > Date: Mon, 20 Apr 2009 16:21:54 +0200
> > To: <wp-hackers at lists.automattic.com>
> > Subject: Re: [wp-hackers] programmatically activate widgets
> >
> > I think that the activated widgets are stored in the database, in the *
> > prefix*_options table. I dun remember where exactly but I'm going to tell
> > you when I find it.
> >
> > On Mon, Apr 20, 2009 at 4:17 PM, Simon Wheatley
> > <simon at sweetinteraction.com>wrote:
> >
> >> On Mon, Apr 20, 2009 at 1:46 PM, John Turner <TurnerJD at cofc.edu> wrote:
> >>>
> >>> I need a way to programmatically activate widgets, anyone know the
> >> function
> >>> or method to call?
> >>>
> >>
> >>
> >> The K2 theme has a sidebar management page, you might get some clues
> >> from there perhaps?
> >>
> >> 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
> >>
> >
> >
> >
> > --
> > Regards,
> > Ibrahim Abdel Fattah Mohamed
> > Web Developer
> > Twitter: @bingorabbit
> > e-mail: bingorabbit at gmail.com
> > Personal bLOG: http://bingorabbit.com/
> > _______________________________________________
> > 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