class Feed_ContextImmutable 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) oruser(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 genericfeedSubjectId.resolve_subject(callable):( int $attribute_value, array $attributes, ?\WP_Block $block ): int. Fall back to the current page, for exampleis_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 arecp_social_postsrows (seeData_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'svisibilityslug (comments, reactions, shares, direct links). Default: falls back tocan_viewfor the subject stored by yourquery, so implement it whenever posts carry their own association.rest_path(callable|string): Path (below the plugin REST namespace) the client loads. Acallablereceives the subject; a string may contain%d. Default:/feeds/{slug}/{subject}/posts, which the plugin serves for you.end_of_feed(callable):( int $subject ): stringmessage shown after the last post.messages(array):unresolvedandforbiddenstrings.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
__construct()Build a context from its registration arguments (see the class docblock).accepts_posts()Whether viewers can post to this context at all.can_post()Whether the user may post to the feed.can_view_post()Whether a single post carrying this context's visibility slug may be read.can_view()Whether the viewer may read the feed.end_of_feed()Message shown after the last post.has_post_gate()Whether a can_view_post callback was supplied.home_post_ids()Post IDs this context contributes to a viewer's home feed.is_valid()Whether the context can run (a query callback is mandatory).query()Query one page of posts.resolve_subject()Resolve the subject ID for a block render.rest_path()REST path (below the plugin namespace) the client loads for this feed.to_editor_array()Data the block editor needs to offer this context.
Defined in inc/Social/Feed_Context.php