Since version: v1.8.0
Filter acf_tablefield/table_manager/validate_save
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 );
-
$errornullallows the save. To reject it, return an array with a non-empty stringcode. The optional keymessagereplaces the default message, all other keys become details of the error. Any other return value allows the save. Return an incoming error that is notnullunchanged, so the first rejection wins.-
Defaults:
null
-
$table_dataThe table data that is going to be saved. It uses short keys, see Field data.
-
$contextfield: the ACF field array.post_id.selector.is_sub_field(bool).stored_table_data: the decoded stored value of the field,nullif there is none.enforce_field_limits(bool): the result of the filterenforce_field_limits.manager_id: string ornull.
-
$managerThe 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.