WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#6316 closed defect (bug) (fixed)

No context for user_func called by 'do_meta_boxes'

Reported by: henrikmelin Owned by: ryan
Milestone: 2.5 Priority: normal
Severity: normal Version: 2.5
Component: Administration Keywords: meta-box admin
Focuses: Cc:

Description

The user function specified in 'add_meta_box' has no context of what box called it. Passing $box, in addition to $object to the user_func in the function 'do_meta_boxes', would be really useful when populating boxes programatically.

i.e.

call_user_func($boxcallback?, $object);

to

call_user_func($boxcallback?, $object, $box);

Thoughts?
Henrik.

Change History (5)

comment:1 @ryan7 years ago

Are you registering a function that handles multiple boxes? I usually register a specific function for each box so there's no need to pass the box.

comment:2 @henrikmelin7 years ago

Yes. Have a look at:

http://labs.dagensskiva.com/plugins/more-fields/

which details the plugin that enables the user to create any number boxes without editing code. These boxes can be made out of text, selects and textareas.

Curretly, I use JS to position the box after creating it in the footer, but I really see using 'add_meta_box' as much more elegant, and integrating better into the WP framework.

The function that builds the content of a box (i.e. the callback function) would in this instance need to know what box is being build.

Cheers,
Henrik.

comment:3 @henrikmelin7 years ago

I've worked around this by using the 'edit_form_advanced' action, appearing just after the creation of the meta boxes. I still see some potential benefit in having all the meta boxes in the $wp_meta_boxes variable tough, which is not possible now.

Cheers,
Henrik.

comment:4 @ryan7 years ago

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

(In [7514]) Pass box to add_meta_box() callback. Props henrikmelin. fixes #6316

comment:5 @ryan7 years ago

  • Milestone changed from 2.6 to 2.5
Note: See TracTickets for help on using tickets.