Clanbite Since 1.6.3
clanbite_register_component( string $slug, array $args ): boolRegister a component: a piece of UI or behaviour (an avatar, reaction chips, an @mention picker) other extensions can use.
Call it on the action clanbite_register_components. A component has a render callback (returns HTML), an enqueue callback (loads its scripts and styles) or both. Consumers never reach into the provider's classes: they ask the registry, so a missing provider means a quiet fallback (clanbite_render_component() returns an empty string) and a replacement provider needs no change in the consumers.
“php add_action( 'clanbite_register_components', function () { clanbite_register_component( 'reaction-summary', array( 'label' => __( 'Reaction chips', 'my-plugin' ), 'provider' => 'my_extension', 'version' => '1.0.0', 'requires' => array( 'reactions' ), 'render' => fn( array $args ): string => my_render_chips( $args ), ) ); } ); “
Parameters
$slug(string) RequiredLowercase slug (
a-z0-9_-), e.g.avatar,reaction-picker.$args(array<string, mixed>) RequiredComponent definition.
$labelstringReadable name.$descriptionstringWhat it is for.$providerstringSlug of the extension that provides it (cp_social_kit,clanbite…).$versionstringComponent versionx.y.z(so consumers can tell what they are using).$rendercallable( array $args ): stringHTML for the arguments the caller passes. Optional.$enqueuecallable(): voidloads the component's scripts and styles. Optional.$requiresstring[]Slugs of components this one needs; it is unavailable while one is missing.$surfacesstring[]Where it is known to be shown (feed,forums…), documented for developers.$argsarrayDocumentation of the argumentsrenderaccepts,name => description.$replaceboolTrue to replace a component another provider registered under the same slug.
Returns
bool True when registered; false for an invalid definition or a slug taken without replace.
Defined in inc/components.php
Changelog
| Version | Description |
|---|---|
| 1.6.3 | Introduced. |