1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 7 8 9 10 11 12 13 14
15 class WC_Admin {
16
17 18 19
20 public function __construct() {
21 add_action( 'init', array( $this, 'includes' ) );
22 add_action( 'current_screen', array( $this, 'conditonal_includes' ) );
23 add_action( 'admin_init', array( $this, 'prevent_admin_access' ) );
24 add_action( 'wp_ajax_page_slurp', array( 'WC_Gateway_Mijireh', 'page_slurp' ) );
25 add_action( 'admin_init', array( $this, 'preview_emails' ) );
26 add_action( 'admin_footer', 'wc_print_js', 25 );
27 }
28
29 30 31
32 public function includes() {
33
34 include_once( 'wc-admin-functions.php' );
35 include_once( 'wc-meta-box-functions.php' );
36
37
38 include_once( 'class-wc-admin-post-types.php' );
39 include_once( 'class-wc-admin-taxonomies.php' );
40
41
42 if ( ! is_ajax() ) {
43 include( 'class-wc-admin-menus.php' );
44 include( 'class-wc-admin-welcome.php' );
45 include( 'class-wc-admin-notices.php' );
46 include( 'class-wc-admin-assets.php' );
47 include( 'class-wc-admin-permalink-settings.php' );
48 include( 'class-wc-admin-editor.php' );
49
50
51 if ( apply_filters( 'woocommerce_enable_admin_help_tab', true ) )
52 include( 'class-wc-admin-help.php' );
53 }
54
55
56 if ( defined( 'WP_LOAD_IMPORTERS' ) )
57 include( 'class-wc-admin-importers.php' );
58 }
59
60 61 62
63 public function conditonal_includes() {
64 $screen = get_current_screen();
65
66 switch ( $screen->id ) {
67 case 'dashboard' :
68 include( 'class-wc-admin-dashboard.php' );
69 break;
70 case 'users' :
71 case 'user' :
72 case 'profile' :
73 case 'user-edit' :
74 include( 'class-wc-admin-profile.php' );
75 break;
76 }
77 }
78
79 80 81
82 public function prevent_admin_access() {
83 $prevent_access = false;
84
85 if ( 'yes' == get_option( 'woocommerce_lock_down_admin' ) && ! is_ajax() && ! ( current_user_can( 'edit_posts' ) || current_user_can( 'manage_woocommerce' ) ) && basename( $_SERVER["SCRIPT_FILENAME"] ) !== 'admin-post.php' ) {
86 $prevent_access = true;
87 }
88
89 $prevent_access = apply_filters( 'woocommerce_prevent_admin_access', $prevent_access );
90
91 if ( $prevent_access ) {
92 wp_safe_redirect( get_permalink( wc_get_page_id( 'myaccount' ) ) );
93 exit;
94 }
95 }
96
97 98 99 100
101 public function preview_emails() {
102 if ( isset( $_GET['preview_woocommerce_mail'] ) ) {
103 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'preview-mail') )
104 die( 'Security check' );
105
106 global $email_heading;
107
108 ob_start();
109
110 include( 'views/html-email-template-preview.php' );
111
112 $mailer = WC()->mailer();
113 $message = ob_get_clean();
114 $email_heading = __( 'HTML Email Template', 'woocommerce' );
115
116 echo $mailer->wrap_message( $email_heading, $message );
117 exit;
118 }
119 }
120 }
121
122 return new WC_Admin();