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:
| What | Prefix |
|---|---|
| Hooks | poly_community_* |
| REST | poly-community/v1 |
| Blocks | poly-community/* |
| Tables | poly_* |
| CSS custom properties | --poly-* |
| Script modules | @poly-community/* |
| Text domain | poly-community |
The main object
Poly_Community() returns the plugin. Its stable parts:
| Part | What it is |
|---|---|
items | Every kind of post: create(), get_item(), update(), delete(), data(). |
kinds | Kinds of item: register(), get(), of(), id(), counts(). |
attachments | What an item carries beside its words: register(). |
access | Who may do and see what: register_rule(), register_who_can(), who_can(), can_see_item(), can_open_item(), viewer(). |
live_data | Rows and lists drawn from data: register_type(), register_list(). |
settings_rows | A setting on any page of Settings: add(), add_section(). |
routes | Addresses: item_url(), profile_url(), space_url(), home_url(), view_url(). |
kits | The components: get(), view_url(). |
thing_fields | The fields of an item: of_kind(), values(), set_visibility(). |
terms | Category trees: register_tree(). |
relationships | Relationship 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:
| Hook | Registers |
|---|---|
poly_community_register_kits | Another plugin folder of components. See Building a component. |
poly_community_register_post_kinds | Kinds of item. See Kinds of item. |
poly_community_register_attachments | What an item can carry. |
poly_community_register_trees | Category trees. |
poly_community_register_review_targets | What members may review. |
poly_community_register_relationship_types | Relationship types. |
poly_community_register_access_rules | Access rules. |
poly_community_requirements | What a member must do before taking part (a filter). |
poly_community_register_row_types, poly_community_register_lists | Rows and lists drawn from data. |
poly_community_register_data_kinds | A component kinds on the data screens. |
poly_community_register_settings_rows | Settings rows on any page and section. |
poly_community_register_forms | Forms, such as applications and claims. |
poly_community_register_jobs | Background 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_:
| Hook | Registers |
|---|---|
wordplus_sso_providers | A 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.