Reorder dashboard widgets

Clearing things up First, there’s a slight misunderstanding. wp_dashboard_setup is an action and not a filter. If it would be a filter, it would have one or multiple arguments and would need to return the first one. How-To #1 For an example of this action, see the following mu-plugin I use: <?php /** * Plugin … Read more

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’ );