Skip to main content

Building on Poly Community

Poly Community is built to be added to. Its own components (events, courses, jobs and the rest) use the same framework another plugin uses, so anything they do, yours can. What you can build lists it all, and what you cannot. To change a component that is there, see Changing a component.

Building or changing a part of a page? Start with Building for instant pages and live updates: the rules that keep its pages moving without a reload and what they show current by itself.

Built on WordPress​

Poly Community is WordPress through and through, with no framework of its own:

  • Pages are blocks, in the Site Editor like any others, with templates and template parts a theme can change.
  • What they show and do is the WordPress Interactivity API: directives in their markup, drawn by PHP on the server first, one store (poly-community), script modules, and moves between pages through the Interactivity Router. The browser runs the Interactivity API of WordPress itself (7.2 or later), never a copy.
  • The WordPress documentation is the full reference for those: the directives, the store and its functions, the router and script modules. These pages cover what Poly Community adds on top.

Built on the Interactivity API maps each part to the WordPress reference, with the rules a block on these pages follows.

What is stable​

The names in the Reference are stable from the day they are listed there, not from 1.0: the parts of Poly_Community() and their methods, the registration hooks, two REST routes, and every block, template part and design token. Each is designed before it is listed, so that it does not need to change, and the list grows by additions.

When a listed name must change anyway, the old way keeps working where it can: an old hook or function with a deprecation notice, an old key read as its new one, an old icon name as an alias. It stays for at least two releases, and the notice names what replaces it. Every change is a line starting with "Developers:" in the changelog of the release it ships in.

Everything else is internal, even when it is public PHP.

The prefixes never change:

WhatPrefix
Hookspoly_community_*
RESTpoly-community/v1
Blockspoly-community/*
Tablespoly_*
CSS custom properties--poly-*
Script modules@poly-community/*
Text domainpoly-community

The main object​

Poly_Community() returns the plugin. Its stable parts:

PartWhat it is
itemsEvery kind of post: create(), get_item(), update(), delete(), data().
kindsKinds of item: register(), get(), of(), id(), counts().
attachmentsWhat an item carries beside its words: register().
accessWho may do and see what: register_rule(), register_who_can(), who_can(), can_see_item(), can_open_item(), viewer().
live_dataRows and lists drawn from data: register_type(), register_list().
settings_rowsA setting on any page of Settings: add(), add_section().
routesAddresses: item_url(), profile_url(), space_url(), home_url(), view_url().
kitsThe components: get(), view_url().
thing_fieldsThe fields of an item: of_kind(), values(), set_visibility().
termsCategory trees: register_tree().
relationshipsRelationship types between members: register_type().

Addresses come from routes​

Build every address with routes or with a component view. Never write /community/ into code: a site may run the community at its root, and a component may have another word for its pages under Settings → Pages and addresses.

$url = Poly_Community()->routes->profile_url( $profile_id );
$url = Poly_Community()->routes->item_url( $item_id );

Registering things​

Each registration hook fires once, with the object to register on:

HookRegisters
poly_community_register_kitsAnother plugin folder of components. See Building a component.
poly_community_register_post_kindsKinds of item. See Kinds of item.
poly_community_register_attachmentsWhat an item can carry.
poly_community_register_treesCategory trees.
poly_community_register_review_targetsWhat members may review.
poly_community_register_relationship_typesRelationship types.
poly_community_register_access_rulesAccess rules.
poly_community_requirementsWhat a member must do before taking part (a filter).
poly_community_register_row_types, poly_community_register_listsRows and lists drawn from data.
poly_community_register_data_kindsA component kinds on the data screens.
poly_community_register_settings_rowsSettings rows on any page and section.
poly_community_register_formsForms, such as applications and claims.
poly_community_register_jobsBackground jobs.

On the WordPlus SDK​

Logging in with another account belongs to the WordPlus SDK, which Poly Community shares with Better Messages and the other WordPlus plugins, so its hook starts with wordplus_ rather than poly_community_:

HookRegisters
wordplus_sso_providersA way to log in, such as Discord or GitLab. See Login providers.

What happened​

poly_community_item_created, poly_community_item_updated and poly_community_item_deleted say what happened to an item. poly_community_kits_changed and poly_community_kit_settings_saved say what happened to the components.

function my_plugin_item_created( $item_id, $item ) {
// An item of any kind is out: a post, a reply, an event, a job.
}
add_action( 'poly_community_item_created', 'my_plugin_item_created', 10, 2 );

Pages​

These filters shape the pages: poly_community_home_choices (what the community home may open on), poly_community_page_kind, poly_community_content_width, poly_community_main_markup, poly_community_sidebar_blocks, poly_community_home_rewrites and poly_community_structured_data. The menus, the tabs of profiles and spaces and the ⋯ menus are places of the registry, poly_community_register_ui, in Tabs and menus and Buttons and menus. poly_community_blueprints adds a folder of kinds of site to the start page.

Blocks and design tokens​

Every poly-community/* block is stable, with every template part name and every --poly-* design token, because sites save them in their templates. Style the community through the tokens rather than its class names, which may change.