[wp-trac] [WordPress Trac] #6916: wp_category_checklist() should take Walker object as argument

WordPress Trac wp-trac at lists.automattic.com
Sun May 4 19:20:08 GMT 2008


#6916: wp_category_checklist() should take Walker object as argument
-------------------------+--------------------------------------------------
 Reporter:  whoismanu    |       Owner:  anonymous                   
     Type:  enhancement  |      Status:  new                         
 Priority:  normal       |   Milestone:  2.7                         
Component:  General      |     Version:                              
 Severity:  normal       |    Keywords:  walker wp_category_checklist
-------------------------+--------------------------------------------------
 currently, the beginning of the wp_category_checklist() function in
 template.php looks like this


 {{{
 function wp_category_checklist( $post_id = 0, $descendants_and_self = 0,
 $selected_cats = false ) {
         $walker = new Walker_Category_Checklist;
 }}}

 i.e. the Walker object is constructed inside the function. Now, the Walker
 object follows a visitor pattern which is nice, but creating it like this
 inside the function in my opinion takes away many of its benefits. I would
 rather see the Walker object passed in as an argument so that e.g. plugin
 authors can define their own custom Walkers. This would be much cleaner
 and versatile.

 Example: My plugin needs to edit several posts on the same page. so for
 the categories i would like to have the checkboxes in array form,
 something like this

 {{{
 <input value="' . $category->term_id . '" type="checkbox"
 name="post_category['.$post_id.'][]"/>
 }}}

 now the current Walker_Category_Checklist defined in template.php outputs
 the category list using

 {{{
 <input value="' . $category->term_id . '" type="checkbox"
 name="post_category[]"/>
 }}}

 so assuming that i defined my own Walker (e.g. MyWalker) that outputs the
 categories as desired, the only thing i can do is to duplicate the whole
 wp_category_checklist() function and replace the first line of the
 function with something like


 {{{
 $walker = new MyWalker($post_id);
 }}}

 If the wp_category_checklist() function would fully adhere to the visitor
 pattern and take the visitor object (the Walker) as an argument as
 suggested here, the whole thing would be much cleaner and easier, i could
 just call the existing wp_category_checklist() function like this


 {{{
 wp_category_checklist(new MyWalker($post_id));
 }}}

-- 
Ticket URL: <http://trac.wordpress.org/ticket/6916>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list