-
Notifications
You must be signed in to change notification settings - Fork 64
/
class-cocart-admin-menus.php
131 lines (114 loc) · 3.3 KB
/
class-cocart-admin-menus.php
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
<?php
/**
* CoCart - Admin Menus.
*
* @author Sébastien Dumont
* @package CoCart\Admin\Menus
* @since 2.0.0
* @version 3.1.0
* @license GPL-2.0+
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'CoCart_Admin_Menus' ) ) {
class CoCart_Admin_Menus {
/**
* Constructor
*
* @access public
*/
public function __construct() {
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
} // END __construct()
/**
* Add CoCart to the menu and register WooCommerce admin bar.
*
* @access public
* @since 2.0.0
* @version 3.1.0
*/
public function admin_menu() {
$section = ! isset( $_GET['section'] ) ? 'getting-started' : trim( sanitize_key( wp_unslash( $_GET['section'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
switch ( $section ) {
default:
$title = apply_filters( 'cocart_page_title_' . strtolower( str_replace( '-', '_', $section ) ), 'CoCart' );
$breadcrumb = apply_filters( 'cocart_page_wc_bar_breadcrumb_' . strtolower( str_replace( '-', '_', $section ) ), '' );
break;
}
$page = admin_url( 'admin.php' );
// Add CoCart page.
add_menu_page(
$title,
'CoCart',
apply_filters( 'cocart_screen_capability', 'manage_options' ),
'cocart',
array( $this, 'cocart_page' ),
'dashicons-cart'
);
// Add Setup Wizard as sub-menu.
if ( apply_filters( 'cocart_enable_setup_wizard', true ) ) {
add_submenu_page(
'cocart',
'',
esc_attr__( 'Setup Wizard', 'cart-rest-api-for-woocommerce' ),
apply_filters( 'cocart_screen_capability', 'manage_options' ),
admin_url( 'admin.php?page=cocart-setup' )
);
}
// Register WooCommerce Admin Bar.
if ( CoCart_Helpers::is_wc_version_gte( '4.0' ) && function_exists( 'wc_admin_connect_page' ) ) {
wc_admin_connect_page(
array(
'id' => 'cocart-getting-started',
'screen_id' => 'toplevel_page_cocart',
'title' => array(
esc_html__( 'CoCart', 'cart-rest-api-for-woocommerce' ),
$breadcrumb,
),
'path' => add_query_arg(
array(
'page' => 'cocart',
'section' => $section,
),
$page
),
)
);
}
/**
* Moves CoCart menu to the new WooCommerce Navigation Menu if it exists.
*
* @since 3.0.0
*/
if ( class_exists( '\Automattic\WooCommerce\Admin\Features\Navigation\Menu' ) && apply_filters( 'cocart_wc_navigation', true ) ) {
// Add Category.
Automattic\WooCommerce\Admin\Features\Navigation\Menu::add_plugin_category(
array(
'id' => 'cocart-category',
'title' => 'CoCart',
'parent' => 'woocommerce',
)
);
}
} // END admin_menu()
/**
* CoCart Page
*
* @access public
* @static
* @since 2.0.1
* @version 2.6.0
*/
public static function cocart_page() {
$section = ! isset( $_GET['section'] ) ? 'getting-started' : trim( sanitize_key( wp_unslash( $_GET['section'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
switch ( $section ) {
default:
do_action( 'cocart_page_section_' . strtolower( str_replace( '-', '_', $section ) ) );
break;
}
} // END cocart_page()
} // END class
} // END if class exists
return new CoCart_Admin_Menus();