PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 2.22.1
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v2.22.1
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.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 All 281 releases
surecart / app / src / Permissions / AdminAccessService.php
AdminAccessService.php
58 lines 997 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\Permissions;
4
5 /**
6 * Admin Access Service
7 */
8 class AdminAccessService {
9
10 /**
11 * Admin access service construct
12 *
13 * @return void
14 */
15 public function bootstrap() {
16 add_action( 'admin_init', [ $this, 'handleAdminAccess' ] );
17 }
18
19 /**
20 * Prevent admin access
21 *
22 * @return method
23 */
24 public function handleAdminAccess() {
25 if ( ! $this->canAccessAdmin() ) {
26 return $this->redirectToAdmin();
27 }
28 }
29
30 /**
31 * Prevent admin access
32 *
33 * @return boolean
34 */
35 public function canAccessAdmin() {
36 if (
37 wp_doing_ajax() ||
38 ! isset( $_SERVER['SCRIPT_FILENAME'] ) ||
39 basename( sanitize_text_field( wp_unslash( $_SERVER['SCRIPT_FILENAME'] ) ) ) === 'admin-post.php' ||
40 current_user_can( 'edit_posts' )
41 ) {
42 return true;
43 }
44
45 return ! current_user_can( 'sc_customer' );
46 }
47
48 /**
49 * Redirect to the admin.
50 *
51 * @return void
52 */
53 public function redirectToAdmin() {
54 wp_safe_redirect( \SureCart::pages()->url( 'dashboard' ) );
55 exit;
56 }
57 }
58