Anchor Posts keeps a public WordPress post as an anchor while each signed-in user comments in a private linked conversation behind the same URL. It is built into Cacbot, so it is off while AI support is switched off.
Storage
| Key | Where | Meaning |
|---|---|---|
_cacbot_anchor_post |
post meta | The post is an anchor. |
_cacbot_linked_to |
post meta on a linked post | The anchor it belongs to. |
_cacbot_linked_post_for_anchor_post_{anchor_id} |
user meta | The user’s active linked post on that anchor. |
_aiplugin7139_cascade_trashed, _aiplugin7139_pre_trash_status, _aiplugin7139_restore_active_for_user |
post meta on a linked post | Recorded when an anchor’s trash cascade takes the linked post, and used to restore it. |
Linked posts are always cacbot-conversation posts (private, authored by their user).
Behavior
- Reads never create linked posts.
- Authenticated comment submission, through the classic form or
POST /wp/v2/comments, creates a private linked post only when no valid active link exists. Routing runs atpreprocess_comment/rest_pre_insert_commentpriority 5, so consumers filtering at the default priority, Cacbot’s comment pipeline among them, see the linked post. - After a classic comment, the browser returns to the public anchor URL with a
#comment-{ID}fragment. - A logged-in viewer’s comment queries on an anchor (
comments_arrayand frontendWP_Comment_Query) return only their linked thread, or nothing when they have no valid link. Logged-out visitors see the anchor’s own comments. Admin, AJAX and REST queries are not rerouted. - A linked thread includes approved and pending comments, oldest first.
- A user can have several linked posts per anchor, with one active selection.
- Cross-user or malformed pointers resolve to a safe anchor context.
- Inherited settings: a new linked post copies the anchor’s transferable Cacbot settings (
MetadataProperties::transferableAnchorPostKeys(), throughaiplugin7139_copy_meta_keys), so the conversation answers with the anchor’s instructions, model, placeholder and limits. - Switching conversations: visiting a linked post’s URL as its author makes it their active link on its anchor, then redirects to the anchor, which now shows that conversation. A menu of linked post links is therefore enough to navigate a user’s conversations. If the link cannot be activated (for example, the anchor’s comments are closed), the author stays on the linked post. When anyone else visits a linked post, nothing happens: no redirect, and no link changes. Linked posts are private, so WordPress decides what they see. The switch happens on an ordinary GET with no nonce, so any page that makes the author’s browser load one of their linked post URLs switches their active conversation. It can only choose among their own linked posts.
- Deactivation removes only the active pointer and preserves history.
- Front-end admin bar: every logged-in user sees the admin bar on the front end. The
show_admin_barfilter runs atPHP_INT_MAX, so a theme or plugin that turns the bar off does not hide it. The “Show Toolbar when viewing site” option is hidden on the profile and user-edit screens, and a profile save keeps each user’s storedshow_admin_bar_front, so deactivating Cacbot brings back their own choice. Logged-out visitors and the Customizer preview keep WordPress’s default of no bar. spawn_linked_postcapability: every user has it by default. An administrator (any user withpromote_userfor that user) turns it off or on per user with the Anchor Posts → Spawn linked posts checkbox on the profile / user-edit screen. With it off, a comment that would create a linked post is refused (403) and New Chat is hidden. Comments still go into the user’s active linked post, and switching conversations by URL still works. It is always checked with the anchor ID (user_can($user, 'spawn_linked_post', $anchor_id)), so amap_meta_capfilter can narrow it to particular anchors.- New Chat admin bar node (
anchor-posts-new-chat): on a singular anchor, for a logged-in user withspawn_linked_post, the admin bar shows New Chat with thedashicons-format-chaticon. Clicking it posts toanchor-posts/v1/new-chatwith awp_restnonce, which unlinks the active linked post, then removes the thread’s comments from the page without a reload. Comments are found by core markup (comment_class()plusid="comment-{ID}"), anddocumentreceives anaiplugin7139:new-chatevent (detail.anchorPostId) for any other thread UI to reset. Without JavaScript, or if the request fails, the node’s link is the nonce’dadmin-post.phphandler below. With no active link the node is rendered collapsed (classanchor-posts-new-chat-hidden). It slides in once the user types into, or submits, the anchor’s comment form, and collapses again after New Chat. The slide is off underprefers-reduced-motion. - New Chat widget (
anchor_posts_new_chat): a classic sidebar widget that an admin places under Appearance → Widgets. On a singular anchor, for a logged-in user withspawn_linked_post, it shows a New Chat button. With an active link the button POSTs toadmin-post.phpwithaction=aiplugin7139_new_chat,anchor_post_id={ID}and a_wpnonceforaiplugin7139_new_chat_{ID}, which deactivates the link and redirects back to the anchor. With no active link the button is disabled. Everywhere else the widget prints nothing. - Recent Chats widget (
anchor_posts_recent_chats): a classic sidebar widget, titled “Recent Chats” until an admin changes it. On a singular anchor, for a logged-in user, it lists links to that user’s linked posts on that anchor, newest first, up to “Number of chats to show” (default 5), labelled with each post’s date and time. The active one hasaria-current="true". Following a link switches conversations. With no linked posts it says “No chats yet.” It does not requirespawn_linked_post. - Trash, restore, and permanent deletion of an anchor cascade to its linked posts according to the recorded lifecycle markers. Trashing or deleting a linked post retires every pointer to it.
PHP interface
Code outside Cacbot should call only these functions, never the classes behind them or the storage keys.
Function (aiplugin7139\AnchorPosts\…) |
Returns |
|---|---|
is_anchor($post_id) |
Whether the post is an anchor. |
is_linked_post($post_id) |
Whether the post is a linked post associated with an anchor. |
linked_post_anchor_id($linked_post_id) |
The linked post’s anchor, or 0. |
linked_post_type() |
cacbot-conversation. |
resolve($post_id, $user_id) |
A Contracts\Resolution: requestedPostId(), effectivePostId(), isAnchor(), hasActiveLink(), state(). |
effective_post_id($post_id, $user_id) |
The post holding the user’s thread: a valid active linked post, else the requested post. |
active_linked_post_id($anchor_id, $user_id) |
The raw active pointer (unvalidated). |
associated_linked_post_ids($anchor_id, $user_id) |
The user’s non-trashed linked posts for the anchor, oldest first. |
create_linked_post($anchor_id, $user_id) |
New active linked post ID, or WP_Error. |
activate_link($anchor_id, $linked_post_id, $user_id) |
true or WP_Error. |
deactivate_link($anchor_id, $user_id) |
true or WP_Error. |
Resolution states are not_anchor, linked, no_linked_post, and invalid_pointer. The frontend data service serves no_linked_post under its legacy payload name no_conversation.
Hooks
Filters:
aiplugin7139_new_linked_post_data($data, $anchor_id, $user_id)runs before insertion; type, status, and author are revalidated afterward.aiplugin7139_copy_meta_keys($keys, $anchor_id, $linked_id, $user_id): the anchor meta copied once, when the linked post is created. Cacbot adds its transferable settings (Integrations\AnchorPostsMetaCopy).aiplugin7139_can_create_linked_post($decision, $anchor_id, $user_id)may tighten policy.aiplugin7139_resolution($resolution, $requested_id, $user_id)runs only for a valid linked resolution.aiplugin7139_new_chat_label($label, $anchor_id)changes the New Chat node’s and widget button’s text (defaultNew Chat).aiplugin7139_recent_chat_label($label, $linked_id, $anchor_id)changes a Recent Chats link’s text.
Actions fire once, after the state change succeeds:
| Action | Arguments |
|---|---|
aiplugin7139_linked_post_created |
linked ID, anchor ID, user ID |
aiplugin7139_link_activated |
anchor ID, linked ID, user ID, previous linked ID |
aiplugin7139_link_deactivated |
anchor ID, linked ID, user ID |
aiplugin7139_linked_post_trashed |
linked ID, anchor ID, user ID |
aiplugin7139_linked_post_deleted |
linked ID, anchor ID, user ID |
The frontend data service listens to the activated, deactivated and trashed actions to mark the anchor and linked post changed.
REST API
All routes require normal WordPress authentication: cookie + X-WP-Nonce, or an application password.
| Route | Parameters | Success |
|---|---|---|
POST /wp-json/anchor-posts/v1/links |
anchor_post_id, linked_post_id |
{success: true, result: true} |
POST /wp-json/anchor-posts/v1/linked-posts |
anchor_post_id |
201 {success: true, result: <linked ID>} |
DELETE /wp-json/anchor-posts/v1/links/{anchor_post_id} |
— | {success: true, result: true} |
POST /wp-json/anchor-posts/v1/new-chat |
anchor_post_id |
{success: true, result: true}, also when there was no active link. Requires spawn_linked_post (otherwise 403 anchor_posts_new_chat_forbidden). |
Failures are WP_Error responses with stable anchor_posts_* codes.
Designating an anchor
The anchor marker is registered as post meta on the core posts endpoint for every comment-enabled post type, so a post is made an anchor (or un-made one) through wp/v2/posts, or with the editor’s Anchor Post checkbox. The current user needs edit_post on that post; otherwise the request fails with rest_cannot_update and the flag is unchanged.
curl -u 'editor:APPLICATION PASSWORD' -X POST https://example.com/wp-json/wp/v2/posts/123 \
-H 'Content-Type: application/json' \
-d '{"meta": {"_cacbot_anchor_post": true}}'
The post response reports the flag as the boolean meta._cacbot_anchor_post. Writing false stores an empty value; writing null deletes the meta row. Either way is_anchor() returns false. An anchor marker alone does not make the anchor itself a Cacbot conversation; its linked posts are.