forked from AyeCode/geodirectory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade.php
285 lines (250 loc) · 6.73 KB
/
upgrade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<?php
/**
* Upgrade related functions.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
global $wpdb;
if ( get_option( 'geodirectory_db_version' ) !== GEODIRECTORY_VERSION ) {
/**
* Include custom database table related functions.
*
* @since 1.0.0
* @package GeoDirectory
*/
add_action( 'plugins_loaded', 'geodir_upgrade_all', 10 );
add_action( 'init', 'geodir_fix_cpt_rewrite_slug', 11 );// this needs to be kept for a few versions.
}
/**
* Handles upgrade for all geodirectory versions.
*
* @since 1.0.0
* @package GeoDirectory
*/
function geodir_upgrade_all() {
}
/**
* Handles upgrade for all geodirectory versions.
*
* @since 2.0.0
* @package GeoDirectory
*/
function geodir_upgrade_200() {
}
/**
* Converts all GD CPT's to the new rewrite slug by removing /%gd_taxonomy% from the slug
*
* @since 1.5.0
* @package GeoDirectory
*/
function geodir_fix_cpt_rewrite_slug() {
// flush the rewrite rules.
flush_rewrite_rules();
}
/**
* Update DB Version.
*/
function geodir_upgrade_20013() {
global $wpdb;
$wpdb->query( 'UPDATE ' . GEODIR_ATTACHMENT_TABLE . " SET type='post_images' WHERE type='post_image'" );
}
function geodir_update_200_settings() {
GeoDir_Admin_Upgrade::update_200_settings();
}
function geodir_update_200_fields() {
GeoDir_Admin_Upgrade::update_200_fields();
}
function geodir_update_200_terms() {
GeoDir_Admin_Upgrade::update_200_terms();
}
function geodir_update_200_posts() {
GeoDir_Admin_Upgrade::update_200_posts();
}
function geodir_update_200_merge_data() {
GeoDir_Admin_Upgrade::update_200_merge_data();
}
function geodir_update_200_db_version() {
GeoDir_Admin_Upgrade::update_200_db_version();
}
/**
* Layout grid view 1 added which replaces layout=1 so we change current layout=1 to layout=0 (back to list view)
*/
function geodir_upgrade_20060() {
// Archive page
$archive_page_id = geodir_archive_page_id();
if ( $archive_page_id ) {
$archive_page_content = get_post_field( 'post_content', $archive_page_id );
if ( strpos( $archive_page_content, '[gd_loop layout=1]' ) !== false ) {
$my_post = array(
'ID' => $archive_page_id,
'post_content' => str_replace( '[gd_loop layout=1]', '[gd_loop layout=0]', $archive_page_content ),
);
wp_update_post( $my_post );
}
}
// Search page
$search_page_id = geodir_search_page_id();
if ( $search_page_id ) {
$search_page_content = get_post_field( 'post_content', $search_page_id );
if ( strpos( $search_page_content, '[gd_loop layout=1]' ) !== false ) {
$my_post = array(
'ID' => $search_page_id,
'post_content' => str_replace( '[gd_loop layout=1]', '[gd_loop layout=0]', $search_page_content ),
);
wp_update_post( $my_post );
}
}
}
/**
* Change country name Russian Federation to Russia.
*/
function geodir_upgrade_20064() {
global $wpdb;
$post_types = geodir_get_posttypes();
$search_country = 'Russian Federation';
$replace_country = 'Russia';
$search_country_slug = 'russian-federation';
$replace_country_slug = 'russia';
// Default Country
$default_country = geodir_get_option( 'default_location_country' );
if ( $default_country == $search_country ) {
geodir_update_option( 'default_location_country', $replace_country );
}
// Details
if ( ! empty( $post_types ) ) {
foreach ( $post_types as $post_type ) {
$table = geodir_db_cpt_table( $post_type );
if ( ! GeoDir_Post_types::supports( $post_type, 'location' ) ) {
continue;
}
$wpdb->query(
$wpdb->prepare(
"UPDATE {$table} SET country = %s WHERE country LIKE %s",
array(
$replace_country,
$search_country,
)
)
);
}
}
// Reviews
$wpdb->query(
$wpdb->prepare(
'UPDATE ' . GEODIR_REVIEW_TABLE . ' SET country = %s WHERE country LIKE %s',
array(
$replace_country,
$search_country,
)
)
);
if ( class_exists( 'GeoDir_Location' ) ) {
// Locations
$wpdb->query(
$wpdb->prepare(
'UPDATE ' . GEODIR_LOCATIONS_TABLE . ' SET country = %s WHERE country LIKE %s',
array(
$replace_country,
$search_country,
)
)
);
$wpdb->query(
$wpdb->prepare(
'UPDATE ' . GEODIR_LOCATIONS_TABLE . ' SET country_slug = %s WHERE country_slug LIKE %s',
array(
$replace_country_slug,
$search_country_slug,
)
)
);
// Location SEO
$wpdb->query(
$wpdb->prepare(
'UPDATE ' . GEODIR_LOCATION_SEO_TABLE . ' SET country_slug = %s WHERE country_slug LIKE %s',
array(
$replace_country_slug,
$search_country_slug,
)
)
);
// Location Term Meta
$wpdb->query(
$wpdb->prepare(
'UPDATE ' . GEODIR_LOCATION_TERM_META . ' SET country_slug = %s WHERE country_slug LIKE %s',
array(
$replace_country_slug,
$search_country_slug,
)
)
);
$wpdb->query(
$wpdb->prepare(
'UPDATE ' . GEODIR_LOCATION_TERM_META . ' SET location_name = %s WHERE location_name LIKE %s',
array(
$replace_country_slug,
$search_country_slug,
)
)
);
}
}
/**
* Update for 2.0.0.82
*
* @since 2.0.0.82
*
* @return void
*/
function geodir_upgrade_20082() {
// Generate title keywords.
geodir_generate_title_keywords();
}
/**
* Update for 2.0.0.96
*
* @since 2.0.0.96
*
* @return void
*/
function geodir_upgrade_20096() {
global $wpdb;
// Add columns in business hours table.
$table = $wpdb->prefix . 'geodir_business_hours';
if ( $wpdb->get_var( "SHOW TABLES LIKE '{$table}'" ) && ! geodir_column_exist( $table, 'open_utc' ) ) {
$wpdb->query(
"ALTER TABLE `{$table}`
ADD open_utc int(9) UNSIGNED NOT NULL,
ADD close_utc int(9) UNSIGNED NOT NULL,
ADD open_dst int(9) UNSIGNED NOT NULL,
ADD close_dst int(9) UNSIGNED NOT NULL,
ADD timezone_string varchar(100) NOT NULL,
ADD has_dst tinyint(1) NOT NULL DEFAULT '0',
ADD is_dst tinyint(1) NOT NULL DEFAULT '0'"
);
}
// Update timezone to timezone string.
if ( ! geodir_get_option( 'default_location_timezone_string' ) ) {
$country = geodir_get_option( 'default_location_country' );
$timezone = geodir_get_option( 'default_location_timezone' );
$timezone_string = geodir_offset_to_timezone_string( $timezone, $country );
geodir_update_option( 'default_location_timezone_string', $timezone_string );
}
}
/**
* Update for 2.1.0.16
*
* @since 2.1.0.16
*
* @return void
*/
function geodir_upgrade_21016() {
// Disable beta addons setting.
geodir_update_option( 'admin_enable_beta', '' );
}