-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.php
101 lines (69 loc) · 3.5 KB
/
update.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
<?php
/**
* @author Jason Lemahieu and Kevin Graeme (Cooperative Extension Technology Services)
* @copyright Copyright (c) 2011 - 2015 Jason Lemahieu and Kevin Graeme (Cooperative Extension Technology Services)
* @license http://www.gnu.org/licenses/gpl-2.0.html GPLv2
* @package CETS\Conditional_Widgets
*/
add_action( 'admin_init', 'conditional_widgets_maybe_update' );
function conditional_widgets_maybe_update() {
$v = get_option( 'conditional_widgets_version', '0' );
if ( version_compare( $v, "2.0", "<" ) ) {
// move post category data to new format
$widget_group_options = conditonal_widgets_get_widget_settings_arrays();
foreach ( $widget_group_options as $widget_group_option ) {
$widget_group_option_name = $widget_group_option->option_name;
$widget_group_option_value = unserialize( $widget_group_option->option_value );
//echo "<hr>WIDGET GROUP: {$widget_group_option_name}<br>";
//var_dump($widget_group_option_value);
//echo "<br>";
foreach ( $widget_group_option_value as $key => $widget_option_value ) {
//see if i'm just the default "_multiwidget" crap.
if ( $key == '_multiwidget' ) {
continue;
}
if ( ! is_array( $widget_option_value ) ) {
// somethings wrong with this one. get me outta here!
continue;
}
//echo "<br><br>-- New Widget Instance :{$key} --<br><br>";
//var_dump($widget_option_value);
if ( ! isset( $widget_option_value['cw_home_enable_checkbox'] ) ) {
// if we don't have conditional widgets data, just skip this one
//echo "<br>Skipping this one because no conditional widgets logic...<br>";
continue;
}
if ( ! isset( $widget_option_value['cw_custom'] ) ) {
$widget_option_value['cw_custom'] = array();
}
//print_r($option_value);
if ( ! isset( $widget_option_value['cw_custom']['post'] ) ) {
$widget_option_value['cw_custom']['post'] = array();
}
if ( ! isset( $widget_option_value['cw_custom']['post']['category'] ) ) {
$widget_option_value['cw_custom']['post']['category'] = array();
}
$widget_option_value['cw_custom']['post']['category']['enable'] = $widget_option_value['cw_cats_enable_checkbox'];
$widget_option_value['cw_custom']['post']['category']['all'] = $widget_option_value['cw_cats_all'];
$widget_option_value['cw_custom']['post']['category']['sub'] = $widget_option_value['cw_cats_sub_checkbox'];
$widget_option_value['cw_custom']['post']['category']['select'] = $widget_option_value['cw_select_cats'];
$widget_option_value['cw_custom']['post']['category']['selected_ids'] = $widget_option_value['cw_selected_cats'];
unset( $widget_option_value['cw_cats_enable_checkbox'] );
unset( $widget_option_value['cw_cats_all'] );
unset( $widget_option_value['cw_cats_sub_checkbox'] );
unset( $widget_option_value['cw_select_cats'] );
unset( $widget_option_value['cw_selected_cats'] );
$widget_group_option_value[$key] = $widget_option_value;
// /each-widget-instance
}
update_option( $widget_group_option_name, $widget_group_option_value );
} // /foreach
}
update_option( 'conditional_widgets_version', '2.0' );
} // /function conditional_widgets_maybe_update()
function conditonal_widgets_get_widget_settings_arrays() {
global $wpdb;
$sql = "SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name LIKE 'widget_%'";
$results = $wpdb->get_results( $sql );
return $results;
} // /function conditonal_widgets_get_widget_settings_arrays()