How to determine type (post/user) of $object_id passed in rwmb_after_save_field

Support MB User Profile How to determine type (post/user) of $object_id passed in rwmb_after_save_field

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #45741
    pluginovenpluginoven
    Participant

    According to the documentation of rwmb_after_save_field the $object_id is:

    The object ID

    So for example, (int) 482 is the object id.
    Cool. Now let's update some meta as the example in the documentation:
    update_post_meta( $object_id, 'log_event_dates', $log );
    except, in this case, the object is not a post, but a user.
    Since rwmb_after_save_field is triggered for both posts AND users (using MB User Profile) how can we determine the type that the object id represents?
    Is this passed in any of the $field attributes?
    Is there an internal function that can be called to determine the type of the object?
    I thought it best to ask before further bloating up the $meta_boxes object by declaring the object type as an attribute.

    #45751
    PeterPeter
    Moderator

    Hello,

    You can use some WordPress function to check the type of the object ID
    https://developer.wordpress.org/reference/functions/get_user_by/
    https://developer.wordpress.org/reference/functions/get_post/

    If you don't want to check the object type, you can use the specific filter with the field ID that is associated with an object type.
    rwmb_{$field_id}_after_save_field

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.