ActiveMenuConfiguration.php
2.39 KB
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
<?php
namespace YahnisElsts\AdminMenuEditor\Customizable\Storage;
class ActiveMenuConfiguration implements StorageInterface {
/**
* @var \WPMenuEditor
*/
private $menuEditor;
/**
* @var null|MenuConfigurationWrapper
*/
private $wrapper = null;
public function __construct(\WPMenuEditor $menuEditor) {
$this->menuEditor = $menuEditor;
}
/**
* @param \WPMenuEditor $menuEditor
* @return self
*/
public static function getInstance($menuEditor = null) {
static $instance = null;
if ( $instance === null ) {
if ( $menuEditor === null ) {
$menuEditor = $GLOBALS['wp_menu_editor'];
}
$instance = new self($menuEditor);
}
return $instance;
}
/**
* @return MenuConfigurationWrapper
*/
private function lazyInit() {
if ( $this->wrapper !== null ) {
return $this->wrapper;
}
$actualConfigId = $this->menuEditor->get_loaded_menu_config_id();
if ( empty($actualConfigId) ) {
$this->menuEditor->load_custom_menu();
$actualConfigId = $this->menuEditor->get_loaded_menu_config_id();
if ( empty($actualConfigId) ) {
$actualConfigId = 'site';
}
}
$this->wrapper = MenuConfigurationWrapper::getStoreByConfigId(
$actualConfigId,
$this->menuEditor
);
return $this->wrapper;
}
public function getValue($defaultValue = null) {
return $this->lazyInit()->getValue($defaultValue);
}
public function setValue($value) {
return $this->lazyInit()->setValue($value);
}
public function getPath($path, $defaultValue = null) {
return $this->lazyInit()->getPath($path, $defaultValue);
}
public function setPath($path, $value) {
return $this->lazyInit()->setPath($path, $value);
}
public function deleteValue() {
$this->lazyInit()->deleteValue();
}
public function deletePath($path) {
$this->lazyInit()->deletePath($path);
}
public function buildSlot($path) {
return $this->lazyInit()->buildSlot($path);
}
public function save() {
$this->lazyInit()->save();
}
public function getStorageKey() {
return $this->lazyInit()->getStorageKey();
}
public function addReadAliases($aliases) {
$this->lazyInit()->addReadAliases($aliases);
}
public function getSmallestSavable() {
return $this->lazyInit()->getSmallestSavable();
}
public function setPreviewValue($value) {
$this->lazyInit()->setPreviewValue($value);
}
public function setPreviewByPath($path, $value) {
$this->lazyInit()->setPreviewByPath($path, $value);
}
}