-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathupgrade.php
206 lines (181 loc) · 5.98 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
<?php
/**
* XML Sitemap Feed upgrade routines
*
* @package XML Sitemap & Google News
*
* @since 5.1
*/
defined( 'WPINC' ) || die;
if ( $db_version ) {
xmlsf_upgrade( $db_version );
} else {
xmlsf_install();
}
update_option( 'xmlsf_version', XMLSF_VERSION );
// Flush rewrite rules on next init.
delete_option( 'rewrite_rules' );
/**
* Update from defaults.
*
* @since 5.1
*
* @param bool $update Wether to add or update options.
*/
function xmlsf_update_from_defaults( $update = true ) {
// Options that need not be autoloaded.
$not_autoload = array( 'robots' );
foreach ( xmlsf()->defaults() as $option => $default ) {
if ( $update ) {
update_option( 'xmlsf_' . $option, $default, '', ! in_array( $option, $not_autoload, true ) );
} else {
add_option( 'xmlsf_' . $option, $default, '', ! in_array( $option, $not_autoload, true ) );
}
}
}
/**
* Set up default plugin data.
*
* @since 5.1
*/
function xmlsf_install() {
// Add or update all defaults.
xmlsf_update_from_defaults();
do_action( 'xmlsf_install' );
}
/**
* Upgrade plugin data.
*
* @param int $db_version Database version.
* @since 5.1
*/
function xmlsf_upgrade( $db_version ) {
global $wpdb;
if ( version_compare( '4.4', $db_version, '>' ) ) {
// Remove robots.txt rules blocking stylesheets.
$robot_rules = get_option( 'xmlsf_robots' );
if ( ! empty( $robot_rules ) ) {
$robot_rules = str_replace( array( 'Disallow: */wp-content/', 'Allow: */wp-content/uploads/' ), '', $robot_rules );
delete_option( 'xmlsf_robots' );
add_option( 'xmlsf_robots', $robot_rules, '', false );
}
// Make sure custom sitemaps is an array.
$urls = get_option( 'xmlsf_custom_sitemaps' );
if ( ! is_array( $urls ) ) {
$urls = explode( PHP_EOL, $urls );
update_option( 'xmlsf_custom_sitemaps', $urls );
}
// Register location taxonomies then delete all terms.
$taxonomies = array( 'gn-location-3', 'gn-location-2', 'gn-location-1' );
foreach ( $taxonomies as $taxonomy ) {
register_taxonomy( $taxonomy, null );
$terms = get_terms(
array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
)
);
foreach ( (array) $terms as $term ) {
wp_delete_term( $term->term_id, 'gn-location-3' );
}
}
}
if ( version_compare( '5.0.1', $db_version, '>' ) ) {
// Delete all taxonomy terms.
register_taxonomy( 'gn-genre', null );
$terms = get_terms(
array(
'taxonomy' => 'gn-genre',
'hide_empty' => false,
)
);
foreach ( (array) $terms as $term ) {
wp_delete_term( $term->term_id, 'gn-genre' );
}
// New taxonomy settings.
$taxonomies = get_option( 'xmlsf_taxonomies' );
if ( empty( $taxonomies ) ) {
$active = '';
} else {
$available = 0;
$checked = count( $taxonomies );
foreach ( (array) get_option( 'xmlsf_post_types' ) as $post_type => $settings ) {
if ( empty( $settings['active'] ) ) {
continue;
}
$taxonomies = get_object_taxonomies( $post_type, 'objects' );
// Check each tax public flag and term count and append name to array.
foreach ( $taxonomies as $taxonomy ) {
if ( ! empty( $taxonomy->public ) && ! in_array( $taxonomy->name, xmlsf()->disabled_taxonomies() ) ) {
++$available;
}
}
}
if ( $checked === $available ) {
update_option( 'xmlsf_taxonomies', '' );
}
$active = '1';
}
$taxonomy_settings = array(
'active' => $active,
'priority' => '0.3',
'dynamic_priority' => '1',
'limit' => '5000',
);
add_option( 'xmlsf_taxonomy_settings', $taxonomy_settings );
// Make sure no pong option remains.
delete_option( 'xmlsf_pong' );
// Update or create robots option.
$robots = get_option( 'xmlsf_robots', '' );
delete_option( 'xmlsf_robots' );
add_option( 'xmlsf_robots', $robots, '', false );
}
if ( version_compare( '5.4', $db_version, '>' ) ) {
// Delete old transients.
delete_transient( 'xmlsf_ping_google_sitemap_news' );
delete_transient( 'xmlsf_ping_google_sitemap' );
delete_transient( 'xmlsf_ping_bing_sitemap' );
delete_transient( 'xmlsf_flush_rewrite_rules' );
delete_transient( 'xmlsf_check_static_files' );
delete_transient( 'xmlsf_prefetch_post_meta_failed' );
// Remove term meta term_modified_gmt.
delete_metadata( 'term', 0, 'term_modified_gmt', '', true );
// Remove comments meta _xmlsf_comment_date.
delete_metadata( 'post', 0, '_xmlsf_comment_date', '', true );
$author_settings = (array) get_option( 'xmlsf_author_settings', array() );
$tax_settings = (array) get_option( 'xmlsf_taxonomy_settings', array() );
// Do not switch to core sitemap when upgrading.
add_option( 'xmlsf_server', 'plugin' );
// Set include array.
$disabled = array();
if ( empty( $tax_settings['active'] ) ) {
$disabled[] = 'taxonomies';
}
if ( empty( $author_settings['active'] ) ) {
$disabled[] = 'users';
}
// Add general settings option.
add_option( 'xmlsf_disabled_providers', ! empty( $disabled ) ? $disabled : '' );
// Update taxonomy terms limit.
$tax_settings['limit'] = isset( $tax_settings['term_limit'] ) ? $tax_settings['term_limit'] : '3000';
unset( $tax_settings['term_limit'] );
update_option( 'xmlsf_taxonomy_settings', $tax_settings );
// Update users limit.
$author_settings['limit'] = isset( $author_settings['term_limit'] ) ? $author_settings['term_limit'] : '1000';
unset( $author_settings['term_limit'] );
update_option( 'xmlsf_author_settings', $author_settings );
// Delete old settings.
delete_option( 'xmlsf_ping' );
delete_option( 'xmlsf_permalinks_flushed' );
delete_option( 'xmlsf_domains' );
set_transient( 'xmlsf_images_meta_primed', get_option( 'xmlsf_images_meta_primed' ) );
set_transient( 'xmlsf_comments_meta_primed', get_option( 'xmlsf_comments_meta_primed' ) );
delete_option( 'xmlsf_images_meta_primed' );
delete_option( 'xmlsf_comments_meta_primed' );
// Remove deprecated transient.
delete_transient( 'xmlsf_static_files' );
}
// Add missing new defaults.
xmlsf_update_from_defaults( false );
do_action( 'xmlsf_upgrade', $db_version );
}