Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Extensive tests required] acf_get_field() performance bottleneck on local fields (~40%) #258

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions includes/acf-field-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
18 changes: 18 additions & 0 deletions includes/local-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

}
}

Expand Down