| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
function webling_plugin_setup() { |
| 5 |
webling_plugin_update_check(); |
| 6 |
} |
| 7 |
|
| 8 |
function webling_plugin_update_check() { |
| 9 |
$installed_db_version = get_option('webling-db-version', 0); |
| 10 |
|
| 11 |
// abort if the installed version is the current version |
| 12 |
if ($installed_db_version == WEBLING_DB_VERSION) { |
| 13 |
return; |
| 14 |
} |
| 15 |
|
| 16 |
if ($installed_db_version < 2) { |
| 17 |
webling_plugin_initial_setup(); |
| 18 |
} |
| 19 |
if ($installed_db_version < 3) { |
| 20 |
webling_plugin_setup_upgrade_v3(); |
| 21 |
} |
| 22 |
if ($installed_db_version < 4) { |
| 23 |
webling_plugin_setup_upgrade_v4(); |
| 24 |
} |
| 25 |
if ($installed_db_version < 5) { |
| 26 |
webling_plugin_setup_upgrade_v5(); |
| 27 |
} |
| 28 |
if ($installed_db_version < 6) { |
| 29 |
webling_plugin_setup_upgrade_v6(); |
| 30 |
} |
| 31 |
if ($installed_db_version < 7) { |
| 32 |
webling_plugin_setup_upgrade_v7(); |
| 33 |
} |
| 34 |
if ($installed_db_version < 8) { |
| 35 |
webling_plugin_setup_upgrade_v8(); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
// ************* Version Upgrade Functions ************* |
| 40 |
|
| 41 |
|
| 42 |
// upgrade to db version 8 |
| 43 |
// savedsearches for memberlist |
| 44 |
function webling_plugin_setup_upgrade_v8() { |
| 45 |
global $wpdb; |
| 46 |
|
| 47 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 48 |
|
| 49 |
$charset_collate = $wpdb->get_charset_collate(); |
| 50 |
|
| 51 |
// update memberlists table |
| 52 |
// add savedsearch fields |
| 53 |
$table_name = $wpdb->prefix . 'webling_memberlists'; |
| 54 |
$sql = "CREATE TABLE $table_name ( |
| 55 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 56 |
`title` varchar(255) DEFAULT NULL, |
| 57 |
`show_all_groups` tinyint(1) NOT NULL DEFAULT '0', |
| 58 |
`groups` text, |
| 59 |
`fields` text, |
| 60 |
`sortorder` enum('ASC','DESC') DEFAULT 'ASC', |
| 61 |
`sortfield` varchar(255) DEFAULT NULL, |
| 62 |
`class` varchar(255) DEFAULT NULL, |
| 63 |
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| 64 |
`created_at` timestamp NULL DEFAULT NULL, |
| 65 |
`design` enum('LIST','CUSTOM') NOT NULL DEFAULT 'LIST', |
| 66 |
`custom_template` text, |
| 67 |
`type` enum('ALL','GROUPS','SAVEDSEARCH') NOT NULL DEFAULT 'ALL', |
| 68 |
`savedsearch` int(11) NOT NULL DEFAULT '0', |
| 69 |
`savedsearch_cache` text, |
| 70 |
`savedsearch_cache_revision` int(11) NOT NULL DEFAULT '0', |
| 71 |
PRIMARY KEY (`id`) |
| 72 |
) $charset_collate;"; |
| 73 |
dbDelta( $sql ); |
| 74 |
|
| 75 |
$wpdb->query( "UPDATE $table_name SET type = 'GROUPS' WHERE show_all_groups = 0" ); |
| 76 |
|
| 77 |
// remove obsolete show_all_groups field |
| 78 |
$wpdb->query( "ALTER TABLE $table_name DROP COLUMN show_all_groups" ); |
| 79 |
|
| 80 |
update_option("webling-db-version", 8); |
| 81 |
} |
| 82 |
|
| 83 |
// upgrade to db version 7 |
| 84 |
// add memberform select options |
| 85 |
function webling_plugin_setup_upgrade_v7() { |
| 86 |
global $wpdb; |
| 87 |
|
| 88 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 89 |
|
| 90 |
$charset_collate = $wpdb->get_charset_collate(); |
| 91 |
|
| 92 |
// update memberlists table |
| 93 |
// add max signup field |
| 94 |
$table_name = $wpdb->prefix . 'webling_form_fields'; |
| 95 |
$sql = "CREATE TABLE $table_name ( |
| 96 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 97 |
`form_id` int(11) NOT NULL, |
| 98 |
`order` int(11) NOT NULL, |
| 99 |
`webling_field_id` int(11) NOT NULL, |
| 100 |
`type` varchar(50) NOT NULL DEFAULT 'text', |
| 101 |
`required` tinyint(1) NOT NULL DEFAULT '0', |
| 102 |
`field_name` varchar(255) NOT NULL DEFAULT '', |
| 103 |
`field_name_position` enum('TOP','LEFT','HIDDEN') NOT NULL DEFAULT 'TOP', |
| 104 |
`placeholder_text` varchar(255) DEFAULT NULL, |
| 105 |
`description_text` text, |
| 106 |
`class` varchar(255) DEFAULT NULL, |
| 107 |
`select_options` text |
| 108 |
PRIMARY KEY (`id`), |
| 109 |
KEY `form_id` (`form_id`) |
| 110 |
PRIMARY KEY (`id`) |
| 111 |
) $charset_collate;"; |
| 112 |
dbDelta( $sql ); |
| 113 |
|
| 114 |
update_option("webling-db-version", 7); |
| 115 |
} |
| 116 |
|
| 117 |
// upgrade to db version 6 |
| 118 |
// add max signups fields |
| 119 |
function webling_plugin_setup_upgrade_v6() { |
| 120 |
global $wpdb; |
| 121 |
|
| 122 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 123 |
|
| 124 |
$charset_collate = $wpdb->get_charset_collate(); |
| 125 |
|
| 126 |
// update memberlists table |
| 127 |
// add max signup field |
| 128 |
$table_name = $wpdb->prefix . 'webling_forms'; |
| 129 |
$sql = "CREATE TABLE $table_name ( |
| 130 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 131 |
`title` varchar(255) DEFAULT '', |
| 132 |
`group_id` int(11) NOT NULL, |
| 133 |
`notification_email` varchar(255) DEFAULT NULL, |
| 134 |
`confirmation_email_enabled` tinyint(1) NOT NULL DEFAULT '0', |
| 135 |
`confirmation_email_webling_field` int(11) DEFAULT NULL, |
| 136 |
`confirmation_email_subject` varchar(255) DEFAULT '', |
| 137 |
`confirmation_email_text` text, |
| 138 |
`confirmation_text` text, |
| 139 |
`submit_button_text` varchar(255) DEFAULT NULL, |
| 140 |
`class` varchar(255) DEFAULT NULL, |
| 141 |
`max_signups` int(11) NOT NULL DEFAULT 0, |
| 142 |
`max_signups_text` text DEFAULT '', |
| 143 |
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| 144 |
`created_at` timestamp NULL DEFAULT NULL, |
| 145 |
PRIMARY KEY (`id`) |
| 146 |
) $charset_collate;"; |
| 147 |
dbDelta( $sql ); |
| 148 |
|
| 149 |
// set some defaults |
| 150 |
$wpdb->query( "UPDATE $table_name SET max_signups_text = 'Die maximale Anzahl Anmeldungen wurde erreicht. Das Formular ist deaktiviert.'" ); |
| 151 |
|
| 152 |
update_option("webling-db-version", 6); |
| 153 |
} |
| 154 |
|
| 155 |
// upgrade to db version 5 |
| 156 |
// add custom memberlist template fields |
| 157 |
function webling_plugin_setup_upgrade_v5() { |
| 158 |
global $wpdb; |
| 159 |
|
| 160 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 161 |
|
| 162 |
$charset_collate = $wpdb->get_charset_collate(); |
| 163 |
|
| 164 |
// update memberlists table |
| 165 |
// add custom template fields |
| 166 |
$table_name = $wpdb->prefix . 'webling_memberlists'; |
| 167 |
$sql = "CREATE TABLE $table_name ( |
| 168 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 169 |
`title` varchar(255) DEFAULT NULL, |
| 170 |
`show_all_groups` tinyint(1) NOT NULL DEFAULT '0', |
| 171 |
`groups` text, |
| 172 |
`fields` text, |
| 173 |
`sortorder` enum('ASC','DESC') DEFAULT 'ASC', |
| 174 |
`sortfield` varchar(255) DEFAULT NULL, |
| 175 |
`class` varchar(255) DEFAULT NULL, |
| 176 |
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| 177 |
`created_at` timestamp NULL DEFAULT NULL, |
| 178 |
`design` enum('LIST','CUSTOM') NOT NULL DEFAULT 'LIST', |
| 179 |
`custom_template` text, |
| 180 |
PRIMARY KEY (`id`) |
| 181 |
) $charset_collate;"; |
| 182 |
dbDelta( $sql ); |
| 183 |
|
| 184 |
update_option("webling-db-version", 5); |
| 185 |
} |
| 186 |
|
| 187 |
// upgrade to db version 4 |
| 188 |
// fixing schema for MySQL 5.5 (can not have more than one AUTO CURRENT_TIMESTAMP field) |
| 189 |
function webling_plugin_setup_upgrade_v4() { |
| 190 |
global $wpdb; |
| 191 |
|
| 192 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 193 |
|
| 194 |
$charset_collate = $wpdb->get_charset_collate(); |
| 195 |
|
| 196 |
// update forms table (or create if it failed till now) |
| 197 |
// only updated_at field is now auto-updating |
| 198 |
$table_name = $wpdb->prefix . 'webling_forms'; |
| 199 |
$sql = "CREATE TABLE $table_name ( |
| 200 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 201 |
`title` varchar(255) DEFAULT '', |
| 202 |
`group_id` int(11) NOT NULL, |
| 203 |
`notification_email` varchar(255) DEFAULT NULL, |
| 204 |
`confirmation_email_enabled` tinyint(1) NOT NULL DEFAULT '0', |
| 205 |
`confirmation_email_webling_field` int(11) DEFAULT NULL, |
| 206 |
`confirmation_email_subject` varchar(255) DEFAULT '', |
| 207 |
`confirmation_email_text` text, |
| 208 |
`confirmation_text` text, |
| 209 |
`submit_button_text` varchar(255) DEFAULT NULL, |
| 210 |
`class` varchar(255) DEFAULT NULL, |
| 211 |
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| 212 |
`created_at` timestamp NULL DEFAULT NULL, |
| 213 |
PRIMARY KEY (`id`) |
| 214 |
) $charset_collate;"; |
| 215 |
dbDelta( $sql ); |
| 216 |
|
| 217 |
// change definitions on old installations |
| 218 |
$wpdb->query( "ALTER TABLE $table_name MODIFY COLUMN `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP" ); |
| 219 |
$wpdb->query( "ALTER TABLE $table_name MODIFY COLUMN `created_at` timestamp NULL DEFAULT NULL" ); |
| 220 |
|
| 221 |
// update memberlists table (or create if it failed till now) |
| 222 |
// only updated_at field is now auto-updating |
| 223 |
$table_name = $wpdb->prefix . 'webling_memberlists'; |
| 224 |
$sql = "CREATE TABLE $table_name ( |
| 225 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 226 |
`title` varchar(255) DEFAULT NULL, |
| 227 |
`show_all_groups` tinyint(1) NOT NULL DEFAULT '0', |
| 228 |
`groups` text, |
| 229 |
`fields` text, |
| 230 |
`sortorder` enum('ASC','DESC') DEFAULT 'ASC', |
| 231 |
`sortfield` varchar(255) DEFAULT NULL, |
| 232 |
`class` varchar(255) DEFAULT NULL, |
| 233 |
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| 234 |
`created_at` timestamp NULL DEFAULT NULL, |
| 235 |
PRIMARY KEY (`id`) |
| 236 |
) $charset_collate;"; |
| 237 |
dbDelta( $sql ); |
| 238 |
|
| 239 |
// change definitions on old installations |
| 240 |
$wpdb->query( "ALTER TABLE $table_name MODIFY COLUMN `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP" ); |
| 241 |
$wpdb->query( "ALTER TABLE $table_name MODIFY COLUMN `created_at` timestamp NULL DEFAULT NULL" ); |
| 242 |
|
| 243 |
// update form fields table (or create if it failed till now) |
| 244 |
// remove updated_at and created_at fields, there is no use for them |
| 245 |
$table_name = $wpdb->prefix . 'webling_form_fields'; |
| 246 |
$sql = "CREATE TABLE $table_name ( |
| 247 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 248 |
`form_id` int(11) NOT NULL, |
| 249 |
`order` int(11) NOT NULL, |
| 250 |
`webling_field_id` int(11) NOT NULL, |
| 251 |
`type` varchar(50) NOT NULL DEFAULT 'text', |
| 252 |
`required` tinyint(1) NOT NULL DEFAULT '0', |
| 253 |
`field_name` varchar(255) NOT NULL DEFAULT '', |
| 254 |
`field_name_position` enum('TOP','LEFT','HIDDEN') NOT NULL DEFAULT 'TOP', |
| 255 |
`placeholder_text` varchar(255) DEFAULT NULL, |
| 256 |
`description_text` text, |
| 257 |
`class` varchar(255) DEFAULT NULL, |
| 258 |
PRIMARY KEY (`id`), |
| 259 |
KEY `form_id` (`form_id`) |
| 260 |
) $charset_collate;"; |
| 261 |
dbDelta( $sql ); |
| 262 |
|
| 263 |
// remove updated_at and created_at on existing installations |
| 264 |
$table_name = $wpdb->prefix . 'webling_form_fields'; |
| 265 |
$wpdb->query( "ALTER TABLE $table_name DROP COLUMN `updated_at`" ); |
| 266 |
$wpdb->query( "ALTER TABLE $table_name DROP COLUMN `created_at`" ); |
| 267 |
|
| 268 |
update_option("webling-db-version", 4); |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
// upgrade to db version 3 |
| 273 |
// add confirmation email fields |
| 274 |
function webling_plugin_setup_upgrade_v3() { |
| 275 |
global $wpdb; |
| 276 |
|
| 277 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 278 |
|
| 279 |
$charset_collate = $wpdb->get_charset_collate(); |
| 280 |
|
| 281 |
// update forms table |
| 282 |
$table_name = $wpdb->prefix . 'webling_forms'; |
| 283 |
$sql = "CREATE TABLE $table_name ( |
| 284 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 285 |
`title` varchar(255) DEFAULT '', |
| 286 |
`group_id` int(11) NOT NULL, |
| 287 |
`notification_email` varchar(255) DEFAULT NULL, |
| 288 |
`confirmation_email_enabled` tinyint(1) NOT NULL DEFAULT '0', |
| 289 |
`confirmation_email_webling_field` int(11) DEFAULT NULL, |
| 290 |
`confirmation_email_subject` varchar(255) DEFAULT '', |
| 291 |
`confirmation_email_text` text, |
| 292 |
`confirmation_text` text, |
| 293 |
`submit_button_text` varchar(255) DEFAULT NULL, |
| 294 |
`class` varchar(255) DEFAULT NULL, |
| 295 |
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, |
| 296 |
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| 297 |
PRIMARY KEY (`id`) |
| 298 |
) $charset_collate;"; |
| 299 |
dbDelta( $sql ); |
| 300 |
|
| 301 |
update_option("webling-db-version", 3); |
| 302 |
} |
| 303 |
|
| 304 |
// upgrade to db version 2 |
| 305 |
function webling_plugin_initial_setup() { |
| 306 |
global $wpdb; |
| 307 |
|
| 308 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 309 |
|
| 310 |
$charset_collate = $wpdb->get_charset_collate(); |
| 311 |
|
| 312 |
// create cache table |
| 313 |
$table_name = $wpdb->prefix . 'webling_cache'; |
| 314 |
$sql = "CREATE TABLE $table_name ( |
| 315 |
id mediumint(9) NOT NULL, |
| 316 |
type VARCHAR(20) NOT NULL, |
| 317 |
data text NOT NULL, |
| 318 |
PRIMARY KEY (id) |
| 319 |
) $charset_collate;"; |
| 320 |
dbDelta( $sql ); |
| 321 |
|
| 322 |
// create memberlists table |
| 323 |
$table_name = $wpdb->prefix . 'webling_memberlists'; |
| 324 |
$sql = "CREATE TABLE $table_name ( |
| 325 |
id int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 326 |
title varchar(255) DEFAULT NULL, |
| 327 |
show_all_groups tinyint(1) NOT NULL DEFAULT '0', |
| 328 |
groups text, |
| 329 |
fields text, |
| 330 |
sortorder enum('ASC','DESC') DEFAULT 'ASC', |
| 331 |
sortfield varchar(255) DEFAULT NULL, |
| 332 |
class varchar(255) DEFAULT NULL, |
| 333 |
updated_at timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, |
| 334 |
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| 335 |
PRIMARY KEY (`id`) |
| 336 |
) $charset_collate;"; |
| 337 |
dbDelta( $sql ); |
| 338 |
|
| 339 |
// create forms table |
| 340 |
$table_name = $wpdb->prefix . 'webling_forms'; |
| 341 |
$sql = "CREATE TABLE $table_name ( |
| 342 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 343 |
`title` varchar(255) DEFAULT '', |
| 344 |
`group_id` int(11) NOT NULL, |
| 345 |
`notification_email` varchar(255) DEFAULT NULL, |
| 346 |
`confirmation_text` text, |
| 347 |
`submit_button_text` varchar(255) DEFAULT NULL, |
| 348 |
`class` varchar(255) DEFAULT NULL, |
| 349 |
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, |
| 350 |
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| 351 |
PRIMARY KEY (`id`) |
| 352 |
) $charset_collate;"; |
| 353 |
dbDelta( $sql ); |
| 354 |
|
| 355 |
// create form fields table |
| 356 |
$table_name = $wpdb->prefix . 'webling_form_fields'; |
| 357 |
$sql = "CREATE TABLE $table_name ( |
| 358 |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, |
| 359 |
`form_id` int(11) NOT NULL, |
| 360 |
`order` int(11) NOT NULL, |
| 361 |
`webling_field_id` int(11) NOT NULL, |
| 362 |
`type` varchar(50) NOT NULL DEFAULT 'text', |
| 363 |
`required` tinyint(1) NOT NULL DEFAULT '0', |
| 364 |
`field_name` varchar(255) NOT NULL DEFAULT '', |
| 365 |
`field_name_position` enum('TOP','LEFT','HIDDEN') NOT NULL DEFAULT 'TOP', |
| 366 |
`placeholder_text` varchar(255) DEFAULT NULL, |
| 367 |
`description_text` text, |
| 368 |
`class` varchar(255) DEFAULT NULL, |
| 369 |
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, |
| 370 |
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| 371 |
PRIMARY KEY (`id`), |
| 372 |
KEY `form_id` (`form_id`) |
| 373 |
) $charset_collate;"; |
| 374 |
dbDelta( $sql ); |
| 375 |
|
| 376 |
|
| 377 |
// migrate old shortcodes to new format |
| 378 |
$defaultOptions = array( |
| 379 |
'host' => '', |
| 380 |
'apikey' => '', |
| 381 |
'css' => '' |
| 382 |
); |
| 383 |
$options = get_option('webling-options', $defaultOptions); |
| 384 |
if (isset($options['fields'])) { |
| 385 |
$old_fields = explode(',', $options['fields']); |
| 386 |
} else { |
| 387 |
$old_fields = ['Vorname']; |
| 388 |
} |
| 389 |
$firstfield = $old_fields[0]; |
| 390 |
|
| 391 |
|
| 392 |
$sql = "SELECT * FROM {$wpdb->prefix}posts WHERE post_content LIKE '%[webling_memberlist%' |
| 393 |
and ( |
| 394 |
post_status = 'publish' or |
| 395 |
post_status = 'draft' or |
| 396 |
post_status = 'pending' or |
| 397 |
post_status = 'private' or |
| 398 |
post_status = 'future' |
| 399 |
)"; |
| 400 |
$posts = $wpdb->get_results($sql, 'ARRAY_A'); |
| 401 |
foreach ($posts as $post) { |
| 402 |
$original_content = $post['post_content']; |
| 403 |
$hasError = false; |
| 404 |
|
| 405 |
preg_match_all("/\[webling_memberlist(.*)\]/", $post['post_content'], $matches); |
| 406 |
foreach ($matches[0] as $index => $match) { |
| 407 |
$shortcode = $match; |
| 408 |
$arguments = shortcode_parse_atts($matches[1][$index]); |
| 409 |
|
| 410 |
// abort if there is already an id argument (migration probably done aready) |
| 411 |
if (isset($arguments['id'])) { |
| 412 |
$hasError = true; |
| 413 |
continue; |
| 414 |
} |
| 415 |
|
| 416 |
$groups = array(); |
| 417 |
if (isset($arguments['groups'])) { |
| 418 |
$groupIds = explode(',', $arguments['groups']); |
| 419 |
if(is_array($groupIds)) { |
| 420 |
foreach ($groupIds as $groupId) { |
| 421 |
if (intval($groupId) > 0) { |
| 422 |
$groups[] = intval($groupId); |
| 423 |
} |
| 424 |
} |
| 425 |
} |
| 426 |
} |
| 427 |
|
| 428 |
// create new list |
| 429 |
$wpdb->query( |
| 430 |
$wpdb->prepare(" |
| 431 |
INSERT INTO {$wpdb->prefix}webling_memberlists |
| 432 |
( |
| 433 |
`title`, |
| 434 |
`show_all_groups`, |
| 435 |
`groups`, |
| 436 |
`fields`, |
| 437 |
`class`, |
| 438 |
`sortfield`, |
| 439 |
`sortorder` |
| 440 |
) VALUES ( |
| 441 |
%s, |
| 442 |
%s, |
| 443 |
%s, |
| 444 |
%s, |
| 445 |
%s, |
| 446 |
%s, |
| 447 |
%s |
| 448 |
)", |
| 449 |
'Mitgliederliste', |
| 450 |
(count($groups) > 0 ? 0 : 1), |
| 451 |
serialize($groups), |
| 452 |
json_encode($old_fields), |
| 453 |
'', |
| 454 |
$firstfield, |
| 455 |
'ASC' |
| 456 |
) |
| 457 |
); |
| 458 |
|
| 459 |
$list_id = $wpdb->insert_id; |
| 460 |
$new_shortcode = '[webling_memberlist id="'.$list_id.'"]'; |
| 461 |
|
| 462 |
$pos = strpos($original_content, $shortcode); |
| 463 |
if ($pos !== false) { |
| 464 |
$original_content = substr_replace($original_content, $new_shortcode, $pos, strlen($shortcode)); |
| 465 |
} |
| 466 |
} |
| 467 |
|
| 468 |
if (!$hasError) { |
| 469 |
wp_update_post( |
| 470 |
[ |
| 471 |
'ID' => $post['ID'], |
| 472 |
'post_content' => $original_content, |
| 473 |
] |
| 474 |
); |
| 475 |
|
| 476 |
// add a new revision as a backup if anything goes wrong |
| 477 |
wp_save_post_revision($post['ID']); |
| 478 |
} |
| 479 |
} |
| 480 |
|
| 481 |
// unset "fields" in webling-options as it is not used anymore |
| 482 |
unset($options['fields']); |
| 483 |
update_option('webling-options', $options); |
| 484 |
|
| 485 |
// update version |
| 486 |
add_option("webling-db-version", 2); |
| 487 |
update_option("webling-db-version", 2); |
| 488 |
} |
| 489 |
|