Skip to content

Filter hooks

Aleksandar Predic edited this page Jul 24, 2020 · 1 revision

Filter hooks

Filter registered fields for the metabox

/**
 * @hook psmfields_metabox_fields_{metabox_id}
 * @param array $registeredFields All registered field for the current class instance
 */
return apply_filters(
    sprintf('psmfields_metabox_fields_%s', $this->id),
    $this->facadeInstance->getFieldsArray()
);

Filter field before it is saved to the database

/**
 * @hook psmfields_model_save_field_{meta_key}
 * @param mixed $value Value passed to the model
 * @param int $postId Post object id
 */
$value = apply_filters(
    sprintf(
        'psmfields_model_save_field_%s',
        $metaKey
    ),
    $value,
    $postId
);

Filter field value just after it is fetched from DB and before it is returned

/**
 * @hook psmfields_model_get_field_{meta_key}
 * @param string $metaKey Registered field name that is actually meta_key in the post_meta table
 * @param int $postId Post object id
 */
return apply_filters(
    sprintf(
        'psmfields_model_get_field_%s',
        $metaKey
    ),
    get_post_meta($postId, $metaKey, true),
    $postId
);