[wp-hackers] Plugin port to WP2.0

Owen Winkler ringmaster at midnightcircus.com
Mon Jan 9 14:50:41 GMT 2006


CK wrote:
>>> I was wondering if I want to use the new AJAX functionality in  the  
>>> new wordpress, I am talking about the expandable "advance"  options  
>>> like "Optional Excerpt" and "Trackbacks" in my own plugin  what do I  
>>> need to add?
>>
> The reason I want to this info is because my plugin adds some stuff  in 
> the wordpress write post page, where custom fields is. I don't  know if 
> this is of any help, or if it changes anything. otherwise  you've been 
> very helpful and I will try everything you said as soon  as I still some 
> time. :)

A few thoughts:

First off, the DBX code isn't strictly Ajax.  There is no communication 
back with the server.  Even the storage of the positions of the boxes is 
using cookies on the client.  An example of Ajax on the post page (the 
only one I can think of, actually) is the adding of new categories.

The problem with DBX is that the thing that makes DBX run is loaded via 
the addLoadEvent() js function in admin-header.php:

function addLoadEvent(func) {
   if ( typeof wpOnload != 'function' ) {
     wpOnload = func;
   } else {
     var oldonload = wpOnload;
     wpOnload = function() {
       oldonload();
       func();
     }
   }
}

Notice how func() is called after the old oldonload().  That means that 
anything you add to the queue is executed sequentially *after* what has 
already been loaded.

Unfortunately, there isn't an easy place to insert a new addLoadEvent() 
call before DBX inserts its own.  The reason you would want to do this 
is so that you could insert a new div into the main DBX div so that the 
DBX code would manipulate it, too.  Because your new div can't be inside 
that main div before DBX initialized, you've got a problem.

There isn't really an easy solution.  There might be a hook in the 
output chain before the DBX script tag that's added in admin-header.php, 
but I don't see it.  A superior solution would be to add a new hook to 
the core that's inside the DBX area (and also to the one on the side).

These type of hooks weren't added before because you could use DOM to 
insert new elements whever you wanted.  But because of the new dynamic 
interface, this becomes more problematic.

I have added a Trac ticket with a patch for adding the described hooks:
http://trac.wordpress.org/ticket/2250

For folks who don't want to wait for a new hook, check out my very own 
brand of insanity:
http://dev.wp-plugins.org/file/geo/trunk/geo.php

Owen







More information about the wp-hackers mailing list