Lowercase theme directory slug => theme id. */ function mlsimport_theme_directory_map() { return array( 'wpresidence' => 991, 'houzez' => 992, 'realhomes' => 993, 'wpestate' => 994, ); } /** * Resolve the supported theme id this site should run as. * * Step by step: * 1. If the user has already saved a theme in the plugin options, that choice * wins outright. An explicit configuration decision is never second-guessed * by detection - the saved value is what every other code path (the write * adapter, standalone mode) already acts on. * 2. Otherwise look at the active parent theme's directory slug and match it * against the four real-estate themes. * 3. No match means standalone (990). This is the normal, healthy outcome for * the majority of sites - not a failure. * * @return int One of 990, 991, 992, 993, 994. Never anything else. */ function mlsimport_resolve_theme_id() { // Step 1: an explicit saved choice is authoritative. Only values the plugin // can actually write with are honoured; a stale or corrupt id falls through // to detection rather than routing listings to a non-existent adapter. $options = get_option( 'mlsimport_admin_options' ); $saved = ( is_array( $options ) && isset( $options['mlsimport_theme_used'] ) ) ? intval( $options['mlsimport_theme_used'] ) : 0; $supported = array( 990, 991, 992, 993, 994 ); if ( in_array( $saved, $supported, true ) ) { return $saved; } // Step 2: no saved choice - detect from the active parent theme directory. $slug = strtolower( (string) get_template() ); $map = mlsimport_theme_directory_map(); if ( isset( $map[ $slug ] ) ) { return $map[ $slug ]; } // Step 3: anything else is a standalone site. return 990; } /** * The theme's name as the wizard drops it into a sentence. * * Three later steps ("connect your %s website", "imported properties from your * MLS into %s") each carried their own copy of a theme matcher just to fill in * this word. They share this one instead. * * Standalone deliberately does not read as its selector label, "Standalone * (any theme)" - that label belongs in a dropdown, not in a sentence. A * standalone site is a WordPress site, and every one of those sentences reads * correctly with that word. * * @return string Theme name for 991-994, or 'WordPress' for standalone. */ function mlsimport_theme_copy_label() { $theme_id = mlsimport_resolve_theme_id(); // Standalone has no host theme to name. if ( 990 === $theme_id ) { return __( 'WordPress', 'mlsimport' ); } return MLSIMPORT_THEME[ $theme_id ]; } /** * Build the theme HTML. */ function mlsiport_mls_select_list( $key, $value, $data_array ) { // Step 1 - open the select, binding it to the mlsimport_admin_options field. $select = ''; return $select; }