Changeset 2943682
- Timestamp:
- 07/26/2023 01:23:42 PM (3 years ago)
- Location:
- eshipper-commerce
- Files:
-
- 24 edited
- 1 copied
-
tags/2.15.3 (copied) (copied from eshipper-commerce/trunk)
-
tags/2.15.3/assets/eShipper.js (modified) (1 diff)
-
tags/2.15.3/framework/db.php (modified) (3 diffs)
-
tags/2.15.3/framework/lib/admin-settings.js (modified) (1 diff)
-
tags/2.15.3/framework/lib/plugin_health.css (modified) (4 diffs)
-
tags/2.15.3/framework/plugin.php (modified) (2 diffs)
-
tags/2.15.3/framework/shippingmethod.php (modified) (3 diffs)
-
tags/2.15.3/plugin/PluginHealthHelper.php (modified) (6 diffs)
-
tags/2.15.3/plugin/eshipperCalls.php (modified) (2 diffs)
-
tags/2.15.3/plugin/pluginLifeCycle.php (modified) (11 diffs)
-
tags/2.15.3/readme.txt (modified) (3 diffs)
-
tags/2.15.3/views/login_thickbox.php (modified) (3 diffs)
-
tags/2.15.3/woocommerce-eshipper.php (modified) (10 diffs)
-
trunk/assets/eShipper.js (modified) (1 diff)
-
trunk/framework/db.php (modified) (3 diffs)
-
trunk/framework/lib/admin-settings.js (modified) (1 diff)
-
trunk/framework/lib/plugin_health.css (modified) (4 diffs)
-
trunk/framework/plugin.php (modified) (2 diffs)
-
trunk/framework/shippingmethod.php (modified) (3 diffs)
-
trunk/plugin/PluginHealthHelper.php (modified) (6 diffs)
-
trunk/plugin/eshipperCalls.php (modified) (2 diffs)
-
trunk/plugin/pluginLifeCycle.php (modified) (11 diffs)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/views/login_thickbox.php (modified) (3 diffs)
-
trunk/woocommerce-eshipper.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
eshipper-commerce/tags/2.15.3/assets/eShipper.js
r2921864 r2943682 120 120 var errorMsg = ''; 121 121 122 if (domainUrl === 'undefined' || domainUrl == null || domainUrl === '' || !is_url_valid(domainUrl)) { 123 errorMsg = "Please provide valid domain url"; 122 // Validate eShipper domain 123 if (domainUrl === 'undefined' || domainUrl == null || domainUrl === '' || !is_url_valid(domainUrl) || !domainUrl.includes('eshipper.com')) { 124 console.log('invalid domain'); 125 errorMsg = "Please provide valid eShipper domain url"; 124 126 show_error_msg(); 125 127 resize_activation_tb_window(); 126 jQuery('#eshipper_message p').text(errorMsg);128 jQuery('#eshipper_message .msg').html(errorMsg); 127 129 return false; 128 130 } else if (username == 'undefined' || username == null || username == '') { 129 errorMsg = "Please provide valid username ";131 errorMsg = "Please provide valid username to connect to eShipper"; 130 132 show_error_msg(); 131 133 resize_activation_tb_window(); 132 jQuery('#eshipper_message p').text(errorMsg);134 jQuery('#eshipper_message .msg').html(errorMsg); 133 135 return false; 134 136 } else if (password == 'undefined' || password == null || password == '') { 135 errorMsg = "Please provide valid password ";137 errorMsg = "Please provide valid password to connect to eShipper"; 136 138 show_error_msg(); 137 139 resize_activation_tb_window(); 138 jQuery('#eshipper_message p').text(errorMsg);140 jQuery('#eshipper_message .msg').html(errorMsg); 139 141 return false; 140 142 } -
eshipper-commerce/tags/2.15.3/framework/db.php
r2923508 r2943682 29 29 PluginHealthHelper::createEshipperPluginHealthTable(); 30 30 31 update_option('eshipper_version', ESHIPPER_VERSION_2_15); 31 // Shipping address table structure was updated to change 'phone_no' datatype to varchar from int 32 pluginLifeCycle::createEshipperShippingAddressTable(); 33 34 update_option('eshipper_version', ESHIPPER_VERSION_LATEST); 32 35 } 33 36 … … 35 38 global $wpdb; 36 39 if ($wpdb->has_cap( 'utf8mb4_520' )){ 37 $this->collate = 'DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci';40 $this->collate = 'DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci'; 38 41 } elseif ($wpdb->has_cap( 'utf8mb4' )){ 39 42 $this->collate = 'DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci'; … … 43 46 return $this->collate; 44 47 } 45 48 46 49 47 50 /* 48 51 * Return resources 49 52 */ 50 abstract function get_resource($id);51 53 abstract function get_resource($id); 54 52 55 /* 53 56 * Date format -
eshipper-commerce/tags/2.15.3/framework/lib/admin-settings.js
r2921864 r2943682 413 413 })(); 414 414 415 if (window.location.href.includes('eshipper_health')) { 416 jQuery('.woocommerce-save-button').addClass('es-d-none'); 417 } else if (window.location.href.includes('eshipper_services') || window.location.href.includes('eshipper_settings')) { 418 jQuery('.woocommerce-save-button').removeClass('es-d-none'); 419 } // else do nothing 420 421 jQuery('#eshipper_health_tab').on('click', function (e) { 422 jQuery('.woocommerce-save-button').addClass('es-d-none'); 423 }); 424 425 jQuery('#eshipper_settings_tab').on('click', function (e) { 426 jQuery('.woocommerce-save-button').removeClass('es-d-none'); 427 }); 428 429 jQuery('#eshipper_services_tab').on('click', function (e) { 430 jQuery('.woocommerce-save-button').removeClass('es-d-none'); 431 }); 432 433 jQuery('#es-plugin-health-db-update').on('click', function (e) { 434 e.preventDefault(); 435 console.log('Attempting to update database to add plugin health table'); 436 437 jQuery.ajax({ 438 type: "post", 439 dataType: "json", 440 url: ajaxurl, 441 data: { 442 action: "plugin_health_db_update", 443 }, 444 success: function (response) { 445 console.log('Successfully updated database'); 446 447 jQuery('#es-plugin-health-db-update-message').removeClass('es-d-none').html( 448 response.msg + " <br><br><small><code>Reloading the page in 5 seconds... <br>If the page doesn't reload automatically, click <a href='javascript:void(0)' onclick='window.location.reload();'>here</a> </code></small>" 449 ); 450 451 (function () { 452 setTimeout(function () { 453 window.location.reload(); 454 }, 5000); 455 })(); 456 }, 457 error: function (response) { 458 console.log('Failed to update database. Error Response: '); 459 console.log(response); 460 jQuery('#es-plugin-health-db-update-message').removeClass('es-d-none').html(response.msg); 461 } 462 }); 463 }); 464 415 465 /** 416 466 * Fix health button on click - Calls woocommerce-eshipper.php -> fix_eshipper_plugin() -
eshipper-commerce/tags/2.15.3/framework/lib/plugin_health.css
r2921864 r2943682 113 113 } 114 114 115 .es-row + .es-row { 116 margin-top: 15px; 117 } 118 115 119 .es-col { 116 120 position: relative; … … 121 125 122 126 @media (min-width: 992px) { 127 .es-col:only-child { 128 width: 100%; 129 } 123 130 .es-col { 124 131 float: left; … … 182 189 } 183 190 191 .es-text-bold { 192 font-weight: bold; 193 } 194 195 .es-text-large { 196 font-size: larger; 197 } 198 199 .es-text-small { 200 font-size: smaller; 201 line-height: 20px; 202 } 203 184 204 .es-bg-secondary { 185 205 background-color: #31b5c1 !important; … … 234 254 .es-box-success { 235 255 border: 2px solid #24ED88; 256 } 257 258 .es-box-primary { 259 border: 2px solid #472F92; 236 260 } 237 261 -
eshipper-commerce/tags/2.15.3/framework/plugin.php
r2923508 r2943682 194 194 wp_enqueue_script('eshipper-require-postalcode', plugins_url('lib/require-postalcode.js', ESHIPPER_PLUGIN_FILE), ['jquery'], '1.0', true); 195 195 echo '<div id="calc_shipping_postcode_required" class="hidden woocommerce-info" style="display:none">' . __( 196 'Zip / Postal Code is required to calculate shipping',197 'woocommerce-eshipper'198 ) . '</div>';196 'Zip / Postal Code is required to calculate shipping', 197 'woocommerce-eshipper' 198 ) . '</div>'; 199 199 } 200 200 … … 269 269 // DB upgrade for version 2.15.1 270 270 $version = get_option('eshipper_version', '1.0'); 271 if (version_compare($version, ESHIPPER_VERSION_ 2_15, '<')) {271 if (version_compare($version, ESHIPPER_VERSION_LATEST, '<')) { 272 272 // Get required files for db upgrade 273 273 if (!class_exists('woocommerce_eshipper_db')) { -
eshipper-commerce/tags/2.15.3/framework/shippingmethod.php
r2923508 r2943682 877 877 } ?>" id="eshipper_health"> 878 878 879 <?php $pluginHealth = PluginHealthHelper::getPluginHealth(); ?>880 881 879 <div id="eshipper_health_panel_overlay"> 882 880 <div class="eshipper-preloader"> … … 886 884 887 885 <div class="es-row"> 888 <div class="es-col es_health_font_size"> 889 890 <div class="es_health_check_chart"> 891 <div class="flex-wrapper"> 892 <div class="single-chart"> 893 <svg viewBox="0 0 36 36" class="circular-chart blue" id="health-chart"> 894 <path class="circle-bg" 895 d="M18 2.0845 886 <div class="es-col"> 887 <div class="es-box es-box-primary"> 888 <p class="es-text-primary" style="text-align: center"> 889 <span class="es-text-bold es-text-large">eShipper Plugin Health*</span> 890 </p> 891 <p>This page visualizes various parameters to help you gauge the health of the eShipper Plugin and it's settings</p> 892 <p>The all new eShipper Plugin can now fix issues automatically! You can view, validate & fix most of the issues 893 automatically by just clicking the 'Fix' button against the issue item in the 'Health Check' table. 894 </p> 895 <p><b>Now you can also validate plugin settings!</b> When you make any changes to eShipper's settings, you can validate 896 them by clicking on the 'Verify' button against the related health item and wait for the result. If anything goes 897 wrong, use the 'Fix' button! You can also use this feature to validate any future updates to the eShipper Plugin. 898 </p> 899 <p><b>NOTE: While this page covers most of the common issues that usually occur in the plugin as observed on many 900 stores like yours, it should be noted that this is not a comprehensive list and some issues are specific to your 901 WordPress installation which would need manual resolution. For any such issues, please contact <em>eShipper 902 Support</em>.</b> 903 </p> 904 </div> 905 <hr> 906 </div> 907 </div> 908 909 <?php 910 // Enable Plugin Health feature only on PHP v8.0 911 $validPhpVersion = false; 912 if (version_compare(phpversion(), '8.0', '<')) { 913 $pluginHealth = null; 914 } else { 915 $validPhpVersion = true; 916 $pluginHealth = PluginHealthHelper::getPluginHealth(); 917 } 918 ?> 919 920 <?php if (empty($pluginHealth)) { 921 // This will be executed when the plugin health table does not exist in the db 922 // Show the user an option to update db, if for any reason table could not be created during install/update. 923 ?> 924 <div class="es-row"> 925 <div class="es-col"> 926 <div class="es-box es-box-danger"> 927 <p> 928 <span class="es-text-danger es-text-bold">Action Required: </span> 929 <br> 930 <?php if ($validPhpVersion) { ?> 931 <span>To view this page, a database update is required. Please click the button below to run the 932 update.</span> 933 <?php } else { ?> 934 To view this page, minimum required version of PHP is 8.0 935 <br>Your site is currently running on PHP version - <span class="es-text-danger"><?= phpversion(); ?></span> 936 <br>Upgrade your PHP version to experience the latest features. 937 <?php } ?> 938 </p> 939 <p class="es-text-primary"><b>Don't worry if you are not able to view this page properly, this does NOT affect any 940 eShipper services on your store!</b></p> 941 942 <?php if ($validPhpVersion) { ?> 943 <button class='es-button es-button-primary' id="es-plugin-health-db-update">Update Database</button> 944 <p class="es-d-none" id="es-plugin-health-db-update-message"></p> 945 <?php } ?> 946 947 </div> 948 </div> 949 </div> 950 <?php } else { 951 // If table exists, then show the plugin health page. 952 // (dev note: closing tag for else is below the following div) 953 ?> 954 955 <div class="es-row"> 956 <div class="es-col es_health_font_size"> 957 958 <div class="es_health_check_chart"> 959 <div class="flex-wrapper"> 960 <div class="single-chart"> 961 <svg viewBox="0 0 36 36" class="circular-chart blue" id="health-chart"> 962 <path class="circle-bg" 963 d="M18 2.0845 896 964 a 15.9155 15.9155 0 0 1 0 31.831 897 965 a 15.9155 15.9155 0 0 1 0 -31.831" 898 />899 <path class="circle"900 stroke-dasharray="<?php echo $pluginHealth['percentage_health'] ?>, 100"901 d="M18 2.0845966 /> 967 <path class="circle" 968 stroke-dasharray="<?php echo $pluginHealth['percentage_health'] ?>, 100" 969 d="M18 2.0845 902 970 a 15.9155 15.9155 0 0 1 0 31.831 903 971 a 15.9155 15.9155 0 0 1 0 -31.831" 904 /> 905 <text x="18" y="20.35" class="percentage"><?php echo $pluginHealth['percentage_health'] . '%' ?></text> 906 </svg> 972 /> 973 <text x="18" y="20.35" class="percentage"><?php echo $pluginHealth['percentage_health'] . '%' ?></text> 974 </svg> 975 </div> 907 976 </div> 908 977 </div> 978 979 <div class="es-row"> 980 <div class="es-col"> 981 <h3>eShipper Plugin Status: <span id="plugin-stats-status"><?php echo $pluginHealth['status']; ?></span> 982 </h3> 983 984 <p> 985 <b>Issues found: </b> <span id="plugin-stats-issue-count"><?php echo $pluginHealth['issue_count'] ?></span> 986 </p> 987 988 <p> 989 <b>Last updated at: </b> <span 990 id="plugin-stats-updated-time"><?php echo $pluginHealth['updated_time']; ?></span> 991 </p> 992 </div> 993 <div class="es-col"> 994 <button class='es-button es-button-primary' onclick="window.location.reload();">Recheck</button> 995 </div> 996 </div> 997 998 <?php if (!empty($pluginHealth['notice'])) { ?> 999 <div class="es-box es-box-danger" id="health-action-notice"> 1000 <p> 1001 <span class="es-text-danger es-text-bold">Action Required: </span> 1002 <span id="health-action-message"><?php echo $pluginHealth['notice']; ?></span> 1003 </p> 1004 </div> 1005 <?php } ?> 1006 <div class="es-box es-box-success" style="display: none;" id="fix-success-message"></div> 909 1007 </div> 910 1008 911 <div class="es-row"> 912 <div class="es-col"> 913 <h3>eShipper Plugin Status: <span id="plugin-stats-status"><?php echo $pluginHealth['status']; ?></span> 914 </h3> 915 916 <p> 917 <b>Issues found: </b> <span id="plugin-stats-issue-count"><?php echo $pluginHealth['issue_count'] ?></span> 918 </p> 919 920 <p> 921 <b>Last updated at: </b> <span id="plugin-stats-updated-time"><?php echo $pluginHealth['updated_time']; ?></span> 922 </p> 923 </div> 924 <div class="es-col"> 925 <button class='es-button es-button-primary' onclick="window.location.reload();">Recheck</button> 926 </div> 927 </div> 928 929 <?php if (!empty($pluginHealth['notice'])) { ?> 930 <div class="es-box es-box-danger" id="health-action-notice"> 931 <p> 932 <span class="es-text-danger es-text-bold">Action Required: </span> 933 <span id="health-action-message"><?php echo $pluginHealth['notice']; ?></span> 934 </p> 935 </div> 936 <?php } ?> 937 <div class="es-box es-box-success" style="display: none;" id="fix-success-message"></div> 938 </div> 939 940 <div class="es-col"> 941 <table class="es_health_table"> 942 <thead> 943 <tr> 944 <th colspan="2">Health Check</th> 945 <th style="text-align: center">Status</th> 946 <th style="text-align: center">Action</th> 947 </tr> 948 </thead> 949 <tbody> 950 <?php 951 $validAuth = $pluginHealth['items'][PluginHealthHelper::ATTR_AUTH]; 952 foreach ($pluginHealth['items'] as $item => $health) { 953 $name = PluginHealthHelper::getDisplayName($item); 954 955 // Insert trigger for auth dialog (this will only be done for auth FIX button) 956 $auth = $item === PluginHealthHelper::ATTR_AUTH && !$validAuth ? "onclick='show_login_popup()'" : ""; 957 958 // When Auth is NOT working, all other buttons except FIX button for Auth, will be disabled. 959 $disabled = $item !== PluginHealthHelper::ATTR_AUTH && !$validAuth ? "disabled title='Please fix Authentication!'" : ""; 960 961 $loaderUrl = ESHIPPER_PLUGIN_URL . '/img/preloader.gif'; 962 $loader = "<div class='fix-loader-icon es-d-none' id='$item-fix-loader'> 1009 <div class="es-col"> 1010 <table class="es_health_table"> 1011 <thead> 1012 <tr> 1013 <th colspan="2">Health Check</th> 1014 <th style="text-align: center">Status</th> 1015 <th style="text-align: center">Action</th> 1016 </tr> 1017 </thead> 1018 <tbody> 1019 <?php 1020 $validAuth = $pluginHealth['items'][PluginHealthHelper::ATTR_AUTH]; 1021 foreach ($pluginHealth['items'] as $item => $health) { 1022 $name = PluginHealthHelper::getDisplayName($item); 1023 1024 // Insert trigger for auth dialog (this will only be done for auth FIX button) 1025 $auth = $item === PluginHealthHelper::ATTR_AUTH && !$validAuth ? "onclick='show_login_popup()'" : ""; 1026 1027 // When Auth is NOT working, all other buttons except FIX button for Auth, will be disabled. 1028 $disabled = $item !== PluginHealthHelper::ATTR_AUTH && !$validAuth ? "disabled title='Please fix Authentication!'" : ""; 1029 1030 $loaderUrl = ESHIPPER_PLUGIN_URL . '/img/preloader.gif'; 1031 $loader = "<div class='fix-loader-icon es-d-none' id='$item-fix-loader'> 963 1032 <img src='$loaderUrl' alt='Please wait...'> 964 1033 </div>"; 965 1034 966 // Health item status is OK967 if ($health) {968 $icon = "<span class='es-text-success' id='$item-status'>OK</span>";969 // If these items are OK, no action is required970 if ($item === PluginHealthHelper::ATTR_AUTH) {971 $action = "";972 } else {973 $action = "<button class='es-button es-button-primary fix-health-btn' $disabled $auth data-issue='$item' data-type='verify'>1035 // Health item status is OK 1036 if ($health) { 1037 $icon = "<span class='es-text-success' id='$item-status'>OK</span>"; 1038 // If these items are OK, no action is required 1039 if ($item === PluginHealthHelper::ATTR_AUTH) { 1040 $action = ""; 1041 } else { 1042 $action = "<button class='es-button es-button-primary fix-health-btn' $disabled $auth data-issue='$item' data-type='verify'> 974 1043 <span class='btn-text'>Verify</span> 975 1044 $loader 976 1045 </button>"; 977 }978 } else {979 $icon = "<span class='es-text-danger' id='$item-status'>X</span>";980 981 // If these items are NOT OK, only re-install can fix the problem, hence just display 'Re-install'982 if ($item === PluginHealthHelper::ATTR_BACKEND_SYNC) {983 if (!$validAuth) {984 $action = "";985 } else {986 $action = "Re-install";987 }988 } else {989 $action = "<button class='es-button es-button-danger fix-health-btn' $disabled $auth data-issue='$item' data-type='fix'>1046 } 1047 } else { 1048 $icon = "<span class='es-text-danger' id='$item-status'>X</span>"; 1049 1050 // If these items are NOT OK, only re-install can fix the problem, hence just display 'Re-install' 1051 if ($item === PluginHealthHelper::ATTR_BACKEND_SYNC) { 1052 if (!$validAuth) { 1053 $action = ""; 1054 } else { 1055 $action = "Re-install"; 1056 } 1057 } else { 1058 $action = "<button class='es-button es-button-danger fix-health-btn' $disabled $auth data-issue='$item' data-type='fix'> 990 1059 <span class='btn-text'>Fix</span> 991 1060 $loader 992 1061 </button>"; 993 }994 }995 996 echo "1062 } 1063 } 1064 1065 echo " 997 1066 <tr> 998 1067 <td colspan='2'>$name</td> … … 1001 1070 </tr> 1002 1071 "; 1003 } 1004 ?> 1005 </tbody> 1006 </table> 1072 } 1073 ?> 1074 </tbody> 1075 </table> 1076 </div> 1077 </div> 1078 1079 <?php } ?> 1080 1081 <div class="es-row" style="margin-top: 50px"> 1082 <div class="es-col"> 1083 <hr> 1084 <p> 1085 <small> 1086 * This page is only a visual representation of the eShipper plugin's health and is only meant for reporting purposes. 1087 <b> * If you are not able to view this page, it does NOT affect any eShipper services on your store.</b> * 1088 To view this page, minimum required PHP 1089 version is 8.0 1090 </small> 1091 </p> 1007 1092 </div> 1008 1093 </div> 1009 1010 1094 </div> 1011 1095 -
eshipper-commerce/tags/2.15.3/plugin/PluginHealthHelper.php
r2921864 r2943682 46 46 public static function createEshipperPluginHealthTable() 47 47 { 48 global $wpdb;49 48 $table = self::getPluginHealthTableName(); 50 49 50 // TODO: This will be removed in the upcoming versions since this is not required because dbDelta() takes care of this action. 51 51 // Drop table if already exists 52 if ($wpdb->get_var("SHOW TABLES LIKE '$table'") === $table) {53 $wpdb->query("DROP TABLE $table");54 }52 // if ($wpdb->get_var("SHOW TABLES LIKE '$table'") === $table) { 53 // $wpdb->query("DROP TABLE $table"); 54 // } 55 55 56 56 $columns = ''; 57 foreach (self::getEnabledAttributes() as $attribute) { 58 $columns .= $attribute . ' tinyint(1) DEFAULT 0,'; 59 } 60 61 $create_plugin_health_table = " CREATE TABLE $table( 57 foreach (self::getEnabledAttributes() as $index => $attribute) { 58 // Add a new line for every column (as per wordpress doc here: https://codex.wordpress.org/Creating_Tables_with_Plugins#Creating_or_Updating_the_Table) 59 // DO NOT REMOVE the formatting below: 60 $columns .= ' 61 ' . $attribute . ' tinyint(1) DEFAULT 0,'; 62 } 63 64 $create_plugin_health_table = "CREATE TABLE $table( 62 65 $columns 63 66 created_time timestamp DEFAULT CURRENT_TIMESTAMP, … … 131 134 132 135 /** 133 * @return array 136 * @return array|null 134 137 */ 135 138 public static function getPluginHealth($asyncRequest = false) … … 137 140 // Get the table name 138 141 global $wpdb; 139 $table = self::getPluginHealthTableName(); 142 143 // This also checks and creates the table if it doesn't exist in the db 144 $table = self::getPluginHealthTableName(true); 140 145 141 146 // First update the plugin health … … 148 153 // Get the items & their respective status from health table 149 154 $healthItems = $wpdb->get_row("SELECT * from $table", ARRAY_A); 155 156 // If there are no items populated in the db, return null 157 if (empty($healthItems)) { 158 return null; 159 } 150 160 151 161 // Filter out items to be displayed … … 276 286 $domainUrl = $wpdb->get_var("SELECT domain_url FROM {$wpdb->prefix}eshipper_access_tokens WHERE currently_active = 1"); 277 287 288 // If domain is empty, no further action - mark auth as false 289 // if (empty($domainUrl)) { 290 // return self::recordAuthStatus(false); 291 // } 292 293 // Check in real time if store is connected: Upcoming version 294 // $storeConnected = eshipperCalls::checkIfStoreIsConnected($domainUrl); 295 278 296 return self::recordAuthStatus(!empty($domainUrl)); 279 297 } … … 508 526 509 527 /** 510 * @return string 511 */ 512 private static function getPluginHealthTableName() 513 { 514 global $wpdb; 515 516 return $wpdb->prefix . self::TABLE_NAME; 528 * @param $createTableIfDoesntExist 529 * @return string|null 530 */ 531 private static function getPluginHealthTableName(bool $createTableIfDoesntExist = false) 532 { 533 global $wpdb; 534 535 $table = $wpdb->prefix . self::TABLE_NAME; 536 537 // Check if the plugin health table exists and create if it doesn't 538 if ($createTableIfDoesntExist && $wpdb->get_var("SHOW TABLES LIKE '$table'") !== $table) { 539 self::createEshipperPluginHealthTable(); 540 } 541 542 return $table; 517 543 } 518 544 } -
eshipper-commerce/tags/2.15.3/plugin/eshipperCalls.php
r2921864 r2943682 205 205 206 206 $httpResponseCode = $response['httpResponseCode']; 207 $error_message = $response['response']->errors;207 $error_message = isset($response['response']->errors) ? $response['response']->errors : 'Something went wrong! Please contact support.'; 208 208 209 209 //if the response code is 200 then create tables and what not … … 233 233 return $responseArray; 234 234 } 235 236 /** 237 * Check if store is connected by invoking eShipper API 238 * @param $domainUrl 239 * @return bool 240 */ 241 public static function checkIfStoreIsConnected($domainUrl) 242 { 243 // Get the store domain name 244 $shopName = trim(str_replace('/shop', '', get_site_url())); 245 $shopName = rtrim(preg_replace("#^[^:/.]*[:/]+#i", "", $shopName), '/'); 246 247 // Call the eShipper API to check if this store is installed 248 $response = (new curlHandler())->sendCurlRequest( 249 json_encode(['shop' => $shopName]), 250 "$domainUrl/ecommerce/woocommerce/is-store-installed", 251 'POST', 252 [ 253 'Accept: application/json', 254 'Content-Type: application/json', 255 ] 256 ); 257 258 // If the response is 200 then return true 259 if (!empty($response['response']) && !empty($httpResponseCode = $response['httpResponseCode']) && $httpResponseCode === 200) { 260 return true; 261 } 262 263 // If response is not 200 return false 264 return false; 265 } 235 266 } -
eshipper-commerce/tags/2.15.3/plugin/pluginLifeCycle.php
r2923508 r2943682 146 146 147 147 // Drop table if already exists 148 if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_boxing_services_master'") === $eshipper_boxing_services_master) {149 $wpdb->query("DROP TABLE $eshipper_boxing_services_master");150 }148 // if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_boxing_services_master'") === $eshipper_boxing_services_master) { 149 // $wpdb->query("DROP TABLE $eshipper_boxing_services_master"); 150 // } 151 151 152 152 $create_boxing_master_table_query = " CREATE TABLE $eshipper_boxing_services_master( … … 171 171 private static function createEshipperAccessTokensTable() 172 172 { 173 wc_get_logger()->debug('Attempting to create table - eshipper_access_tokens', ['source' => 'eshipper']); 174 173 175 global $wpdb; 174 176 $eshipper_access_tokens = $wpdb->prefix . "eshipper_access_tokens"; 175 177 176 178 // Drop table if already exists 177 if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_access_tokens'") === $eshipper_access_tokens) { 178 $wpdb->query("DROP TABLE $eshipper_access_tokens"); 179 } 179 // Not required - dbDelta() takes care of that 180 // if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_access_tokens'") === $eshipper_access_tokens) { 181 // $wpdb->query("DROP TABLE $eshipper_access_tokens"); 182 // } 180 183 181 184 $access_tokens_query = " CREATE TABLE $eshipper_access_tokens( … … 192 195 require_once(ABSPATH . "wp-admin/includes/upgrade.php"); 193 196 dbDelta($access_tokens_query); 197 198 wc_get_logger()->debug('Successfully to create table - eshipper_access_tokens', ['source' => 'eshipper']); 194 199 } 195 200 … … 201 206 private static function createEshipperCarrierServicesTable() 202 207 { 208 wc_get_logger()->debug('Attempting to create table - eshipper_carrier_service_master', ['source' => 'eshipper']); 209 203 210 global $wpdb; 204 211 $eshipper_carrier_services = $wpdb->prefix . "eshipper_carrier_service_master"; 205 212 206 213 // Drop table if already exists 207 if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_carrier_services'") === $eshipper_carrier_services) {208 $wpdb->query("DROP TABLE $eshipper_carrier_services");209 }214 // if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_carrier_services'") === $eshipper_carrier_services) { 215 // $wpdb->query("DROP TABLE $eshipper_carrier_services"); 216 // } 210 217 211 218 $access_tokens_query = " CREATE TABLE $eshipper_carrier_services( … … 259 266 $status = PluginHealthHelper::recordAuthStatus(true); 260 267 } catch (Exception $exception) { 261 wc_get_logger()-> debug(268 wc_get_logger()->error( 262 269 'Error while storing eshipper access token in DB - [ERROR] - ' . print_r($exception->getMessage(), true), 263 270 ['source' => 'eshipper'] … … 297 304 $status = PluginHealthHelper::recordStoreAddressStatus(true); 298 305 } catch (Exception $exception) { 299 wc_get_logger()-> debug(306 wc_get_logger()->error( 300 307 'Error while copying store address from woocommerce - [ERROR] - ' . print_r($exception->getMessage(), true), 301 308 ['source' => 'eshipper'] … … 434 441 $status = PluginHealthHelper::recordWebhooksStatus(true); 435 442 } catch (Exception $exception) { 436 wc_get_logger()-> debug('Error while creating webhooks. - [ERROR] - ' . print_r($exception->getMessage(), true), ['source' => 'eshipper']);443 wc_get_logger()->error('Error while creating webhooks. - [ERROR] - ' . print_r($exception->getMessage(), true), ['source' => 'eshipper']); 437 444 438 445 $status = PluginHealthHelper::recordWebhooksStatus(false); … … 485 492 * Function to create table in Woo-Commerce DB to store the Shipping Address 486 493 */ 487 p rivatestatic function createEshipperShippingAddressTable()494 public static function createEshipperShippingAddressTable() 488 495 { 489 496 global $wpdb; … … 491 498 492 499 // Drop table if already exists 493 if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_shipping_address'") === $eshipper_shipping_address) {494 $wpdb->query("DROP TABLE $eshipper_shipping_address");495 }500 // if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_shipping_address'") === $eshipper_shipping_address) { 501 // $wpdb->query("DROP TABLE $eshipper_shipping_address"); 502 // } 496 503 497 504 $create_shipping_address_query = " CREATE TABLE $eshipper_shipping_address( … … 505 512 zipcode varchar(255) , 506 513 shipping_name text , 507 phone_no int(14) ,514 phone_no varchar(20) , 508 515 email_id varchar (255), 509 516 created_time timestamp DEFAULT CURRENT_TIMESTAMP, … … 560 567 $status = PluginHealthHelper::recordCarrierServicesStatus(true); 561 568 } catch (Exception $exception) { 562 wc_get_logger()-> debug(569 wc_get_logger()->error( 563 570 'Error while adding eshipper carrier services - [ERROR] - ' . print_r($exception->getMessage(), true), 564 571 ['source' => 'eshipper'] -
eshipper-commerce/tags/2.15.3/readme.txt
r2923520 r2943682 5 5 Tested up to: 6.2.2 6 6 Requires PHP: 7.1 7 Stable tag: 2.15. 27 Stable tag: 2.15.3 8 8 License: GPLv3 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 54 54 55 55 == Changelog == 56 = 2.15.3 = 57 * Critical Bug Fixes for versions 2.14.3 & v2.15.2 58 56 59 = 2.15.2 = 57 60 * Critical bug fixes & better user experience … … 82 85 83 86 == Upgrade Notice == 87 = 2.15.3 = 88 Upgrade to receive critical bug fixes NOW! 89 84 90 = 2.15.2 = 85 91 Recommended upgrade for critical bug fixes in versions 2.15 & 2.15.1 -
eshipper-commerce/tags/2.15.3/views/login_thickbox.php
r2921864 r2943682 91 91 <div class="col-75"> 92 92 <input class="es_input_class" type="text" id="domain_url" name="domain_url" placeholder="https://domain_name.com" value="https://ww2.eshipper.com"> 93 <small>This should be a valid eShipper domain.</small> 93 94 </div> 94 95 </div> … … 99 100 <div class="col-75"> 100 101 <input class="es_input_class" type="text" id="username" name="username" placeholder="Username"> 102 <small>Enter your eShipper username to connect the plugin to eShipper services.</small> 101 103 </div> 102 104 </div> … … 109 111 <input type="hidden" name="grant_type" value="password"> 110 112 <input type="hidden" name="client_id" value="web_app"> 113 <small>Enter your eShipper password to connect the plugin to eShipper services.</small> 111 114 </div> 112 115 </div> -
eshipper-commerce/tags/2.15.3/woocommerce-eshipper.php
r2923508 r2943682 4 4 Plugin URI: https://ww2.eshipper.com/ecommerce/ 5 5 Description: Extends WooCommerce with Shipping Rates from eShipper 6 Version: 2.15. 26 Version: 2.15.3 7 7 Author: eShipper 8 8 Author URI: https://ww2.eshipper.com/ … … 29 29 ))) { 30 30 define('ESHIPPER_VERSION', '1.4.1'); 31 define('ESHIPPER_VERSION_ 2_15', '2.15.2');31 define('ESHIPPER_VERSION_LATEST', '2.15.3'); 32 32 //Plugin Path 33 33 define('ESHIPPER_PLUGIN_PATH', dirname(__FILE__)); … … 154 154 add_action('wp_ajax_boxing_insert', 'boxing_insert'); 155 155 add_action('wp_ajax_fix_eshipper_plugin', 'fix_eshipper_plugin'); 156 add_action('wp_ajax_plugin_health_db_update', 'plugin_health_db_update'); 156 157 157 158 function fix_eshipper_plugin() … … 254 255 } 255 256 257 function plugin_health_db_update() 258 { 259 $update = false; 260 try { 261 // Log the activity 262 wc_get_logger()->debug('Attempting to create plugin health table', ['source' => 'eshipper']); 263 264 // Attempt to create plugin health table 265 $update = PluginHealthHelper::createEshipperPluginHealthTable(); 266 } catch (Exception $e) { 267 wc_get_logger()->error( 268 'ERROR creating plugin health table: [CODE]: ' . $e->getCode() . ' [ERROR] - ' . print_r($e->getMessage(), true), 269 ['source' => 'eshipper'] 270 ); 271 } 272 273 if ($update) { 274 $statusCode = 200; 275 $msg = 'Database Update is successful!'; 276 277 wc_get_logger()->debug('Successfully created plugin health table.', ['source' => 'eshipper']); 278 279 // Validate Plugin health to populate current state of the plugin 280 PluginHealthHelper::validatePluginHealth(); 281 } else { 282 $statusCode = 412; 283 $msg = 'Could not update database, something went wrong while processing your request. Please contact support to fix the issue.'; 284 285 wc_get_logger()->error('Failed to create plugin health table.', ['source' => 'eshipper']); 286 } 287 288 $result = [ 289 'statusCode' => $statusCode, 290 'msg' => $msg, 291 ]; 292 293 // Return Error Response 294 echo json_encode($result); 295 die(); 296 } 297 256 298 function eshipper_health_check_admin_notice() 257 299 { … … 329 371 'methods' => 'DELETE', 330 372 'callback' => 'uninstallEshipperPlugin', 373 'permission_callback' => '__return_true', 331 374 ]); 332 375 }); … … 334 377 function uninstallEshipperPlugin($request) 335 378 { 379 wc_get_logger()->debug('Attempting to deactivate eShipper plugin. Store was detached from eShipper', ['source' => 'eshipper']); 336 380 $all_headers = $request->get_headers(); 337 381 … … 340 384 $responseArray = ['statusCode' => "401", "msg" => "Sorry, you are not authorized to do this event"]; 341 385 386 wc_get_logger()->error('Failed to deactivate eShipper plugin', ['source' => 'eshipper']); 387 342 388 return new WP_REST_Response($responseArray, 401); 343 389 } 344 390 345 $plugin = 'eShipper-plugin/woocommerce-eshipper.php'; 346 deactivate_plugins($plugin); 347 $responseArray = ['statusCode' => "200", "msg" => "eShipper plugin uninstalled successfully"]; 348 349 return new WP_REST_Response($responseArray, 200); 391 // Deactivate the plugin 392 require_once(ABSPATH . 'wp-admin/includes/plugin.php'); 393 deactivate_plugins(ESHIPPER_PLUGIN_PATH); 394 395 // If the plugin is still active at this point then return error 396 if (is_plugin_active(plugin_basename(ESHIPPER_PLUGIN_FILE))) { 397 wc_get_logger()->error('Failed to deactivate eShipper plugin. Please deactivate the plugin directly from your store.', ['source' => 'eshipper']); 398 399 $responseArray = [ 400 'statusCode' => "412", 401 "msg" => "Failed to deactivate eShipper plugin. Please deactivate the plugin directly from your store.", 402 ]; 403 return new WP_REST_Response($responseArray, 412); 404 } else { 405 wc_get_logger()->debug('eShipper plugin deactivated successfully. Good bye!', ['source' => 'eshipper']); 406 407 $responseArray = [ 408 'statusCode' => "200", 409 "msg" => "eShipper plugin deactivated successfully!", 410 ]; 411 return new WP_REST_Response($responseArray, 200); 412 } 350 413 } 351 414 … … 582 645 $validateParameters = 1; 583 646 $requestData = []; 647 $msg = ''; 584 648 if (isset($_POST['formdata']) && is_array($_POST['formdata'])) { 585 649 foreach ($_POST['formdata'] as $k => $formdata) { … … 589 653 break; 590 654 } 655 656 // Validate eShipper's domain (this check is also applied in js hence the code below is a fail safe) 657 if ($formdata['name'] === 'domain_url' && !str_contains($formdata['value'], 'eshipper.com')) { 658 $validateParameters = 0; 659 $msg = 'Invalid Domain URL. Please enter the correct eshipper domain'; 660 break; 661 } 662 591 663 $key = $formdata['name']; 592 664 $val = $formdata['value']; … … 599 671 echo json_encode([ 600 672 'statusCode' => 412, 601 'msg' => 'The credentials you entered are incorrect. Please provide correct data.',673 'msg' => $msg ?? 'The credentials you entered are incorrect. Please provide correct data.', 602 674 ]); 603 675 die(); -
eshipper-commerce/trunk/assets/eShipper.js
r2921864 r2943682 120 120 var errorMsg = ''; 121 121 122 if (domainUrl === 'undefined' || domainUrl == null || domainUrl === '' || !is_url_valid(domainUrl)) { 123 errorMsg = "Please provide valid domain url"; 122 // Validate eShipper domain 123 if (domainUrl === 'undefined' || domainUrl == null || domainUrl === '' || !is_url_valid(domainUrl) || !domainUrl.includes('eshipper.com')) { 124 console.log('invalid domain'); 125 errorMsg = "Please provide valid eShipper domain url"; 124 126 show_error_msg(); 125 127 resize_activation_tb_window(); 126 jQuery('#eshipper_message p').text(errorMsg);128 jQuery('#eshipper_message .msg').html(errorMsg); 127 129 return false; 128 130 } else if (username == 'undefined' || username == null || username == '') { 129 errorMsg = "Please provide valid username ";131 errorMsg = "Please provide valid username to connect to eShipper"; 130 132 show_error_msg(); 131 133 resize_activation_tb_window(); 132 jQuery('#eshipper_message p').text(errorMsg);134 jQuery('#eshipper_message .msg').html(errorMsg); 133 135 return false; 134 136 } else if (password == 'undefined' || password == null || password == '') { 135 errorMsg = "Please provide valid password ";137 errorMsg = "Please provide valid password to connect to eShipper"; 136 138 show_error_msg(); 137 139 resize_activation_tb_window(); 138 jQuery('#eshipper_message p').text(errorMsg);140 jQuery('#eshipper_message .msg').html(errorMsg); 139 141 return false; 140 142 } -
eshipper-commerce/trunk/framework/db.php
r2923508 r2943682 29 29 PluginHealthHelper::createEshipperPluginHealthTable(); 30 30 31 update_option('eshipper_version', ESHIPPER_VERSION_2_15); 31 // Shipping address table structure was updated to change 'phone_no' datatype to varchar from int 32 pluginLifeCycle::createEshipperShippingAddressTable(); 33 34 update_option('eshipper_version', ESHIPPER_VERSION_LATEST); 32 35 } 33 36 … … 35 38 global $wpdb; 36 39 if ($wpdb->has_cap( 'utf8mb4_520' )){ 37 $this->collate = 'DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci';40 $this->collate = 'DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci'; 38 41 } elseif ($wpdb->has_cap( 'utf8mb4' )){ 39 42 $this->collate = 'DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci'; … … 43 46 return $this->collate; 44 47 } 45 48 46 49 47 50 /* 48 51 * Return resources 49 52 */ 50 abstract function get_resource($id);51 53 abstract function get_resource($id); 54 52 55 /* 53 56 * Date format -
eshipper-commerce/trunk/framework/lib/admin-settings.js
r2921864 r2943682 413 413 })(); 414 414 415 if (window.location.href.includes('eshipper_health')) { 416 jQuery('.woocommerce-save-button').addClass('es-d-none'); 417 } else if (window.location.href.includes('eshipper_services') || window.location.href.includes('eshipper_settings')) { 418 jQuery('.woocommerce-save-button').removeClass('es-d-none'); 419 } // else do nothing 420 421 jQuery('#eshipper_health_tab').on('click', function (e) { 422 jQuery('.woocommerce-save-button').addClass('es-d-none'); 423 }); 424 425 jQuery('#eshipper_settings_tab').on('click', function (e) { 426 jQuery('.woocommerce-save-button').removeClass('es-d-none'); 427 }); 428 429 jQuery('#eshipper_services_tab').on('click', function (e) { 430 jQuery('.woocommerce-save-button').removeClass('es-d-none'); 431 }); 432 433 jQuery('#es-plugin-health-db-update').on('click', function (e) { 434 e.preventDefault(); 435 console.log('Attempting to update database to add plugin health table'); 436 437 jQuery.ajax({ 438 type: "post", 439 dataType: "json", 440 url: ajaxurl, 441 data: { 442 action: "plugin_health_db_update", 443 }, 444 success: function (response) { 445 console.log('Successfully updated database'); 446 447 jQuery('#es-plugin-health-db-update-message').removeClass('es-d-none').html( 448 response.msg + " <br><br><small><code>Reloading the page in 5 seconds... <br>If the page doesn't reload automatically, click <a href='javascript:void(0)' onclick='window.location.reload();'>here</a> </code></small>" 449 ); 450 451 (function () { 452 setTimeout(function () { 453 window.location.reload(); 454 }, 5000); 455 })(); 456 }, 457 error: function (response) { 458 console.log('Failed to update database. Error Response: '); 459 console.log(response); 460 jQuery('#es-plugin-health-db-update-message').removeClass('es-d-none').html(response.msg); 461 } 462 }); 463 }); 464 415 465 /** 416 466 * Fix health button on click - Calls woocommerce-eshipper.php -> fix_eshipper_plugin() -
eshipper-commerce/trunk/framework/lib/plugin_health.css
r2921864 r2943682 113 113 } 114 114 115 .es-row + .es-row { 116 margin-top: 15px; 117 } 118 115 119 .es-col { 116 120 position: relative; … … 121 125 122 126 @media (min-width: 992px) { 127 .es-col:only-child { 128 width: 100%; 129 } 123 130 .es-col { 124 131 float: left; … … 182 189 } 183 190 191 .es-text-bold { 192 font-weight: bold; 193 } 194 195 .es-text-large { 196 font-size: larger; 197 } 198 199 .es-text-small { 200 font-size: smaller; 201 line-height: 20px; 202 } 203 184 204 .es-bg-secondary { 185 205 background-color: #31b5c1 !important; … … 234 254 .es-box-success { 235 255 border: 2px solid #24ED88; 256 } 257 258 .es-box-primary { 259 border: 2px solid #472F92; 236 260 } 237 261 -
eshipper-commerce/trunk/framework/plugin.php
r2923508 r2943682 194 194 wp_enqueue_script('eshipper-require-postalcode', plugins_url('lib/require-postalcode.js', ESHIPPER_PLUGIN_FILE), ['jquery'], '1.0', true); 195 195 echo '<div id="calc_shipping_postcode_required" class="hidden woocommerce-info" style="display:none">' . __( 196 'Zip / Postal Code is required to calculate shipping',197 'woocommerce-eshipper'198 ) . '</div>';196 'Zip / Postal Code is required to calculate shipping', 197 'woocommerce-eshipper' 198 ) . '</div>'; 199 199 } 200 200 … … 269 269 // DB upgrade for version 2.15.1 270 270 $version = get_option('eshipper_version', '1.0'); 271 if (version_compare($version, ESHIPPER_VERSION_ 2_15, '<')) {271 if (version_compare($version, ESHIPPER_VERSION_LATEST, '<')) { 272 272 // Get required files for db upgrade 273 273 if (!class_exists('woocommerce_eshipper_db')) { -
eshipper-commerce/trunk/framework/shippingmethod.php
r2923508 r2943682 877 877 } ?>" id="eshipper_health"> 878 878 879 <?php $pluginHealth = PluginHealthHelper::getPluginHealth(); ?>880 881 879 <div id="eshipper_health_panel_overlay"> 882 880 <div class="eshipper-preloader"> … … 886 884 887 885 <div class="es-row"> 888 <div class="es-col es_health_font_size"> 889 890 <div class="es_health_check_chart"> 891 <div class="flex-wrapper"> 892 <div class="single-chart"> 893 <svg viewBox="0 0 36 36" class="circular-chart blue" id="health-chart"> 894 <path class="circle-bg" 895 d="M18 2.0845 886 <div class="es-col"> 887 <div class="es-box es-box-primary"> 888 <p class="es-text-primary" style="text-align: center"> 889 <span class="es-text-bold es-text-large">eShipper Plugin Health*</span> 890 </p> 891 <p>This page visualizes various parameters to help you gauge the health of the eShipper Plugin and it's settings</p> 892 <p>The all new eShipper Plugin can now fix issues automatically! You can view, validate & fix most of the issues 893 automatically by just clicking the 'Fix' button against the issue item in the 'Health Check' table. 894 </p> 895 <p><b>Now you can also validate plugin settings!</b> When you make any changes to eShipper's settings, you can validate 896 them by clicking on the 'Verify' button against the related health item and wait for the result. If anything goes 897 wrong, use the 'Fix' button! You can also use this feature to validate any future updates to the eShipper Plugin. 898 </p> 899 <p><b>NOTE: While this page covers most of the common issues that usually occur in the plugin as observed on many 900 stores like yours, it should be noted that this is not a comprehensive list and some issues are specific to your 901 WordPress installation which would need manual resolution. For any such issues, please contact <em>eShipper 902 Support</em>.</b> 903 </p> 904 </div> 905 <hr> 906 </div> 907 </div> 908 909 <?php 910 // Enable Plugin Health feature only on PHP v8.0 911 $validPhpVersion = false; 912 if (version_compare(phpversion(), '8.0', '<')) { 913 $pluginHealth = null; 914 } else { 915 $validPhpVersion = true; 916 $pluginHealth = PluginHealthHelper::getPluginHealth(); 917 } 918 ?> 919 920 <?php if (empty($pluginHealth)) { 921 // This will be executed when the plugin health table does not exist in the db 922 // Show the user an option to update db, if for any reason table could not be created during install/update. 923 ?> 924 <div class="es-row"> 925 <div class="es-col"> 926 <div class="es-box es-box-danger"> 927 <p> 928 <span class="es-text-danger es-text-bold">Action Required: </span> 929 <br> 930 <?php if ($validPhpVersion) { ?> 931 <span>To view this page, a database update is required. Please click the button below to run the 932 update.</span> 933 <?php } else { ?> 934 To view this page, minimum required version of PHP is 8.0 935 <br>Your site is currently running on PHP version - <span class="es-text-danger"><?= phpversion(); ?></span> 936 <br>Upgrade your PHP version to experience the latest features. 937 <?php } ?> 938 </p> 939 <p class="es-text-primary"><b>Don't worry if you are not able to view this page properly, this does NOT affect any 940 eShipper services on your store!</b></p> 941 942 <?php if ($validPhpVersion) { ?> 943 <button class='es-button es-button-primary' id="es-plugin-health-db-update">Update Database</button> 944 <p class="es-d-none" id="es-plugin-health-db-update-message"></p> 945 <?php } ?> 946 947 </div> 948 </div> 949 </div> 950 <?php } else { 951 // If table exists, then show the plugin health page. 952 // (dev note: closing tag for else is below the following div) 953 ?> 954 955 <div class="es-row"> 956 <div class="es-col es_health_font_size"> 957 958 <div class="es_health_check_chart"> 959 <div class="flex-wrapper"> 960 <div class="single-chart"> 961 <svg viewBox="0 0 36 36" class="circular-chart blue" id="health-chart"> 962 <path class="circle-bg" 963 d="M18 2.0845 896 964 a 15.9155 15.9155 0 0 1 0 31.831 897 965 a 15.9155 15.9155 0 0 1 0 -31.831" 898 />899 <path class="circle"900 stroke-dasharray="<?php echo $pluginHealth['percentage_health'] ?>, 100"901 d="M18 2.0845966 /> 967 <path class="circle" 968 stroke-dasharray="<?php echo $pluginHealth['percentage_health'] ?>, 100" 969 d="M18 2.0845 902 970 a 15.9155 15.9155 0 0 1 0 31.831 903 971 a 15.9155 15.9155 0 0 1 0 -31.831" 904 /> 905 <text x="18" y="20.35" class="percentage"><?php echo $pluginHealth['percentage_health'] . '%' ?></text> 906 </svg> 972 /> 973 <text x="18" y="20.35" class="percentage"><?php echo $pluginHealth['percentage_health'] . '%' ?></text> 974 </svg> 975 </div> 907 976 </div> 908 977 </div> 978 979 <div class="es-row"> 980 <div class="es-col"> 981 <h3>eShipper Plugin Status: <span id="plugin-stats-status"><?php echo $pluginHealth['status']; ?></span> 982 </h3> 983 984 <p> 985 <b>Issues found: </b> <span id="plugin-stats-issue-count"><?php echo $pluginHealth['issue_count'] ?></span> 986 </p> 987 988 <p> 989 <b>Last updated at: </b> <span 990 id="plugin-stats-updated-time"><?php echo $pluginHealth['updated_time']; ?></span> 991 </p> 992 </div> 993 <div class="es-col"> 994 <button class='es-button es-button-primary' onclick="window.location.reload();">Recheck</button> 995 </div> 996 </div> 997 998 <?php if (!empty($pluginHealth['notice'])) { ?> 999 <div class="es-box es-box-danger" id="health-action-notice"> 1000 <p> 1001 <span class="es-text-danger es-text-bold">Action Required: </span> 1002 <span id="health-action-message"><?php echo $pluginHealth['notice']; ?></span> 1003 </p> 1004 </div> 1005 <?php } ?> 1006 <div class="es-box es-box-success" style="display: none;" id="fix-success-message"></div> 909 1007 </div> 910 1008 911 <div class="es-row"> 912 <div class="es-col"> 913 <h3>eShipper Plugin Status: <span id="plugin-stats-status"><?php echo $pluginHealth['status']; ?></span> 914 </h3> 915 916 <p> 917 <b>Issues found: </b> <span id="plugin-stats-issue-count"><?php echo $pluginHealth['issue_count'] ?></span> 918 </p> 919 920 <p> 921 <b>Last updated at: </b> <span id="plugin-stats-updated-time"><?php echo $pluginHealth['updated_time']; ?></span> 922 </p> 923 </div> 924 <div class="es-col"> 925 <button class='es-button es-button-primary' onclick="window.location.reload();">Recheck</button> 926 </div> 927 </div> 928 929 <?php if (!empty($pluginHealth['notice'])) { ?> 930 <div class="es-box es-box-danger" id="health-action-notice"> 931 <p> 932 <span class="es-text-danger es-text-bold">Action Required: </span> 933 <span id="health-action-message"><?php echo $pluginHealth['notice']; ?></span> 934 </p> 935 </div> 936 <?php } ?> 937 <div class="es-box es-box-success" style="display: none;" id="fix-success-message"></div> 938 </div> 939 940 <div class="es-col"> 941 <table class="es_health_table"> 942 <thead> 943 <tr> 944 <th colspan="2">Health Check</th> 945 <th style="text-align: center">Status</th> 946 <th style="text-align: center">Action</th> 947 </tr> 948 </thead> 949 <tbody> 950 <?php 951 $validAuth = $pluginHealth['items'][PluginHealthHelper::ATTR_AUTH]; 952 foreach ($pluginHealth['items'] as $item => $health) { 953 $name = PluginHealthHelper::getDisplayName($item); 954 955 // Insert trigger for auth dialog (this will only be done for auth FIX button) 956 $auth = $item === PluginHealthHelper::ATTR_AUTH && !$validAuth ? "onclick='show_login_popup()'" : ""; 957 958 // When Auth is NOT working, all other buttons except FIX button for Auth, will be disabled. 959 $disabled = $item !== PluginHealthHelper::ATTR_AUTH && !$validAuth ? "disabled title='Please fix Authentication!'" : ""; 960 961 $loaderUrl = ESHIPPER_PLUGIN_URL . '/img/preloader.gif'; 962 $loader = "<div class='fix-loader-icon es-d-none' id='$item-fix-loader'> 1009 <div class="es-col"> 1010 <table class="es_health_table"> 1011 <thead> 1012 <tr> 1013 <th colspan="2">Health Check</th> 1014 <th style="text-align: center">Status</th> 1015 <th style="text-align: center">Action</th> 1016 </tr> 1017 </thead> 1018 <tbody> 1019 <?php 1020 $validAuth = $pluginHealth['items'][PluginHealthHelper::ATTR_AUTH]; 1021 foreach ($pluginHealth['items'] as $item => $health) { 1022 $name = PluginHealthHelper::getDisplayName($item); 1023 1024 // Insert trigger for auth dialog (this will only be done for auth FIX button) 1025 $auth = $item === PluginHealthHelper::ATTR_AUTH && !$validAuth ? "onclick='show_login_popup()'" : ""; 1026 1027 // When Auth is NOT working, all other buttons except FIX button for Auth, will be disabled. 1028 $disabled = $item !== PluginHealthHelper::ATTR_AUTH && !$validAuth ? "disabled title='Please fix Authentication!'" : ""; 1029 1030 $loaderUrl = ESHIPPER_PLUGIN_URL . '/img/preloader.gif'; 1031 $loader = "<div class='fix-loader-icon es-d-none' id='$item-fix-loader'> 963 1032 <img src='$loaderUrl' alt='Please wait...'> 964 1033 </div>"; 965 1034 966 // Health item status is OK967 if ($health) {968 $icon = "<span class='es-text-success' id='$item-status'>OK</span>";969 // If these items are OK, no action is required970 if ($item === PluginHealthHelper::ATTR_AUTH) {971 $action = "";972 } else {973 $action = "<button class='es-button es-button-primary fix-health-btn' $disabled $auth data-issue='$item' data-type='verify'>1035 // Health item status is OK 1036 if ($health) { 1037 $icon = "<span class='es-text-success' id='$item-status'>OK</span>"; 1038 // If these items are OK, no action is required 1039 if ($item === PluginHealthHelper::ATTR_AUTH) { 1040 $action = ""; 1041 } else { 1042 $action = "<button class='es-button es-button-primary fix-health-btn' $disabled $auth data-issue='$item' data-type='verify'> 974 1043 <span class='btn-text'>Verify</span> 975 1044 $loader 976 1045 </button>"; 977 }978 } else {979 $icon = "<span class='es-text-danger' id='$item-status'>X</span>";980 981 // If these items are NOT OK, only re-install can fix the problem, hence just display 'Re-install'982 if ($item === PluginHealthHelper::ATTR_BACKEND_SYNC) {983 if (!$validAuth) {984 $action = "";985 } else {986 $action = "Re-install";987 }988 } else {989 $action = "<button class='es-button es-button-danger fix-health-btn' $disabled $auth data-issue='$item' data-type='fix'>1046 } 1047 } else { 1048 $icon = "<span class='es-text-danger' id='$item-status'>X</span>"; 1049 1050 // If these items are NOT OK, only re-install can fix the problem, hence just display 'Re-install' 1051 if ($item === PluginHealthHelper::ATTR_BACKEND_SYNC) { 1052 if (!$validAuth) { 1053 $action = ""; 1054 } else { 1055 $action = "Re-install"; 1056 } 1057 } else { 1058 $action = "<button class='es-button es-button-danger fix-health-btn' $disabled $auth data-issue='$item' data-type='fix'> 990 1059 <span class='btn-text'>Fix</span> 991 1060 $loader 992 1061 </button>"; 993 }994 }995 996 echo "1062 } 1063 } 1064 1065 echo " 997 1066 <tr> 998 1067 <td colspan='2'>$name</td> … … 1001 1070 </tr> 1002 1071 "; 1003 } 1004 ?> 1005 </tbody> 1006 </table> 1072 } 1073 ?> 1074 </tbody> 1075 </table> 1076 </div> 1077 </div> 1078 1079 <?php } ?> 1080 1081 <div class="es-row" style="margin-top: 50px"> 1082 <div class="es-col"> 1083 <hr> 1084 <p> 1085 <small> 1086 * This page is only a visual representation of the eShipper plugin's health and is only meant for reporting purposes. 1087 <b> * If you are not able to view this page, it does NOT affect any eShipper services on your store.</b> * 1088 To view this page, minimum required PHP 1089 version is 8.0 1090 </small> 1091 </p> 1007 1092 </div> 1008 1093 </div> 1009 1010 1094 </div> 1011 1095 -
eshipper-commerce/trunk/plugin/PluginHealthHelper.php
r2921864 r2943682 46 46 public static function createEshipperPluginHealthTable() 47 47 { 48 global $wpdb;49 48 $table = self::getPluginHealthTableName(); 50 49 50 // TODO: This will be removed in the upcoming versions since this is not required because dbDelta() takes care of this action. 51 51 // Drop table if already exists 52 if ($wpdb->get_var("SHOW TABLES LIKE '$table'") === $table) {53 $wpdb->query("DROP TABLE $table");54 }52 // if ($wpdb->get_var("SHOW TABLES LIKE '$table'") === $table) { 53 // $wpdb->query("DROP TABLE $table"); 54 // } 55 55 56 56 $columns = ''; 57 foreach (self::getEnabledAttributes() as $attribute) { 58 $columns .= $attribute . ' tinyint(1) DEFAULT 0,'; 59 } 60 61 $create_plugin_health_table = " CREATE TABLE $table( 57 foreach (self::getEnabledAttributes() as $index => $attribute) { 58 // Add a new line for every column (as per wordpress doc here: https://codex.wordpress.org/Creating_Tables_with_Plugins#Creating_or_Updating_the_Table) 59 // DO NOT REMOVE the formatting below: 60 $columns .= ' 61 ' . $attribute . ' tinyint(1) DEFAULT 0,'; 62 } 63 64 $create_plugin_health_table = "CREATE TABLE $table( 62 65 $columns 63 66 created_time timestamp DEFAULT CURRENT_TIMESTAMP, … … 131 134 132 135 /** 133 * @return array 136 * @return array|null 134 137 */ 135 138 public static function getPluginHealth($asyncRequest = false) … … 137 140 // Get the table name 138 141 global $wpdb; 139 $table = self::getPluginHealthTableName(); 142 143 // This also checks and creates the table if it doesn't exist in the db 144 $table = self::getPluginHealthTableName(true); 140 145 141 146 // First update the plugin health … … 148 153 // Get the items & their respective status from health table 149 154 $healthItems = $wpdb->get_row("SELECT * from $table", ARRAY_A); 155 156 // If there are no items populated in the db, return null 157 if (empty($healthItems)) { 158 return null; 159 } 150 160 151 161 // Filter out items to be displayed … … 276 286 $domainUrl = $wpdb->get_var("SELECT domain_url FROM {$wpdb->prefix}eshipper_access_tokens WHERE currently_active = 1"); 277 287 288 // If domain is empty, no further action - mark auth as false 289 // if (empty($domainUrl)) { 290 // return self::recordAuthStatus(false); 291 // } 292 293 // Check in real time if store is connected: Upcoming version 294 // $storeConnected = eshipperCalls::checkIfStoreIsConnected($domainUrl); 295 278 296 return self::recordAuthStatus(!empty($domainUrl)); 279 297 } … … 508 526 509 527 /** 510 * @return string 511 */ 512 private static function getPluginHealthTableName() 513 { 514 global $wpdb; 515 516 return $wpdb->prefix . self::TABLE_NAME; 528 * @param $createTableIfDoesntExist 529 * @return string|null 530 */ 531 private static function getPluginHealthTableName(bool $createTableIfDoesntExist = false) 532 { 533 global $wpdb; 534 535 $table = $wpdb->prefix . self::TABLE_NAME; 536 537 // Check if the plugin health table exists and create if it doesn't 538 if ($createTableIfDoesntExist && $wpdb->get_var("SHOW TABLES LIKE '$table'") !== $table) { 539 self::createEshipperPluginHealthTable(); 540 } 541 542 return $table; 517 543 } 518 544 } -
eshipper-commerce/trunk/plugin/eshipperCalls.php
r2921864 r2943682 205 205 206 206 $httpResponseCode = $response['httpResponseCode']; 207 $error_message = $response['response']->errors;207 $error_message = isset($response['response']->errors) ? $response['response']->errors : 'Something went wrong! Please contact support.'; 208 208 209 209 //if the response code is 200 then create tables and what not … … 233 233 return $responseArray; 234 234 } 235 236 /** 237 * Check if store is connected by invoking eShipper API 238 * @param $domainUrl 239 * @return bool 240 */ 241 public static function checkIfStoreIsConnected($domainUrl) 242 { 243 // Get the store domain name 244 $shopName = trim(str_replace('/shop', '', get_site_url())); 245 $shopName = rtrim(preg_replace("#^[^:/.]*[:/]+#i", "", $shopName), '/'); 246 247 // Call the eShipper API to check if this store is installed 248 $response = (new curlHandler())->sendCurlRequest( 249 json_encode(['shop' => $shopName]), 250 "$domainUrl/ecommerce/woocommerce/is-store-installed", 251 'POST', 252 [ 253 'Accept: application/json', 254 'Content-Type: application/json', 255 ] 256 ); 257 258 // If the response is 200 then return true 259 if (!empty($response['response']) && !empty($httpResponseCode = $response['httpResponseCode']) && $httpResponseCode === 200) { 260 return true; 261 } 262 263 // If response is not 200 return false 264 return false; 265 } 235 266 } -
eshipper-commerce/trunk/plugin/pluginLifeCycle.php
r2923508 r2943682 146 146 147 147 // Drop table if already exists 148 if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_boxing_services_master'") === $eshipper_boxing_services_master) {149 $wpdb->query("DROP TABLE $eshipper_boxing_services_master");150 }148 // if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_boxing_services_master'") === $eshipper_boxing_services_master) { 149 // $wpdb->query("DROP TABLE $eshipper_boxing_services_master"); 150 // } 151 151 152 152 $create_boxing_master_table_query = " CREATE TABLE $eshipper_boxing_services_master( … … 171 171 private static function createEshipperAccessTokensTable() 172 172 { 173 wc_get_logger()->debug('Attempting to create table - eshipper_access_tokens', ['source' => 'eshipper']); 174 173 175 global $wpdb; 174 176 $eshipper_access_tokens = $wpdb->prefix . "eshipper_access_tokens"; 175 177 176 178 // Drop table if already exists 177 if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_access_tokens'") === $eshipper_access_tokens) { 178 $wpdb->query("DROP TABLE $eshipper_access_tokens"); 179 } 179 // Not required - dbDelta() takes care of that 180 // if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_access_tokens'") === $eshipper_access_tokens) { 181 // $wpdb->query("DROP TABLE $eshipper_access_tokens"); 182 // } 180 183 181 184 $access_tokens_query = " CREATE TABLE $eshipper_access_tokens( … … 192 195 require_once(ABSPATH . "wp-admin/includes/upgrade.php"); 193 196 dbDelta($access_tokens_query); 197 198 wc_get_logger()->debug('Successfully to create table - eshipper_access_tokens', ['source' => 'eshipper']); 194 199 } 195 200 … … 201 206 private static function createEshipperCarrierServicesTable() 202 207 { 208 wc_get_logger()->debug('Attempting to create table - eshipper_carrier_service_master', ['source' => 'eshipper']); 209 203 210 global $wpdb; 204 211 $eshipper_carrier_services = $wpdb->prefix . "eshipper_carrier_service_master"; 205 212 206 213 // Drop table if already exists 207 if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_carrier_services'") === $eshipper_carrier_services) {208 $wpdb->query("DROP TABLE $eshipper_carrier_services");209 }214 // if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_carrier_services'") === $eshipper_carrier_services) { 215 // $wpdb->query("DROP TABLE $eshipper_carrier_services"); 216 // } 210 217 211 218 $access_tokens_query = " CREATE TABLE $eshipper_carrier_services( … … 259 266 $status = PluginHealthHelper::recordAuthStatus(true); 260 267 } catch (Exception $exception) { 261 wc_get_logger()-> debug(268 wc_get_logger()->error( 262 269 'Error while storing eshipper access token in DB - [ERROR] - ' . print_r($exception->getMessage(), true), 263 270 ['source' => 'eshipper'] … … 297 304 $status = PluginHealthHelper::recordStoreAddressStatus(true); 298 305 } catch (Exception $exception) { 299 wc_get_logger()-> debug(306 wc_get_logger()->error( 300 307 'Error while copying store address from woocommerce - [ERROR] - ' . print_r($exception->getMessage(), true), 301 308 ['source' => 'eshipper'] … … 434 441 $status = PluginHealthHelper::recordWebhooksStatus(true); 435 442 } catch (Exception $exception) { 436 wc_get_logger()-> debug('Error while creating webhooks. - [ERROR] - ' . print_r($exception->getMessage(), true), ['source' => 'eshipper']);443 wc_get_logger()->error('Error while creating webhooks. - [ERROR] - ' . print_r($exception->getMessage(), true), ['source' => 'eshipper']); 437 444 438 445 $status = PluginHealthHelper::recordWebhooksStatus(false); … … 485 492 * Function to create table in Woo-Commerce DB to store the Shipping Address 486 493 */ 487 p rivatestatic function createEshipperShippingAddressTable()494 public static function createEshipperShippingAddressTable() 488 495 { 489 496 global $wpdb; … … 491 498 492 499 // Drop table if already exists 493 if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_shipping_address'") === $eshipper_shipping_address) {494 $wpdb->query("DROP TABLE $eshipper_shipping_address");495 }500 // if ($wpdb->get_var("SHOW TABLES LIKE '$eshipper_shipping_address'") === $eshipper_shipping_address) { 501 // $wpdb->query("DROP TABLE $eshipper_shipping_address"); 502 // } 496 503 497 504 $create_shipping_address_query = " CREATE TABLE $eshipper_shipping_address( … … 505 512 zipcode varchar(255) , 506 513 shipping_name text , 507 phone_no int(14) ,514 phone_no varchar(20) , 508 515 email_id varchar (255), 509 516 created_time timestamp DEFAULT CURRENT_TIMESTAMP, … … 560 567 $status = PluginHealthHelper::recordCarrierServicesStatus(true); 561 568 } catch (Exception $exception) { 562 wc_get_logger()-> debug(569 wc_get_logger()->error( 563 570 'Error while adding eshipper carrier services - [ERROR] - ' . print_r($exception->getMessage(), true), 564 571 ['source' => 'eshipper'] -
eshipper-commerce/trunk/readme.txt
r2923520 r2943682 5 5 Tested up to: 6.2.2 6 6 Requires PHP: 7.1 7 Stable tag: 2.15. 27 Stable tag: 2.15.3 8 8 License: GPLv3 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 54 54 55 55 == Changelog == 56 = 2.15.3 = 57 * Critical Bug Fixes for versions 2.14.3 & v2.15.2 58 56 59 = 2.15.2 = 57 60 * Critical bug fixes & better user experience … … 82 85 83 86 == Upgrade Notice == 87 = 2.15.3 = 88 Upgrade to receive critical bug fixes NOW! 89 84 90 = 2.15.2 = 85 91 Recommended upgrade for critical bug fixes in versions 2.15 & 2.15.1 -
eshipper-commerce/trunk/views/login_thickbox.php
r2921864 r2943682 91 91 <div class="col-75"> 92 92 <input class="es_input_class" type="text" id="domain_url" name="domain_url" placeholder="https://domain_name.com" value="https://ww2.eshipper.com"> 93 <small>This should be a valid eShipper domain.</small> 93 94 </div> 94 95 </div> … … 99 100 <div class="col-75"> 100 101 <input class="es_input_class" type="text" id="username" name="username" placeholder="Username"> 102 <small>Enter your eShipper username to connect the plugin to eShipper services.</small> 101 103 </div> 102 104 </div> … … 109 111 <input type="hidden" name="grant_type" value="password"> 110 112 <input type="hidden" name="client_id" value="web_app"> 113 <small>Enter your eShipper password to connect the plugin to eShipper services.</small> 111 114 </div> 112 115 </div> -
eshipper-commerce/trunk/woocommerce-eshipper.php
r2923508 r2943682 4 4 Plugin URI: https://ww2.eshipper.com/ecommerce/ 5 5 Description: Extends WooCommerce with Shipping Rates from eShipper 6 Version: 2.15. 26 Version: 2.15.3 7 7 Author: eShipper 8 8 Author URI: https://ww2.eshipper.com/ … … 29 29 ))) { 30 30 define('ESHIPPER_VERSION', '1.4.1'); 31 define('ESHIPPER_VERSION_ 2_15', '2.15.2');31 define('ESHIPPER_VERSION_LATEST', '2.15.3'); 32 32 //Plugin Path 33 33 define('ESHIPPER_PLUGIN_PATH', dirname(__FILE__)); … … 154 154 add_action('wp_ajax_boxing_insert', 'boxing_insert'); 155 155 add_action('wp_ajax_fix_eshipper_plugin', 'fix_eshipper_plugin'); 156 add_action('wp_ajax_plugin_health_db_update', 'plugin_health_db_update'); 156 157 157 158 function fix_eshipper_plugin() … … 254 255 } 255 256 257 function plugin_health_db_update() 258 { 259 $update = false; 260 try { 261 // Log the activity 262 wc_get_logger()->debug('Attempting to create plugin health table', ['source' => 'eshipper']); 263 264 // Attempt to create plugin health table 265 $update = PluginHealthHelper::createEshipperPluginHealthTable(); 266 } catch (Exception $e) { 267 wc_get_logger()->error( 268 'ERROR creating plugin health table: [CODE]: ' . $e->getCode() . ' [ERROR] - ' . print_r($e->getMessage(), true), 269 ['source' => 'eshipper'] 270 ); 271 } 272 273 if ($update) { 274 $statusCode = 200; 275 $msg = 'Database Update is successful!'; 276 277 wc_get_logger()->debug('Successfully created plugin health table.', ['source' => 'eshipper']); 278 279 // Validate Plugin health to populate current state of the plugin 280 PluginHealthHelper::validatePluginHealth(); 281 } else { 282 $statusCode = 412; 283 $msg = 'Could not update database, something went wrong while processing your request. Please contact support to fix the issue.'; 284 285 wc_get_logger()->error('Failed to create plugin health table.', ['source' => 'eshipper']); 286 } 287 288 $result = [ 289 'statusCode' => $statusCode, 290 'msg' => $msg, 291 ]; 292 293 // Return Error Response 294 echo json_encode($result); 295 die(); 296 } 297 256 298 function eshipper_health_check_admin_notice() 257 299 { … … 329 371 'methods' => 'DELETE', 330 372 'callback' => 'uninstallEshipperPlugin', 373 'permission_callback' => '__return_true', 331 374 ]); 332 375 }); … … 334 377 function uninstallEshipperPlugin($request) 335 378 { 379 wc_get_logger()->debug('Attempting to deactivate eShipper plugin. Store was detached from eShipper', ['source' => 'eshipper']); 336 380 $all_headers = $request->get_headers(); 337 381 … … 340 384 $responseArray = ['statusCode' => "401", "msg" => "Sorry, you are not authorized to do this event"]; 341 385 386 wc_get_logger()->error('Failed to deactivate eShipper plugin', ['source' => 'eshipper']); 387 342 388 return new WP_REST_Response($responseArray, 401); 343 389 } 344 390 345 $plugin = 'eShipper-plugin/woocommerce-eshipper.php'; 346 deactivate_plugins($plugin); 347 $responseArray = ['statusCode' => "200", "msg" => "eShipper plugin uninstalled successfully"]; 348 349 return new WP_REST_Response($responseArray, 200); 391 // Deactivate the plugin 392 require_once(ABSPATH . 'wp-admin/includes/plugin.php'); 393 deactivate_plugins(ESHIPPER_PLUGIN_PATH); 394 395 // If the plugin is still active at this point then return error 396 if (is_plugin_active(plugin_basename(ESHIPPER_PLUGIN_FILE))) { 397 wc_get_logger()->error('Failed to deactivate eShipper plugin. Please deactivate the plugin directly from your store.', ['source' => 'eshipper']); 398 399 $responseArray = [ 400 'statusCode' => "412", 401 "msg" => "Failed to deactivate eShipper plugin. Please deactivate the plugin directly from your store.", 402 ]; 403 return new WP_REST_Response($responseArray, 412); 404 } else { 405 wc_get_logger()->debug('eShipper plugin deactivated successfully. Good bye!', ['source' => 'eshipper']); 406 407 $responseArray = [ 408 'statusCode' => "200", 409 "msg" => "eShipper plugin deactivated successfully!", 410 ]; 411 return new WP_REST_Response($responseArray, 200); 412 } 350 413 } 351 414 … … 582 645 $validateParameters = 1; 583 646 $requestData = []; 647 $msg = ''; 584 648 if (isset($_POST['formdata']) && is_array($_POST['formdata'])) { 585 649 foreach ($_POST['formdata'] as $k => $formdata) { … … 589 653 break; 590 654 } 655 656 // Validate eShipper's domain (this check is also applied in js hence the code below is a fail safe) 657 if ($formdata['name'] === 'domain_url' && !str_contains($formdata['value'], 'eshipper.com')) { 658 $validateParameters = 0; 659 $msg = 'Invalid Domain URL. Please enter the correct eshipper domain'; 660 break; 661 } 662 591 663 $key = $formdata['name']; 592 664 $val = $formdata['value']; … … 599 671 echo json_encode([ 600 672 'statusCode' => 412, 601 'msg' => 'The credentials you entered are incorrect. Please provide correct data.',673 'msg' => $msg ?? 'The credentials you entered are incorrect. Please provide correct data.', 602 674 ]); 603 675 die();
Note: See TracChangeset
for help on using the changeset viewer.