function acf_get_field($selector = null, $db_only = false) { // vars $field = false; $type = 'ID'; // ID if (is_numeric($selector)) { // do nothing // object } elseif (is_object($selector)) { $selector = $selector->ID; // string } elseif (is_string($selector)) { $type = acf_is_field_key($selector) ? 'key' : 'name'; // other } else { return false; } // return early if cache is found $cache_key = "get_field/{$type}={$selector}"; if (!$db_only && acf_isset_cache($cache_key)) { return acf_get_cache($cache_key); } // ID if ($type == 'ID') { $field = _acf_get_field_by_id($selector, $db_only); // key } elseif ($type == 'key') { $field = _acf_get_field_by_key($selector, $db_only); // name (rare case) } else { $field = _acf_get_field_by_name($selector, $db_only); } // bail early if no field if (!$field) { return false; } // validate $field = acf_get_valid_field($field); // set prefix (acf fields save with prefix 'acf') $field['prefix'] = 'acf'; // bail early if db only value (no need to update cache) if ($db_only) { return $field; } // filter for 3rd party customization $field = apply_filters("acf/load_field", $field); $field = apply_filters("acf/load_field/type={$field['type']}", $field); $field = apply_filters("acf/load_field/name={$field['name']}", $field); $field = apply_filters("acf/load_field/key={$field['key']}", $field); // update cache // - Use key instead of ID for best compatibility (not all fields exist in the DB) $cache_key = acf_set_cache("get_field/key={$field['key']}", $field); // update cache reference // - allow cache to return if using an ID selector acf_set_cache_reference("get_field/ID={$field['ID']}", $cache_key); // return return $field; }
function acf_get_field_group($selector = null) { // vars $field_group = false; $type = 'ID'; // ID if (is_numeric($selector)) { // do nothing // object } elseif (is_object($selector)) { $selector = $selector->ID; // string } elseif (is_string($selector)) { $type = 'key'; // other } else { return false; } // return early if cache is found $cache_key = "get_field_group/{$type}={$selector}"; if (acf_isset_cache($cache_key)) { return acf_get_cache($cache_key); } // ID if ($type == 'ID') { $field_group = _acf_get_field_group_by_id($selector); // key } else { $field_group = _acf_get_field_group_by_key($selector); } // bail early if no field if (!$field_group) { return false; } // filter for 3rd party customization $field_group = apply_filters('acf/get_field_group', $field_group); // update cache // - Use key instead of ID for best compatibility (not all field groups exist in the DB) $cache_key = acf_set_cache("get_field_group/key={$field_group['key']}", $field_group); // update cache reference // - allow cache to return if using an ID selector acf_set_cache_reference("get_field_group/ID={$field_group['ID']}", $cache_key); // return return $field_group; }
function acf_format_value($value, $post_id, $field) { // vars $cache_key = "format_value/post_id={$post_id}/name={$field['name']}"; // return early if cache is found if (acf_isset_cache($cache_key)) { return acf_get_cache($cache_key); } // apply filters $value = apply_filters("acf/format_value", $value, $post_id, $field); $value = apply_filters("acf/format_value/type={$field['type']}", $value, $post_id, $field); $value = apply_filters("acf/format_value/name={$field['_name']}", $value, $post_id, $field); $value = apply_filters("acf/format_value/key={$field['key']}", $value, $post_id, $field); // update cache acf_set_cache($cache_key, $value); // return return $value; }
function acf_get_field_types() { // vars $cache_key = 'acf_get_field_types'; // check cache if (acf_isset_cache($cache_key)) { return acf_get_cache($cache_key); } // get types $types = apply_filters('acf/get_field_types', array()); // update cache acf_set_cache($cache_key, $types); // return return $types; }