groundhogg/sanitize_object_meta

πŸ“… Published on

πŸ“ Last updated

Documentation

Β»

Filter Hooks

Β»

groundhogg/sanitize_object_meta

Filters a meta value before it is saved to the database for any Groundhogg object. Use this to sanitise, validate, or transform custom meta values written by your extension.

apply_filters( 'groundhogg/sanitize_object_meta', $value, $key, $object_type, $original_value );

You will receive the sanitised value, the meta key string, the object type string (e.g. 'contact'), and the original unsanitised value.

Example

add_filter( 'groundhogg/sanitize_object_meta', 'my_extension_sanitize_meta', 10, 4 );

/**
 * Enforce a maximum value for the loyalty_points meta key.
 *
 * @param mixed  $value
 * @param string $key
 * @param string $object_type
 * @param mixed  $original_value
 *
 * @return mixed
 */
function my_extension_sanitize_meta( $value, $key, $object_type, $original_value ) {
    if ( $key === 'loyalty_points' && $object_type === 'contact' ) {
        return min( absint( $value ), 10000 );
    }

    return $value;
}

Was this helpful?

Let us know if this document answered your question. That’s the only way we can improve.