← All changes
|
includes/admin/class-ph-admin-matching-properties.php
+133
-73
2.2.5
→
2.3.1
View file →
| @@ -1,5 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | +// phpcs:set WordPress.Security.ValidatedSanitizedInput customSanitizingFunctions[] ph_clean | |
| 3 | +// ph_clean() recursively sanitizes text; presence, shape and unslashing checks remain separate. | |
| 4 | + | |
| 2 | 5 | /** |
| 3 | 6 | * PropertyHive Admin Matching Properties Class. |
| 4 | 7 | * |
| 5 | 8 | * @author PropertyHive |
| @@ -14,35 +17,47 @@ | ||
| 14 | 17 | |
| 15 | 18 | /** |
| 16 | 19 | * PH_Admin_Matching_Properties |
| 17 | 20 | */ |
| 21 | +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Legacy public global class PH_Admin_Matching_Properties; preserving the existing PH_* class name is required for plugin and extension compatibility. | |
| 18 | 22 | class PH_Admin_Matching_Properties { |
| 19 | 23 | |
| 20 | 24 | public function output() |
| 21 | 25 | { |
| 22 | - if ( !isset($_GET['contact_id']) || (isset($_GET['contact_id']) && get_post_type((int)$_GET['contact_id']) != 'contact') ) | |
| 23 | - { | |
| 24 | - die('Invalid contact_id passed'); | |
| 25 | - } | |
| 26 | - if ( !isset($_GET['applicant_profile']) ) | |
| 27 | - { | |
| 28 | - die('Invalid applicant_profile passed'); | |
| 29 | - } | |
| 26 | + // The initial matching screen is read-only. The POST branch below verifies the | |
| 27 | + // matching nonce before it performs any state-changing action. | |
| 28 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This request is used to render the read-only matching screen; POST mutations verify the matching nonce below. | |
| 29 | + $request_get = wp_unslash( $_GET ); | |
| 30 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Only the presence of the action selector is checked here; request values are normalized after the nonce check below. | |
| 31 | + $has_step = isset( $_POST['step'] ); | |
| 30 | 32 | |
| 31 | - $contact_id = (int)$_GET['contact_id']; | |
| 33 | + $contact_id = ( isset( $request_get['contact_id'] ) && is_scalar( $request_get['contact_id'] ) ) ? absint( $request_get['contact_id'] ) : 0; | |
| 34 | + $applicant_profile_id = ( isset( $request_get['applicant_profile'] ) && is_scalar( $request_get['applicant_profile'] ) ) ? absint( $request_get['applicant_profile'] ) : 0; | |
| 32 | 35 | |
| 33 | - $email_address = get_post_meta( $contact_id, '_email_address', TRUE ); | |
| 36 | + if ( ! $contact_id || get_post_type( $contact_id ) !== 'contact' ) | |
| 37 | + { | |
| 38 | + die('Invalid contact_id passed'); | |
| 39 | + } | |
| 40 | + if ( ! isset( $request_get['applicant_profile'] ) || ! is_scalar( $request_get['applicant_profile'] ) ) | |
| 41 | + { | |
| 42 | + die('Invalid applicant_profile passed'); | |
| 43 | + } | |
| 34 | 44 | |
| 35 | - $applicant_profile_id = (int)$_GET['applicant_profile']; | |
| 45 | + $email_address = get_post_meta( $contact_id, '_email_address', TRUE ); | |
| 36 | 46 | |
| 37 | 47 | $applicant_profile = get_post_meta( $contact_id, '_applicant_profile_' . $applicant_profile_id, TRUE ); |
| 38 | 48 | |
| 39 | - if ( isset($_POST['step']) ) | |
| 49 | + if ( $has_step ) | |
| 40 | 50 | { |
| 41 | - if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'propertyhive-matching-properties' ) ) | |
| 51 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Only the nonce value is read before verification; all other POST values are normalized after the check below. | |
| 52 | + $request_request = wp_unslash( $_REQUEST ); | |
| 53 | + if ( empty( $request_request['_wpnonce'] ) || ! wp_verify_nonce( ( isset( $request_request['_wpnonce'] ) && is_string( $request_request['_wpnonce'] ) ) ? sanitize_text_field( $request_request['_wpnonce'] ) : '', 'propertyhive-matching-properties' ) ) | |
| 42 | 54 | die( esc_html(__( 'Action failed. Please refresh the page and retry.', 'propertyhive' )) ); |
| 43 | 55 | |
| 44 | - switch ( $_POST['step'] ) | |
| 56 | + $request_post = wp_unslash( $_POST ); | |
| 57 | + $step = is_string( $request_post['step'] ) ? sanitize_key( $request_post['step'] ) : ''; | |
| 58 | + | |
| 59 | + switch ( $step ) | |
| 45 | 60 | { |
| 46 | 61 | case "one": |
| 47 | 62 | { |
| 48 | 63 | // Properties have been selected to email or dismiss |
| @@ -47,14 +62,14 @@ | ||
| 47 | 62 | { |
| 48 | 63 | // Properties have been selected to email or dismiss |
| 49 | 64 | |
| 50 | 65 | // Handle dismissed properties |
| 51 | - $this->dismiss_properties(); | |
| 66 | + $this->dismiss_properties(); | |
| 52 | 67 | |
| 53 | - $nothing_to_send = true; | |
| 68 | + $nothing_to_send = true; | |
| 54 | 69 | |
| 55 | - // Handle properties to email | |
| 56 | - if ( isset($_POST['email_property_id']) && !empty($_POST['email_property_id']) ) | |
| 70 | + // Handle properties to email | |
| 71 | + if ( isset( $request_post['email_property_id'] ) && ! empty( $request_post['email_property_id'] ) ) | |
| 57 | 72 | { |
| 58 | 73 | $nothing_to_send = false; |
| 59 | 74 | |
| 60 | 75 | $subject = get_option( 'propertyhive_property_match_default_email_subject', '' ); |
| @@ -82,9 +97,9 @@ | ||
| 82 | 97 | <div id="poststuff"> |
| 83 | 98 | |
| 84 | 99 | <form method="post" id="mainform" action="" enctype="multipart/form-data"> |
| 85 | 100 | <?php |
| 86 | - if ( isset($_POST['email_property_id']) && !empty($_POST['email_property_id']) ) | |
| 101 | + if ( isset( $request_post['email_property_id'] ) && ! empty( $request_post['email_property_id'] ) ) | |
| 87 | 102 | { |
| 88 | 103 | // We've got emails to send |
| 89 | 104 | include 'views/html-admin-matching-properties-email.php'; |
| 90 | 105 | } |
| @@ -93,14 +108,24 @@ | ||
| 93 | 108 | ?> |
| 94 | 109 | <p class="submit"> |
| 95 | 110 | |
| 96 | 111 | <input name="save" class="button-primary" type="submit" value="<?php echo esc_attr(__( 'Send Matches', 'propertyhive' )); ?>" /> |
| 97 | - <?php if ( isset($_POST['email_property_id']) && !empty($_POST['email_property_id']) ) { ?> | |
| 112 | + <?php if ( isset( $request_post['email_property_id'] ) && ! empty( $request_post['email_property_id'] ) ) { ?> | |
| 98 | 113 | <input name="preview" id="preview_email" class="button" type="button" value="<?php echo esc_attr(__( 'Preview Email', 'propertyhive' )); ?>" /> |
| 99 | 114 | <?php } ?> |
| 100 | 115 | |
| 101 | 116 | <input type="hidden" name="step" value="two" /> |
| 102 | - <input type="hidden" name="email_property_id" value="<?php echo ( isset($_POST['email_property_id']) && is_array($_POST['email_property_id']) && !empty($_POST['email_property_id']) ) ? esc_attr(implode(",", ph_clean($_POST['email_property_id']))) : ''; ?>" /> | |
| 117 | + <input type="hidden" name="email_property_id" value="<?php | |
| 118 | + $selected_property_ids = array(); | |
| 119 | + if ( isset( $request_post['email_property_id'] ) && is_array( $request_post['email_property_id'] ) ) { | |
| 120 | + foreach ( $request_post['email_property_id'] as $selected_property_id ) { | |
| 121 | + if ( is_scalar( $selected_property_id ) ) { | |
| 122 | + $selected_property_ids[] = absint( $selected_property_id ); | |
| 123 | + } | |
| 124 | + } | |
| 125 | + } | |
| 126 | + echo esc_attr( implode( ',', $selected_property_ids ) ); | |
| 127 | + ?>" /> | |
| 103 | 128 | <?php do_action( 'propertyhive_property_match_step_two_hidden_fields' ); ?> |
| 104 | 129 | <?php wp_nonce_field( 'propertyhive-matching-properties' ); ?> |
| 105 | 130 | |
| 106 | 131 | </p> |
| @@ -105,9 +130,9 @@ | ||
| 105 | 130 | |
| 106 | 131 | </p> |
| 107 | 132 | |
| 108 | 133 | <p> |
| 109 | - <?php echo __( 'When sending out lots of emails we recommend using <a href="https://en-gb.wordpress.org/plugins/tags/smtp" target="_blank">a plugin</a> to send them out using SMTP. Your web developer or hosting company should be able to advise on this.', 'propertyhive' ); | |
| 134 | + <?php echo wp_kses_post( __( 'When sending out lots of emails we recommend using <a href="https://en-gb.wordpress.org/plugins/tags/smtp" target="_blank">a plugin</a> to send them out using SMTP. Your web developer or hosting company should be able to advise on this.', 'propertyhive' ) ); | |
| 110 | 135 | ?> |
| 111 | 136 | </p> |
| 112 | 137 | |
| 113 | 138 | </form> |
| @@ -130,9 +155,9 @@ | ||
| 130 | 155 | |
| 131 | 156 | function showPreview() |
| 132 | 157 | { |
| 133 | 158 | jQuery('#mainform').attr('target', '_blank'); |
| 134 | - jQuery('#mainform').attr('action', '<?php echo admin_url( '?preview_propertyhive_email=true&contact_id=' . (int)$_GET['contact_id'] . '&applicant_profile=' . (int)$_GET['applicant_profile'] ); ?>'); | |
| 159 | + jQuery('#mainform').attr('action', <?php echo wp_json_encode( admin_url( '?preview_propertyhive_email=true&contact_id=' . $contact_id . '&applicant_profile=' . $applicant_profile_id ), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ); ?>); | |
| 135 | 160 | |
| 136 | 161 | jQuery('#mainform').submit(); |
| 137 | 162 | jQuery('#mainform').attr('target', '_self'); |
| 138 | 163 | jQuery('#mainform').attr('action', ''); |
| @@ -142,10 +167,10 @@ | ||
| 142 | 167 | <?php |
| 143 | 168 | } |
| 144 | 169 | |
| 145 | 170 | if ( $nothing_to_send == true ) |
| 146 | - { | |
| 147 | - echo '<script>window.location.href = "' . get_edit_post_link( $contact_id, 'url' ) . '&ph_message=2";</script>'; | |
| 171 | + { | |
| 172 | + echo '<script>window.location.href = ' . wp_json_encode( get_edit_post_link( $contact_id, 'url' ) . '&ph_message=2', JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ) . ';</script>'; | |
| 148 | 173 | |
| 149 | 174 | //header("Location: " . get_edit_post_link( $contact_id, 'url' ) . '&ph_message=2' ); // properties marked as not interested |
| 150 | 175 | //die(); |
| 151 | 176 | } |
| @@ -153,11 +178,12 @@ | ||
| 153 | 178 | break; |
| 154 | 179 | } |
| 155 | 180 | case "two": |
| 156 | 181 | { |
| 157 | - if ( isset($_POST['email_property_id']) && !empty($_POST['email_property_id']) ) | |
| 158 | - { | |
| 159 | - $to_email_addresses = explode(",", $_POST['to_email_address']); | |
| 182 | + if ( isset( $request_post['email_property_id'] ) && ! empty( $request_post['email_property_id'] ) ) | |
| 183 | + { | |
| 184 | + $to_email_address_input = ( isset( $request_post['to_email_address'] ) && is_string( $request_post['to_email_address'] ) ) ? $request_post['to_email_address'] : ''; | |
| 185 | + $to_email_addresses = explode( ',', $to_email_address_input ); | |
| 160 | 186 | $new_to_email_addresses = array(); |
| 161 | 187 | foreach ( $to_email_addresses as $to_email_address ) |
| 162 | 188 | { |
| 163 | 189 | $new_to_email_addresses[] = sanitize_email($to_email_address); |
| @@ -162,9 +188,10 @@ | ||
| 162 | 188 | { |
| 163 | 189 | $new_to_email_addresses[] = sanitize_email($to_email_address); |
| 164 | 190 | } |
| 165 | 191 | |
| 166 | - $cc_email_addresses = explode(",", $_POST['cc_email_address']); | |
| 192 | + $cc_email_address_input = ( isset( $request_post['cc_email_address'] ) && is_string( $request_post['cc_email_address'] ) ) ? $request_post['cc_email_address'] : ''; | |
| 193 | + $cc_email_addresses = explode( ',', $cc_email_address_input ); | |
| 167 | 194 | $new_cc_email_addresses = array(); |
| 168 | 195 | foreach ( $cc_email_addresses as $cc_email_address ) |
| 169 | 196 | { |
| 170 | 197 | $new_cc_email_addresses[] = sanitize_email($cc_email_address); |
| @@ -169,9 +196,10 @@ | ||
| 169 | 196 | { |
| 170 | 197 | $new_cc_email_addresses[] = sanitize_email($cc_email_address); |
| 171 | 198 | } |
| 172 | 199 | |
| 173 | - $bcc_email_addresses = explode(",", $_POST['bcc_email_address']); | |
| 200 | + $bcc_email_address_input = ( isset( $request_post['bcc_email_address'] ) && is_string( $request_post['bcc_email_address'] ) ) ? $request_post['bcc_email_address'] : ''; | |
| 201 | + $bcc_email_addresses = explode( ',', $bcc_email_address_input ); | |
| 174 | 202 | $new_bcc_email_addresses = array(); |
| 175 | 203 | foreach ( $bcc_email_addresses as $bcc_email_address ) |
| 176 | 204 | { |
| 177 | 205 | $new_bcc_email_addresses[] = sanitize_email($bcc_email_address); |
| @@ -196,18 +224,23 @@ | ||
| 196 | 224 | ), |
| 197 | 225 | ); |
| 198 | 226 | $allowed_tags = apply_filters( 'propertyhive_match_email_allowed_tags', $allowed_tags ); |
| 199 | 227 | |
| 200 | - $body = wp_kses(wp_unslash($_POST['body']), $allowedposttags); | |
| 228 | + $body_input = ( isset( $request_post['body'] ) && is_string( $request_post['body'] ) ) ? $request_post['body'] : ''; | |
| 229 | + $body = wp_kses( $body_input, $allowed_tags ); | |
| 230 | + $email_property_id_input = ( isset( $request_post['email_property_id'] ) && is_scalar( $request_post['email_property_id'] ) ) ? $request_post['email_property_id'] : ''; | |
| 231 | + $from_name_input = ( isset( $request_post['from_name'] ) && is_string( $request_post['from_name'] ) ) ? $request_post['from_name'] : ''; | |
| 232 | + $from_email_address_input = ( isset( $request_post['from_email_address'] ) && is_string( $request_post['from_email_address'] ) ) ? $request_post['from_email_address'] : ''; | |
| 233 | + $subject_input = ( isset( $request_post['subject'] ) && is_string( $request_post['subject'] ) ) ? $request_post['subject'] : ''; | |
| 201 | 234 | |
| 202 | 235 | // Email info entered. Time to send emails |
| 203 | 236 | $this->send_emails( |
| 204 | - (int)$_GET['contact_id'], | |
| 205 | - (int)$_GET['applicant_profile'], | |
| 206 | - explode(",", ph_clean($_POST['email_property_id'])), | |
| 207 | - ph_clean(wp_unslash($_POST['from_name'])), | |
| 208 | - sanitize_email(wp_unslash($_POST['from_email_address'])), | |
| 209 | - ph_clean(wp_unslash($_POST['subject'])), | |
| 237 | + $contact_id, | |
| 238 | + $applicant_profile_id, | |
| 239 | + array_values( array_filter( array_map( 'absint', explode( ',', sanitize_text_field( $email_property_id_input ) ) ) ) ), | |
| 240 | + ph_clean( $from_name_input ), | |
| 241 | + sanitize_email( $from_email_address_input ), | |
| 242 | + ph_clean( $subject_input ), | |
| 210 | 243 | $body, |
| 211 | 244 | implode(",", $new_to_email_addresses), |
| 212 | 245 | implode(",", $new_cc_email_addresses), |
| 213 | 246 | implode(",", $new_bcc_email_addresses) |
| @@ -218,9 +251,9 @@ | ||
| 218 | 251 | } |
| 219 | 252 | |
| 220 | 253 | do_action( 'propertyhive_property_match_step_send', $contact_id, $applicant_profile_id ); |
| 221 | 254 | |
| 222 | - echo '<script>window.location.href = "' . get_edit_post_link( $contact_id, 'url' ) . '&ph_message=1";</script>'; | |
| 255 | + echo '<script>window.location.href = ' . wp_json_encode( get_edit_post_link( $contact_id, 'url' ) . '&ph_message=1', JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ) . ';</script>'; | |
| 223 | 256 | } |
| 224 | 257 | } |
| 225 | 258 | } |
| 226 | 259 | else |
| @@ -226,12 +259,12 @@ | ||
| 226 | 259 | else |
| 227 | 260 | { |
| 228 | 261 | $applicant_profile_match_history = get_post_meta( $contact_id, '_applicant_profile_' . $applicant_profile_id . '_match_history', TRUE ); |
| 229 | 262 | |
| 230 | - $properties = $this->get_matching_properties( (int)$_GET['contact_id'], (int)$_GET['applicant_profile'] ); | |
| 263 | + $properties = $this->get_matching_properties( $contact_id, $applicant_profile_id ); | |
| 231 | 264 | |
| 232 | 265 | $do_not_email = false; |
| 233 | - $forbidden_contact_methods = get_post_meta( (int)$_GET['contact_id'], '_forbidden_contact_methods', TRUE ); | |
| 266 | + $forbidden_contact_methods = get_post_meta( $contact_id, '_forbidden_contact_methods', TRUE ); | |
| 234 | 267 | if ( is_array($forbidden_contact_methods) && in_array('email', $forbidden_contact_methods) ) |
| 235 | 268 | { |
| 236 | 269 | $do_not_email = true; |
| 237 | 270 | } |
| @@ -239,15 +272,19 @@ | ||
| 239 | 272 | include 'views/html-admin-matching-properties.php'; |
| 240 | 273 | } |
| 241 | 274 | } |
| 242 | 275 | |
| 243 | - private function dismiss_properties() | |
| 244 | - { | |
| 245 | - $contact_id = (int)$_GET['contact_id']; | |
| 246 | - $applicant_profile_id = (int)$_GET['applicant_profile']; | |
| 276 | + private function dismiss_properties() | |
| 277 | + { | |
| 278 | + // output() verifies the matching nonce before calling this private mutator. | |
| 279 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing -- This private helper is only called from output() after the matching nonce has been verified. | |
| 280 | + $request_post = wp_unslash( $_POST ); | |
| 281 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This private helper receives the read-only contact identifier from the already-authorized matching screen. | |
| 282 | + $request_get = wp_unslash( $_GET ); | |
| 283 | + $contact_id = ( isset( $request_get['contact_id'] ) && is_scalar( $request_get['contact_id'] ) ) ? absint( $request_get['contact_id'] ) : 0; | |
| 247 | 284 | |
| 248 | - // Get currently dismissed properties for this contact to decide if we need to add or remove it | |
| 249 | - $dismissed_properties = get_post_meta( $contact_id, '_dismissed_properties', TRUE ); | |
| 285 | + // Get currently dismissed properties for this contact to decide if we need to add or remove it | |
| 286 | + $dismissed_properties = get_post_meta( $contact_id, '_dismissed_properties', TRUE ); | |
| 250 | 287 | |
| 251 | 288 | if ( !is_array($dismissed_properties) ) |
| 252 | 289 | { |
| 253 | 290 | $dismissed_properties = array(); |
| @@ -252,12 +289,15 @@ | ||
| 252 | 289 | { |
| 253 | 290 | $dismissed_properties = array(); |
| 254 | 291 | } |
| 255 | 292 | |
| 256 | - if ( isset($_POST['not_interested_property_id']) && !empty($_POST['not_interested_property_id']) ) | |
| 257 | - { | |
| 258 | - foreach ( $_POST['not_interested_property_id'] as $property_id ) | |
| 293 | + if ( isset( $request_post['not_interested_property_id'] ) && is_array( $request_post['not_interested_property_id'] ) && ! empty( $request_post['not_interested_property_id'] ) ) | |
| 259 | 294 | { |
| 295 | + foreach ( $request_post['not_interested_property_id'] as $property_id ) | |
| 296 | + { | |
| 297 | + if ( ! is_scalar( $property_id ) ) { | |
| 298 | + continue; | |
| 299 | + } | |
| 260 | 300 | if ( in_array((int)$property_id, $dismissed_properties) ) |
| 261 | 301 | { |
| 262 | 302 | // Already dismissed. Need to remove from array |
| 263 | 303 | if( ($key = array_search((int)$property_id, $dismissed_properties)) !== false ) |
| @@ -301,30 +341,47 @@ | ||
| 301 | 341 | |
| 302 | 342 | $args = array( |
| 303 | 343 | 'post_type' => 'property', |
| 304 | 344 | 'nopaging' => true, |
| 345 | + // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in -- Exclude this contact's explicitly dismissed properties before applying existing matching and extension query conditions. | |
| 305 | 346 | 'post__not_in' => $dismissed_properties |
| 306 | 347 | ); |
| 307 | 348 | |
| 349 | + // Meta query | |
| 350 | + $meta_query = array('relation' => 'AND'); | |
| 351 | + | |
| 308 | 352 | if ( $date_added_from != '' ) |
| 309 | 353 | { |
| 310 | - // Convert stored UTC date to site timezone | |
| 311 | - $timezone = wp_timezone(); // Returns DateTimeZone object based on site settings | |
| 354 | + $datetime = new DateTimeImmutable( | |
| 355 | + $date_added_from, | |
| 356 | + new DateTimeZone( 'UTC' ) | |
| 357 | + ); | |
| 312 | 358 | |
| 313 | - $datetime = new DateTime($date_added_from, new DateTimeZone('UTC')); | |
| 314 | - $datetime->setTimezone($timezone); | |
| 315 | - $local_date = $datetime->format('Y-m-d H:i:s'); | |
| 359 | + if ( apply_filters( 'propertyhive_matching_properties_use_on_market_change_date', false ) === true ) | |
| 360 | + { | |
| 361 | + // _on_market_change_date is currently stored using date(), | |
| 362 | + // which will normally be UTC in WordPress. | |
| 363 | + $meta_query[] = array( | |
| 364 | + 'key' => '_on_market_change_date', | |
| 365 | + 'value' => $datetime->format( 'Y-m-d H:i:s' ), | |
| 366 | + 'compare' => '>=', | |
| 367 | + 'type' => 'DATETIME', | |
| 368 | + ); | |
| 369 | + } | |
| 370 | + else | |
| 371 | + { | |
| 372 | + // post_date is stored in the site's local timezone. | |
| 373 | + $local_datetime = $datetime->setTimezone( wp_timezone() ); | |
| 316 | 374 | |
| 317 | - $args['date_query'] = array( | |
| 318 | - array( | |
| 319 | - 'after' => $local_date, | |
| 320 | - 'inclusive' => true, | |
| 321 | - ) | |
| 322 | - ); | |
| 375 | + $args['date_query'] = array( | |
| 376 | + array( | |
| 377 | + 'after' => $local_datetime->format( 'Y-m-d H:i:s' ), | |
| 378 | + 'inclusive' => true, | |
| 379 | + ), | |
| 380 | + ); | |
| 381 | + } | |
| 323 | 382 | } |
| 324 | 383 | |
| 325 | - // Meta query | |
| 326 | - $meta_query = array('relation' => 'AND'); | |
| 327 | 384 | $meta_query[] = array( |
| 328 | 385 | 'key' => '_on_market', |
| 329 | 386 | 'value' => 'yes' |
| 330 | 387 | ); |
| @@ -611,8 +668,9 @@ | ||
| 611 | 668 | } |
| 612 | 669 | $meta_query[] = $location_query; |
| 613 | 670 | } |
| 614 | 671 | } |
| 672 | + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Required property matching criteria (department, price, market state and area) use the plugin's existing metadata schema. | |
| 615 | 673 | $args['meta_query'] = $meta_query; |
| 616 | 674 | |
| 617 | 675 | // Term query |
| 618 | 676 | $tax_query = array('relation' => 'AND'); |
| @@ -675,8 +733,9 @@ | ||
| 675 | 733 | 'terms' => $property_match_statuses, |
| 676 | 734 | 'operator' => 'IN', |
| 677 | 735 | ); |
| 678 | 736 | } |
| 737 | + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Applicant property-type/location and availability constraints require the existing taxonomies; preserve extension query semantics. | |
| 679 | 738 | $args['tax_query'] = $tax_query; |
| 680 | 739 | |
| 681 | 740 | $args = apply_filters( 'propertyhive_matching_properties_args', $args, $contact_id, $applicant_profile ); |
| 682 | 741 | |
| @@ -714,10 +773,10 @@ | ||
| 714 | 773 | } |
| 715 | 774 | |
| 716 | 775 | $subject = str_replace("[property_count]", count($email_property_ids) . ' propert' . ( ( count($email_property_ids) != 1 ) ? 'ies' : 'y' ), $subject); |
| 717 | 776 | |
| 718 | - $body = str_replace("[contact_name]", $contact->post_title, $body); | |
| 719 | - $body = str_replace("[contact_dear]", $contact->dear(), $body); | |
| 777 | + $body = str_replace( '[contact_name]', esc_html( $contact->post_title ), $body ); | |
| 778 | + $body = str_replace( '[contact_dear]', esc_html( $contact->dear() ), $body ); | |
| 720 | 779 | $body = str_replace("[property_count]", count($email_property_ids) . ' propert' . ( ( count($email_property_ids) != 1 ) ? 'ies' : 'y' ), $body); |
| 721 | 780 | |
| 722 | 781 | $office_counts = array(); |
| 723 | 782 | |
| @@ -764,13 +823,13 @@ | ||
| 764 | 823 | $office_name = get_the_title($office_id); |
| 765 | 824 | $office_email_address = get_post_meta( $office_id, '_office_email_address_' . str_replace("residential-", "", $applicant_profile_details['department']), TRUE ); |
| 766 | 825 | } |
| 767 | 826 | |
| 768 | - $body = str_replace("[office_name]", $office_name, $body); | |
| 769 | - $body = str_replace("[office_email_address]", $office_email_address, $body); | |
| 827 | + $body = str_replace( '[office_name]', esc_html( $office_name ), $body ); | |
| 828 | + $body = str_replace( '[office_email_address]', esc_html( $office_email_address ), $body ); | |
| 770 | 829 | |
| 771 | - $body = str_replace("[negotiator_name]", $current_user->display_name, $body); | |
| 772 | - $body = str_replace("[negotiator_email_address]", $current_user->user_email, $body); | |
| 830 | + $body = str_replace( '[negotiator_name]', esc_html( $current_user->display_name ), $body ); | |
| 831 | + $body = str_replace( '[negotiator_email_address]', esc_html( $current_user->user_email ), $body ); | |
| 773 | 832 | |
| 774 | 833 | $body = stripslashes($body); |
| 775 | 834 | |
| 776 | 835 | if (extension_loaded('zlib')) |
| @@ -782,8 +841,9 @@ | ||
| 782 | 841 | } |
| 783 | 842 | } |
| 784 | 843 | |
| 785 | 844 | // Insert into email log |
| 845 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Typed insert into the plugin-owned email queue table; no WordPress object API represents these queued messages. | |
| 786 | 846 | $insert = $wpdb->insert( |
| 787 | 847 | $wpdb->prefix . 'ph_email_log', |
| 788 | 848 | array( |
| 789 | 849 | 'contact_id' => $contact_id, |
| @@ -796,9 +856,9 @@ | ||
| 796 | 856 | 'from_email_address' => $from_email_address, |
| 797 | 857 | 'subject' => stripslashes($subject), |
| 798 | 858 | 'body' => $body, |
| 799 | 859 | 'status' => '', |
| 800 | - 'send_at' => date("Y-m-d H:i:s"), | |
| 860 | + 'send_at' => gmdate("Y-m-d H:i:s"), | |
| 801 | 861 | 'sent_by' => $current_user->ID, |
| 802 | 862 | ), |
| 803 | 863 | array( |
| 804 | 864 | '%d', |
| @@ -837,9 +897,9 @@ | ||
| 837 | 897 | $applicant_profile_match_history[$email_property_id] = array(); |
| 838 | 898 | } |
| 839 | 899 | |
| 840 | 900 | $applicant_profile_match_history[$email_property_id][] = array( |
| 841 | - 'date' => date("Y-m-d H:i:s"), | |
| 901 | + 'date' => gmdate("Y-m-d H:i:s"), | |
| 842 | 902 | 'method' => 'email', |
| 843 | 903 | 'email_log_id' => $email_log_id, |
| 844 | 904 | ); |
| 845 | 905 | |
| @@ -854,9 +914,9 @@ | ||
| 854 | 914 | 'comment_post_ID' => $email_property_id, |
| 855 | 915 | 'comment_author' => $current_user->display_name, |
| 856 | 916 | 'comment_author_email' => 'propertyhive@noreply.com', |
| 857 | 917 | 'comment_author_url' => '', |
| 858 | - 'comment_date' => date("Y-m-d H:i:s"), | |
| 918 | + 'comment_date' => gmdate("Y-m-d H:i:s"), | |
| 859 | 919 | 'comment_content' => serialize($comment), |
| 860 | 920 | 'comment_approved' => 1, |
| 861 | 921 | 'comment_type' => 'propertyhive_note', |
| 862 | 922 | ); |
| @@ -877,9 +937,9 @@ | ||
| 877 | 937 | 'comment_post_ID' => $contact_id, |
| 878 | 938 | 'comment_author' => $current_user->display_name, |
| 879 | 939 | 'comment_author_email' => 'propertyhive@noreply.com', |
| 880 | 940 | 'comment_author_url' => '', |
| 881 | - 'comment_date' => date("Y-m-d H:i:s"), | |
| 941 | + 'comment_date' => gmdate("Y-m-d H:i:s"), | |
| 882 | 942 | 'comment_content' => serialize($comment), |
| 883 | 943 | 'comment_approved' => 1, |
| 884 | 944 | 'comment_type' => 'propertyhive_note', |
| 885 | 945 | ); |
| @@ -889,5 +949,5 @@ | ||
| 889 | 949 | } |
| 890 | 950 | |
| 891 | 951 | } |
| 892 | 952 | |
| 893 | -endif; | |
| 953 | +endif; | |