New Field class, hooking to rwmb_after_save_post
- This topic has 4 replies, 2 voices, and was last updated 9 years ago by
Biznet.
-
AuthorPosts
-
October 4, 2016 at 4:27 PM #4233
Biznet
ParticipantHi !
following my previous post, I am creating a new plugin which adds the reverse post field, to get it proper on both side of the relation in admin.My trouble is, with the serialization, there are inconsistencies, depending on PHP version, WordPress version or whatever, values are either stored as int or as string.
So I would like to implement the copy of the meta as a json encoded string, or as multi value meta.
What I'd like to know is, is there a way to register my hook inside the field class, so that for each declared reverse_post field, I hook to the rwmb_after_save_post to have an automation, and not having to create it outside the field.Could that be in a method of the RWMB_Field, or is there some kind of reflexion somewhere on the declared metaboxes, which would happen before the rwmb_after_save_post can't be registered anymore ?
Thank you already !
October 5, 2016 at 11:05 AM #4236Anh Tran
KeymasterThere's a method
add_actionsofRWMB_Fieldthat you can use to define custom actions for sub-fields. For more info, please see this docs:https://metabox.io/docs/rwmb-field-class/#section-add_actions
October 5, 2016 at 8:27 PM #4239Biznet
ParticipantHi !
sorry, but that won't do the trick, as $field is not an argument in that function. I won't be able to get the 'id' parameter of each declared metabox to copy the meta for the declared ones and only for them.would there be a way to get, from there, all the defined metaboxes, so I could chain on the list, select the reverse_post ones, then copy data only for those for the given post ?
October 8, 2016 at 2:29 PM #4262Anh Tran
KeymasterI got it. To get
$fieldinadd_actionsmethod, you can use this snippet:$args = func_get_args(); $field = $args[0];It would do the trick.
By the way, why don't you just hook to
rwmb_after_save_postfrom outside the field class?October 10, 2016 at 3:12 PM #4265Biznet
ParticipantThank you, I'll use that !
I just didn't want to hook it from outside because I'd like to have a proper plugin, which I could use on any site and for any number of relation without having to write it on 2 places.
In the end, I will extend your post field class to make only 1 metabox declaration (with 2 arguments as post_types) which will create the display on both ends of the relation, and for that I will need something which the class can manage alone !
-
AuthorPosts
- You must be logged in to reply to this topic.