Make WordPress Core

Opened 14 years ago

Closed 13 years ago

#15066 closed enhancement (duplicate)

Create a Meta Box class

Reported by: ericmann's profile ericmann Owned by: nacin's profile nacin
Milestone: Priority: normal
Severity: normal Version:
Component: Editor Keywords: needs-patch
Focuses: Cc:

Description

Widgets became much more extensible when we introduced the WP_Widget class in version 2.8. New widgets were easier to make, and we finally had the ability to create multi-instance widgets without a lot of coding overhead and headaches.

Meta Boxes are used by themes and plug-ins in a similar fashion to customize the layout and functionality of the post/page/custom-post-type edit screen. Unfortunately, the code for creating a new meta box and handling the subsequent form submission is difficult to track down, prone to errors, and nearly impossible to use in a multi-instance situation.

We should abstract the meta box creation process so that adding a new meta box is as easy as adding a new widget - just extend a WP_Meta_Box class to add the functionality.

Change History (23)

#1 @Denis-de-Bernardy
14 years ago

  • Cc Denis-de-Bernardy added

#2 follow-ups: @sirzooro
14 years ago

  • Cc sirzooro added

+1 for this.

This new class should also include things listed in example for add_meta_box() - I mean nonce, capability and autosave checks - they are used in many custom meta boxes. Of course there should be option(s) to disable them if necessary.

#3 in reply to: ↑ 2 ; follow-up: @ericmann
14 years ago

Replying to sirzooro:

Of course there should be option(s) to disable them if necessary.

I can't think of a situation where disabling nonce verification would be necessary or a good idea (given, I can't ever think of everything ... so if you can give me an example, that would be much appreciated).

But I definitely think noncing, capability and auto-save checks, and AJAX support should be built-in. I spend a lot of time helping new devs trouble-shoot their meta boxes, and most of them just forget to verify a nonce, or have a typo (missed semi-colon) in the code that we all copy-paste whenever making a new box.

#4 in reply to: ↑ 3 @sirzooro
14 years ago

Replying to ericmann:

Replying to sirzooro:

Of course there should be option(s) to disable them if necessary.

I can't think of a situation where disabling nonce verification would be necessary or a good idea (given, I can't ever think of everything ... so if you can give me an example, that would be much appreciated).

I can think of three cases:

  • informational only box - it presents some information only and does not allow any modifications (or they are not sent back to server) - in this case nonces are not needed at all;
  • solution which uses more than one once to track multiple parts of meta box, which may be present or not depending on some condition - in this case plugin should be able to print and validate multiple onces;
  • custom nonce-like solution (although I do not see a point why someone would like to go this way).

#5 in reply to: ↑ 2 @scribu
14 years ago

+1 on a metabox class

Replying to sirzooro:

This new class should also include things listed in example for add_meta_box() - I mean nonce, capability and autosave checks - they are used in many custom meta boxes. Of course there should be option(s) to disable them if necessary.

You have to remember that metaboxes are not only for the post editing page.

We should have a general WP_Metabox class and a WP_Post_Metabox that extends it.

#6 @scribu
14 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release

#7 @nacin
14 years ago

Marked #12450 as a duplicate. Some good ideas there.

#8 @azizur
14 years ago

  • Cc azizur added

#9 @sbressler
14 years ago

  • Cc sbressler@… added

#10 @ramiy
14 years ago

  • Cc ramiy added

#11 follow-up: @azizur
14 years ago

I am working on a patch for this. If anyone wish to help reply to this note.

#12 in reply to: ↑ 11 ; follow-up: @westi
14 years ago

  • Keywords gci added

Replying to azizur:

I am working on a patch for this. If anyone wish to help reply to this note.

Are you working on this for Google Code In?

We have it as a task for that so if not we need to know to remove it from there so we don't get a student who wants to work on this finding the work already done ;-)

#13 in reply to: ↑ 12 @azizur
14 years ago

Replying to westi:

Are you working on this for Google Code In?

I am not a student so can't take part in Google Code In.

I am working on couple of projects that heavily depends on this feature and would really help if this was built-in as part of the core.

I have just started development and looking into replicating WP_Widget class into WP_Metabox class to keep the same coding standard. Unless you feel that I should take a different approach.

#14 @GamajoTech
14 years ago

  • Cc gary@… added

#15 @mikeschinkel
14 years ago

  • Cc mikeschinkel@… added

#16 @vteixeira
14 years ago

  • Cc victorhteixeira@… added

#17 @vteixeira
14 years ago

I just want to point out this class for reference: http://farinspace.com/wpalchemy-metabox/ or on github: https://github.com/farinspace/wpalchemy

#18 @bainternet
14 years ago

  • Cc bainternet added

+1 on a metabox class

#19 @kingkool68
14 years ago

I wrote my own -> http://svn.kingkool68.com/projects/metabox/

Takes the same arguments as add_meta_box but adds a new option to specify category IDs so the boxes are only visible if that category is checked. It helps reduce the visual clutter.

Just throwing it out there.

#20 @scribu
14 years ago

Related: #14877

#21 @nacin
14 years ago

  • Keywords gci removed
  • Owner set to nacin
  • Status changed from new to reviewing

#22 @c3mdigital
13 years ago

  • Cc chris@… added

#23 @koopersmith
13 years ago

  • Milestone Future Release deleted
  • Resolution set to duplicate
  • Status changed from reviewing to closed

Let's give this a shot for 3.3 — a fresh ticket can be found at #18179.

Note: See TracTickets for help on using tickets.