Changeset 3449046
- Timestamp:
- 01/28/2026 09:32:20 PM (6 weeks ago)
- Location:
- workzen-connector/trunk
- Files:
-
- 5 edited
-
includes/class-admin-pages.php (modified) (1 diff)
-
includes/class-ajax-handlers.php (modified) (1 diff)
-
includes/class-online-booking.php (modified) (3 diffs)
-
readme.txt (modified) (1 diff)
-
workzen-connector.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
workzen-connector/trunk/includes/class-admin-pages.php
r3449035 r3449046 635 635 <?php esc_html_e( 'This will delete ALL plugin settings, the request log, retry queue, transients, and scheduled events. Like a fresh install.', 'workzen-connector' ); ?> 636 636 </p> 637 638 <?php 639 // Get booking data for display 640 $online_booking = WorkZen_Connector::instance()->get_online_booking(); 641 $booking_data = $online_booking->get_booking_data(); 642 $work_hours = isset( $booking_data['work_hours'] ) ? $booking_data['work_hours'] : array(); 643 $job_types = isset( $booking_data['job_types'] ) ? $booking_data['job_types'] : array(); 644 ?> 645 646 <!-- Work Hours Table --> 647 <div style="margin-top: 20px;"> 648 <h4 style="margin: 0 0 8px 0; color: #991b1b;">📅 Work Hours (from WorkZen)</h4> 649 <?php if ( ! empty( $work_hours ) ) : ?> 650 <table style="width: 100%; border-collapse: collapse; font-size: 13px; background: white; border-radius: 4px; overflow: hidden;"> 651 <thead> 652 <tr style="background: #fee2e2;"> 653 <th style="padding: 8px 12px; text-align: left; border-bottom: 1px solid #fecaca;">Day</th> 654 <th style="padding: 8px 12px; text-align: left; border-bottom: 1px solid #fecaca;">Hours</th> 655 </tr> 656 </thead> 657 <tbody> 658 <?php 659 $days = array( 'sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday' ); 660 foreach ( $days as $day ) : 661 $hours = isset( $work_hours[ $day ] ) ? $work_hours[ $day ] : 'closed'; 662 if ( is_array( $hours ) ) { 663 $display = esc_html( $hours['start'] ) . ' - ' . esc_html( $hours['end'] ); 664 } else { 665 $display = '<span style="color: #9ca3af; font-style: italic;">Closed</span>'; 666 } 667 ?> 668 <tr> 669 <td style="padding: 6px 12px; border-bottom: 1px solid #fef2f2; text-transform: capitalize;"><?php echo esc_html( $day ); ?></td> 670 <td style="padding: 6px 12px; border-bottom: 1px solid #fef2f2;"><?php echo $display; ?></td> 671 </tr> 672 <?php endforeach; ?> 673 </tbody> 674 </table> 675 <?php else : ?> 676 <p style="color: #9ca3af; font-style: italic; margin: 0;">No work hours data available. Try syncing booking data.</p> 677 <?php endif; ?> 678 </div> 679 680 <!-- Service Types Table --> 681 <div style="margin-top: 20px;"> 682 <h4 style="margin: 0 0 8px 0; color: #991b1b;">🛠️ Service Types (from WorkZen)</h4> 683 <?php if ( ! empty( $job_types ) ) : ?> 684 <table style="width: 100%; border-collapse: collapse; font-size: 13px; background: white; border-radius: 4px; overflow: hidden;"> 685 <thead> 686 <tr style="background: #fee2e2;"> 687 <th style="padding: 8px 12px; text-align: left; border-bottom: 1px solid #fecaca;">GUID</th> 688 <th style="padding: 8px 12px; text-align: left; border-bottom: 1px solid #fecaca;">Name</th> 689 <th style="padding: 8px 12px; text-align: left; border-bottom: 1px solid #fecaca;">Description</th> 690 </tr> 691 </thead> 692 <tbody> 693 <?php foreach ( $job_types as $job_type ) : ?> 694 <tr> 695 <td style="padding: 6px 12px; border-bottom: 1px solid #fef2f2; font-family: monospace; font-size: 11px; color: #6b7280;"> 696 <?php echo esc_html( isset( $job_type['guid'] ) ? $job_type['guid'] : '-' ); ?> 697 </td> 698 <td style="padding: 6px 12px; border-bottom: 1px solid #fef2f2; font-weight: 500;"> 699 <?php echo esc_html( isset( $job_type['name'] ) ? $job_type['name'] : '-' ); ?> 700 </td> 701 <td style="padding: 6px 12px; border-bottom: 1px solid #fef2f2; color: #6b7280;"> 702 <?php echo esc_html( isset( $job_type['description'] ) && $job_type['description'] ? $job_type['description'] : '-' ); ?> 703 </td> 704 </tr> 705 <?php endforeach; ?> 706 </tbody> 707 </table> 708 <p style="margin: 8px 0 0 0; font-size: 12px; color: #9ca3af;"> 709 <?php echo esc_html( sprintf( __( '%d service type(s) synced', 'workzen-connector' ), count( $job_types ) ) ); ?> 710 </p> 711 <?php else : ?> 712 <p style="color: #9ca3af; font-style: italic; margin: 0;">No service types available. Try syncing booking data or add job types in WorkZen.</p> 713 <?php endif; ?> 714 </div> 715 716 <!-- Floating Button Settings Debug --> 717 <div style="margin-top: 20px;"> 718 <h4 style="margin: 0 0 8px 0; color: #991b1b;">🔧 Floating Button Settings (Debug)</h4> 719 <table style="width: 100%; border-collapse: collapse; font-size: 13px; background: white; border-radius: 4px; overflow: hidden;"> 720 <thead> 721 <tr style="background: #fee2e2;"> 722 <th style="padding: 8px 12px; text-align: left; border-bottom: 1px solid #fecaca;">Setting</th> 723 <th style="padding: 8px 12px; text-align: left; border-bottom: 1px solid #fecaca;">Raw Value</th> 724 <th style="padding: 8px 12px; text-align: left; border-bottom: 1px solid #fecaca;">Enabled?</th> 725 </tr> 726 </thead> 727 <tbody> 728 <?php 729 $debug_settings = array( 730 'Floating Buttons Master' => WZC_Constants::OPTION_FLOATING_ENABLED, 731 'Call Button' => WZC_Constants::OPTION_FLOATING_CALL_ENABLED, 732 'WhatsApp Button' => WZC_Constants::OPTION_FLOATING_WHATSAPP_ENABLED, 733 'Contact Form Button' => WZC_Constants::OPTION_FLOATING_CONTACT_ENABLED, 734 'Booking Button' => WZC_Constants::OPTION_BOOKING_ENABLED, 735 ); 736 foreach ( $debug_settings as $label => $option_key ) : 737 $raw_value = get_option( $option_key ); 738 $is_enabled = $raw_value === '1'; 739 ?> 740 <tr> 741 <td style="padding: 6px 12px; border-bottom: 1px solid #fef2f2;"><?php echo esc_html( $label ); ?></td> 742 <td style="padding: 6px 12px; border-bottom: 1px solid #fef2f2; font-family: monospace;"> 743 <?php echo esc_html( var_export( $raw_value, true ) ); ?> 744 </td> 745 <td style="padding: 6px 12px; border-bottom: 1px solid #fef2f2;"> 746 <?php echo $is_enabled ? '<span style="color: #16a34a;">✓ Yes</span>' : '<span style="color: #dc2626;">✗ No</span>'; ?> 747 </td> 748 </tr> 749 <?php endforeach; ?> 750 </tbody> 751 </table> 752 <p style="margin: 8px 0 0 0; font-size: 12px; color: #9ca3af;"> 753 Phone: <?php echo esc_html( get_option( WZC_Constants::OPTION_FLOATING_PHONE, '(not set)' ) ?: '(empty)' ); ?> | 754 WhatsApp: <?php echo esc_html( get_option( WZC_Constants::OPTION_FLOATING_WHATSAPP, '(not set)' ) ?: '(empty)' ); ?> 755 </p> 756 </div> 637 757 </div> 638 758 -
workzen-connector/trunk/includes/class-ajax-handlers.php
r3449035 r3449046 74 74 75 75 $online_booking = WorkZen_Connector::instance()->get_online_booking(); 76 $data = $online_booking->sync_booking_data(); 77 78 if ( $data && ! empty( $data['work_hours'] ) ) { 76 $result = $online_booking->sync_booking_data(); 77 78 if ( $result['success'] && ! empty( $result['data'] ) ) { 79 $data = $result['data']; 79 80 wp_send_json_success( array( 80 81 'message' => __( 'Successfully synced data from WorkZen.io', 'workzen-connector' ), 81 'job_types' => count( $data['job_types'] ),82 'work_hours' => $data['work_hours'] ,82 'job_types' => count( $data['job_types'] ?? array() ), 83 'work_hours' => $data['work_hours'] ?? array(), 83 84 ) ); 84 85 } else { 85 86 wp_send_json_error( array( 86 'message' => __( 'Failed to sync data. Please check your API connection.', 'workzen-connector' ),87 'message' => $result['error'] ?? __( 'Failed to sync data. Please contact support.', 'workzen-connector' ), 87 88 ) ); 88 89 } -
workzen-connector/trunk/includes/class-online-booking.php
r3447338 r3449046 82 82 83 83 $body = wp_remote_retrieve_body( $response ); 84 $data = json_decode( $body, true ); 84 $response_data = json_decode( $body, true ); 85 86 // API returns standard format: { "success": true, "data": { "work_hours": ..., "job_types": ... } } 87 // Extract the nested data object 88 $data = isset( $response_data['data'] ) ? $response_data['data'] : $response_data; 85 89 86 90 if ( ! is_array( $data ) || ! isset( $data['work_hours'] ) || ! isset( $data['job_types'] ) ) { 87 $this->log_error( 'Invalid booking config response format ');91 $this->log_error( 'Invalid booking config response format: ' . wp_json_encode( $response_data ) ); 88 92 return $this->get_fallback_booking_data( $cached_data ); 89 93 } … … 133 137 134 138 /** 135 * Clear the booking data cache and force a fresh fetch 139 * Clear the booking data cache and force a fresh fetch from API 136 140 * 137 * @return array |false The fresh booking data, or false on failure141 * @return array Array with 'success' boolean and 'data' or 'error' message 138 142 */ 139 143 public function sync_booking_data() { … … 141 145 delete_transient( 'wzc_booking_data' ); 142 146 143 // Force a fresh fetch (temporarily act as dev mode to skip cache read) 144 $data = $this->get_booking_data(); 145 146 return $data; 147 // Build config endpoint URL 148 $endpoint = get_option( WZC_Constants::OPTION_ENDPOINT ); 149 if ( empty( $endpoint ) ) { 150 return array( 151 'success' => false, 152 'error' => __( 'API endpoint not configured. Please set up your integration key first.', 'workzen-connector' ), 153 ); 154 } 155 156 $config_url = rtrim( $endpoint, '/' ) . '/config'; 157 $integration_key = get_option( WZC_Constants::OPTION_INTEGRATION_KEY ); 158 159 if ( empty( $integration_key ) ) { 160 return array( 161 'success' => false, 162 'error' => __( 'Integration key not configured. Please set up your integration key first.', 'workzen-connector' ), 163 ); 164 } 165 166 $args = array( 167 'headers' => array( 168 'X-Integration-Key' => $integration_key, 169 'X-Site-URL' => get_site_url(), 170 'Accept' => 'application/json', 171 ), 172 'timeout' => 15, 173 ); 174 175 if ( defined( 'WORKZEN_DEV' ) && WORKZEN_DEV ) { 176 $args['sslverify'] = false; 177 } 178 179 $response = wp_remote_get( $config_url, $args ); 180 181 if ( is_wp_error( $response ) ) { 182 return array( 183 'success' => false, 184 'error' => sprintf( 185 /* translators: %s: error message */ 186 __( 'Connection failed: %s. Please contact support if this persists.', 'workzen-connector' ), 187 $response->get_error_message() 188 ), 189 ); 190 } 191 192 $response_code = wp_remote_retrieve_response_code( $response ); 193 if ( $response_code !== 200 ) { 194 return array( 195 'success' => false, 196 'error' => sprintf( 197 /* translators: %d: HTTP status code */ 198 __( 'API returned error (HTTP %d). Please contact support if this persists.', 'workzen-connector' ), 199 $response_code 200 ), 201 ); 202 } 203 204 $body = wp_remote_retrieve_body( $response ); 205 $response_data = json_decode( $body, true ); 206 207 // API returns standard format: { "success": true, "data": { "work_hours": ..., "job_types": ... } } 208 $data = isset( $response_data['data'] ) ? $response_data['data'] : $response_data; 209 210 if ( ! is_array( $data ) || ! isset( $data['work_hours'] ) || ! isset( $data['job_types'] ) ) { 211 return array( 212 'success' => false, 213 'error' => __( 'Invalid response format from API. Please contact support.', 'workzen-connector' ), 214 ); 215 } 216 217 $booking_data = array( 218 'work_hours' => $data['work_hours'], 219 'job_types' => $data['job_types'], 220 ); 221 222 // Cache the fresh data 223 if ( ! ( defined( 'WORKZEN_DEV' ) && WORKZEN_DEV ) ) { 224 set_transient( 'wzc_booking_data', $booking_data, 12 * HOUR_IN_SECONDS ); 225 } 226 227 return array( 228 'success' => true, 229 'data' => $booking_data, 230 ); 147 231 } 148 232 -
workzen-connector/trunk/readme.txt
r3449035 r3449046 5 5 Tested up to: 6.8 6 6 Requires PHP: 7.4 7 Stable tag: 1.12. 27 Stable tag: 1.12.3 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html -
workzen-connector/trunk/workzen-connector.php
r3449035 r3449046 3 3 * Plugin Name: WorkZen Connector 4 4 * Description: Connects WordPress forms to WorkZen CRM. Captures leads from Contact Form 7, WPForms, Gravity Forms, and other popular form plugins, sending them securely to your WorkZen account via the WorkZen API (https://api.workzen.io). Includes floating buttons with online booking functionality. 5 * Version: 1.12. 25 * Version: 1.12.3 6 6 * Author: Ika Balzam 7 7 * Author URI: https://workzen.io … … 20 20 21 21 // Define plugin constants 22 define( 'WZC_VERSION', '1.12. 2' );22 define( 'WZC_VERSION', '1.12.3' ); 23 23 define( 'WZC_PLUGIN_FILE', __FILE__ ); 24 24 define( 'WZC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
Note: See TracChangeset
for help on using the changeset viewer.