ACF Table Field Pro Add-on Docs Last updated:

Parent sources

On this page

Since version: v1.8.0

Release Candidate 1.8.0-RC1

This page documents version 1.8.0, which is available as Release Candidate 1.8.0-RC1 for manual installation. The current public version is 1.7.6, automatic plugin updates still deliver that version.

Download the Release Candidate from your account (Download the plugin) and install it manually (Install the plugin). Details may still change until the final release.

Filter acf_tablefield/table_manager/validate_save

New since version 1.8.0

This filter is new.

This filter lets you reject a save of the Table Manager. It runs in update_field() and update_sub_field() after the field was found and before the table is saved. A listener returns null to allow the save, or an array with a code to reject it. Then update_field() returns false, nothing is saved, and get_last_error() returns the code, the message and the details, see Error handling. The check of the field limits is a listener of this filter, see Field limits and the filter acf_tablefield/table_manager/enforce_field_limits.

Parameters

add_filter( 'acf_tablefield/table_manager/validate_save', function( $error, $table_data, $context, $manager ) { 
 
	return $error; 
}, 10, 4 );
    • $error
    • (array|null)
    • null allows the save. To reject it, return an array with a non-empty string code. The optional key message replaces the default message, all other keys become details of the error. Any other return value allows the save. Return an incoming error that is not null unchanged, so the first rejection wins.

    • Defaults: null
    • $table_data
    • (array)
    • The table data that is going to be saved. It uses short keys, see Field data.

    • $context
    • (array)
    • field: the ACF field array. post_id. selector. is_sub_field (bool). stored_table_data: the decoded stored value of the field, null if there is none. enforce_field_limits (bool): the result of the filter enforce_field_limits. manager_id: string or null.

    • $manager
    • (object)
    • The Table Manager instance.

Example: a table needs a caption

add_filter( 'acf_tablefield/table_manager/validate_save', function( $error, $table_data, $context ) { 
 
	if ( null !== $error ) { 
		return $error; 
	} 
 
	if ( empty( $table_data['t']['o']['ca'] ) ) { 
		return array( 'code' => 'missing_caption', 'message' => 'The table needs a caption.' ); 
	} 
 
	return $error; 
}, 10, 3 );

The incoming error is returned unchanged, so an earlier rejection stays.

Respect $context['enforce_field_limits'] if your check should follow the switch of the filter enforce_field_limits. Use $context['stored_table_data'] to compare with the stored table, for example to reject only a change that moves a value further away, like the field limits do.

Previous and Next Sources

Parent sources