Changeset 3387916
- Timestamp:
- 11/01/2025 05:39:03 AM (4 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
shipping-rate-by-cities/trunk/shipping_rate_by_cities.php
r3368394 r3387916 106 106 } 107 107 } 108 109 110 /** 111 * Return the full table name for the shiprate_cities table using the active WP DB prefix. 112 * 113 * The function will: 114 * - Prefer an exact match for {$wpdb->prefix}shiprate_cities if it exists. 115 * - Otherwise search all tables for a name that ends with '_shiprate_cities' and return the first match. 116 * - If nothing is found, return {$wpdb->prefix}shiprate_cities (safe fallback). 117 * 118 * @return string Full table name (with prefix). Example: wp_shiprate_cities or wp_2_shiprate_cities 119 */ 120 function shiprate_get_table_name() { 121 global $wpdb; 122 123 // canonical candidate using current prefix 124 $candidate = $wpdb->prefix . 'shiprate_cities'; 125 126 // quick check for exact table (prepared to avoid SQL injection) 127 $found = $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $candidate ) ); 128 if ( $found ) { 129 return $candidate; 130 } 131 132 // Try a more permissive search: find any table that ends with '_shiprate_cities' 133 // This handles multisite/site-specific prefixes like 'wp_2_' 134 $like = '%' . $wpdb->esc_like( 'shiprate_cities' ); 135 $matches = $wpdb->get_col( $wpdb->prepare( "SHOW TABLES LIKE %s", $like ) ); 136 137 if ( ! empty( $matches ) ) { 138 // Return first match (should be the intended table) 139 return $matches[0]; 140 } 141 142 // Fallback: return candidate even if it doesn't exist (safe default) 143 return $candidate; 144 } 145 146 108 147 109 148 // In your main plugin file (shipping-rate-cities.php)
Note: See TracChangeset
for help on using the changeset viewer.