get_error_message() ); } } ); /** * A setting's default (MAPP_MORTGAGE_APP_BASE_DATA), or ''. * * @param string $option Option name. * @return string */ function mapp_default_option( $option ) { return defined( 'MAPP_MORTGAGE_APP_BASE_DATA' ) && isset( MAPP_MORTGAGE_APP_BASE_DATA[ $option ] ) ? (string) MAPP_MORTGAGE_APP_BASE_DATA[ $option ] : ''; } /** * Get a mortgage application option, processing any shortcodes before sanitizing. * Use this instead of manually calling get_front_mortgage_application_option + do_shortcode + sanitize. * * @param string $option Option name. * @param string $network_option Network option key (default empty). * @param string $sanitize Sanitization type: 'text', 'email', or 'html' (default 'text'). * @return string Sanitized option value with shortcodes processed. */ function mapp_get_option_with_shortcode( $option, $network_option = '', $sanitize = 'text' ) { $value = get_front_mortgage_application_option( $option, $network_option ); if ( ! empty( $value ) && strpos( $value, '[' ) !== false ) { $value = do_shortcode( $value ); } switch ( $sanitize ) { case 'email': return sanitize_email( $value ); case 'html': return wp_kses_post( $value ); default: return sanitize_text_field( $value ); } } /** * Sanitize a CSS color value. Accepts hex (#fff, #ffffff), rgb(), rgba(), and CSS named colors. * Also processes WordPress shortcodes in the value. * * @param string $color The color value to sanitize. * @return string Sanitized color value or empty string if invalid. */ function mapp_sanitize_color( $color ) { if ( empty( $color ) ) { return ''; } // Process shortcodes first. if ( strpos( $color, '[' ) !== false ) { $color = do_shortcode( $color ); } $color = trim( $color ); // Allow hex colors. if ( preg_match( '/^#([A-Fa-f0-9]{3}){1,2}$/', $color ) ) { return $color; } // Allow rgb() and rgba(). if ( preg_match( '/^rgba?\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*(,\s*(0|1|0?\.\d+))?\s*\)$/', $color ) ) { return $color; } // Allow CSS named colors. $named_colors = array( 'aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige', 'bisque', 'black', 'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'fuchsia', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'gray', 'green', 'greenyellow', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightslategray', 'lightsteelblue', 'lightyellow', 'lime', 'limegreen', 'linen', 'magenta', 'maroon', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 'moccasin', 'navajowhite', 'navy', 'oldlace', 'olive', 'olivedrab', 'orange', 'orangered', 'orchid', 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 'purple', 'rebeccapurple', 'red', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'silver', 'skyblue', 'slateblue', 'slategray', 'snow', 'springgreen', 'steelblue', 'tan', 'teal', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'white', 'whitesmoke', 'yellow', 'yellowgreen' ); if ( in_array( strtolower( $color ), $named_colors, true ) ) { return strtolower( $color ); } return ''; } /** * get application setting base on multisite setting. * * @perma option name (string), network setting option name (string) to check network setting is enable **/ function get_front_mortgage_application_option( $option, $network_option = 'mortgage_application_use_form_network_settings' ) { $check_network_form_enbale = get_option( $network_option ); if ( is_multisite() && isset( $check_network_form_enbale ) && $check_network_form_enbale == '0' ) { return $options = get_site_option( $option ); } else { return $options = get_option( $option ); } } /** * show application form in edit form **/ function mapp_generate_edit_token( $post_id ) { return hash_hmac( 'sha256', 'mapp_edit_' . intval( $post_id ), wp_salt( 'auth' ) ); } function mapp_verify_edit_token( $post_id, $token ) { $expected = mapp_generate_edit_token( $post_id ); return hash_equals( $expected, $token ); } /** * Generate a long-lived export token for use in email export links. * Unlike wp_nonce, this is not tied to a user session and does not expire, * so emailed export links continue to work for the recipient. */ function mapp_generate_export_token( $post_id ) { return hash_hmac( 'sha256', 'mapp_export_' . intval( $post_id ), wp_salt( 'auth' ) ); } function mapp_verify_export_token( $post_id, $token ) { if ( empty( $token ) ) { return false; } $expected = mapp_generate_export_token( $post_id ); return hash_equals( $expected, $token ); } /** * get application meta data * * @perma int post id **/ function mapp_mortgage_application_get_application_meta( $post_id ) { global $mortgage_application_form_fields; $meta_data = array(); if ( ! empty( $mortgage_application_form_fields ) && isset( $mortgage_application_form_fields ) ) { foreach ( $mortgage_application_form_fields as $form_field_key => $form_field_label ) { $field_value = esc_attr( get_post_meta( $post_id, $form_field_key, true ) ); if ( isset( $field_value ) && $field_value != '' ) { if ( isset( $form_field_key ) && ! empty( $form_field_key ) && $form_field_key == 'ss_number' ) { $field_value = mapp_decrypt_ssn( $field_value ); } $meta_data[ $form_field_key ] = $field_value; } } } return $meta_data; }