Skip to main content

Tabs and menus

A profile and a space each have a bar of tabs under their head, and the community has two menus: the community menu beside or above every page, and the member menu under the picture of the member. A plugin adds to the tab bars through the registry of buttons, menus and tabs, poly_community_register_ui (Buttons and menus), and to the two menus with a filter. A component declares its tabs in its kit.json.

Download the example plugin (Tweaks for Poly Community, a zip to upload under Plugins → Add New Plugin → Upload Plugin). The code for profiles, spaces and the two menus on this page is in it, and the tests of Poly Community run it as a site owner installs it. In each picture, a red box marks the change it shows. Changes the example makes elsewhere on the same screen, such as its buttons, are left unboxed.

The head of a member profile with its tabs: Posts, Info and Projects boxed in red, then Followers
A Projects tab added after About, About renamed Info, and Following taken out of the bar

One rule for all of it​

A page of the community is drawn once and kept as a page file, which pages move to without a reload, one file serving every reader of a kind. The tabs and menu items are part of it. So a tab says who sees it with a rule, who, which Poly Community settles in every file and in the browser (Who sees it), and what it is for a profile or a space (its count, whether it is there) is worked out from the profile or the space alone.

Each hook below takes a named function, prefixed with the name of your plugin, never an anonymous function: another plugin or a theme can then take it off again with remove_action( 'poly_community_register_ui', 'my_plugin_projects_tab' ), and an error names it.

A tab on every profile​

One registration puts the tab in the bar and gives it its page:

// After About, its page the blocks a function answers for the profile.
function my_plugin_projects_tab( $ui ) {
$ui->add( 'profile.tabs', 'my-plugin-projects', array(
'label' => __( 'Projects', 'my-plugin' ),
'slug' => 'projects',
'after' => 'about',
'page' => array( 'render' => 'my_plugin_projects_page' ),
) );
}
add_action( 'poly_community_register_ui', 'my_plugin_projects_tab' );

// Its page: blocks, as a template holds them.
function my_plugin_projects_page( $profile ) {
return '<!-- wp:heading {"level":2} --><h2 class="wp-block-heading">Projects</h2><!-- /wp:heading -->'
. '<!-- wp:paragraph --><p>What this member is working on shows here.</p><!-- /wp:paragraph -->';
}

A tab takes the keys of an item (An item in a ⋯ menu), and these:

KeyWhat
slugThe last part of its address, /members/{handle}/projects/. Its id when left out.
pageIts page: template, the path of a file of block markup, or render, a named function given the profile or the space that answers block markup.
countA named function given the profile or the space: a number shown after the label, none at 0.

The page is blocks: any blocks of WordPress, of Poly Community, or of your plugin, written as a template holds them. Pressed in the bar, the tab draws its page without a reload: the Interactivity Router brings its page as HTML, as it does every page whose blocks are not among those listed for page files (Page moves).

The tabs of Poly Community on a profile are posts, about, friends (whose slug is the word the site chose, friends or connections), followers and following, then those of the components by their slug, such as reviews and achievements. In a tab bar, where a tab stands is worked out from the tabs that profile or space has: a tab after one it does not have stands with the rest.

Changing the tabs there​

change() renames a tab of Poly Community, moves it, or keeps it from some readers (who) or some profiles (when), and remove() takes it out of the bar:

// About called Info, and Following out of the bar.
function my_plugin_profile_tab_changes( $ui ) {
$ui->change( 'profile.tabs', 'about', array( 'label' => __( 'Info', 'my-plugin' ) ) );
$ui->remove( 'profile.tabs', 'following' );
}
add_action( 'poly_community_register_ui', 'my_plugin_profile_tab_changes' );

A tab of the community taken out of the bar is hidden, not closed: its page still answers at its address. What a page shows and to whom is set in Settings and by the privacy choices of each member. To rename a tab without code, Settings → Words gives any text of Poly Community words of the site own.

A tab for some readers alone​

who keeps a tab from the readers its rule leaves out, its page too: for them the bar leaves it out and its address is not found, from the one registration.

// A Drafts tab for the member on their own profile alone.
function my_plugin_drafts_tab( $ui ) {
$ui->add( 'profile.tabs', 'my-plugin-drafts', array(
'label' => __( 'Drafts', 'my-plugin' ),
'slug' => 'drafts',
'who' => 'own',
'page' => array( 'render' => 'my_plugin_drafts_page' ),
) );
}
add_action( 'poly_community_register_ui', 'my_plugin_drafts_tab' );

function my_plugin_drafts_page( $profile ) {
return '<!-- wp:paragraph --><p>What you have not published yet, seen by you alone.</p><!-- /wp:paragraph -->';
}

own is the member on their own profile and no one else. A tab for the team of the community is array( 'roles' => array( 'moderator', 'staff' ) ), and Who sees it lists every rule. A tab whose rule a page file cannot settle for all its readers keeps its page out of the file, drawn for each reader instead.

A member on their own profile: Edit profile, then Add a project boxed in red, and a Drafts tab boxed in red
A member on their own profile: a Drafts tab and an Add a project button, which no one else sees

A tab on every space​

The place space.tabs the same way, and its page is shown to those who may see what the space holds, as the other tabs of a space are:

function my_plugin_resources_tab( $ui ) {
$ui->add( 'space.tabs', 'my-plugin-resources', array(
'label' => __( 'Resources', 'my-plugin' ),
'slug' => 'resources',
'page' => array( 'render' => 'my_plugin_resources_page' ),
) );
}
add_action( 'poly_community_register_ui', 'my_plugin_resources_tab' );

function my_plugin_resources_page( $space ) {
return '<!-- wp:paragraph --><p>Links and files the space keeps for its members.</p><!-- /wp:paragraph -->';
}

The tabs of Poly Community on a space are posts, members and about (About first for a space without its feed), then those of the components by their slug, such as leaderboard.

poly_community_profile_tabs, the filter before the registry, still works after it, with a deprecation notice, for at least two releases. poly_community_space_tabs and the two page filters, poly_community_space_tab_markup and poly_community_profile_tab_markup, are still supported with no notice: the registry is the way for new code, and they will be deprecated in a later release, once Better Messages has moved to it. A space is a group in other plugins, and every kind of space a component adds (a course, an organization) has the same bar.

The head of a space, Trail Runners, with its tabs: Posts, Members, About and Resources (shown), Resources boxed in red
A Resources tab added to every space

A tab from a component​

A component declares its tabs in its kit.json, each a tab of the registry by its slug, standing after or before the tab it names or with the rest, shown to whom its who says, and keeps its page as a template of its own, templates/profile-{slug}.html or templates/space-{slug}.html:

"tabs": {
"profile": [ { "slug": "learning", "label": "Learning", "after": "about" } ],
"space": []
}

The tab shows while the component is on. A method kit_tab( $tab, $where, $object ) on the component class changes its tab as drawn: it is given array( slug, label, url ) and answers it with a count or other words, or null to leave it out there. To show it on some profiles or spaces only (spaces of one type, members of one type), use poly_community_kit_tab_shown too:

function my_plugin_kit_tab_shown( $shown, $kit, $where, $tab, $object ) {
// $where is profile or space, $object the profile or the space.
return $shown;
}
add_filter( 'poly_community_kit_tab_shown', 'my_plugin_kit_tab_shown', 10, 5 );

A tab that only the member whose page it is sees (Listings, for a member who may list and has none out) is drawn in the page file for every reader, so the member page moves from its file for them as for anyone. Show it in a file (Poly_Community_Json_Moves::for_all()) where its member would see it, and answer it from kit_tab() with the readers it is for, for, as for_readers() takes them:

public function kit_tab( $tab, $where, $profile ) {
if ( 'profile' === $where && $this->only_its_member_sees( $profile ) ) {
$tab['for'] = 'own:' . Poly_Community_Json_Moves()->subject_mark( 'profile', (int) $profile->id );
}
return $tab;
}

A tab with for is left out of what makes member pages alike. A tab shown to some readers without it makes their member pages move by their HTML.

A slug of the community (posts, about, members, followers, following, friends, connections) is never taken by a component.

Other tab bars​

Two more tab bars are places of the registry, a tab there taking the same keys:

PlaceTabsIds of Poly Community
space.settingsThe settings of a space, for whoever runs itgeneral (the page itself), privacy, posts, then those of the components (place, auto)
settings.tabsEdit profile, of the readerprofile (the page itself), notifications, privacy, account, then those of the components (billing, requests and the others). Unlike a profile tab, one taken out is closed: its address answers 404.

The tabs of the members directory are links that narrow it, with no page of their own: the place members.tabs. Its ids of Poly Community are discover, friends and following, then a tab for each member type that has one (type-{slug}). A tab of yours gives its url, count a number beside it, and it is the tab of the page where the address asked has every part of the query of its url:

function my_plugin_members_tabs( $ui ) {
$ui->add( 'members.tabs', 'my-plugin-nearby', array(
'label' => __( 'Nearby', 'my-plugin' ),
'url' => Poly_Community()->routes->members_url( array( 'show' => 'nearby' ) ),
'after' => 'discover',
'who' => 'members',
) );
}
add_action( 'poly_community_register_ui', 'my_plugin_members_tabs' );

poly_community_members_tabs, the filter before the registry, still works after it, with a deprecation notice, for at least two releases.

Two more each have a filter of their own, not on the stable list:

TabsFilterEach tab
My items, for a kind of itempoly_community_my_items_tabs( $tabs, $kind )key ⇒ label, where and order (SQL on the items i), none, empty
A tagpoly_community_tag_tabs( $tabs, $tag )slug ⇒ label, kinds (type ids), look (posts, topics or questions)

An item in the community menu​

The place nav of the registry is the default community menu:

function my_plugin_nav_items( $ui ) {
$ui->add( 'nav', 'my-plugin-help', array(
'label' => __( 'Help', 'my-plugin' ),
'icon' => 'question',
'url' => home_url( '/help/' ),
) );
}
add_action( 'poly_community_register_ui', 'my_plugin_nav_items' );

The menu shows it while the site keeps the default menu. Once the owner saves a menu of their own under Settings → Appearance → Menus, that menu is what shows, and the item is one of the pages offered there to add. It is the item of the page shown where its address is the address of that page.

The ids of Poly Community there are home (or activity where the home is the feed), activity, members, spaces and profile, then the pages of the components: forum, questions, help, and kit-{view} for each page a component names in its nav. An item there takes the keys of an item (An item in a ⋯ menu), and count gives it a number.

An item in the member menu​

The place account is the menu under the picture of the member. A visitor has no picture there, and sees the items of that menu as links beside Log in, so an item for members alone says so with who:

function my_plugin_account_items( $ui ) {
$ui->add( 'account', 'my-plugin-billing', array(
'label' => __( 'Billing', 'my-plugin' ),
'icon' => 'wallet',
'url' => home_url( '/billing/' ),
'who' => 'members',
) );
}
add_action( 'poly_community_register_ui', 'my_plugin_account_items' );

The ids of Poly Community there are profile, settings, my-spaces and saved, then the pages of the components whose place is that menu. These two menus are drawn for their reader, never from a page file, so who there may use any rule, and note puts a second line under the label.

An icon is the name of one of the icons of Poly Community: question, wallet, calendar, star, users, globe and the others the community uses. A page of a component goes in the menus by its nav in kit.json instead (Building a component).

poly_community_account_items, the filter before the registry, still works after it, with a deprecation notice, for at least two releases. poly_community_nav_items is still supported with no notice: the registry is the way for new code, and it will be deprecated in a later release, once Better Messages has moved to it.

The buttons at the foot of the community menu, where it is a column (Live chat of Live Support), are the place nav.foot: an item there runs its action on a press, with its data.

For the buttons of a profile, a space and a post, and the items of their ⋯ menus, see Buttons and menus.

See also Changing a component, Page moves and Hooks of the components.