66use AutomateWoo \Admin \AssetData ;
77use AutomateWoo \Admin \WCAdminConnectPages ;
88use AutomateWoo \HPOS_Helper ;
9- use Automattic \WooCommerce \Admin \Features \Navigation \Menu ;
10- use Automattic \WooCommerce \Admin \Features \Navigation \Screen ;
119use Automattic \WooCommerce \Admin \PageController ;
1210use Automattic \WooCommerce \Blocks \Assets \AssetDataRegistry ;
1311use Automattic \WooCommerce \Blocks \Package as BlocksPackage ;
@@ -139,10 +137,9 @@ public static function handle_save_screen_option( $keep, $option, $value ) {
139137 * Add menu entries.
140138 */
141139 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+PHBvbHlnb24gZmlsbD0iIzlFQTNBOCIgcG9pbnRzPSIxMTcuNiwyNzIuNyAxNjYuOSwyNzIuNyAxNDIuMywyMDUuNCAiLz48cGF0aCBmaWxsPSIjOUVBM0E4IiBkPSJNNDY0LDU0LjRINDhDMjUuMSw1NC40LDYuNCw3My4xLDYuNCw5NnYzMjBjMCwyMi45LDE4LjcsNDEuNiw0MS42LDQxLjZoNDE2YzIyLjksMCw0MS42LTE4LjcsNDEuNi00MS42Vjk2QzUwNS42LDczLjEsNDg2LjksNTQuNCw0NjQsNTQuNHogTTE5My4zLDM0NS4xbC0xNC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LjFIMTkzLjN6IE00MDguMSwzNDUuMWgtMzUuN2wtNDAuNy0xMjYuOUwyOTEsMzQ1LjFoLTM2LjJsLTQ5LjUtMTc4LjJIMjQybDMyLjcsMTIyLjZsMzkuNS0xMjIuNmgzNS45TDM4OS45LDI5MEw0MjIsMTY2LjloMzUuNEw0MDguMSwzNDUuMXoiLz48L2c+PC9zdmc+ ' ;
146143
147144 add_menu_page (
148145 __ ( 'AutomateWoo ' , 'automatewoo ' ),
@@ -154,123 +151,67 @@ public static function admin_menu() {
154151 $ position
155152 );
156153
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-
178154 $ sub_menu ['dashboard ' ] = [
179155 'title ' => __ ( 'Dashboard ' , 'automatewoo ' ),
180156 'function ' => [ __CLASS__ , 'load_controller ' ],
181- 'order ' => 0 ,
182157 ];
183158
184159 // Workflows menu group
185160 $ 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 ' ,
190163 ];
191164
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-
212165 $ sub_menu ['logs ' ] = [
213166 'title ' => __ ( 'Logs ' , 'automatewoo ' ),
214167 'function ' => [ __CLASS__ , 'load_controller ' ],
215- 'parent ' => $ workflows_group ,
216- 'order ' => 2 ,
217168 ];
218169 $ sub_menu ['queue ' ] = [
219170 'title ' => __ ( 'Queue ' , 'automatewoo ' ),
220171 'function ' => [ __CLASS__ , 'load_controller ' ],
221- 'parent ' => $ workflows_group ,
222- 'order ' => 3 ,
223172 ];
224173
225174 if ( Options::abandoned_cart_enabled () ) {
226175 $ sub_menu ['carts ' ] = [
227176 'title ' => __ ( 'Carts ' , 'automatewoo ' ),
228177 'function ' => [ __CLASS__ , 'load_controller ' ],
229- 'order ' => 2 ,
230178 ];
231179 }
232180
233181 $ sub_menu ['guests ' ] = [
234182 'title ' => __ ( 'Guests ' , 'automatewoo ' ),
235183 'function ' => [ __CLASS__ , 'load_controller ' ],
236- 'order ' => 3 ,
237184 ];
238185
239186 $ sub_menu ['opt-ins ' ] = [
240187 'title ' => Options::optin_enabled () ? __ ( 'Opt-ins ' , 'automatewoo ' ) : __ ( 'Opt-outs ' , 'automatewoo ' ),
241188 'function ' => [ __CLASS__ , 'load_controller ' ],
242- 'order ' => 4 ,
243189 ];
244190
245191 $ sub_menu ['reports ' ] = [
246192 'title ' => __ ( 'Reports ' , 'automatewoo ' ),
247193 'function ' => [ __CLASS__ , 'load_controller ' ],
248- 'order ' => 5 ,
249194 'enabled ' => ! HPOS_Helper::is_HPOS_enabled (),
250195 ];
251196
252197 $ sub_menu ['tools ' ] = [
253198 'title ' => __ ( 'Tools ' , 'automatewoo ' ),
254199 'function ' => [ __CLASS__ , 'load_controller ' ],
255- 'order ' => 6 ,
256200 ];
257201
258202 $ sub_menu ['settings ' ] = [
259203 'title ' => __ ( 'Settings ' , 'automatewoo ' ),
260204 'function ' => [ __CLASS__ , 'load_controller ' ],
261- 'order ' => 7 ,
262205 ];
263206
264207 $ sub_menu ['preview ' ] = [
265208 'title ' => __ ( 'Preview ' , 'automatewoo ' ),
266209 'function ' => [ __CLASS__ , 'load_controller ' ],
267- 'display ' => WCAdminConnectPages::PAGE_DISPLAY_STANDALONE ,
268210 ];
269211
270212 $ sub_menu ['data-upgrade ' ] = [
271213 'title ' => __ ( 'AutomateWoo Data Update ' , 'automatewoo ' ),
272214 'function ' => [ __CLASS__ , 'page_data_upgrade ' ],
273- 'display ' => WCAdminConnectPages::PAGE_DISPLAY_HIDDEN ,
274215 ];
275216
276217 foreach ( $ sub_menu as $ key => $ item ) {
@@ -286,31 +227,11 @@ public static function admin_menu() {
286227 if ( empty ( $ item ['page_title ' ] ) ) {
287228 $ item ['page_title ' ] = $ item ['title ' ];
288229 }
289- if ( ! isset ( $ item ['parent ' ] ) ) {
290- $ item ['parent ' ] = 'automatewoo ' ;
291- }
292230
293231 $ is_enabled = $ item ['enabled ' ] ?? true ;
294232
295233 add_submenu_page ( $ is_enabled ? 'automatewoo ' : 'automatewoo_disabled ' , $ item ['page_title ' ], $ item ['title ' ], $ item ['capability ' ], $ item ['slug ' ], $ item ['function ' ] );
296234
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-
314235 if ( $ key === 'workflows ' ) {
315236 do_action ( 'automatewoo/admin/submenu_pages ' , 'automatewoo ' );
316237 }
@@ -333,7 +254,7 @@ public static function admin_menu() {
333254 * This is because we need to add .hide-if-js classname in the submenu for hide them in Calypso for wp.com
334255 * The classes are usually loaded in position 4 in the submenu.
335256 *
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)
337258 * @param array $menu Menu items
338259 * @return array Menu items
339260 */
0 commit comments