PluginProbe
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings / 7.1.1
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings v7.1.1
7.2.2 7.2.1 7.2 7.1.2 7.1.1 7.1 7.0.4 7.0.6 7.0.7 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 6.3.1 trunk 5.7.3 5.7.5 5.8.1 5.8.2 5.8.3 5.8.4 5.8.6 6.0.4 All 37 releases
mlsimport / includes / standalone / class-mlsimport-standalone-assets.php

class-mlsimport-standalone-assets.php in MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings 7.1.1, at includes/standalone/class-mlsimport-standalone-assets.php

177 lines 9.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Standalone (theme_id 990) front-end assets (M6).
4 *
5 * Registers the self-contained BEM stylesheet and the AJAX filter/paginate
6 * script, localizing the admin-ajax URL + nonce. The stylesheet can be turned
7 * off by sites that prefer to style everything themselves:
8 * add_filter( 'mlsimport_standalone_styles', '__return_false' );
9 *
10 * @package Mlsimport
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Enqueues the standalone front-end CSS/JS.
19 */
20 class Mlsimport_Standalone_Assets {
21
22 /**
23 * Register + enqueue the front-end assets.
24 *
25 * @return void
26 */
27 public static function enqueue(): void {
28 $url = defined( 'MLSIMPORT_PLUGIN_URL' ) ? MLSIMPORT_PLUGIN_URL : plugin_dir_url( dirname( __DIR__ ) . '/mlsimport.php' );
29 $ver = defined( 'MLSIMPORT_VERSION' ) ? MLSIMPORT_VERSION : '1';
30
31 if ( apply_filters( 'mlsimport_standalone_styles', true ) ) {
32 wp_enqueue_style( 'mlsimport-listings', $url . 'public/css/mlsimport-listings.css', array(), $ver );
33 wp_enqueue_style( 'mlsimport-multiselect', $url . 'public/css/mlsimport-multiselect.css', array(), $ver );
34 wp_enqueue_style( 'mlsimport-search-popups', $url . 'public/css/mlsimport-search-popups.css', array(), $ver );
35 // Re-theme the listing-grid accent (--mli-accent) from the "Main Color"
36 // design setting; printed after the stylesheet so it wins the cascade.
37 // listings.css loads on every front-end page, so this also seeds the
38 // override globally for any widget/block that inherits the accent tokens.
39 if ( function_exists( 'mlsimport_standalone_attach_brand_color' ) ) {
40 mlsimport_standalone_attach_brand_color( 'mlsimport-listings' );
41 }
42 }
43
44 // Dropdown multi-select for the search-form taxonomy fields.
45 wp_enqueue_script( 'mlsimport-multiselect', $url . 'public/js/mlsimport-multiselect.js', array(), $ver, true );
46 // Range sliders (price, area, lot, year) + beds/baths tile popups for the search-form column fields.
47 wp_enqueue_script( 'mlsimport-search-popups', $url . 'public/js/mlsimport-search-popups.js', array(), $ver, true );
48 // City / area / county / ZIP suggestions for the search form's Location field.
49 wp_enqueue_script( 'mlsimport-location-autocomplete', $url . 'public/js/mlsimport-location-autocomplete.js', array(), $ver, true );
50 wp_localize_script(
51 'mlsimport-location-autocomplete',
52 'MLSImportLocations',
53 array(
54 'ajaxurl' => admin_url( 'admin-ajax.php' ),
55 'action' => Mlsimport_Standalone_Ajax::LOCATIONS_ACTION,
56 'nonce' => wp_create_nonce( Mlsimport_Standalone_Ajax::LOCATIONS_ACTION ),
57 )
58 );
59 // The Sort control is a .mlsimport-interest wrapper (see the results toolbar in
60 // class-mlsimport-standalone-render.php), so it needs the same enhancer the
61 // property lead form uses. The script is self-contained and enhances any
62 // .mlsimport-interest on the page; the panel markup it builds reuses
63 // .mlsimport-location__list, which mlsimport-listings.css already provides here.
64 wp_enqueue_script( 'mlsimport-property-interest', $url . 'public/js/mlsimport-property-interest.js', array(), $ver, true );
65 wp_enqueue_script( 'mlsimport-listings', $url . 'public/js/mlsimport-listings.js', array(), $ver, true );
66 wp_localize_script(
67 'mlsimport-listings',
68 'MLSImportListings',
69 array(
70 'ajaxurl' => admin_url( 'admin-ajax.php' ),
71 'action' => Mlsimport_Standalone_Ajax::ACTION,
72 'nonce' => wp_create_nonce( Mlsimport_Standalone_Ajax::ACTION ),
73 )
74 );
75
76 // Favorites: the card hearts, the single-page Save button and the "My saved
77 // properties" view. Loaded on every front-end page (like the listings assets)
78 // so a saved heart hydrates wherever a card or the single page appears. The
79 // bootstrap carries the logged-in user's saved list for one-pass hydration.
80 if ( apply_filters( 'mlsimport_standalone_styles', true ) ) {
81 wp_enqueue_style( 'mlsimport-favorites', $url . 'public/css/mlsimport-favorites.css', array( 'mlsimport-listings' ), $ver );
82 }
83 wp_enqueue_script( 'mlsimport-favorites', $url . 'public/js/mlsimport-favorites.js', array(), $ver, true );
84 if ( class_exists( 'Mlsimport_Favorites' ) ) {
85 wp_localize_script( 'mlsimport-favorites', 'MLSImportFav', Mlsimport_Favorites::bootstrap() );
86 }
87
88 // Elementor's editor renders canvas widgets over AJAX and injects the HTML into
89 // the preview iframe, so a widget's own render-time enqueue never reaches the
90 // iframe document (the same quirk enqueue_editor() works around for Gutenberg).
91 // Load the section stylesheet up front in preview mode instead — otherwise the
92 // Featured Property card and the property sections preview unstyled.
93 if ( class_exists( '\Elementor\Plugin' ) && isset( \Elementor\Plugin::$instance->preview )
94 && \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
95 Mlsimport_Property_Section_Assets::enqueue();
96 // The Half Map widget's split layout AND its floating map controls (the
97 // mobile List/Map switch, the Draw/Clear tools) are styled by this sheet.
98 // Without it the preview shows those as unstyled theme buttons and the
99 // desktop-only "hide the mobile switch" rule never runs — four stray buttons.
100 // Style only (Leaflet/JS don't run in the editor); the handle is registered
101 // by the enqueue() call above via ensure_registered().
102 wp_enqueue_style( 'mlsimport-half-map' );
103 }
104 }
105
106 /**
107 * Load the front-end stylesheets into the block editor so the dynamic blocks'
108 * ServerSideRender previews (listings, page blocks, single-property sections)
109 * match the front end. The blocks render identical HTML in both contexts but
110 * the editor never loads the front-end CSS, so the preview shows raw markup.
111 *
112 * Hooked on enqueue_block_assets (not enqueue_block_editor_assets) because that
113 * is the hook WordPress injects into the editor's iframe; guarded to the editor
114 * so the front end — which already enqueues these on render — isn't double-loaded.
115 *
116 * @return void
117 */
118 public static function enqueue_editor(): void {
119 if ( ! is_admin() || ! function_exists( 'wp_enqueue_style' ) ) {
120 return;
121 }
122
123 $url = defined( 'MLSIMPORT_PLUGIN_URL' ) ? MLSIMPORT_PLUGIN_URL : plugin_dir_url( dirname( __DIR__ ) . '/mlsimport.php' );
124 $ver = defined( 'MLSIMPORT_VERSION' ) ? MLSIMPORT_VERSION : '1';
125
126 // Card grid, search form, toolbar, pager — listings + page blocks.
127 if ( apply_filters( 'mlsimport_standalone_styles', true ) ) {
128 wp_enqueue_style( 'mlsimport-listings', $url . 'public/css/mlsimport-listings.css', array(), $ver );
129 wp_enqueue_style( 'mlsimport-multiselect', $url . 'public/css/mlsimport-multiselect.css', array(), $ver );
130 wp_enqueue_style( 'mlsimport-search-popups', $url . 'public/css/mlsimport-search-popups.css', array(), $ver );
131 // Card hearts appear in the SSR card previews — style them in the editor too.
132 wp_enqueue_style( 'mlsimport-favorites', $url . 'public/css/mlsimport-favorites.css', array( 'mlsimport-listings' ), $ver );
133 if ( function_exists( 'mlsimport_standalone_attach_brand_color' ) ) {
134 mlsimport_standalone_attach_brand_color( 'mlsimport-listings' );
135 }
136 }
137
138 // The search-form block's multi-selects render as dropdowns in the preview too.
139 wp_enqueue_script( 'mlsimport-multiselect', $url . 'public/js/mlsimport-multiselect.js', array(), $ver, true );
140 // And its range sliders + beds/baths tile popups enhance in the preview too.
141 wp_enqueue_script( 'mlsimport-search-popups', $url . 'public/js/mlsimport-search-popups.js', array(), $ver, true );
142
143 // Single-property section shell + agent profile + vendored gallery/map/slider
144 // CSS, so every section and page block previews styled.
145 Mlsimport_Property_Section_Assets::ensure_registered();
146 foreach ( array( Mlsimport_Property_Section_Assets::BASE_STYLE, 'mlsimport-agent', 'mlsimport-splide', 'mlsimport-glightbox', 'mlsimport-leaflet' ) as $handle ) {
147 wp_enqueue_style( $handle );
148 }
149
150 // The section/page-block shell stylesheet (BASE_STYLE) also by EXPLICIT URL
151 // under an editor-only handle: handle-only enqueues of pre-registered styles
152 // do NOT reach the block-editor iframe (same quirk as the scripts below), so
153 // the handle enqueue above styles only the outer document. Without this the
154 // Featured Property / section SSR previews render unstyled in the editor.
155 wp_enqueue_style( 'mlsimport-property-sections-editor', $url . 'public/css/mlsimport-property-sections.css', array(), $ver );
156 // Re-theme the section tokens (--mlsimport-accent) in the editor iframe too,
157 // on the URL-based handle that actually reaches it.
158 if ( function_exists( 'mlsimport_standalone_attach_brand_color' ) ) {
159 mlsimport_standalone_attach_brand_color( 'mlsimport-property-sections-editor' );
160 }
161
162 // Half Map block: the split list/map layout, by explicit URL so it reaches
163 // the editor iframe (the SSR preview shows the panes side by side; Leaflet
164 // itself doesn't run in the editor, so the map pane previews empty).
165 wp_enqueue_style( 'mlsimport-half-map-editor', $url . 'public/css/mlsimport-half-map.css', array(), $ver );
166
167 // Content Slider block: load Splide + the slider init by EXPLICIT URL (under
168 // editor-only handles) so they reach the block-editor iframe. Handle-only
169 // enqueues of pre-registered scripts do NOT reach the iframe here; the
170 // multiselect script above proves the URL form does. The slider script
171 // observes the DOM and mounts Splide on the async-injected SSR preview.
172 wp_enqueue_style( 'mlsimport-splide-editor', $url . 'public/vendor/splide/splide.min.css', array(), $ver );
173 wp_enqueue_script( 'mlsimport-splide-editor', $url . 'public/vendor/splide/splide.min.js', array(), $ver, true );
174 wp_enqueue_script( 'mlsimport-content-slider-editor', $url . 'public/js/mlsimport-property-slider.js', array( 'mlsimport-splide-editor' ), $ver, true );
175 }
176 }
177