feat(Listings): add map_card_renderer extension point#2774
Open
nazmulhasan103 wants to merge 10 commits intosovware:developmentfrom
Open
feat(Listings): add map_card_renderer extension point#2774nazmulhasan103 wants to merge 10 commits intosovware:developmentfrom
nazmulhasan103 wants to merge 10 commits intosovware:developmentfrom
Conversation
Introduce a public nullable callable property `$map_card_renderer` on `Directorist_Listings`. When set, it is invoked instead of the default template for each map marker card — in both `openstreet_map_card_data()` and `load_google_map()`. This gives integrations (e.g. page builders, themes) a clean, zero-overhead way to replace the map popup markup without relying on global template-path filters or shared static state. Signature: callable( int $listing_id, array $opt ): string The property defaults to null so all existing behaviour is fully preserved.
4 tasks
Consolidates thumb-card template and loop_get_the_thumbnail() into a single static call — no Directorist_Listings instantiation needed. Key improvements over the previous approach: - Zero class instantiation, zero setup_postdata, zero global state - Attachment IDs fetched once and reused for both the front image and the optional blur-background layer (previously fetched twice) - Accepts a listing ID directly instead of relying on get_the_ID() Helper::get_listing_card_image( int $listing_id ): string Helper::listing_thumbnail_img( ... ): string (private, handles single image, multiple images/swiper, and fallback default image)
This reverts commit 22ce4a9.
Collaborator
|
Why not use a WordPress filter here instead of a callable property? $content = apply_filters( 'directorist_map_card_content', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two focused additions to eliminate the need for
Directorist_Listingsinstantiation in integrations that only need specific listing output.1.
Helper::get_listing_card_image( int $listing_id ): stringConsolidates the
thumb-cardtemplate andloop_get_the_thumbnail()into a single static call. No class instantiation, nosetup_postdata, no global post state required.Improvements over the current approach:
$listing_iddirectly — no reliance onget_the_ID()listing_thumbnail_img()handles single image, swiper carousel, and default image fallback2.
Directorist_Listings::$map_card_renderercallable propertyAllows integrations to replace the map marker card HTML for both OpenStreet and Google Maps without hooking a global template filter or using shared static state.
Signature:
callable( int $listing_id, array $opt ): stringDefaults to
null— all existing behaviour fully preserved, zero breaking changes.Test plan
Helper::get_listing_card_image()renders identically to the existing thumb-card template (cover / contain / full modes)map_card_renderer = null(default) — no regression in map rendering🤖 Generated with Claude Code