Changeset 3694341
- Timestamp:
- 09/14/2026 01:35:18 AM (2 months ago)
- Location:
- integrate-palace-properties
- Files:
-
- 8 added
- 2 deleted
- 80 edited
- 1 copied
-
tags/3.0.0 (copied) (copied from integrate-palace-properties/trunk )
-
tags/3.0.0/DEVELOPERS.md (added)
-
tags/3.0.0/README.md (deleted)
-
tags/3.0.0/admin/class-integratepalacep-admin-ajax.php (modified) (3 diffs)
-
tags/3.0.0/admin/class-integratepalacep-admin.php (modified) (13 diffs)
-
tags/3.0.0/admin/class-integratepalacep-dashboard.php (modified) (9 diffs)
-
tags/3.0.0/includes/class-integratepalacep-activator.php (modified) (1 diff)
-
tags/3.0.0/includes/class-integratepalacep-customizer.php (modified) (1 diff)
-
tags/3.0.0/includes/class-integratepalacep-deactivator.php (added)
-
tags/3.0.0/includes/class-integratepalacep-local-fields.php (modified) (3 diffs)
-
tags/3.0.0/includes/class-integratepalacep-property-helper.php (modified) (6 diffs)
-
tags/3.0.0/includes/class-integratepalacep-settings.php (modified) (13 diffs)
-
tags/3.0.0/includes/class-integratepalacep-webhooks.php (modified) (13 diffs)
-
tags/3.0.0/includes/class-integratepalacep.php (modified) (4 diffs)
-
tags/3.0.0/includes/class-ipp-customizer-settings.php (modified) (3 diffs)
-
tags/3.0.0/includes/class-ipp-developer-api.php (modified) (2 diffs)
-
tags/3.0.0/includes/class-ipp-hooks.php (modified) (4 diffs)
-
tags/3.0.0/includes/class-ipp-rest-api.php (modified) (3 diffs)
-
tags/3.0.0/includes/class-ipp-shortcodes.php (modified) (5 diffs)
-
tags/3.0.0/includes/class-ipp-sync-cli.php (added)
-
tags/3.0.0/includes/class-ipp-sync.php (added)
-
tags/3.0.0/includes/customizer/class-integratepalacep-customizer-register_sections_panels.php (modified) (1 diff)
-
tags/3.0.0/includes/customizer/class-integratepalacep-customizer-sanitizes.php (modified) (1 diff)
-
tags/3.0.0/includes/customizer/class-integratepalacep-template-defaults.php (modified) (1 diff)
-
tags/3.0.0/includes/customizer/class-integratepalacep-template-dynamic-css.php (modified) (5 diffs)
-
tags/3.0.0/includes/customizer/configurations/class-integratepalacep-colors-config.php (modified) (1 diff)
-
tags/3.0.0/includes/customizer/configurations/class-integratepalacep-typography-config.php (modified) (1 diff)
-
tags/3.0.0/includes/customizer/extend-custom-controls/class-integratepalacep-extend-custom-controls.php (modified) (15 diffs)
-
tags/3.0.0/includes/customizer/extend-customizer/class-integratepalacep-customize-panels.php (modified) (1 diff)
-
tags/3.0.0/includes/customizer/extend-customizer/class-integratepalacep-customize-sections.php (modified) (1 diff)
-
tags/3.0.0/integrate-palace-properties.php (modified) (4 diffs)
-
tags/3.0.0/public/archive-palace_property.php (modified) (5 diffs)
-
tags/3.0.0/public/class-integratepalacep-public.php (modified) (9 diffs)
-
tags/3.0.0/public/class-integratepalacep-svg-icons.php (modified) (1 diff)
-
tags/3.0.0/public/single-palace_property.php (modified) (2 diffs)
-
tags/3.0.0/public/templates/archive.php (modified) (3 diffs)
-
tags/3.0.0/public/templates/classic/single.php (modified) (3 diffs)
-
tags/3.0.0/public/templates/developer/single.php (modified) (4 diffs)
-
tags/3.0.0/public/templates/grid-gallery/single.php (modified) (3 diffs)
-
tags/3.0.0/public/templates/minimal/single.php (modified) (3 diffs)
-
tags/3.0.0/public/templates/modern/single.php (modified) (3 diffs)
-
tags/3.0.0/public/templates/palace-property/single.php (modified) (4 diffs)
-
tags/3.0.0/public/templates/search-default.php (modified) (3 diffs)
-
tags/3.0.0/public/templates/single.php (modified) (2 diffs)
-
tags/3.0.0/readme.txt (modified) (8 diffs)
-
tags/3.0.0/uninstall.php (modified) (4 diffs)
-
trunk/DEVELOPERS.md (added)
-
trunk/README.md (deleted)
-
trunk/admin/class-integratepalacep-admin-ajax.php (modified) (3 diffs)
-
trunk/admin/class-integratepalacep-admin.php (modified) (13 diffs)
-
trunk/admin/class-integratepalacep-dashboard.php (modified) (9 diffs)
-
trunk/includes/class-integratepalacep-activator.php (modified) (1 diff)
-
trunk/includes/class-integratepalacep-customizer.php (modified) (1 diff)
-
trunk/includes/class-integratepalacep-deactivator.php (added)
-
trunk/includes/class-integratepalacep-local-fields.php (modified) (3 diffs)
-
trunk/includes/class-integratepalacep-property-helper.php (modified) (6 diffs)
-
trunk/includes/class-integratepalacep-settings.php (modified) (13 diffs)
-
trunk/includes/class-integratepalacep-webhooks.php (modified) (13 diffs)
-
trunk/includes/class-integratepalacep.php (modified) (4 diffs)
-
trunk/includes/class-ipp-customizer-settings.php (modified) (3 diffs)
-
trunk/includes/class-ipp-developer-api.php (modified) (2 diffs)
-
trunk/includes/class-ipp-hooks.php (modified) (4 diffs)
-
trunk/includes/class-ipp-rest-api.php (modified) (3 diffs)
-
trunk/includes/class-ipp-shortcodes.php (modified) (5 diffs)
-
trunk/includes/class-ipp-sync-cli.php (added)
-
trunk/includes/class-ipp-sync.php (added)
-
trunk/includes/customizer/class-integratepalacep-customizer-register_sections_panels.php (modified) (1 diff)
-
trunk/includes/customizer/class-integratepalacep-customizer-sanitizes.php (modified) (1 diff)
-
trunk/includes/customizer/class-integratepalacep-template-defaults.php (modified) (1 diff)
-
trunk/includes/customizer/class-integratepalacep-template-dynamic-css.php (modified) (5 diffs)
-
trunk/includes/customizer/configurations/class-integratepalacep-colors-config.php (modified) (1 diff)
-
trunk/includes/customizer/configurations/class-integratepalacep-typography-config.php (modified) (1 diff)
-
trunk/includes/customizer/extend-custom-controls/class-integratepalacep-extend-custom-controls.php (modified) (15 diffs)
-
trunk/includes/customizer/extend-customizer/class-integratepalacep-customize-panels.php (modified) (1 diff)
-
trunk/includes/customizer/extend-customizer/class-integratepalacep-customize-sections.php (modified) (1 diff)
-
trunk/integrate-palace-properties.php (modified) (4 diffs)
-
trunk/public/archive-palace_property.php (modified) (5 diffs)
-
trunk/public/class-integratepalacep-public.php (modified) (9 diffs)
-
trunk/public/class-integratepalacep-svg-icons.php (modified) (1 diff)
-
trunk/public/single-palace_property.php (modified) (2 diffs)
-
trunk/public/templates/archive.php (modified) (3 diffs)
-
trunk/public/templates/classic/single.php (modified) (3 diffs)
-
trunk/public/templates/developer/single.php (modified) (4 diffs)
-
trunk/public/templates/grid-gallery/single.php (modified) (3 diffs)
-
trunk/public/templates/minimal/single.php (modified) (3 diffs)
-
trunk/public/templates/modern/single.php (modified) (3 diffs)
-
trunk/public/templates/palace-property/single.php (modified) (4 diffs)
-
trunk/public/templates/search-default.php (modified) (3 diffs)
-
trunk/public/templates/single.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (8 diffs)
-
trunk/uninstall.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
integrate-palace-properties/tags/3.0.0/admin/class-integratepalacep-admin-ajax.php
r3486430 r3694341 6 6 public static function init() { 7 7 add_action( 'wp_ajax_ipp_trigger_sync', array( __CLASS__, 'trigger_sync' ) ); 8 add_action( 'wp_ajax_ipp_force_sync', array( __CLASS__, 'force_sync' ) ); 8 9 add_action( 'wp_ajax_ipp_get_sync_status', array( __CLASS__, 'get_sync_status' ) ); 9 10 add_action( 'wp_ajax_ipp_test_connection', array( __CLASS__, 'test_connection' ) ); … … 14 15 15 16 /** 16 * Trigger a property sync via the Laravel API.17 * Start a sync run against the Palace API straight away. 17 18 */ 18 19 public static function trigger_sync() { … … 23 24 } 24 25 25 $api_base = defined( 'IPP_API_URL' ) ? IPP_API_URL : 'https://wp-palace.kiwibrain.co.nz'; 26 $sub_key = get_option( 'integrate_palace_properties_subscription_key', '' ); 27 28 if ( empty( $sub_key ) ) { 29 wp_send_json_error( __( 'No subscription key configured.', 'integrate-palace-properties' ) ); 30 } 31 32 // Call the Laravel API to trigger sync 33 $response = wp_remote_post( $api_base . '/api/sync/trigger', array( 34 'method' => 'POST', 35 'headers' => array( 36 'Content-Type' => 'application/json', 37 'X-Subscription-Key' => sanitize_text_field( $sub_key ), 38 ), 39 'body' => wp_json_encode( array( 40 'subscription_key' => sanitize_text_field( $sub_key ), 41 ) ), 42 'timeout' => 30, 43 ) ); 26 if ( ! IPP_Sync::has_credentials() ) { 27 wp_send_json_error( __( 'Add your Palace API username and password on the Configs page first.', 'integrate-palace-properties' ) ); 28 } 29 30 if ( IPP_Sync::is_running() ) { 31 $progress = IPP_Sync::get_progress(); 32 wp_send_json_success( array( 33 'message' => sprintf( 34 /* translators: 1: batches completed, 2: total batches. */ 35 __( 'A sync is already running — batch %1$d of %2$d.', 'integrate-palace-properties' ), 36 (int) $progress['done'], 37 (int) $progress['total'] 38 ), 39 'running' => true, 40 ) ); 41 } 42 43 // Do not run the sync inline. Fetching the full property list can take 44 // minutes, and admin-ajax would hit the host's gateway timeout first — 45 // the user would see "Request failed" for a sync that is actually fine. 46 // Hand it to cron and return immediately. 47 // The args array( false ) matter. WordPress refuses a single event that 48 // matches an existing one (same hook and args) within ten minutes, so 49 // scheduling with no args was silently ignored whenever the recurring 50 // event happened to be due soon. 51 wp_schedule_single_event( time() + 1, IPP_Sync::CRON_HOOK, array( false ) ); 52 spawn_cron(); 44 53 45 54 $prop_count = wp_count_posts( 'palace-properties' ); 46 $count = isset( $prop_count->publish ) ? $prop_count->publish : 0; 47 48 if ( is_wp_error( $response ) ) { 49 wp_send_json_error( sprintf( 50 /* translators: %s: error message */ 51 __( 'Sync request failed: %s. You have %d properties locally.', 'integrate-palace-properties' ), 52 $response->get_error_message(), 53 $count 54 ) ); 55 } 56 57 $status_code = wp_remote_retrieve_response_code( $response ); 58 59 if ( $status_code < 200 || $status_code >= 300 ) { 60 wp_send_json_error( sprintf( 61 /* translators: %d: HTTP status code, %d: property count */ 62 __( 'Sync request returned HTTP %1$d. You have %2$d properties locally.', 'integrate-palace-properties' ), 63 $status_code, 64 $count 65 ) ); 66 } 67 68 // Only update last sync time on actual success 69 update_option( 'ipp_last_sync_time', current_time( 'mysql' ) ); 70 update_option( 'ipp_last_sync_count', $count ); 71 72 wp_send_json_success( array( 73 'message' => __( 'Resync requested from Palace server.', 'integrate-palace-properties' ), 74 'count' => $count, 75 'api_status' => $status_code, 55 $count = isset( $prop_count->publish ) ? (int) $prop_count->publish : 0; 56 57 wp_send_json_success( array( 58 'message' => __( 'Sync queued. Properties will import over the next few minutes.', 'integrate-palace-properties' ), 59 'count' => $count, 60 'running' => true, 61 ) ); 62 } 63 64 /** 65 * Queue a full re-import that ignores change codes. 66 * 67 * For recovering from damaged or hand-edited property data. It replaces any 68 * sync already in progress. 69 */ 70 public static function force_sync() { 71 check_ajax_referer( 'ipp_admin_nonce', 'nonce' ); 72 73 if ( ! current_user_can( 'manage_options' ) ) { 74 wp_send_json_error( __( 'Permission denied.', 'integrate-palace-properties' ) ); 75 } 76 77 if ( ! IPP_Sync::has_credentials() ) { 78 wp_send_json_error( __( 'Add your Palace API username and password on the Configs page first.', 'integrate-palace-properties' ) ); 79 } 80 81 wp_schedule_single_event( time() + 1, IPP_Sync::CRON_HOOK, array( true ) ); 82 spawn_cron(); 83 84 wp_send_json_success( array( 85 'message' => __( 'Full re-import queued. Every property will be refreshed from Palace over the next few minutes.', 'integrate-palace-properties' ), 86 'running' => true, 76 87 ) ); 77 88 } -
integrate-palace-properties/tags/3.0.0/admin/class-integratepalacep-admin.php
r3524333 r3694341 29 29 } 30 30 31 // WP-Cron runs every due event in one request. After a big import that is 32 // one image job per property, each fetching several megabytes: measured 33 // against the real Palace API, 30 jobs took about 150 seconds in a single 34 // request, far past typical host limits. A job killed part-way is lost, 35 // because WordPress unschedules an event before running it. So once this 36 // request has been busy for a while, defer to the next cron run instead. 37 // WP-CLI and manual runs have no such limit and are not deferred. 38 if ( wp_doing_cron() && timer_float() > self::gallery_time_budget() ) { 39 wp_schedule_single_event( time() + MINUTE_IN_SECONDS, 'update_integrate_palace_gallery', array( $post_id, $property_code ) ); 40 self::update_gallery_sync_status( $post_id, 'queued', 'Queued for the next cron run.' ); 41 return; 42 } 43 31 44 self::update_gallery_sync_status( $post_id, 'syncing', 'Fetching image list from Palace API...' ); 32 45 … … 42 55 $api_url = "https://api.getpalace.com/Service.svc/RestService/v2AvailablePropertyImages/JSON/$property_code"; 43 56 $headers = array( 'Authorization' => 'Basic ' . base64_encode( "$username:$password" ) ); 44 // Throttle: respect Palace API rate limits during batch operations 45 $last_call = get_transient( 'ipp_gallery_api_last_call' ); 57 58 // Share one throttle with the property-list sync (IPP_Sync::request()), 59 // so the two never hit Palace at the same moment. 60 $last_call = get_transient( 'ipp_api_last_call' ); 46 61 if ( $last_call && ( microtime( true ) - (float) $last_call ) < 1.5 ) { 47 62 usleep( 1500000 ); // 1.5s minimum gap between API calls … … 49 64 50 65 $response = wp_remote_get( $api_url, array( 'headers' => $headers, 'timeout' => 60 ) ); 51 set_transient( 'ipp_gallery_api_last_call', microtime( true ), 60 ); 52 53 if ( is_wp_error( $response ) ) { 54 $error_msg = $response->get_error_message(); 66 set_transient( 'ipp_api_last_call', microtime( true ), 60 ); 67 68 // Treat an HTTP error (401, 429, 500...) exactly like a transport error. 69 // Only transport errors used to be caught, so an error body was parsed 70 // as the image list, yielded no valid images, and the entire existing 71 // gallery was deleted. 72 $http_code = is_wp_error( $response ) ? 0 : (int) wp_remote_retrieve_response_code( $response ); 73 74 if ( is_wp_error( $response ) || $http_code < 200 || $http_code >= 300 ) { 75 $error_msg = is_wp_error( $response ) ? $response->get_error_message() : 'HTTP ' . $http_code; 55 76 error_log( 'IPP Gallery: API error — ' . $error_msg ); 56 77 … … 70 91 71 92 $images = json_decode( wp_remote_retrieve_body( $response ), true ); 93 unset( $response ); // The body holds every photo base64-encoded; free it now. 94 72 95 if ( empty( $images ) ) { 73 96 // Don't touch existing gallery — API may just have no data right now. … … 76 99 } 77 100 78 // Build map of existing gallery attachments by filename 101 // Palace returns a JSON list of image records. Anything else (an error 102 // envelope, a single object) is not an image list and must not be allowed 103 // anywhere near the existing gallery. 104 if ( ! is_array( $images ) || array_values( $images ) !== $images ) { 105 self::update_gallery_sync_status( $post_id, 'failed', 'Unexpected response from the Palace images API. The existing gallery was left untouched.' ); 106 return; 107 } 108 109 // Map existing attachments by their Palace image code. Matching on the file 110 // name broke whenever WordPress renamed an upload ("-scaled" for large 111 // photos, or "-1" on a name clash), and every such image was downloaded 112 // and re-created again on each sync. 79 113 $gallery = get_post_meta( $post_id, 'integrate_palace_gallery', true ); 80 114 if ( ! is_array( $gallery ) ) { … … 83 117 $existing = array(); 84 118 foreach ( $gallery as $att_id ) { 85 $url = wp_get_attachment_url( $att_id ); 86 if ( $url ) { 87 $existing[ basename( $url ) ] = $att_id; 88 } 89 } 90 91 if ( ! function_exists( 'pp_get_image_extension' ) ) { 92 function pp_get_image_extension( $base64_string ) { 93 $img_info = getimagesizefromstring( base64_decode( $base64_string ) ); 94 return $img_info ? image_type_to_extension( $img_info[2], false ) : 'jpg'; 95 } 119 $att_id = (int) $att_id; 120 $code = (string) get_post_meta( $att_id, 'ipp_image_code', true ); 121 122 if ( '' === $code ) { 123 // Attachments created before 3.0.0 have no stored code: fall back 124 // to the file name, which was "{image code}.{extension}". 125 $url = wp_get_attachment_url( $att_id ); 126 if ( ! $url ) { 127 continue; 128 } 129 $code = preg_replace( '/(-scaled)?\.[a-z0-9]+$/i', '', basename( $url ) ); 130 } 131 132 $existing[ $code ] = $att_id; 96 133 } 97 134 … … 105 142 $processed = 0; 106 143 107 foreach ( $images as $image ) { 144 // array_shift() releases each photo's base64 once it is handled, rather 145 // than holding every image of a large gallery in memory at once. 146 while ( null !== ( $image = array_shift( $images ) ) ) { 147 if ( ! is_array( $image ) ) { 148 $errors[] = 'unknown: not an image record'; 149 continue; 150 } 151 108 152 $image_code = sanitize_file_name( $image['PropertyImageCode'] ?? '' ); 109 153 $base64 = $image['PropertyImageBase64'] ?? ''; 154 unset( $image ); 110 155 111 156 if ( empty( $image_code ) || empty( $base64 ) ) { … … 114 159 } 115 160 116 $file_extension = pp_get_image_extension( $base64 ); 117 $filename = "$image_code.$file_extension"; 118 119 if ( isset( $existing[ $filename ] ) ) { 120 $kept[] = $existing[ $filename ]; 121 unset( $existing[ $filename ] ); 161 if ( isset( $existing[ $image_code ] ) ) { 162 // Already downloaded: keep it without decoding anything. 163 $kept[] = $existing[ $image_code ]; 164 unset( $existing[ $image_code ] ); 122 165 } else { 123 166 $image_data = base64_decode( $base64 ); 167 unset( $base64 ); 168 124 169 if ( empty( $image_data ) ) { 125 $errors[] = $ filename . ': decode failed';170 $errors[] = $image_code . ': decode failed'; 126 171 continue; 127 172 } 128 173 174 $img_info = getimagesizefromstring( $image_data ); 175 $file_extension = $img_info ? image_type_to_extension( $img_info[2], false ) : 'jpg'; 176 $filename = "$image_code.$file_extension"; 177 129 178 $upload = wp_upload_bits( $filename, null, $image_data ); 179 unset( $image_data ); 180 130 181 if ( $upload['error'] ) { 131 182 $errors[] = $filename . ': ' . $upload['error']; … … 140 191 141 192 if ( ! is_wp_error( $attach_id ) ) { 193 update_post_meta( $attach_id, 'ipp_image_code', $image_code ); 142 194 $meta = wp_generate_attachment_metadata( $attach_id, $upload['file'] ); 143 195 wp_update_attachment_metadata( $attach_id, $meta ); … … 155 207 } 156 208 209 // Nothing usable came back, but the property already has photos: keep them. 210 // Never replace a working gallery with an empty one. 211 if ( empty( $kept ) && ! empty( $gallery ) ) { 212 $msg = '0/' . $total . ' images could be saved, so the existing gallery was left untouched.'; 213 if ( count( $errors ) > 0 ) { 214 $msg .= ' Errors: ' . implode( '; ', array_slice( $errors, 0, 3 ) ); 215 } 216 self::update_gallery_sync_status( $post_id, 'failed', $msg, 0, $total ); 217 return; 218 } 219 157 220 // Finalize gallery 158 221 $new_gallery = $kept; … … 164 227 update_post_meta( $post_id, 'integrate_palace_gallery', $new_gallery ); 165 228 166 // Delete orphaned old images 229 // Delete images Palace no longer lists. Anything still in $existing was 230 // absent from the response entirely; images that are listed but failed 231 // to download were never in $existing, so a partial failure cannot 232 // remove photos that are still current. 167 233 foreach ( $existing as $old_id ) { 168 234 wp_delete_attachment( $old_id, true ); … … 188 254 /** @hook ipp_gallery_updated */ 189 255 do_action( 'ipp_gallery_updated', $post_id, $new_gallery ); 256 } 257 258 /** 259 * Seconds a cron request may spend before image jobs defer to the next run. 260 * 261 * @return int 262 */ 263 private static function gallery_time_budget() { 264 /** 265 * Filter how long one cron request keeps processing image jobs. 266 * 267 * Keep it comfortably below the host's PHP request timeout. 268 * 269 * @param int $seconds Defaults to 20. 270 */ 271 return max( 5, (int) apply_filters( 'ipp_gallery_tick_seconds', 20 ) ); 190 272 } 191 273 … … 238 320 if (strpos($file, 'integrate-palace-properties') !== false) { 239 321 $new_links = array( 240 '<a target="_blank" href="https://wp-palace.kiwibrain.co.nz/register"><b>Go Pro</b></a>', 241 '<a href="mailto:itsisaf@gmail.com">Support</a>', 242 '<a target="_blank" href="https://wp-palace.kiwibrain.co.nz">View details</a>', 243 '<a href="' . esc_url( admin_url( 'admin.php?page=ipp-developer-docs' ) ) . '">Developer Docs</a>', 322 '<a href="' . esc_url( admin_url( 'admin.php?page=integrate-palace-properties-configs' ) ) . '">' . esc_html__( 'Settings', 'integrate-palace-properties' ) . '</a>', 323 '<a href="mailto:itsisaf@gmail.com">' . esc_html__( 'Support', 'integrate-palace-properties' ) . '</a>', 324 '<a href="' . esc_url( admin_url( 'admin.php?page=ipp-developer-docs' ) ) . '">' . esc_html__( 'Developer Docs', 'integrate-palace-properties' ) . '</a>', 244 325 ); 245 326 $links = array_merge($links, $new_links); -
integrate-palace-properties/tags/3.0.0/admin/class-integratepalacep-dashboard.php
r3486430 r3694341 10 10 11 11 // ─── Gather Data ──────────────────────────────────────────── 12 $status_html = get_option( 'integrate_palace_properties_webhook_status', '' ); 13 $is_connected = strpos( $status_html, 'wh_connected' ) !== false; 12 // "Connected" now means the site has Palace credentials it can poll with. 13 $is_connected = IPP_Sync::has_credentials(); 14 $last_run = IPP_Sync::get_last_run(); 15 $sync_running = IPP_Sync::is_running(); 16 $sync_progress = IPP_Sync::get_progress(); 17 $next_sync = wp_next_scheduled( IPP_Sync::CRON_HOOK ); 14 18 $template = get_option( 'ipp_select_template', 'palace-property' ); 15 19 $last_sync = get_option( 'ipp_last_sync_time', '' ); 16 20 $last_sync_count = get_option( 'ipp_last_sync_count', 0 ); 17 $webhook_url = get_option( 'integrate_palace_properties_webhook_url', '' );18 $blog_id = get_option( 'integrate_palace-palace-unique-id', '' );19 $sub_key = get_option( 'integrate_palace_properties_subscription_key', '' );20 21 $slug = get_option( 'integrate_palace_properties_slug', 'palace-property' ); 21 22 $default_fields = IntegratePalace_Properties_Settings::get_default_display_fields(); 22 23 $display_fields = get_option( 'ipp_display_fields', $default_fields ); 23 24 if ( empty( $display_fields ) ) $display_fields = $default_fields; // treat empty as "all defaults" 24 $sync_archived = get_option( 'ipp_sync_archived', 'no' );25 25 26 26 // Property counts … … 63 63 $archive_url = get_post_type_archive_link( 'palace-properties' ); 64 64 $rest_url = rest_url( 'palace-properties/v1/properties' ); 65 $api_base = defined( 'IPP_API_URL' ) ? IPP_API_URL : 'https://wp-palace.kiwibrain.co.nz';66 65 67 66 // Count pending gallery cron events (lightweight — no cleanup on page load) … … 169 168 <span class="dashicons dashicons-update"></span> <?php esc_html_e( 'Sync Now', 'integrate-palace-properties' ); ?> 170 169 </button> 170 <button type="button" id="ipp-force-sync" class="button" <?php echo $is_connected ? '' : 'disabled'; ?>> 171 <span class="dashicons dashicons-backup" style="margin-top:3px;"></span> <?php esc_html_e( 'Full Re-import', 'integrate-palace-properties' ); ?> 172 </button> 171 173 <button type="button" id="ipp-resync-galleries" class="button"> 172 174 <span class="dashicons dashicons-format-gallery" style="margin-top:3px;"></span> <?php esc_html_e( 'Resync Galleries', 'integrate-palace-properties' ); ?> … … 178 180 </div> 179 181 </div> 182 183 <?php 184 // WP-Cron only runs when the site gets visits, or from a real server 185 // cron. If the scheduled check is long overdue, syncing has stalled, 186 // and with no relay any more the owner is the only one who can fix it. 187 $ipp_schedules = wp_get_schedules(); 188 $ipp_interval = IPP_Sync::get_interval(); 189 $ipp_interval_secs = isset( $ipp_schedules[ $ipp_interval ]['interval'] ) ? (int) $ipp_schedules[ $ipp_interval ]['interval'] : HOUR_IN_SECONDS; 190 $ipp_cron_overdue = $is_connected && $next_sync && ( time() - $next_sync ) > 2 * $ipp_interval_secs; 191 if ( $ipp_cron_overdue ) : 192 ?> 193 <div class="notice notice-warning inline" style="margin:0 0 20px;"> 194 <p> 195 <strong><?php esc_html_e( 'Scheduled syncing appears to have stopped.', 'integrate-palace-properties' ); ?></strong> 196 <?php 197 if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) { 198 esc_html_e( 'This site sets DISABLE_WP_CRON, so a server cron job must call wp-cron.php, and it does not seem to be running. Ask your host to set one up. Use Sync Now in the meantime.', 'integrate-palace-properties' ); 199 } else { 200 esc_html_e( 'The last check is well overdue. WP-Cron only runs when the site receives visits, so a quiet site, or one whose loopback requests are blocked, can stop syncing. Ask your host to run WordPress cron from a server cron job. Use Sync Now in the meantime.', 'integrate-palace-properties' ); 201 } 202 ?> 203 </p> 204 </div> 205 <?php endif; ?> 206 207 <?php $ipp_unfinished = IPP_Sync::get_unfinished_attempt(); ?> 208 <?php if ( $is_connected && $ipp_unfinished ) : ?> 209 <div class="notice notice-error inline" style="margin:0 0 20px;"> 210 <p> 211 <strong><?php esc_html_e( 'The last sync did not finish.', 'integrate-palace-properties' ); ?></strong> 212 <?php 213 printf( 214 /* translators: %s: human-readable time since the sync started, e.g. "2 hours". */ 215 esc_html__( 'It started %s ago but never recorded a result, which usually means the host stopped the request while it was fetching properties from Palace. Try Sync Now. If it keeps happening, ask your host to raise the PHP request timeout, or to run WordPress cron from a server cron job.', 'integrate-palace-properties' ), 216 esc_html( human_time_diff( $ipp_unfinished, time() ) ) 217 ); 218 ?> 219 </p> 220 </div> 221 <?php endif; ?> 222 223 <script> 224 jQuery( function ( $ ) { 225 $( '#ipp-force-sync' ).on( 'click', function () { 226 var $btn = $( this ), $status = $( '#ipp-sync-status' ); 227 if ( ! window.confirm( '<?php echo esc_js( __( 'Re-import every property from Palace, ignoring what has already been synced? This replaces any sync in progress and can take several minutes on a large library.', 'integrate-palace-properties' ) ); ?>' ) ) { 228 return; 229 } 230 $btn.prop( 'disabled', true ); 231 $status.text( '<?php echo esc_js( __( 'Queuing full re-import...', 'integrate-palace-properties' ) ); ?>' ).removeClass( 'success error' ); 232 $.post( ajaxurl, { 233 action: 'ipp_force_sync', 234 nonce: '<?php echo esc_js( wp_create_nonce( 'ipp_admin_nonce' ) ); ?>' 235 } ).done( function ( r ) { 236 $btn.prop( 'disabled', false ); 237 if ( r.success ) { 238 $status.text( r.data.message ).addClass( 'success' ); 239 setTimeout( function () { window.location.reload(); }, 4000 ); 240 } else { 241 $status.text( r.data || 'Request failed' ).addClass( 'error' ); 242 } 243 } ).fail( function () { 244 $btn.prop( 'disabled', false ); 245 $status.text( 'Request failed' ).addClass( 'error' ); 246 } ); 247 } ); 248 } ); 249 </script> 180 250 181 251 <?php … … 189 259 } 190 260 } 191 $visible_on_frontend = ( $sync_archived === 'yes' ) ? ( $published - $hidden ) : ( $active_count - $hidden ); 261 // Every published property is shown unless it has been hidden in 262 // the editor — the front end does not filter by Palace status. 263 $visible_on_frontend = $published - $hidden; 192 264 if ( $visible_on_frontend < 0 ) $visible_on_frontend = 0; 193 265 ?> … … 234 306 <div class="ippd-grid ippd-grid--2"> 235 307 236 <!-- Connection & Webhook-->308 <!-- Palace API Connection --> 237 309 <div class="ippd-card"> 238 310 <div class="ippd-card__head"> 239 <h3><span class="dashicons dashicons-cloud"></span> <?php esc_html_e( ' Connection & Webhook', 'integrate-palace-properties' ); ?></h3>311 <h3><span class="dashicons dashicons-cloud"></span> <?php esc_html_e( 'Palace API Connection', 'integrate-palace-properties' ); ?></h3> 240 312 <span class="ippd-badge <?php echo $is_connected ? 'ippd-badge--green' : 'ippd-badge--red'; ?>"> 241 313 <span class="ippd-dot <?php echo $is_connected ? 'ippd-dot--green' : 'ippd-dot--red'; ?>"></span> 242 <?php echo $is_connected ? esc_html__( 'C onnected', 'integrate-palace-properties' ) : esc_html__( 'Disconnected', 'integrate-palace-properties' ); ?>314 <?php echo $is_connected ? esc_html__( 'Credentials set', 'integrate-palace-properties' ) : esc_html__( 'Not configured', 'integrate-palace-properties' ); ?> 243 315 </span> 244 316 </div> 245 317 <div class="ippd-card__body"> 246 318 <div class="ippd-kv"> 247 <span class="ippd-kv__label"><span class="dashicons dashicons-admin-links"></span> API Endpoint</span> 248 <span class="ippd-kv__value"><code><?php echo esc_html( parse_url( $api_base, PHP_URL_HOST ) ?: $api_base ); ?></code></span> 249 </div> 250 <div class="ippd-kv"> 251 <span class="ippd-kv__label"><span class="dashicons dashicons-admin-site"></span> Webhook URL</span> 252 <span class="ippd-kv__value" title="<?php echo esc_attr( $webhook_url ); ?>"><?php echo $webhook_url ? '<code>' . esc_html( wp_parse_url( $webhook_url, PHP_URL_PATH ) ) . '</code>' : '<em>Not set</em>'; ?></span> 253 </div> 254 <div class="ippd-kv"> 255 <span class="ippd-kv__label"><span class="dashicons dashicons-nametag"></span> Blog ID</span> 256 <span class="ippd-kv__value"><code><?php echo esc_html( substr( $blog_id, 0, 8 ) . '...' ); ?></code></span> 257 </div> 258 <div class="ippd-kv"> 259 <span class="ippd-kv__label"><span class="dashicons dashicons-lock"></span> Subscription Key</span> 260 <span class="ippd-kv__value"><?php echo $sub_key ? '<span class="ippd-badge ippd-badge--green">Configured</span>' : '<span class="ippd-badge ippd-badge--red">Missing</span>'; ?></span> 261 </div> 262 <div class="ippd-kv"> 263 <span class="ippd-kv__label"><span class="dashicons dashicons-shield"></span> Webhook Auth</span> 264 <span class="ippd-kv__value"><?php echo get_option( 'integrate_palace_webhook_secret' ) ? '<span class="ippd-badge ippd-badge--green">HMAC Enabled</span>' : '<span class="ippd-badge ippd-badge--yellow">Open</span>'; ?></span> 265 </div> 266 <div class="ippd-kv"> 267 <span class="ippd-kv__label"><span class="dashicons dashicons-rest-api"></span> REST API</span> 319 <span class="ippd-kv__label"><span class="dashicons dashicons-admin-links"></span> <?php esc_html_e( 'API Endpoint', 'integrate-palace-properties' ); ?></span> 320 <span class="ippd-kv__value"><code>api.getpalace.com</code></span> 321 </div> 322 <div class="ippd-kv"> 323 <span class="ippd-kv__label"><span class="dashicons dashicons-update"></span> <?php esc_html_e( 'Sync Method', 'integrate-palace-properties' ); ?></span> 324 <span class="ippd-kv__value"><?php esc_html_e( 'Scheduled, direct from this site', 'integrate-palace-properties' ); ?></span> 325 </div> 326 <div class="ippd-kv"> 327 <span class="ippd-kv__label"><span class="dashicons dashicons-clock"></span> <?php esc_html_e( 'Next Check', 'integrate-palace-properties' ); ?></span> 328 <span class="ippd-kv__value"> 329 <?php 330 if ( $sync_running ) { 331 printf( 332 /* translators: 1: batches done, 2: total batches. */ 333 esc_html__( 'Importing — batch %1$d of %2$d', 'integrate-palace-properties' ), 334 (int) $sync_progress['done'], 335 (int) $sync_progress['total'] 336 ); 337 } elseif ( $next_sync ) { 338 echo esc_html( human_time_diff( time(), $next_sync ) ); 339 } else { 340 echo '<em>' . esc_html__( 'Not scheduled', 'integrate-palace-properties' ) . '</em>'; 341 } 342 ?> 343 </span> 344 </div> 345 <div class="ippd-kv"> 346 <span class="ippd-kv__label"><span class="dashicons dashicons-yes-alt"></span> <?php esc_html_e( 'Last Result', 'integrate-palace-properties' ); ?></span> 347 <span class="ippd-kv__value"> 348 <?php 349 if ( empty( $last_run ) ) { 350 echo '<em>' . esc_html__( 'No sync yet', 'integrate-palace-properties' ) . '</em>'; 351 } elseif ( isset( $last_run['status'] ) && 'failed' === $last_run['status'] ) { 352 echo '<span class="ippd-badge ippd-badge--red">' . esc_html__( 'Failed', 'integrate-palace-properties' ) . '</span>'; 353 } elseif ( isset( $last_run['status'] ) && 'warning' === $last_run['status'] ) { 354 echo '<span class="ippd-badge ippd-badge--yellow">' . esc_html__( 'Needs attention', 'integrate-palace-properties' ) . '</span>'; 355 } else { 356 printf( 357 /* translators: 1: properties updated, 2: properties removed. */ 358 esc_html__( '%1$d updated, %2$d removed', 'integrate-palace-properties' ), 359 isset( $last_run['imported'] ) ? (int) $last_run['imported'] : 0, 360 isset( $last_run['deleted'] ) ? (int) $last_run['deleted'] : 0 361 ); 362 } 363 ?> 364 </span> 365 </div> 366 <?php if ( ! empty( $last_run['message'] ) && isset( $last_run['status'] ) && in_array( $last_run['status'], array( 'failed', 'warning' ), true ) ) : ?> 367 <div class="ippd-kv"> 368 <span class="ippd-kv__label"><span class="dashicons dashicons-warning"></span> <?php esc_html_e( 'Details', 'integrate-palace-properties' ); ?></span> 369 <span class="ippd-kv__value"><?php echo esc_html( $last_run['message'] ); ?></span> 370 </div> 371 <?php endif; ?> 372 <div class="ippd-kv"> 373 <span class="ippd-kv__label"><span class="dashicons dashicons-rest-api"></span> <?php esc_html_e( 'REST API', 'integrate-palace-properties' ); ?></span> 268 374 <span class="ippd-kv__value"><a href="<?php echo esc_url( $rest_url ); ?>" target="_blank">palace-properties/v1</a></span> 269 375 </div> … … 278 384 <div class="ippd-card__body"> 279 385 <div class="ippd-kv"> 280 <span class="ippd-kv__label"><span class="dashicons dashicons-clock"></span> Last Property Received</span>386 <span class="ippd-kv__label"><span class="dashicons dashicons-clock"></span> <?php esc_html_e( 'Last Property Update', 'integrate-palace-properties' ); ?></span> 281 387 <span class="ippd-kv__value"><?php echo $last_sync ? esc_html( human_time_diff( strtotime( $last_sync ), current_time( 'timestamp' ) ) ) . ' ago' : '<em>Never</em>'; ?></span> 282 388 </div> … … 292 398 </div> 293 399 <div class="ippd-kv"> 294 <span class="ippd-kv__label"><span class="dashicons dashicons-archive"></span> Show on Frontend</span> 295 <span class="ippd-kv__value"> 296 <?php if ( $sync_archived === 'yes' ) : ?> 297 <span class="ippd-badge ippd-badge--blue">All (Active + Archived)</span> 298 <?php else : ?> 299 <span class="ippd-badge ippd-badge--green">Active Only</span> 300 <?php endif; ?> 301 </span> 400 <span class="ippd-kv__label"><span class="dashicons dashicons-hidden"></span> <?php esc_html_e( 'Hidden from Frontend', 'integrate-palace-properties' ); ?></span> 401 <span class="ippd-kv__value"><?php echo esc_html( $hidden ); ?></span> 302 402 </div> 303 403 <div class="ippd-kv"> … … 503 603 if (r.success) { 504 604 $status.text(r.data.message).addClass('success'); 605 // Properties import on WP-Cron over the following 606 // minutes; refresh so the counts reflect the new state. 607 setTimeout(function() { window.location.reload(); }, 4000); 505 608 } else { 506 609 $status.text(r.data || 'Sync failed').addClass('error'); -
integrate-palace-properties/tags/3.0.0/includes/class-integratepalacep-activator.php
r3236864 r3694341 12 12 flush_rewrite_rules(); 13 13 } 14 15 // Start polling Palace on a schedule. Safe to call on reactivation: 16 // IPP_Sync::schedule() leaves an existing matching event alone. 17 if ( class_exists( 'IPP_Sync' ) ) { 18 IPP_Sync::schedule(); 19 } 14 20 } catch (Exception $e) { 15 21 if (defined('WP_DEBUG') && WP_DEBUG) { -
integrate-palace-properties/tags/3.0.0/includes/class-integratepalacep-customizer.php
r3236864 r3694341 193 193 $dir = SCRIPT_DEBUG ? 'unminified' : 'minified'; 194 194 195 wp_enqueue_script('ippr-extend-customizer', INTEGRATE_PALACE_P_PLUGIN_URI . 'includes/customizer/assets/js/' . $dir . '/integratepalacep-extend-customizer' . $js_prefix, array( 'jquery', 'customize-preview', 'wp-color-picker' , 'customize-controls' ), false, false );196 wp_enqueue_script('color-picker-alpha', INTEGRATE_PALACE_P_PLUGIN_URI . 'includes/customizer/assets/js/' . $dir . '/wp-color-picker-alpha' . $js_prefix, array( 'jquery', 'customize-preview', 'wp-color-picker' , 'customize-controls' ), false, false );195 wp_enqueue_script('ippr-extend-customizer', INTEGRATE_PALACE_P_PLUGIN_URI . 'includes/customizer/assets/js/' . $dir . '/integratepalacep-extend-customizer' . $js_prefix, array( 'jquery', 'customize-preview', 'wp-color-picker' , 'customize-controls' ), $this->version, false ); 196 wp_enqueue_script('color-picker-alpha', INTEGRATE_PALACE_P_PLUGIN_URI . 'includes/customizer/assets/js/' . $dir . '/wp-color-picker-alpha' . $js_prefix, array( 'jquery', 'customize-preview', 'wp-color-picker' , 'customize-controls' ), $this->version, false ); 197 197 wp_enqueue_script('ippr-customizer-scripts', INTEGRATE_PALACE_P_PLUGIN_URI . 'includes/customizer/assets/js/' . $dir . '/integratepalacep-customizer' . $js_prefix, array( 'jquery', 'customize-preview', 'wp-color-picker' , 'customize-controls' ), $this->version, false ); 198 198 -
integrate-palace-properties/tags/3.0.0/includes/class-integratepalacep-local-fields.php
r3486430 r3694341 865 865 // Verify nonce 866 866 if (!isset($_POST['ipp_property_meta_nonce']) || 867 !wp_verify_nonce( $_POST['ipp_property_meta_nonce'], 'ipp_save_property_meta')) {867 !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['ipp_property_meta_nonce'])), 'ipp_save_property_meta')) { 868 868 return; 869 869 } … … 992 992 foreach ($toggle_fields as $key) { 993 993 $val = isset($_POST[$key]) ? '1' : '0'; 994 // Changing the pets/smoking checkbox by hand overrides the policy 995 // wording imported from Palace (such as "By consent"), so the label 996 // shown on the site always matches the checkbox. 997 if ( in_array( $key, array( 'ipp_pets_allowed', 'ipp_smokers_allowed' ), true ) && get_post_meta( $post_id, $key, true ) !== $val ) { 998 delete_post_meta( $post_id, 'ipp_pets_allowed' === $key ? 'ipp_pets_policy' : 'ipp_smokers_policy' ); 999 } 994 1000 update_post_meta($post_id, $key, $val); 995 1001 } … … 997 1003 // ---- Archived ---- 998 1004 if (isset($_POST['ipp_archived'])) { 999 update_post_meta($post_id, 'ipp_archived', sanitize_text_field( $_POST['ipp_archived']));1005 update_post_meta($post_id, 'ipp_archived', sanitize_text_field(wp_unslash($_POST['ipp_archived']))); 1000 1006 } 1001 1007 -
integrate-palace-properties/tags/3.0.0/includes/class-integratepalacep-property-helper.php
r3486430 r3694341 48 48 // ─── Address ──────────────────────────────────────────────────── 49 49 50 public function address1() { return $this->meta( 'address1', 'street_number' ); } 51 public function address2() { return $this->meta( 'address2', 'street_name' ); } 50 /** 51 * Whether Palace says this listing's street address must not be published. 52 * 53 * Every public output of the street address, unit and exact coordinates goes 54 * through this helper, so honouring the flag here covers the templates, the 55 * REST API, shortcodes and structured data alike. 56 * 57 * @return bool 58 */ 59 public function address_hidden() { 60 $hidden = 'no' === strtolower( trim( (string) get_post_meta( $this->post_id, 'ipp_publish_address', true ) ) ); 61 62 /** 63 * Filter whether a property's street address is hidden from visitors. 64 * 65 * @param bool $hidden True when Palace marks the address "do not publish". 66 * @param int $post_id Property post ID. 67 */ 68 return (bool) apply_filters( 'ipp_address_hidden', $hidden, $this->post_id ); 69 } 70 71 public function address1() { return $this->address_hidden() ? '' : $this->meta( 'address1', 'street_number' ); } 72 public function address2() { return $this->address_hidden() ? '' : $this->meta( 'address2', 'street_name' ); } 52 73 public function address3() { return $this->meta( 'address3', 'property_city' ); } 53 74 public function address4() { return $this->meta( 'address4' ); } 54 public function unit() { return $this-> meta( 'unit' ); }75 public function unit() { return $this->address_hidden() ? '' : $this->meta( 'unit' ); } 55 76 public function postcode() { return $this->meta( 'postcode', 'zipcode' ); } 56 77 public function suburb() { return $this->meta( 'suburb', 'information_suburb' ); } … … 120 141 public function smokers_allowed() { return (bool) $this->meta( 'smokers_allowed', 'property_smokers_allowed' ); } 121 142 143 /** 144 * Pets policy as display text: "Yes", "No", or Palace's own wording such as 145 * "By consent". pets_allowed() stays a strict yes/no for existing code. 146 * 147 * @return string 148 */ 149 public function pets_label() { return $this->policy_label( 'pets_policy', $this->pets_allowed() ); } 150 151 /** 152 * Smoking policy as display text. 153 * 154 * @return string 155 */ 156 public function smokers_label() { return $this->policy_label( 'smokers_policy', $this->smokers_allowed() ); } 157 158 /** 159 * Turn a stored Palace policy into display text. 160 * 161 * @param string $policy_key Meta key, without the ipp_ prefix. 162 * @param bool $allowed The yes/no flag, used when no policy text exists. 163 * @return string 164 */ 165 private function policy_label( $policy_key, $allowed ) { 166 $policy = trim( (string) $this->meta( $policy_key ) ); 167 168 if ( '' === $policy ) { 169 // Imported before 3.0.0, or edited by hand: only the yes/no flag exists. 170 return $allowed ? __( 'Yes', 'integrate-palace-properties' ) : __( 'No', 'integrate-palace-properties' ); 171 } 172 173 switch ( strtolower( $policy ) ) { 174 case 'yes': 175 case 'true': 176 return __( 'Yes', 'integrate-palace-properties' ); 177 case 'no': 178 case 'false': 179 return __( 'No', 'integrate-palace-properties' ); 180 case 'by consent': 181 return __( 'By consent', 'integrate-palace-properties' ); 182 } 183 184 return $policy; 185 } 186 122 187 // ─── Links & Media ────────────────────────────────────────────── 123 188 124 189 public function virtual_tour_url() { return $this->meta( 'virtual_tour_url', 'property_virtual_tour_url' ); } 125 190 public function web_link_url() { return $this->meta( 'web_link_url' ); } 126 public function geographic_location() { return $this-> meta( 'geographic_location', 'property_geographic_location' ); }191 public function geographic_location() { return $this->address_hidden() ? '' : $this->meta( 'geographic_location', 'property_geographic_location' ); } 127 192 public function advert_text() { return $this->meta( 'advert_text' ); } 128 193 public function feature_details() { return $this->meta( 'feature_details' ); } … … 191 256 } 192 257 258 /** 259 * Whether to show a map. A listing whose address is hidden still gets one, 260 * centred on its suburb (map_embed_url() falls back to full_address(), which 261 * is suburb-only for these) rather than on its exact location. 262 * 263 * @return bool 264 */ 265 public function show_map() { 266 return $this->has_map_coords() || ( $this->address_hidden() && '' !== $this->full_address() ); 267 } 268 193 269 public function map_lat() { 194 270 $loc = $this->geographic_location(); … … 239 315 240 316 if ( $this->full_address() ) { 241 $schema['address'] = [ 317 // array_filter() drops the empty street address of a listing whose 318 // address is hidden, rather than publishing an empty field. 319 $schema['address'] = array_filter( [ 242 320 '@type' => 'PostalAddress', 243 321 'streetAddress' => trim( $this->address1() . ' ' . $this->address2() ), … … 245 323 'addressRegion' => $this->region(), 246 324 'postalCode' => $this->postcode(), 247 ] ;325 ] ); 248 326 } 249 327 … … 261 339 } 262 340 263 return '<script type="application/ld+json">' . wp_json_encode( $schema, JSON_UNESCAPED_SLASHES ) . '</script>'; 341 // JSON_HEX_TAG escapes < and > as < / >. Without it, a property 342 // field containing the literal text "</script>" would close this block 343 // early and anything after it would be parsed as markup. The values come 344 // from the Palace API, so they are not trustworthy input. JSON parsers 345 // and structured-data crawlers read the escaped form identically. 346 return '<script type="application/ld+json">' . wp_json_encode( $schema, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG ) . '</script>'; 264 347 } 265 348 } -
integrate-palace-properties/tags/3.0.0/includes/class-integratepalacep-settings.php
r3524333 r3694341 6 6 self::register_settings(); 7 7 8 // Always re-push the registration to the API after the configs form is saved, 9 // even when no field values changed. The Settings API normally fires 10 // update_option_X only on actual change, which is not enough — a plain 11 // re-save should reliably push the current site_url() to the API too. 12 add_action( 'admin_init', [ __CLASS__, 'maybe_force_resync_after_save' ], 100 ); 13 14 // Re-register the webhook URL when the site URL changes between page loads 15 // (typical after a staging → production migration that copies the WP DB). 16 self::maybe_reregister_webhook_url(); 17 18 // Handle the "Re-sync now" button on the configs page. 19 add_action( 'admin_post_ipp_resync_now', [ __CLASS__, 'handle_resync_now' ] ); 20 21 // Slug change still needs a CPT re-register on top of the API push. 8 // Saving credentials should make the site usable straight away rather 9 // than leaving the owner waiting for the next scheduled run. 10 add_action( 'admin_init', [ __CLASS__, 'maybe_sync_after_save' ], 100 ); 11 12 // Slug change needs a CPT re-register. 22 13 add_action( 'update_option_integrate_palace_properties_slug', [ __CLASS__, 'on_slug_changed' ], 10, 3 ); 23 14 } 24 15 25 16 /** 26 * Fires after WordPress's Settings API processes the configs form submission 27 * and redirects back with ?settings-updated=true. Triggers a forced re-push 28 * of registration data to the API regardless of whether values changed. 29 */ 30 public static function maybe_force_resync_after_save() { 31 if ( ! is_admin() ) return; 32 if ( empty( $_GET['page'] ) || $_GET['page'] !== 'integrate-palace-properties-configs' ) return; 33 if ( empty( $_GET['settings-updated'] ) || $_GET['settings-updated'] !== 'true' ) return; 34 if ( ! current_user_can( 'manage_options' ) ) return; 35 36 self::update_subscription(); 37 } 38 39 /** 40 * Manual "Re-sync now" action — pushes the current site URL/credentials to the API 41 * even when nothing was edited. Useful after a domain migration. 42 */ 43 public static function handle_resync_now() { 17 * Queue a sync run once the configs form has been saved. 18 * 19 * The Settings API redirects back with ?settings-updated=true, which is the 20 * only reliable signal that the form was submitted — update_option_X fires 21 * only when a value actually changed. 22 */ 23 public static function maybe_sync_after_save() { 24 if ( ! is_admin() ) { 25 return; 26 } 44 27 if ( ! current_user_can( 'manage_options' ) ) { 45 wp_die( __( 'Insufficient permissions.', 'integrate-palace-properties' ) ); 46 } 47 check_admin_referer( 'ipp_resync_now' ); 48 49 self::update_subscription(); 50 51 wp_safe_redirect( add_query_arg( 52 [ 'page' => 'integrate-palace-properties-configs', 'settings-updated' => 'true' ], 53 admin_url( 'admin.php' ) 54 ) ); 55 exit; 28 return; 29 } 30 31 // Read-only checks on a redirect WordPress itself produced; nothing is 32 // written from these values, so no nonce is involved. 33 // phpcs:disable WordPress.Security.NonceVerification.Recommended 34 $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; 35 $updated = isset( $_GET['settings-updated'] ) ? sanitize_key( wp_unslash( $_GET['settings-updated'] ) ) : ''; 36 // phpcs:enable WordPress.Security.NonceVerification.Recommended 37 38 if ( 'integrate-palace-properties-configs' !== $page || 'true' !== $updated ) { 39 return; 40 } 41 42 if ( ! IPP_Sync::has_credentials() ) { 43 return; 44 } 45 46 IPP_Sync::schedule(); 47 48 // Run out of band so saving settings never blocks on a slow API call. 49 if ( ! IPP_Sync::is_running() ) { 50 // Distinct args, or WordPress treats it as a duplicate of the recurring 51 // event that schedule() has just created and silently drops it. 52 wp_schedule_single_event( time() + 5, IPP_Sync::CRON_HOOK, array( false ) ); 53 } 56 54 } 57 55 … … 63 61 } 64 62 65 /**66 * Re-register the webhook URL with the API if the site URL has changed67 * (e.g. after migrating from staging to production).68 */69 private static function maybe_reregister_webhook_url() {70 $stored_webhook_url = get_option( 'integrate_palace_properties_webhook_url', '' );71 if ( empty( $stored_webhook_url ) ) {72 return;73 }74 75 $last_site_url = get_option( 'ipp_registered_site_url', '' );76 $current_site_url = site_url();77 78 if ( empty( $last_site_url ) || $last_site_url !== $current_site_url ) {79 self::update_subscription();80 }81 }82 83 63 public static function register_settings() { 84 64 register_setting('integrate_palace_properties_configs', 'integrate_palace_properties_username', ['sanitize_callback' => 'sanitize_text_field']); 85 register_setting('integrate_palace_properties_configs', 'integrate_palace_properties_password', ['sanitize_callback' => 'sanitize_text_field']); 86 register_setting('integrate_palace_properties_configs', 'integrate_palace_properties_subscription_key', ['sanitize_callback' => 'sanitize_text_field']); 65 register_setting('integrate_palace_properties_configs', 'integrate_palace_properties_password', ['sanitize_callback' => [__CLASS__, 'sanitize_password']]); 87 66 register_setting('integrate_palace_properties_configs', 'integrate_palace_properties_slug', ['sanitize_callback' => 'sanitize_text_field']); 67 register_setting('integrate_palace_properties_configs', 'ipp_sync_interval', [ 68 'type' => 'string', 69 'sanitize_callback' => [__CLASS__, 'sanitize_sync_interval'], 70 'default' => 'hourly', 71 ]); 88 72 89 73 add_settings_section( … … 111 95 112 96 add_settings_field( 113 'integrate_palace_properties_subscription_key',114 __('Subscription Key', 'integrate-palace-properties'),115 [__CLASS__, 'render_subscription_key_field'],116 'integrate_palace_properties_configs',117 'integrate_palace_properties_settings_section'118 );119 120 add_settings_field(121 97 'integrate_palace_properties_slug', 122 98 __('Property Slug', 'integrate-palace-properties'), … … 127 103 128 104 add_settings_field( 129 'i ntegrate_palace_properties_webhook_status',130 __('S TATUS', 'integrate-palace-properties'),131 [__CLASS__, 'render_ webhook_status_field'],105 'ipp_sync_interval', 106 __('Sync Frequency', 'integrate-palace-properties'), 107 [__CLASS__, 'render_sync_interval_field'], 132 108 'integrate_palace_properties_configs', 133 109 'integrate_palace_properties_settings_section' … … 135 111 136 112 add_settings_field( 137 'ipp_ domain_status',138 __( 'Site Domain Status', 'integrate-palace-properties'),139 [ __CLASS__, 'render_domain_status_field'],113 'ipp_sync_status', 114 __('Sync Status', 'integrate-palace-properties'), 115 [__CLASS__, 'render_sync_status_field'], 140 116 'integrate_palace_properties_configs', 141 117 'integrate_palace_properties_settings_section' … … 178 154 'default' => self::get_default_display_fields(), 179 155 ]); 180 register_setting('integrate_palace_properties_configs', 'ipp_sync_archived', [181 'type' => 'string',182 'sanitize_callback' => 'sanitize_text_field',183 'default' => 'no',184 ]);185 register_setting('integrate_palace_properties_configs', 'ipp_sync_statuses', [186 'type' => 'array',187 'sanitize_callback' => [__CLASS__, 'sanitize_sync_statuses'],188 'default' => ['Active'],189 ]);190 156 191 157 add_settings_section( … … 200 166 __('Property Details to Display', 'integrate-palace-properties'), 201 167 [__CLASS__, 'render_display_fields'], 202 'integrate_palace_properties_configs',203 'ipp_display_config_section'204 );205 206 add_settings_field(207 'ipp_sync_archived',208 __('Include Archived Properties', 'integrate-palace-properties'),209 [__CLASS__, 'render_sync_archived_field'],210 'integrate_palace_properties_configs',211 'ipp_display_config_section'212 );213 214 add_settings_field(215 'ipp_sync_statuses',216 __('Property Statuses to Sync', 'integrate-palace-properties'),217 [__CLASS__, 'render_sync_statuses_field'],218 168 'integrate_palace_properties_configs', 219 169 'ipp_display_config_section' … … 294 244 } 295 245 296 public static function sanitize_sync_statuses( $input ) {297 if ( ! is_array( $input ) ) return array( 'Active' );298 return array_map( 'sanitize_text_field', $input );299 }300 301 246 public static function render_display_section_description() { 302 echo '<p>' . esc_html__( 'Control which property details are displayed on your website and how properties are synced from Palace.', 'integrate-palace-properties' ) . '</p>';247 echo '<p>' . esc_html__( 'Control which property details are displayed on your website.', 'integrate-palace-properties' ) . '</p>'; 303 248 } 304 249 … … 312 257 echo '<legend style="font-weight:600; padding:0 6px;">' . esc_html( $group_label ) . '</legend>'; 313 258 foreach ( $fields as $key => $label ) { 314 $checked = in_array( $key, $saved, true ) ? 'checked' : '';315 259 echo '<label style="display:block; margin-bottom:6px; cursor:pointer;">'; 316 echo '<input type="checkbox" name="ipp_display_fields[]" value="' . esc_attr( $key ) . '" ' . $checked. ' /> ';260 echo '<input type="checkbox" name="ipp_display_fields[]" value="' . esc_attr( $key ) . '" ' . checked( in_array( $key, $saved, true ), true, false ) . ' /> '; 317 261 echo esc_html( $label ); 318 262 echo '</label>'; … … 324 268 } 325 269 326 public static function render_sync_archived_field() {327 $value = get_option( 'ipp_sync_archived', 'no' );328 echo '<label>';329 echo '<input type="checkbox" name="ipp_sync_archived" value="yes" ' . checked( $value, 'yes', false ) . ' /> ';330 echo esc_html__( 'Also sync archived/inactive properties from Palace', 'integrate-palace-properties' );331 echo '</label>';332 echo '<p class="description">' . esc_html__( 'When enabled, both current and archived properties will be imported. Archived properties will be marked with the "Inactive" status taxonomy.', 'integrate-palace-properties' ) . '</p>';333 }334 335 public static function render_sync_statuses_field() {336 $saved = get_option( 'ipp_sync_statuses', array( 'Active' ) );337 $statuses = array( 'Active', 'Inactive' );338 foreach ( $statuses as $status ) {339 $checked = in_array( $status, $saved, true ) ? 'checked' : '';340 echo '<label style="display:inline-block; margin-right:16px;">';341 echo '<input type="checkbox" name="ipp_sync_statuses[]" value="' . esc_attr( $status ) . '" ' . $checked . ' /> ';342 echo esc_html( $status );343 echo '</label>';344 }345 echo '<p class="description">' . esc_html__( 'Choose which property statuses to sync from Palace API.', 'integrate-palace-properties' ) . '</p>';346 }347 348 270 public static function render_username_field() { 349 271 $value = get_option('integrate_palace_properties_username', ''); … … 351 273 } 352 274 275 /** 276 * Password field. 277 * 278 * The stored password is never rendered back into the page. An empty 279 * submission leaves the saved value untouched (see keep_existing_password), 280 * so the field can stay blank once credentials are set. 281 */ 353 282 public static function render_password_field() { 354 $value = get_option('integrate_palace_properties_password', ''); 355 echo '<input type="password" name="integrate_palace_properties_password" value="' . esc_attr($value) . '" class="ipp-full-width" />'; 356 } 357 358 public static function render_subscription_key_field() { 359 $value = get_option('integrate_palace_properties_subscription_key', ''); 360 echo '<input type="password" name="integrate_palace_properties_subscription_key" value="' . esc_attr($value) . '" class="ipp-full-width" />'; 283 $has_password = '' !== trim( (string) get_option( 'integrate_palace_properties_password', '' ) ); 284 285 echo '<input type="password" name="integrate_palace_properties_password" value="" autocomplete="new-password" class="ipp-full-width" placeholder="'; 286 echo esc_attr( 287 $has_password 288 ? __( 'Saved — leave blank to keep it', 'integrate-palace-properties' ) 289 : __( 'Enter your Palace API password', 'integrate-palace-properties' ) 290 ); 291 echo '" />'; 292 293 if ( $has_password ) { 294 echo '<p class="description">' . esc_html__( 'A password is saved. Type a new one only if you want to replace it.', 'integrate-palace-properties' ) . '</p>'; 295 } 296 } 297 298 /** 299 * Keep the stored password when the field is submitted empty. 300 * 301 * Registered as the sanitize callback, so an untouched form does not wipe 302 * working credentials. 303 * 304 * @param string $value Submitted value. 305 * @return string 306 */ 307 public static function sanitize_password( $value ) { 308 $value = is_string( $value ) ? trim( $value ) : ''; 309 310 if ( '' === $value ) { 311 return (string) get_option( 'integrate_palace_properties_password', '' ); 312 } 313 314 return sanitize_text_field( $value ); 361 315 } 362 316 … … 366 320 } 367 321 368 public static function render_webhook_status_field() { 369 $value = get_option('integrate_palace_properties_webhook_status', ''); 370 echo '<label>' . wp_kses_post($value) . '</label>'; 371 } 372 373 /** 374 * Compares the host this WordPress install reports vs. the host the API 375 * was last told to deliver webhooks to. Mismatch = the API is pointing at 376 * a stale domain and webhooks won't arrive. 377 */ 378 public static function render_domain_status_field() { 379 $registered_url = get_option( 'integrate_palace_properties_webhook_url', '' ); 380 $current_host = parse_url( site_url(), PHP_URL_HOST ); 381 $registered_host = $registered_url ? parse_url( $registered_url, PHP_URL_HOST ) : ''; 382 383 $resync_url = wp_nonce_url( 384 admin_url( 'admin-post.php?action=ipp_resync_now' ), 385 'ipp_resync_now' 386 ); 387 388 echo '<div style="display:flex; flex-direction:column; gap:6px;">'; 389 390 if ( empty( $registered_url ) ) { 391 echo '<span style="display:inline-block; padding:4px 10px; background:#f0f0f1; color:#646970; border-radius:3px; font-size:12px;">'; 392 echo esc_html__( 'Not registered — save settings to register this site with the API.', 'integrate-palace-properties' ); 322 /** 323 * Restrict the sync interval to a schedule the plugin actually registers. 324 * 325 * @param string $value Submitted value. 326 * @return string 327 */ 328 public static function sanitize_sync_interval( $value ) { 329 $allowed = [ 'ipp_fifteen_minutes', 'hourly', 'ipp_two_hours', 'twicedaily', 'daily' ]; 330 $value = sanitize_text_field( $value ); 331 332 return in_array( $value, $allowed, true ) ? $value : 'hourly'; 333 } 334 335 /** 336 * How often the site should poll Palace for changes. 337 */ 338 public static function render_sync_interval_field() { 339 $current = IPP_Sync::get_interval(); 340 $options = [ 341 'ipp_fifteen_minutes' => __( 'Every 15 minutes', 'integrate-palace-properties' ), 342 'hourly' => __( 'Hourly (recommended)', 'integrate-palace-properties' ), 343 'ipp_two_hours' => __( 'Every 2 hours', 'integrate-palace-properties' ), 344 'twicedaily' => __( 'Twice daily', 'integrate-palace-properties' ), 345 'daily' => __( 'Once daily', 'integrate-palace-properties' ), 346 ]; 347 348 echo '<select name="ipp_sync_interval">'; 349 foreach ( $options as $value => $label ) { 350 echo '<option value="' . esc_attr( $value ) . '" ' . selected( $current, $value, false ) . '>'; 351 echo esc_html( $label ); 352 echo '</option>'; 353 } 354 echo '</select>'; 355 echo '<p class="description">' . esc_html__( 'How often this site checks Palace for new, changed and removed properties.', 'integrate-palace-properties' ) . '</p>'; 356 } 357 358 /** 359 * Report the outcome of the most recent scheduled run. 360 */ 361 public static function render_sync_status_field() { 362 if ( ! IPP_Sync::has_credentials() ) { 363 echo '<span class="ipp-status-pill ipp-status-idle">'; 364 echo esc_html__( 'Enter your Palace API username and password to begin syncing.', 'integrate-palace-properties' ); 393 365 echo '</span>'; 394 } elseif ( $registered_host && strcasecmp( $registered_host, $current_host ) === 0 ) { 395 echo '<span style="display:inline-block; padding:4px 10px; background:#d1e7dd; color:#0f5132; border-radius:3px; font-size:12px;">'; 396 echo '✓ ' . esc_html__( 'Domain in sync with API', 'integrate-palace-properties' ); 366 return; 367 } 368 369 if ( IPP_Sync::is_running() ) { 370 $progress = IPP_Sync::get_progress(); 371 echo '<span class="ipp-status-pill ipp-status-running">'; 372 echo esc_html( 373 sprintf( 374 /* translators: 1: batches completed, 2: total batches. */ 375 __( 'Sync in progress — batch %1$d of %2$d.', 'integrate-palace-properties' ), 376 (int) $progress['done'], 377 (int) $progress['total'] 378 ) 379 ); 397 380 echo '</span>'; 398 echo '<span style="font-size:11px; color:#646970;">'; 399 echo esc_html( sprintf( __( 'API is delivering webhooks to: %s', 'integrate-palace-properties' ), $registered_host ) ); 381 return; 382 } 383 384 $unfinished = IPP_Sync::get_unfinished_attempt(); 385 386 if ( $unfinished ) { 387 echo '<span class="ipp-status-pill ipp-status-error">'; 388 echo esc_html__( 'The last sync did not finish', 'integrate-palace-properties' ); 400 389 echo '</span>'; 401 } else { 402 echo '<span style="display:inline-block; padding:4px 10px; background:#f8d7da; color:#842029; border-radius:3px; font-size:12px;">'; 403 echo '⚠ ' . esc_html__( 'Domain mismatch — webhooks will not arrive', 'integrate-palace-properties' ); 390 echo '<p class="description">'; 391 echo esc_html( 392 sprintf( 393 /* translators: %s: human-readable time since the sync started, e.g. "2 hours". */ 394 __( 'A sync started %s ago but never recorded a result. This usually means your host stopped the request while it was fetching properties from Palace. Try Sync Now. If it keeps happening, ask your host to raise the PHP request timeout, or to run WordPress cron from a server cron job.', 'integrate-palace-properties' ), 395 human_time_diff( $unfinished, time() ) 396 ) 397 ); 398 echo '</p>'; 399 return; 400 } 401 402 $last = IPP_Sync::get_last_run(); 403 404 if ( empty( $last ) ) { 405 echo '<span class="ipp-status-pill ipp-status-idle">'; 406 echo esc_html__( 'No sync has run yet.', 'integrate-palace-properties' ); 404 407 echo '</span>'; 405 echo '<span style="font-size:11px; color:#646970;">'; 406 echo esc_html( sprintf( 407 __( 'This site: %1$s — API has registered: %2$s', 'integrate-palace-properties' ), 408 $current_host, 409 $registered_host ?: 'unknown' 410 ) ); 408 return; 409 } 410 411 $time = isset( $last['time'] ) ? $last['time'] : ''; 412 413 if ( isset( $last['status'] ) && 'failed' === $last['status'] ) { 414 echo '<span class="ipp-status-pill ipp-status-error">'; 415 echo esc_html__( 'Last sync failed', 'integrate-palace-properties' ); 411 416 echo '</span>'; 412 echo '<a href="' . esc_url( $resync_url ) . '" class="button" style="width:fit-content; margin-top:4px;">'; 413 echo esc_html__( 'Re-sync this site with API', 'integrate-palace-properties' ); 414 echo '</a>'; 415 } 416 417 echo '</div>'; 417 if ( ! empty( $last['message'] ) ) { 418 echo '<p class="description">' . esc_html( $last['message'] ) . '</p>'; 419 } 420 return; 421 } 422 423 if ( isset( $last['status'] ) && 'warning' === $last['status'] ) { 424 echo '<span class="ipp-status-pill ipp-status-warn">'; 425 echo esc_html__( 'Last sync completed with a warning', 'integrate-palace-properties' ); 426 echo '</span>'; 427 if ( ! empty( $last['message'] ) ) { 428 echo '<p class="description">' . esc_html( $last['message'] ) . '</p>'; 429 } 430 return; 431 } 432 433 echo '<span class="ipp-status-pill ipp-status-ok">'; 434 echo esc_html__( 'Last sync successful', 'integrate-palace-properties' ); 435 echo '</span>'; 436 echo '<p class="description">'; 437 echo esc_html( 438 sprintf( 439 /* translators: 1: date and time, 2: number of properties updated, 3: number removed. */ 440 __( '%1$s — %2$d updated, %3$d removed.', 'integrate-palace-properties' ), 441 $time, 442 isset( $last['imported'] ) ? (int) $last['imported'] : 0, 443 isset( $last['deleted'] ) ? (int) $last['deleted'] : 0 444 ) 445 ); 446 echo '</p>'; 447 448 $next = wp_next_scheduled( IPP_Sync::CRON_HOOK ); 449 if ( $next ) { 450 echo '<p class="description">'; 451 echo esc_html( 452 sprintf( 453 /* translators: %s: human-readable time difference, e.g. "42 mins". */ 454 __( 'Next check in %s.', 'integrate-palace-properties' ), 455 human_time_diff( time(), $next ) 456 ) 457 ); 458 echo '</p>'; 459 } 418 460 } 419 461 … … 458 500 } 459 501 460 /**461 * Push current credentials, blog ID, and webhook URL to the API. Self-heals462 * any missing local options (blog UUID, webhook secret) so a freshly migrated463 * or cloned WP install becomes fully functional after one save.464 */465 public static function update_subscription() {466 $username = get_option( 'integrate_palace_properties_username', '' );467 $password = get_option( 'integrate_palace_properties_password', '' );468 $subscription_key = get_option( 'integrate_palace_properties_subscription_key', '' );469 470 // Self-heal: ensure the unique blog ID exists. Generated on activation,471 // but a partial DB clone or option deletion could leave it missing.472 $blog_id = get_option( 'integrate_palace-palace-unique-id' );473 if ( empty( $blog_id ) ) {474 $blog_id = wp_generate_uuid4();475 update_option( 'integrate_palace-palace-unique-id', $blog_id );476 }477 478 $webhook_url = esc_url_raw( rest_url( 'integrate-palace-properties/v1/webhook' ) );479 480 $api_base = defined( 'IPP_API_URL' ) ? IPP_API_URL : 'https://wp-palace.kiwibrain.co.nz';481 $response = wp_remote_post( $api_base . '/api/update-user', [482 'timeout' => 15,483 'body' => wp_json_encode( [484 'palace_api_key' => base64_encode( sanitize_text_field( $username ) . ':' . sanitize_text_field( $password ) ),485 'wp_palace_blog_id' => $blog_id,486 'webhook_url' => $webhook_url,487 'subscription_key' => sanitize_text_field( $subscription_key ),488 ] ),489 'headers' => [490 'Content-Type' => 'application/json',491 ],492 ] );493 494 if ( is_wp_error( $response ) ) {495 error_log( '[IPP] Failed to reach API: ' . $response->get_error_message() );496 update_option(497 'integrate_palace_properties_webhook_status',498 "<span class='wh_error'><i>" . esc_html__( 'Could not reach the API. Check network/DNS.', 'integrate-palace-properties' ) . '</i></span>'499 );500 return;501 }502 503 $status_code = wp_remote_retrieve_response_code( $response );504 $body = wp_remote_retrieve_body( $response );505 $data = json_decode( $body, true );506 507 if ( $status_code >= 200 && $status_code < 300 && isset( $data['subscription']['webhook_url'] ) ) {508 $subscription_name = sanitize_text_field( $data['subscription']['name'] ?? '' );509 $properties_allowed = isset( $data['subscription']['properties_allowed'] ) ? sanitize_text_field( $data['subscription']['properties_allowed'] ) : '';510 $properties_allowed = ( $properties_allowed == '-1' ) ? 'unlimited' : $properties_allowed;511 512 update_option( 'integrate_palace_properties_webhook_url', esc_url_raw( $data['subscription']['webhook_url'] ) );513 update_option( 'integrate_palace_properties_webhook_status', "<span class='wh_connected'><i>Connected ($subscription_name) Max Properties: " . esc_html( $properties_allowed ) . '</i></span>' );514 update_option( 'ipp_registered_site_url', site_url() );515 516 // Mirror the canonical subscription key from the API response into517 // the webhook secret option so verify_webhook_signature has the same518 // HMAC secret the API signs with. Self-heals the "Webhook Auth: Open"519 // case where this option was never set on first registration.520 if ( ! empty( $data['subscription']['subscription_key'] ) ) {521 update_option( 'integrate_palace_webhook_secret', sanitize_text_field( $data['subscription']['subscription_key'] ) );522 }523 524 return;525 }526 527 $error_message = isset( $data['message'] ) && is_string( $data['message'] )528 ? $data['message']529 : 'Invalid Subscription Key';530 531 update_option(532 'integrate_palace_properties_webhook_status',533 "<span class='wh_error'><i>" . esc_html( $error_message ) . '</i></span>'534 );535 error_log( "[IPP] API rejected registration ($status_code): $error_message" );536 }537 502 } 538 503 ?> -
integrate-palace-properties/tags/3.0.0/includes/class-integratepalacep-webhooks.php
r3486430 r3694341 1 1 <?php 2 2 if ( ! defined( 'ABSPATH' ) ) exit; 3 4 /** 5 * Property import. 6 * 7 * Historically this class exposed a REST route that an external relay pushed 8 * properties to. That route has been removed: properties are now pulled 9 * directly from the Palace API by IPP_Sync, so there is no longer any reason 10 * to accept inbound writes, and an endpoint that creates and deletes posts is 11 * not worth keeping open for a sender that no longer exists. 12 * 13 * The class name is retained because save_property() and 14 * delete_property_by_code() are the plugin's import API and may be called by 15 * site-specific code. 16 */ 3 17 class IntegratePalace_Properties_Webhooks { 4 18 19 /** 20 * Clean up state left behind by the retired webhook route. 21 * 22 * @return void 23 */ 5 24 public static function init() { 6 add_action('rest_api_init', array(__CLASS__, 'register_routes')); 7 } 8 9 public static function register_routes() { 10 $blog_id = get_option("integrate_palace-palace-unique-id"); 11 $webhook_url = "/webhook/$blog_id"; 12 register_rest_route('integrate-palace-properties/v1', $webhook_url, array( 13 'methods' => 'POST', 14 'callback' => array(__CLASS__, 'handle_webhook'), 15 'permission_callback' => array(__CLASS__, 'verify_webhook_signature'), 16 )); 17 } 18 19 /** 20 * Verify HMAC signature on incoming webhook requests. 21 */ 22 public static function verify_webhook_signature( WP_REST_Request $request ) { 23 $secret = get_option( 'integrate_palace_webhook_secret', '' ); 24 25 // No secret configured — allow all requests for backwards compatibility 26 if ( empty( $secret ) ) { 27 return true; 28 } 29 30 $signature = $request->get_header('X-Palace-Signature'); 31 if ( empty( $signature ) ) { 32 return new \WP_Error( 33 'rest_forbidden', 34 __( 'Missing webhook signature.', 'integrate-palace-properties' ), 35 array( 'status' => 403 ) 36 ); 37 } 38 39 $body = $request->get_body(); 40 $expected = hash_hmac( 'sha256', $body, $secret ); 41 42 if ( ! hash_equals( $expected, $signature ) ) { 43 return new \WP_Error( 44 'rest_forbidden', 45 __( 'Invalid webhook signature.', 'integrate-palace-properties' ), 46 array( 'status' => 403 ) 47 ); 48 } 49 50 return true; 25 // Clean up a property's images only when the post is really destroyed, 26 // not when it is trashed, so a trashed listing can still be restored. 27 add_action( 'before_delete_post', array( __CLASS__, 'delete_property_attachments' ) ); 28 29 // Once a property is restored, by a re-listing or by hand, it is no longer 30 // "trashed by the sync". 31 add_action( 'untrashed_post', array( __CLASS__, 'clear_sync_trash_flag' ) ); 32 33 // The HMAC secret and blog UUID only existed to authenticate the relay. 34 if ( get_option( 'integrate_palace_webhook_secret', false ) !== false ) { 35 delete_option( 'integrate_palace_webhook_secret' ); 36 } 37 if ( get_option( 'integrate_palace_properties_webhook_url', false ) !== false ) { 38 delete_option( 'integrate_palace_properties_webhook_url' ); 39 } 40 if ( get_option( 'integrate_palace_properties_webhook_status', false ) !== false ) { 41 delete_option( 'integrate_palace_properties_webhook_status' ); 42 } 43 if ( get_option( 'ipp_registered_site_url', false ) !== false ) { 44 delete_option( 'ipp_registered_site_url' ); 45 } 51 46 } 52 47 … … 65 60 } 66 61 62 /** 63 * Forget that a sync trashed this post, once it has been restored. 64 * 65 * @param int $post_id Restored post. 66 * @return void 67 */ 68 public static function clear_sync_trash_flag( $post_id ) { 69 delete_post_meta( $post_id, 'ipp_trashed_by_sync' ); 70 } 71 72 /** 73 * Delete a property's gallery images when the property itself is 74 * permanently deleted. 75 * 76 * @param int $post_id Post being deleted. 77 * @return void 78 */ 79 public static function delete_property_attachments( $post_id ) { 80 if ( 'palace-properties' !== get_post_type( $post_id ) ) { 81 return; 82 } 83 84 $gallery_images = get_post_meta( $post_id, 'integrate_palace_gallery', true ); 85 86 if ( ! empty( $gallery_images ) && is_array( $gallery_images ) ) { 87 foreach ( $gallery_images as $image_id ) { 88 wp_delete_attachment( intval( $image_id ), true ); 89 } 90 } 91 92 $thumbnail_id = get_post_thumbnail_id( $post_id ); 93 if ( $thumbnail_id ) { 94 wp_delete_attachment( (int) $thumbnail_id, true ); 95 } 96 } 97 67 98 private static function get_property_id_by_code($property_code) { 68 99 $cache_key = 'property_id_' . $property_code; … … 70 101 71 102 if ($post_id === false) { 103 // 'any' deliberately excludes trashed posts, so a property that was 104 // removed and later re-listed by Palace would not be found here and 105 // a duplicate post would be created. List the statuses explicitly. 72 106 $args = [ 73 107 'post_type' => 'palace-properties', … … 76 110 'fields' => 'ids', 77 111 'posts_per_page' => 1, 78 'post_status' => 'any',112 'post_status' => array( 'publish', 'draft', 'pending', 'private', 'future', 'trash' ), 79 113 ]; 80 114 … … 96 130 } 97 131 98 private static function delete_property($property_code) { 99 $property_code = sanitize_text_field($property_code); 100 if (!$property_code) { 101 return new WP_REST_Response(['status' => 'error', 'message' => 'Property code does not exist'], 404); 102 } 103 104 $post_id = self::get_property_id_by_code($property_code); 105 106 if ($post_id) { 107 /** @hook ipp_before_property_delete — Fires before a property is deleted via webhook. */ 108 do_action( 'ipp_before_property_delete', $post_id, $property_code ); 109 } 110 111 if ($post_id && wp_delete_post($post_id, false)) { 112 $gallery_images = get_post_meta($post_id, 'integrate_palace_gallery', true); 113 if (!empty($gallery_images) && is_array($gallery_images)) { 114 foreach ($gallery_images as $image_id) { 115 wp_delete_attachment(intval($image_id), true); 116 } 117 } 118 delete_post_thumbnail($post_id); 119 wp_cache_delete('property_id_' . $property_code, 'property_cache'); 120 121 /** @hook ipp_after_property_delete — Fires after a property is deleted via webhook. */ 122 do_action( 'ipp_after_property_delete', $post_id, $property_code ); 123 124 // Update last sync time 125 update_option( 'ipp_last_sync_time', current_time( 'mysql' ), false ); 126 127 return new WP_REST_Response(['status' => 'success', 'message' => 'Property deleted successfully'], 200); 128 } 129 130 return new WP_REST_Response( 131 ['status' => 'error', 'message' => $post_id ? 'Failed to delete property' : 'Property not found'], 132 $post_id ? 500 : 404 133 ); 132 /** 133 * Remove a property and its media. 134 * 135 * Shared by the scheduled sync and the legacy webhook route. 136 * 137 * @param string $property_code Palace property code. 138 * @return bool True when a property was removed, false when there was 139 * nothing to remove or the removal failed. 140 */ 141 public static function delete_property_by_code( $property_code ) { 142 $property_code = sanitize_text_field( $property_code ); 143 144 if ( ! $property_code ) { 145 return false; 146 } 147 148 $post_id = self::get_property_id_by_code( $property_code ); 149 150 if ( ! $post_id ) { 151 return false; 152 } 153 154 // A locked property stays on the site even after Palace drops it. 155 if ( '1' === get_post_meta( $post_id, 'ipp_lock_updates', true ) ) { 156 return false; 157 } 158 159 /** @hook ipp_before_property_delete — Fires before a property is deleted. */ 160 do_action( 'ipp_before_property_delete', $post_id, $property_code ); 161 162 // Trash, don't destroy. wp_delete_post( $id, false ) only trashes the 163 // core 'post' and 'page' types; for a custom post type like this one it 164 // deletes permanently and takes the images with it. Trashing keeps the 165 // listing and its photos restorable. delete_property_attachments() 166 // removes the images once the trash is emptied, which WordPress does 167 // automatically after EMPTY_TRASH_DAYS. On a site with the trash 168 // disabled, wp_trash_post() falls back to a permanent delete. 169 update_post_meta( $post_id, 'ipp_trashed_by_sync', '1' ); 170 171 if ( ! wp_trash_post( $post_id ) ) { 172 delete_post_meta( $post_id, 'ipp_trashed_by_sync' ); 173 return false; 174 } 175 176 wp_cache_delete( 'property_id_' . $property_code, 'property_cache' ); 177 178 /** @hook ipp_after_property_delete — Fires after a property is deleted. */ 179 do_action( 'ipp_after_property_delete', $post_id, $property_code ); 180 181 update_option( 'ipp_last_sync_time', current_time( 'mysql' ), false ); 182 183 return true; 134 184 } 135 185 136 public static function handle_webhook(WP_REST_Request $request) { 137 $property = $request->get_json_params(); 138 139 // Handle delete action 140 if (!empty($property['PropertyCode']) && isset($property['action']) && $property['action'] === 'delete') { 141 return self::delete_property($property['PropertyCode']); 142 } 143 144 if (!isset($property['PropertyCode'])) { 145 return new WP_REST_Response(array('status' => 'error', 'message' => 'Missing required fields'), 400); 146 } 147 186 187 /** 188 * Write a single Palace property record into WordPress. 189 * 190 * Accepts a property exactly as the Palace API returns it and maps every 191 * field onto the custom post type, its meta and its taxonomies. This is the 192 * plugin's single import path. 193 * 194 * @param array $property Property record from the Palace API. 195 * @param bool $force Re-import even when the change code is unchanged. 196 * @param bool $refresh_images Queue an image fetch. When false, properties that 197 * already have photos keep them without a fetch. 198 * @return int|WP_Error Post ID on success, WP_Error on failure. 199 */ 200 public static function save_property( $property, $force = false, $refresh_images = true ) { 201 if ( ! is_array( $property ) || empty( $property['PropertyCode'] ) ) { 202 return new WP_Error( 203 'ipp_invalid_property', 204 __( 'The property record was empty or had no property code.', 'integrate-palace-properties' ) 205 ); 206 } 207 208 /** @hook before_insert_palace_property — Filter the raw property before import. */ 148 209 $property = apply_filters('before_insert_palace_property', $property); 210 211 /** @hook show_on_website_palace_property — Return false to remove the property instead of importing it. */ 149 212 $show_on_website = apply_filters('show_on_website_palace_property', true, $property); 150 213 if (!$show_on_website) { 151 return self::delete_property($property['PropertyCode']); 214 self::delete_property_by_code($property['PropertyCode']); 215 return 0; 152 216 } 153 217 … … 157 221 wp_cache_delete('property_id_' . $property_code, 'property_cache'); 158 222 159 // Check if property is locked (prevent webhook from overwriting)223 // Respect the per-property lock set in the editor. 160 224 $existing_id = self::get_property_id_by_code($property_code); 161 225 if ( $existing_id && get_post_meta( $existing_id, 'ipp_lock_updates', true ) === '1' ) { 162 return new WP_REST_Response( array( 'status' => 'success', 'message' => 'Property is locked, skipping update' ), 200 ); 163 } 226 return (int) $existing_id; 227 } 228 229 if ( $existing_id && 'trash' === get_post_status( $existing_id ) ) { 230 if ( '1' !== get_post_meta( $existing_id, 'ipp_trashed_by_sync', true ) ) { 231 // Someone put this listing in the trash on purpose. Respect that 232 // rather than resurrecting it on every sync; restoring it from the 233 // trash brings it back. 234 return 0; 235 } 236 237 // Removed by an earlier sync and now re-listed by Palace: restore the 238 // original post, images and all, instead of creating a duplicate. 239 wp_untrash_post( $existing_id ); 240 241 // wp_untrash_post() restores to draft on WP 5.6+, and the post still 242 // carries its old change code. If nothing changed in Palace while the 243 // property was off the market, the change-code check below would call 244 // it "already up to date" and return before publishing it, leaving 245 // the listing invisible. A restore always gets a full update. 246 $force = true; 247 } 248 249 // Palace: "Should the Property Address be published online". Only an explicit 250 // "No" hides it, so feeds that omit the flag behave as before. 251 $address_hidden = ( 'no' === strtolower( trim( (string) self::arr_get($property, 'PropertyFeatures.PropertyPublishAddress') ) ) ); 164 252 165 253 // Build post title 166 254 $header = self::arr_get($property, 'PropertyFeatures.PropertyHeader'); 167 $post_title = !empty($header) 168 ? sanitize_text_field($header) 169 : sanitize_text_field( 255 if ( ! empty( $header ) ) { 256 $post_title = sanitize_text_field( $header ); 257 } elseif ( $address_hidden ) { 258 // No headline, and the street address must not be published: never 259 // build the title from it. Use the property type and suburb instead. 260 $type = sanitize_text_field( self::arr_get($property, 'PropertyFeatures.PropertyClass') ); 261 $type = '' !== $type ? $type : __( 'Property', 'integrate-palace-properties' ); 262 $locality = sanitize_text_field( self::arr_get($property, 'PropertyAddress3') ); 263 $post_title = '' !== $locality 264 /* translators: 1: property type such as "House", 2: suburb or town. */ 265 ? sprintf( __( '%1$s in %2$s', 'integrate-palace-properties' ), $type, $locality ) 266 : $type; 267 } else { 268 $post_title = sanitize_text_field( 170 269 self::arr_get($property, 'PropertyAddress3') . ', ' . 171 270 self::arr_get($property, 'PropertyAddress1') . ' ' . 172 271 self::arr_get($property, 'PropertyAddress2') 173 272 ); 273 } 174 274 $post_content = sanitize_textarea_field(self::arr_get($property, 'PropertyFeatures.PropertyAdvertText')); 175 275 … … 178 278 179 279 // Idempotency check 180 if (!empty($post_id) ) {280 if (!empty($post_id) && !$force) { 181 281 $stored_change_code = get_post_meta($post_id, 'ipp_change_code', true); 182 282 // Also check legacy key … … 186 286 $incoming_change_code = self::arr_get($property, 'PropertyChangeCode'); 187 287 if (!empty($stored_change_code) && $stored_change_code == $incoming_change_code) { 188 return new WP_REST_Response(array('status' => 'success', 'message' => 'Already up to date'), 200);189 } 190 } 191 192 /** @hook ipp_before_property_save — Fires before a property is saved/updated via webhook. */288 return (int) $post_id; 289 } 290 } 291 292 /** @hook ipp_before_property_save — Fires before a property is saved/updated. */ 193 293 do_action( 'ipp_before_property_save', $post_id ?: 0, $property ); 294 295 // Palace: "Should the Property entry be published online". A listing Palace 296 // says not to publish is kept as a draft: out of public view, but still 297 // synced, so it goes live automatically once the agency publishes it. 298 $publish_entry = strtolower( trim( (string) self::arr_get($property, 'PropertyFeatures.PropertyPublishEntry') ) ); 299 $post_status = ( 'no' === $publish_entry ) ? 'draft' : 'publish'; 300 301 /** 302 * Filter the status a synced property is saved with. 303 * 304 * @param string $post_status 'publish', or 'draft' when Palace says not to publish it online. 305 * @param array $property Property record from Palace. 306 */ 307 $post_status = apply_filters( 'ipp_property_post_status', $post_status, $property ); 194 308 195 309 // Create or update post … … 197 311 'post_title' => $post_title, 198 312 'post_content' => $post_content, 199 'post_status' => 'publish',313 'post_status' => $post_status, 200 314 'post_type' => 'palace-properties', 201 315 ); … … 207 321 } 208 322 209 if (!$post_id || is_wp_error($post_id)) { 210 return new WP_REST_Response(array('status' => 'error', 'message' => 'Failed to save property'), 500); 323 if (is_wp_error($post_id)) { 324 return $post_id; 325 } 326 327 if (!$post_id) { 328 return new WP_Error( 329 'ipp_save_failed', 330 __( 'The property could not be saved to the database.', 'integrate-palace-properties' ) 331 ); 211 332 } 212 333 … … 225 346 update_post_meta($post_id, 'ipp_property_code', $property_code); 226 347 update_post_meta($post_id, 'information_property_code', $property_code); // legacy compat 227 update_post_meta($post_id, 'ipp_change_code', sanitize_text_field(self::arr_get($property, 'PropertyChangeCode')));228 update_post_meta($post_id, 'information_code', sanitize_text_field(self::arr_get($property, 'PropertyChangeCode'))); // legacy229 348 update_post_meta($post_id, 'ipp_property_code_global', sanitize_text_field(self::arr_get($property, 'PropertyCodeGlobal'))); 230 349 update_post_meta($post_id, 'ipp_our_code', sanitize_text_field(self::arr_get($property, 'PropertyOurCode'))); … … 282 401 update_post_meta($post_id, 'ipp_parking', sanitize_text_field(self::arr_get($features, 'PropertyParking'))); 283 402 update_post_meta($post_id, 'other_parking', sanitize_text_field(self::arr_get($features, 'PropertyParking'))); // legacy 284 update_post_meta($post_id, 'ipp_pets_allowed', self::arr_get($features, 'PropertyPetsAllowed') === 'Yes' ? '1' : '0'); 285 update_post_meta($post_id, 'other_pets', self::arr_get($features, 'PropertyPetsAllowed') === 'Yes' ? '1' : '0'); // legacy 286 update_post_meta($post_id, 'ipp_smokers_allowed', self::arr_get($features, 'PropertySmokersAllowed') === 'Yes' ? '1' : '0'); 287 update_post_meta($post_id, 'property_smokers_allowed', self::arr_get($features, 'PropertySmokersAllowed') === 'Yes' ? '1' : '0'); // legacy 403 // Palace sends a policy, not a yes/no: real values include "By Consent". 404 // Keep Palace's wording for display, and keep the yes/no flags as before 405 // ("Yes" only) so existing theme code reading them behaves the same. 406 $pets_policy = sanitize_text_field(self::arr_get($features, 'PropertyPetsAllowed')); 407 $smokers_policy = sanitize_text_field(self::arr_get($features, 'PropertySmokersAllowed')); 408 update_post_meta($post_id, 'ipp_pets_policy', $pets_policy); 409 update_post_meta($post_id, 'ipp_smokers_policy', $smokers_policy); 410 update_post_meta($post_id, 'ipp_pets_allowed', 'Yes' === $pets_policy ? '1' : '0'); 411 update_post_meta($post_id, 'other_pets', 'Yes' === $pets_policy ? '1' : '0'); // legacy 412 update_post_meta($post_id, 'ipp_smokers_allowed', 'Yes' === $smokers_policy ? '1' : '0'); 413 update_post_meta($post_id, 'property_smokers_allowed', 'Yes' === $smokers_policy ? '1' : '0'); // legacy 288 414 update_post_meta($post_id, 'ipp_class', sanitize_text_field(self::arr_get($features, 'PropertyClass'))); 289 415 update_post_meta($post_id, 'property_class', sanitize_text_field(self::arr_get($features, 'PropertyClass'))); // legacy … … 430 556 431 557 // === Schedule gallery fetch === 432 // Clear ALL existing gallery cron events for this property first 433 $crons = _get_cron_array(); 434 if ( is_array( $crons ) ) { 435 foreach ( $crons as $ts => $hooks ) { 436 if ( isset( $hooks['update_integrate_palace_gallery'] ) ) { 437 foreach ( $hooks['update_integrate_palace_gallery'] as $hash => $event ) { 438 $args = $event['args'] ?? array(); 439 if ( isset( $args[0] ) && (int) $args[0] === (int) $post_id ) { 440 wp_unschedule_event( $ts, 'update_integrate_palace_gallery', $args ); 558 // Skipped for properties that already have photos when the caller says 559 // images need no refresh (the one-off re-import after an upgrade), so 560 // re-applying import rules does not re-download every photo. 561 $has_gallery = ! empty( get_post_meta( $post_id, 'integrate_palace_gallery', true ) ); 562 if ( $refresh_images || ! $has_gallery ) { 563 // Clear ALL existing gallery cron events for this property first 564 $crons = _get_cron_array(); 565 if ( is_array( $crons ) ) { 566 foreach ( $crons as $ts => $hooks ) { 567 if ( isset( $hooks['update_integrate_palace_gallery'] ) ) { 568 foreach ( $hooks['update_integrate_palace_gallery'] as $hash => $event ) { 569 $args = $event['args'] ?? array(); 570 if ( isset( $args[0] ) && (int) $args[0] === (int) $post_id ) { 571 wp_unschedule_event( $ts, 'update_integrate_palace_gallery', $args ); 572 } 441 573 } 442 574 } 443 575 } 444 576 } 445 } 446 // Reset retry counter and schedule fresh 447 delete_post_meta( $post_id, 'ipp_gallery_sync_retries' ); 448 wp_schedule_single_event( time() + 10, 'update_integrate_palace_gallery', array( $post_id, $property_code ) ); 449 IntegratePalace_Properties_Admin::update_gallery_sync_status( $post_id, 'queued', 'Queued for gallery sync.' ); 450 update_post_meta( $post_id, 'ipp_gallery_sync_started_at', current_time( 'mysql' ) ); 451 452 /** @hook ipp_after_property_save — Fires after a property is saved/updated via webhook (all meta written). */ 577 // Reset retry counter and schedule fresh 578 delete_post_meta( $post_id, 'ipp_gallery_sync_retries' ); 579 wp_schedule_single_event( time() + 10, 'update_integrate_palace_gallery', array( $post_id, $property_code ) ); 580 IntegratePalace_Properties_Admin::update_gallery_sync_status( $post_id, 'queued', 'Queued for gallery sync.' ); 581 update_post_meta( $post_id, 'ipp_gallery_sync_started_at', current_time( 'mysql' ) ); 582 } 583 584 // Record the change code LAST. It is what tells the next sync this 585 // property is up to date, so if the request dies part-way through the 586 // import above, leaving the old code in place means it gets retried. 587 update_post_meta($post_id, 'ipp_change_code', sanitize_text_field(self::arr_get($property, 'PropertyChangeCode'))); 588 update_post_meta($post_id, 'information_code', sanitize_text_field(self::arr_get($property, 'PropertyChangeCode'))); // legacy 589 590 /** @hook ipp_after_property_save — Fires after a property is saved/updated (all meta written). */ 453 591 do_action( 'ipp_after_property_save', $post_id, $property ); 454 592 455 593 do_action('ipp_property_synced', $post_id, $property); 456 594 457 // Update last sync time — tracks when properties were last received via webhook595 // Track when property data was last written. 458 596 update_option( 'ipp_last_sync_time', current_time( 'mysql' ), false ); 459 597 $sync_count = wp_count_posts( 'palace-properties' ); 460 598 update_option( 'ipp_last_sync_count', isset( $sync_count->publish ) ? $sync_count->publish : 0, false ); 461 599 462 return new WP_REST_Response(array('status' => 'success'), 200);600 return (int) $post_id; 463 601 } 464 602 } -
integrate-palace-properties/tags/3.0.0/includes/class-integratepalacep.php
r3486430 r3694341 22 22 $this->define_admin_menu(); 23 23 $this->register_settings(); 24 $this->register_webhooks(); 24 $this->register_property_importer(); 25 // Scheduled Palace polling. Registered unconditionally: WP-Cron runs in 26 // a front-end request context, so this cannot be admin-only. 27 IPP_Sync::init(); 25 28 IntegratePalace_Properties_Admin_Ajax::init(); 26 29 $this->define_palace_properties(); … … 33 36 private function load_dependencies() { 34 37 require_once $this->integrate_palace_dir . 'includes/class-integratepalacep-loader.php'; 38 require_once $this->integrate_palace_dir . 'includes/class-ipp-sync.php'; 39 if ( defined( 'WP_CLI' ) && WP_CLI ) { 40 require_once $this->integrate_palace_dir . 'includes/class-ipp-sync-cli.php'; 41 } 35 42 require_once $this->integrate_palace_dir . 'includes/class-integratepalacep-webhooks.php'; 36 43 require_once $this->integrate_palace_dir . 'admin/class-integratepalacep-admin.php'; … … 135 142 } 136 143 137 private function register_ webhooks() {144 private function register_property_importer() { 138 145 IntegratePalace_Properties_Webhooks::init(); 139 146 } … … 220 227 $md_file = $this->integrate_palace_dir . 'DEVELOPERS.md'; 221 228 $content = file_exists( $md_file ) ? file_get_contents( $md_file ) : ''; 229 230 if ( '' === trim( $content ) ) { 231 echo '<div class="wrap"><h1>' . esc_html__( 'Developer Documentation', 'integrate-palace-properties' ) . '</h1>'; 232 echo '<p>' . esc_html__( 'The documentation file could not be read. It ships with the plugin as DEVELOPERS.md in the plugin folder.', 'integrate-palace-properties' ) . '</p></div>'; 233 return; 234 } 222 235 223 236 echo '<div class="wrap" style="max-width:960px;">'; -
integrate-palace-properties/tags/3.0.0/includes/class-ipp-customizer-settings.php
r3486430 r3694341 12 12 add_action( 'customize_register', array( __CLASS__, 'register' ), 20 ); 13 13 add_action( 'wp_head', array( __CLASS__, 'output_css' ), 99 ); 14 add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_google_fonts' ) ); 14 15 add_action( 'customize_controls_enqueue_scripts', array( __CLASS__, 'customizer_preview_nav' ) ); 15 16 } … … 361 362 } 362 363 364 // ─── Google Fonts ──────────────────────────────────────────── 365 366 /** 367 * Load the Google Fonts chosen in the Customizer on property pages. 368 * 369 * Visitors' browsers fetch these from fonts.googleapis.com, as disclosed in 370 * readme.txt. Nothing is loaded unless a Google font has been chosen. 371 * 372 * @return void 373 */ 374 public static function enqueue_google_fonts() { 375 if ( ! is_singular( 'palace-properties' ) && ! is_post_type_archive( 'palace-properties' ) && ! is_tax( array( 'palace-property-type', 'palace-property-status', 'palace-property-region' ) ) ) { 376 return; 377 } 378 379 $d = self::defaults(); 380 $font_heading = get_theme_mod( 'ipp_font_heading', $d['ipp_font_heading'] ?? '' ); 381 $font_body = get_theme_mod( 'ipp_font_body', $d['ipp_font_body'] ?? '' ); 382 $not_google = array( '', 'inherit', 'system-ui', 'Georgia' ); 383 384 $google_fonts = array(); 385 if ( ! in_array( $font_heading, $not_google, true ) ) { 386 $google_fonts[] = $font_heading; 387 } 388 if ( ! in_array( $font_body, $not_google, true ) && $font_body !== $font_heading ) { 389 $google_fonts[] = $font_body; 390 } 391 392 if ( empty( $google_fonts ) ) { 393 return; 394 } 395 396 $families = implode( 397 '&family=', 398 array_map( 399 function ( $font ) { 400 return str_replace( ' ', '+', $font ) . ':wght@400;500;600;700'; 401 }, 402 $google_fonts 403 ) 404 ); 405 406 // A null version stops WordPress appending ?ver=, which the Google Fonts 407 // css2 endpoint does not use. 408 wp_enqueue_style( 'ipp-google-fonts', 'https://fonts.googleapis.com/css2?family=' . $families . '&display=swap', array(), null ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion 409 } 410 363 411 // ─── CSS Output ────────────────────────────────────────────── 364 412 … … 383 431 $font_body = $get('ipp_font_body'); 384 432 385 // Enqueue Google Fonts if needed 386 $google_fonts = array(); 387 if ( $font_heading && $font_heading !== 'inherit' && $font_heading !== 'system-ui' && $font_heading !== 'Georgia' ) { 388 $google_fonts[] = $font_heading; 389 } 390 if ( $font_body && $font_body !== 'inherit' && $font_body !== 'system-ui' && $font_body !== 'Georgia' && $font_body !== $font_heading ) { 391 $google_fonts[] = $font_body; 392 } 393 if ( ! empty( $google_fonts ) ) { 394 $families = implode( '&family=', array_map( function($f) { return str_replace(' ', '+', $f) . ':wght@400;500;600;700'; }, $google_fonts ) ); 395 echo '<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=' . esc_attr( $families ) . '&display=swap" />' . "\n"; 396 } 433 // Google Fonts are loaded by enqueue_google_fonts(), through 434 // wp_enqueue_style(), rather than printed here. 397 435 398 436 $card_shadow = $shadow_map[ $get('ipp_card_shadow') ] ?? $shadow_map['medium']; -
integrate-palace-properties/tags/3.0.0/includes/class-ipp-developer-api.php
r3486430 r3694341 34 34 global $wpdb; 35 35 $like = '%' . $wpdb->esc_like( $search_term ) . '%'; 36 $meta_keys = "'ipp_address1','ipp_address2','ipp_address3','ipp_suburb','ipp_region','ipp_postcode','ipp_property_code','ipp_agent_full_name','ipp_class','ipp_management_type','information_address','information_suburb','information_region','ipp_header','ipp_name','ipp_property_code_global'"; 36 37 $meta_keys = array( 38 'ipp_address1', 39 'ipp_address2', 40 'ipp_address3', 41 'ipp_suburb', 42 'ipp_region', 43 'ipp_postcode', 44 'ipp_property_code', 45 'ipp_agent_full_name', 46 'ipp_class', 47 'ipp_management_type', 48 'information_address', 49 'information_suburb', 50 'information_region', 51 'ipp_header', 52 'ipp_name', 53 'ipp_property_code_global', 54 ); 55 56 // Build one %s per meta key so the whole IN list goes through 57 // prepare() rather than being interpolated into the statement. 58 $placeholders = implode( ',', array_fill( 0, count( $meta_keys ), '%s' ) ); 59 37 60 $meta_condition = $wpdb->prepare( 38 " OR ({$wpdb->posts}.ID IN (SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key IN ({$meta_keys}) AND meta_value LIKE %s))", 39 $like 61 // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $placeholders is a generated list of %s tokens, and the table names come from $wpdb. 62 " OR ({$wpdb->posts}.ID IN (SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key IN ({$placeholders}) AND meta_value LIKE %s))", 63 array_merge( $meta_keys, array( $like ) ) 40 64 ); 41 65 // Append our meta condition before the closing parenthesis of the search WHERE … … 284 308 'land_area_hectares' => $prop->land_area_hectares(), 285 309 'pets_allowed' => $prop->pets_allowed(), 310 'pets_policy' => $prop->pets_label(), 286 311 'smokers_allowed' => $prop->smokers_allowed(), 312 'smokers_policy' => $prop->smokers_label(), 287 313 ], 288 314 'agent' => [ -
integrate-palace-properties/tags/3.0.0/includes/class-ipp-hooks.php
r3486430 r3694341 70 70 * Fire when a sync cycle starts. 71 71 * 72 * @param string $subscription_id73 */ 74 public static function sync_started( $ subscription_id ) {75 do_action( 'ipp_sync_started', $ subscription_id );72 * @param int $queued Number of properties queued for import. 73 */ 74 public static function sync_started( $queued ) { 75 do_action( 'ipp_sync_started', $queued ); 76 76 } 77 77 … … 79 79 * Fire when a sync cycle completes. 80 80 * 81 * @param string $subscription_id82 * @param int $count Number of properties synced.83 */ 84 public static function sync_completed( $ subscription_id, $count) {85 do_action( 'ipp_sync_completed', $ subscription_id, $count);81 * @param int $imported Number of properties created or updated. 82 * @param int $deleted Number of properties removed. 83 */ 84 public static function sync_completed( $imported, $deleted ) { 85 do_action( 'ipp_sync_completed', $imported, $deleted ); 86 86 } 87 87 … … 243 243 'actions' => [ 244 244 // Lifecycle 245 'ipp_before_property_save' => 'Fires before a property is saved via webhook. Args: $post_id, $property_data',246 'ipp_after_property_save' => 'Fires after a property is saved via webhook. Args: $post_id, $property_data',245 'ipp_before_property_save' => 'Fires before a property is saved. Args: $post_id, $property_data', 246 'ipp_after_property_save' => 'Fires after a property is saved. Args: $post_id, $property_data', 247 247 'ipp_before_property_delete' => 'Fires before a property is deleted. Args: $post_id, $property_code', 248 248 'ipp_after_property_delete' => 'Fires after a property is deleted. Args: $post_id, $property_code', 249 'ipp_sync_started' => 'Fires when a sync cycle begins. Args: $ subscription_id',250 'ipp_sync_completed' => 'Fires when a sync cycle ends. Args: $ subscription_id, $count',249 'ipp_sync_started' => 'Fires when a sync cycle begins. Args: $queued', 250 'ipp_sync_completed' => 'Fires when a sync cycle ends. Args: $imported, $deleted', 251 251 'ipp_gallery_updated' => 'Fires after gallery images are synced. Args: $post_id, $image_ids', 252 252 'ipp_property_synced' => 'Fires after a property is fully synced (existing). Args: $post_id, $property_data', … … 267 267 ], 268 268 'filters' => [ 269 // Sync 270 'ipp_sync_fetched_properties' => 'Filter the raw property list from the Palace API before diffing. Args: $properties', 271 'ipp_sync_batch_size' => 'Properties imported per cron tick (default 10). Args: $size', 272 'ipp_sync_max_delete_ratio' => 'Largest share of the library one run may delete (default 0.5). Args: $ratio', 273 'ipp_sync_min_missing_seconds' => 'How long a property must stay missing before removal (default half the interval, min 10 minutes). Args: $seconds', 274 'ipp_sync_tick_seconds' => 'Seconds one cron tick keeps working before yielding (default 20). Args: $seconds', 275 'ipp_gallery_tick_seconds' => 'Seconds one cron request processes image jobs before deferring (default 20). Args: $seconds', 276 'ipp_property_post_status' => 'Status a synced property is saved with (publish, or draft when Palace says not to publish). Args: $status, $property', 277 'ipp_address_hidden' => 'Whether a property street address is hidden from visitors. Args: $hidden, $post_id', 278 269 279 // Data 270 280 'ipp_property_data' => 'Filter property data array before display. Args: $data, $post_id', -
integrate-palace-properties/tags/3.0.0/includes/class-ipp-rest-api.php
r3486430 r3694341 183 183 * @return array 184 184 */ 185 /** 186 * Whether a property may be shown to the public: a published, non-hidden 187 * palace-properties post. 188 * 189 * @param int $post_id Post ID. 190 * @return bool 191 */ 192 private static function is_public_property( $post_id ) { 193 return 'palace-properties' === get_post_type( $post_id ) 194 && 'publish' === get_post_status( $post_id ) 195 && '1' !== get_post_meta( $post_id, 'ipp_hide_property', true ); 196 } 197 185 198 private static function format_property( $post_id ) { 186 199 $data = IPP_Developer_API::property_to_array( $post_id ); … … 243 256 public static function get_property( WP_REST_Request $request ) { 244 257 $post_id = absint( $request->get_param( 'id' ) ); 258 259 // This endpoint is public. Only published listings may be served: a draft 260 // is a listing Palace says must not be published online. 261 if ( ! self::is_public_property( $post_id ) ) { 262 return new WP_Error( 'not_found', 'Property not found', [ 'status' => 404 ] ); 263 } 264 245 265 $data = self::format_property( $post_id ); 246 266 … … 259 279 $post = get_post( $post_id ); 260 280 261 if ( ! $post || $post->post_type !== 'palace-properties' ) {281 if ( ! $post || $post->post_type !== 'palace-properties' || ! self::is_public_property( $post_id ) ) { 262 282 return new WP_Error( 'not_found', 'Property not found', [ 'status' => 404 ] ); 263 283 } -
integrate-palace-properties/tags/3.0.0/includes/class-ipp-shortcodes.php
r3486430 r3694341 132 132 if ( strtolower( $atts['show_pagination'] ) === 'yes' && $query->max_num_pages > 1 ) { 133 133 echo '<div class="ipp-pagination ipp-shortcode-pagination">'; 134 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- paginate_links() returns markup already generated and escaped by WordPress core; wp_kses_post() would strip its aria-current attribute. 134 135 echo paginate_links( [ 135 136 'total' => $query->max_num_pages, … … 166 167 } 167 168 168 if ( ! $post_id || get_post_type( $post_id ) !== 'palace-properties') {169 if ( ! $post_id || ! self::can_display( $post_id ) ) { 169 170 return '<!-- Palace Properties: Invalid property ID -->'; 170 171 } … … 333 334 334 335 $post_id = absint( $atts['id'] ) ?: get_the_ID(); 335 if ( ! $post_id ) return '';336 if ( ! $post_id || ! self::can_display( $post_id ) ) return ''; 336 337 337 338 $prop = new IPP_Property_Helper( $post_id ); … … 380 381 381 382 $post_id = absint( $atts['id'] ) ?: get_the_ID(); 382 if ( ! $post_id || get_post_type( $post_id ) !== 'palace-properties') {383 if ( ! $post_id || ! self::can_display( $post_id ) ) { 383 384 return '<!-- Palace Properties: Invalid property ID for agent -->'; 384 385 } … … 429 430 return ob_get_clean(); 430 431 } 432 433 /** 434 * Whether a shortcode may render this property. 435 * 436 * Shortcodes appear on public pages, so a listing Palace says must not be 437 * published online (kept as a draft) is only shown to someone who could 438 * already see it, such as an editor previewing their own page. 439 * 440 * @param int $post_id Property post ID. 441 * @return bool 442 */ 443 private static function can_display( $post_id ) { 444 if ( 'palace-properties' !== get_post_type( $post_id ) ) { 445 return false; 446 } 447 448 return 'publish' === get_post_status( $post_id ) || current_user_can( 'read_post', $post_id ); 449 } 431 450 } 432 451 -
integrate-palace-properties/tags/3.0.0/includes/customizer/class-integratepalacep-customizer-register_sections_panels.php
r3236864 r3694341 1 1 <?php 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; 4 } 2 5 3 6 if ( ! class_exists( 'IntegratePalace_Properties_Customizer_Register_Sections_Panels' ) ) { -
integrate-palace-properties/tags/3.0.0/includes/customizer/class-integratepalacep-customizer-sanitizes.php
r3236864 r3694341 1 1 <?php 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; 4 } 2 5 if ( ! class_exists( 'IntegratePalace_Properties_Customizer_Sanitizes' ) ) { 3 6 -
integrate-palace-properties/tags/3.0.0/includes/customizer/class-integratepalacep-template-defaults.php
r3236864 r3694341 1 1 <?php 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; 4 } 2 5 3 6 if (!class_exists('IntegratePalace_Properties_Template_Defaults')) { -
integrate-palace-properties/tags/3.0.0/includes/customizer/class-integratepalacep-template-dynamic-css.php
r3236864 r3694341 1 1 <?php 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; 4 } 2 5 3 6 if (!class_exists('IntegratePalace_Properties_Template_Dynamic_CSS')) { … … 41 44 42 45 // Primary Button Padding 43 $pBtnPaddingTD = $ settings['primary_btn_paddings']['desktop']['top'] ?? 0.625;44 $pBtnPaddingRD = $ settings['primary_btn_paddings']['desktop']['right'] ?? 1.5;45 $pBtnPaddingBD = $ settings['primary_btn_paddings']['desktop']['bottom'] ?? 0.625;46 $pBtnPaddingLD = $ settings['primary_btn_paddings']['desktop']['left'] ?? 1.5;47 $pBtnPaddingUnit = $ settings['primary_btn_paddings']['unit'] ?? 'rem';46 $pBtnPaddingTD = $options['primary_btn_paddings']['desktop']['top'] ?? 0.625; 47 $pBtnPaddingRD = $options['primary_btn_paddings']['desktop']['right'] ?? 1.5; 48 $pBtnPaddingBD = $options['primary_btn_paddings']['desktop']['bottom'] ?? 0.625; 49 $pBtnPaddingLD = $options['primary_btn_paddings']['desktop']['left'] ?? 1.5; 50 $pBtnPaddingUnit = $options['primary_btn_paddings']['unit'] ?? 'rem'; 48 51 $pBtnPaddings_D = esc_attr($pBtnPaddingTD) . $pBtnPaddingUnit . ' ' . esc_attr($pBtnPaddingRD) . $pBtnPaddingUnit . ' ' . esc_attr($pBtnPaddingBD) . $pBtnPaddingUnit . ' ' . esc_attr($pBtnPaddingLD) . $pBtnPaddingUnit; 49 52 … … 82 85 83 86 // Secondary Button Padding 84 $sBtnPaddingTD = $ settings['secondary_btn_paddings']['desktop']['top'] ?? 0.625;85 $sBtnPaddingRD = $ settings['secondary_btn_paddings']['desktop']['right'] ?? 1.5;86 $sBtnPaddingBD = $ settings['secondary_btn_paddings']['desktop']['bottom'] ?? 0.625;87 $sBtnPaddingLD = $ settings['secondary_btn_paddings']['desktop']['left'] ?? 1.5;88 $sBtnPaddingUnit = $ settings['secondary_btn_paddings']['unit'] ?? 'rem';87 $sBtnPaddingTD = $options['secondary_btn_paddings']['desktop']['top'] ?? 0.625; 88 $sBtnPaddingRD = $options['secondary_btn_paddings']['desktop']['right'] ?? 1.5; 89 $sBtnPaddingBD = $options['secondary_btn_paddings']['desktop']['bottom'] ?? 0.625; 90 $sBtnPaddingLD = $options['secondary_btn_paddings']['desktop']['left'] ?? 1.5; 91 $sBtnPaddingUnit = $options['secondary_btn_paddings']['unit'] ?? 'rem'; 89 92 $sBtnPaddings_D = esc_attr($sBtnPaddingTD) . $sBtnPaddingUnit . ' ' . esc_attr($sBtnPaddingRD) . $sBtnPaddingUnit . ' ' . esc_attr($sBtnPaddingBD) . $sBtnPaddingUnit . ' ' . esc_attr($sBtnPaddingLD) . $sBtnPaddingUnit; 90 93 … … 107 110 108 111 112 // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- Generated CSS: every interpolated value is escaped with esc_attr() individually (see above); escaping the whole block would corrupt the stylesheet. 109 113 echo "<style> 110 114 … … 187 191 188 192 </style>"; 193 // phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped 189 194 } 190 195 -
integrate-palace-properties/tags/3.0.0/includes/customizer/configurations/class-integratepalacep-colors-config.php
r3236864 r3694341 45 45 'type' => 'control', 46 46 'control' => 'IPPR_Colors', 47 'label' => sprintf( __( '%s', 'integrate-palace-properties' ), $template_name ),47 'label' => $template_name, 48 48 'section' => IPPR_SETTINGS . '[template_colors_section]', 49 49 'settings' => $settings_map, -
integrate-palace-properties/tags/3.0.0/includes/customizer/configurations/class-integratepalacep-typography-config.php
r3236864 r3694341 1 1 <?php 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; 4 } 2 5 if ( ! class_exists( 'IntegratePalace_Properties_Typography' ) ) { 3 6 -
integrate-palace-properties/tags/3.0.0/includes/customizer/extend-custom-controls/class-integratepalacep-extend-custom-controls.php
r3236864 r3694341 94 94 value="<?php echo esc_attr( $value ); ?>" 95 95 id="<?php echo esc_attr( $this->id . '_' . $value ); ?>" 96 <?php echo$this->link(); ?>96 <?php $this->link(); ?> 97 97 <?php checked( $this->value(), $value ); ?> 98 98 aria-label="<?php echo esc_attr( $tooltip ); ?>" /> 99 99 <label for="<?php echo esc_attr( $this->id . '_' . $value ); ?>" class="ippr-radio-img-svg"> 100 <?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon( $value ); ?>100 <?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon( $value ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Trusted static SVG markup from the plugin-bundled svg.json asset; escaping would strip the icon. ?> 101 101 <?php if ( $label ) : ?> 102 <span class="ippr-tooltip" data-tooltip="<?php echo $tooltip; ?>"></span>102 <span class="ippr-tooltip" data-tooltip="<?php echo esc_attr( $label ); ?>"></span> 103 103 <?php endif; ?> 104 104 </label> … … 263 263 264 264 ?> 265 <div class="ippr-responsive-button-control" data-setting-id="<?php echo $setting_id; ?>">265 <div class="ippr-responsive-button-control" data-setting-id="<?php echo $setting_id; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $setting_id is already escaped with esc_attr() above. ?>"> 266 266 <div class="ippr-responsive-button-wrapper"> 267 267 <!-- Tabs Section --> … … 271 271 <?php foreach ($this->devices as $device): ?> 272 272 <div class="ippr-responsive-device-icon ippr-responsive-button-icon <?php echo esc_attr($device); ?>" data-device="<?php echo esc_attr($device); ?>"> 273 <?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon($device); ?>273 <?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon($device); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Trusted static SVG markup from the plugin-bundled svg.json asset; escaping would strip the icon. ?> 274 274 </div> 275 275 <?php endforeach; ?> … … 282 282 <input 283 283 type="radio" 284 name="<?php echo $setting_id ?>"285 value="<?php echo $unit; ?>"284 name="<?php echo $setting_id; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $setting_id is already escaped with esc_attr() above. ?>" 285 value="<?php echo esc_attr($unit); ?>" 286 286 <?php checked($btn_sides_value['unit'] ?? 'rem', $unit); ?> 287 287 /> 288 <?php echo strtoupper($unit); ?>288 <?php echo esc_html(strtoupper($unit)); ?> 289 289 </label> 290 290 <?php endforeach; ?> … … 296 296 <ul class="ippr-spacing-wrapper"> 297 297 <?php foreach ($this->devices as $device): ?> 298 <li class="ippr-spacing-input-item ippr-number-control" data-device="<?php echo $device; ?>">298 <li class="ippr-spacing-input-item ippr-number-control" data-device="<?php echo esc_attr($device); ?>"> 299 299 <?php foreach (['top', 'right', 'bottom', 'left'] as $side): ?> 300 300 <div class="ippr-spacing-input-item-group"> … … 302 302 id="<?php echo esc_attr($setting_id . '_' .$device . '_' . $side); ?>" 303 303 type="number" 304 class="padding-<?php echo $side; ?> ippr-spacing-input"304 class="padding-<?php echo esc_attr($side); ?> ippr-spacing-input" 305 305 value="<?php echo esc_attr($btn_sides_value[$device][$side] ?? ''); ?>" 306 data-side="<?php echo $side; ?>"306 data-side="<?php echo esc_attr($side); ?>" 307 307 placeholder="" 308 308 > … … 316 316 <div class="ippr-spacing-input-item-uniform"> 317 317 <div class="toggle-uniform"> 318 <span class="ippr-spacing-disconnected"><? = Integrate_Palace_Properties_Icons::fetch_svg_icon('spacing-disconnected');?></span>319 <span class="ippr-spacing-connected"><? = Integrate_Palace_Properties_Icons::fetch_svg_icon('spacing-connected');?></span>318 <span class="ippr-spacing-disconnected"><?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon('spacing-disconnected'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Trusted static SVG markup from the plugin-bundled svg.json asset; escaping would strip the icon. ?></span> 319 <span class="ippr-spacing-connected"><?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon('spacing-connected'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Trusted static SVG markup from the plugin-bundled svg.json asset; escaping would strip the icon. ?></span> 320 320 </div> 321 321 </div> … … 366 366 367 367 ?> 368 <div class="ippr-responsive-button-control" data-setting-id="<?php echo $setting_id; ?>">368 <div class="ippr-responsive-button-control" data-setting-id="<?php echo $setting_id; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $setting_id is already escaped with esc_attr() above. ?>"> 369 369 <div class="ippr-responsive-button-wrapper"> 370 370 <div class="ippr-responsive-button-tabs"> … … 379 379 <input 380 380 type="radio" 381 name="<?php echo $setting_id ?>"381 name="<?php echo $setting_id; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $setting_id is already escaped with esc_attr() above. ?>" 382 382 value="<?php echo esc_attr($unit); ?>" 383 383 <?php checked($btn_sides_value['unit'] ?? 'px', $unit); ?> 384 384 /> 385 <?php echo strtoupper($unit); ?>385 <?php echo esc_html(strtoupper($unit)); ?> 386 386 </label> 387 387 <?php endforeach; ?> … … 414 414 <div class="toggle-uniform"> 415 415 <span class="ippr-spacing-disconnected"> 416 <?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon('spacing-disconnected'); ?>416 <?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon('spacing-disconnected'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Trusted static SVG markup from the plugin-bundled svg.json asset; escaping would strip the icon. ?> 417 417 </span> 418 418 <span class="ippr-spacing-connected"> 419 <?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon('spacing-connected'); ?>419 <?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon('spacing-connected'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Trusted static SVG markup from the plugin-bundled svg.json asset; escaping would strip the icon. ?> 420 420 </span> 421 421 </div> … … 498 498 <div class="ippr-btn-font-family ippr-bottom-border-dotted"> 499 499 <!-- Font Family --> 500 <label><?php _e('Font Family', 'integrate-palace-properties'); ?></label>500 <label><?php esc_html_e('Font Family', 'integrate-palace-properties'); ?></label> 501 501 <select class="ippr-btn-font-family-control" <?php $this->link( 'font_family' ); ?>> 502 502 <?php foreach ( $this->font_families as $font_family ) : ?> … … 510 510 <div class="ippr-btn-font-weight ippr-bottom-border-dotted"> 511 511 <!-- Font Weight --> 512 <label><?php _e('Font Weight', 'integrate-palace-properties'); ?></label>512 <label><?php esc_html_e('Font Weight', 'integrate-palace-properties'); ?></label> 513 513 <select class="ippr-btn-font-weight-control" <?php $this->link( 'font_weight' ); ?>> 514 514 <?php foreach ( $this->font_weight as $font_weight ) : ?> … … 522 522 <div class="ippr-responsive-button-tabs"> 523 523 <div class="ippr-responsive-device-icons"> 524 <label><?php echo __( 'Size', 'integrate-palace-properties' ); ?></label>524 <label><?php echo esc_html__( 'Size', 'integrate-palace-properties' ); ?></label> 525 525 <?php foreach ($this->devices as $device): ?> 526 526 <div class="ippr-responsive-device-icon ippr-responsive-font-icon<?php echo esc_attr($device); ?>"> 527 <?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon($device); ?>527 <?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon($device); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Trusted static SVG markup from the plugin-bundled svg.json asset; escaping would strip the icon. ?> 528 528 </div> 529 529 <?php endforeach; ?> … … 535 535 <label> 536 536 <input type="radio" name="<?php echo esc_attr( "{$control_type}_font_size_unit" ); ?>" value="<?php echo esc_attr( $font_unit ); ?>" <?php checked( $cur_font_size_unit, $font_unit ); ?> <?php $this->link( 'font_unit' ); ?>/> 537 <?php echo strtoupper(esc_html($font_unit)); ?>537 <?php echo esc_html(strtoupper($font_unit)); ?> 538 538 </label> 539 539 <?php endforeach; ?> … … 542 542 </div> 543 543 544 <div class="ippr-spacing-wrapper ippr-responsive-font-size" data-setting-id="<?php echo $setting_id?>">544 <div class="ippr-spacing-wrapper ippr-responsive-font-size" data-setting-id="<?php echo esc_attr($setting_id); ?>"> 545 545 <!-- Font Size --> 546 546 <div class="ippr-responsive-font-size-slider"> -
integrate-palace-properties/tags/3.0.0/includes/customizer/extend-customizer/class-integratepalacep-customize-panels.php
r3236864 r3694341 1 1 <?php 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; 4 } 2 5 3 6 if ( class_exists( 'WP_Customize_Panel' ) && !class_exists( 'IntegratePalace_Properties_Property_Panel' ) ) { -
integrate-palace-properties/tags/3.0.0/includes/customizer/extend-customizer/class-integratepalacep-customize-sections.php
r3236864 r3694341 1 1 <?php 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; 4 } 2 5 3 6 if ( class_exists( 'WP_Customize_Section' ) && !class_exists( 'IntegratePalace_Properties_Property_Customize_Section' ) ) { -
integrate-palace-properties/tags/3.0.0/integrate-palace-properties.php
r3524450 r3694341 2 2 /** 3 3 * Plugin Name: Integrate Palace Properties 4 * Description: A plugin to syncronize wp palace properties to your wordpress blog/website. 5 * Version: 2.1.6 4 * Plugin URI: https://wordpress.org/plugins/integrate-palace-properties/ 5 * Description: Sync property listings from MRI Palace to WordPress, directly from your own site. 6 * Version: 3.0.0 7 * Requires at least: 5.8 8 * Requires PHP: 8.0 6 9 * Author: SAFDAR 7 * Author URI: https:// wp-palace.kiwibrain.co.nz/10 * Author URI: https://kiwibrain.co.nz/ 8 11 * Text Domain: integrate-palace-properties 9 12 * Domain Path: /languages … … 20 23 21 24 // Define plugin version. 22 define( 'INTEGRATE_PALACE_P_VERSION', ' 2.1.6' );25 define( 'INTEGRATE_PALACE_P_VERSION', '3.0.0' ); 23 26 define( 'IPPR_SETTINGS', 'ippr-template-settings' ); 24 27 define('INTEGRATE_PALACE_P_PLUGIN_DIR', plugin_dir_path(__FILE__)); … … 31 34 32 35 if ( ! file_exists( $integrate_palace_activator ) ) { 33 wp_die( __( 'Required activation files are missing. Please reinstall the plugin.', 'integrate-palace-properties' ) );36 wp_die( esc_html__( 'Required activation files are missing. Please reinstall the plugin.', 'integrate-palace-properties' ) ); 34 37 } 35 38 … … 44 47 register_activation_hook( __FILE__, 'integrate_palace_activate' ); 45 48 49 // Deactivation: clear scheduled events so no orphaned cron entries are left. 50 function integrate_palace_deactivate() { 51 52 $integrate_palace_deactivator = INTEGRATE_PALACE_P_PLUGIN_DIR . 'includes/class-integratepalacep-deactivator.php'; 53 54 if ( ! file_exists( $integrate_palace_deactivator ) ) { 55 return; 56 } 57 58 require_once $integrate_palace_deactivator; 59 60 if ( class_exists( 'IntegratePalace_Properties_Deactivator' ) ) { 61 IntegratePalace_Properties_Deactivator::deactivate(); 62 } 63 64 } 65 66 register_deactivation_hook( __FILE__, 'integrate_palace_deactivate' ); 67 46 68 // Include the main class file. 47 69 require INTEGRATE_PALACE_P_PLUGIN_DIR . 'includes/class-integratepalacep.php'; -
integrate-palace-properties/tags/3.0.0/public/archive-palace_property.php
r3236864 r3694341 9 9 */ 10 10 if ( ! defined( 'ABSPATH' ) ) exit; 11 get_header();11 IntegratePalace_Properties_Public::render_header(); 12 12 13 13 $options = get_option( 'integrate_palace_settings' ); … … 103 103 104 104 // Bedroom filter 105 if ( isset( $_GET['bedroom'] ) && str_replace( '%20', ' ', $_GET['bedroom'] ) !== 'Any Bedrooms' ) { 106 $bedrooms = absint( $_GET['bedroom'] ); 105 $bedroom_param = isset( $_GET['bedroom'] ) ? sanitize_text_field( wp_unslash( $_GET['bedroom'] ) ) : ''; 106 if ( '' !== $bedroom_param && str_replace( '%20', ' ', $bedroom_param ) !== 'Any Bedrooms' ) { 107 $bedrooms = absint( $bedroom_param ); 107 108 $meta_query[] = array( 108 109 'key' => 'accommodation_bed_room', … … 114 115 115 116 // Bathroom filter 116 if ( isset( $_GET['bathroom'] ) && str_replace( '%20', ' ', $_GET['bathroom'] ) !== 'Any Bathrooms' ) { 117 $bathrooms = absint( $_GET['bathroom'] ); 117 $bathroom_param = isset( $_GET['bathroom'] ) ? sanitize_text_field( wp_unslash( $_GET['bathroom'] ) ) : ''; 118 if ( '' !== $bathroom_param && str_replace( '%20', ' ', $bathroom_param ) !== 'Any Bathrooms' ) { 119 $bathrooms = absint( $bathroom_param ); 118 120 $meta_query[] = array( 119 121 'key' => 'accommodation_bath_room', … … 125 127 126 128 // Region filter 127 if ( isset( $_GET['region'] ) && str_replace( '%20', ' ', $_GET['region'] ) !== 'All Region' ) { 129 $region_param = isset( $_GET['region'] ) ? sanitize_text_field( wp_unslash( $_GET['region'] ) ) : ''; 130 if ( '' !== $region_param && str_replace( '%20', ' ', $region_param ) !== 'All Region' ) { 128 131 $meta_query[] = array( 129 132 'key' => 'information_region', 130 'value' => sanitize_text_field( wp_unslash( $_GET['region'] ) ),133 'value' => $region_param, 131 134 'compare' => '=', 132 135 ); … … 165 168 166 169 <?php 167 get_footer();170 IntegratePalace_Properties_Public::render_footer(); -
integrate-palace-properties/tags/3.0.0/public/class-integratepalacep-public.php
r3486430 r3694341 72 72 $tax_query = array( 'relation' => 'AND' ); 73 73 if ( ! empty( $_GET['region'] ) ) { 74 $tax_query[] = array( 'taxonomy' => 'palace-property-region', 'field' => 'slug', 'terms' => sanitize_text_field( $_GET['region']) );74 $tax_query[] = array( 'taxonomy' => 'palace-property-region', 'field' => 'slug', 'terms' => sanitize_text_field( wp_unslash( $_GET['region'] ) ) ); 75 75 } 76 76 if ( ! empty( $_GET['property_type'] ) ) { 77 $tax_query[] = array( 'taxonomy' => 'palace-property-type', 'field' => 'slug', 'terms' => sanitize_text_field( $_GET['property_type']) );77 $tax_query[] = array( 'taxonomy' => 'palace-property-type', 'field' => 'slug', 'terms' => sanitize_text_field( wp_unslash( $_GET['property_type'] ) ) ); 78 78 } 79 79 if ( ! empty( $_GET['property_status'] ) ) { 80 $tax_query[] = array( 'taxonomy' => 'palace-property-status', 'field' => 'slug', 'terms' => sanitize_text_field( $_GET['property_status']) );80 $tax_query[] = array( 'taxonomy' => 'palace-property-status', 'field' => 'slug', 'terms' => sanitize_text_field( wp_unslash( $_GET['property_status'] ) ) ); 81 81 } 82 82 if ( count( $tax_query ) > 1 ) { … … 86 86 // Sort 87 87 if ( ! empty( $_GET['sort_by'] ) ) { 88 switch ( sanitize_text_field( $_GET['sort_by']) ) {88 switch ( sanitize_text_field( wp_unslash( $_GET['sort_by'] ) ) ) { 89 89 case 'price_asc': 90 90 $query->set( 'meta_key', 'ipp_rent_amount' ); … … 259 259 * Template routing for single and archive views. 260 260 */ 261 /** 262 * Open a plugin page template in a way that works with any theme. 263 * 264 * A block theme has no header.php. Calling get_header() there makes 265 * WordPress fall back to a bare compatibility header, and log a deprecation 266 * notice, so property pages lose the site's real header. On block themes 267 * the page is opened by hand and the theme's own header template part is 268 * rendered instead. 269 * 270 * @return void 271 */ 272 public static function render_header() { 273 if ( ! function_exists( 'wp_is_block_theme' ) || ! wp_is_block_theme() ) { 274 get_header(); 275 return; 276 } 277 ?><!DOCTYPE html> 278 <html <?php language_attributes(); ?>> 279 <head> 280 <meta charset="<?php bloginfo( 'charset' ); ?>"> 281 <meta name="viewport" content="width=device-width, initial-scale=1"> 282 <?php wp_head(); ?> 283 </head> 284 <body <?php body_class(); ?>> 285 <?php wp_body_open(); ?> 286 <div class="wp-site-blocks"> 287 <?php 288 // Render the header as a template-part block, exactly as a block theme's 289 // own templates do. That wraps it in a <header> landmark and applies the 290 // theme's layout styles; block_template_part() would print the bare 291 // contents with neither. do_blocks() also exists back to WordPress 5.0, 292 // so this stays within the plugin's declared minimum version. 293 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Core-rendered block markup from the active theme; escaping would break the navigation block's markup and interactivity attributes. 294 echo do_blocks( '<!-- wp:template-part {"slug":"header","tagName":"header"} /-->' ); 295 } 296 297 /** 298 * Close a plugin page template opened by render_header(). 299 * 300 * @return void 301 */ 302 public static function render_footer() { 303 if ( ! function_exists( 'wp_is_block_theme' ) || ! wp_is_block_theme() ) { 304 get_footer(); 305 return; 306 } 307 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Core-rendered block markup from the active theme. 308 echo do_blocks( '<!-- wp:template-part {"slug":"footer","tagName":"footer"} /-->' ); 309 ?> 310 </div> 311 <?php wp_footer(); ?> 312 </body> 313 </html> 314 <?php 315 } 316 261 317 public function use_palace_property_template( $template ) { 262 318 $post_type = 'palace-properties'; … … 309 365 public function ajax_load_button() { 310 366 $template_slug = $this->get_active_template(); 367 368 // Public, read-only pagination for published properties: it changes no 369 // state and exposes nothing that is not already on the archive page, so 370 // there is no action for a nonce to protect. The value is cast to an 371 // integer and used only as a page number. 372 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Read-only public endpoint, see above. 311 373 $paged = isset( $_POST['page'] ) ? intval( $_POST['page'] ) : 1; 312 374 … … 364 426 $page = isset( $_POST['page'] ) ? absint( $_POST['page'] ) : 1; 365 427 $per_page = isset( $_POST['per_page'] ) ? absint( $_POST['per_page'] ) : 9; 366 $sort_by = isset( $_POST['sort_by'] ) ? sanitize_text_field( $_POST['sort_by']) : 'date_desc';428 $sort_by = isset( $_POST['sort_by'] ) ? sanitize_text_field( wp_unslash( $_POST['sort_by'] ) ) : 'date_desc'; 367 429 368 430 // Build query … … 401 463 402 464 if ( ! empty( $_POST['search_text'] ) ) { 403 $search = sanitize_text_field( $_POST['search_text']);465 $search = sanitize_text_field( wp_unslash( $_POST['search_text'] ) ); 404 466 $args['ipp_meta_search'] = true; 405 467 $this->add_meta_search_filter( $search ); … … 462 524 'taxonomy' => 'palace-property-type', 463 525 'field' => 'slug', 464 'terms' => array_map( 'sanitize_text_field', (array) $_POST['property_type']),526 'terms' => array_map( 'sanitize_text_field', wp_unslash( (array) $_POST['property_type'] ) ), 465 527 ); 466 528 } … … 470 532 'taxonomy' => 'palace-property-status', 471 533 'field' => 'slug', 472 'terms' => array_map( 'sanitize_text_field', (array) $_POST['property_status']),534 'terms' => array_map( 'sanitize_text_field', wp_unslash( (array) $_POST['property_status'] ) ), 473 535 ); 474 536 } … … 478 540 'taxonomy' => 'palace-property-region', 479 541 'field' => 'slug', 480 'terms' => array_map( 'sanitize_text_field', (array) $_POST['region']),542 'terms' => array_map( 'sanitize_text_field', wp_unslash( (array) $_POST['region'] ) ), 481 543 ); 482 544 } -
integrate-palace-properties/tags/3.0.0/public/class-integratepalacep-svg-icons.php
r3236864 r3694341 1 1 <?php 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; 4 } 2 5 if ( ! class_exists( 'Integrate_Palace_Properties_Icons' ) ) { 3 6 -
integrate-palace-properties/tags/3.0.0/public/single-palace_property.php
r3236864 r3694341 10 10 11 11 if ( ! defined( 'ABSPATH' ) ) exit; 12 get_header();12 IntegratePalace_Properties_Public::render_header(); 13 13 14 14 $post_id = get_the_ID(); … … 65 65 66 66 67 <?php get_footer(); ?>67 <?php IntegratePalace_Properties_Public::render_footer(); ?> -
integrate-palace-properties/tags/3.0.0/public/templates/archive.php
r3486430 r3694341 6 6 if ( ! defined( 'ABSPATH' ) ) exit; 7 7 8 get_header();8 IntegratePalace_Properties_Public::render_header(); 9 9 10 10 $template_slug = sanitize_text_field( get_option( 'ipp_select_template', 'palace-property' ) ); … … 37 37 global $wp_query; 38 38 printf( 39 /* translators: %s: number of properties found, wrapped in <strong> tags. */ 39 40 esc_html( _n( '%s Property', '%s Properties', $wp_query->found_posts, 'integrate-palace-properties' ) ), 40 41 '<strong>' . esc_html( number_format_i18n( $wp_query->found_posts ) ) . '</strong>' … … 98 99 </div> 99 100 100 <?php get_footer(); ?>101 <?php IntegratePalace_Properties_Public::render_footer(); ?> -
integrate-palace-properties/tags/3.0.0/public/templates/classic/single.php
r3486430 r3694341 14 14 ?> 15 15 16 <?php echo $prop->schema_json_ld();?>16 <?php // Schema.org JSON-LD is printed once, by the wrapper (public/templates/single.php), where the ipp_property_schema filter applies. ?> 17 17 18 18 <div class="ipp-single ipp-single--classic ipp-container"> … … 111 111 'land_area' => ['Land Area', $prop->land_area_sqm() ? $prop->land_area_sqm() . ' sqm' : ''], 112 112 'parking' => ['Parking', $prop->parking()], 113 'pets_allowed' => ['Pets Allowed', $prop->pets_ allowed()],114 'smokers_allowed'=> ['Smokers Allowed', $prop->smokers_ allowed()],113 'pets_allowed' => ['Pets Allowed', $prop->pets_label()], 114 'smokers_allowed'=> ['Smokers Allowed', $prop->smokers_label()], 115 115 ]; 116 116 ?> … … 158 158 159 159 <!-- Map --> 160 <?php if ($prop->show('geographic_location') && $prop-> has_map_coords()) : ?>160 <?php if ($prop->show('geographic_location') && $prop->show_map()) : ?> 161 161 <section class="ipp-single__section" aria-labelledby="ipp-classic-map"> 162 162 <h2 id="ipp-classic-map" class="ipp-single__section-title">Location</h2> -
integrate-palace-properties/tags/3.0.0/public/templates/developer/single.php
r3486430 r3694341 15 15 ?> 16 16 17 <?php echo $prop->schema_json_ld();?>17 <?php // Schema.org JSON-LD is printed once, by the wrapper (public/templates/single.php), where the ipp_property_schema filter applies. ?> 18 18 19 19 <article class="ipp-single ipp-single--developer" … … 32 32 data-date-available="<?php echo esc_attr($prop->date_available()); ?>" 33 33 data-pets-allowed="<?php echo esc_attr($prop->pets_allowed()); ?>" 34 data-pets-policy="<?php echo esc_attr($prop->pets_label()); ?>" 34 35 data-smokers-allowed="<?php echo esc_attr($prop->smokers_allowed()); ?>" 36 data-smokers-policy="<?php echo esc_attr($prop->smokers_label()); ?>" 35 37 aria-label="<?php echo esc_attr($prop->name()); ?>"> 36 38 … … 176 178 </div> 177 179 <?php endif; ?> 178 <?php if ($prop->show('pets_allowed') && $prop->pets_allowed()) : ?>180 <?php if ($prop->show('pets_allowed')) : ?> 179 181 <div data-detail="pets-allowed"> 180 182 <dt>Pets Allowed</dt> 181 <dd><?php echo esc_html($prop->pets_ allowed()); ?></dd>182 </div> 183 <?php endif; ?> 184 <?php if ($prop->show('smokers_allowed') && $prop->smokers_allowed()) : ?>183 <dd><?php echo esc_html($prop->pets_label()); ?></dd> 184 </div> 185 <?php endif; ?> 186 <?php if ($prop->show('smokers_allowed')) : ?> 185 187 <div data-detail="smokers-allowed"> 186 188 <dt>Smokers Allowed</dt> 187 <dd><?php echo esc_html($prop->smokers_ allowed()); ?></dd>189 <dd><?php echo esc_html($prop->smokers_label()); ?></dd> 188 190 </div> 189 191 <?php endif; ?> … … 243 245 244 246 <!-- Map --> 245 <?php if ($prop->show('geographic_location') && $prop-> has_map_coords()) : ?>247 <?php if ($prop->show('geographic_location') && $prop->show_map()) : ?> 246 248 <section data-role="property-map" aria-labelledby="dev-map-heading"> 247 249 <h2 id="dev-map-heading">Location</h2> -
integrate-palace-properties/tags/3.0.0/public/templates/grid-gallery/single.php
r3486430 r3694341 14 14 ?> 15 15 16 <?php echo $prop->schema_json_ld();?>16 <?php // Schema.org JSON-LD is printed once, by the wrapper (public/templates/single.php), where the ipp_property_schema filter applies. ?> 17 17 18 18 <div class="ipp-single ipp-single--grid-gallery"> … … 109 109 'land_area' => ['Land Area', $prop->land_area_sqm() ? $prop->land_area_sqm() . ' sqm' : ''], 110 110 'parking' => ['Parking', $prop->parking()], 111 'pets_allowed' => ['Pets Allowed', $prop->pets_ allowed()],112 'smokers_allowed'=> ['Smokers Allowed', $prop->smokers_ allowed()],111 'pets_allowed' => ['Pets Allowed', $prop->pets_label()], 112 'smokers_allowed'=> ['Smokers Allowed', $prop->smokers_label()], 113 113 ]; 114 114 ?> … … 160 160 161 161 <!-- Map --> 162 <?php if ($prop->show('geographic_location') && $prop-> has_map_coords()) : ?>162 <?php if ($prop->show('geographic_location') && $prop->show_map()) : ?> 163 163 <section class="ipp-single__section" aria-labelledby="ipp-gg-map" style="margin-bottom:2rem;"> 164 164 <h2 id="ipp-gg-map" class="ipp-single__section-title">Location</h2> -
integrate-palace-properties/tags/3.0.0/public/templates/minimal/single.php
r3486430 r3694341 15 15 ?> 16 16 17 <?php echo $prop->schema_json_ld();?>17 <?php // Schema.org JSON-LD is printed once, by the wrapper (public/templates/single.php), where the ipp_property_schema filter applies. ?> 18 18 19 19 <div class="ipp-single ipp-single--minimal" style="max-width:800px;margin:0 auto;padding:2rem 1rem;"> … … 117 117 'floor_area' => ['Floor Area', $prop->floor_area()], 118 118 'land_area' => ['Land Area', $prop->land_area_sqm() ? $prop->land_area_sqm() . ' sqm' : ''], 119 'pets_allowed' => ['Pets', $prop->pets_ allowed()],120 'smokers_allowed'=> ['Smokers', $prop->smokers_ allowed()],119 'pets_allowed' => ['Pets', $prop->pets_label()], 120 'smokers_allowed'=> ['Smokers', $prop->smokers_label()], 121 121 ]; 122 122 ?> … … 171 171 172 172 <!-- Map --> 173 <?php if ($prop->show('geographic_location') && $prop-> has_map_coords()) : ?>173 <?php if ($prop->show('geographic_location') && $prop->show_map()) : ?> 174 174 <section class="ipp-single__section" aria-labelledby="ipp-minimal-map" style="margin-bottom:2.5rem;"> 175 175 <h2 id="ipp-minimal-map" class="ipp-single__section-title" style="font-family:var(--ipp-font-heading,Georgia,serif);font-weight:400;font-size:1.5rem;margin-bottom:1.25rem;"> -
integrate-palace-properties/tags/3.0.0/public/templates/modern/single.php
r3486430 r3694341 14 14 ?> 15 15 16 <?php echo $prop->schema_json_ld();?>16 <?php // Schema.org JSON-LD is printed once, by the wrapper (public/templates/single.php), where the ipp_property_schema filter applies. ?> 17 17 18 18 <div class="ipp-single ipp-single--modern"> … … 116 116 'land_area' => ['Land Area', $prop->land_area_sqm() ? $prop->land_area_sqm() . ' sqm' : ''], 117 117 'parking' => ['Parking', $prop->parking()], 118 'pets_allowed' => ['Pets Allowed', $prop->pets_ allowed()],119 'smokers_allowed'=> ['Smokers Allowed', $prop->smokers_ allowed()],118 'pets_allowed' => ['Pets Allowed', $prop->pets_label()], 119 'smokers_allowed'=> ['Smokers Allowed', $prop->smokers_label()], 120 120 ]; 121 121 ?> … … 168 168 169 169 <!-- Map --> 170 <?php if ($prop->show('geographic_location') && $prop-> has_map_coords()) : ?>170 <?php if ($prop->show('geographic_location') && $prop->show_map()) : ?> 171 171 <section class="ipp-single__section" aria-labelledby="ipp-modern-map" style="margin-bottom:3rem;"> 172 172 <h2 id="ipp-modern-map" class="ipp-single__section-title" style="font-size:1.5rem;">Location</h2> -
integrate-palace-properties/tags/3.0.0/public/templates/palace-property/single.php
r3486430 r3694341 935 935 if ($prop->show('furnishings') && $prop->furnishings()) $details[] = ['Furnishings', $prop->furnishings()]; 936 936 if ($prop->show('new_construction') && $prop->new_construction()) $details[] = ['New Construction', $prop->new_construction()]; 937 if ($prop->show('pets_allowed')) $details[] = ['Pets Allowed', $prop->pets_ allowed() ? 'Yes' : 'No', $prop->pets_allowed()];938 if ($prop->show('smokers_allowed')) $details[] = ['Smokers Allowed', $prop->smokers_ allowed() ? 'Yes' : 'No', $prop->smokers_allowed()];937 if ($prop->show('pets_allowed')) $details[] = ['Pets Allowed', $prop->pets_label(), $prop->pets_allowed()]; 938 if ($prop->show('smokers_allowed')) $details[] = ['Smokers Allowed', $prop->smokers_label(), $prop->smokers_allowed()]; 939 939 if ($prop->show('unit') && $prop->unit()) $details[] = ['Unit', $prop->unit()]; 940 940 ?> … … 1037 1037 1038 1038 <!-- Map --> 1039 <?php if ($prop->show('geographic_location') && $prop-> has_map_coords()) : ?>1039 <?php if ($prop->show('geographic_location') && $prop->show_map()) : ?> 1040 1040 <div class="ipp-section ipp-single__section"> 1041 1041 <h2 class="ipp-section__title ipp-single__section-title">Location</h2> … … 1125 1125 <h4 class="ipp-share__title">Share This Property</h4> 1126 1126 <div class="ipp-share__links"> 1127 <a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo $share_url; ?>" target="_blank" rel="noopener noreferrer" class="ipp-share__link ipp-share__link--facebook" title="Share on Facebook">1127 <a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo esc_attr($share_url); ?>" target="_blank" rel="noopener noreferrer" class="ipp-share__link ipp-share__link--facebook" title="Share on Facebook"> 1128 1128 <svg viewBox="0 0 24 24" fill="currentColor"><path d="M18 2h-3a5 5 0 0 0-5 5v3H7v4h3v8h4v-8h3l1-4h-4V7a1 1 0 0 1 1-1h3z"/></svg> 1129 1129 </a> 1130 <a href="https://twitter.com/intent/tweet?url=<?php echo $share_url; ?>&text=<?php echo $share_title; ?>" target="_blank" rel="noopener noreferrer" class="ipp-share__link ipp-share__link--twitter" title="Share on X">1130 <a href="https://twitter.com/intent/tweet?url=<?php echo esc_attr($share_url); ?>&text=<?php echo esc_attr($share_title); ?>" target="_blank" rel="noopener noreferrer" class="ipp-share__link ipp-share__link--twitter" title="Share on X"> 1131 1131 <svg viewBox="0 0 24 24" fill="currentColor"><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/></svg> 1132 1132 </a> 1133 <a href="mailto:?subject=<?php echo $share_title; ?>&body=Check%20out%20this%20property:%20<?php echo $share_url; ?>" class="ipp-share__link ipp-share__link--email" title="Share via Email">1133 <a href="mailto:?subject=<?php echo esc_attr($share_title); ?>&body=Check%20out%20this%20property:%20<?php echo esc_attr($share_url); ?>" class="ipp-share__link ipp-share__link--email" title="Share via Email"> 1134 1134 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect width="20" height="16" x="2" y="4" rx="2"/><path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"/></svg> 1135 1135 </a> … … 1142 1142 1143 1143 <!-- ==================== SCHEMA.ORG ==================== --> 1144 <?php echo $prop->schema_json_ld();?>1144 <?php // Schema.org JSON-LD is printed once, by the wrapper (public/templates/single.php), where the ipp_property_schema filter applies. ?> 1145 1145 1146 1146 </div> -
integrate-palace-properties/tags/3.0.0/public/templates/search-default.php
r3486430 r3694341 60 60 <option value=""><?php esc_html_e( 'All Regions', 'integrate-palace-properties' ); ?></option> 61 61 <?php foreach ( $regions as $region ) : ?> 62 <option value="<?php echo esc_attr( $region->slug ); ?>" <?php selected( isset( $_GET['region'] ) ? sanitize_text_field( $_GET['region']) : '', $region->slug ); ?>>62 <option value="<?php echo esc_attr( $region->slug ); ?>" <?php selected( isset( $_GET['region'] ) ? sanitize_text_field( wp_unslash( $_GET['region'] ) ) : '', $region->slug ); ?>> 63 63 <?php echo esc_html( $region->name ); ?> (<?php echo esc_html( $region->count ); ?>) 64 64 </option> … … 74 74 <option value=""><?php esc_html_e( 'All Types', 'integrate-palace-properties' ); ?></option> 75 75 <?php foreach ( $property_types as $type ) : ?> 76 <option value="<?php echo esc_attr( $type->slug ); ?>" <?php selected( isset( $_GET['property_type'] ) ? sanitize_text_field( $_GET['property_type']) : '', $type->slug ); ?>>76 <option value="<?php echo esc_attr( $type->slug ); ?>" <?php selected( isset( $_GET['property_type'] ) ? sanitize_text_field( wp_unslash( $_GET['property_type'] ) ) : '', $type->slug ); ?>> 77 77 <?php echo esc_html( $type->name ); ?> 78 78 </option> … … 88 88 <option value=""><?php esc_html_e( 'All', 'integrate-palace-properties' ); ?></option> 89 89 <?php foreach ( $statuses as $status ) : ?> 90 <option value="<?php echo esc_attr( $status->slug ); ?>" <?php selected( isset( $_GET['property_status'] ) ? sanitize_text_field( $_GET['property_status']) : '', $status->slug ); ?>>90 <option value="<?php echo esc_attr( $status->slug ); ?>" <?php selected( isset( $_GET['property_status'] ) ? sanitize_text_field( wp_unslash( $_GET['property_status'] ) ) : '', $status->slug ); ?>> 91 91 <?php echo esc_html( $status->name ); ?> 92 92 </option> -
integrate-palace-properties/tags/3.0.0/public/templates/single.php
r3486430 r3694341 6 6 if ( ! defined( 'ABSPATH' ) ) exit; 7 7 8 get_header();8 IntegratePalace_Properties_Public::render_header(); 9 9 10 10 $template_slug = sanitize_text_field( get_option( 'ipp_select_template', 'palace-property' ) ); … … 40 40 // Schema.org structured data — filterable 41 41 $schema = $prop->schema_json_ld(); 42 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Deliberate HTML: a <script type="application/ld+json"> block built by IPP_Property_Helper::schema_json_ld() via wp_json_encode(); escaping would break the structured data. 42 43 echo apply_filters( 'ipp_property_schema', $schema, $post_id ); 43 44 44 get_footer();45 IntegratePalace_Properties_Public::render_footer(); 45 46 ?> -
integrate-palace-properties/tags/3.0.0/readme.txt
r3524450 r3694341 3 3 Tags: palace, property, real-estate, mri-palace, rental 4 4 Requires at least: 5.8 5 Tested up to: 6.95 Tested up to: 7.1 6 6 Requires PHP: 8.0 7 Stable tag: 2.1.67 Stable tag: 3.0.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 13 13 == Description == 14 14 15 Integrate Palace Properties connects your WordPress site to [MRI Palace](https://www.palace.co.nz/) property management software. Properties are automatically synced via a secure cloud-hosted backend, keeping your listings always up to date. 15 Integrate Palace Properties connects your WordPress site to [MRI Palace](https://www.palace.co.nz/) property management software. Your site talks to the Palace API directly using your own Palace credentials — no third-party server sits in between — and keeps your listings up to date on a schedule you choose. 16 17 **This plugin requires an MRI Palace account with API access.** It sends your Palace API username and password to `api.getpalace.com` in order to retrieve your property records, and sends nothing at all until you have entered those credentials. No visitor or site data is ever transmitted. See the External services section below for full detail. MRI Software's [terms of use](https://www.mrisoftware.com/nz/legal-notices/) and [privacy policy](https://www.mrisoftware.com/nz/privacy-policy/) apply to that service. 16 18 17 19 **Key Features:** 18 20 19 * **Automatic Sync** — Properties sync hourly with smart delta detection (only changed properties are updated) 21 * **Automatic Sync** — Your site polls Palace on WP-Cron with smart delta detection (only changed properties are updated) 22 * **No Middleman** — Properties are fetched straight from the Palace API by your own site; nothing is routed through anyone else's server 20 23 * **6 Beautiful Templates** — Palace Property (default), Classic, Modern, Minimal, Grid Gallery, and Developer 21 24 * **AJAX Filtering** — Real-time search, filter by price/bedrooms/bathrooms/region/type/status, sortable … … 32 35 33 36 1. Configure your Palace API credentials in the plugin settings 34 2. The cloud backend fetches properties from Palace API and sends them to your site via webhook 35 3. Properties appear as a custom post type with full filtering and beautiful templates 37 2. On a schedule you choose, your site asks the Palace API which properties are available, and imports the ones that are new or changed 38 3. Properties no longer offered by Palace are removed from your site automatically 39 4. Properties appear as a custom post type with full filtering and beautiful templates 36 40 37 41 == Installation == … … 39 43 1. Upload the plugin files to `/wp-content/plugins/integrate-palace-properties/` or install through the WordPress dashboard. 40 44 2. Activate the plugin through the 'Plugins' screen in WordPress. 41 3. Navigate to **WP Palace Properties → Settings** and enter your Palace API credentials. 42 4. Enter your subscription key (or leave blank for a free plan with 10 properties). 43 5. Click **Save Changes**. Properties will begin syncing automatically. 45 3. Navigate to **WP Palace Properties → Configs** and enter your Palace API username and password. 46 4. Choose how often you want the site to check Palace for changes. Hourly suits most sites. 47 5. Click **Save Changes**. The first sync starts within a minute, and runs on your chosen schedule from then on. 48 49 The plugin is free and has no property limit. You need an MRI Palace account with API access — ask Palace for your API credentials if you do not have them. 44 50 45 51 == Frequently Asked Questions == … … 47 53 = How often do properties sync? = 48 54 49 Properties sync hourly. You can also trigger a manual sync from the Dashboard page. 55 As often as you choose on the Configs page: every 15 minutes, hourly (the default), every 2 hours, twice daily, or daily. You can also trigger a sync immediately with the **Sync Now** button on the Dashboard, or re-import everything with **Full Re-import**. 56 57 Syncing runs on WP-Cron, which WordPress triggers when someone visits your site. On a very quiet site a scheduled sync can therefore run late, and the Dashboard warns you if scheduled syncing appears to have stopped. If punctual syncing matters, ask your host to run WordPress cron from a real server cron job. With WP-CLI you can also run a complete sync in one go with `wp palace-sync run`, and check on it with `wp palace-sync status`. 58 59 = What happens when a property is rented or withdrawn? = 60 61 Palace stops listing it as available, and the plugin moves it to the trash. To guard against a brief glitch in Palace's data removing listings, a property has to be missing from two syncs, at least half a sync interval apart, before it is removed. With the default hourly sync, a rented property typically leaves your site within one to two hours. 62 63 The listing goes to the trash with its images intact, so it can be restored if needed. If Palace lists the property again later, the original entry is restored and updated rather than duplicated. Trashed properties, and their images, are deleted permanently when WordPress empties the trash (after 30 days by default). 64 65 To keep a property on your site regardless, open it in the editor and enable **Lock updates**. A locked property is neither updated nor removed by syncs. If you move a property to the trash yourself, syncs leave it there. 66 67 = Does the plugin send my data anywhere? = 68 69 Your site sends your Palace credentials to the Palace API, and nothing else, to anyone. No data about your site, visitors, or users is sent by the plugin. Visitors' browsers do load Google Maps on property pages and, if you choose one, a Google Font. See the External services section below. 50 70 51 71 = Can I control which properties appear? = 52 72 53 Yes. Use the Display Configuration settings to choose which statuses (Active/Inactive) to sync, and which property details to show on the frontend. 73 The plugin follows the publishing settings you make in Palace. A property whose "publish entry" setting is off is kept on your site as a draft, out of public view, and goes live automatically when you publish it in Palace. A property whose "publish address" setting is off is shown without its street address: its page, map, search results and structured data show the suburb only, and its map is centred on the suburb rather than the exact location. 74 75 The plugin syncs what Palace lists as available, so the place to control which properties appear is Palace itself. On the WordPress side you can hide an individual property from the front end, or lock it so syncs never overwrite your edits, using the options in the property editor. Use the Display Configuration settings to choose which property details are shown. 54 76 55 77 = Can I customize the templates? = … … 60 82 61 83 Yes. The plugin works with both classic and block themes (like Twenty Twenty-Five). 84 85 == External services == 86 87 This plugin connects to the MRI Palace API to fetch the property listings it displays. This is the service your property data already lives in, and the connection is made directly from your own site. 88 89 **What the service is used for:** retrieving your property records and their images so they can be shown on your website. 90 91 **What data is sent, and when:** 92 93 * Your Palace API username and password are sent as an HTTP Basic authorization header with every request, so that Palace can identify your account. They are stored in your site's database and are never transmitted anywhere else. 94 * No data about your site, your visitors, or your WordPress users is ever sent. 95 * Requests are made on the schedule you choose on the Configs page, when you press **Sync Now** or **Test Connection**, and when property images are fetched. 96 97 **Endpoints contacted** (all on `https://api.getpalace.com`): 98 99 * `/Service.svc/RestService/v2AvailableProperties/JSON` — the list of available properties 100 * `/Service.svc/RestService/v2AvailablePropertyImages/JSON/{code}` — images for one property 101 * `/Service.svc/RestService/v2GetCompanyDetailsByAPICredentials/JSON` — used by the Test Connection button 102 103 Nothing is sent until you have entered your Palace credentials; with no credentials configured the plugin makes no external requests at all. 104 105 This service is provided by MRI Software. Terms of use: [https://www.mrisoftware.com/nz/legal-notices/](https://www.mrisoftware.com/nz/legal-notices/) — Privacy policy: [https://www.mrisoftware.com/nz/privacy-policy/](https://www.mrisoftware.com/nz/privacy-policy/) 106 107 **Services loaded by your visitors' browsers** 108 109 These are not contacted by your server, and receive no Palace or site data from the plugin. Like any embedded third-party resource, they receive the visitor's IP address and browser details. 110 111 * **Google Maps** — property pages embed a map of the property's location from `maps.google.com`. The property's address or coordinates are sent in the map URL. Google's [terms of service](https://policies.google.com/terms) and [privacy policy](https://policies.google.com/privacy) apply. 112 * **Google Fonts** — if you choose a Google Font in the plugin's Appearance or template settings, it is loaded from `fonts.googleapis.com` on property pages. Nothing is loaded from Google Fonts unless you select one. Google's [terms of service](https://policies.google.com/terms) and [privacy policy](https://policies.google.com/privacy) apply. 113 114 The single property template also contains Facebook and X (Twitter) share links. These are ordinary links: nothing is sent to either service unless a visitor clicks one. 115 116 No other external service is contacted. 62 117 63 118 == Screenshots == … … 70 125 71 126 == Changelog == 127 128 = 3.0.0 = 129 * **Properties are now fetched directly from the Palace API by your own site.** The external relay service that previously polled Palace and pushed properties to your site over a webhook has been removed entirely. 130 * No subscription key and no account with a third-party service is needed any more, and there is no longer a property limit — the plugin is fully free 131 * New **Sync Frequency** setting: every 15 minutes, hourly, every 2 hours, twice daily or daily 132 * Imports and removals run in time-limited slices across cron ticks, so a large library imports in a few ticks rather than one batch per visit, without long-running requests 133 * **Full Re-import** button to refresh every property from Palace regardless of what has already been synced 134 * WP-CLI commands: `wp palace-sync run [--force]` completes a whole sync in one process, `wp palace-sync status` reports the last result and when the next check is due 135 * The Dashboard warns when scheduled syncing appears to have stopped (for example `DISABLE_WP_CRON` without a server cron job), and when a sync started but never finished, which usually means the host stopped the request 136 * Syncs take a lock, so two overlapping cron requests can never import, or confirm a removal, at the same time 137 * Locked properties are no longer removed when Palace stops listing them, and a property you trash yourself stays in the trash 138 * A property whose import is interrupted part-way is retried on the next sync, rather than being treated as up to date 139 * Properties that fail to save are reported on the Dashboard with the reason, and retried automatically 140 * Gallery sync: a Palace error response can no longer wipe a property's existing photos, large photos are no longer re-downloaded on every sync, and memory use for big galleries is much lower 141 * Fixed a fatal error in uninstall.php on PHP 8 that stopped settings and scheduled events being cleaned up, and uninstalling with data removal now also deletes properties in the trash and their images 142 * Google Fonts chosen in the Customizer now load through the standard WordPress stylesheet queue 143 * A property that Palace re-lists after it was removed is now restored and published, even when nothing about it changed while it was off the market (previously it could come back as a hidden draft) 144 * Property pages on block themes (such as Twenty Twenty-Five) now use the theme's real header and footer, with proper header and footer landmarks, instead of WordPress's bare fallback header 145 * Schema.org structured data is now printed once per property page instead of twice, and the `ipp_property_schema` filter applies to all of it 146 * Two safety guards against a bad response from Palace emptying your site: a property must be missing from two consecutive syncs before it is removed, and a sync that would remove an implausible share of your library is held back and reported instead 147 * Removed properties are moved to the trash and keep their images, so a listing removed in error can be restored intact. Images are only deleted when the property is deleted permanently 148 * A property that is re-listed by Palace after being removed now reuses its original entry instead of creating a duplicate 149 * The Dashboard and Configs pages now report real sync results — when the last run happened, how many properties were updated and removed, when the next check is due, and the reason for any failure 150 * Scheduled events are now cleared properly when the plugin is deactivated 151 * Your Palace password is no longer rendered back into the settings page; leave the field blank to keep the saved one 152 * macOS `.DS_Store` files are no longer included in the plugin package 153 * **Follows Palace's publishing settings.** A listing Palace marks as not to be published online is kept as a draft, out of public view, and published automatically once the agency publishes it in Palace. A listing whose address Palace marks as not to be published no longer shows its street address, unit or exact location anywhere: pages, maps (centred on the suburb instead), search, the REST API and structured data. Previous versions published both regardless. 154 * The REST API's single-property and gallery endpoints, and the `[palace_property]`, `[palace_property_field]` and `[palace_agent]` shortcodes, no longer serve an unpublished listing to visitors who ask for it by ID 155 * Pets and smoking policies now show Palace's own wording, such as "By consent", instead of treating anything other than "Yes" as not allowed. Several templates also showed "1" instead of "Yes"; that is fixed. 156 * After updating, every property is re-imported once in the background so the settings above apply to existing listings. Photos already on the site are kept, not downloaded again. 157 * Image downloads after a large import no longer risk being cut off by the host: once a cron request has been busy for a while, remaining image jobs wait for the next run instead of being lost 158 * Removed the "Property Statuses to Sync" and "Include Archived Properties" settings. They were never connected to anything — the plugin syncs what the Palace available-properties feed contains — so they promised control they did not provide. To filter what is imported, use the `ipp_sync_fetched_properties` filter documented in DEVELOPERS.md. 159 * Fixed the Dashboard's "Visible on Frontend" figure, which assumed a status filter that was never applied 160 * **Security:** hardened the Schema.org JSON-LD output. A property whose name or address contained the text `</script>` could previously break out of the structured-data block, which made the Palace feed a potential source of injected markup 161 * **Security:** front-end search and filter parameters are now unslashed as well as sanitized 162 * **Security:** the inbound webhook endpoint has been removed. It was authenticated with a shared secret issued by the relay service, so with that service gone the endpoint could no longer verify anything. Nothing pushes to your site any more — your site does the asking. 163 164 **Upgrading:** enter your Palace API username and password on the Configs page if they are not already saved, then press Save Changes. Your existing properties, images and settings are preserved. 72 165 73 166 = 2.1.6 = … … 127 220 == Upgrade Notice == 128 221 222 = 3.0.0 = 223 Syncs directly from Palace, with no relay or property limit. Now follows Palace's publish settings: unpublished listings become drafts and hidden addresses are no longer shown. Check your Palace credentials on the Configs page after updating. 224 129 225 = 2.1.0 = 130 226 Gallery sync reliability improvements, progress tracking dashboard, and critical bug fixes. Recommended update for all users. -
integrate-palace-properties/tags/3.0.0/uninstall.php
r3486430 r3694341 20 20 21 21 // 1. Delete all palace-properties posts and their meta 22 // List every status explicitly: 'any' excludes the trash, and syncs move 23 // properties Palace no longer lists into the trash. Those, and their images, 24 // would otherwise survive an uninstall that was asked to remove all data. 22 25 $posts = get_posts( array( 23 26 'post_type' => 'palace-properties', 24 27 'posts_per_page' => -1, 25 'post_status' => 'any',28 'post_status' => array( 'publish', 'draft', 'pending', 'private', 'future', 'trash', 'auto-draft' ), 26 29 'fields' => 'ids', 27 30 ) ); … … 79 82 'ipp_remove_data_on_uninstall', 80 83 'ipp_settings', 81 IPPR_SETTINGS ?? 'ippr-template-settings', 84 'ipp_sync_interval', 85 'ipp_sync_state', 86 'ipp_sync_last_run', 87 'ipp_sync_blocked_deletions', 88 'ipp_sync_missing', 89 'ipp_sync_lock', 90 'ipp_sync_force_pending', 91 'ipp_sync_last_attempt', 92 'ipp_registered_site_url', 93 // The main plugin file (where IPPR_SETTINGS is defined) is not loaded during 94 // uninstall, and on PHP 8 an undefined constant is a fatal error even with ??. 95 'ippr-template-settings', 82 96 ); 83 97 … … 95 109 96 110 // 5. Clear scheduled events 97 wp_clear_scheduled_hook( 'update_integrate_palace_gallery' ); 111 wp_unschedule_hook( 'update_integrate_palace_gallery' ); // Events carry args, so clear by hook. 112 wp_clear_scheduled_hook( 'ipp_sync_properties' ); 113 wp_clear_scheduled_hook( 'ipp_sync_process_batch' ); 98 114 wp_clear_scheduled_hook( 'integrate_palace_update_gallery' ); // legacy misnamed hook 99 115 wp_clear_scheduled_hook( 'ipp_process_gallery_image' ); // legacy Phase 2 hook … … 101 117 // 6. Clean up transients 102 118 delete_transient( 'ipp_gallery_api_last_call' ); 119 delete_transient( 'ipp_api_last_call' ); 120 delete_transient( 'ipp_schedule_checked' ); 121 122 // Queued sync batches are stored as transients keyed by run ID, so they have to 123 // be matched by prefix rather than deleted by name. 124 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- One-off cleanup on uninstall; no caching layer applies. 125 $wpdb->query( 126 "DELETE FROM {$wpdb->options} 127 WHERE option_name LIKE '\_transient\_ipp\_sync\_batch\_%' 128 OR option_name LIKE '\_transient\_timeout\_ipp\_sync\_batch\_%'" 129 ); 103 130 104 131 // 6. Flush rewrite rules -
integrate-palace-properties/trunk/admin/class-integratepalacep-admin-ajax.php
r3486430 r3694341 6 6 public static function init() { 7 7 add_action( 'wp_ajax_ipp_trigger_sync', array( __CLASS__, 'trigger_sync' ) ); 8 add_action( 'wp_ajax_ipp_force_sync', array( __CLASS__, 'force_sync' ) ); 8 9 add_action( 'wp_ajax_ipp_get_sync_status', array( __CLASS__, 'get_sync_status' ) ); 9 10 add_action( 'wp_ajax_ipp_test_connection', array( __CLASS__, 'test_connection' ) ); … … 14 15 15 16 /** 16 * Trigger a property sync via the Laravel API.17 * Start a sync run against the Palace API straight away. 17 18 */ 18 19 public static function trigger_sync() { … … 23 24 } 24 25 25 $api_base = defined( 'IPP_API_URL' ) ? IPP_API_URL : 'https://wp-palace.kiwibrain.co.nz'; 26 $sub_key = get_option( 'integrate_palace_properties_subscription_key', '' ); 27 28 if ( empty( $sub_key ) ) { 29 wp_send_json_error( __( 'No subscription key configured.', 'integrate-palace-properties' ) ); 30 } 31 32 // Call the Laravel API to trigger sync 33 $response = wp_remote_post( $api_base . '/api/sync/trigger', array( 34 'method' => 'POST', 35 'headers' => array( 36 'Content-Type' => 'application/json', 37 'X-Subscription-Key' => sanitize_text_field( $sub_key ), 38 ), 39 'body' => wp_json_encode( array( 40 'subscription_key' => sanitize_text_field( $sub_key ), 41 ) ), 42 'timeout' => 30, 43 ) ); 26 if ( ! IPP_Sync::has_credentials() ) { 27 wp_send_json_error( __( 'Add your Palace API username and password on the Configs page first.', 'integrate-palace-properties' ) ); 28 } 29 30 if ( IPP_Sync::is_running() ) { 31 $progress = IPP_Sync::get_progress(); 32 wp_send_json_success( array( 33 'message' => sprintf( 34 /* translators: 1: batches completed, 2: total batches. */ 35 __( 'A sync is already running — batch %1$d of %2$d.', 'integrate-palace-properties' ), 36 (int) $progress['done'], 37 (int) $progress['total'] 38 ), 39 'running' => true, 40 ) ); 41 } 42 43 // Do not run the sync inline. Fetching the full property list can take 44 // minutes, and admin-ajax would hit the host's gateway timeout first — 45 // the user would see "Request failed" for a sync that is actually fine. 46 // Hand it to cron and return immediately. 47 // The args array( false ) matter. WordPress refuses a single event that 48 // matches an existing one (same hook and args) within ten minutes, so 49 // scheduling with no args was silently ignored whenever the recurring 50 // event happened to be due soon. 51 wp_schedule_single_event( time() + 1, IPP_Sync::CRON_HOOK, array( false ) ); 52 spawn_cron(); 44 53 45 54 $prop_count = wp_count_posts( 'palace-properties' ); 46 $count = isset( $prop_count->publish ) ? $prop_count->publish : 0; 47 48 if ( is_wp_error( $response ) ) { 49 wp_send_json_error( sprintf( 50 /* translators: %s: error message */ 51 __( 'Sync request failed: %s. You have %d properties locally.', 'integrate-palace-properties' ), 52 $response->get_error_message(), 53 $count 54 ) ); 55 } 56 57 $status_code = wp_remote_retrieve_response_code( $response ); 58 59 if ( $status_code < 200 || $status_code >= 300 ) { 60 wp_send_json_error( sprintf( 61 /* translators: %d: HTTP status code, %d: property count */ 62 __( 'Sync request returned HTTP %1$d. You have %2$d properties locally.', 'integrate-palace-properties' ), 63 $status_code, 64 $count 65 ) ); 66 } 67 68 // Only update last sync time on actual success 69 update_option( 'ipp_last_sync_time', current_time( 'mysql' ) ); 70 update_option( 'ipp_last_sync_count', $count ); 71 72 wp_send_json_success( array( 73 'message' => __( 'Resync requested from Palace server.', 'integrate-palace-properties' ), 74 'count' => $count, 75 'api_status' => $status_code, 55 $count = isset( $prop_count->publish ) ? (int) $prop_count->publish : 0; 56 57 wp_send_json_success( array( 58 'message' => __( 'Sync queued. Properties will import over the next few minutes.', 'integrate-palace-properties' ), 59 'count' => $count, 60 'running' => true, 61 ) ); 62 } 63 64 /** 65 * Queue a full re-import that ignores change codes. 66 * 67 * For recovering from damaged or hand-edited property data. It replaces any 68 * sync already in progress. 69 */ 70 public static function force_sync() { 71 check_ajax_referer( 'ipp_admin_nonce', 'nonce' ); 72 73 if ( ! current_user_can( 'manage_options' ) ) { 74 wp_send_json_error( __( 'Permission denied.', 'integrate-palace-properties' ) ); 75 } 76 77 if ( ! IPP_Sync::has_credentials() ) { 78 wp_send_json_error( __( 'Add your Palace API username and password on the Configs page first.', 'integrate-palace-properties' ) ); 79 } 80 81 wp_schedule_single_event( time() + 1, IPP_Sync::CRON_HOOK, array( true ) ); 82 spawn_cron(); 83 84 wp_send_json_success( array( 85 'message' => __( 'Full re-import queued. Every property will be refreshed from Palace over the next few minutes.', 'integrate-palace-properties' ), 86 'running' => true, 76 87 ) ); 77 88 } -
integrate-palace-properties/trunk/admin/class-integratepalacep-admin.php
r3524333 r3694341 29 29 } 30 30 31 // WP-Cron runs every due event in one request. After a big import that is 32 // one image job per property, each fetching several megabytes: measured 33 // against the real Palace API, 30 jobs took about 150 seconds in a single 34 // request, far past typical host limits. A job killed part-way is lost, 35 // because WordPress unschedules an event before running it. So once this 36 // request has been busy for a while, defer to the next cron run instead. 37 // WP-CLI and manual runs have no such limit and are not deferred. 38 if ( wp_doing_cron() && timer_float() > self::gallery_time_budget() ) { 39 wp_schedule_single_event( time() + MINUTE_IN_SECONDS, 'update_integrate_palace_gallery', array( $post_id, $property_code ) ); 40 self::update_gallery_sync_status( $post_id, 'queued', 'Queued for the next cron run.' ); 41 return; 42 } 43 31 44 self::update_gallery_sync_status( $post_id, 'syncing', 'Fetching image list from Palace API...' ); 32 45 … … 42 55 $api_url = "https://api.getpalace.com/Service.svc/RestService/v2AvailablePropertyImages/JSON/$property_code"; 43 56 $headers = array( 'Authorization' => 'Basic ' . base64_encode( "$username:$password" ) ); 44 // Throttle: respect Palace API rate limits during batch operations 45 $last_call = get_transient( 'ipp_gallery_api_last_call' ); 57 58 // Share one throttle with the property-list sync (IPP_Sync::request()), 59 // so the two never hit Palace at the same moment. 60 $last_call = get_transient( 'ipp_api_last_call' ); 46 61 if ( $last_call && ( microtime( true ) - (float) $last_call ) < 1.5 ) { 47 62 usleep( 1500000 ); // 1.5s minimum gap between API calls … … 49 64 50 65 $response = wp_remote_get( $api_url, array( 'headers' => $headers, 'timeout' => 60 ) ); 51 set_transient( 'ipp_gallery_api_last_call', microtime( true ), 60 ); 52 53 if ( is_wp_error( $response ) ) { 54 $error_msg = $response->get_error_message(); 66 set_transient( 'ipp_api_last_call', microtime( true ), 60 ); 67 68 // Treat an HTTP error (401, 429, 500...) exactly like a transport error. 69 // Only transport errors used to be caught, so an error body was parsed 70 // as the image list, yielded no valid images, and the entire existing 71 // gallery was deleted. 72 $http_code = is_wp_error( $response ) ? 0 : (int) wp_remote_retrieve_response_code( $response ); 73 74 if ( is_wp_error( $response ) || $http_code < 200 || $http_code >= 300 ) { 75 $error_msg = is_wp_error( $response ) ? $response->get_error_message() : 'HTTP ' . $http_code; 55 76 error_log( 'IPP Gallery: API error — ' . $error_msg ); 56 77 … … 70 91 71 92 $images = json_decode( wp_remote_retrieve_body( $response ), true ); 93 unset( $response ); // The body holds every photo base64-encoded; free it now. 94 72 95 if ( empty( $images ) ) { 73 96 // Don't touch existing gallery — API may just have no data right now. … … 76 99 } 77 100 78 // Build map of existing gallery attachments by filename 101 // Palace returns a JSON list of image records. Anything else (an error 102 // envelope, a single object) is not an image list and must not be allowed 103 // anywhere near the existing gallery. 104 if ( ! is_array( $images ) || array_values( $images ) !== $images ) { 105 self::update_gallery_sync_status( $post_id, 'failed', 'Unexpected response from the Palace images API. The existing gallery was left untouched.' ); 106 return; 107 } 108 109 // Map existing attachments by their Palace image code. Matching on the file 110 // name broke whenever WordPress renamed an upload ("-scaled" for large 111 // photos, or "-1" on a name clash), and every such image was downloaded 112 // and re-created again on each sync. 79 113 $gallery = get_post_meta( $post_id, 'integrate_palace_gallery', true ); 80 114 if ( ! is_array( $gallery ) ) { … … 83 117 $existing = array(); 84 118 foreach ( $gallery as $att_id ) { 85 $url = wp_get_attachment_url( $att_id ); 86 if ( $url ) { 87 $existing[ basename( $url ) ] = $att_id; 88 } 89 } 90 91 if ( ! function_exists( 'pp_get_image_extension' ) ) { 92 function pp_get_image_extension( $base64_string ) { 93 $img_info = getimagesizefromstring( base64_decode( $base64_string ) ); 94 return $img_info ? image_type_to_extension( $img_info[2], false ) : 'jpg'; 95 } 119 $att_id = (int) $att_id; 120 $code = (string) get_post_meta( $att_id, 'ipp_image_code', true ); 121 122 if ( '' === $code ) { 123 // Attachments created before 3.0.0 have no stored code: fall back 124 // to the file name, which was "{image code}.{extension}". 125 $url = wp_get_attachment_url( $att_id ); 126 if ( ! $url ) { 127 continue; 128 } 129 $code = preg_replace( '/(-scaled)?\.[a-z0-9]+$/i', '', basename( $url ) ); 130 } 131 132 $existing[ $code ] = $att_id; 96 133 } 97 134 … … 105 142 $processed = 0; 106 143 107 foreach ( $images as $image ) { 144 // array_shift() releases each photo's base64 once it is handled, rather 145 // than holding every image of a large gallery in memory at once. 146 while ( null !== ( $image = array_shift( $images ) ) ) { 147 if ( ! is_array( $image ) ) { 148 $errors[] = 'unknown: not an image record'; 149 continue; 150 } 151 108 152 $image_code = sanitize_file_name( $image['PropertyImageCode'] ?? '' ); 109 153 $base64 = $image['PropertyImageBase64'] ?? ''; 154 unset( $image ); 110 155 111 156 if ( empty( $image_code ) || empty( $base64 ) ) { … … 114 159 } 115 160 116 $file_extension = pp_get_image_extension( $base64 ); 117 $filename = "$image_code.$file_extension"; 118 119 if ( isset( $existing[ $filename ] ) ) { 120 $kept[] = $existing[ $filename ]; 121 unset( $existing[ $filename ] ); 161 if ( isset( $existing[ $image_code ] ) ) { 162 // Already downloaded: keep it without decoding anything. 163 $kept[] = $existing[ $image_code ]; 164 unset( $existing[ $image_code ] ); 122 165 } else { 123 166 $image_data = base64_decode( $base64 ); 167 unset( $base64 ); 168 124 169 if ( empty( $image_data ) ) { 125 $errors[] = $ filename . ': decode failed';170 $errors[] = $image_code . ': decode failed'; 126 171 continue; 127 172 } 128 173 174 $img_info = getimagesizefromstring( $image_data ); 175 $file_extension = $img_info ? image_type_to_extension( $img_info[2], false ) : 'jpg'; 176 $filename = "$image_code.$file_extension"; 177 129 178 $upload = wp_upload_bits( $filename, null, $image_data ); 179 unset( $image_data ); 180 130 181 if ( $upload['error'] ) { 131 182 $errors[] = $filename . ': ' . $upload['error']; … … 140 191 141 192 if ( ! is_wp_error( $attach_id ) ) { 193 update_post_meta( $attach_id, 'ipp_image_code', $image_code ); 142 194 $meta = wp_generate_attachment_metadata( $attach_id, $upload['file'] ); 143 195 wp_update_attachment_metadata( $attach_id, $meta ); … … 155 207 } 156 208 209 // Nothing usable came back, but the property already has photos: keep them. 210 // Never replace a working gallery with an empty one. 211 if ( empty( $kept ) && ! empty( $gallery ) ) { 212 $msg = '0/' . $total . ' images could be saved, so the existing gallery was left untouched.'; 213 if ( count( $errors ) > 0 ) { 214 $msg .= ' Errors: ' . implode( '; ', array_slice( $errors, 0, 3 ) ); 215 } 216 self::update_gallery_sync_status( $post_id, 'failed', $msg, 0, $total ); 217 return; 218 } 219 157 220 // Finalize gallery 158 221 $new_gallery = $kept; … … 164 227 update_post_meta( $post_id, 'integrate_palace_gallery', $new_gallery ); 165 228 166 // Delete orphaned old images 229 // Delete images Palace no longer lists. Anything still in $existing was 230 // absent from the response entirely; images that are listed but failed 231 // to download were never in $existing, so a partial failure cannot 232 // remove photos that are still current. 167 233 foreach ( $existing as $old_id ) { 168 234 wp_delete_attachment( $old_id, true ); … … 188 254 /** @hook ipp_gallery_updated */ 189 255 do_action( 'ipp_gallery_updated', $post_id, $new_gallery ); 256 } 257 258 /** 259 * Seconds a cron request may spend before image jobs defer to the next run. 260 * 261 * @return int 262 */ 263 private static function gallery_time_budget() { 264 /** 265 * Filter how long one cron request keeps processing image jobs. 266 * 267 * Keep it comfortably below the host's PHP request timeout. 268 * 269 * @param int $seconds Defaults to 20. 270 */ 271 return max( 5, (int) apply_filters( 'ipp_gallery_tick_seconds', 20 ) ); 190 272 } 191 273 … … 238 320 if (strpos($file, 'integrate-palace-properties') !== false) { 239 321 $new_links = array( 240 '<a target="_blank" href="https://wp-palace.kiwibrain.co.nz/register"><b>Go Pro</b></a>', 241 '<a href="mailto:itsisaf@gmail.com">Support</a>', 242 '<a target="_blank" href="https://wp-palace.kiwibrain.co.nz">View details</a>', 243 '<a href="' . esc_url( admin_url( 'admin.php?page=ipp-developer-docs' ) ) . '">Developer Docs</a>', 322 '<a href="' . esc_url( admin_url( 'admin.php?page=integrate-palace-properties-configs' ) ) . '">' . esc_html__( 'Settings', 'integrate-palace-properties' ) . '</a>', 323 '<a href="mailto:itsisaf@gmail.com">' . esc_html__( 'Support', 'integrate-palace-properties' ) . '</a>', 324 '<a href="' . esc_url( admin_url( 'admin.php?page=ipp-developer-docs' ) ) . '">' . esc_html__( 'Developer Docs', 'integrate-palace-properties' ) . '</a>', 244 325 ); 245 326 $links = array_merge($links, $new_links); -
integrate-palace-properties/trunk/admin/class-integratepalacep-dashboard.php
r3486430 r3694341 10 10 11 11 // ─── Gather Data ──────────────────────────────────────────── 12 $status_html = get_option( 'integrate_palace_properties_webhook_status', '' ); 13 $is_connected = strpos( $status_html, 'wh_connected' ) !== false; 12 // "Connected" now means the site has Palace credentials it can poll with. 13 $is_connected = IPP_Sync::has_credentials(); 14 $last_run = IPP_Sync::get_last_run(); 15 $sync_running = IPP_Sync::is_running(); 16 $sync_progress = IPP_Sync::get_progress(); 17 $next_sync = wp_next_scheduled( IPP_Sync::CRON_HOOK ); 14 18 $template = get_option( 'ipp_select_template', 'palace-property' ); 15 19 $last_sync = get_option( 'ipp_last_sync_time', '' ); 16 20 $last_sync_count = get_option( 'ipp_last_sync_count', 0 ); 17 $webhook_url = get_option( 'integrate_palace_properties_webhook_url', '' );18 $blog_id = get_option( 'integrate_palace-palace-unique-id', '' );19 $sub_key = get_option( 'integrate_palace_properties_subscription_key', '' );20 21 $slug = get_option( 'integrate_palace_properties_slug', 'palace-property' ); 21 22 $default_fields = IntegratePalace_Properties_Settings::get_default_display_fields(); 22 23 $display_fields = get_option( 'ipp_display_fields', $default_fields ); 23 24 if ( empty( $display_fields ) ) $display_fields = $default_fields; // treat empty as "all defaults" 24 $sync_archived = get_option( 'ipp_sync_archived', 'no' );25 25 26 26 // Property counts … … 63 63 $archive_url = get_post_type_archive_link( 'palace-properties' ); 64 64 $rest_url = rest_url( 'palace-properties/v1/properties' ); 65 $api_base = defined( 'IPP_API_URL' ) ? IPP_API_URL : 'https://wp-palace.kiwibrain.co.nz';66 65 67 66 // Count pending gallery cron events (lightweight — no cleanup on page load) … … 169 168 <span class="dashicons dashicons-update"></span> <?php esc_html_e( 'Sync Now', 'integrate-palace-properties' ); ?> 170 169 </button> 170 <button type="button" id="ipp-force-sync" class="button" <?php echo $is_connected ? '' : 'disabled'; ?>> 171 <span class="dashicons dashicons-backup" style="margin-top:3px;"></span> <?php esc_html_e( 'Full Re-import', 'integrate-palace-properties' ); ?> 172 </button> 171 173 <button type="button" id="ipp-resync-galleries" class="button"> 172 174 <span class="dashicons dashicons-format-gallery" style="margin-top:3px;"></span> <?php esc_html_e( 'Resync Galleries', 'integrate-palace-properties' ); ?> … … 178 180 </div> 179 181 </div> 182 183 <?php 184 // WP-Cron only runs when the site gets visits, or from a real server 185 // cron. If the scheduled check is long overdue, syncing has stalled, 186 // and with no relay any more the owner is the only one who can fix it. 187 $ipp_schedules = wp_get_schedules(); 188 $ipp_interval = IPP_Sync::get_interval(); 189 $ipp_interval_secs = isset( $ipp_schedules[ $ipp_interval ]['interval'] ) ? (int) $ipp_schedules[ $ipp_interval ]['interval'] : HOUR_IN_SECONDS; 190 $ipp_cron_overdue = $is_connected && $next_sync && ( time() - $next_sync ) > 2 * $ipp_interval_secs; 191 if ( $ipp_cron_overdue ) : 192 ?> 193 <div class="notice notice-warning inline" style="margin:0 0 20px;"> 194 <p> 195 <strong><?php esc_html_e( 'Scheduled syncing appears to have stopped.', 'integrate-palace-properties' ); ?></strong> 196 <?php 197 if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) { 198 esc_html_e( 'This site sets DISABLE_WP_CRON, so a server cron job must call wp-cron.php, and it does not seem to be running. Ask your host to set one up. Use Sync Now in the meantime.', 'integrate-palace-properties' ); 199 } else { 200 esc_html_e( 'The last check is well overdue. WP-Cron only runs when the site receives visits, so a quiet site, or one whose loopback requests are blocked, can stop syncing. Ask your host to run WordPress cron from a server cron job. Use Sync Now in the meantime.', 'integrate-palace-properties' ); 201 } 202 ?> 203 </p> 204 </div> 205 <?php endif; ?> 206 207 <?php $ipp_unfinished = IPP_Sync::get_unfinished_attempt(); ?> 208 <?php if ( $is_connected && $ipp_unfinished ) : ?> 209 <div class="notice notice-error inline" style="margin:0 0 20px;"> 210 <p> 211 <strong><?php esc_html_e( 'The last sync did not finish.', 'integrate-palace-properties' ); ?></strong> 212 <?php 213 printf( 214 /* translators: %s: human-readable time since the sync started, e.g. "2 hours". */ 215 esc_html__( 'It started %s ago but never recorded a result, which usually means the host stopped the request while it was fetching properties from Palace. Try Sync Now. If it keeps happening, ask your host to raise the PHP request timeout, or to run WordPress cron from a server cron job.', 'integrate-palace-properties' ), 216 esc_html( human_time_diff( $ipp_unfinished, time() ) ) 217 ); 218 ?> 219 </p> 220 </div> 221 <?php endif; ?> 222 223 <script> 224 jQuery( function ( $ ) { 225 $( '#ipp-force-sync' ).on( 'click', function () { 226 var $btn = $( this ), $status = $( '#ipp-sync-status' ); 227 if ( ! window.confirm( '<?php echo esc_js( __( 'Re-import every property from Palace, ignoring what has already been synced? This replaces any sync in progress and can take several minutes on a large library.', 'integrate-palace-properties' ) ); ?>' ) ) { 228 return; 229 } 230 $btn.prop( 'disabled', true ); 231 $status.text( '<?php echo esc_js( __( 'Queuing full re-import...', 'integrate-palace-properties' ) ); ?>' ).removeClass( 'success error' ); 232 $.post( ajaxurl, { 233 action: 'ipp_force_sync', 234 nonce: '<?php echo esc_js( wp_create_nonce( 'ipp_admin_nonce' ) ); ?>' 235 } ).done( function ( r ) { 236 $btn.prop( 'disabled', false ); 237 if ( r.success ) { 238 $status.text( r.data.message ).addClass( 'success' ); 239 setTimeout( function () { window.location.reload(); }, 4000 ); 240 } else { 241 $status.text( r.data || 'Request failed' ).addClass( 'error' ); 242 } 243 } ).fail( function () { 244 $btn.prop( 'disabled', false ); 245 $status.text( 'Request failed' ).addClass( 'error' ); 246 } ); 247 } ); 248 } ); 249 </script> 180 250 181 251 <?php … … 189 259 } 190 260 } 191 $visible_on_frontend = ( $sync_archived === 'yes' ) ? ( $published - $hidden ) : ( $active_count - $hidden ); 261 // Every published property is shown unless it has been hidden in 262 // the editor — the front end does not filter by Palace status. 263 $visible_on_frontend = $published - $hidden; 192 264 if ( $visible_on_frontend < 0 ) $visible_on_frontend = 0; 193 265 ?> … … 234 306 <div class="ippd-grid ippd-grid--2"> 235 307 236 <!-- Connection & Webhook-->308 <!-- Palace API Connection --> 237 309 <div class="ippd-card"> 238 310 <div class="ippd-card__head"> 239 <h3><span class="dashicons dashicons-cloud"></span> <?php esc_html_e( ' Connection & Webhook', 'integrate-palace-properties' ); ?></h3>311 <h3><span class="dashicons dashicons-cloud"></span> <?php esc_html_e( 'Palace API Connection', 'integrate-palace-properties' ); ?></h3> 240 312 <span class="ippd-badge <?php echo $is_connected ? 'ippd-badge--green' : 'ippd-badge--red'; ?>"> 241 313 <span class="ippd-dot <?php echo $is_connected ? 'ippd-dot--green' : 'ippd-dot--red'; ?>"></span> 242 <?php echo $is_connected ? esc_html__( 'C onnected', 'integrate-palace-properties' ) : esc_html__( 'Disconnected', 'integrate-palace-properties' ); ?>314 <?php echo $is_connected ? esc_html__( 'Credentials set', 'integrate-palace-properties' ) : esc_html__( 'Not configured', 'integrate-palace-properties' ); ?> 243 315 </span> 244 316 </div> 245 317 <div class="ippd-card__body"> 246 318 <div class="ippd-kv"> 247 <span class="ippd-kv__label"><span class="dashicons dashicons-admin-links"></span> API Endpoint</span> 248 <span class="ippd-kv__value"><code><?php echo esc_html( parse_url( $api_base, PHP_URL_HOST ) ?: $api_base ); ?></code></span> 249 </div> 250 <div class="ippd-kv"> 251 <span class="ippd-kv__label"><span class="dashicons dashicons-admin-site"></span> Webhook URL</span> 252 <span class="ippd-kv__value" title="<?php echo esc_attr( $webhook_url ); ?>"><?php echo $webhook_url ? '<code>' . esc_html( wp_parse_url( $webhook_url, PHP_URL_PATH ) ) . '</code>' : '<em>Not set</em>'; ?></span> 253 </div> 254 <div class="ippd-kv"> 255 <span class="ippd-kv__label"><span class="dashicons dashicons-nametag"></span> Blog ID</span> 256 <span class="ippd-kv__value"><code><?php echo esc_html( substr( $blog_id, 0, 8 ) . '...' ); ?></code></span> 257 </div> 258 <div class="ippd-kv"> 259 <span class="ippd-kv__label"><span class="dashicons dashicons-lock"></span> Subscription Key</span> 260 <span class="ippd-kv__value"><?php echo $sub_key ? '<span class="ippd-badge ippd-badge--green">Configured</span>' : '<span class="ippd-badge ippd-badge--red">Missing</span>'; ?></span> 261 </div> 262 <div class="ippd-kv"> 263 <span class="ippd-kv__label"><span class="dashicons dashicons-shield"></span> Webhook Auth</span> 264 <span class="ippd-kv__value"><?php echo get_option( 'integrate_palace_webhook_secret' ) ? '<span class="ippd-badge ippd-badge--green">HMAC Enabled</span>' : '<span class="ippd-badge ippd-badge--yellow">Open</span>'; ?></span> 265 </div> 266 <div class="ippd-kv"> 267 <span class="ippd-kv__label"><span class="dashicons dashicons-rest-api"></span> REST API</span> 319 <span class="ippd-kv__label"><span class="dashicons dashicons-admin-links"></span> <?php esc_html_e( 'API Endpoint', 'integrate-palace-properties' ); ?></span> 320 <span class="ippd-kv__value"><code>api.getpalace.com</code></span> 321 </div> 322 <div class="ippd-kv"> 323 <span class="ippd-kv__label"><span class="dashicons dashicons-update"></span> <?php esc_html_e( 'Sync Method', 'integrate-palace-properties' ); ?></span> 324 <span class="ippd-kv__value"><?php esc_html_e( 'Scheduled, direct from this site', 'integrate-palace-properties' ); ?></span> 325 </div> 326 <div class="ippd-kv"> 327 <span class="ippd-kv__label"><span class="dashicons dashicons-clock"></span> <?php esc_html_e( 'Next Check', 'integrate-palace-properties' ); ?></span> 328 <span class="ippd-kv__value"> 329 <?php 330 if ( $sync_running ) { 331 printf( 332 /* translators: 1: batches done, 2: total batches. */ 333 esc_html__( 'Importing — batch %1$d of %2$d', 'integrate-palace-properties' ), 334 (int) $sync_progress['done'], 335 (int) $sync_progress['total'] 336 ); 337 } elseif ( $next_sync ) { 338 echo esc_html( human_time_diff( time(), $next_sync ) ); 339 } else { 340 echo '<em>' . esc_html__( 'Not scheduled', 'integrate-palace-properties' ) . '</em>'; 341 } 342 ?> 343 </span> 344 </div> 345 <div class="ippd-kv"> 346 <span class="ippd-kv__label"><span class="dashicons dashicons-yes-alt"></span> <?php esc_html_e( 'Last Result', 'integrate-palace-properties' ); ?></span> 347 <span class="ippd-kv__value"> 348 <?php 349 if ( empty( $last_run ) ) { 350 echo '<em>' . esc_html__( 'No sync yet', 'integrate-palace-properties' ) . '</em>'; 351 } elseif ( isset( $last_run['status'] ) && 'failed' === $last_run['status'] ) { 352 echo '<span class="ippd-badge ippd-badge--red">' . esc_html__( 'Failed', 'integrate-palace-properties' ) . '</span>'; 353 } elseif ( isset( $last_run['status'] ) && 'warning' === $last_run['status'] ) { 354 echo '<span class="ippd-badge ippd-badge--yellow">' . esc_html__( 'Needs attention', 'integrate-palace-properties' ) . '</span>'; 355 } else { 356 printf( 357 /* translators: 1: properties updated, 2: properties removed. */ 358 esc_html__( '%1$d updated, %2$d removed', 'integrate-palace-properties' ), 359 isset( $last_run['imported'] ) ? (int) $last_run['imported'] : 0, 360 isset( $last_run['deleted'] ) ? (int) $last_run['deleted'] : 0 361 ); 362 } 363 ?> 364 </span> 365 </div> 366 <?php if ( ! empty( $last_run['message'] ) && isset( $last_run['status'] ) && in_array( $last_run['status'], array( 'failed', 'warning' ), true ) ) : ?> 367 <div class="ippd-kv"> 368 <span class="ippd-kv__label"><span class="dashicons dashicons-warning"></span> <?php esc_html_e( 'Details', 'integrate-palace-properties' ); ?></span> 369 <span class="ippd-kv__value"><?php echo esc_html( $last_run['message'] ); ?></span> 370 </div> 371 <?php endif; ?> 372 <div class="ippd-kv"> 373 <span class="ippd-kv__label"><span class="dashicons dashicons-rest-api"></span> <?php esc_html_e( 'REST API', 'integrate-palace-properties' ); ?></span> 268 374 <span class="ippd-kv__value"><a href="<?php echo esc_url( $rest_url ); ?>" target="_blank">palace-properties/v1</a></span> 269 375 </div> … … 278 384 <div class="ippd-card__body"> 279 385 <div class="ippd-kv"> 280 <span class="ippd-kv__label"><span class="dashicons dashicons-clock"></span> Last Property Received</span>386 <span class="ippd-kv__label"><span class="dashicons dashicons-clock"></span> <?php esc_html_e( 'Last Property Update', 'integrate-palace-properties' ); ?></span> 281 387 <span class="ippd-kv__value"><?php echo $last_sync ? esc_html( human_time_diff( strtotime( $last_sync ), current_time( 'timestamp' ) ) ) . ' ago' : '<em>Never</em>'; ?></span> 282 388 </div> … … 292 398 </div> 293 399 <div class="ippd-kv"> 294 <span class="ippd-kv__label"><span class="dashicons dashicons-archive"></span> Show on Frontend</span> 295 <span class="ippd-kv__value"> 296 <?php if ( $sync_archived === 'yes' ) : ?> 297 <span class="ippd-badge ippd-badge--blue">All (Active + Archived)</span> 298 <?php else : ?> 299 <span class="ippd-badge ippd-badge--green">Active Only</span> 300 <?php endif; ?> 301 </span> 400 <span class="ippd-kv__label"><span class="dashicons dashicons-hidden"></span> <?php esc_html_e( 'Hidden from Frontend', 'integrate-palace-properties' ); ?></span> 401 <span class="ippd-kv__value"><?php echo esc_html( $hidden ); ?></span> 302 402 </div> 303 403 <div class="ippd-kv"> … … 503 603 if (r.success) { 504 604 $status.text(r.data.message).addClass('success'); 605 // Properties import on WP-Cron over the following 606 // minutes; refresh so the counts reflect the new state. 607 setTimeout(function() { window.location.reload(); }, 4000); 505 608 } else { 506 609 $status.text(r.data || 'Sync failed').addClass('error'); -
integrate-palace-properties/trunk/includes/class-integratepalacep-activator.php
r3236864 r3694341 12 12 flush_rewrite_rules(); 13 13 } 14 15 // Start polling Palace on a schedule. Safe to call on reactivation: 16 // IPP_Sync::schedule() leaves an existing matching event alone. 17 if ( class_exists( 'IPP_Sync' ) ) { 18 IPP_Sync::schedule(); 19 } 14 20 } catch (Exception $e) { 15 21 if (defined('WP_DEBUG') && WP_DEBUG) { -
integrate-palace-properties/trunk/includes/class-integratepalacep-customizer.php
r3236864 r3694341 193 193 $dir = SCRIPT_DEBUG ? 'unminified' : 'minified'; 194 194 195 wp_enqueue_script('ippr-extend-customizer', INTEGRATE_PALACE_P_PLUGIN_URI . 'includes/customizer/assets/js/' . $dir . '/integratepalacep-extend-customizer' . $js_prefix, array( 'jquery', 'customize-preview', 'wp-color-picker' , 'customize-controls' ), false, false );196 wp_enqueue_script('color-picker-alpha', INTEGRATE_PALACE_P_PLUGIN_URI . 'includes/customizer/assets/js/' . $dir . '/wp-color-picker-alpha' . $js_prefix, array( 'jquery', 'customize-preview', 'wp-color-picker' , 'customize-controls' ), false, false );195 wp_enqueue_script('ippr-extend-customizer', INTEGRATE_PALACE_P_PLUGIN_URI . 'includes/customizer/assets/js/' . $dir . '/integratepalacep-extend-customizer' . $js_prefix, array( 'jquery', 'customize-preview', 'wp-color-picker' , 'customize-controls' ), $this->version, false ); 196 wp_enqueue_script('color-picker-alpha', INTEGRATE_PALACE_P_PLUGIN_URI . 'includes/customizer/assets/js/' . $dir . '/wp-color-picker-alpha' . $js_prefix, array( 'jquery', 'customize-preview', 'wp-color-picker' , 'customize-controls' ), $this->version, false ); 197 197 wp_enqueue_script('ippr-customizer-scripts', INTEGRATE_PALACE_P_PLUGIN_URI . 'includes/customizer/assets/js/' . $dir . '/integratepalacep-customizer' . $js_prefix, array( 'jquery', 'customize-preview', 'wp-color-picker' , 'customize-controls' ), $this->version, false ); 198 198 -
integrate-palace-properties/trunk/includes/class-integratepalacep-local-fields.php
r3486430 r3694341 865 865 // Verify nonce 866 866 if (!isset($_POST['ipp_property_meta_nonce']) || 867 !wp_verify_nonce( $_POST['ipp_property_meta_nonce'], 'ipp_save_property_meta')) {867 !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['ipp_property_meta_nonce'])), 'ipp_save_property_meta')) { 868 868 return; 869 869 } … … 992 992 foreach ($toggle_fields as $key) { 993 993 $val = isset($_POST[$key]) ? '1' : '0'; 994 // Changing the pets/smoking checkbox by hand overrides the policy 995 // wording imported from Palace (such as "By consent"), so the label 996 // shown on the site always matches the checkbox. 997 if ( in_array( $key, array( 'ipp_pets_allowed', 'ipp_smokers_allowed' ), true ) && get_post_meta( $post_id, $key, true ) !== $val ) { 998 delete_post_meta( $post_id, 'ipp_pets_allowed' === $key ? 'ipp_pets_policy' : 'ipp_smokers_policy' ); 999 } 994 1000 update_post_meta($post_id, $key, $val); 995 1001 } … … 997 1003 // ---- Archived ---- 998 1004 if (isset($_POST['ipp_archived'])) { 999 update_post_meta($post_id, 'ipp_archived', sanitize_text_field( $_POST['ipp_archived']));1005 update_post_meta($post_id, 'ipp_archived', sanitize_text_field(wp_unslash($_POST['ipp_archived']))); 1000 1006 } 1001 1007 -
integrate-palace-properties/trunk/includes/class-integratepalacep-property-helper.php
r3486430 r3694341 48 48 // ─── Address ──────────────────────────────────────────────────── 49 49 50 public function address1() { return $this->meta( 'address1', 'street_number' ); } 51 public function address2() { return $this->meta( 'address2', 'street_name' ); } 50 /** 51 * Whether Palace says this listing's street address must not be published. 52 * 53 * Every public output of the street address, unit and exact coordinates goes 54 * through this helper, so honouring the flag here covers the templates, the 55 * REST API, shortcodes and structured data alike. 56 * 57 * @return bool 58 */ 59 public function address_hidden() { 60 $hidden = 'no' === strtolower( trim( (string) get_post_meta( $this->post_id, 'ipp_publish_address', true ) ) ); 61 62 /** 63 * Filter whether a property's street address is hidden from visitors. 64 * 65 * @param bool $hidden True when Palace marks the address "do not publish". 66 * @param int $post_id Property post ID. 67 */ 68 return (bool) apply_filters( 'ipp_address_hidden', $hidden, $this->post_id ); 69 } 70 71 public function address1() { return $this->address_hidden() ? '' : $this->meta( 'address1', 'street_number' ); } 72 public function address2() { return $this->address_hidden() ? '' : $this->meta( 'address2', 'street_name' ); } 52 73 public function address3() { return $this->meta( 'address3', 'property_city' ); } 53 74 public function address4() { return $this->meta( 'address4' ); } 54 public function unit() { return $this-> meta( 'unit' ); }75 public function unit() { return $this->address_hidden() ? '' : $this->meta( 'unit' ); } 55 76 public function postcode() { return $this->meta( 'postcode', 'zipcode' ); } 56 77 public function suburb() { return $this->meta( 'suburb', 'information_suburb' ); } … … 120 141 public function smokers_allowed() { return (bool) $this->meta( 'smokers_allowed', 'property_smokers_allowed' ); } 121 142 143 /** 144 * Pets policy as display text: "Yes", "No", or Palace's own wording such as 145 * "By consent". pets_allowed() stays a strict yes/no for existing code. 146 * 147 * @return string 148 */ 149 public function pets_label() { return $this->policy_label( 'pets_policy', $this->pets_allowed() ); } 150 151 /** 152 * Smoking policy as display text. 153 * 154 * @return string 155 */ 156 public function smokers_label() { return $this->policy_label( 'smokers_policy', $this->smokers_allowed() ); } 157 158 /** 159 * Turn a stored Palace policy into display text. 160 * 161 * @param string $policy_key Meta key, without the ipp_ prefix. 162 * @param bool $allowed The yes/no flag, used when no policy text exists. 163 * @return string 164 */ 165 private function policy_label( $policy_key, $allowed ) { 166 $policy = trim( (string) $this->meta( $policy_key ) ); 167 168 if ( '' === $policy ) { 169 // Imported before 3.0.0, or edited by hand: only the yes/no flag exists. 170 return $allowed ? __( 'Yes', 'integrate-palace-properties' ) : __( 'No', 'integrate-palace-properties' ); 171 } 172 173 switch ( strtolower( $policy ) ) { 174 case 'yes': 175 case 'true': 176 return __( 'Yes', 'integrate-palace-properties' ); 177 case 'no': 178 case 'false': 179 return __( 'No', 'integrate-palace-properties' ); 180 case 'by consent': 181 return __( 'By consent', 'integrate-palace-properties' ); 182 } 183 184 return $policy; 185 } 186 122 187 // ─── Links & Media ────────────────────────────────────────────── 123 188 124 189 public function virtual_tour_url() { return $this->meta( 'virtual_tour_url', 'property_virtual_tour_url' ); } 125 190 public function web_link_url() { return $this->meta( 'web_link_url' ); } 126 public function geographic_location() { return $this-> meta( 'geographic_location', 'property_geographic_location' ); }191 public function geographic_location() { return $this->address_hidden() ? '' : $this->meta( 'geographic_location', 'property_geographic_location' ); } 127 192 public function advert_text() { return $this->meta( 'advert_text' ); } 128 193 public function feature_details() { return $this->meta( 'feature_details' ); } … … 191 256 } 192 257 258 /** 259 * Whether to show a map. A listing whose address is hidden still gets one, 260 * centred on its suburb (map_embed_url() falls back to full_address(), which 261 * is suburb-only for these) rather than on its exact location. 262 * 263 * @return bool 264 */ 265 public function show_map() { 266 return $this->has_map_coords() || ( $this->address_hidden() && '' !== $this->full_address() ); 267 } 268 193 269 public function map_lat() { 194 270 $loc = $this->geographic_location(); … … 239 315 240 316 if ( $this->full_address() ) { 241 $schema['address'] = [ 317 // array_filter() drops the empty street address of a listing whose 318 // address is hidden, rather than publishing an empty field. 319 $schema['address'] = array_filter( [ 242 320 '@type' => 'PostalAddress', 243 321 'streetAddress' => trim( $this->address1() . ' ' . $this->address2() ), … … 245 323 'addressRegion' => $this->region(), 246 324 'postalCode' => $this->postcode(), 247 ] ;325 ] ); 248 326 } 249 327 … … 261 339 } 262 340 263 return '<script type="application/ld+json">' . wp_json_encode( $schema, JSON_UNESCAPED_SLASHES ) . '</script>'; 341 // JSON_HEX_TAG escapes < and > as < / >. Without it, a property 342 // field containing the literal text "</script>" would close this block 343 // early and anything after it would be parsed as markup. The values come 344 // from the Palace API, so they are not trustworthy input. JSON parsers 345 // and structured-data crawlers read the escaped form identically. 346 return '<script type="application/ld+json">' . wp_json_encode( $schema, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG ) . '</script>'; 264 347 } 265 348 } -
integrate-palace-properties/trunk/includes/class-integratepalacep-settings.php
r3524333 r3694341 6 6 self::register_settings(); 7 7 8 // Always re-push the registration to the API after the configs form is saved, 9 // even when no field values changed. The Settings API normally fires 10 // update_option_X only on actual change, which is not enough — a plain 11 // re-save should reliably push the current site_url() to the API too. 12 add_action( 'admin_init', [ __CLASS__, 'maybe_force_resync_after_save' ], 100 ); 13 14 // Re-register the webhook URL when the site URL changes between page loads 15 // (typical after a staging → production migration that copies the WP DB). 16 self::maybe_reregister_webhook_url(); 17 18 // Handle the "Re-sync now" button on the configs page. 19 add_action( 'admin_post_ipp_resync_now', [ __CLASS__, 'handle_resync_now' ] ); 20 21 // Slug change still needs a CPT re-register on top of the API push. 8 // Saving credentials should make the site usable straight away rather 9 // than leaving the owner waiting for the next scheduled run. 10 add_action( 'admin_init', [ __CLASS__, 'maybe_sync_after_save' ], 100 ); 11 12 // Slug change needs a CPT re-register. 22 13 add_action( 'update_option_integrate_palace_properties_slug', [ __CLASS__, 'on_slug_changed' ], 10, 3 ); 23 14 } 24 15 25 16 /** 26 * Fires after WordPress's Settings API processes the configs form submission 27 * and redirects back with ?settings-updated=true. Triggers a forced re-push 28 * of registration data to the API regardless of whether values changed. 29 */ 30 public static function maybe_force_resync_after_save() { 31 if ( ! is_admin() ) return; 32 if ( empty( $_GET['page'] ) || $_GET['page'] !== 'integrate-palace-properties-configs' ) return; 33 if ( empty( $_GET['settings-updated'] ) || $_GET['settings-updated'] !== 'true' ) return; 34 if ( ! current_user_can( 'manage_options' ) ) return; 35 36 self::update_subscription(); 37 } 38 39 /** 40 * Manual "Re-sync now" action — pushes the current site URL/credentials to the API 41 * even when nothing was edited. Useful after a domain migration. 42 */ 43 public static function handle_resync_now() { 17 * Queue a sync run once the configs form has been saved. 18 * 19 * The Settings API redirects back with ?settings-updated=true, which is the 20 * only reliable signal that the form was submitted — update_option_X fires 21 * only when a value actually changed. 22 */ 23 public static function maybe_sync_after_save() { 24 if ( ! is_admin() ) { 25 return; 26 } 44 27 if ( ! current_user_can( 'manage_options' ) ) { 45 wp_die( __( 'Insufficient permissions.', 'integrate-palace-properties' ) ); 46 } 47 check_admin_referer( 'ipp_resync_now' ); 48 49 self::update_subscription(); 50 51 wp_safe_redirect( add_query_arg( 52 [ 'page' => 'integrate-palace-properties-configs', 'settings-updated' => 'true' ], 53 admin_url( 'admin.php' ) 54 ) ); 55 exit; 28 return; 29 } 30 31 // Read-only checks on a redirect WordPress itself produced; nothing is 32 // written from these values, so no nonce is involved. 33 // phpcs:disable WordPress.Security.NonceVerification.Recommended 34 $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; 35 $updated = isset( $_GET['settings-updated'] ) ? sanitize_key( wp_unslash( $_GET['settings-updated'] ) ) : ''; 36 // phpcs:enable WordPress.Security.NonceVerification.Recommended 37 38 if ( 'integrate-palace-properties-configs' !== $page || 'true' !== $updated ) { 39 return; 40 } 41 42 if ( ! IPP_Sync::has_credentials() ) { 43 return; 44 } 45 46 IPP_Sync::schedule(); 47 48 // Run out of band so saving settings never blocks on a slow API call. 49 if ( ! IPP_Sync::is_running() ) { 50 // Distinct args, or WordPress treats it as a duplicate of the recurring 51 // event that schedule() has just created and silently drops it. 52 wp_schedule_single_event( time() + 5, IPP_Sync::CRON_HOOK, array( false ) ); 53 } 56 54 } 57 55 … … 63 61 } 64 62 65 /**66 * Re-register the webhook URL with the API if the site URL has changed67 * (e.g. after migrating from staging to production).68 */69 private static function maybe_reregister_webhook_url() {70 $stored_webhook_url = get_option( 'integrate_palace_properties_webhook_url', '' );71 if ( empty( $stored_webhook_url ) ) {72 return;73 }74 75 $last_site_url = get_option( 'ipp_registered_site_url', '' );76 $current_site_url = site_url();77 78 if ( empty( $last_site_url ) || $last_site_url !== $current_site_url ) {79 self::update_subscription();80 }81 }82 83 63 public static function register_settings() { 84 64 register_setting('integrate_palace_properties_configs', 'integrate_palace_properties_username', ['sanitize_callback' => 'sanitize_text_field']); 85 register_setting('integrate_palace_properties_configs', 'integrate_palace_properties_password', ['sanitize_callback' => 'sanitize_text_field']); 86 register_setting('integrate_palace_properties_configs', 'integrate_palace_properties_subscription_key', ['sanitize_callback' => 'sanitize_text_field']); 65 register_setting('integrate_palace_properties_configs', 'integrate_palace_properties_password', ['sanitize_callback' => [__CLASS__, 'sanitize_password']]); 87 66 register_setting('integrate_palace_properties_configs', 'integrate_palace_properties_slug', ['sanitize_callback' => 'sanitize_text_field']); 67 register_setting('integrate_palace_properties_configs', 'ipp_sync_interval', [ 68 'type' => 'string', 69 'sanitize_callback' => [__CLASS__, 'sanitize_sync_interval'], 70 'default' => 'hourly', 71 ]); 88 72 89 73 add_settings_section( … … 111 95 112 96 add_settings_field( 113 'integrate_palace_properties_subscription_key',114 __('Subscription Key', 'integrate-palace-properties'),115 [__CLASS__, 'render_subscription_key_field'],116 'integrate_palace_properties_configs',117 'integrate_palace_properties_settings_section'118 );119 120 add_settings_field(121 97 'integrate_palace_properties_slug', 122 98 __('Property Slug', 'integrate-palace-properties'), … … 127 103 128 104 add_settings_field( 129 'i ntegrate_palace_properties_webhook_status',130 __('S TATUS', 'integrate-palace-properties'),131 [__CLASS__, 'render_ webhook_status_field'],105 'ipp_sync_interval', 106 __('Sync Frequency', 'integrate-palace-properties'), 107 [__CLASS__, 'render_sync_interval_field'], 132 108 'integrate_palace_properties_configs', 133 109 'integrate_palace_properties_settings_section' … … 135 111 136 112 add_settings_field( 137 'ipp_ domain_status',138 __( 'Site Domain Status', 'integrate-palace-properties'),139 [ __CLASS__, 'render_domain_status_field'],113 'ipp_sync_status', 114 __('Sync Status', 'integrate-palace-properties'), 115 [__CLASS__, 'render_sync_status_field'], 140 116 'integrate_palace_properties_configs', 141 117 'integrate_palace_properties_settings_section' … … 178 154 'default' => self::get_default_display_fields(), 179 155 ]); 180 register_setting('integrate_palace_properties_configs', 'ipp_sync_archived', [181 'type' => 'string',182 'sanitize_callback' => 'sanitize_text_field',183 'default' => 'no',184 ]);185 register_setting('integrate_palace_properties_configs', 'ipp_sync_statuses', [186 'type' => 'array',187 'sanitize_callback' => [__CLASS__, 'sanitize_sync_statuses'],188 'default' => ['Active'],189 ]);190 156 191 157 add_settings_section( … … 200 166 __('Property Details to Display', 'integrate-palace-properties'), 201 167 [__CLASS__, 'render_display_fields'], 202 'integrate_palace_properties_configs',203 'ipp_display_config_section'204 );205 206 add_settings_field(207 'ipp_sync_archived',208 __('Include Archived Properties', 'integrate-palace-properties'),209 [__CLASS__, 'render_sync_archived_field'],210 'integrate_palace_properties_configs',211 'ipp_display_config_section'212 );213 214 add_settings_field(215 'ipp_sync_statuses',216 __('Property Statuses to Sync', 'integrate-palace-properties'),217 [__CLASS__, 'render_sync_statuses_field'],218 168 'integrate_palace_properties_configs', 219 169 'ipp_display_config_section' … … 294 244 } 295 245 296 public static function sanitize_sync_statuses( $input ) {297 if ( ! is_array( $input ) ) return array( 'Active' );298 return array_map( 'sanitize_text_field', $input );299 }300 301 246 public static function render_display_section_description() { 302 echo '<p>' . esc_html__( 'Control which property details are displayed on your website and how properties are synced from Palace.', 'integrate-palace-properties' ) . '</p>';247 echo '<p>' . esc_html__( 'Control which property details are displayed on your website.', 'integrate-palace-properties' ) . '</p>'; 303 248 } 304 249 … … 312 257 echo '<legend style="font-weight:600; padding:0 6px;">' . esc_html( $group_label ) . '</legend>'; 313 258 foreach ( $fields as $key => $label ) { 314 $checked = in_array( $key, $saved, true ) ? 'checked' : '';315 259 echo '<label style="display:block; margin-bottom:6px; cursor:pointer;">'; 316 echo '<input type="checkbox" name="ipp_display_fields[]" value="' . esc_attr( $key ) . '" ' . $checked. ' /> ';260 echo '<input type="checkbox" name="ipp_display_fields[]" value="' . esc_attr( $key ) . '" ' . checked( in_array( $key, $saved, true ), true, false ) . ' /> '; 317 261 echo esc_html( $label ); 318 262 echo '</label>'; … … 324 268 } 325 269 326 public static function render_sync_archived_field() {327 $value = get_option( 'ipp_sync_archived', 'no' );328 echo '<label>';329 echo '<input type="checkbox" name="ipp_sync_archived" value="yes" ' . checked( $value, 'yes', false ) . ' /> ';330 echo esc_html__( 'Also sync archived/inactive properties from Palace', 'integrate-palace-properties' );331 echo '</label>';332 echo '<p class="description">' . esc_html__( 'When enabled, both current and archived properties will be imported. Archived properties will be marked with the "Inactive" status taxonomy.', 'integrate-palace-properties' ) . '</p>';333 }334 335 public static function render_sync_statuses_field() {336 $saved = get_option( 'ipp_sync_statuses', array( 'Active' ) );337 $statuses = array( 'Active', 'Inactive' );338 foreach ( $statuses as $status ) {339 $checked = in_array( $status, $saved, true ) ? 'checked' : '';340 echo '<label style="display:inline-block; margin-right:16px;">';341 echo '<input type="checkbox" name="ipp_sync_statuses[]" value="' . esc_attr( $status ) . '" ' . $checked . ' /> ';342 echo esc_html( $status );343 echo '</label>';344 }345 echo '<p class="description">' . esc_html__( 'Choose which property statuses to sync from Palace API.', 'integrate-palace-properties' ) . '</p>';346 }347 348 270 public static function render_username_field() { 349 271 $value = get_option('integrate_palace_properties_username', ''); … … 351 273 } 352 274 275 /** 276 * Password field. 277 * 278 * The stored password is never rendered back into the page. An empty 279 * submission leaves the saved value untouched (see keep_existing_password), 280 * so the field can stay blank once credentials are set. 281 */ 353 282 public static function render_password_field() { 354 $value = get_option('integrate_palace_properties_password', ''); 355 echo '<input type="password" name="integrate_palace_properties_password" value="' . esc_attr($value) . '" class="ipp-full-width" />'; 356 } 357 358 public static function render_subscription_key_field() { 359 $value = get_option('integrate_palace_properties_subscription_key', ''); 360 echo '<input type="password" name="integrate_palace_properties_subscription_key" value="' . esc_attr($value) . '" class="ipp-full-width" />'; 283 $has_password = '' !== trim( (string) get_option( 'integrate_palace_properties_password', '' ) ); 284 285 echo '<input type="password" name="integrate_palace_properties_password" value="" autocomplete="new-password" class="ipp-full-width" placeholder="'; 286 echo esc_attr( 287 $has_password 288 ? __( 'Saved — leave blank to keep it', 'integrate-palace-properties' ) 289 : __( 'Enter your Palace API password', 'integrate-palace-properties' ) 290 ); 291 echo '" />'; 292 293 if ( $has_password ) { 294 echo '<p class="description">' . esc_html__( 'A password is saved. Type a new one only if you want to replace it.', 'integrate-palace-properties' ) . '</p>'; 295 } 296 } 297 298 /** 299 * Keep the stored password when the field is submitted empty. 300 * 301 * Registered as the sanitize callback, so an untouched form does not wipe 302 * working credentials. 303 * 304 * @param string $value Submitted value. 305 * @return string 306 */ 307 public static function sanitize_password( $value ) { 308 $value = is_string( $value ) ? trim( $value ) : ''; 309 310 if ( '' === $value ) { 311 return (string) get_option( 'integrate_palace_properties_password', '' ); 312 } 313 314 return sanitize_text_field( $value ); 361 315 } 362 316 … … 366 320 } 367 321 368 public static function render_webhook_status_field() { 369 $value = get_option('integrate_palace_properties_webhook_status', ''); 370 echo '<label>' . wp_kses_post($value) . '</label>'; 371 } 372 373 /** 374 * Compares the host this WordPress install reports vs. the host the API 375 * was last told to deliver webhooks to. Mismatch = the API is pointing at 376 * a stale domain and webhooks won't arrive. 377 */ 378 public static function render_domain_status_field() { 379 $registered_url = get_option( 'integrate_palace_properties_webhook_url', '' ); 380 $current_host = parse_url( site_url(), PHP_URL_HOST ); 381 $registered_host = $registered_url ? parse_url( $registered_url, PHP_URL_HOST ) : ''; 382 383 $resync_url = wp_nonce_url( 384 admin_url( 'admin-post.php?action=ipp_resync_now' ), 385 'ipp_resync_now' 386 ); 387 388 echo '<div style="display:flex; flex-direction:column; gap:6px;">'; 389 390 if ( empty( $registered_url ) ) { 391 echo '<span style="display:inline-block; padding:4px 10px; background:#f0f0f1; color:#646970; border-radius:3px; font-size:12px;">'; 392 echo esc_html__( 'Not registered — save settings to register this site with the API.', 'integrate-palace-properties' ); 322 /** 323 * Restrict the sync interval to a schedule the plugin actually registers. 324 * 325 * @param string $value Submitted value. 326 * @return string 327 */ 328 public static function sanitize_sync_interval( $value ) { 329 $allowed = [ 'ipp_fifteen_minutes', 'hourly', 'ipp_two_hours', 'twicedaily', 'daily' ]; 330 $value = sanitize_text_field( $value ); 331 332 return in_array( $value, $allowed, true ) ? $value : 'hourly'; 333 } 334 335 /** 336 * How often the site should poll Palace for changes. 337 */ 338 public static function render_sync_interval_field() { 339 $current = IPP_Sync::get_interval(); 340 $options = [ 341 'ipp_fifteen_minutes' => __( 'Every 15 minutes', 'integrate-palace-properties' ), 342 'hourly' => __( 'Hourly (recommended)', 'integrate-palace-properties' ), 343 'ipp_two_hours' => __( 'Every 2 hours', 'integrate-palace-properties' ), 344 'twicedaily' => __( 'Twice daily', 'integrate-palace-properties' ), 345 'daily' => __( 'Once daily', 'integrate-palace-properties' ), 346 ]; 347 348 echo '<select name="ipp_sync_interval">'; 349 foreach ( $options as $value => $label ) { 350 echo '<option value="' . esc_attr( $value ) . '" ' . selected( $current, $value, false ) . '>'; 351 echo esc_html( $label ); 352 echo '</option>'; 353 } 354 echo '</select>'; 355 echo '<p class="description">' . esc_html__( 'How often this site checks Palace for new, changed and removed properties.', 'integrate-palace-properties' ) . '</p>'; 356 } 357 358 /** 359 * Report the outcome of the most recent scheduled run. 360 */ 361 public static function render_sync_status_field() { 362 if ( ! IPP_Sync::has_credentials() ) { 363 echo '<span class="ipp-status-pill ipp-status-idle">'; 364 echo esc_html__( 'Enter your Palace API username and password to begin syncing.', 'integrate-palace-properties' ); 393 365 echo '</span>'; 394 } elseif ( $registered_host && strcasecmp( $registered_host, $current_host ) === 0 ) { 395 echo '<span style="display:inline-block; padding:4px 10px; background:#d1e7dd; color:#0f5132; border-radius:3px; font-size:12px;">'; 396 echo '✓ ' . esc_html__( 'Domain in sync with API', 'integrate-palace-properties' ); 366 return; 367 } 368 369 if ( IPP_Sync::is_running() ) { 370 $progress = IPP_Sync::get_progress(); 371 echo '<span class="ipp-status-pill ipp-status-running">'; 372 echo esc_html( 373 sprintf( 374 /* translators: 1: batches completed, 2: total batches. */ 375 __( 'Sync in progress — batch %1$d of %2$d.', 'integrate-palace-properties' ), 376 (int) $progress['done'], 377 (int) $progress['total'] 378 ) 379 ); 397 380 echo '</span>'; 398 echo '<span style="font-size:11px; color:#646970;">'; 399 echo esc_html( sprintf( __( 'API is delivering webhooks to: %s', 'integrate-palace-properties' ), $registered_host ) ); 381 return; 382 } 383 384 $unfinished = IPP_Sync::get_unfinished_attempt(); 385 386 if ( $unfinished ) { 387 echo '<span class="ipp-status-pill ipp-status-error">'; 388 echo esc_html__( 'The last sync did not finish', 'integrate-palace-properties' ); 400 389 echo '</span>'; 401 } else { 402 echo '<span style="display:inline-block; padding:4px 10px; background:#f8d7da; color:#842029; border-radius:3px; font-size:12px;">'; 403 echo '⚠ ' . esc_html__( 'Domain mismatch — webhooks will not arrive', 'integrate-palace-properties' ); 390 echo '<p class="description">'; 391 echo esc_html( 392 sprintf( 393 /* translators: %s: human-readable time since the sync started, e.g. "2 hours". */ 394 __( 'A sync started %s ago but never recorded a result. This usually means your host stopped the request while it was fetching properties from Palace. Try Sync Now. If it keeps happening, ask your host to raise the PHP request timeout, or to run WordPress cron from a server cron job.', 'integrate-palace-properties' ), 395 human_time_diff( $unfinished, time() ) 396 ) 397 ); 398 echo '</p>'; 399 return; 400 } 401 402 $last = IPP_Sync::get_last_run(); 403 404 if ( empty( $last ) ) { 405 echo '<span class="ipp-status-pill ipp-status-idle">'; 406 echo esc_html__( 'No sync has run yet.', 'integrate-palace-properties' ); 404 407 echo '</span>'; 405 echo '<span style="font-size:11px; color:#646970;">'; 406 echo esc_html( sprintf( 407 __( 'This site: %1$s — API has registered: %2$s', 'integrate-palace-properties' ), 408 $current_host, 409 $registered_host ?: 'unknown' 410 ) ); 408 return; 409 } 410 411 $time = isset( $last['time'] ) ? $last['time'] : ''; 412 413 if ( isset( $last['status'] ) && 'failed' === $last['status'] ) { 414 echo '<span class="ipp-status-pill ipp-status-error">'; 415 echo esc_html__( 'Last sync failed', 'integrate-palace-properties' ); 411 416 echo '</span>'; 412 echo '<a href="' . esc_url( $resync_url ) . '" class="button" style="width:fit-content; margin-top:4px;">'; 413 echo esc_html__( 'Re-sync this site with API', 'integrate-palace-properties' ); 414 echo '</a>'; 415 } 416 417 echo '</div>'; 417 if ( ! empty( $last['message'] ) ) { 418 echo '<p class="description">' . esc_html( $last['message'] ) . '</p>'; 419 } 420 return; 421 } 422 423 if ( isset( $last['status'] ) && 'warning' === $last['status'] ) { 424 echo '<span class="ipp-status-pill ipp-status-warn">'; 425 echo esc_html__( 'Last sync completed with a warning', 'integrate-palace-properties' ); 426 echo '</span>'; 427 if ( ! empty( $last['message'] ) ) { 428 echo '<p class="description">' . esc_html( $last['message'] ) . '</p>'; 429 } 430 return; 431 } 432 433 echo '<span class="ipp-status-pill ipp-status-ok">'; 434 echo esc_html__( 'Last sync successful', 'integrate-palace-properties' ); 435 echo '</span>'; 436 echo '<p class="description">'; 437 echo esc_html( 438 sprintf( 439 /* translators: 1: date and time, 2: number of properties updated, 3: number removed. */ 440 __( '%1$s — %2$d updated, %3$d removed.', 'integrate-palace-properties' ), 441 $time, 442 isset( $last['imported'] ) ? (int) $last['imported'] : 0, 443 isset( $last['deleted'] ) ? (int) $last['deleted'] : 0 444 ) 445 ); 446 echo '</p>'; 447 448 $next = wp_next_scheduled( IPP_Sync::CRON_HOOK ); 449 if ( $next ) { 450 echo '<p class="description">'; 451 echo esc_html( 452 sprintf( 453 /* translators: %s: human-readable time difference, e.g. "42 mins". */ 454 __( 'Next check in %s.', 'integrate-palace-properties' ), 455 human_time_diff( time(), $next ) 456 ) 457 ); 458 echo '</p>'; 459 } 418 460 } 419 461 … … 458 500 } 459 501 460 /**461 * Push current credentials, blog ID, and webhook URL to the API. Self-heals462 * any missing local options (blog UUID, webhook secret) so a freshly migrated463 * or cloned WP install becomes fully functional after one save.464 */465 public static function update_subscription() {466 $username = get_option( 'integrate_palace_properties_username', '' );467 $password = get_option( 'integrate_palace_properties_password', '' );468 $subscription_key = get_option( 'integrate_palace_properties_subscription_key', '' );469 470 // Self-heal: ensure the unique blog ID exists. Generated on activation,471 // but a partial DB clone or option deletion could leave it missing.472 $blog_id = get_option( 'integrate_palace-palace-unique-id' );473 if ( empty( $blog_id ) ) {474 $blog_id = wp_generate_uuid4();475 update_option( 'integrate_palace-palace-unique-id', $blog_id );476 }477 478 $webhook_url = esc_url_raw( rest_url( 'integrate-palace-properties/v1/webhook' ) );479 480 $api_base = defined( 'IPP_API_URL' ) ? IPP_API_URL : 'https://wp-palace.kiwibrain.co.nz';481 $response = wp_remote_post( $api_base . '/api/update-user', [482 'timeout' => 15,483 'body' => wp_json_encode( [484 'palace_api_key' => base64_encode( sanitize_text_field( $username ) . ':' . sanitize_text_field( $password ) ),485 'wp_palace_blog_id' => $blog_id,486 'webhook_url' => $webhook_url,487 'subscription_key' => sanitize_text_field( $subscription_key ),488 ] ),489 'headers' => [490 'Content-Type' => 'application/json',491 ],492 ] );493 494 if ( is_wp_error( $response ) ) {495 error_log( '[IPP] Failed to reach API: ' . $response->get_error_message() );496 update_option(497 'integrate_palace_properties_webhook_status',498 "<span class='wh_error'><i>" . esc_html__( 'Could not reach the API. Check network/DNS.', 'integrate-palace-properties' ) . '</i></span>'499 );500 return;501 }502 503 $status_code = wp_remote_retrieve_response_code( $response );504 $body = wp_remote_retrieve_body( $response );505 $data = json_decode( $body, true );506 507 if ( $status_code >= 200 && $status_code < 300 && isset( $data['subscription']['webhook_url'] ) ) {508 $subscription_name = sanitize_text_field( $data['subscription']['name'] ?? '' );509 $properties_allowed = isset( $data['subscription']['properties_allowed'] ) ? sanitize_text_field( $data['subscription']['properties_allowed'] ) : '';510 $properties_allowed = ( $properties_allowed == '-1' ) ? 'unlimited' : $properties_allowed;511 512 update_option( 'integrate_palace_properties_webhook_url', esc_url_raw( $data['subscription']['webhook_url'] ) );513 update_option( 'integrate_palace_properties_webhook_status', "<span class='wh_connected'><i>Connected ($subscription_name) Max Properties: " . esc_html( $properties_allowed ) . '</i></span>' );514 update_option( 'ipp_registered_site_url', site_url() );515 516 // Mirror the canonical subscription key from the API response into517 // the webhook secret option so verify_webhook_signature has the same518 // HMAC secret the API signs with. Self-heals the "Webhook Auth: Open"519 // case where this option was never set on first registration.520 if ( ! empty( $data['subscription']['subscription_key'] ) ) {521 update_option( 'integrate_palace_webhook_secret', sanitize_text_field( $data['subscription']['subscription_key'] ) );522 }523 524 return;525 }526 527 $error_message = isset( $data['message'] ) && is_string( $data['message'] )528 ? $data['message']529 : 'Invalid Subscription Key';530 531 update_option(532 'integrate_palace_properties_webhook_status',533 "<span class='wh_error'><i>" . esc_html( $error_message ) . '</i></span>'534 );535 error_log( "[IPP] API rejected registration ($status_code): $error_message" );536 }537 502 } 538 503 ?> -
integrate-palace-properties/trunk/includes/class-integratepalacep-webhooks.php
r3486430 r3694341 1 1 <?php 2 2 if ( ! defined( 'ABSPATH' ) ) exit; 3 4 /** 5 * Property import. 6 * 7 * Historically this class exposed a REST route that an external relay pushed 8 * properties to. That route has been removed: properties are now pulled 9 * directly from the Palace API by IPP_Sync, so there is no longer any reason 10 * to accept inbound writes, and an endpoint that creates and deletes posts is 11 * not worth keeping open for a sender that no longer exists. 12 * 13 * The class name is retained because save_property() and 14 * delete_property_by_code() are the plugin's import API and may be called by 15 * site-specific code. 16 */ 3 17 class IntegratePalace_Properties_Webhooks { 4 18 19 /** 20 * Clean up state left behind by the retired webhook route. 21 * 22 * @return void 23 */ 5 24 public static function init() { 6 add_action('rest_api_init', array(__CLASS__, 'register_routes')); 7 } 8 9 public static function register_routes() { 10 $blog_id = get_option("integrate_palace-palace-unique-id"); 11 $webhook_url = "/webhook/$blog_id"; 12 register_rest_route('integrate-palace-properties/v1', $webhook_url, array( 13 'methods' => 'POST', 14 'callback' => array(__CLASS__, 'handle_webhook'), 15 'permission_callback' => array(__CLASS__, 'verify_webhook_signature'), 16 )); 17 } 18 19 /** 20 * Verify HMAC signature on incoming webhook requests. 21 */ 22 public static function verify_webhook_signature( WP_REST_Request $request ) { 23 $secret = get_option( 'integrate_palace_webhook_secret', '' ); 24 25 // No secret configured — allow all requests for backwards compatibility 26 if ( empty( $secret ) ) { 27 return true; 28 } 29 30 $signature = $request->get_header('X-Palace-Signature'); 31 if ( empty( $signature ) ) { 32 return new \WP_Error( 33 'rest_forbidden', 34 __( 'Missing webhook signature.', 'integrate-palace-properties' ), 35 array( 'status' => 403 ) 36 ); 37 } 38 39 $body = $request->get_body(); 40 $expected = hash_hmac( 'sha256', $body, $secret ); 41 42 if ( ! hash_equals( $expected, $signature ) ) { 43 return new \WP_Error( 44 'rest_forbidden', 45 __( 'Invalid webhook signature.', 'integrate-palace-properties' ), 46 array( 'status' => 403 ) 47 ); 48 } 49 50 return true; 25 // Clean up a property's images only when the post is really destroyed, 26 // not when it is trashed, so a trashed listing can still be restored. 27 add_action( 'before_delete_post', array( __CLASS__, 'delete_property_attachments' ) ); 28 29 // Once a property is restored, by a re-listing or by hand, it is no longer 30 // "trashed by the sync". 31 add_action( 'untrashed_post', array( __CLASS__, 'clear_sync_trash_flag' ) ); 32 33 // The HMAC secret and blog UUID only existed to authenticate the relay. 34 if ( get_option( 'integrate_palace_webhook_secret', false ) !== false ) { 35 delete_option( 'integrate_palace_webhook_secret' ); 36 } 37 if ( get_option( 'integrate_palace_properties_webhook_url', false ) !== false ) { 38 delete_option( 'integrate_palace_properties_webhook_url' ); 39 } 40 if ( get_option( 'integrate_palace_properties_webhook_status', false ) !== false ) { 41 delete_option( 'integrate_palace_properties_webhook_status' ); 42 } 43 if ( get_option( 'ipp_registered_site_url', false ) !== false ) { 44 delete_option( 'ipp_registered_site_url' ); 45 } 51 46 } 52 47 … … 65 60 } 66 61 62 /** 63 * Forget that a sync trashed this post, once it has been restored. 64 * 65 * @param int $post_id Restored post. 66 * @return void 67 */ 68 public static function clear_sync_trash_flag( $post_id ) { 69 delete_post_meta( $post_id, 'ipp_trashed_by_sync' ); 70 } 71 72 /** 73 * Delete a property's gallery images when the property itself is 74 * permanently deleted. 75 * 76 * @param int $post_id Post being deleted. 77 * @return void 78 */ 79 public static function delete_property_attachments( $post_id ) { 80 if ( 'palace-properties' !== get_post_type( $post_id ) ) { 81 return; 82 } 83 84 $gallery_images = get_post_meta( $post_id, 'integrate_palace_gallery', true ); 85 86 if ( ! empty( $gallery_images ) && is_array( $gallery_images ) ) { 87 foreach ( $gallery_images as $image_id ) { 88 wp_delete_attachment( intval( $image_id ), true ); 89 } 90 } 91 92 $thumbnail_id = get_post_thumbnail_id( $post_id ); 93 if ( $thumbnail_id ) { 94 wp_delete_attachment( (int) $thumbnail_id, true ); 95 } 96 } 97 67 98 private static function get_property_id_by_code($property_code) { 68 99 $cache_key = 'property_id_' . $property_code; … … 70 101 71 102 if ($post_id === false) { 103 // 'any' deliberately excludes trashed posts, so a property that was 104 // removed and later re-listed by Palace would not be found here and 105 // a duplicate post would be created. List the statuses explicitly. 72 106 $args = [ 73 107 'post_type' => 'palace-properties', … … 76 110 'fields' => 'ids', 77 111 'posts_per_page' => 1, 78 'post_status' => 'any',112 'post_status' => array( 'publish', 'draft', 'pending', 'private', 'future', 'trash' ), 79 113 ]; 80 114 … … 96 130 } 97 131 98 private static function delete_property($property_code) { 99 $property_code = sanitize_text_field($property_code); 100 if (!$property_code) { 101 return new WP_REST_Response(['status' => 'error', 'message' => 'Property code does not exist'], 404); 102 } 103 104 $post_id = self::get_property_id_by_code($property_code); 105 106 if ($post_id) { 107 /** @hook ipp_before_property_delete — Fires before a property is deleted via webhook. */ 108 do_action( 'ipp_before_property_delete', $post_id, $property_code ); 109 } 110 111 if ($post_id && wp_delete_post($post_id, false)) { 112 $gallery_images = get_post_meta($post_id, 'integrate_palace_gallery', true); 113 if (!empty($gallery_images) && is_array($gallery_images)) { 114 foreach ($gallery_images as $image_id) { 115 wp_delete_attachment(intval($image_id), true); 116 } 117 } 118 delete_post_thumbnail($post_id); 119 wp_cache_delete('property_id_' . $property_code, 'property_cache'); 120 121 /** @hook ipp_after_property_delete — Fires after a property is deleted via webhook. */ 122 do_action( 'ipp_after_property_delete', $post_id, $property_code ); 123 124 // Update last sync time 125 update_option( 'ipp_last_sync_time', current_time( 'mysql' ), false ); 126 127 return new WP_REST_Response(['status' => 'success', 'message' => 'Property deleted successfully'], 200); 128 } 129 130 return new WP_REST_Response( 131 ['status' => 'error', 'message' => $post_id ? 'Failed to delete property' : 'Property not found'], 132 $post_id ? 500 : 404 133 ); 132 /** 133 * Remove a property and its media. 134 * 135 * Shared by the scheduled sync and the legacy webhook route. 136 * 137 * @param string $property_code Palace property code. 138 * @return bool True when a property was removed, false when there was 139 * nothing to remove or the removal failed. 140 */ 141 public static function delete_property_by_code( $property_code ) { 142 $property_code = sanitize_text_field( $property_code ); 143 144 if ( ! $property_code ) { 145 return false; 146 } 147 148 $post_id = self::get_property_id_by_code( $property_code ); 149 150 if ( ! $post_id ) { 151 return false; 152 } 153 154 // A locked property stays on the site even after Palace drops it. 155 if ( '1' === get_post_meta( $post_id, 'ipp_lock_updates', true ) ) { 156 return false; 157 } 158 159 /** @hook ipp_before_property_delete — Fires before a property is deleted. */ 160 do_action( 'ipp_before_property_delete', $post_id, $property_code ); 161 162 // Trash, don't destroy. wp_delete_post( $id, false ) only trashes the 163 // core 'post' and 'page' types; for a custom post type like this one it 164 // deletes permanently and takes the images with it. Trashing keeps the 165 // listing and its photos restorable. delete_property_attachments() 166 // removes the images once the trash is emptied, which WordPress does 167 // automatically after EMPTY_TRASH_DAYS. On a site with the trash 168 // disabled, wp_trash_post() falls back to a permanent delete. 169 update_post_meta( $post_id, 'ipp_trashed_by_sync', '1' ); 170 171 if ( ! wp_trash_post( $post_id ) ) { 172 delete_post_meta( $post_id, 'ipp_trashed_by_sync' ); 173 return false; 174 } 175 176 wp_cache_delete( 'property_id_' . $property_code, 'property_cache' ); 177 178 /** @hook ipp_after_property_delete — Fires after a property is deleted. */ 179 do_action( 'ipp_after_property_delete', $post_id, $property_code ); 180 181 update_option( 'ipp_last_sync_time', current_time( 'mysql' ), false ); 182 183 return true; 134 184 } 135 185 136 public static function handle_webhook(WP_REST_Request $request) { 137 $property = $request->get_json_params(); 138 139 // Handle delete action 140 if (!empty($property['PropertyCode']) && isset($property['action']) && $property['action'] === 'delete') { 141 return self::delete_property($property['PropertyCode']); 142 } 143 144 if (!isset($property['PropertyCode'])) { 145 return new WP_REST_Response(array('status' => 'error', 'message' => 'Missing required fields'), 400); 146 } 147 186 187 /** 188 * Write a single Palace property record into WordPress. 189 * 190 * Accepts a property exactly as the Palace API returns it and maps every 191 * field onto the custom post type, its meta and its taxonomies. This is the 192 * plugin's single import path. 193 * 194 * @param array $property Property record from the Palace API. 195 * @param bool $force Re-import even when the change code is unchanged. 196 * @param bool $refresh_images Queue an image fetch. When false, properties that 197 * already have photos keep them without a fetch. 198 * @return int|WP_Error Post ID on success, WP_Error on failure. 199 */ 200 public static function save_property( $property, $force = false, $refresh_images = true ) { 201 if ( ! is_array( $property ) || empty( $property['PropertyCode'] ) ) { 202 return new WP_Error( 203 'ipp_invalid_property', 204 __( 'The property record was empty or had no property code.', 'integrate-palace-properties' ) 205 ); 206 } 207 208 /** @hook before_insert_palace_property — Filter the raw property before import. */ 148 209 $property = apply_filters('before_insert_palace_property', $property); 210 211 /** @hook show_on_website_palace_property — Return false to remove the property instead of importing it. */ 149 212 $show_on_website = apply_filters('show_on_website_palace_property', true, $property); 150 213 if (!$show_on_website) { 151 return self::delete_property($property['PropertyCode']); 214 self::delete_property_by_code($property['PropertyCode']); 215 return 0; 152 216 } 153 217 … … 157 221 wp_cache_delete('property_id_' . $property_code, 'property_cache'); 158 222 159 // Check if property is locked (prevent webhook from overwriting)223 // Respect the per-property lock set in the editor. 160 224 $existing_id = self::get_property_id_by_code($property_code); 161 225 if ( $existing_id && get_post_meta( $existing_id, 'ipp_lock_updates', true ) === '1' ) { 162 return new WP_REST_Response( array( 'status' => 'success', 'message' => 'Property is locked, skipping update' ), 200 ); 163 } 226 return (int) $existing_id; 227 } 228 229 if ( $existing_id && 'trash' === get_post_status( $existing_id ) ) { 230 if ( '1' !== get_post_meta( $existing_id, 'ipp_trashed_by_sync', true ) ) { 231 // Someone put this listing in the trash on purpose. Respect that 232 // rather than resurrecting it on every sync; restoring it from the 233 // trash brings it back. 234 return 0; 235 } 236 237 // Removed by an earlier sync and now re-listed by Palace: restore the 238 // original post, images and all, instead of creating a duplicate. 239 wp_untrash_post( $existing_id ); 240 241 // wp_untrash_post() restores to draft on WP 5.6+, and the post still 242 // carries its old change code. If nothing changed in Palace while the 243 // property was off the market, the change-code check below would call 244 // it "already up to date" and return before publishing it, leaving 245 // the listing invisible. A restore always gets a full update. 246 $force = true; 247 } 248 249 // Palace: "Should the Property Address be published online". Only an explicit 250 // "No" hides it, so feeds that omit the flag behave as before. 251 $address_hidden = ( 'no' === strtolower( trim( (string) self::arr_get($property, 'PropertyFeatures.PropertyPublishAddress') ) ) ); 164 252 165 253 // Build post title 166 254 $header = self::arr_get($property, 'PropertyFeatures.PropertyHeader'); 167 $post_title = !empty($header) 168 ? sanitize_text_field($header) 169 : sanitize_text_field( 255 if ( ! empty( $header ) ) { 256 $post_title = sanitize_text_field( $header ); 257 } elseif ( $address_hidden ) { 258 // No headline, and the street address must not be published: never 259 // build the title from it. Use the property type and suburb instead. 260 $type = sanitize_text_field( self::arr_get($property, 'PropertyFeatures.PropertyClass') ); 261 $type = '' !== $type ? $type : __( 'Property', 'integrate-palace-properties' ); 262 $locality = sanitize_text_field( self::arr_get($property, 'PropertyAddress3') ); 263 $post_title = '' !== $locality 264 /* translators: 1: property type such as "House", 2: suburb or town. */ 265 ? sprintf( __( '%1$s in %2$s', 'integrate-palace-properties' ), $type, $locality ) 266 : $type; 267 } else { 268 $post_title = sanitize_text_field( 170 269 self::arr_get($property, 'PropertyAddress3') . ', ' . 171 270 self::arr_get($property, 'PropertyAddress1') . ' ' . 172 271 self::arr_get($property, 'PropertyAddress2') 173 272 ); 273 } 174 274 $post_content = sanitize_textarea_field(self::arr_get($property, 'PropertyFeatures.PropertyAdvertText')); 175 275 … … 178 278 179 279 // Idempotency check 180 if (!empty($post_id) ) {280 if (!empty($post_id) && !$force) { 181 281 $stored_change_code = get_post_meta($post_id, 'ipp_change_code', true); 182 282 // Also check legacy key … … 186 286 $incoming_change_code = self::arr_get($property, 'PropertyChangeCode'); 187 287 if (!empty($stored_change_code) && $stored_change_code == $incoming_change_code) { 188 return new WP_REST_Response(array('status' => 'success', 'message' => 'Already up to date'), 200);189 } 190 } 191 192 /** @hook ipp_before_property_save — Fires before a property is saved/updated via webhook. */288 return (int) $post_id; 289 } 290 } 291 292 /** @hook ipp_before_property_save — Fires before a property is saved/updated. */ 193 293 do_action( 'ipp_before_property_save', $post_id ?: 0, $property ); 294 295 // Palace: "Should the Property entry be published online". A listing Palace 296 // says not to publish is kept as a draft: out of public view, but still 297 // synced, so it goes live automatically once the agency publishes it. 298 $publish_entry = strtolower( trim( (string) self::arr_get($property, 'PropertyFeatures.PropertyPublishEntry') ) ); 299 $post_status = ( 'no' === $publish_entry ) ? 'draft' : 'publish'; 300 301 /** 302 * Filter the status a synced property is saved with. 303 * 304 * @param string $post_status 'publish', or 'draft' when Palace says not to publish it online. 305 * @param array $property Property record from Palace. 306 */ 307 $post_status = apply_filters( 'ipp_property_post_status', $post_status, $property ); 194 308 195 309 // Create or update post … … 197 311 'post_title' => $post_title, 198 312 'post_content' => $post_content, 199 'post_status' => 'publish',313 'post_status' => $post_status, 200 314 'post_type' => 'palace-properties', 201 315 ); … … 207 321 } 208 322 209 if (!$post_id || is_wp_error($post_id)) { 210 return new WP_REST_Response(array('status' => 'error', 'message' => 'Failed to save property'), 500); 323 if (is_wp_error($post_id)) { 324 return $post_id; 325 } 326 327 if (!$post_id) { 328 return new WP_Error( 329 'ipp_save_failed', 330 __( 'The property could not be saved to the database.', 'integrate-palace-properties' ) 331 ); 211 332 } 212 333 … … 225 346 update_post_meta($post_id, 'ipp_property_code', $property_code); 226 347 update_post_meta($post_id, 'information_property_code', $property_code); // legacy compat 227 update_post_meta($post_id, 'ipp_change_code', sanitize_text_field(self::arr_get($property, 'PropertyChangeCode')));228 update_post_meta($post_id, 'information_code', sanitize_text_field(self::arr_get($property, 'PropertyChangeCode'))); // legacy229 348 update_post_meta($post_id, 'ipp_property_code_global', sanitize_text_field(self::arr_get($property, 'PropertyCodeGlobal'))); 230 349 update_post_meta($post_id, 'ipp_our_code', sanitize_text_field(self::arr_get($property, 'PropertyOurCode'))); … … 282 401 update_post_meta($post_id, 'ipp_parking', sanitize_text_field(self::arr_get($features, 'PropertyParking'))); 283 402 update_post_meta($post_id, 'other_parking', sanitize_text_field(self::arr_get($features, 'PropertyParking'))); // legacy 284 update_post_meta($post_id, 'ipp_pets_allowed', self::arr_get($features, 'PropertyPetsAllowed') === 'Yes' ? '1' : '0'); 285 update_post_meta($post_id, 'other_pets', self::arr_get($features, 'PropertyPetsAllowed') === 'Yes' ? '1' : '0'); // legacy 286 update_post_meta($post_id, 'ipp_smokers_allowed', self::arr_get($features, 'PropertySmokersAllowed') === 'Yes' ? '1' : '0'); 287 update_post_meta($post_id, 'property_smokers_allowed', self::arr_get($features, 'PropertySmokersAllowed') === 'Yes' ? '1' : '0'); // legacy 403 // Palace sends a policy, not a yes/no: real values include "By Consent". 404 // Keep Palace's wording for display, and keep the yes/no flags as before 405 // ("Yes" only) so existing theme code reading them behaves the same. 406 $pets_policy = sanitize_text_field(self::arr_get($features, 'PropertyPetsAllowed')); 407 $smokers_policy = sanitize_text_field(self::arr_get($features, 'PropertySmokersAllowed')); 408 update_post_meta($post_id, 'ipp_pets_policy', $pets_policy); 409 update_post_meta($post_id, 'ipp_smokers_policy', $smokers_policy); 410 update_post_meta($post_id, 'ipp_pets_allowed', 'Yes' === $pets_policy ? '1' : '0'); 411 update_post_meta($post_id, 'other_pets', 'Yes' === $pets_policy ? '1' : '0'); // legacy 412 update_post_meta($post_id, 'ipp_smokers_allowed', 'Yes' === $smokers_policy ? '1' : '0'); 413 update_post_meta($post_id, 'property_smokers_allowed', 'Yes' === $smokers_policy ? '1' : '0'); // legacy 288 414 update_post_meta($post_id, 'ipp_class', sanitize_text_field(self::arr_get($features, 'PropertyClass'))); 289 415 update_post_meta($post_id, 'property_class', sanitize_text_field(self::arr_get($features, 'PropertyClass'))); // legacy … … 430 556 431 557 // === Schedule gallery fetch === 432 // Clear ALL existing gallery cron events for this property first 433 $crons = _get_cron_array(); 434 if ( is_array( $crons ) ) { 435 foreach ( $crons as $ts => $hooks ) { 436 if ( isset( $hooks['update_integrate_palace_gallery'] ) ) { 437 foreach ( $hooks['update_integrate_palace_gallery'] as $hash => $event ) { 438 $args = $event['args'] ?? array(); 439 if ( isset( $args[0] ) && (int) $args[0] === (int) $post_id ) { 440 wp_unschedule_event( $ts, 'update_integrate_palace_gallery', $args ); 558 // Skipped for properties that already have photos when the caller says 559 // images need no refresh (the one-off re-import after an upgrade), so 560 // re-applying import rules does not re-download every photo. 561 $has_gallery = ! empty( get_post_meta( $post_id, 'integrate_palace_gallery', true ) ); 562 if ( $refresh_images || ! $has_gallery ) { 563 // Clear ALL existing gallery cron events for this property first 564 $crons = _get_cron_array(); 565 if ( is_array( $crons ) ) { 566 foreach ( $crons as $ts => $hooks ) { 567 if ( isset( $hooks['update_integrate_palace_gallery'] ) ) { 568 foreach ( $hooks['update_integrate_palace_gallery'] as $hash => $event ) { 569 $args = $event['args'] ?? array(); 570 if ( isset( $args[0] ) && (int) $args[0] === (int) $post_id ) { 571 wp_unschedule_event( $ts, 'update_integrate_palace_gallery', $args ); 572 } 441 573 } 442 574 } 443 575 } 444 576 } 445 } 446 // Reset retry counter and schedule fresh 447 delete_post_meta( $post_id, 'ipp_gallery_sync_retries' ); 448 wp_schedule_single_event( time() + 10, 'update_integrate_palace_gallery', array( $post_id, $property_code ) ); 449 IntegratePalace_Properties_Admin::update_gallery_sync_status( $post_id, 'queued', 'Queued for gallery sync.' ); 450 update_post_meta( $post_id, 'ipp_gallery_sync_started_at', current_time( 'mysql' ) ); 451 452 /** @hook ipp_after_property_save — Fires after a property is saved/updated via webhook (all meta written). */ 577 // Reset retry counter and schedule fresh 578 delete_post_meta( $post_id, 'ipp_gallery_sync_retries' ); 579 wp_schedule_single_event( time() + 10, 'update_integrate_palace_gallery', array( $post_id, $property_code ) ); 580 IntegratePalace_Properties_Admin::update_gallery_sync_status( $post_id, 'queued', 'Queued for gallery sync.' ); 581 update_post_meta( $post_id, 'ipp_gallery_sync_started_at', current_time( 'mysql' ) ); 582 } 583 584 // Record the change code LAST. It is what tells the next sync this 585 // property is up to date, so if the request dies part-way through the 586 // import above, leaving the old code in place means it gets retried. 587 update_post_meta($post_id, 'ipp_change_code', sanitize_text_field(self::arr_get($property, 'PropertyChangeCode'))); 588 update_post_meta($post_id, 'information_code', sanitize_text_field(self::arr_get($property, 'PropertyChangeCode'))); // legacy 589 590 /** @hook ipp_after_property_save — Fires after a property is saved/updated (all meta written). */ 453 591 do_action( 'ipp_after_property_save', $post_id, $property ); 454 592 455 593 do_action('ipp_property_synced', $post_id, $property); 456 594 457 // Update last sync time — tracks when properties were last received via webhook595 // Track when property data was last written. 458 596 update_option( 'ipp_last_sync_time', current_time( 'mysql' ), false ); 459 597 $sync_count = wp_count_posts( 'palace-properties' ); 460 598 update_option( 'ipp_last_sync_count', isset( $sync_count->publish ) ? $sync_count->publish : 0, false ); 461 599 462 return new WP_REST_Response(array('status' => 'success'), 200);600 return (int) $post_id; 463 601 } 464 602 } -
integrate-palace-properties/trunk/includes/class-integratepalacep.php
r3486430 r3694341 22 22 $this->define_admin_menu(); 23 23 $this->register_settings(); 24 $this->register_webhooks(); 24 $this->register_property_importer(); 25 // Scheduled Palace polling. Registered unconditionally: WP-Cron runs in 26 // a front-end request context, so this cannot be admin-only. 27 IPP_Sync::init(); 25 28 IntegratePalace_Properties_Admin_Ajax::init(); 26 29 $this->define_palace_properties(); … … 33 36 private function load_dependencies() { 34 37 require_once $this->integrate_palace_dir . 'includes/class-integratepalacep-loader.php'; 38 require_once $this->integrate_palace_dir . 'includes/class-ipp-sync.php'; 39 if ( defined( 'WP_CLI' ) && WP_CLI ) { 40 require_once $this->integrate_palace_dir . 'includes/class-ipp-sync-cli.php'; 41 } 35 42 require_once $this->integrate_palace_dir . 'includes/class-integratepalacep-webhooks.php'; 36 43 require_once $this->integrate_palace_dir . 'admin/class-integratepalacep-admin.php'; … … 135 142 } 136 143 137 private function register_ webhooks() {144 private function register_property_importer() { 138 145 IntegratePalace_Properties_Webhooks::init(); 139 146 } … … 220 227 $md_file = $this->integrate_palace_dir . 'DEVELOPERS.md'; 221 228 $content = file_exists( $md_file ) ? file_get_contents( $md_file ) : ''; 229 230 if ( '' === trim( $content ) ) { 231 echo '<div class="wrap"><h1>' . esc_html__( 'Developer Documentation', 'integrate-palace-properties' ) . '</h1>'; 232 echo '<p>' . esc_html__( 'The documentation file could not be read. It ships with the plugin as DEVELOPERS.md in the plugin folder.', 'integrate-palace-properties' ) . '</p></div>'; 233 return; 234 } 222 235 223 236 echo '<div class="wrap" style="max-width:960px;">'; -
integrate-palace-properties/trunk/includes/class-ipp-customizer-settings.php
r3486430 r3694341 12 12 add_action( 'customize_register', array( __CLASS__, 'register' ), 20 ); 13 13 add_action( 'wp_head', array( __CLASS__, 'output_css' ), 99 ); 14 add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_google_fonts' ) ); 14 15 add_action( 'customize_controls_enqueue_scripts', array( __CLASS__, 'customizer_preview_nav' ) ); 15 16 } … … 361 362 } 362 363 364 // ─── Google Fonts ──────────────────────────────────────────── 365 366 /** 367 * Load the Google Fonts chosen in the Customizer on property pages. 368 * 369 * Visitors' browsers fetch these from fonts.googleapis.com, as disclosed in 370 * readme.txt. Nothing is loaded unless a Google font has been chosen. 371 * 372 * @return void 373 */ 374 public static function enqueue_google_fonts() { 375 if ( ! is_singular( 'palace-properties' ) && ! is_post_type_archive( 'palace-properties' ) && ! is_tax( array( 'palace-property-type', 'palace-property-status', 'palace-property-region' ) ) ) { 376 return; 377 } 378 379 $d = self::defaults(); 380 $font_heading = get_theme_mod( 'ipp_font_heading', $d['ipp_font_heading'] ?? '' ); 381 $font_body = get_theme_mod( 'ipp_font_body', $d['ipp_font_body'] ?? '' ); 382 $not_google = array( '', 'inherit', 'system-ui', 'Georgia' ); 383 384 $google_fonts = array(); 385 if ( ! in_array( $font_heading, $not_google, true ) ) { 386 $google_fonts[] = $font_heading; 387 } 388 if ( ! in_array( $font_body, $not_google, true ) && $font_body !== $font_heading ) { 389 $google_fonts[] = $font_body; 390 } 391 392 if ( empty( $google_fonts ) ) { 393 return; 394 } 395 396 $families = implode( 397 '&family=', 398 array_map( 399 function ( $font ) { 400 return str_replace( ' ', '+', $font ) . ':wght@400;500;600;700'; 401 }, 402 $google_fonts 403 ) 404 ); 405 406 // A null version stops WordPress appending ?ver=, which the Google Fonts 407 // css2 endpoint does not use. 408 wp_enqueue_style( 'ipp-google-fonts', 'https://fonts.googleapis.com/css2?family=' . $families . '&display=swap', array(), null ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion 409 } 410 363 411 // ─── CSS Output ────────────────────────────────────────────── 364 412 … … 383 431 $font_body = $get('ipp_font_body'); 384 432 385 // Enqueue Google Fonts if needed 386 $google_fonts = array(); 387 if ( $font_heading && $font_heading !== 'inherit' && $font_heading !== 'system-ui' && $font_heading !== 'Georgia' ) { 388 $google_fonts[] = $font_heading; 389 } 390 if ( $font_body && $font_body !== 'inherit' && $font_body !== 'system-ui' && $font_body !== 'Georgia' && $font_body !== $font_heading ) { 391 $google_fonts[] = $font_body; 392 } 393 if ( ! empty( $google_fonts ) ) { 394 $families = implode( '&family=', array_map( function($f) { return str_replace(' ', '+', $f) . ':wght@400;500;600;700'; }, $google_fonts ) ); 395 echo '<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=' . esc_attr( $families ) . '&display=swap" />' . "\n"; 396 } 433 // Google Fonts are loaded by enqueue_google_fonts(), through 434 // wp_enqueue_style(), rather than printed here. 397 435 398 436 $card_shadow = $shadow_map[ $get('ipp_card_shadow') ] ?? $shadow_map['medium']; -
integrate-palace-properties/trunk/includes/class-ipp-developer-api.php
r3486430 r3694341 34 34 global $wpdb; 35 35 $like = '%' . $wpdb->esc_like( $search_term ) . '%'; 36 $meta_keys = "'ipp_address1','ipp_address2','ipp_address3','ipp_suburb','ipp_region','ipp_postcode','ipp_property_code','ipp_agent_full_name','ipp_class','ipp_management_type','information_address','information_suburb','information_region','ipp_header','ipp_name','ipp_property_code_global'"; 36 37 $meta_keys = array( 38 'ipp_address1', 39 'ipp_address2', 40 'ipp_address3', 41 'ipp_suburb', 42 'ipp_region', 43 'ipp_postcode', 44 'ipp_property_code', 45 'ipp_agent_full_name', 46 'ipp_class', 47 'ipp_management_type', 48 'information_address', 49 'information_suburb', 50 'information_region', 51 'ipp_header', 52 'ipp_name', 53 'ipp_property_code_global', 54 ); 55 56 // Build one %s per meta key so the whole IN list goes through 57 // prepare() rather than being interpolated into the statement. 58 $placeholders = implode( ',', array_fill( 0, count( $meta_keys ), '%s' ) ); 59 37 60 $meta_condition = $wpdb->prepare( 38 " OR ({$wpdb->posts}.ID IN (SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key IN ({$meta_keys}) AND meta_value LIKE %s))", 39 $like 61 // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $placeholders is a generated list of %s tokens, and the table names come from $wpdb. 62 " OR ({$wpdb->posts}.ID IN (SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key IN ({$placeholders}) AND meta_value LIKE %s))", 63 array_merge( $meta_keys, array( $like ) ) 40 64 ); 41 65 // Append our meta condition before the closing parenthesis of the search WHERE … … 284 308 'land_area_hectares' => $prop->land_area_hectares(), 285 309 'pets_allowed' => $prop->pets_allowed(), 310 'pets_policy' => $prop->pets_label(), 286 311 'smokers_allowed' => $prop->smokers_allowed(), 312 'smokers_policy' => $prop->smokers_label(), 287 313 ], 288 314 'agent' => [ -
integrate-palace-properties/trunk/includes/class-ipp-hooks.php
r3486430 r3694341 70 70 * Fire when a sync cycle starts. 71 71 * 72 * @param string $subscription_id73 */ 74 public static function sync_started( $ subscription_id ) {75 do_action( 'ipp_sync_started', $ subscription_id );72 * @param int $queued Number of properties queued for import. 73 */ 74 public static function sync_started( $queued ) { 75 do_action( 'ipp_sync_started', $queued ); 76 76 } 77 77 … … 79 79 * Fire when a sync cycle completes. 80 80 * 81 * @param string $subscription_id82 * @param int $count Number of properties synced.83 */ 84 public static function sync_completed( $ subscription_id, $count) {85 do_action( 'ipp_sync_completed', $ subscription_id, $count);81 * @param int $imported Number of properties created or updated. 82 * @param int $deleted Number of properties removed. 83 */ 84 public static function sync_completed( $imported, $deleted ) { 85 do_action( 'ipp_sync_completed', $imported, $deleted ); 86 86 } 87 87 … … 243 243 'actions' => [ 244 244 // Lifecycle 245 'ipp_before_property_save' => 'Fires before a property is saved via webhook. Args: $post_id, $property_data',246 'ipp_after_property_save' => 'Fires after a property is saved via webhook. Args: $post_id, $property_data',245 'ipp_before_property_save' => 'Fires before a property is saved. Args: $post_id, $property_data', 246 'ipp_after_property_save' => 'Fires after a property is saved. Args: $post_id, $property_data', 247 247 'ipp_before_property_delete' => 'Fires before a property is deleted. Args: $post_id, $property_code', 248 248 'ipp_after_property_delete' => 'Fires after a property is deleted. Args: $post_id, $property_code', 249 'ipp_sync_started' => 'Fires when a sync cycle begins. Args: $ subscription_id',250 'ipp_sync_completed' => 'Fires when a sync cycle ends. Args: $ subscription_id, $count',249 'ipp_sync_started' => 'Fires when a sync cycle begins. Args: $queued', 250 'ipp_sync_completed' => 'Fires when a sync cycle ends. Args: $imported, $deleted', 251 251 'ipp_gallery_updated' => 'Fires after gallery images are synced. Args: $post_id, $image_ids', 252 252 'ipp_property_synced' => 'Fires after a property is fully synced (existing). Args: $post_id, $property_data', … … 267 267 ], 268 268 'filters' => [ 269 // Sync 270 'ipp_sync_fetched_properties' => 'Filter the raw property list from the Palace API before diffing. Args: $properties', 271 'ipp_sync_batch_size' => 'Properties imported per cron tick (default 10). Args: $size', 272 'ipp_sync_max_delete_ratio' => 'Largest share of the library one run may delete (default 0.5). Args: $ratio', 273 'ipp_sync_min_missing_seconds' => 'How long a property must stay missing before removal (default half the interval, min 10 minutes). Args: $seconds', 274 'ipp_sync_tick_seconds' => 'Seconds one cron tick keeps working before yielding (default 20). Args: $seconds', 275 'ipp_gallery_tick_seconds' => 'Seconds one cron request processes image jobs before deferring (default 20). Args: $seconds', 276 'ipp_property_post_status' => 'Status a synced property is saved with (publish, or draft when Palace says not to publish). Args: $status, $property', 277 'ipp_address_hidden' => 'Whether a property street address is hidden from visitors. Args: $hidden, $post_id', 278 269 279 // Data 270 280 'ipp_property_data' => 'Filter property data array before display. Args: $data, $post_id', -
integrate-palace-properties/trunk/includes/class-ipp-rest-api.php
r3486430 r3694341 183 183 * @return array 184 184 */ 185 /** 186 * Whether a property may be shown to the public: a published, non-hidden 187 * palace-properties post. 188 * 189 * @param int $post_id Post ID. 190 * @return bool 191 */ 192 private static function is_public_property( $post_id ) { 193 return 'palace-properties' === get_post_type( $post_id ) 194 && 'publish' === get_post_status( $post_id ) 195 && '1' !== get_post_meta( $post_id, 'ipp_hide_property', true ); 196 } 197 185 198 private static function format_property( $post_id ) { 186 199 $data = IPP_Developer_API::property_to_array( $post_id ); … … 243 256 public static function get_property( WP_REST_Request $request ) { 244 257 $post_id = absint( $request->get_param( 'id' ) ); 258 259 // This endpoint is public. Only published listings may be served: a draft 260 // is a listing Palace says must not be published online. 261 if ( ! self::is_public_property( $post_id ) ) { 262 return new WP_Error( 'not_found', 'Property not found', [ 'status' => 404 ] ); 263 } 264 245 265 $data = self::format_property( $post_id ); 246 266 … … 259 279 $post = get_post( $post_id ); 260 280 261 if ( ! $post || $post->post_type !== 'palace-properties' ) {281 if ( ! $post || $post->post_type !== 'palace-properties' || ! self::is_public_property( $post_id ) ) { 262 282 return new WP_Error( 'not_found', 'Property not found', [ 'status' => 404 ] ); 263 283 } -
integrate-palace-properties/trunk/includes/class-ipp-shortcodes.php
r3486430 r3694341 132 132 if ( strtolower( $atts['show_pagination'] ) === 'yes' && $query->max_num_pages > 1 ) { 133 133 echo '<div class="ipp-pagination ipp-shortcode-pagination">'; 134 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- paginate_links() returns markup already generated and escaped by WordPress core; wp_kses_post() would strip its aria-current attribute. 134 135 echo paginate_links( [ 135 136 'total' => $query->max_num_pages, … … 166 167 } 167 168 168 if ( ! $post_id || get_post_type( $post_id ) !== 'palace-properties') {169 if ( ! $post_id || ! self::can_display( $post_id ) ) { 169 170 return '<!-- Palace Properties: Invalid property ID -->'; 170 171 } … … 333 334 334 335 $post_id = absint( $atts['id'] ) ?: get_the_ID(); 335 if ( ! $post_id ) return '';336 if ( ! $post_id || ! self::can_display( $post_id ) ) return ''; 336 337 337 338 $prop = new IPP_Property_Helper( $post_id ); … … 380 381 381 382 $post_id = absint( $atts['id'] ) ?: get_the_ID(); 382 if ( ! $post_id || get_post_type( $post_id ) !== 'palace-properties') {383 if ( ! $post_id || ! self::can_display( $post_id ) ) { 383 384 return '<!-- Palace Properties: Invalid property ID for agent -->'; 384 385 } … … 429 430 return ob_get_clean(); 430 431 } 432 433 /** 434 * Whether a shortcode may render this property. 435 * 436 * Shortcodes appear on public pages, so a listing Palace says must not be 437 * published online (kept as a draft) is only shown to someone who could 438 * already see it, such as an editor previewing their own page. 439 * 440 * @param int $post_id Property post ID. 441 * @return bool 442 */ 443 private static function can_display( $post_id ) { 444 if ( 'palace-properties' !== get_post_type( $post_id ) ) { 445 return false; 446 } 447 448 return 'publish' === get_post_status( $post_id ) || current_user_can( 'read_post', $post_id ); 449 } 431 450 } 432 451 -
integrate-palace-properties/trunk/includes/customizer/class-integratepalacep-customizer-register_sections_panels.php
r3236864 r3694341 1 1 <?php 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; 4 } 2 5 3 6 if ( ! class_exists( 'IntegratePalace_Properties_Customizer_Register_Sections_Panels' ) ) { -
integrate-palace-properties/trunk/includes/customizer/class-integratepalacep-customizer-sanitizes.php
r3236864 r3694341 1 1 <?php 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; 4 } 2 5 if ( ! class_exists( 'IntegratePalace_Properties_Customizer_Sanitizes' ) ) { 3 6 -
integrate-palace-properties/trunk/includes/customizer/class-integratepalacep-template-defaults.php
r3236864 r3694341 1 1 <?php 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; 4 } 2 5 3 6 if (!class_exists('IntegratePalace_Properties_Template_Defaults')) { -
integrate-palace-properties/trunk/includes/customizer/class-integratepalacep-template-dynamic-css.php
r3236864 r3694341 1 1 <?php 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; 4 } 2 5 3 6 if (!class_exists('IntegratePalace_Properties_Template_Dynamic_CSS')) { … … 41 44 42 45 // Primary Button Padding 43 $pBtnPaddingTD = $ settings['primary_btn_paddings']['desktop']['top'] ?? 0.625;44 $pBtnPaddingRD = $ settings['primary_btn_paddings']['desktop']['right'] ?? 1.5;45 $pBtnPaddingBD = $ settings['primary_btn_paddings']['desktop']['bottom'] ?? 0.625;46 $pBtnPaddingLD = $ settings['primary_btn_paddings']['desktop']['left'] ?? 1.5;47 $pBtnPaddingUnit = $ settings['primary_btn_paddings']['unit'] ?? 'rem';46 $pBtnPaddingTD = $options['primary_btn_paddings']['desktop']['top'] ?? 0.625; 47 $pBtnPaddingRD = $options['primary_btn_paddings']['desktop']['right'] ?? 1.5; 48 $pBtnPaddingBD = $options['primary_btn_paddings']['desktop']['bottom'] ?? 0.625; 49 $pBtnPaddingLD = $options['primary_btn_paddings']['desktop']['left'] ?? 1.5; 50 $pBtnPaddingUnit = $options['primary_btn_paddings']['unit'] ?? 'rem'; 48 51 $pBtnPaddings_D = esc_attr($pBtnPaddingTD) . $pBtnPaddingUnit . ' ' . esc_attr($pBtnPaddingRD) . $pBtnPaddingUnit . ' ' . esc_attr($pBtnPaddingBD) . $pBtnPaddingUnit . ' ' . esc_attr($pBtnPaddingLD) . $pBtnPaddingUnit; 49 52 … … 82 85 83 86 // Secondary Button Padding 84 $sBtnPaddingTD = $ settings['secondary_btn_paddings']['desktop']['top'] ?? 0.625;85 $sBtnPaddingRD = $ settings['secondary_btn_paddings']['desktop']['right'] ?? 1.5;86 $sBtnPaddingBD = $ settings['secondary_btn_paddings']['desktop']['bottom'] ?? 0.625;87 $sBtnPaddingLD = $ settings['secondary_btn_paddings']['desktop']['left'] ?? 1.5;88 $sBtnPaddingUnit = $ settings['secondary_btn_paddings']['unit'] ?? 'rem';87 $sBtnPaddingTD = $options['secondary_btn_paddings']['desktop']['top'] ?? 0.625; 88 $sBtnPaddingRD = $options['secondary_btn_paddings']['desktop']['right'] ?? 1.5; 89 $sBtnPaddingBD = $options['secondary_btn_paddings']['desktop']['bottom'] ?? 0.625; 90 $sBtnPaddingLD = $options['secondary_btn_paddings']['desktop']['left'] ?? 1.5; 91 $sBtnPaddingUnit = $options['secondary_btn_paddings']['unit'] ?? 'rem'; 89 92 $sBtnPaddings_D = esc_attr($sBtnPaddingTD) . $sBtnPaddingUnit . ' ' . esc_attr($sBtnPaddingRD) . $sBtnPaddingUnit . ' ' . esc_attr($sBtnPaddingBD) . $sBtnPaddingUnit . ' ' . esc_attr($sBtnPaddingLD) . $sBtnPaddingUnit; 90 93 … … 107 110 108 111 112 // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- Generated CSS: every interpolated value is escaped with esc_attr() individually (see above); escaping the whole block would corrupt the stylesheet. 109 113 echo "<style> 110 114 … … 187 191 188 192 </style>"; 193 // phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped 189 194 } 190 195 -
integrate-palace-properties/trunk/includes/customizer/configurations/class-integratepalacep-colors-config.php
r3236864 r3694341 45 45 'type' => 'control', 46 46 'control' => 'IPPR_Colors', 47 'label' => sprintf( __( '%s', 'integrate-palace-properties' ), $template_name ),47 'label' => $template_name, 48 48 'section' => IPPR_SETTINGS . '[template_colors_section]', 49 49 'settings' => $settings_map, -
integrate-palace-properties/trunk/includes/customizer/configurations/class-integratepalacep-typography-config.php
r3236864 r3694341 1 1 <?php 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; 4 } 2 5 if ( ! class_exists( 'IntegratePalace_Properties_Typography' ) ) { 3 6 -
integrate-palace-properties/trunk/includes/customizer/extend-custom-controls/class-integratepalacep-extend-custom-controls.php
r3236864 r3694341 94 94 value="<?php echo esc_attr( $value ); ?>" 95 95 id="<?php echo esc_attr( $this->id . '_' . $value ); ?>" 96 <?php echo$this->link(); ?>96 <?php $this->link(); ?> 97 97 <?php checked( $this->value(), $value ); ?> 98 98 aria-label="<?php echo esc_attr( $tooltip ); ?>" /> 99 99 <label for="<?php echo esc_attr( $this->id . '_' . $value ); ?>" class="ippr-radio-img-svg"> 100 <?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon( $value ); ?>100 <?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon( $value ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Trusted static SVG markup from the plugin-bundled svg.json asset; escaping would strip the icon. ?> 101 101 <?php if ( $label ) : ?> 102 <span class="ippr-tooltip" data-tooltip="<?php echo $tooltip; ?>"></span>102 <span class="ippr-tooltip" data-tooltip="<?php echo esc_attr( $label ); ?>"></span> 103 103 <?php endif; ?> 104 104 </label> … … 263 263 264 264 ?> 265 <div class="ippr-responsive-button-control" data-setting-id="<?php echo $setting_id; ?>">265 <div class="ippr-responsive-button-control" data-setting-id="<?php echo $setting_id; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $setting_id is already escaped with esc_attr() above. ?>"> 266 266 <div class="ippr-responsive-button-wrapper"> 267 267 <!-- Tabs Section --> … … 271 271 <?php foreach ($this->devices as $device): ?> 272 272 <div class="ippr-responsive-device-icon ippr-responsive-button-icon <?php echo esc_attr($device); ?>" data-device="<?php echo esc_attr($device); ?>"> 273 <?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon($device); ?>273 <?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon($device); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Trusted static SVG markup from the plugin-bundled svg.json asset; escaping would strip the icon. ?> 274 274 </div> 275 275 <?php endforeach; ?> … … 282 282 <input 283 283 type="radio" 284 name="<?php echo $setting_id ?>"285 value="<?php echo $unit; ?>"284 name="<?php echo $setting_id; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $setting_id is already escaped with esc_attr() above. ?>" 285 value="<?php echo esc_attr($unit); ?>" 286 286 <?php checked($btn_sides_value['unit'] ?? 'rem', $unit); ?> 287 287 /> 288 <?php echo strtoupper($unit); ?>288 <?php echo esc_html(strtoupper($unit)); ?> 289 289 </label> 290 290 <?php endforeach; ?> … … 296 296 <ul class="ippr-spacing-wrapper"> 297 297 <?php foreach ($this->devices as $device): ?> 298 <li class="ippr-spacing-input-item ippr-number-control" data-device="<?php echo $device; ?>">298 <li class="ippr-spacing-input-item ippr-number-control" data-device="<?php echo esc_attr($device); ?>"> 299 299 <?php foreach (['top', 'right', 'bottom', 'left'] as $side): ?> 300 300 <div class="ippr-spacing-input-item-group"> … … 302 302 id="<?php echo esc_attr($setting_id . '_' .$device . '_' . $side); ?>" 303 303 type="number" 304 class="padding-<?php echo $side; ?> ippr-spacing-input"304 class="padding-<?php echo esc_attr($side); ?> ippr-spacing-input" 305 305 value="<?php echo esc_attr($btn_sides_value[$device][$side] ?? ''); ?>" 306 data-side="<?php echo $side; ?>"306 data-side="<?php echo esc_attr($side); ?>" 307 307 placeholder="" 308 308 > … … 316 316 <div class="ippr-spacing-input-item-uniform"> 317 317 <div class="toggle-uniform"> 318 <span class="ippr-spacing-disconnected"><? = Integrate_Palace_Properties_Icons::fetch_svg_icon('spacing-disconnected');?></span>319 <span class="ippr-spacing-connected"><? = Integrate_Palace_Properties_Icons::fetch_svg_icon('spacing-connected');?></span>318 <span class="ippr-spacing-disconnected"><?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon('spacing-disconnected'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Trusted static SVG markup from the plugin-bundled svg.json asset; escaping would strip the icon. ?></span> 319 <span class="ippr-spacing-connected"><?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon('spacing-connected'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Trusted static SVG markup from the plugin-bundled svg.json asset; escaping would strip the icon. ?></span> 320 320 </div> 321 321 </div> … … 366 366 367 367 ?> 368 <div class="ippr-responsive-button-control" data-setting-id="<?php echo $setting_id; ?>">368 <div class="ippr-responsive-button-control" data-setting-id="<?php echo $setting_id; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $setting_id is already escaped with esc_attr() above. ?>"> 369 369 <div class="ippr-responsive-button-wrapper"> 370 370 <div class="ippr-responsive-button-tabs"> … … 379 379 <input 380 380 type="radio" 381 name="<?php echo $setting_id ?>"381 name="<?php echo $setting_id; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $setting_id is already escaped with esc_attr() above. ?>" 382 382 value="<?php echo esc_attr($unit); ?>" 383 383 <?php checked($btn_sides_value['unit'] ?? 'px', $unit); ?> 384 384 /> 385 <?php echo strtoupper($unit); ?>385 <?php echo esc_html(strtoupper($unit)); ?> 386 386 </label> 387 387 <?php endforeach; ?> … … 414 414 <div class="toggle-uniform"> 415 415 <span class="ippr-spacing-disconnected"> 416 <?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon('spacing-disconnected'); ?>416 <?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon('spacing-disconnected'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Trusted static SVG markup from the plugin-bundled svg.json asset; escaping would strip the icon. ?> 417 417 </span> 418 418 <span class="ippr-spacing-connected"> 419 <?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon('spacing-connected'); ?>419 <?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon('spacing-connected'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Trusted static SVG markup from the plugin-bundled svg.json asset; escaping would strip the icon. ?> 420 420 </span> 421 421 </div> … … 498 498 <div class="ippr-btn-font-family ippr-bottom-border-dotted"> 499 499 <!-- Font Family --> 500 <label><?php _e('Font Family', 'integrate-palace-properties'); ?></label>500 <label><?php esc_html_e('Font Family', 'integrate-palace-properties'); ?></label> 501 501 <select class="ippr-btn-font-family-control" <?php $this->link( 'font_family' ); ?>> 502 502 <?php foreach ( $this->font_families as $font_family ) : ?> … … 510 510 <div class="ippr-btn-font-weight ippr-bottom-border-dotted"> 511 511 <!-- Font Weight --> 512 <label><?php _e('Font Weight', 'integrate-palace-properties'); ?></label>512 <label><?php esc_html_e('Font Weight', 'integrate-palace-properties'); ?></label> 513 513 <select class="ippr-btn-font-weight-control" <?php $this->link( 'font_weight' ); ?>> 514 514 <?php foreach ( $this->font_weight as $font_weight ) : ?> … … 522 522 <div class="ippr-responsive-button-tabs"> 523 523 <div class="ippr-responsive-device-icons"> 524 <label><?php echo __( 'Size', 'integrate-palace-properties' ); ?></label>524 <label><?php echo esc_html__( 'Size', 'integrate-palace-properties' ); ?></label> 525 525 <?php foreach ($this->devices as $device): ?> 526 526 <div class="ippr-responsive-device-icon ippr-responsive-font-icon<?php echo esc_attr($device); ?>"> 527 <?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon($device); ?>527 <?php echo Integrate_Palace_Properties_Icons::fetch_svg_icon($device); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Trusted static SVG markup from the plugin-bundled svg.json asset; escaping would strip the icon. ?> 528 528 </div> 529 529 <?php endforeach; ?> … … 535 535 <label> 536 536 <input type="radio" name="<?php echo esc_attr( "{$control_type}_font_size_unit" ); ?>" value="<?php echo esc_attr( $font_unit ); ?>" <?php checked( $cur_font_size_unit, $font_unit ); ?> <?php $this->link( 'font_unit' ); ?>/> 537 <?php echo strtoupper(esc_html($font_unit)); ?>537 <?php echo esc_html(strtoupper($font_unit)); ?> 538 538 </label> 539 539 <?php endforeach; ?> … … 542 542 </div> 543 543 544 <div class="ippr-spacing-wrapper ippr-responsive-font-size" data-setting-id="<?php echo $setting_id?>">544 <div class="ippr-spacing-wrapper ippr-responsive-font-size" data-setting-id="<?php echo esc_attr($setting_id); ?>"> 545 545 <!-- Font Size --> 546 546 <div class="ippr-responsive-font-size-slider"> -
integrate-palace-properties/trunk/includes/customizer/extend-customizer/class-integratepalacep-customize-panels.php
r3236864 r3694341 1 1 <?php 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; 4 } 2 5 3 6 if ( class_exists( 'WP_Customize_Panel' ) && !class_exists( 'IntegratePalace_Properties_Property_Panel' ) ) { -
integrate-palace-properties/trunk/includes/customizer/extend-customizer/class-integratepalacep-customize-sections.php
r3236864 r3694341 1 1 <?php 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; 4 } 2 5 3 6 if ( class_exists( 'WP_Customize_Section' ) && !class_exists( 'IntegratePalace_Properties_Property_Customize_Section' ) ) { -
integrate-palace-properties/trunk/integrate-palace-properties.php
r3524450 r3694341 2 2 /** 3 3 * Plugin Name: Integrate Palace Properties 4 * Description: A plugin to syncronize wp palace properties to your wordpress blog/website. 5 * Version: 2.1.6 4 * Plugin URI: https://wordpress.org/plugins/integrate-palace-properties/ 5 * Description: Sync property listings from MRI Palace to WordPress, directly from your own site. 6 * Version: 3.0.0 7 * Requires at least: 5.8 8 * Requires PHP: 8.0 6 9 * Author: SAFDAR 7 * Author URI: https:// wp-palace.kiwibrain.co.nz/10 * Author URI: https://kiwibrain.co.nz/ 8 11 * Text Domain: integrate-palace-properties 9 12 * Domain Path: /languages … … 20 23 21 24 // Define plugin version. 22 define( 'INTEGRATE_PALACE_P_VERSION', ' 2.1.6' );25 define( 'INTEGRATE_PALACE_P_VERSION', '3.0.0' ); 23 26 define( 'IPPR_SETTINGS', 'ippr-template-settings' ); 24 27 define('INTEGRATE_PALACE_P_PLUGIN_DIR', plugin_dir_path(__FILE__)); … … 31 34 32 35 if ( ! file_exists( $integrate_palace_activator ) ) { 33 wp_die( __( 'Required activation files are missing. Please reinstall the plugin.', 'integrate-palace-properties' ) );36 wp_die( esc_html__( 'Required activation files are missing. Please reinstall the plugin.', 'integrate-palace-properties' ) ); 34 37 } 35 38 … … 44 47 register_activation_hook( __FILE__, 'integrate_palace_activate' ); 45 48 49 // Deactivation: clear scheduled events so no orphaned cron entries are left. 50 function integrate_palace_deactivate() { 51 52 $integrate_palace_deactivator = INTEGRATE_PALACE_P_PLUGIN_DIR . 'includes/class-integratepalacep-deactivator.php'; 53 54 if ( ! file_exists( $integrate_palace_deactivator ) ) { 55 return; 56 } 57 58 require_once $integrate_palace_deactivator; 59 60 if ( class_exists( 'IntegratePalace_Properties_Deactivator' ) ) { 61 IntegratePalace_Properties_Deactivator::deactivate(); 62 } 63 64 } 65 66 register_deactivation_hook( __FILE__, 'integrate_palace_deactivate' ); 67 46 68 // Include the main class file. 47 69 require INTEGRATE_PALACE_P_PLUGIN_DIR . 'includes/class-integratepalacep.php'; -
integrate-palace-properties/trunk/public/archive-palace_property.php
r3236864 r3694341 9 9 */ 10 10 if ( ! defined( 'ABSPATH' ) ) exit; 11 get_header();11 IntegratePalace_Properties_Public::render_header(); 12 12 13 13 $options = get_option( 'integrate_palace_settings' ); … … 103 103 104 104 // Bedroom filter 105 if ( isset( $_GET['bedroom'] ) && str_replace( '%20', ' ', $_GET['bedroom'] ) !== 'Any Bedrooms' ) { 106 $bedrooms = absint( $_GET['bedroom'] ); 105 $bedroom_param = isset( $_GET['bedroom'] ) ? sanitize_text_field( wp_unslash( $_GET['bedroom'] ) ) : ''; 106 if ( '' !== $bedroom_param && str_replace( '%20', ' ', $bedroom_param ) !== 'Any Bedrooms' ) { 107 $bedrooms = absint( $bedroom_param ); 107 108 $meta_query[] = array( 108 109 'key' => 'accommodation_bed_room', … … 114 115 115 116 // Bathroom filter 116 if ( isset( $_GET['bathroom'] ) && str_replace( '%20', ' ', $_GET['bathroom'] ) !== 'Any Bathrooms' ) { 117 $bathrooms = absint( $_GET['bathroom'] ); 117 $bathroom_param = isset( $_GET['bathroom'] ) ? sanitize_text_field( wp_unslash( $_GET['bathroom'] ) ) : ''; 118 if ( '' !== $bathroom_param && str_replace( '%20', ' ', $bathroom_param ) !== 'Any Bathrooms' ) { 119 $bathrooms = absint( $bathroom_param ); 118 120 $meta_query[] = array( 119 121 'key' => 'accommodation_bath_room', … … 125 127 126 128 // Region filter 127 if ( isset( $_GET['region'] ) && str_replace( '%20', ' ', $_GET['region'] ) !== 'All Region' ) { 129 $region_param = isset( $_GET['region'] ) ? sanitize_text_field( wp_unslash( $_GET['region'] ) ) : ''; 130 if ( '' !== $region_param && str_replace( '%20', ' ', $region_param ) !== 'All Region' ) { 128 131 $meta_query[] = array( 129 132 'key' => 'information_region', 130 'value' => sanitize_text_field( wp_unslash( $_GET['region'] ) ),133 'value' => $region_param, 131 134 'compare' => '=', 132 135 ); … … 165 168 166 169 <?php 167 get_footer();170 IntegratePalace_Properties_Public::render_footer(); -
integrate-palace-properties/trunk/public/class-integratepalacep-public.php
r3486430 r3694341 72 72 $tax_query = array( 'relation' => 'AND' ); 73 73 if ( ! empty( $_GET['region'] ) ) { 74 $tax_query[] = array( 'taxonomy' => 'palace-property-region', 'field' => 'slug', 'terms' => sanitize_text_field( $_GET['region']) );74 $tax_query[] = array( 'taxonomy' => 'palace-property-region', 'field' => 'slug', 'terms' => sanitize_text_field( wp_unslash( $_GET['region'] ) ) ); 75 75 } 76 76 if ( ! empty( $_GET['property_type'] ) ) { 77 $tax_query[] = array( 'taxonomy' => 'palace-property-type', 'field' => 'slug', 'terms' => sanitize_text_field( $_GET['property_type']) );77 $tax_query[] = array( 'taxonomy' => 'palace-property-type', 'field' => 'slug', 'terms' => sanitize_text_field( wp_unslash( $_GET['property_type'] ) ) ); 78 78 } 79 79 if ( ! empty( $_GET['property_status'] ) ) { 80 $tax_query[] = array( 'taxonomy' => 'palace-property-status', 'field' => 'slug', 'terms' => sanitize_text_field( $_GET['property_status']) );80 $tax_query[] = array( 'taxonomy' => 'palace-property-status', 'field' => 'slug', 'terms' => sanitize_text_field( wp_unslash( $_GET['property_status'] ) ) ); 81 81 } 82 82 if ( count( $tax_query ) > 1 ) { … … 86 86 // Sort 87 87 if ( ! empty( $_GET['sort_by'] ) ) { 88 switch ( sanitize_text_field( $_GET['sort_by']) ) {88 switch ( sanitize_text_field( wp_unslash( $_GET['sort_by'] ) ) ) { 89 89 case 'price_asc': 90 90 $query->set( 'meta_key', 'ipp_rent_amount' ); … … 259 259 * Template routing for single and archive views. 260 260 */ 261 /** 262 * Open a plugin page template in a way that works with any theme. 263 * 264 * A block theme has no header.php. Calling get_header() there makes 265 * WordPress fall back to a bare compatibility header, and log a deprecation 266 * notice, so property pages lose the site's real header. On block themes 267 * the page is opened by hand and the theme's own header template part is 268 * rendered instead. 269 * 270 * @return void 271 */ 272 public static function render_header() { 273 if ( ! function_exists( 'wp_is_block_theme' ) || ! wp_is_block_theme() ) { 274 get_header(); 275 return; 276 } 277 ?><!DOCTYPE html> 278 <html <?php language_attributes(); ?>> 279 <head> 280 <meta charset="<?php bloginfo( 'charset' ); ?>"> 281 <meta name="viewport" content="width=device-width, initial-scale=1"> 282 <?php wp_head(); ?> 283 </head> 284 <body <?php body_class(); ?>> 285 <?php wp_body_open(); ?> 286 <div class="wp-site-blocks"> 287 <?php 288 // Render the header as a template-part block, exactly as a block theme's 289 // own templates do. That wraps it in a <header> landmark and applies the 290 // theme's layout styles; block_template_part() would print the bare 291 // contents with neither. do_blocks() also exists back to WordPress 5.0, 292 // so this stays within the plugin's declared minimum version. 293 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Core-rendered block markup from the active theme; escaping would break the navigation block's markup and interactivity attributes. 294 echo do_blocks( '<!-- wp:template-part {"slug":"header","tagName":"header"} /-->' ); 295 } 296 297 /** 298 * Close a plugin page template opened by render_header(). 299 * 300 * @return void 301 */ 302 public static function render_footer() { 303 if ( ! function_exists( 'wp_is_block_theme' ) || ! wp_is_block_theme() ) { 304 get_footer(); 305 return; 306 } 307 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Core-rendered block markup from the active theme. 308 echo do_blocks( '<!-- wp:template-part {"slug":"footer","tagName":"footer"} /-->' ); 309 ?> 310 </div> 311 <?php wp_footer(); ?> 312 </body> 313 </html> 314 <?php 315 } 316 261 317 public function use_palace_property_template( $template ) { 262 318 $post_type = 'palace-properties'; … … 309 365 public function ajax_load_button() { 310 366 $template_slug = $this->get_active_template(); 367 368 // Public, read-only pagination for published properties: it changes no 369 // state and exposes nothing that is not already on the archive page, so 370 // there is no action for a nonce to protect. The value is cast to an 371 // integer and used only as a page number. 372 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Read-only public endpoint, see above. 311 373 $paged = isset( $_POST['page'] ) ? intval( $_POST['page'] ) : 1; 312 374 … … 364 426 $page = isset( $_POST['page'] ) ? absint( $_POST['page'] ) : 1; 365 427 $per_page = isset( $_POST['per_page'] ) ? absint( $_POST['per_page'] ) : 9; 366 $sort_by = isset( $_POST['sort_by'] ) ? sanitize_text_field( $_POST['sort_by']) : 'date_desc';428 $sort_by = isset( $_POST['sort_by'] ) ? sanitize_text_field( wp_unslash( $_POST['sort_by'] ) ) : 'date_desc'; 367 429 368 430 // Build query … … 401 463 402 464 if ( ! empty( $_POST['search_text'] ) ) { 403 $search = sanitize_text_field( $_POST['search_text']);465 $search = sanitize_text_field( wp_unslash( $_POST['search_text'] ) ); 404 466 $args['ipp_meta_search'] = true; 405 467 $this->add_meta_search_filter( $search ); … … 462 524 'taxonomy' => 'palace-property-type', 463 525 'field' => 'slug', 464 'terms' => array_map( 'sanitize_text_field', (array) $_POST['property_type']),526 'terms' => array_map( 'sanitize_text_field', wp_unslash( (array) $_POST['property_type'] ) ), 465 527 ); 466 528 } … … 470 532 'taxonomy' => 'palace-property-status', 471 533 'field' => 'slug', 472 'terms' => array_map( 'sanitize_text_field', (array) $_POST['property_status']),534 'terms' => array_map( 'sanitize_text_field', wp_unslash( (array) $_POST['property_status'] ) ), 473 535 ); 474 536 } … … 478 540 'taxonomy' => 'palace-property-region', 479 541 'field' => 'slug', 480 'terms' => array_map( 'sanitize_text_field', (array) $_POST['region']),542 'terms' => array_map( 'sanitize_text_field', wp_unslash( (array) $_POST['region'] ) ), 481 543 ); 482 544 } -
integrate-palace-properties/trunk/public/class-integratepalacep-svg-icons.php
r3236864 r3694341 1 1 <?php 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; 4 } 2 5 if ( ! class_exists( 'Integrate_Palace_Properties_Icons' ) ) { 3 6 -
integrate-palace-properties/trunk/public/single-palace_property.php
r3236864 r3694341 10 10 11 11 if ( ! defined( 'ABSPATH' ) ) exit; 12 get_header();12 IntegratePalace_Properties_Public::render_header(); 13 13 14 14 $post_id = get_the_ID(); … … 65 65 66 66 67 <?php get_footer(); ?>67 <?php IntegratePalace_Properties_Public::render_footer(); ?> -
integrate-palace-properties/trunk/public/templates/archive.php
r3486430 r3694341 6 6 if ( ! defined( 'ABSPATH' ) ) exit; 7 7 8 get_header();8 IntegratePalace_Properties_Public::render_header(); 9 9 10 10 $template_slug = sanitize_text_field( get_option( 'ipp_select_template', 'palace-property' ) ); … … 37 37 global $wp_query; 38 38 printf( 39 /* translators: %s: number of properties found, wrapped in <strong> tags. */ 39 40 esc_html( _n( '%s Property', '%s Properties', $wp_query->found_posts, 'integrate-palace-properties' ) ), 40 41 '<strong>' . esc_html( number_format_i18n( $wp_query->found_posts ) ) . '</strong>' … … 98 99 </div> 99 100 100 <?php get_footer(); ?>101 <?php IntegratePalace_Properties_Public::render_footer(); ?> -
integrate-palace-properties/trunk/public/templates/classic/single.php
r3486430 r3694341 14 14 ?> 15 15 16 <?php echo $prop->schema_json_ld();?>16 <?php // Schema.org JSON-LD is printed once, by the wrapper (public/templates/single.php), where the ipp_property_schema filter applies. ?> 17 17 18 18 <div class="ipp-single ipp-single--classic ipp-container"> … … 111 111 'land_area' => ['Land Area', $prop->land_area_sqm() ? $prop->land_area_sqm() . ' sqm' : ''], 112 112 'parking' => ['Parking', $prop->parking()], 113 'pets_allowed' => ['Pets Allowed', $prop->pets_ allowed()],114 'smokers_allowed'=> ['Smokers Allowed', $prop->smokers_ allowed()],113 'pets_allowed' => ['Pets Allowed', $prop->pets_label()], 114 'smokers_allowed'=> ['Smokers Allowed', $prop->smokers_label()], 115 115 ]; 116 116 ?> … … 158 158 159 159 <!-- Map --> 160 <?php if ($prop->show('geographic_location') && $prop-> has_map_coords()) : ?>160 <?php if ($prop->show('geographic_location') && $prop->show_map()) : ?> 161 161 <section class="ipp-single__section" aria-labelledby="ipp-classic-map"> 162 162 <h2 id="ipp-classic-map" class="ipp-single__section-title">Location</h2> -
integrate-palace-properties/trunk/public/templates/developer/single.php
r3486430 r3694341 15 15 ?> 16 16 17 <?php echo $prop->schema_json_ld();?>17 <?php // Schema.org JSON-LD is printed once, by the wrapper (public/templates/single.php), where the ipp_property_schema filter applies. ?> 18 18 19 19 <article class="ipp-single ipp-single--developer" … … 32 32 data-date-available="<?php echo esc_attr($prop->date_available()); ?>" 33 33 data-pets-allowed="<?php echo esc_attr($prop->pets_allowed()); ?>" 34 data-pets-policy="<?php echo esc_attr($prop->pets_label()); ?>" 34 35 data-smokers-allowed="<?php echo esc_attr($prop->smokers_allowed()); ?>" 36 data-smokers-policy="<?php echo esc_attr($prop->smokers_label()); ?>" 35 37 aria-label="<?php echo esc_attr($prop->name()); ?>"> 36 38 … … 176 178 </div> 177 179 <?php endif; ?> 178 <?php if ($prop->show('pets_allowed') && $prop->pets_allowed()) : ?>180 <?php if ($prop->show('pets_allowed')) : ?> 179 181 <div data-detail="pets-allowed"> 180 182 <dt>Pets Allowed</dt> 181 <dd><?php echo esc_html($prop->pets_ allowed()); ?></dd>182 </div> 183 <?php endif; ?> 184 <?php if ($prop->show('smokers_allowed') && $prop->smokers_allowed()) : ?>183 <dd><?php echo esc_html($prop->pets_label()); ?></dd> 184 </div> 185 <?php endif; ?> 186 <?php if ($prop->show('smokers_allowed')) : ?> 185 187 <div data-detail="smokers-allowed"> 186 188 <dt>Smokers Allowed</dt> 187 <dd><?php echo esc_html($prop->smokers_ allowed()); ?></dd>189 <dd><?php echo esc_html($prop->smokers_label()); ?></dd> 188 190 </div> 189 191 <?php endif; ?> … … 243 245 244 246 <!-- Map --> 245 <?php if ($prop->show('geographic_location') && $prop-> has_map_coords()) : ?>247 <?php if ($prop->show('geographic_location') && $prop->show_map()) : ?> 246 248 <section data-role="property-map" aria-labelledby="dev-map-heading"> 247 249 <h2 id="dev-map-heading">Location</h2> -
integrate-palace-properties/trunk/public/templates/grid-gallery/single.php
r3486430 r3694341 14 14 ?> 15 15 16 <?php echo $prop->schema_json_ld();?>16 <?php // Schema.org JSON-LD is printed once, by the wrapper (public/templates/single.php), where the ipp_property_schema filter applies. ?> 17 17 18 18 <div class="ipp-single ipp-single--grid-gallery"> … … 109 109 'land_area' => ['Land Area', $prop->land_area_sqm() ? $prop->land_area_sqm() . ' sqm' : ''], 110 110 'parking' => ['Parking', $prop->parking()], 111 'pets_allowed' => ['Pets Allowed', $prop->pets_ allowed()],112 'smokers_allowed'=> ['Smokers Allowed', $prop->smokers_ allowed()],111 'pets_allowed' => ['Pets Allowed', $prop->pets_label()], 112 'smokers_allowed'=> ['Smokers Allowed', $prop->smokers_label()], 113 113 ]; 114 114 ?> … … 160 160 161 161 <!-- Map --> 162 <?php if ($prop->show('geographic_location') && $prop-> has_map_coords()) : ?>162 <?php if ($prop->show('geographic_location') && $prop->show_map()) : ?> 163 163 <section class="ipp-single__section" aria-labelledby="ipp-gg-map" style="margin-bottom:2rem;"> 164 164 <h2 id="ipp-gg-map" class="ipp-single__section-title">Location</h2> -
integrate-palace-properties/trunk/public/templates/minimal/single.php
r3486430 r3694341 15 15 ?> 16 16 17 <?php echo $prop->schema_json_ld();?>17 <?php // Schema.org JSON-LD is printed once, by the wrapper (public/templates/single.php), where the ipp_property_schema filter applies. ?> 18 18 19 19 <div class="ipp-single ipp-single--minimal" style="max-width:800px;margin:0 auto;padding:2rem 1rem;"> … … 117 117 'floor_area' => ['Floor Area', $prop->floor_area()], 118 118 'land_area' => ['Land Area', $prop->land_area_sqm() ? $prop->land_area_sqm() . ' sqm' : ''], 119 'pets_allowed' => ['Pets', $prop->pets_ allowed()],120 'smokers_allowed'=> ['Smokers', $prop->smokers_ allowed()],119 'pets_allowed' => ['Pets', $prop->pets_label()], 120 'smokers_allowed'=> ['Smokers', $prop->smokers_label()], 121 121 ]; 122 122 ?> … … 171 171 172 172 <!-- Map --> 173 <?php if ($prop->show('geographic_location') && $prop-> has_map_coords()) : ?>173 <?php if ($prop->show('geographic_location') && $prop->show_map()) : ?> 174 174 <section class="ipp-single__section" aria-labelledby="ipp-minimal-map" style="margin-bottom:2.5rem;"> 175 175 <h2 id="ipp-minimal-map" class="ipp-single__section-title" style="font-family:var(--ipp-font-heading,Georgia,serif);font-weight:400;font-size:1.5rem;margin-bottom:1.25rem;"> -
integrate-palace-properties/trunk/public/templates/modern/single.php
r3486430 r3694341 14 14 ?> 15 15 16 <?php echo $prop->schema_json_ld();?>16 <?php // Schema.org JSON-LD is printed once, by the wrapper (public/templates/single.php), where the ipp_property_schema filter applies. ?> 17 17 18 18 <div class="ipp-single ipp-single--modern"> … … 116 116 'land_area' => ['Land Area', $prop->land_area_sqm() ? $prop->land_area_sqm() . ' sqm' : ''], 117 117 'parking' => ['Parking', $prop->parking()], 118 'pets_allowed' => ['Pets Allowed', $prop->pets_ allowed()],119 'smokers_allowed'=> ['Smokers Allowed', $prop->smokers_ allowed()],118 'pets_allowed' => ['Pets Allowed', $prop->pets_label()], 119 'smokers_allowed'=> ['Smokers Allowed', $prop->smokers_label()], 120 120 ]; 121 121 ?> … … 168 168 169 169 <!-- Map --> 170 <?php if ($prop->show('geographic_location') && $prop-> has_map_coords()) : ?>170 <?php if ($prop->show('geographic_location') && $prop->show_map()) : ?> 171 171 <section class="ipp-single__section" aria-labelledby="ipp-modern-map" style="margin-bottom:3rem;"> 172 172 <h2 id="ipp-modern-map" class="ipp-single__section-title" style="font-size:1.5rem;">Location</h2> -
integrate-palace-properties/trunk/public/templates/palace-property/single.php
r3486430 r3694341 935 935 if ($prop->show('furnishings') && $prop->furnishings()) $details[] = ['Furnishings', $prop->furnishings()]; 936 936 if ($prop->show('new_construction') && $prop->new_construction()) $details[] = ['New Construction', $prop->new_construction()]; 937 if ($prop->show('pets_allowed')) $details[] = ['Pets Allowed', $prop->pets_ allowed() ? 'Yes' : 'No', $prop->pets_allowed()];938 if ($prop->show('smokers_allowed')) $details[] = ['Smokers Allowed', $prop->smokers_ allowed() ? 'Yes' : 'No', $prop->smokers_allowed()];937 if ($prop->show('pets_allowed')) $details[] = ['Pets Allowed', $prop->pets_label(), $prop->pets_allowed()]; 938 if ($prop->show('smokers_allowed')) $details[] = ['Smokers Allowed', $prop->smokers_label(), $prop->smokers_allowed()]; 939 939 if ($prop->show('unit') && $prop->unit()) $details[] = ['Unit', $prop->unit()]; 940 940 ?> … … 1037 1037 1038 1038 <!-- Map --> 1039 <?php if ($prop->show('geographic_location') && $prop-> has_map_coords()) : ?>1039 <?php if ($prop->show('geographic_location') && $prop->show_map()) : ?> 1040 1040 <div class="ipp-section ipp-single__section"> 1041 1041 <h2 class="ipp-section__title ipp-single__section-title">Location</h2> … … 1125 1125 <h4 class="ipp-share__title">Share This Property</h4> 1126 1126 <div class="ipp-share__links"> 1127 <a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo $share_url; ?>" target="_blank" rel="noopener noreferrer" class="ipp-share__link ipp-share__link--facebook" title="Share on Facebook">1127 <a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo esc_attr($share_url); ?>" target="_blank" rel="noopener noreferrer" class="ipp-share__link ipp-share__link--facebook" title="Share on Facebook"> 1128 1128 <svg viewBox="0 0 24 24" fill="currentColor"><path d="M18 2h-3a5 5 0 0 0-5 5v3H7v4h3v8h4v-8h3l1-4h-4V7a1 1 0 0 1 1-1h3z"/></svg> 1129 1129 </a> 1130 <a href="https://twitter.com/intent/tweet?url=<?php echo $share_url; ?>&text=<?php echo $share_title; ?>" target="_blank" rel="noopener noreferrer" class="ipp-share__link ipp-share__link--twitter" title="Share on X">1130 <a href="https://twitter.com/intent/tweet?url=<?php echo esc_attr($share_url); ?>&text=<?php echo esc_attr($share_title); ?>" target="_blank" rel="noopener noreferrer" class="ipp-share__link ipp-share__link--twitter" title="Share on X"> 1131 1131 <svg viewBox="0 0 24 24" fill="currentColor"><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/></svg> 1132 1132 </a> 1133 <a href="mailto:?subject=<?php echo $share_title; ?>&body=Check%20out%20this%20property:%20<?php echo $share_url; ?>" class="ipp-share__link ipp-share__link--email" title="Share via Email">1133 <a href="mailto:?subject=<?php echo esc_attr($share_title); ?>&body=Check%20out%20this%20property:%20<?php echo esc_attr($share_url); ?>" class="ipp-share__link ipp-share__link--email" title="Share via Email"> 1134 1134 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect width="20" height="16" x="2" y="4" rx="2"/><path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"/></svg> 1135 1135 </a> … … 1142 1142 1143 1143 <!-- ==================== SCHEMA.ORG ==================== --> 1144 <?php echo $prop->schema_json_ld();?>1144 <?php // Schema.org JSON-LD is printed once, by the wrapper (public/templates/single.php), where the ipp_property_schema filter applies. ?> 1145 1145 1146 1146 </div> -
integrate-palace-properties/trunk/public/templates/search-default.php
r3486430 r3694341 60 60 <option value=""><?php esc_html_e( 'All Regions', 'integrate-palace-properties' ); ?></option> 61 61 <?php foreach ( $regions as $region ) : ?> 62 <option value="<?php echo esc_attr( $region->slug ); ?>" <?php selected( isset( $_GET['region'] ) ? sanitize_text_field( $_GET['region']) : '', $region->slug ); ?>>62 <option value="<?php echo esc_attr( $region->slug ); ?>" <?php selected( isset( $_GET['region'] ) ? sanitize_text_field( wp_unslash( $_GET['region'] ) ) : '', $region->slug ); ?>> 63 63 <?php echo esc_html( $region->name ); ?> (<?php echo esc_html( $region->count ); ?>) 64 64 </option> … … 74 74 <option value=""><?php esc_html_e( 'All Types', 'integrate-palace-properties' ); ?></option> 75 75 <?php foreach ( $property_types as $type ) : ?> 76 <option value="<?php echo esc_attr( $type->slug ); ?>" <?php selected( isset( $_GET['property_type'] ) ? sanitize_text_field( $_GET['property_type']) : '', $type->slug ); ?>>76 <option value="<?php echo esc_attr( $type->slug ); ?>" <?php selected( isset( $_GET['property_type'] ) ? sanitize_text_field( wp_unslash( $_GET['property_type'] ) ) : '', $type->slug ); ?>> 77 77 <?php echo esc_html( $type->name ); ?> 78 78 </option> … … 88 88 <option value=""><?php esc_html_e( 'All', 'integrate-palace-properties' ); ?></option> 89 89 <?php foreach ( $statuses as $status ) : ?> 90 <option value="<?php echo esc_attr( $status->slug ); ?>" <?php selected( isset( $_GET['property_status'] ) ? sanitize_text_field( $_GET['property_status']) : '', $status->slug ); ?>>90 <option value="<?php echo esc_attr( $status->slug ); ?>" <?php selected( isset( $_GET['property_status'] ) ? sanitize_text_field( wp_unslash( $_GET['property_status'] ) ) : '', $status->slug ); ?>> 91 91 <?php echo esc_html( $status->name ); ?> 92 92 </option> -
integrate-palace-properties/trunk/public/templates/single.php
r3486430 r3694341 6 6 if ( ! defined( 'ABSPATH' ) ) exit; 7 7 8 get_header();8 IntegratePalace_Properties_Public::render_header(); 9 9 10 10 $template_slug = sanitize_text_field( get_option( 'ipp_select_template', 'palace-property' ) ); … … 40 40 // Schema.org structured data — filterable 41 41 $schema = $prop->schema_json_ld(); 42 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Deliberate HTML: a <script type="application/ld+json"> block built by IPP_Property_Helper::schema_json_ld() via wp_json_encode(); escaping would break the structured data. 42 43 echo apply_filters( 'ipp_property_schema', $schema, $post_id ); 43 44 44 get_footer();45 IntegratePalace_Properties_Public::render_footer(); 45 46 ?> -
integrate-palace-properties/trunk/readme.txt
r3524450 r3694341 3 3 Tags: palace, property, real-estate, mri-palace, rental 4 4 Requires at least: 5.8 5 Tested up to: 6.95 Tested up to: 7.1 6 6 Requires PHP: 8.0 7 Stable tag: 2.1.67 Stable tag: 3.0.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 13 13 == Description == 14 14 15 Integrate Palace Properties connects your WordPress site to [MRI Palace](https://www.palace.co.nz/) property management software. Properties are automatically synced via a secure cloud-hosted backend, keeping your listings always up to date. 15 Integrate Palace Properties connects your WordPress site to [MRI Palace](https://www.palace.co.nz/) property management software. Your site talks to the Palace API directly using your own Palace credentials — no third-party server sits in between — and keeps your listings up to date on a schedule you choose. 16 17 **This plugin requires an MRI Palace account with API access.** It sends your Palace API username and password to `api.getpalace.com` in order to retrieve your property records, and sends nothing at all until you have entered those credentials. No visitor or site data is ever transmitted. See the External services section below for full detail. MRI Software's [terms of use](https://www.mrisoftware.com/nz/legal-notices/) and [privacy policy](https://www.mrisoftware.com/nz/privacy-policy/) apply to that service. 16 18 17 19 **Key Features:** 18 20 19 * **Automatic Sync** — Properties sync hourly with smart delta detection (only changed properties are updated) 21 * **Automatic Sync** — Your site polls Palace on WP-Cron with smart delta detection (only changed properties are updated) 22 * **No Middleman** — Properties are fetched straight from the Palace API by your own site; nothing is routed through anyone else's server 20 23 * **6 Beautiful Templates** — Palace Property (default), Classic, Modern, Minimal, Grid Gallery, and Developer 21 24 * **AJAX Filtering** — Real-time search, filter by price/bedrooms/bathrooms/region/type/status, sortable … … 32 35 33 36 1. Configure your Palace API credentials in the plugin settings 34 2. The cloud backend fetches properties from Palace API and sends them to your site via webhook 35 3. Properties appear as a custom post type with full filtering and beautiful templates 37 2. On a schedule you choose, your site asks the Palace API which properties are available, and imports the ones that are new or changed 38 3. Properties no longer offered by Palace are removed from your site automatically 39 4. Properties appear as a custom post type with full filtering and beautiful templates 36 40 37 41 == Installation == … … 39 43 1. Upload the plugin files to `/wp-content/plugins/integrate-palace-properties/` or install through the WordPress dashboard. 40 44 2. Activate the plugin through the 'Plugins' screen in WordPress. 41 3. Navigate to **WP Palace Properties → Settings** and enter your Palace API credentials. 42 4. Enter your subscription key (or leave blank for a free plan with 10 properties). 43 5. Click **Save Changes**. Properties will begin syncing automatically. 45 3. Navigate to **WP Palace Properties → Configs** and enter your Palace API username and password. 46 4. Choose how often you want the site to check Palace for changes. Hourly suits most sites. 47 5. Click **Save Changes**. The first sync starts within a minute, and runs on your chosen schedule from then on. 48 49 The plugin is free and has no property limit. You need an MRI Palace account with API access — ask Palace for your API credentials if you do not have them. 44 50 45 51 == Frequently Asked Questions == … … 47 53 = How often do properties sync? = 48 54 49 Properties sync hourly. You can also trigger a manual sync from the Dashboard page. 55 As often as you choose on the Configs page: every 15 minutes, hourly (the default), every 2 hours, twice daily, or daily. You can also trigger a sync immediately with the **Sync Now** button on the Dashboard, or re-import everything with **Full Re-import**. 56 57 Syncing runs on WP-Cron, which WordPress triggers when someone visits your site. On a very quiet site a scheduled sync can therefore run late, and the Dashboard warns you if scheduled syncing appears to have stopped. If punctual syncing matters, ask your host to run WordPress cron from a real server cron job. With WP-CLI you can also run a complete sync in one go with `wp palace-sync run`, and check on it with `wp palace-sync status`. 58 59 = What happens when a property is rented or withdrawn? = 60 61 Palace stops listing it as available, and the plugin moves it to the trash. To guard against a brief glitch in Palace's data removing listings, a property has to be missing from two syncs, at least half a sync interval apart, before it is removed. With the default hourly sync, a rented property typically leaves your site within one to two hours. 62 63 The listing goes to the trash with its images intact, so it can be restored if needed. If Palace lists the property again later, the original entry is restored and updated rather than duplicated. Trashed properties, and their images, are deleted permanently when WordPress empties the trash (after 30 days by default). 64 65 To keep a property on your site regardless, open it in the editor and enable **Lock updates**. A locked property is neither updated nor removed by syncs. If you move a property to the trash yourself, syncs leave it there. 66 67 = Does the plugin send my data anywhere? = 68 69 Your site sends your Palace credentials to the Palace API, and nothing else, to anyone. No data about your site, visitors, or users is sent by the plugin. Visitors' browsers do load Google Maps on property pages and, if you choose one, a Google Font. See the External services section below. 50 70 51 71 = Can I control which properties appear? = 52 72 53 Yes. Use the Display Configuration settings to choose which statuses (Active/Inactive) to sync, and which property details to show on the frontend. 73 The plugin follows the publishing settings you make in Palace. A property whose "publish entry" setting is off is kept on your site as a draft, out of public view, and goes live automatically when you publish it in Palace. A property whose "publish address" setting is off is shown without its street address: its page, map, search results and structured data show the suburb only, and its map is centred on the suburb rather than the exact location. 74 75 The plugin syncs what Palace lists as available, so the place to control which properties appear is Palace itself. On the WordPress side you can hide an individual property from the front end, or lock it so syncs never overwrite your edits, using the options in the property editor. Use the Display Configuration settings to choose which property details are shown. 54 76 55 77 = Can I customize the templates? = … … 60 82 61 83 Yes. The plugin works with both classic and block themes (like Twenty Twenty-Five). 84 85 == External services == 86 87 This plugin connects to the MRI Palace API to fetch the property listings it displays. This is the service your property data already lives in, and the connection is made directly from your own site. 88 89 **What the service is used for:** retrieving your property records and their images so they can be shown on your website. 90 91 **What data is sent, and when:** 92 93 * Your Palace API username and password are sent as an HTTP Basic authorization header with every request, so that Palace can identify your account. They are stored in your site's database and are never transmitted anywhere else. 94 * No data about your site, your visitors, or your WordPress users is ever sent. 95 * Requests are made on the schedule you choose on the Configs page, when you press **Sync Now** or **Test Connection**, and when property images are fetched. 96 97 **Endpoints contacted** (all on `https://api.getpalace.com`): 98 99 * `/Service.svc/RestService/v2AvailableProperties/JSON` — the list of available properties 100 * `/Service.svc/RestService/v2AvailablePropertyImages/JSON/{code}` — images for one property 101 * `/Service.svc/RestService/v2GetCompanyDetailsByAPICredentials/JSON` — used by the Test Connection button 102 103 Nothing is sent until you have entered your Palace credentials; with no credentials configured the plugin makes no external requests at all. 104 105 This service is provided by MRI Software. Terms of use: [https://www.mrisoftware.com/nz/legal-notices/](https://www.mrisoftware.com/nz/legal-notices/) — Privacy policy: [https://www.mrisoftware.com/nz/privacy-policy/](https://www.mrisoftware.com/nz/privacy-policy/) 106 107 **Services loaded by your visitors' browsers** 108 109 These are not contacted by your server, and receive no Palace or site data from the plugin. Like any embedded third-party resource, they receive the visitor's IP address and browser details. 110 111 * **Google Maps** — property pages embed a map of the property's location from `maps.google.com`. The property's address or coordinates are sent in the map URL. Google's [terms of service](https://policies.google.com/terms) and [privacy policy](https://policies.google.com/privacy) apply. 112 * **Google Fonts** — if you choose a Google Font in the plugin's Appearance or template settings, it is loaded from `fonts.googleapis.com` on property pages. Nothing is loaded from Google Fonts unless you select one. Google's [terms of service](https://policies.google.com/terms) and [privacy policy](https://policies.google.com/privacy) apply. 113 114 The single property template also contains Facebook and X (Twitter) share links. These are ordinary links: nothing is sent to either service unless a visitor clicks one. 115 116 No other external service is contacted. 62 117 63 118 == Screenshots == … … 70 125 71 126 == Changelog == 127 128 = 3.0.0 = 129 * **Properties are now fetched directly from the Palace API by your own site.** The external relay service that previously polled Palace and pushed properties to your site over a webhook has been removed entirely. 130 * No subscription key and no account with a third-party service is needed any more, and there is no longer a property limit — the plugin is fully free 131 * New **Sync Frequency** setting: every 15 minutes, hourly, every 2 hours, twice daily or daily 132 * Imports and removals run in time-limited slices across cron ticks, so a large library imports in a few ticks rather than one batch per visit, without long-running requests 133 * **Full Re-import** button to refresh every property from Palace regardless of what has already been synced 134 * WP-CLI commands: `wp palace-sync run [--force]` completes a whole sync in one process, `wp palace-sync status` reports the last result and when the next check is due 135 * The Dashboard warns when scheduled syncing appears to have stopped (for example `DISABLE_WP_CRON` without a server cron job), and when a sync started but never finished, which usually means the host stopped the request 136 * Syncs take a lock, so two overlapping cron requests can never import, or confirm a removal, at the same time 137 * Locked properties are no longer removed when Palace stops listing them, and a property you trash yourself stays in the trash 138 * A property whose import is interrupted part-way is retried on the next sync, rather than being treated as up to date 139 * Properties that fail to save are reported on the Dashboard with the reason, and retried automatically 140 * Gallery sync: a Palace error response can no longer wipe a property's existing photos, large photos are no longer re-downloaded on every sync, and memory use for big galleries is much lower 141 * Fixed a fatal error in uninstall.php on PHP 8 that stopped settings and scheduled events being cleaned up, and uninstalling with data removal now also deletes properties in the trash and their images 142 * Google Fonts chosen in the Customizer now load through the standard WordPress stylesheet queue 143 * A property that Palace re-lists after it was removed is now restored and published, even when nothing about it changed while it was off the market (previously it could come back as a hidden draft) 144 * Property pages on block themes (such as Twenty Twenty-Five) now use the theme's real header and footer, with proper header and footer landmarks, instead of WordPress's bare fallback header 145 * Schema.org structured data is now printed once per property page instead of twice, and the `ipp_property_schema` filter applies to all of it 146 * Two safety guards against a bad response from Palace emptying your site: a property must be missing from two consecutive syncs before it is removed, and a sync that would remove an implausible share of your library is held back and reported instead 147 * Removed properties are moved to the trash and keep their images, so a listing removed in error can be restored intact. Images are only deleted when the property is deleted permanently 148 * A property that is re-listed by Palace after being removed now reuses its original entry instead of creating a duplicate 149 * The Dashboard and Configs pages now report real sync results — when the last run happened, how many properties were updated and removed, when the next check is due, and the reason for any failure 150 * Scheduled events are now cleared properly when the plugin is deactivated 151 * Your Palace password is no longer rendered back into the settings page; leave the field blank to keep the saved one 152 * macOS `.DS_Store` files are no longer included in the plugin package 153 * **Follows Palace's publishing settings.** A listing Palace marks as not to be published online is kept as a draft, out of public view, and published automatically once the agency publishes it in Palace. A listing whose address Palace marks as not to be published no longer shows its street address, unit or exact location anywhere: pages, maps (centred on the suburb instead), search, the REST API and structured data. Previous versions published both regardless. 154 * The REST API's single-property and gallery endpoints, and the `[palace_property]`, `[palace_property_field]` and `[palace_agent]` shortcodes, no longer serve an unpublished listing to visitors who ask for it by ID 155 * Pets and smoking policies now show Palace's own wording, such as "By consent", instead of treating anything other than "Yes" as not allowed. Several templates also showed "1" instead of "Yes"; that is fixed. 156 * After updating, every property is re-imported once in the background so the settings above apply to existing listings. Photos already on the site are kept, not downloaded again. 157 * Image downloads after a large import no longer risk being cut off by the host: once a cron request has been busy for a while, remaining image jobs wait for the next run instead of being lost 158 * Removed the "Property Statuses to Sync" and "Include Archived Properties" settings. They were never connected to anything — the plugin syncs what the Palace available-properties feed contains — so they promised control they did not provide. To filter what is imported, use the `ipp_sync_fetched_properties` filter documented in DEVELOPERS.md. 159 * Fixed the Dashboard's "Visible on Frontend" figure, which assumed a status filter that was never applied 160 * **Security:** hardened the Schema.org JSON-LD output. A property whose name or address contained the text `</script>` could previously break out of the structured-data block, which made the Palace feed a potential source of injected markup 161 * **Security:** front-end search and filter parameters are now unslashed as well as sanitized 162 * **Security:** the inbound webhook endpoint has been removed. It was authenticated with a shared secret issued by the relay service, so with that service gone the endpoint could no longer verify anything. Nothing pushes to your site any more — your site does the asking. 163 164 **Upgrading:** enter your Palace API username and password on the Configs page if they are not already saved, then press Save Changes. Your existing properties, images and settings are preserved. 72 165 73 166 = 2.1.6 = … … 127 220 == Upgrade Notice == 128 221 222 = 3.0.0 = 223 Syncs directly from Palace, with no relay or property limit. Now follows Palace's publish settings: unpublished listings become drafts and hidden addresses are no longer shown. Check your Palace credentials on the Configs page after updating. 224 129 225 = 2.1.0 = 130 226 Gallery sync reliability improvements, progress tracking dashboard, and critical bug fixes. Recommended update for all users. -
integrate-palace-properties/trunk/uninstall.php
r3486430 r3694341 20 20 21 21 // 1. Delete all palace-properties posts and their meta 22 // List every status explicitly: 'any' excludes the trash, and syncs move 23 // properties Palace no longer lists into the trash. Those, and their images, 24 // would otherwise survive an uninstall that was asked to remove all data. 22 25 $posts = get_posts( array( 23 26 'post_type' => 'palace-properties', 24 27 'posts_per_page' => -1, 25 'post_status' => 'any',28 'post_status' => array( 'publish', 'draft', 'pending', 'private', 'future', 'trash', 'auto-draft' ), 26 29 'fields' => 'ids', 27 30 ) ); … … 79 82 'ipp_remove_data_on_uninstall', 80 83 'ipp_settings', 81 IPPR_SETTINGS ?? 'ippr-template-settings', 84 'ipp_sync_interval', 85 'ipp_sync_state', 86 'ipp_sync_last_run', 87 'ipp_sync_blocked_deletions', 88 'ipp_sync_missing', 89 'ipp_sync_lock', 90 'ipp_sync_force_pending', 91 'ipp_sync_last_attempt', 92 'ipp_registered_site_url', 93 // The main plugin file (where IPPR_SETTINGS is defined) is not loaded during 94 // uninstall, and on PHP 8 an undefined constant is a fatal error even with ??. 95 'ippr-template-settings', 82 96 ); 83 97 … … 95 109 96 110 // 5. Clear scheduled events 97 wp_clear_scheduled_hook( 'update_integrate_palace_gallery' ); 111 wp_unschedule_hook( 'update_integrate_palace_gallery' ); // Events carry args, so clear by hook. 112 wp_clear_scheduled_hook( 'ipp_sync_properties' ); 113 wp_clear_scheduled_hook( 'ipp_sync_process_batch' ); 98 114 wp_clear_scheduled_hook( 'integrate_palace_update_gallery' ); // legacy misnamed hook 99 115 wp_clear_scheduled_hook( 'ipp_process_gallery_image' ); // legacy Phase 2 hook … … 101 117 // 6. Clean up transients 102 118 delete_transient( 'ipp_gallery_api_last_call' ); 119 delete_transient( 'ipp_api_last_call' ); 120 delete_transient( 'ipp_schedule_checked' ); 121 122 // Queued sync batches are stored as transients keyed by run ID, so they have to 123 // be matched by prefix rather than deleted by name. 124 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- One-off cleanup on uninstall; no caching layer applies. 125 $wpdb->query( 126 "DELETE FROM {$wpdb->options} 127 WHERE option_name LIKE '\_transient\_ipp\_sync\_batch\_%' 128 OR option_name LIKE '\_transient\_timeout\_ipp\_sync\_batch\_%'" 129 ); 103 130 104 131 // 6. Flush rewrite rules
Note:
See TracChangeset
for help on using the changeset viewer.