acf_untrash_field_group()
acf_untrash_field_group
Restores a field_group from the trash.
Hooks from the function
Returns
true|false. True if field_group was trashed.
Usage
acf_untrash_field_group( $id );
- $id((int|string))
- The field_group ID, key or name.
Changelog
| Since 5.0.0 | Introduced. |
acf_untrash_field_group() acf untrash field group code ACF 6.0.4
function acf_untrash_field_group( $id = 0 ) {
// Disable filters to ensure ACF loads data from DB.
acf_disable_filters();
// Get the field_group.
$field_group = acf_get_field_group( $id );
// Bail early if field_group was not found.
if ( ! $field_group || ! $field_group['ID'] ) {
return false;
}
// Untrash fields.
$fields = acf_get_fields( $field_group );
if ( $fields ) {
foreach ( $fields as $field ) {
acf_untrash_field( $field['ID'] );
}
}
// Untrash post.
wp_untrash_post( $field_group['ID'], true );
// Flush field group cache.
acf_flush_field_group_cache( $field_group );
/**
* Fires immediately after a field_group has been trashed.
*
* @date 12/02/2014
* @since 5.0.0
*
* @param array $field_group The field_group array.
*/
do_action( 'acf/untrash_field_group', $field_group );
// Return true.
return true;
}