| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 3 |
|
| 4 |
if ( ! class_exists( 'ewdotpBackwardsCompatibility' ) ) { |
| 5 |
/** |
| 6 |
* Class to handle transforming the plugin settings from the |
| 7 |
* previous style (individual options) to the new one (options array) |
| 8 |
* |
| 9 |
* @since 3.0.0 |
| 10 |
*/ |
| 11 |
class ewdotpBackwardsCompatibility { |
| 12 |
|
| 13 |
public function __construct() { |
| 14 |
|
| 15 |
if ( empty( get_option( 'ewd-otp-settings' ) ) and get_option( 'EWD_OTP_Full_Version' ) ) { $this->run_backwards_compat(); } |
| 16 |
elseif ( ! get_option( 'ewd-otp-permission-level' ) ) { update_option( 'ewd-otp-permission-level', 1 ); } |
| 17 |
} |
| 18 |
|
| 19 |
public function run_backwards_compat() { |
| 20 |
|
| 21 |
$this->convert_custom_fields(); |
| 22 |
|
| 23 |
$settings = array( |
| 24 |
'custom-css' => get_option( 'EWD_OTP_Custom_CSS' ), |
| 25 |
'disable-ajax-loading' => get_option( 'EWD_OTP_AJAX_Reload' ) == 'Yes' ? false : true, |
| 26 |
'new-window' => get_option( 'EWD_OTP_New_Window' ) == 'Yes' ? true : false, |
| 27 |
'order-information' => is_array( get_option( 'EWD_OTP_Order_Information' ) ) ? array_map( 'strtolower', get_option( 'EWD_OTP_Order_Information' ) ) : array(), |
| 28 |
'hide-blank-fields' => get_option( 'EWD_OTP_Hide_Blank_Fields' ) == 'Yes' ? true : false, |
| 29 |
'form-instructions' => get_option( 'EWD_OTP_Form_Instructions' ), |
| 30 |
'date-format' => get_option( 'EWD_OTP_Localize_Date_Time' ) == 'North_American' ? 'y-m-d H:i:s' : 'd-m-y H:i:s', |
| 31 |
'email-verification' => get_option( 'EWD_OTP_Email_Confirmation' ) == 'Order_Email' ? true : false, |
| 32 |
'display-print-button' => get_option( 'EWD_OTP_Display_Print_Button' ) == 'Yes' ? true : false, |
| 33 |
'email-frequency' => strtolower( get_option( 'EWD_OTP_Order_Email' ) ), |
| 34 |
'tracking-page-url' => get_option( 'EWD_OTP_Tracking_Page' ), |
| 35 |
|
| 36 |
'statuses' => $this->convert_statuses(), |
| 37 |
|
| 38 |
'email-messages' => $this->convert_emails(), |
| 39 |
'admin-email' => get_option( 'EWD_OTP_Admin_Email' ), |
| 40 |
|
| 41 |
'access-role' => get_option( 'EWD_OTP_Access_Role' ), |
| 42 |
'tracking-graphic' => strtolower( get_option( 'EWD_OTP_Display_Graphic' ) ), |
| 43 |
'customer-notes-email' => $this->get_corresponding_email( get_option( 'EWD_OTP_Customer_Notes_Email' ) ), |
| 44 |
'customer-order-email' => $this->get_corresponding_email( get_option( 'EWD_OTP_Customer_Order_Email' ) ), |
| 45 |
'allow-customer-downloads' => get_option( 'EWD_OTP_Allow_Customer_Downloads' ) == 'Yes' ? true : false, |
| 46 |
'allow-sales-rep-downloads' => get_option( 'EWD_OTP_Allow_Sales_Rep_Downloads' ) == 'Yes' ? true : false, |
| 47 |
'allow-sales-rep-selection' => get_option( 'EWD_OTP_Allow_Sales_Rep_Selection' ) == 'Yes' ? true : false, |
| 48 |
'allow-assign-orders-to-customers' => get_option( 'EWD_OTP_Auto_Assign_Orders_To_Customers' ) == 'Yes' ? true : false, |
| 49 |
'customer-order-number-prefix' => get_option( 'EWD_OTP_Customer_Order_Number_Prefix' ), |
| 50 |
'customer-order-number-suffix' => get_option( 'EWD_OTP_Customer_Order_Number_Suffix' ), |
| 51 |
'default-sales-rep' => intval( get_option( 'EWD_OTP_Default_Sales_Rep' ) ), |
| 52 |
|
| 53 |
'locations' => $this->convert_locations(), |
| 54 |
|
| 55 |
'allow-order-payments' => get_option( 'EWD_OTP_Allow_Order_Payments' ) == 'Yes' ? true : false, |
| 56 |
'default-payment-status' => get_option( 'EWD_OTP_Default_Payment_Status' ), |
| 57 |
'paypal-email-address' => get_option( 'EWD_OTP_PayPal_Email_Address' ), |
| 58 |
'pricing-currency-code' => get_option( 'EWD_OTP_Pricing_Currency_Code' ), |
| 59 |
'thank-you-url' => get_option( 'EWD_OTP_Thank_You_URL' ), |
| 60 |
|
| 61 |
'woocommerce-integration' => get_option( 'EWD_OTP_WooCommerce_Integration' ) == 'Yes' ? true : false, |
| 62 |
'woocommerce-prefix' => get_option( 'EWD_OTP_WooCommerce_Prefix' ), |
| 63 |
'woocommerce-disable-random-suffix' => get_option( 'EWD_OTP_WooCommerce_Random_Suffix' ) == 'Yes' ? false : true, |
| 64 |
'woocommerce-show-on-order-page' => get_option( 'EWD_OTP_WooCommerce_Show_On_Order_Page' ) == 'Yes' ? true : false, |
| 65 |
'woocommerce-locations-enabled' => get_option( 'EWD_OTP_Enabled_Locations_For_WooCommerce' ) == 'Yes' ? true : false, |
| 66 |
'woocommerce-replace-statuses' => get_option( 'EWD_OTP_Replace_WooCommerce_Statuses' ) == 'Yes' ? true : false, |
| 67 |
'woocommerce-revert-statuses' => get_option( 'EWD_OTP_WooCommerce_Revert_Statuses' ) == 'Yes' ? true : false, |
| 68 |
'woocommerce-paid-status' => get_option( 'EWD_OTP_WooCommerce_Paid_Order_Status' ), |
| 69 |
'woocommerce-unpaid-status' => get_option( 'EWD_OTP_WooCommerce_Unpaid_Order_Status' ), |
| 70 |
'woocommerce-processing-status' => get_option( 'EWD_OTP_WooCommerce_Processing_Order_Status' ), |
| 71 |
'woocommerce-cancelled-status' => get_option( 'EWD_OTP_WooCommerce_Cancelled_Order_Status' ), |
| 72 |
'woocommerce-onhold-status' => get_option( 'EWD_OTP_WooCommerce_OnHold_Order_Status' ), |
| 73 |
'woocommerce-failed-status' => get_option( 'EWD_OTP_WooCommerce_Failed_Order_Status' ), |
| 74 |
'woocommerce-refunded-status' => get_option( 'EWD_OTP_WooCommerce_Refunded_Order_Status' ), |
| 75 |
|
| 76 |
'zendesk-integration' => get_option( 'EWD_OTP_Zendesk_Integration' ) == 'Yes' ? true : false, |
| 77 |
'zendesk-api-key' => get_option( 'EWD_OTP_Zendesk_API_Key' ), |
| 78 |
|
| 79 |
'label-order-form-title' => get_option( 'EWD_OTP_Tracking_Title_Label' ), |
| 80 |
'label-order-form-number' => get_option( 'EWD_OTP_Tracking_Ordernumber_Label' ), |
| 81 |
'label-order-form-number-placeholder' => get_option( 'EWD_OTP_Tracking_Ordernumber_Placeholder_Label' ), |
| 82 |
'label-order-form-email' => get_option( 'EWD_OTP_Tracking_Email_Label' ), |
| 83 |
'label-order-form-email-placeholder' => get_option( 'EWD_OTP_Tracking_Email_Placeholder_Label' ), |
| 84 |
'label-order-form-button' => get_option( 'EWD_OTP_Tracking_Button_Label' ), |
| 85 |
'label-retrieving-results' => get_option( 'EWD_OTP_Retrieving_Results_Label' ), |
| 86 |
'label-customer-form-title' => get_option( 'EWD_OTP_Customer_Form_Title_Label' ), |
| 87 |
'label-customer-form-instructions' => get_option( 'EWD_OTP_Customer_Form_Description_Label' ), |
| 88 |
'label-customer-form-number' => get_option( 'EWD_OTP_Customer_Form_Number_Label' ), |
| 89 |
'label-customer-form-number-placeholder' => get_option( 'EWD_OTP_Customer_Form_Number_Placeholder_Label' ), |
| 90 |
'label-customer-form-email' => get_option( 'EWD_OTP_Customer_Form_Email_Label' ), |
| 91 |
'label-customer-form-email-placeholder' => get_option( 'EWD_OTP_Customer_Form_Email_Placeholder_Label' ), |
| 92 |
'label-customer-form-button' => get_option( 'EWD_OTP_Customer_Form_Button_Label' ), |
| 93 |
'label-sales-rep-form-title' => get_option( 'EWD_OTP_Sales_Rep_Form_Title_Label' ), |
| 94 |
'label-sales-rep-form-instructions' => get_option( 'EWD_OTP_Sales_Rep_Form_Description_Label' ), |
| 95 |
'label-sales-rep-form-number' => get_option( 'EWD_OTP_Sales_Rep_Form_Number_Label' ), |
| 96 |
'label-sales-rep-form-number-placeholder' => get_option( 'EWD_OTP_Sales_Rep_Form_Number_Placeholder_Label' ), |
| 97 |
'label-sales-rep-form-email' => get_option( 'EWD_OTP_Sales_Rep_Form_Email_Label' ), |
| 98 |
'label-sales-rep-form-email-placeholder' => get_option( 'EWD_OTP_Sales_Rep_Form_Email_Placeholder_Label' ), |
| 99 |
'label-sales-rep-form-button' => get_option( 'EWD_OTP_Sales_Rep_Form_Button_Label' ), |
| 100 |
'label-order-information' => get_option( 'EWD_OTP_Order_Information_Label' ), |
| 101 |
'label-order-number' => get_option( 'EWD_OTP_Order_Number_Label' ), |
| 102 |
'label-order-name' => get_option( 'EWD_OTP_Order_Name_Label' ), |
| 103 |
'label-order-notes' => get_option( 'EWD_OTP_Order_Notes_Label' ), |
| 104 |
'label-customer-notes' => get_option( 'EWD_OTP_Customer_Notes_Label' ), |
| 105 |
'label-order-status' => get_option( 'EWD_OTP_Order_Status_Label' ), |
| 106 |
'label-order-location' => get_option( 'EWD_OTP_Order_Location_Label' ), |
| 107 |
'label-order-updated' => get_option( 'EWD_OTP_Order_Updated_Label' ), |
| 108 |
'label-order-current-location' => get_option( 'EWD_OTP_Order_Current_Location_Label' ), |
| 109 |
'label-order-print-button' => get_option( 'EWD_OTP_Order_Print_Button_Label' ), |
| 110 |
'label-order-add-note-button' => get_option( 'EWD_OTP_Order_Add_Note_Button_Label' ), |
| 111 |
'label-order-update-status' => get_option( 'EWD_OTP_Order_Update_Status_Button_Label' ), |
| 112 |
'label-customer-display-name' => get_option( 'EWD_OTP_Customer_Display_Name_Label' ), |
| 113 |
'label-customer-display-email' => get_option( 'EWD_OTP_Customer_Display_Email_Label' ), |
| 114 |
'label-customer-display-download' => get_option( 'EWD_OTP_Customer_Display_Download_Label' ), |
| 115 |
'label-sales-rep-display-first-name' => get_option( 'EWD_OTP_Sales_Rep_Display_First_Name_Label' ), |
| 116 |
'label-sales-rep-display-last-name' => get_option( 'EWD_OTP_Sales_Rep_Display_Last_Name_Label' ), |
| 117 |
'label-customer-order-name' => get_option( 'EWD_OTP_Customer_Order_Name_Label' ), |
| 118 |
'label-customer-order-email' => get_option( 'EWD_OTP_Customer_Order_Email_Label' ), |
| 119 |
'label-customer-order-notes' => get_option( 'EWD_OTP_Customer_Order_Notes_Label' ), |
| 120 |
'label-customer-order-button' => get_option( 'EWD_OTP_Customer_Order_Button_Label' ), |
| 121 |
'label-customer-order-thank-you' => get_option( 'EWD_OTP_Customer_Order_Thank_You_Label' ), |
| 122 |
'label-customer-order-email-instructions' => get_option( 'EWD_OTP_Customer_Order_Email_Instructions_Label' ), |
| 123 |
|
| 124 |
'styling-title-font' => get_option( 'EWD_OTP_Styling_Title_Font' ), |
| 125 |
'styling-title-font-size' => get_option( 'EWD_OTP_Styling_Title_Font_Size' ), |
| 126 |
'styling-title-font-color' => get_option( 'EWD_OTP_Styling_Title_Font_Color' ), |
| 127 |
'styling-title-margin' => get_option( 'EWD_OTP_Styling_Title_Margin' ), |
| 128 |
'styling-title-padding' => get_option( 'EWD_OTP_Styling_Title_Padding' ), |
| 129 |
'styling-label-font' => get_option( 'EWD_OTP_Styling_Label_Font' ), |
| 130 |
'styling-label-font-size' => get_option( 'EWD_OTP_Styling_Label_Font_Size' ), |
| 131 |
'styling-label-font-color' => get_option( 'EWD_OTP_Styling_Label_Font_Color' ), |
| 132 |
'styling-label-margin' => get_option( 'EWD_OTP_Styling_Body_Margin' ), |
| 133 |
'styling-label-padding' => get_option( 'EWD_OTP_Styling_Body_Padding' ), |
| 134 |
'styling-content-font' => get_option( 'EWD_OTP_Styling_Content_Font' ), |
| 135 |
'styling-content-font-size' => get_option( 'EWD_OTP_Styling_Content_Font_Size' ), |
| 136 |
'styling-content-font-color' => get_option( 'EWD_OTP_Styling_Content_Font_Color' ), |
| 137 |
'styling-content-margin' => get_option( 'EWD_OTP_Styling_Body_Margin' ), |
| 138 |
'styling-content-padding' => get_option( 'EWD_OTP_Styling_Body_Padding' ), |
| 139 |
'styling-button-font-color' => get_option( 'EWD_OTP_Styling_Button_Font_Color' ), |
| 140 |
'styling-button-background-color' => get_option( 'EWD_OTP_Styling_Button_Bg_Color' ), |
| 141 |
'styling-button-border' => get_option( 'EWD_OTP_Styling_Button_Border' ), |
| 142 |
'styling-button-margin' => get_option( 'EWD_OTP_Styling_Button_Margin' ), |
| 143 |
'styling-button-padding' => get_option( 'EWD_OTP_Styling_Button_Padding' ), |
| 144 |
|
| 145 |
); |
| 146 |
|
| 147 |
add_option( 'ewd-otp-review-ask-time', get_option( 'EWD_OTP_Ask_Review_Date' ) ); |
| 148 |
add_option( 'ewd-otp-installation-time', get_option( 'EWD_OTP_Install_Time' ) ); |
| 149 |
|
| 150 |
update_option( 'ewd-otp-permission-level', get_option( 'EWD_OTP_Full_Version' ) == 'Yes' ? 2 : 1 ); |
| 151 |
|
| 152 |
update_option( 'ewd-otp-settings', $settings ); |
| 153 |
} |
| 154 |
|
| 155 |
public function convert_statuses() { |
| 156 |
|
| 157 |
$old_statuses = is_array( get_option( 'EWD_OTP_Statuses_Array' ) ) ? get_option( 'EWD_OTP_Statuses_Array' ) : array(); |
| 158 |
$new_statuses = array(); |
| 159 |
|
| 160 |
foreach ( $old_statuses as $old_status ) { |
| 161 |
|
| 162 |
$new_status = array( |
| 163 |
'status' => $old_status['Status'], |
| 164 |
'percentage' => $old_status['Percentage'], |
| 165 |
'email' => $this->get_corresponding_email( $old_status['Message'] ), |
| 166 |
'internal' => strtolower( $old_status['Internal'] ), |
| 167 |
); |
| 168 |
|
| 169 |
$new_statuses[] = $new_status; |
| 170 |
} |
| 171 |
|
| 172 |
return json_encode( $new_statuses ); |
| 173 |
} |
| 174 |
|
| 175 |
public function convert_emails() { |
| 176 |
|
| 177 |
$subject = get_option( 'EWD_OTP_Subject_Line' ); |
| 178 |
|
| 179 |
$old_emails = is_array( get_option( 'EWD_OTP_Email_Messages_Array' ) ) ? get_option( 'EWD_OTP_Email_Messages_Array' ) : array(); |
| 180 |
$new_emails = array(); |
| 181 |
|
| 182 |
foreach ( $old_emails as $count => $old_email ) { |
| 183 |
|
| 184 |
$new_email = array( |
| 185 |
'id' => ( $count + 1 ), |
| 186 |
'name' => $old_email['Name'], |
| 187 |
'subject' => $subject, |
| 188 |
'message' => $old_email['Message'] |
| 189 |
); |
| 190 |
|
| 191 |
$new_emails[] = $new_email; |
| 192 |
} |
| 193 |
|
| 194 |
return json_encode( $new_emails ); |
| 195 |
} |
| 196 |
|
| 197 |
public function get_corresponding_email( $email_name ) { |
| 198 |
|
| 199 |
$old_emails = is_array( get_option( 'EWD_OTP_Email_Messages_Array' ) ) ? get_option( 'EWD_OTP_Email_Messages_Array' ) : array(); |
| 200 |
|
| 201 |
foreach ( $old_emails as $count => $old_email ) { |
| 202 |
|
| 203 |
if ( $email_name == $old_email['Name'] ) { return ( $count + 1 ); } |
| 204 |
} |
| 205 |
|
| 206 |
return 0; |
| 207 |
} |
| 208 |
|
| 209 |
public function convert_locations() { |
| 210 |
|
| 211 |
$old_locations = is_array( get_option( 'EWD_OTP_Locations_Array' ) ) ? get_option( 'EWD_OTP_Locations_Array' ) : array(); |
| 212 |
$new_locations = array(); |
| 213 |
|
| 214 |
foreach ( $old_locations as $old_location ) { |
| 215 |
|
| 216 |
$new_location = array( |
| 217 |
'name' => $old_location['Name'], |
| 218 |
'latitude' => $old_location['Latitude'], |
| 219 |
'longitude' => $old_location['Longitude'] |
| 220 |
); |
| 221 |
|
| 222 |
$new_locations[] = $new_location; |
| 223 |
} |
| 224 |
|
| 225 |
return json_encode( $new_locations ); |
| 226 |
} |
| 227 |
|
| 228 |
public function convert_custom_fields() { |
| 229 |
global $wpdb; |
| 230 |
|
| 231 |
$custom_fields_table_name = $wpdb->prefix . 'EWD_OTP_Custom_Fields'; |
| 232 |
|
| 233 |
$old_fields = $wpdb->get_results( "SELECT * FROM $custom_fields_table_name ORDER BY Field_Order ASC" ); |
| 234 |
|
| 235 |
$new_fields = array(); |
| 236 |
|
| 237 |
$meta_table_name = $wpdb->prefix . 'EWD_OTP_Fields_Meta'; |
| 238 |
|
| 239 |
$uploads_dir = site_url( '/wp-content/uploads/order-tracking-uploads/' ); |
| 240 |
|
| 241 |
foreach ( $old_fields as $old_field ) { |
| 242 |
|
| 243 |
if ( $old_field->Field_Type == 'picture' or $old_field->Field_Type == 'file' ) { |
| 244 |
|
| 245 |
$wpdb->get_results( $wpdb->prepare( "UPDATE $meta_table_name SET Meta_Value = CONCAT( %s, Meta_Value ) WHERE Field_ID=%d", $uploads_dir, $old_field->Field_ID ) ); |
| 246 |
} |
| 247 |
|
| 248 |
$new_field = array( |
| 249 |
'id' => $old_field->Field_ID, |
| 250 |
'name' => $old_field->Field_Name, |
| 251 |
'slug' => $old_field->Field_Slug, |
| 252 |
'function' => strtolower( $old_field->Field_Function ), |
| 253 |
'type' => $old_field->Field_Type == 'mediumint' ? 'number' : ( $old_field->Field_Type == 'picture' ? 'image' : $old_field->Field_Type ), |
| 254 |
'options' => $old_field->Field_Values, |
| 255 |
'display' => $old_field->Field_Display == 'Yes' ? true : false, |
| 256 |
'front_end_display' => $old_field->Field_Front_End_Display == 'Yes' ? true : false, |
| 257 |
'required' => strtolower( $old_field->Field_Required ), |
| 258 |
'equivalent' => ( empty( $old_field->Field_Equivalent ) or $old_field->Field_Equivalent == 'None' ) ? 'none' : $old_field->Field_Equivalent, |
| 259 |
); |
| 260 |
|
| 261 |
$new_fields[] = (object) $new_field; |
| 262 |
} |
| 263 |
|
| 264 |
update_option( 'ewd-otp-custom-fields', $new_fields ); |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
} |