get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_status = 'publish' AND post_type IN ('page','post') AND post_content LIKE %s ORDER BY post_type = 'page' DESC, ID ASC LIMIT 1", '%' . $wpdb->esc_like( '[mortgage_application_form' ) . '%' ) ); if ( $found ) { $pages[0] = $found; update_option( self::PAGES, array_map( 'intval', $pages ), false ); } return $found; } /** Swap the 2.6 shortcode for this one. */ public static function replace_shortcode() { remove_shortcode( 'mortgage_application_form' ); add_shortcode( 'mortgage_application_form', array( __CLASS__, 'render' ) ); } /** Register (not enqueue) the form assets. */ public static function register_assets() { $base = MAPP_MORTGAGE_APP_BASE_URL . 'assets/app/'; $ver = MAPP_MORTGAGE_APP_VERSION; wp_register_style( 'mapp-form', $base . 'form.css', array(), $ver ); wp_register_script( 'mapp-form', $base . 'form.js', array(), $ver, array( 'in_footer' => true, 'strategy' => 'defer' ) ); } /** * @param array|string $atts Attributes. * @return string */ public static function render( $atts = array() ) { $atts = shortcode_atts( array( 'lo' => '', 'email' => '', 'lang' => 'auto', 'purpose' => '', 'resume' => '', // 2.6 attributes, accepted and ignored. 'bar' => '', 'notification' => '', ), array_change_key_case( (array) $atts, CASE_LOWER ), 'mortgage_application_form' ); if ( ! is_ssl() && ! ( defined( 'MAPP_ALLOW_HTTP' ) && MAPP_ALLOW_HTTP ) ) { return '

' . esc_html__( 'This application needs a secure (https) page. Please contact the site owner.', '1003-mortgage-application' ) . '

'; } if ( ! wp_style_is( 'mapp-form', 'registered' ) ) { self::register_assets(); } wp_enqueue_style( 'mapp-form' ); wp_enqueue_script( 'mapp-form' ); $lo_id = LoanOfficers::find( $atts['lo'] ); $route = is_email( $atts['email'] ) ? sanitize_email( $atts['email'] ) : ''; $page = is_singular() ? (int) get_queried_object_id() : 0; self::remember_page( $page, $lo_id ); $lang = $atts['lang']; if ( ! in_array( $lang, array( 'en', 'es' ), true ) ) { $lang = 0 === strpos( determine_locale(), 'es' ) ? 'es' : 'auto'; } $purpose = array( 'purchase' => 'Home Purchase', 'refinance' => 'Home Refinance', ); $purpose = isset( $purpose[ strtolower( $atts['purpose'] ) ] ) ? $purpose[ strtolower( $atts['purpose'] ) ] : ''; $accent = ''; if ( function_exists( 'get_front_mortgage_application_option' ) && function_exists( 'mapp_sanitize_color' ) ) { $accent = mapp_sanitize_color( get_front_mortgage_application_option( 'mortgage_application_button_color', 'mortgage_application_use_network_settings' ) ); } $google = function_exists( 'get_front_mortgage_application_option' ) ? sanitize_text_field( (string) get_front_mortgage_application_option( 'mortgage_application_google_map_api_key', 'mortgage_application_use_network_settings' ) ) : ''; $terms = function_exists( 'get_front_mortgage_application_option' ) ? wp_kses_post( (string) get_front_mortgage_application_option( 'disclaimer_field_1' ) ) : ''; $boot = array( 'rest' => esc_url_raw( rest_url( 'mapp/v1/' ) ), 'config' => Config::sign( array( 'lo_id' => $lo_id, 'route_email' => $route, 'page_id' => $page, ) ), 'lang' => $lang, 'purpose' => $purpose, 'resume' => preg_match( '/^\d+\.[A-Za-z0-9_-]+$/', (string) $atts['resume'] ) ? $atts['resume'] : '', 'schema' => Schema::public_payload(), 'lo' => LoanOfficers::public_card( $lo_id ), 'company' => Copy::company(), 'terms' => $terms, 'accent' => $accent ? $accent : '#3d5ea0', 'google' => $google, 'turnstile' => Turnstile::enabled() ? (string) get_option( 'mapp_turnstile_site_key' ) : '', 'reveal' => array( 'show_payment' => 'yes' === get_option( 'mapp_reveal_payment', 'no' ), 'rate' => (float) get_option( 'mapp_reveal_rate', 0 ), 'max_ltv_cash' => (float) get_option( 'mapp_reveal_cash_ltv', 80 ), ), 'upload' => array( 'types' => \Mapp\Files\Store::allowed_types(), 'max_bytes' => \Mapp\Files\Store::max_bytes(), ), ); // Text on the brand color, and a link color that reads on white (light brand colors fall back to ink). $on_accent = \Mapp\Notifications\Layout::on( $boot['accent'] ); $accent_text = '#ffffff' === $on_accent ? $boot['accent'] : '#202124'; $n = ++self::$instance; $json = wp_json_encode( $boot, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ob_start(); ?>