<?php /** * Vancouver Dwelling — Theme Functions */ // ---- Enqueue styles & scripts ---- add_action( 'wp_enqueue_scripts', function() { wp_enqueue_style( 'vancouver-dwelling-style', get_stylesheet_uri(), [], wp_get_theme()->get( 'Version' ) ); } ); // ---- Register Custom Post Types ---- add_action( 'init', function() { // Presales register_post_type( 'vd_presale', [ 'labels' => [ 'name' => 'Presales', 'singular_name' => 'Presale', 'add_new_item' => 'Add New Presale', 'edit_item' => 'Edit Presale', 'new_item' => 'New Presale', 'view_item' => 'View Presale', 'search_items' => 'Search Presales', 'not_found' => 'No presales found', ], 'public' => true, 'has_archive' => 'presales', 'rewrite' => [ 'slug' => 'presales' ], 'supports' => [ 'title', 'editor', 'thumbnail', 'excerpt', 'custom-fields' ], 'menu_icon' => 'dashicons-building', 'show_in_rest' => true, ] ); // Insights register_post_type( 'vd_insight', [ 'labels' => [ 'name' => 'Market Insights', 'singular_name' => 'Insight', 'add_new_item' => 'Add New Insight', 'edit_item' => 'Edit Insight', 'new_item' => 'New Insight', 'view_item' => 'View Insight', 'search_items' => 'Search Insights', 'not_found' => 'No insights found', ], 'public' => true, 'has_archive' => 'insights', 'rewrite' => [ 'slug' => 'insights' ], 'supports' => [ 'title', 'editor', 'thumbnail', 'excerpt', 'custom-fields' ], 'menu_icon' => 'dashicons-analytics', 'show_in_rest' => true, ] ); // ---- Taxonomies ---- // Neighbourhood (for presales) register_taxonomy( 'vd_neighbourhood', 'vd_presale', [ 'labels' => [ 'name' => 'Neighbourhoods', 'singular_name' => 'Neighbourhood' ], 'hierarchical' => true, 'rewrite' => [ 'slug' => 'neighbourhood' ], 'show_in_rest' => true, ] ); // Developer (for presales) register_taxonomy( 'vd_developer', 'vd_presale', [ 'labels' => [ 'name' => 'Developers', 'singular_name' => 'Developer' ], 'hierarchical' => false, 'rewrite' => [ 'slug' => 'developer' ], 'show_in_rest' => true, ] ); // Insight Category register_taxonomy( 'vd_insight_category', 'vd_insight', [ 'labels' => [ 'name' => 'Insight Categories', 'singular_name' => 'Insight Category' ], 'hierarchical' => true, 'rewrite' => [ 'slug' => 'insight-category' ], 'show_in_rest' => true, ] ); } ); // ---- Theme support ---- add_action( 'after_setup_theme', function() { add_theme_support( 'post-thumbnails' ); add_theme_support( 'title-tag' ); add_theme_support( 'html5', [ 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption' ] ); add_image_size( 'vd-hero', 1600, 900, true ); add_image_size( 'vd-card', 800, 1000, true ); add_image_size( 'vd-wide', 1200, 800, true ); } ); // ---- Body open hook ---- if ( ! function_exists( 'wp_body_open' ) ) { function wp_body_open() { do_action( 'wp_body_open' ); } } // ---- Theme customizer settings ---- add_action( 'customize_register', function( $wp_customize ) { $wp_customize->add_section( 'vd_contact', [ 'title' => 'Contact Info', 'priority' => 30 ] ); $wp_customize->add_setting( 'vd_phone', [ 'default' => '+1 (604) 000-0000', 'sanitize_callback' => 'sanitize_text_field' ] ); $wp_customize->add_control( 'vd_phone', [ 'label' => 'Phone Number', 'section' => 'vd_contact' ] ); $wp_customize->add_setting( 'vd_email', [ 'default' => 'hello@vancouverdwelling.ca', 'sanitize_callback' => 'sanitize_email' ] ); $wp_customize->add_control( 'vd_email', [ 'label' => 'Email Address', 'section' => 'vd_contact' ] ); } ); // ---- Flush rewrite rules on theme activation ---- add_action( 'after_switch_theme', function() { flush_rewrite_rules(); } ); // Shims: Houzez Studio plugin requires these functions from Houzez theme if (!function_exists('houzez_is_listings_template')) { function houzez_is_listings_template() { return false; } } if (!function_exists('houzez_is_search_result')) { function houzez_is_search_result() { return false; } } if (!function_exists('houzez_is_agents_template')) { function houzez_is_agents_template() { return false; } } if (!function_exists('houzez_is_agencies_template')) { function houzez_is_agencies_template() { return false; } } // Route vd_presale archive through archive-presale.php add_filter( 'template_include', function( $template ) { if ( is_post_type_archive( 'vd_presale' ) ) { $custom = locate_template( 'archive-presale.php' ); if ( $custom ) return $custom; } return $template; } ); // Bridge: map vd_* ACF fields to Houzez property meta // so the Elementor "Building Presale" template populates from old property data add_filter( 'acf/pre_load_value', function( $value, $post_id, $field ) { if ( get_post_type( $post_id ) !== 'property' ) { return $value; } $name = isset( $field['name'] ) ? $field['name'] : ''; $map = [ 'vd_price_from' => 'fave_property_price', 'vd_price_to' => 'fave_max_price', 'vd_bedroom_mix' => 'fave_property_bedrooms', 'vd_sqft_min' => 'fave_property_size', 'vd_sqft_max' => 'fave_property_max_size', 'vd_address' => 'fave_property_address', 'vd_completion' => 'fave_property_year_built', 'vd_total_units' => 'fave_property_units', 'vd_storeys' => 'fave_property_floors', 'vd_parking' => 'fave_property_parking', ]; if ( $name === 'vd_summary' ) { $post = get_post( $post_id ); return ( $post && $post->post_content ) ? $post->post_content : $value; } if ( isset( $map[$name] ) ) { $meta = get_post_meta( $post_id, $map[$name], true ); if ( '' !== $meta && false !== $meta ) { return $meta; } } return $value; }, 10, 3 ); // Route individual presale property pages through single-presale.php add_filter( 'template_include', function( $template ) { if ( is_singular( 'property' ) && has_term( 'presale', 'property_status' ) ) { $custom = locate_template( 'single-presale.php' ); if ( $custom ) return $custom; } return $template; }, 99 ); // VD_TMP_READER_START add_action('wp_ajax_vd_tmp_read', function() { if (!current_user_can('edit_themes')) wp_die('-1'); $f = isset($_POST['f']) ? sanitize_text_field($_POST['f']) : ''; $path = get_template_directory() . '/' . ltrim($f, '/'); echo file_exists($path) ? base64_encode(file_get_contents($path)) : 'NOT_FOUND'; wp_die(); }); // VD_TMP_READER_END
·
Book a Call

No content found.

Compare