Skip to content

Add extensibility hooks for item/location lifecycle and scoped queries - #35

Open
datengraben wants to merge 4 commits into
masterfrom
claude/commonsbooking-buddypress-integration-rtm82b
Open

Add extensibility hooks for item/location lifecycle and scoped queries#35
datengraben wants to merge 4 commits into
masterfrom
claude/commonsbooking-buddypress-integration-rtm82b

Conversation

@datengraben

@datengraben datengraben commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

Small, independent extensibility additions identified while assessing what it would take to integrate CommonsBooking with an external community/group system (e.g. BuddyPress) without forking core logic. Each is its own commit:

  • Lifecycle action hooks (b1322fc, trimmed by 4f5c5fc): adds commonsbooking_booking_cancelled, commonsbooking_item_created and commonsbooking_location_created. Previously the only custom hook in the plugin was commonsbooking_mail_sent, so external code had no reliable way to react to these state transitions without hooking generic save_post/post_updated and re-deriving the "what changed" logic itself. Each hook fires at the single existing point in the codebase where that transition already happens (Model\Booking::cancel(), Item::savePost(), Location::savePost()).

    Note: this originally also added commonsbooking_booking_created / commonsbooking_booking_confirmed, but Add filter/action hooks for admin-extensible booking process #12 (open, unmerged) already adds both at the same call sites with a richer ($postId, $booking) signature. Commit 4f5c5fc drops the duplicates from this PR to avoid double-firing with incompatible signatures once both land — Add filter/action hooks for admin-extensible booking process #12 is the source of truth for those two hooks.

  • Filterable booking eligibility (c79ea5f): commonsbooking_isCurrentUserAllowedToBook() now applies a commonsbooking_isCurrentUserAllowedToBook filter to its result, matching the existing pattern used by commonsbooking_isCurrentUserAdmin / commonsbooking_isCurrentUserCBManager. Today, restricting a timeframe to members of some external group means minting a dedicated WordPress role per group, which doesn't scale. The filter lets external code layer additional eligibility logic on top of the existing role check.

  • Scoped Item/Location queries (88187e4): BookablePost::get() (shared by Item::get()/Location::get(), and therefore also the map, the cb_items/cb_locations shortcodes and the REST API) now applies a commonsbooking_repository_query_args filter to the WP_Query args before running the query. This lets external code scope results by an arbitrary criterion (e.g. a postmeta value tying a post to an externally-managed group) instead of only the built-in category taxonomy. The query cache key is derived from the filtered args rather than the raw input args, so context-dependent scoping (e.g. "current group") can't return stale results cached for a different context.

None of these change default behavior — they only add hook points that no-op until something attaches a callback.

Test plan

  • php -l on all changed files
  • Confirmed no other overlap with Add filter/action hooks for admin-extensible booking process #12 (only touches Booking.php + 2 templates; my remaining hooks touch Model/Booking.php, Item.php, Location.php, includes/Users.php, Repository/BookablePost.php)
  • CI (PHPUnit/PHPCS) — no local PHP toolchain (composer/vendor) available in this environment to run it beforehand
  • Manual smoke test: attach a callback to each new hook/filter in a throwaway mu-plugin and confirm it fires at the expected point (booking cancellation, item/location creation, item/location listing)

Generated by Claude Code

claude added 4 commits July 13, 2026 06:23
Fires commonsbooking_booking_created, commonsbooking_booking_confirmed
and commonsbooking_booking_cancelled at the existing single points
where these state transitions already happen, plus
commonsbooking_item_created and commonsbooking_location_created when
those post types are first published.

Previously the only custom hook in the plugin was commonsbooking_mail_sent,
so external code had no reliable way to react to booking/item/location
lifecycle events (e.g. to mirror them into another system's activity
stream or notifications) without polling or hooking generic WP save_post.
The role-based booking eligibility check had no filter, unlike the
neighbouring commonsbooking_isCurrentUserAdmin and
commonsbooking_isCurrentUserCBManager checks. Restricting a timeframe
to members of an external group/community (rather than a WordPress
role) previously meant minting a dedicated WP role per group, which
does not scale. External code can now layer additional eligibility
logic on top of the existing role check via the
commonsbooking_isCurrentUserAllowedToBook filter.
…ries

BookablePost::get() (shared by Item::get() and Location::get(), and
therefore also the map, the cb_items/cb_locations shortcodes and the
REST API) previously only supported scoping results by post args or
the built-in category taxonomy. External code had no way to scope
results by an arbitrary external criterion, e.g. tagging items/locations
with a postmeta value tying them to a group/community managed outside
of CommonsBooking, without forking the query.

The cache key is now derived from the filtered query args rather than
the raw input args, so that context-dependent filtering (e.g. scoping
by "current group") doesn't return stale results cached for a
different context.
…12

The already-open (unmerged) PR #12 independently adds these same two
hooks at the same call sites in handleBookingRequest()/postUpdated(),
with a richer ($postId, $booking) signature. Keeping both would fire
each hook twice per event with incompatible signatures once both PRs
land. Deferring to PR #12 for booking_created/booking_confirmed;
commonsbooking_booking_cancelled, commonsbooking_item_created and
commonsbooking_location_created are unaffected since PR #12 doesn't
touch Model/Booking.php, Item.php or Location.php.
@datengraben datengraben changed the title Add extensibility hooks for booking/item/location lifecycle and scoped queries Add extensibility hooks for item/location lifecycle and scoped queries Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants