|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Modules\Migrations; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Application; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Helpers\Arr; |
|
7
|
|
|
use GeminiLabs\SiteReviews\Helpers\Str; |
|
8
|
|
|
|
|
9
|
|
|
class Migrate_4_6_0 |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @return void |
|
13
|
|
|
*/ |
|
14
|
1 |
|
public function migrateSidebarWidgets() |
|
15
|
|
|
{ |
|
16
|
1 |
|
$sidebars = get_option('sidebars_widgets'); |
|
17
|
1 |
|
if ($this->widgetsExist($sidebars)) { |
|
|
|
|
|
|
18
|
|
|
$sidebars = $this->updateWidgetNames($sidebars); |
|
|
|
|
|
|
19
|
|
|
update_option('sidebars_widgets', $sidebars); |
|
20
|
|
|
} |
|
21
|
1 |
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @return void |
|
25
|
|
|
*/ |
|
26
|
1 |
|
public function migrateThemeModWidgets() |
|
27
|
|
|
{ |
|
28
|
1 |
|
$themes = $this->queryThemeMods(); |
|
29
|
1 |
|
foreach ($themes as $theme) { |
|
30
|
|
|
$themeMod = get_option($theme); |
|
31
|
|
|
$sidebars = Arr::get($themeMod, 'sidebars_widgets.data'); |
|
32
|
|
|
if ($this->widgetsExist($sidebars)) { |
|
|
|
|
|
|
33
|
|
|
$themeMod['sidebars_widgets']['data'] = $this->updateWidgetNames($sidebars); |
|
|
|
|
|
|
34
|
|
|
update_option($theme, $themeMod); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
1 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return void |
|
41
|
|
|
*/ |
|
42
|
1 |
|
public function run() |
|
43
|
|
|
{ |
|
44
|
1 |
|
$this->migrateSidebarWidgets(); |
|
45
|
1 |
|
$this->migrateThemeModWidgets(); |
|
46
|
1 |
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return array |
|
50
|
|
|
*/ |
|
51
|
1 |
|
protected function queryThemeMods() |
|
52
|
|
|
{ |
|
53
|
1 |
|
global $wpdb; |
|
54
|
1 |
|
return $wpdb->get_col(" |
|
55
|
|
|
SELECT option_name |
|
56
|
1 |
|
FROM {$wpdb->options} |
|
57
|
|
|
WHERE option_name LIKE '%theme_mods_%' |
|
58
|
|
|
"); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param array $sidebars |
|
63
|
|
|
* @return array |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function updateWidgetNames(array $sidebars) |
|
66
|
|
|
{ |
|
67
|
|
|
array_walk($sidebars, function(&$widgets) { |
|
68
|
|
|
array_walk($widgets, function(&$widget) { |
|
69
|
|
|
if (Str::startsWith(Application::ID.'_', $widget)) { |
|
70
|
|
|
$widget = Str::replaceFirst(Application::ID.'_', Application::PREFIX, $widget); |
|
71
|
|
|
} |
|
72
|
|
|
}); |
|
73
|
|
|
}); |
|
74
|
|
|
return $sidebars; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param array $sidebars |
|
79
|
|
|
* @return bool |
|
80
|
|
|
*/ |
|
81
|
1 |
|
protected function widgetsExist($sidebars) |
|
82
|
|
|
{ |
|
83
|
1 |
|
$widgets = call_user_func_array('array_merge', array_filter(Arr::consolidate($sidebars), 'is_array')); |
|
84
|
1 |
|
foreach ($widgets as $widget) { |
|
85
|
1 |
|
if (Str::startsWith(Application::ID.'_', $widget)) { |
|
86
|
1 |
|
return true; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
1 |
|
return false; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|