25. Hooks and Filters -- Actions | Field Forge - Custom Fields, Built for Speed
Download Log in

25. Hooks and Filters — Actions

Developer Guide

Field Forge provides actions that fire after data changes, enabling you to extend behavior, sync data, and invalidate caches.

fieldforge/field_group_saved

Fires after a field group is created or updated.

php
/**
 * @param int    $group_id The field group ID.
 * @param object $group    The full group object.
 */
add_action( 'fieldforge/field_group_saved', function( $group_id, $group ) {
    wp_cache_flush_group( 'my_theme_cache' );
    error_log( sprintf( 'Field group "%s" (#%d) saved.', $group->title, $group_id ) );
}, 10, 2 );

fieldforge/field_group_deleted

Fires before a field group is deleted.

php
/**
 * @param int $group_id The field group ID being deleted.
 */
add_action( 'fieldforge/field_group_deleted', function( $group_id ) {
    delete_transient( 'my_theme_fields_' . $group_id );
}, 10, 1 );

fieldforge/value_updated

Fires after a field value is inserted or updated.

php
/**
 * @param int    $post_id    The post ID.
 * @param string $field_name The field name that was updated.
 */
add_action( 'fieldforge/value_updated', function( $post_id, $field_name ) {
    // Sync a specific field to postmeta for third-party compatibility
    if ( $field_name === 'price' ) {
        $value = FIELDFORGE_Field_Values::instance()->get_value( 'price', $post_id );
        update_post_meta( $post_id, '_price', $value );
    }

    // Invalidate page cache
    if ( function_exists( 'wp_cache_delete' ) ) {
        wp_cache_delete( 'page_html_' . $post_id, 'my_cache' );
    }
}, 10, 2 );

fieldforge/values_deleted

Fires after all values for a post are deleted.

php
/**
 * @param int $post_id The post ID whose values were deleted.
 */
add_action( 'fieldforge/values_deleted', function( $post_id ) {
    delete_post_meta( $post_id, '_price' );
    delete_post_meta( $post_id, '_sku' );
}, 10, 1 );

Forge AI Assistant Online

Hi! I'm the Field Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs