Skip to main content
Documentation/Developers/APIs/Adding an API Key Field

Adding an API Key Field

Breakdance has a place to keep third-party credentials: the API Keys tab on the Breakdance
settings page. If your extension talks to an external service, registering a field there is
better than building your own settings screen — users already know where keys live, and the
values are stored with Breakdance's other global options.

Registering a field

PHP
add_action('breakdance_loaded', function () {
    BreakdanceAPIKeysregisterKey([
        'name' => 'Go High Level',
        'slug' => 'custom_go_high_level',
    ]);
});

Prefix the slug with something specific to your plugin. Every registered key shares one
storage array, so a generic api_key is asking for a collision.

Reading the value

PHP
$key = BreakdanceAPIKeysgetKey('custom_go_high_level');

if (!$key) {
    return; // not configured yet
}

getKey() returns an empty string when the field has never been filled in, so check before
using it. There's also BreakdanceAPIKeysgetAllKeys(), which returns every stored key as
a slug-to-value array.

Values can be set programmatically with BreakdanceAPIKeyssetKey($slug, $value). Use it
for migrations — for a key a human types, the settings tab is the right surface.