class-wpml-main-admin-menu.php
6.01 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
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
<?php
/**
* @author OnTheGo Systems
*/
class WPML_Main_Admin_Menu {
const MENU_ORDER_LANGUAGES = 100;
const MENU_ORDER_THEMES_AND_PLUGINS_LOCALIZATION = 200;
const MENU_ORDER_TAXONOMY_TRANSLATION = 900;
const MENU_ORDER_SETTINGS = 9900;
const MENU_ORDER_MAX = 10000;
/** @var string */
private $languages_menu_slug;
/**
* @var WPML_Admin_Menu_Root
*/
private $root;
/**
* @var SitePress
*/
private $sitepress;
/**
* WPML_Menu_Main constructor.
*
* @param SitePress $sitepress
*
* @throws \InvalidArgumentException
*/
public function __construct( SitePress $sitepress ) {
$this->sitepress = $sitepress;
$this->languages_menu_slug = WPML_PLUGIN_FOLDER . '/menu/languages.php';
}
/**
* @throws \InvalidArgumentException
*/
public function configure() {
$this->root = new WPML_Admin_Menu_Root(
array(
'menu_id' => 'WPML',
'page_title' => __( 'WPML', 'sitepress' ),
'menu_title' => __( 'WPML', 'sitepress' ),
'capability' => 'wpml_manage_languages',
'menu_slug',
'function' => null,
'icon_url' => ICL_PLUGIN_URL . '/res/img/icon16.png',
)
);
$this->root->init_hooks();
if ( $this->sitepress->is_setup_complete() ) {
$this->languages();
do_action( 'icl_wpml_top_menu_added' );
if ( $this->is_wpml_setup_completed() ) {
$this->themes_and_plugins_localization();
if ( ! $this->is_tm_active() ) {
$this->translation_options();
}
}
$this->taxonomy_translation();
do_action( 'wpml_core_admin_menus_added' );
} else {
$this->wizard();
}
$this->support();
do_action( 'wpml_core_admin_menus_completed' );
}
/**
* @throws \InvalidArgumentException
*/
private function languages() {
$menu = new WPML_Admin_Menu_Item();
$menu->set_order( self::MENU_ORDER_LANGUAGES );
$menu->set_page_title( __( 'Languages', 'sitepress' ) );
$menu->set_menu_title( __( 'Languages', 'sitepress' ) );
$menu->set_capability( 'wpml_manage_languages' );
$menu->set_menu_slug( $this->languages_menu_slug );
$this->root->add_item( $menu );
}
private function wizard() {
$menu = new WPML_Admin_Menu_Item();
$menu->set_order( self::MENU_ORDER_LANGUAGES );
$menu->set_page_title( __( 'WPML Setup', 'sitepress' ) );
$menu->set_menu_title( __( 'Setup', 'sitepress' ) );
$menu->set_capability( 'wpml_manage_languages' );
$menu->set_menu_slug( WPML_PLUGIN_FOLDER . '/menu/setup.php' );
$this->root->add_item( $menu );
}
/**
* @return bool
*/
private function is_wpml_setup_completed() {
return $this->sitepress->get_setting( 'existing_content_language_verified' )
&& 2 <= count( $this->sitepress->get_active_languages() );
}
/**
* @throws \InvalidArgumentException
*/
private function themes_and_plugins_localization() {
$menu = new WPML_Admin_Menu_Item();
$menu->set_order( self::MENU_ORDER_THEMES_AND_PLUGINS_LOCALIZATION );
$menu->set_page_title( __( 'Theme and plugins localization', 'sitepress' ) );
$menu->set_menu_title( __( 'Theme and plugins localization', 'sitepress' ) );
$menu->set_capability( 'wpml_manage_theme_and_plugin_localization' );
$menu->set_menu_slug( WPML_PLUGIN_FOLDER . '/menu/theme-localization.php' );
$this->root->add_item( $menu );
}
/**
* @return bool
*/
private function is_tm_active() {
return $this->sitepress->get_wp_api()->defined( 'WPML_TM_VERSION' );
}
/**
* @throws \InvalidArgumentException
*/
private function translation_options() {
$menu = new WPML_Admin_Menu_Item();
$menu->set_order( self::MENU_ORDER_SETTINGS );
$menu->set_page_title( __( 'Settings', 'sitepress' ) );
$menu->set_menu_title( __( 'Settings', 'sitepress' ) );
$menu->set_capability( 'wpml_manage_translation_options' );
$menu->set_menu_slug( WPML_PLUGIN_FOLDER . '/menu/translation-options.php' );
$this->root->add_item( $menu );
}
/**
* @throws \InvalidArgumentException
*/
private function taxonomy_translation() {
$menu = new WPML_Admin_Menu_Item();
$menu->set_order( self::MENU_ORDER_TAXONOMY_TRANSLATION );
$menu->set_page_title( __( 'Taxonomy translation', 'sitepress' ) );
$menu->set_menu_title( __( 'Taxonomy translation', 'sitepress' ) );
$menu->set_capability( 'wpml_manage_taxonomy_translation' );
$menu->set_menu_slug( WPML_PLUGIN_FOLDER . '/menu/taxonomy-translation.php' );
$menu->set_function( array( $this->sitepress, 'taxonomy_translation_page' ) );
$this->root->add_item( $menu );
}
/**
* @throws \InvalidArgumentException
*/
private function support() {
$menu_slug = WPML_PLUGIN_FOLDER . '/menu/support.php';
$menu = new WPML_Admin_Menu_Item();
$menu->set_order( self::MENU_ORDER_MAX );
$menu->set_page_title( __( 'Support', 'sitepress' ) );
$menu->set_menu_title( __( 'Support', 'sitepress' ) );
$menu->set_capability( 'wpml_manage_support' );
$menu->set_menu_slug( $menu_slug );
$this->root->add_item( $menu );
$this->troubleshooting_menu( $menu_slug );
$this->debug_information_menu( $menu_slug );
}
/**
* @param string $parent_slug
*
* @throws \InvalidArgumentException
*/
private function troubleshooting_menu( $parent_slug ) {
$menu = new WPML_Admin_Menu_Item();
$menu->set_parent_slug( $parent_slug );
$menu->set_page_title( __( 'Troubleshooting', 'sitepress' ) );
$menu->set_menu_title( __( 'Troubleshooting', 'sitepress' ) );
$menu->set_capability( 'wpml_manage_troubleshooting' );
$menu->set_menu_slug( WPML_PLUGIN_FOLDER . '/menu/troubleshooting.php' );
$this->root->add_item( $menu );
}
/**
* @param string $parent_slug
*
* @throws \InvalidArgumentException
*/
private function debug_information_menu( $parent_slug ) {
$menu = new WPML_Admin_Menu_Item();
$menu->set_parent_slug( $parent_slug );
$menu->set_page_title( __( 'Debug information', 'sitepress' ) );
$menu->set_menu_title( __( 'Debug information', 'sitepress' ) );
$menu->set_capability( 'wpml_manage_troubleshooting' );
$menu->set_menu_slug( WPML_PLUGIN_FOLDER . '/menu/debug-information.php' );
$this->root->add_item( $menu );
}
}