Dynamic Content API
This article is a guide instructing you how to get started building your own Dynamic Content integration.
Sample Class
This can serve as a template for creating your own group and touches on the basic features of Dynamic Content.
<?php
class DynamicContentExample {
/**
* This is the group in the dynamic content
* {{dc:GROUP}}
*/
const GROUP = "example";
// Set filters
static public function setup() {
// Every {{dc:GROUP}} will filter to this function
add_filter('cs_dynamic_content_' . self::GROUP, [self::class, 'supplyField'], 0, 4);
// When cornerstone loads and wants to see what fields
// it can provide in the UI
add_action('cs_dynamic_content_setup', [self::class, 'register']);
}
// Register names and fields for use with
// the UI
static public function register() {
// Register the Group name
cornerstone_dynamic_content_register_group([
'name' => self::GROUP,
'label' => "Example Group",
]);
// Register a field called 'Field'
cornerstone_dynamic_content_register_field([
'name' => 'field',
'group' => self::GROUP,
'label' => 'Field',
'controls' => [
[
'key' => 'key',
'type' => 'text',
'label' => 'Key',
],
],
]);
}
// Runs when the group has been called
// through {{dc:GROUP:SOME_FIELD}}
static public function supplyField($result, $field, $args = []) {
// Which field
switch ( $field ) {
case 'field':
// Filtering args is a keyed array when used
$result = 'Field Called with ' . json_encode($args);
break;
default:
break;
}
// Accepts all return types
// although arrays won't display without
// {{dc:GROUP:SOME_FIELD type='json'}} or another type return
// or used via a looper
return $result;
}
}
// Load through how you see fit
add_action("init", [DynamicContentExample::class, "setup"]);
Then in the UI, it will look something like this.

See something inaccurate? Let us know