6
6
use AutomateWoo \Admin \AssetData ;
7
7
use AutomateWoo \Admin \WCAdminConnectPages ;
8
8
use AutomateWoo \HPOS_Helper ;
9
- use Automattic \WooCommerce \Admin \Features \Navigation \Menu ;
10
- use Automattic \WooCommerce \Admin \Features \Navigation \Screen ;
11
9
use Automattic \WooCommerce \Admin \PageController ;
12
10
use Automattic \WooCommerce \Blocks \Assets \AssetDataRegistry ;
13
11
use Automattic \WooCommerce \Blocks \Package as BlocksPackage ;
@@ -139,10 +137,9 @@ public static function handle_save_screen_option( $keep, $option, $value ) {
139
137
* Add menu entries.
140
138
*/
141
139
public static function admin_menu () {
142
- $ sub_menu = [];
143
- $ position = '55.6324 ' ; // fix for rare position clash bug
144
- $ workflows_group = 'automatewoo-workflows-group ' ;
145
- $ icon = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgNTEyIDUxMiIgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgNTEyIDUxMiIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PGc+PHBvbHlnb24gZmlsbD0iIzlFQTNBOCIgcG9pbnRzPSIxMTcuNiwyNzIuNyAxNjYuOSwyNzIuNyAxNDIuMywyMDUuNCAiLz48cGF0aCBmaWxsPSIjOUVBM0E4IiBkPSJNNDY0LDU0LjRINDhDMjUuMSw1NC40LDYuNCw3My4xLDYuNCw5NnYzMjBjMCwyMi45LDE4LjcsNDEuNiw0MS42LDQxLjZoNDE2YzIyLjksMCw0MS42LTE4LjcsNDEuNi00MS42Vjk2QzUwNS42LDczLjEsNDg2LjksNTQuNCw0NjQsNT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xMjMsMTY2LjloNDAuMkwyMzEsMzQ1LjFIMTkzLjN6IE00MDguMSwzNDUuMWgtMzUuN2wtNDAuNy0xMjYuOUwyOTEsMzQ1LjFoLTM2LjJsLTQ5LjUtMTc4LjJIMjQybDMyLjcsMTIyLjZsMzkuNS0xMjIuNmgzNS45TDM4OS45LDI5MEw0MjIsMTY2LjloMzUuNEw0MDguMSwzNDUuMXoiLz48L2c+PC9zdmc+ ' ;
146
143
147
144
add_menu_page (
148
145
__ ( 'AutomateWoo ' , 'automatewoo ' ),
@@ -154,123 +151,67 @@ public static function admin_menu() {
154
151
$ position
155
152
);
156
153
157
- if ( class_exists ( Menu::class ) ) {
158
- Menu::add_plugin_category (
159
- array (
160
- 'id ' => 'automatewoo ' ,
161
- 'title ' => __ ( 'AutomateWoo ' , 'automatewoo ' ),
162
- 'capability ' => 'manage_woocommerce ' ,
163
- 'url ' => 'automatewoo ' ,
164
- )
165
- );
166
- Menu::add_plugin_category (
167
- [
168
- 'id ' => $ workflows_group ,
169
- 'title ' => __ ( 'Workflows ' , 'automatewoo ' ),
170
- 'capability ' => 'manage_woocommerce ' ,
171
- 'url ' => $ workflows_group ,
172
- 'parent ' => 'automatewoo ' ,
173
- 'order ' => 1 ,
174
- ]
175
- );
176
- }
177
-
178
154
$ sub_menu ['dashboard ' ] = [
179
155
'title ' => __ ( 'Dashboard ' , 'automatewoo ' ),
180
156
'function ' => [ __CLASS__ , 'load_controller ' ],
181
- 'order ' => 0 ,
182
157
];
183
158
184
159
// Workflows menu group
185
160
$ sub_menu ['workflows ' ] = [
186
- 'title ' => __ ( 'Workflows ' , 'automatewoo ' ),
187
- 'slug ' => 'edit.php?post_type=aw_workflow ' ,
188
- // Hide in new nav and use `\Automattic\WooCommerce\Admin\Features\Navigation\Menu::get_post_type_items` instead
189
- 'display ' => WCAdminConnectPages::PAGE_DISPLAY_HIDDEN ,
161
+ 'title ' => __ ( 'Workflows ' , 'automatewoo ' ),
162
+ 'slug ' => 'edit.php?post_type=aw_workflow ' ,
190
163
];
191
164
192
- if ( class_exists ( Screen::class ) ) {
193
- $ menu_post_type_items = Menu::get_post_type_items (
194
- 'aw_workflow ' ,
195
- [
196
- 'title ' => __ ( 'Workflows ' , 'automatewoo ' ),
197
- 'parent ' => $ workflows_group ,
198
- 'order ' => 0 ,
199
- ]
200
- );
201
-
202
- if ( isset ( $ menu_post_type_items ['all ' ] ) ) {
203
- Menu::add_plugin_item ( $ menu_post_type_items ['all ' ] );
204
- }
205
- if ( isset ( $ menu_post_type_items ['new ' ] ) ) {
206
- $ menu_post_type_items ['new ' ]['title ' ] = __ ( 'Add workflow ' , 'automatewoo ' );
207
- $ menu_post_type_items ['new ' ]['order ' ] = 1 ;
208
- Menu::add_plugin_item ( $ menu_post_type_items ['new ' ] );
209
- }
210
- }
211
-
212
165
$ sub_menu ['logs ' ] = [
213
166
'title ' => __ ( 'Logs ' , 'automatewoo ' ),
214
167
'function ' => [ __CLASS__ , 'load_controller ' ],
215
- 'parent ' => $ workflows_group ,
216
- 'order ' => 2 ,
217
168
];
218
169
$ sub_menu ['queue ' ] = [
219
170
'title ' => __ ( 'Queue ' , 'automatewoo ' ),
220
171
'function ' => [ __CLASS__ , 'load_controller ' ],
221
- 'parent ' => $ workflows_group ,
222
- 'order ' => 3 ,
223
172
];
224
173
225
174
if ( Options::abandoned_cart_enabled () ) {
226
175
$ sub_menu ['carts ' ] = [
227
176
'title ' => __ ( 'Carts ' , 'automatewoo ' ),
228
177
'function ' => [ __CLASS__ , 'load_controller ' ],
229
- 'order ' => 2 ,
230
178
];
231
179
}
232
180
233
181
$ sub_menu ['guests ' ] = [
234
182
'title ' => __ ( 'Guests ' , 'automatewoo ' ),
235
183
'function ' => [ __CLASS__ , 'load_controller ' ],
236
- 'order ' => 3 ,
237
184
];
238
185
239
186
$ sub_menu ['opt-ins ' ] = [
240
187
'title ' => Options::optin_enabled () ? __ ( 'Opt-ins ' , 'automatewoo ' ) : __ ( 'Opt-outs ' , 'automatewoo ' ),
241
188
'function ' => [ __CLASS__ , 'load_controller ' ],
242
- 'order ' => 4 ,
243
189
];
244
190
245
191
$ sub_menu ['reports ' ] = [
246
192
'title ' => __ ( 'Reports ' , 'automatewoo ' ),
247
193
'function ' => [ __CLASS__ , 'load_controller ' ],
248
- 'order ' => 5 ,
249
194
'enabled ' => ! HPOS_Helper::is_HPOS_enabled (),
250
195
];
251
196
252
197
$ sub_menu ['tools ' ] = [
253
198
'title ' => __ ( 'Tools ' , 'automatewoo ' ),
254
199
'function ' => [ __CLASS__ , 'load_controller ' ],
255
- 'order ' => 6 ,
256
200
];
257
201
258
202
$ sub_menu ['settings ' ] = [
259
203
'title ' => __ ( 'Settings ' , 'automatewoo ' ),
260
204
'function ' => [ __CLASS__ , 'load_controller ' ],
261
- 'order ' => 7 ,
262
205
];
263
206
264
207
$ sub_menu ['preview ' ] = [
265
208
'title ' => __ ( 'Preview ' , 'automatewoo ' ),
266
209
'function ' => [ __CLASS__ , 'load_controller ' ],
267
- 'display ' => WCAdminConnectPages::PAGE_DISPLAY_STANDALONE ,
268
210
];
269
211
270
212
$ sub_menu ['data-upgrade ' ] = [
271
213
'title ' => __ ( 'AutomateWoo Data Update ' , 'automatewoo ' ),
272
214
'function ' => [ __CLASS__ , 'page_data_upgrade ' ],
273
- 'display ' => WCAdminConnectPages::PAGE_DISPLAY_HIDDEN ,
274
215
];
275
216
276
217
foreach ( $ sub_menu as $ key => $ item ) {
@@ -286,31 +227,11 @@ public static function admin_menu() {
286
227
if ( empty ( $ item ['page_title ' ] ) ) {
287
228
$ item ['page_title ' ] = $ item ['title ' ];
288
229
}
289
- if ( ! isset ( $ item ['parent ' ] ) ) {
290
- $ item ['parent ' ] = 'automatewoo ' ;
291
- }
292
230
293
231
$ is_enabled = $ item ['enabled ' ] ?? true ;
294
232
295
233
add_submenu_page ( $ is_enabled ? 'automatewoo ' : 'automatewoo_disabled ' , $ item ['page_title ' ], $ item ['title ' ], $ item ['capability ' ], $ item ['slug ' ], $ item ['function ' ] );
296
234
297
- if ( class_exists ( Menu::class ) ) {
298
- if ( ! isset ( $ item ['display ' ] ) || WCAdminConnectPages::PAGE_DISPLAY_FULL === $ item ['display ' ] ) {
299
- Menu::add_plugin_item (
300
- array (
301
- 'id ' => 'automatewoo- ' . $ key ,
302
- 'parent ' => $ item ['parent ' ],
303
- 'title ' => $ item ['title ' ],
304
- 'capability ' => $ item ['capability ' ],
305
- 'url ' => $ item ['slug ' ],
306
- 'order ' => isset ( $ item ['order ' ] ) ? $ item ['order ' ] : 99 ,
307
- )
308
- );
309
- } elseif ( WCAdminConnectPages::PAGE_DISPLAY_HIDDEN === $ item ['display ' ] ) {
310
- Screen::add_screen ( $ item ['slug ' ] );
311
- }
312
- }
313
-
314
235
if ( $ key === 'workflows ' ) {
315
236
do_action ( 'automatewoo/admin/submenu_pages ' , 'automatewoo ' );
316
237
}
@@ -333,7 +254,7 @@ public static function admin_menu() {
333
254
* This is because we need to add .hide-if-js classname in the submenu for hide them in Calypso for wp.com
334
255
* The classes are usually loaded in position 4 in the submenu.
335
256
*
336
- * @see Menu::migrate_menu_items for a reference of how WC Admin loads this class.
257
+ * @see Menu::migrate_menu_items for a reference of how WC Admin loads this class. (https://github.com/woocommerce/woocommerce/blob/47e4d918c91ea980c41f4567e823256acbac4317/plugins/woocommerce/src/Admin/Features/Navigation/Menu.php#L636)
337
258
* @param array $menu Menu items
338
259
* @return array Menu items
339
260
*/
0 commit comments