Opened 14 years ago
Closed 13 years ago
#15066 closed enhancement (duplicate)
Create a Meta Box class
Reported by: | ericmann | Owned by: | 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)
#3
in reply to:
↑ 2
;
follow-up:
↓ 4
@
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
@
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
@
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
@
14 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to Future Release
#11
follow-up:
↓ 12
@
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:
↓ 13
@
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
@
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.
#17
@
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
#19
@
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.
+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.