Skip to content

Extending SpaceBay (add-ons)

Add-ons such as SpaceBay Pro can add features to the portal, the admin screens, the login, events, badges, messages and settings. These are the PHP hooks for that:

HookTypePurpose
spacebay_settings_schemaFilterAdd settings. An entry can have a sanitize callable that cleans the value. Type array takes a list of objects and needs sanitize.
spacebay_settings_responseFilterAdd what your settings need to the data sent to the settings screen.
spacebay_table_namesFilterRegister the short names of your own tables. Add-ons create and remove their tables themselves.
spacebay_app_configFilterChange the configuration passed to the portal and admin apps. Receives the config and the current user.
spacebay_pulseFilterAdd data to the pulse that the apps poll (/me/pulse). Receives the data and the member ID.
spacebay_conversation_messagesFilterChange a page of a conversation’s messages.
spacebay_conversation_itemsFilterChange the list of conversations sent to a member.
spacebay_message_system_textFilterText of a system line in a chat for your own events, such as Pro’s call lines.
spacebay_social_profileFilterThe profile read from Google or Facebook (id, email, verified, name) and the provider. Set verified to false to stop accounts from being connected by email address.
spacebay_login_challengeFilterAdd a second login step after a correct password or a Google or Facebook login. Return an array that describes the step, a WP_Error, or null to log the member in.
spacebay_security_summaryFilterAdd data to the member’s Password and security page.
spacebay_signup_catalogueFilterAdd fields that can be on the signup form. Keys start with field_.
spacebay_signup_rowsFilterChoose which signup fields are shown, which are required and their order.
spacebay_profile_field_valuesFilterClean answers to extra profile fields before they are saved.
spacebay_profile_display_fieldsFilterExtra profile fields shown on a profile, as label and value.
spacebay_default_badgesFilterChange the badges new communities start with.
spacebay_achievementsFilterChange the points, level and badges shown on a profile. Receives the summary, the member ID and the viewer ID.
spacebay_event_fieldsFilterAdd fields an event form may send, as REST argument definitions.
spacebay_event_cleanFilterAdd your own clean values to an event before it is saved.
spacebay_event_answer_checkFilterReturn a WP_Error to refuse an event answer, for example when the event is full.
spacebay_event_can_see_linkFilterWhether the viewer may see an event’s online link.
spacebay_event_dataFilterChange an event as sent to the apps.
spacebay_enqueue_appActionAfter the portal or admin app is enqueued. Receives $app (portal or admin) and $handle. Enqueue your script here with $handle as a dependency.
spacebay_conversation_deletingActionBefore a conversation is deleted, so you can remove your own data. Receives the conversation ID.
spacebay_admin_screensFilterAdd a screen to the SpaceBay admin menu: route (for example /shops) => label. Add the route with addRoute() in the admin app.
spacebay_member_profileFilterAdd data to a member’s profile page. Receives the data, the member ID and the viewer ID.
spacebay_notification_groupFilterChoose the email preference group (for example moderation) of your own notification actions, so they can be emailed.

JavaScript. The portal and admin apps expose window.SpaceBay. Your script loads after the app script and registers before the app starts.

NamePurpose
extend( callback )Register your add-on. The callback receives { app, router, config, api, area } (and pinia in the portal) before the app mounts. area is portal or admin.
addSlot( name, component, { order, replace } )Show a Vue component in a named slot. Lower order shows first; replace: true shows it instead of the slot’s own content.
addRoute( route )Add a Vue Router route.
addHook( name, fn ), runHook( name, ...args )Run code when the app calls a hook.
addFilter( name, fn ), applyFilters( name, value, ...args )Change a value the app passes through a filter.
Vue, VueRouter, PiniaThe libraries the app uses (Pinia in the portal only). Build your add-on with vue, vue-router and pinia as externals that point here, so both scripts share one copy.
AppSlotsHooks and filters
Portalapp.layers, messages.header.actions, login.step, account.security, account.profile.fields, member.achievements.actions, event.form.fields, nav.items (each component renders an <li>), home.feed.top, space.posts.top (receives space)Hook pulse (receives the pulse data); filters login.resume and member.tabs (add { key, label, component } profile tabs; receives { member, config }; the component gets member)
Adminsettings.login, settings.signup, settings.messages, settings.events, settings.badges, admin.members, and settings.<id> for sections you addFilter settings.sections (add { id, icon, title } sections to Settings; their content goes in slot settings.<id>, which receives the settings form). Routes added with addRoute() can set meta.title for the browser tab.

Check the extension version. SpaceBay defines the constant SPACEBAY_EXTENSION_API, a whole number that is the version of the extension points on this page. It is raised whenever an extension point is added or changed. The current value is 2. It is separate from SPACEBAY_VERSION, because a build can have the same plugin version and still lack a hook. Check it before your add-on registers anything, and show an admin notice instead of running when the constant is missing or too low. SpaceBay Pro does this, and requires the lowest value that has the hooks it uses:

if ( ! defined( 'SPACEBAY_EXTENSION_API' ) || (int) SPACEBAY_EXTENSION_API < 2 ) {
// Show an admin notice and stop. Do not add your hooks.
return;
}

A small add-on that puts a button at the top of every chat:

my-addon.php
add_action( 'spacebay_enqueue_app', function ( $app, $handle ) {
if ( 'portal' === $app ) {
wp_enqueue_script( 'my-addon', plugins_url( 'my-addon.js', __FILE__ ), array( $handle ), '1.0.0', true );
}
}, 10, 2 );
// my-addon.js
window.SpaceBay.extend( () => {
const { h } = window.SpaceBay.Vue;
const MyButton = { render: () => h( 'button', { type: 'button' }, 'Hello' ) };
window.SpaceBay.addSlot( 'messages.header.actions', MyButton, { order: 20 } );
} );