WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#5750 closed enhancement (fixed)

New Dashboard Interface

Reported by: mdawaffe Owned by: mdawaffe
Milestone: 2.5 Priority: normal
Severity: normal Version:
Component: Administration Keywords: has-patch needs-testing
Focuses: Cc:

Description

The attached converts the WP dashboard into a collection of widgets. These widgets are the same as "ordinary" WP widgets, but are a little bit souped up:

  1. Widget display and widget configuration are done on the same screen.
  2. Widgets can be 1/3, 1/4 1/2 or 1/1 of the dashboard width (example: all widgets in patch are 'half' width except the planet widget which is 'full' width).
  3. Widgets can be single or double high (no example, but can pass 'height' => 'double').

There is no interface for reordering widgets or adding new ones. I don't expect there to be such a UI until WP 2.6 at least. Hooks are available for plugins to register new widgets and to set/modify the order:

// Hook to register new widgets
do_action( 'wp_dashboard_setup' );

// Filter widget order
$dashboard_widgets = apply_filters( 'wp_dashboard_widgets', $dashboard_widgets );

Widgets are registered like ordinary WP widgets, but take a few more parameters (all optional):

wp_register_sidebar_widget( $widget_id, $widget_name, $widget_callback,
  array(
    'all_link'  => [full url for "See All" link],
    'feed_link' => [full url for "RSS" link],
    'width'     => 'third', 'fourth', 'HALF', 'full',
    'height'    => 'SINGLE', 'double'
  )
);
wp_register_widget_control(
  $widget_id,
  $widget_control_name,
  $widget_control_callback,
  array(), // Just leave it blank: oddity in widget code
  array(
    'widget_id' => $widget_id // Yes - again.  This is required: oddity in widget code
  )
);

Widgets do not need controls. Those with controls will show an "Edit" link and can be edited "in place" (new page load).

The dynamic_sidebar() function has been modified (in a backward compatible way) to handle some of the dashboard requirements:

  1. New hooks: dynamic_sidebar_params
  2. widget_id and widget_name are now passed to the widget_callback function along with before_title and friends.

Since most of the default widgets are specialized RSS widgets, the wp_widget_rss_*() functions have been broken up a bit more to accommodate the needed re-use.

Particularly hacky things are noted in the code.

Attachments (6)

5750.diff (39.9 KB) - added by mdawaffe 6 years ago.
5750b.diff (4.5 KB) - added by mdawaffe 6 years ago.
5750c.diff (9.3 KB) - added by mdawaffe 6 years ago.
style tweaks - move to separate css file
5750d.diff (1.7 KB) - added by mdawaffe 6 years ago.
fix "right now". FF, Safari, IE
5750-cache.diff (19.6 KB) - added by mdawaffe 6 years ago.
5750-ie.diff (1.8 KB) - added by mdawaffe 6 years ago.

Download all attachments as: .zip

Change History (27)

mdawaffe6 years ago

comment:1 mdawaffe6 years ago

  • Status changed from new to assigned

Forgot to mention: uses new cap: edit_dashboard. Upgrade function included in patch.

comment:2 ryan6 years ago

(In [6705]) New dashboard from mdawaffe. see #5750

comment:3 ryan6 years ago

My sidebar reverted to the default, it seems.

comment:4 ryan6 years ago

Visiting the dashboard causes sidebar widget configuration to be lost.

comment:5 ryan6 years ago

[02-Feb-2008 13:23:10] PHP Fatal error:  Cannot redeclare widget_gsearch() (previously declared in /Applications/MAMP/htdocs/trunk/wp-content/plugins/widgets/gsearch.php:20) in /Applications/MAMP/htdocs/trunk/wp-content/plugins/widgets/gsearch.php on line 20

I can reproduce that even after backing out the new dash changes, so I suspect it was introduced with the earlier widget admin redesign.

comment:6 ryan6 years ago

That happens when clicking "Save Changes" on the widget admin page, BTW.

comment:7 follow-up: ryan6 years ago

The call to wp_widgets_init() in the http_post case of wp-admin/widgets.php is causing this. Some widgets define their control and display functions within their init function. Lame, but it seems to be fairly common.

comment:8 in reply to: ↑ 7 darkdragon6 years ago

Replying to ryan:

Some widgets define their control and display functions within their init function. Lame, but it seems to be fairly common.

I'm going to start a campaign to stop that behavior, as it is quite annoying. I think I posted my thoughts to wp-hackers, but I doubt anyone responded.

So basically what you are saying is that when the *_init() is called more than once, PHP is trying to compile the internal functions more than once? That seems odd, PHP should realize that the functions have already been compiled and not compile them again. However, the behavior for having functions inside of functions might be undefined to the compiler, so might not realize that it already compiled the functions or doesn't need to compile them again. Or whatever.

mdawaffe6 years ago

comment:9 mdawaffe6 years ago

5750b.diff

  1. Visiting dashboard no longer ruins your sidebar widgets.
  2. Better support for both new-skool "multi-widgets" and old-skool "how many X widgets do you want". Multi-widgets only need to be listed once (not once per widget instance) and their respective control callbacks only need to be called once on POST update. Each Old-skool widget needs to be listed once per instance and their respective callbacks need to be called once per instance.
  3. Old-skool widgets no longer break widgets admin page HTML.
  4. PHP warnings.

Does not fix PHP Fatal error.

comment:10 ryan6 years ago

(In [6717]) Dashboard fixes from mdawaffe. No longer stomps sidebar. see #5750

comment:11 ryan6 years ago

(In [6718]) No need to re-register widgets. see #5750

mdawaffe6 years ago

style tweaks - move to separate css file

comment:12 ryan6 years ago

(In [6810]) Dashboard styling from mdawaffe. see #5750

mdawaffe6 years ago

fix "right now". FF, Safari, IE

comment:13 ryan6 years ago

(In [6811]) Dashboard styling from mdawaffe. see #5750

comment:14 _ck_6 years ago

By the way, I've successfully tested a method to re-order these "widgets" (divs) by applying jquery.ui.sortable to them.

It's as simple as applying a class to each widget, wrapping the main wider column on the left with one div and the sidebar with another div. Needs 3 small jquery.ui libraries.

Then you can move the widgets up and down or even from the main column to the sidebar and back.

Only thing I don't have ready is a way to save the positions, which could be done via cookies like wordpress.com or via ajax as the open/closed method is currently done in the trunk. That part's a bit harder and I wanted to wait to hear if this was interesting.

comment:15 mdawaffe6 years ago

Many of these new widgets are based on RSS feeds. We know when a feed is cached.

It's silly to always do another HTTP request (via AJAX) just to load some content we already have stored in the cache.

Further more, the widgets are just big white boxes until they get AJAX populated. A "Loading..." message would be nice so that people know what's up.

Attached:

  1. If the all the feeds for a widget are cached and not stale, just output the content.
  2. If feeds are not cached or cache is stale, output "Loading..." message (yes, Matt, with an ellipsis entity :) ), and AJAX load feed.
  3. light docs for dashboard widgets.

Accomplished via:

  1. wp_dashboard_cached_rss_widget()
  2. A bunch of per-widget callback functions.

mdawaffe6 years ago

comment:16 ryan6 years ago

(In [6958]) Dashboard widgets caching improvements from mdawaffe. see #5750

comment:17 mdawaffe6 years ago

5750-ie.diff

Fixes dashboard widgets in IE6/7

Tested in FF2, FF3b3, Safari3, Opera9, IE6, IE7

mdawaffe6 years ago

comment:18 mdawaffe6 years ago

5750-ie.diff also contains a small IE6 fix for the Widgets page.

comment:19 ryan6 years ago

(In [7197]) Dashboard IE fixes from mdawaffe. see #5750

comment:20 djr6 years ago

May I propose looking at MyDashboard http://dev.clearskys.net/Wordpress/MyDashboard, which is based on iGoogle and has similar widgets/gadgets functionality?

comment:21 mdawaffe6 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

Fixed. Please open new tickets for specific bugs or enhancements.

Note: See TracTickets for help on using tickets.