Support Forum
Hi !
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 !
There's a method add_actions
of RWMB_Field
that 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
Hi !
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 ?
I got it. To get $field
in add_actions
method, 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_post
from outside the field class?
Thank 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 !