WP Webhooks / Docs / fswa_normalize_object
Filter since v1.5.0

fswa_normalize_object

Converts custom PHP objects in hook arguments into plain arrays for JSON serialization.

$

/ Signature

apply_filters( 'fswa_normalize_object', $data, $object )

/ When it fires

Fires for each PHP object encountered when serializing WordPress hook arguments to JSON — except closures, DateTimeInterface and Traversable objects, which are converted before this filter runs.

/ Parameters

NameInTypeReqDescription
$dataparammixedyesCurrent normalized value — `null` initially. Return an array to replace the object.
$objectparamobjectyesThe PHP object to normalize (e.g. a `WPCF7_Submission`). Use `instanceof` or `get_class()` to pick yours.

/ Returns

array|null Return an array to use as the object's representation; its values are normalized recursively and a `__type` key with the class name is added. Return anything else (leave `null`) to fall through to the default extraction: `get_data()`, then `jsonSerialize()`, then `get_properties()`, then the public properties.

/ Examples

Normalize a custom form submission object

add_filter( 'fswa_normalize_object', function ( $data, $object ) {
    if ( ! $object instanceof My_Form_Submission ) return $data;
    return [
        'form_id' => $object->get_form_id(),
        'fields'  => $object->get_fields(),
    ];
}, 10, 2 );

/ Related

Ready

Your next automation is
one sentence away.

$ wp plugin install flowsystems-webhook-actions --activate