Displaying a variable stored in functions.php inside widget

The widget operates in a different scope than the functions.php. You could use two different approaches to get around that. Make the variable global (put it into the top scope): // functions.php $GLOBALS[‘var_name’] = ‘hello’; // widget echo $GLOBALS[‘var_name’]; But that is risky: any other script can change the variable now accidentally, and it is … Read more

How to update widget from widget() function?

Huh. It had never actually occurred to me to use widget instance as cache. I hadn’t ever seen such implementation either. This is quite an original idea, and as such it is hard to accurately point out benefits and issues with implementation. For starters update() doesn’t actually save anything, it just used as check for … Read more

How can I delete all inactive widgets?

You should do it with after_setup_theme action: function remove_inactive_widgets() { $sidebars_widgets = get_option( ‘sidebars_widgets’ ); $sidebars_widgets[‘wp_inactive_widgets’] = array(); update_option( ‘sidebars_widgets’, $sidebars_widgets ); } add_action( ‘after_setup_theme’, ‘remove_inactive_widgets’ );

What is the best way to include a widget in a Page?

This plugin might be the easy way. http://wordpress.org/extend/plugins/add-widgets-to-page/ But for a scratch method… Look into Theme Twenty-Ten’s functions.php file and find where the dynamic sidebars are registered. It looks like this: <?php function twentyten_widgets_init() { // Area 1, located at the top of the sidebar. register_sidebar( array( ‘name’ => __( ‘Primary Widget Area’, ‘twentyten’ ), … Read more

Copy widget settings from one blog to another

I don’t think there is anything specifically for this. You might want to look at the plugin code to find calls to get_option() and see what keys they are using, then browse the DB table wp_options with phpMyAdmin (or whatever) and grab the associated values. Without specific support from the plugin this can be iffy … Read more

Bookshelf plugin and/or widget [closed]

There are quite a few plugins tagged books in official repository. A lot of them seems to pull covers from services like Amazon, which may or may not fit your needs. If you want to simply display some self-hosted images with links and basic categorizing/sorting, personally I like to use Links for such.

Override dynamic_sidebar() in plugin?

dynamic_sidebar() calls wp_get_sidebars_widgets() to get the list of all sidebars and their widgets. This output is filtered through sidebars_widgets, so you can modify it to add or remove widgets. This array only contains widget IDs, so you need to register the widget instance too (it should end up in the global $wp_registered_widgets array). I think … Read more