Skip to content

feat(Listings): add map_card_renderer extension point#2774

Open
nazmulhasan103 wants to merge 10 commits intosovware:developmentfrom
nazmulhasan103:feature/map-card-renderer
Open

feat(Listings): add map_card_renderer extension point#2774
nazmulhasan103 wants to merge 10 commits intosovware:developmentfrom
nazmulhasan103:feature/map-card-renderer

Conversation

@nazmulhasan103
Copy link
Copy Markdown
Member

@nazmulhasan103 nazmulhasan103 commented Mar 31, 2026

Summary

Two focused additions to eliminate the need for Directorist_Listings instantiation in integrations that only need specific listing output.

1. Helper::get_listing_card_image( int $listing_id ): string

Consolidates the thumb-card template and loop_get_the_thumbnail() into a single static call. No class instantiation, no setup_postdata, no global post state required.

Improvements over the current approach:

  • Attachment IDs fetched once, reused for both front image and blur-background layer (previously fetched twice per render)
  • Accepts $listing_id directly — no reliance on get_the_ID()
  • Private listing_thumbnail_img() handles single image, swiper carousel, and default image fallback

2. Directorist_Listings::$map_card_renderer callable property

Allows 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 ): string

Defaults to null — all existing behaviour fully preserved, zero breaking changes.

$listings->map_card_renderer = function( int $listing_id, array $opt ): string {
    ob_start();
    // render custom markup
    return ob_get_clean();
};
$listings->render_map();
$listings->map_card_renderer = null;

Test plan

  • Helper::get_listing_card_image() renders identically to the existing thumb-card template (cover / contain / full modes)
  • Blur background mode renders correctly with a single fetch of attachment IDs
  • Swiper carousel renders correctly for listings with multiple images
  • Default image renders when no images are attached
  • map_card_renderer = null (default) — no regression in map rendering
  • OpenStreet map: custom renderer output appears in marker popups
  • Google Maps: custom renderer output appears in info windows

🤖 Generated with Claude Code

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.
@nazmulhasan103 nazmulhasan103 changed the title Feature/map card renderer feat(Listings): add map_card_renderer extension point Mar 31, 2026
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)
@Armanul46 Armanul46 added this to the 8.6.7 milestone Apr 2, 2026
@Armanul46 Armanul46 removed this from the 8.6.7 milestone Apr 5, 2026
@Armanul46 Armanul46 modified the milestone: 8.6.8 Apr 8, 2026
@Armanul46
Copy link
Copy Markdown
Collaborator

Why not use a WordPress filter here instead of a callable property?

$content = apply_filters( 'directorist_map_card_content',
Helper::get_template_contents( 'archive/fields/openstreet-map', $opt ),
$listings_id,
$opt
);
A filter would be the standard WordPress approach — no need to get a reference to the Listings instance, supports multiple callbacks with priority, and works from anywhere (other plugins, themes, functions.php). The callable property limits it to a single renderer and requires direct object access, which isn't how WP plugins typically expose extension points.

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.

3 participants