From ba20aff44324c7d4899cc81e70250c3ce8d8ded9 Mon Sep 17 00:00:00 2001 From: Konrad Date: Sat, 30 Nov 2019 12:18:38 +0100 Subject: [PATCH] Fix get_field() performance bottleneck on local fields --- includes/acf-field-functions.php | 17 ++++++++--------- includes/local-fields.php | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/includes/acf-field-functions.php b/includes/acf-field-functions.php index f0e48644..abddd845 100644 --- a/includes/acf-field-functions.php +++ b/includes/acf-field-functions.php @@ -20,21 +20,20 @@ function acf_get_field( $id = 0 ) { if( is_object($id) ) { $id = $id->ID; } + + // Check local fields first. + if( acf_is_local_field($id) ) { + return acf_get_local_field( $id ); + } // Check store. $store = acf_get_store( 'fields' ); if( $store->has( $id ) ) { return $store->get( $id ); } - - // Check local fields first. - if( acf_is_local_field($id) ) { - $field = acf_get_local_field( $id ); - - // Then check database. - } else { - $field = acf_get_raw_field( $id ); - } + + // Then check database. + $field = acf_get_raw_field( $id ); // Bail early if no field. if( !$field ) { diff --git a/includes/local-fields.php b/includes/local-fields.php index 26f57f29..f604c040 100644 --- a/includes/local-fields.php +++ b/includes/local-fields.php @@ -275,7 +275,25 @@ function acf_add_local_fields( $fields = array() ) { // Add each field. foreach( $fields as $field ) { + + // Validate field. + $field = acf_validate_field( $field ); + + // Set input prefix. + $field['prefix'] = 'acf'; + + /** + * Filters the $field array after it has been loaded. + * + * @date 12/02/2014 + * @since 5.0.0 + * + * @param array The field array. + */ + $field = apply_filters( "acf/load_field", $field ); + acf_add_local_field( $field, true ); + } }