PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 2.13.0
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v2.13.0
4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.11.1 1.11.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 2.0.0 2.0.1 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.13.0 2.14.0 2.14.1 2.15.0 2.15.1 2.16.0 2.16.1 2.16.2 2.16.3 2.17.0 2.17.1 2.17.2 2.18.0 2.19.0 2.19.2 2.19.3 2.19.4 2.2.0 2.2.1 2.20.0 2.20.1 2.20.2 2.20.3 2.20.4 2.20.5 2.20.6 2.21.0 2.22.0 2.22.1 2.23.0 2.24.0 2.25.0 2.25.1 2.25.2 2.26.0 2.27.0 2.27.1 2.28.0 2.29.0 2.29.1 2.29.2 2.29.3 2.29.4 2.3.0 2.3.1 2.30.0 2.31.0 2.31.1 2.31.2 2.31.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.40.0 2.40.1 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.9.0 3.0.0 3.0.0-RC1 3.0.0-RC2 3.0.0-beta1 3.0.0-beta2 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.10.0 3.10.1 3.11.0 3.12.0 3.13.0 3.13.1 3.13.2 3.13.3 3.13.4 3.14.0 3.15.0 3.15.1 3.15.2 3.15.3 3.15.4 3.15.5 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.16.6 3.16.7 3.16.8 3.17.0 3.17.1 3.17.2 3.17.3 3.17.4 3.17.5 3.17.6 3.18.0 3.19.0 3.19.1 3.19.2 3.2.0 3.2.1 3.2.2 3.20.0 3.20.1 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 trunk 4.1.0 0.2.19.1 4.1.1 1.0.0 4.2.0 1.0.1 1.0.2
surecart / app / src / WordPress / Admin / Menus / AdminMenuPageService.php
surecart / app / src / WordPress / Admin / Menus Last commit date
AdminMenuPageService.php 2 years ago AdminMenuPageServiceProvider.php 2 years ago ProductCollectionsMenuService.php 2 years ago
AdminMenuPageService.php
212 lines
1 <?php
2
3 namespace SureCart\WordPress\Admin\Menus;
4
5 use SureCart\Models\ApiToken;
6
7 /**
8 * Handles creation and enqueueing of admin menu pages and assets.
9 */
10 class AdminMenuPageService {
11 /**
12 * Top level menu slug.
13 *
14 * @var string
15 */
16 protected $slug = 'sc-dashboard';
17
18 /**
19 * Pages
20 *
21 * @var array
22 */
23 protected $pages = [];
24
25 /**
26 * Add menu items.
27 */
28 public function bootstrap() {
29 add_action( 'admin_menu', [ $this, 'registerAdminPages' ] );
30 add_action( 'admin_head', [ $this, 'adminMenuCSS' ] );
31 add_filter( 'parent_file', [ $this, 'forceSelect' ] );
32
33 // Admin bar menus.
34 if ( apply_filters( 'surecart_show_admin_bar_visit_store', true ) ) {
35 add_action( 'admin_bar_menu', array( $this, 'adminBarMenu' ), 31 );
36 }
37 }
38
39 /**
40 * Add the "Visit Store" link in admin bar main menu.
41 *
42 * @since 2.4.0
43 * @param WP_Admin_Bar $wp_admin_bar Admin bar instance.
44 */
45 public function adminBarMenu( $wp_admin_bar ) {
46 if ( ! is_admin() || ! is_admin_bar_showing() ) {
47 return;
48 }
49
50 // Show only when the user is a member of this site, or they're a super admin.
51 if ( ! is_user_member_of_blog() && ! is_super_admin() ) {
52 return;
53 }
54
55 // Don't display when shop page is the same of the page on front.
56 if ( intval( get_option( 'page_on_front' ) ) === \SureCart::pages()->getId( 'shop' ) ) {
57 return;
58 }
59
60 // Add an option to visit the store.
61 $wp_admin_bar->add_node(
62 array(
63 'parent' => 'site-name',
64 'id' => 'view-sc-store',
65 'title' => class_exists( 'WooCommerce' ) ? __( 'Visit SureCart Store', 'surecart' ) : __( 'Visit Store', 'surecart' ),
66 'href' => \SureCart::pages()->url( 'shop' ),
67 )
68 );
69 }
70
71 /**
72 * Make sure these menu items get selected.
73 *
74 * @param string $file The file string.
75 *
76 * @return string
77 */
78 public function forceSelect( $file ) {
79 global $submenu_file;
80 global $post;
81
82 if ( ! empty( $post->ID ) && in_array(
83 $post->ID,
84 [
85 \SureCart::pages()->getId( 'cart', 'sc_cart' ),
86 \SureCart::pages()->getId( 'checkout' ),
87 \SureCart::pages()->getId( 'shop' ),
88 \SureCart::pages()->getId( 'dashboard' ),
89 ]
90 ) ) {
91 $file = 'sc-dashboard';
92 // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
93 $submenu_file = 'post.php?post=' . (int) $post->ID . '&action=edit';
94 }
95
96 return $file;
97 }
98
99 /**
100 * Add some divider css.
101 *
102 * @return void
103 */
104 public function adminMenuCSS(): void {
105 echo '<style>
106 #toplevel_page_sc-dashboard li {
107 clear: both;
108 }
109 #toplevel_page_sc-dashboard li:not(:last-child) a[href^="admin.php?page=sc-customers"]:after {
110 border-bottom: 1px solid hsla(0,0%,100%,.2);
111 display: block;
112 float: left;
113 margin: 13px -15px 8px;
114 content: "";
115 width: calc(100% + 26px);
116 }
117 #toplevel_page_sc-dashboard li:not(:last-child) a[href^="admin.php?page=sc-dashboard"]:after {
118 border-bottom: 1px solid hsla(0,0%,100%,.2);
119 display: block;
120 float: left;
121 margin: 13px -15px 8px;
122 content: "";
123 width: calc(100% + 26px);
124 }
125 #toplevel_page_sc-dashboard li:not(:last-child) a[href^="edit.php?post_type=sc_form"]:after {
126 border-bottom: 1px solid hsla(0,0%,100%,.2);
127 display: block;
128 float: left;
129 margin: 13px -15px 8px;
130 content: "";
131 width: calc(100% + 26px);
132 }
133 </style>';
134 }
135
136 /**
137 * Register admin pages.
138 *
139 * @return void
140 */
141 public function registerAdminPages() {
142 $entitlements = \SureCart::account()->entitlements;
143 if ( ! ApiToken::get() ) {
144 $this->slug = 'sc-getting-started';
145 }
146
147 $logo = file_get_contents( plugin_dir_path( SURECART_PLUGIN_FILE ) . 'images/icon.svg' );
148 \add_menu_page( __( 'Dashboard', 'surecart' ), __( 'SureCart', 'surecart' ), 'manage_sc_shop_settings', $this->slug, '__return_false', 'data:image/svg+xml;base64,' . base64_encode( $logo ), 30.6001 );
149
150 // not yet installed.
151 if ( ! ApiToken::get() ) {
152 $this->pages = [
153 'get-started' => \add_submenu_page( $this->slug, __( 'Get Started', 'surecart' ), __( 'Get Started', 'surecart' ), 'manage_options', $this->slug, '__return_false' ),
154 'complete-signup' => \add_submenu_page( '', __( 'Complete Signup', 'surecart' ), __( 'Complete Signup', 'surecart' ), 'manage_options', 'sc-complete-signup', '__return_false' ),
155 'settings' => \add_submenu_page( $this->slug, __( 'Settings', 'surecart' ), __( 'Settings', 'surecart' ), 'manage_options', 'sc-settings', '__return_false' ),
156 ];
157 return;
158 }
159
160 $this->pages = [
161 'get-started' => \add_submenu_page( $this->slug, __( 'Dashboard', 'surecart' ), __( 'Dashboard', 'surecart' ), 'manage_sc_shop_settings', $this->slug, '__return_false' ),
162 'complete-signup' => \add_submenu_page( '', __( 'Complete Signup', 'surecart' ), __( 'Complete Signup', 'surecart' ), 'manage_options', 'sc-complete-signup', '__return_false' ),
163 'claim-account' => \add_submenu_page( '', __( 'Claim Account', 'surecart' ), __( 'Claim Account', 'surecart' ), 'manage_options', 'sc-claim-account', '__return_false' ),
164 'orders' => \add_submenu_page( $this->slug, __( 'Orders', 'surecart' ), __( 'Orders', 'surecart' ), 'edit_sc_orders', 'sc-orders', '__return_false' ),
165 'checkouts' => in_array( $_GET['page'] ?? '', [ 'sc-checkouts' ] ) ? \add_submenu_page( $this->slug, __( 'Checkouts', 'surecart' ), '' . __( 'Add New', 'surecart' ), 'edit_sc_orders', 'sc-checkouts', '__return_false' ) : null,
166 'abandoned' => in_array( $_GET['page'] ?? '', [ 'sc-orders', 'sc-abandoned-checkouts', 'sc-checkouts' ], true ) ? \add_submenu_page( $this->slug, __( 'Abandoned', 'surecart' ), '' . __( 'Abandoned', 'surecart' ), 'edit_sc_orders', 'sc-abandoned-checkouts', '__return_false' ) : null,
167 'products' => \add_submenu_page( $this->slug, __( 'Products', 'surecart' ), __( 'Products', 'surecart' ), 'edit_sc_products', 'sc-products', '__return_false' ),
168 'product-collections' => in_array( $_GET['page'] ?? '', [ 'sc-products', 'sc-product-groups', 'sc-bumps', 'sc-product-collections' ], true ) ? \add_submenu_page( $this->slug, __( 'Collections', 'surecart' ), '' . __( 'Collections', 'surecart' ), 'edit_sc_products', 'sc-product-collections', '__return_false' ) : null,
169 'bumps' => ! empty( $entitlements->bumps ) && in_array( $_GET['page'] ?? '', [ 'sc-products', 'sc-product-groups', 'sc-bumps', 'sc-product-collections' ] ) ? \add_submenu_page( $this->slug, __( 'Order Bumps', 'surecart' ), '' . __( 'Order Bumps', 'surecart' ), 'edit_sc_products', 'sc-bumps', '__return_false' ) : null,
170 'product-groups' => ! empty( $entitlements->product_groups ) && in_array( $_GET['page'] ?? '', [ 'sc-products', 'sc-product-groups', 'sc-bumps', 'sc-product-collections' ] ) ? \add_submenu_page( $this->slug, __( 'Upgrade Groups', 'surecart' ), '' . __( 'Upgrade Groups', 'surecart' ), 'edit_sc_products', 'sc-product-groups', '__return_false' ) : null,
171 'coupons' => \add_submenu_page( $this->slug, __( 'Coupons', 'surecart' ), __( 'Coupons', 'surecart' ), 'edit_sc_coupons', 'sc-coupons', '__return_false' ),
172 'licenses' => ! empty( $entitlements->licensing ) ? \add_submenu_page( $this->slug, __( 'Licenses', 'surecart' ), __( 'Licenses', 'surecart' ), 'edit_sc_products', 'sc-licenses', '__return_false' ) : null,
173 'subscriptions' => \add_submenu_page( $this->slug, __( 'Subscriptions', 'surecart' ), __( 'Subscriptions', 'surecart' ), 'edit_sc_subscriptions', 'sc-subscriptions', '__return_false' ),
174 'cancellations' => in_array( $_GET['page'] ?? '', [ 'sc-subscriptions', 'sc-cancellation-insights' ] ) ? \add_submenu_page( $this->slug, __( 'Cancellation Insights', 'surecart' ), '' . __( 'Cancellations', 'surecart' ), 'edit_sc_subscriptions', 'sc-cancellation-insights', '__return_false' ) : null,
175 'customers' => \add_submenu_page( $this->slug, __( 'Customers', 'surecart' ), __( 'Customers', 'surecart' ), 'edit_sc_customers', 'sc-customers', '__return_false' ),
176 'shop' => $this->getPage( 'shop', __( 'Shop', 'surecart' ) ),
177 'cart' => $this->getPage( 'cart', __( 'Cart', 'surecart' ), 'sc_cart' ),
178 'checkout' => $this->getPage( 'checkout', __( 'Checkout', 'surecart' ) ),
179 'dashboard' => $this->getPage( 'dashboard', __( 'Customer Area', 'surecart' ) ),
180 'forms' => \add_submenu_page( $this->slug, __( 'Forms', 'surecart' ), __( 'Custom Forms', 'surecart' ), 'edit_posts', 'edit.php?post_type=sc_form', '' ),
181 'settings' => \add_submenu_page( $this->slug, __( 'Settings', 'surecart' ), __( 'Settings', 'surecart' ), 'manage_options', 'sc-settings', '__return_false' ),
182 ];
183 }
184
185 /**
186 * Get the page link.
187 *
188 * @param string $slug The slug.
189 * @param string $name The name.
190 * @param string $post_type The post type.
191 *
192 * @return void
193 */
194 public function getPage( $slug, $name, $post_type = 'page' ) {
195 // add filter to disable shop page menu item.
196 if ( ! get_option( 'surecart_' . $slug . '_admin_menu', true ) ) {
197 return;
198 }
199
200 $page_id = \SureCart::pages()->getId( $slug, $post_type );
201
202 $status = '';
203
204 $post_status = get_post_status( $page_id );
205 if ( 'publish' !== $post_status ) {
206 $status = '<span class="awaiting-mod">' . ( get_post_status_object( $post_status )->label ?? esc_html__( 'Deleted', 'surecart' ) ) . '</span>';
207 }
208
209 return \add_submenu_page( $this->slug, $name, $name . $status, 'manage_options', 'post.php?post=' . (int) $page_id . '&action=edit', '' );
210 }
211 }
212