Filters & Hooks: Examples
WP-ImmoMakler provides numerous WordPress filter hooks and action hooks that allow you to customize outputs and importer behavior from your own code. All code examples belong in the file /wp-content/plugins/immomakler-child/functions.php of your WP-ImmoMakler Child-Skin-Plugin.
Redirect after successful contact request
Section titled “Redirect after successful contact request”Redirect to a custom confirmation page after the contact form is submitted:
add_filter('immomakler_contactform_mailsent', 'immomakler_mailsent', 10, 3);function immomakler_mailsent($text, $requested_items, $values) { $objektid = $requested_items[0]; return $text . '<script>location.href="/anfrage-gesendet/?id=' . get_post_meta($objektid, 'objektnr_extern', true) . '";</script>';}Trigger analytics events on form submission
Section titled “Trigger analytics events on form submission”For the standard case, WP-ImmoMakler → Settings → Contact Form provides the Analytics event on form submission option — no custom code is required for that, see Configuring the contact form. The following examples are useful if you need additional, custom event parameters.
Google Analytics (gtag.js)
Section titled “Google Analytics (gtag.js)”add_filter('immomakler_contactform_mailsent', 'immomakler_contactform_mailsent_analytics_event', 10, 2);function immomakler_contactform_mailsent_analytics_event($response, $requested_items) { return $response . '<script>if (typeof gtag === "function") { gtag("event", "direktanfrage_versendet", { objekt_id: "' . esc_js(get_post_meta($requested_items[0], 'objektnr_extern', true)) . '" }); }</script>';}Google Tag Manager
Section titled “Google Tag Manager”add_filter('immomakler_contactform_mailsent', 'immomakler_contactform_mailsent_gtm_event', 10, 2);function immomakler_contactform_mailsent_gtm_event($response, $requested_items) { return $response . '<script>window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: "form_submit_wp_immomakler", objekt_id: "' . esc_js(get_post_meta($requested_items[0], 'objektnr_extern', true)) . '" });</script>';}Make custom fields searchable
Section titled “Make custom fields searchable”To include custom meta fields in WP_Query search queries:
add_filter('immomakler_searchable_postmeta_keys', 'custom_immomakler_searchable_postmeta_keys');function custom_immomakler_searchable_postmeta_keys($immomakler_metakeys) { $immomakler_metakeys[] = 'verwaltung_objekt-user_defined_simplefield-objekt_des_tages'; return $immomakler_metakeys;}Define extended search fields
Section titled “Define extended search fields”Configure slider-based search fields for area, number of rooms, and price:
add_filter('immomakler_search_enabled_ranges', 'my_immomakler_search_ranges');function my_immomakler_search_ranges($ranges) { return array( 'immomakler_search_size' => array( 'label' => 'Fläche', 'slug' => 'qm', 'unit' => 'm²', 'decimals' => 0, 'meta_key' => 'flaeche', 'slider_step' => 5, ), 'immomakler_search_rooms' => array( 'label' => 'Anzahl Zimmer', 'slug' => 'zimmer', 'unit' => '', 'decimals' => 1, 'meta_key' => 'anzahl_zimmer', 'slider_step' => 0.5, ), 'immomakler_search_price_rent' => array( 'label' => 'Kaltmiete', 'slug' => 'kaltmiete', 'unit' => '€', 'decimals' => 0, 'meta_key' => 'kaltmiete', 'slider_step' => 100, ), 'immomakler_search_price_buy' => array( 'label' => 'Kaufpreis', 'slug' => 'kaufpreis', 'unit' => '€', 'decimals' => 0, 'meta_key' => 'kaufpreis', 'slider_step' => 25000, ), );}Customize image sizes
Section titled “Customize image sizes”add_filter('immomakler_image_sizes', 'custom_immomakler_image_sizes');function custom_immomakler_image_sizes($images_sizes) { $images_sizes['immomakler-archive-thumb'] = [ 'width' => 350, 'height' => 250, 'crop' => false, ]; $images_sizes['immomakler-archive-thumb-big'] = [ 'width' => 475, 'height' => 300, 'crop' => true, ]; $images_sizes['immomakler-archive-big'] = [ 'width' => 900, 'height' => 600, 'crop' => ['center', 'top'], ]; return $images_sizes;}For the height, specify at least 1.5 times the width wherever possible (without cropping). If the height is smaller than the width, the height limits the image for landscape-format photos and it is generated narrower than specified — in the display it is then upscaled and appears blurry. For more details, see Property image processing.
Update modification date on property updates
Section titled “Update modification date on property updates”By default, the original publication date is preserved. To update the modification date on every import update:
add_filter('immomakler_preserve_post_date_on_update', '__return_false');Create foreign country entries in taxonomies
Section titled “Create foreign country entries in taxonomies”add_filter('immomakler_mark_foreign_countries', '__return_true');Create custom property types
Section titled “Create custom property types”add_filter('immomakler_object_terms_types', 'custom_immomakler_object_terms_types', 10, 2);function custom_immomakler_object_terms_types($object_types, $openimmo_data) { if ($openimmo_data['gewerbe']) { $object_types[] = 'Gewerbe'; } if ($openimmo_data['verwaltung_objekt-user_defined_simplefield-xyz'] == 'PREMIUM') { $object_types[] = 'Premiumimmobilie'; } return $object_types;}Create custom usage types
Section titled “Create custom usage types”add_filter('immomakler_object_terms_nutzungsart', 'custom_immomakler_object_terms_nutzungsart', 10, 2);function custom_immomakler_object_terms_nutzungsart($object_nutzungsart, $openimmo_data) { if ($openimmo_data['verwaltung_objekt-user_defined_simplefield-xyz'] == 'PRIVAT') { $object_nutzungsart[] = 'Privat'; } if ($openimmo_data['verwaltung_objekt-user_defined_simplefield-xyz'] == 'INSTITUTIONELL') { $object_nutzungsart[] = 'Institutionell'; } return $object_nutzungsart;}Register and populate a custom taxonomy
Section titled “Register and populate a custom taxonomy”Example: create a postal code taxonomy and populate it automatically during import:
add_action('init', 'custom_immomakler_register_taxonomies');function custom_immomakler_register_taxonomies() { register_taxonomy('immomakler_search_plz', 'immomakler_object', array( 'labels' => array( 'name' => _x('Postleitzahlen', 'taxonomy general name'), 'singular_name' => _x('Postleitzahl', 'taxonomy singular name'), 'all_items' => _x('Alle Postleitzahlen', 'taxonomy choose all'), ), 'rewrite' => array( 'slug' => 'immobilien-plz', 'hierarchical' => false, 'with_front' => false, ), 'hierarchical' => false, 'query_var' => 'plz', 'public' => true, 'show_ui' => true, ));}
add_action('immomakler_after_post_create', 'custom_immomakler_index', 10, 2);function custom_immomakler_index($post_id, $openimmo_data) { if (!empty($openimmo_data['plz'])) { wp_set_object_terms($post_id, $openimmo_data['plz'], 'immomakler_search_plz'); }}Check the search criteria of a property alert
Section titled “Check the search criteria of a property alert”With the filter immomakler_searchagents_validate_criteria you define your own rules for which search criteria a property alert may have. WP-ImmoMakler applies the filter before a property alert is created or changed and before an email is sent. If you return a WP_Error, WP-ImmoMakler rejects the property alert and shows the prospect the error’s message. If you return null, the property alert is accepted.
The filter receives three parameters:
| Parameter | Content |
|---|---|
$error | The result of the built-in check: a WP_Error if a minimum value is greater than the corresponding maximum value, otherwise null |
$criteria | The search criteria as an array, for example [ 'vermarktungsart' => 'kauf', 'von-zimmer' => '3' ]. Ranges are stored under the keys von-… and bis-… |
$request | The remaining data from the form, such as email. For a change made from the results list, the array is empty |
The following example rejects property alerts with a minimum of more than 20 rooms. The built-in check is preserved, because the filter returns an existing $error unchanged:
add_filter( 'immomakler_searchagents_validate_criteria', 'meine_suchauftrag_pruefung', 10, 3 );function meine_suchauftrag_pruefung( $error, $criteria, $request ) { if ( null === $error && isset( $criteria['von-zimmer'] ) && (float) $criteria['von-zimmer'] > 20 ) { return new WP_Error( 'zu_viele_zimmer', 'Please check the number of rooms.' ); } return $error;}If your filter always returns null, you also switch off the built-in check for contradictory ranges.
Complete hooks reference
Section titled “Complete hooks reference”A complete, categorized overview of all available filter and action hooks can be found at Filter & Action Hooks.
You might also be interested in
Section titled “You might also be interested in”- Filter & Action Hooks — complete reference of all hooks, grouped by category
- Making customizations update-safe — Child Skin Plugin as the safe place for custom code
- Customizing templates — overriding skin files for in-depth layout changes
- Contact form hooks — hooks for enquiries and email dispatch