fewbricks\acf\field_group::check_keys PHP Method

check_keys() private method

Checks for duplicate keys. This functions hould not be called in a production environment since it will cause wp_die if a duplicate key is found and will also slow down performance by looping lots of multidimensional arrays.
private check_keys ( $fields )
$fields
    private function check_keys($fields)
    {
        global $debug_keys;
        $error_string = false;
        $name_of_looped_field = false;
        foreach ($fields as $array_key => $value) {
            if (!$error_string && is_array($value)) {
                // If we have not already run into an error and we are dealting with an array
                $this->check_keys($value);
            } elseif ($array_key === 'key') {
                if (array_search($value, $debug_keys) !== false) {
                    // If key already exists
                    $error_string = 'The key <b>' . $value . '</b> already exists.';
                } elseif (substr($value, 0, 1) == '_' || substr($value, -1) == '_') {
                    // If the key starts or ends with an underscore
                    $error_string = 'A key must not start or end with an underscore. You have probably forgotten to set a key somewhere. Key with errors: <b>' . $value . '</b>';
                } else {
                    $debug_keys[] = $value;
                }
            } elseif ($array_key === 'name') {
                $name_of_looped_field = $value;
            }
            if ($error_string !== false && $name_of_looped_field !== false) {
                // If we have an error and have found the name
                $die_string = 'Message from Fewbricks: ';
                $die_string .= 'Fatal error when adding field group "' . $this->settings['title'] . '". ';
                $die_string .= $error_string . ' ';
                $die_string .= 'Please use another key for field "' . $name_of_looped_field . '"';
                wp_die($die_string);
            }
        }
    }