Clanbite Social Kit

class Feed_Context

Immutable definition of a feed context (home, profile, team, group, or one registered by a third party).

Register contexts with Feed_Context_Registry::register() (or clanbite_social_kit_register_feed_context()) on the clanbite_social_kit_register_feed_contexts action. A context supplies everything the blocks need, so no block, REST or JavaScript code has to know its name:

  • how to resolve its subject (the team, group, player, or anything else the feed belongs to),
  • who may read it and who may post to it,
  • how to query its posts,
  • the REST path the client loads, and the strings shown for errors.

Supported $args keys (all optional except query):

  • label (string): Name shown in the block editor.
  • subject (string): none (no subject, like Home), number (a numeric ID typed in the editor) or user (a player picker).
  • subject_label (string): Editor label for the subject field, for example "Clan".
  • attribute (string): Block attribute that stores the subject. Leave empty to use the generic feedSubjectId.
  • resolve_subject (callable): ( int $attribute_value, array $attributes, ?\WP_Block $block ): int. Fall back to the current page, for example is_singular( 'my_cpt' ) ? get_queried_object_id() : 0.
  • requires_login (bool): Logged-out visitors get a "log in" message instead of the feed.
  • can_view (callable): ( int $subject, int $viewer_id ): bool. Default: everyone.
  • query (callable, required): ( int $subject, int $viewer_id, int $page, int $per_page ): array{rows: object[], total: int}. Rows are cp_social_posts rows (see Data_Access::get_post()), newest first.
  • can_post (callable): ( int $subject, int $user_id ): bool. Default: nobody (the composer stays hidden).
  • visibility (string): Visibility slug stored on posts created here. Defaults to the context slug. Posts with a custom slug never appear in a player profile or the home feed.
  • fixed_audience (bool): The audience is fixed by the context, so the composer hides its privacy menu. Default true when the context accepts posts.
  • can_view_post (callable): ( object $post, int $viewer_id ): bool. Gate for a single post with this context's visibility slug (comments, reactions, shares, direct links). Default: falls back to can_view for the subject stored by your query, so implement it whenever posts carry their own association.
  • rest_path (callable|string): Path (below the plugin REST namespace) the client loads. A callable receives the subject; a string may contain %d. Default: /feeds/{slug}/{subject}/posts, which the plugin serves for you.
  • end_of_feed (callable): ( int $subject ): string message shown after the last post.
  • messages (array): unresolved and forbidden strings.
  • home_post_ids (callable): ( int $viewer_id, int $limit ): int[]. Post IDs this context contributes to the viewer's home feed (only posts the viewer may read). Omit it and the context never appears in Home.
  • home_stream (bool): Mark a merged multi-author stream so the author is shown on each card. Default false.

class final

Full name
Kernowdev\ClanbiteSocialKit\Social\Feed_Context

Methods

Defined in inc/Social/Feed_Context.php