2013-07-24 16:01:36 +00:00
|
|
|
<?php
|
2014-02-05 15:02:30 +00:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit; // Exit if accessed directly
|
|
|
|
}
|
|
|
|
|
2013-07-24 16:01:36 +00:00
|
|
|
/**
|
|
|
|
* WooCommerce Admin.
|
|
|
|
*
|
2014-02-05 15:02:30 +00:00
|
|
|
* @class WC_Admin
|
2013-07-24 16:01:36 +00:00
|
|
|
* @author WooThemes
|
|
|
|
* @category Admin
|
|
|
|
* @package WooCommerce/Admin
|
|
|
|
* @version 2.1.0
|
|
|
|
*/
|
|
|
|
class WC_Admin {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
2013-11-07 09:53:24 +00:00
|
|
|
add_action( 'init', array( $this, 'includes' ) );
|
|
|
|
add_action( 'current_screen', array( $this, 'conditonal_includes' ) );
|
2013-08-06 15:56:15 +00:00
|
|
|
add_action( 'admin_init', array( $this, 'prevent_admin_access' ) );
|
|
|
|
add_action( 'wp_ajax_page_slurp', array( 'WC_Gateway_Mijireh', 'page_slurp' ) );
|
|
|
|
add_action( 'admin_init', array( $this, 'preview_emails' ) );
|
2013-09-12 13:41:02 +00:00
|
|
|
add_action( 'admin_footer', 'wc_print_js', 25 );
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Include any classes we need within admin.
|
|
|
|
*/
|
|
|
|
public function includes() {
|
|
|
|
// Functions
|
2014-01-21 11:24:48 +00:00
|
|
|
include_once( 'wc-admin-functions.php' );
|
|
|
|
include_once( 'wc-meta-box-functions.php' );
|
2013-07-24 16:01:36 +00:00
|
|
|
|
|
|
|
// Classes
|
2014-02-05 15:02:30 +00:00
|
|
|
include_once( 'class-wc-admin-post-types.php' );
|
|
|
|
include_once( 'class-wc-admin-taxonomies.php' );
|
2013-07-24 16:01:36 +00:00
|
|
|
|
2013-12-05 15:34:37 +00:00
|
|
|
// Classes we only need if the ajax is not-ajax
|
|
|
|
if ( ! is_ajax() ) {
|
|
|
|
include( 'class-wc-admin-menus.php' );
|
|
|
|
include( 'class-wc-admin-welcome.php' );
|
|
|
|
include( 'class-wc-admin-notices.php' );
|
|
|
|
include( 'class-wc-admin-assets.php' );
|
|
|
|
include( 'class-wc-admin-permalink-settings.php' );
|
|
|
|
|
|
|
|
// Help
|
|
|
|
if ( apply_filters( 'woocommerce_enable_admin_help_tab', true ) )
|
|
|
|
include( 'class-wc-admin-help.php' );
|
|
|
|
}
|
2013-10-22 17:20:33 +00:00
|
|
|
|
2013-07-24 16:01:36 +00:00
|
|
|
// Importers
|
|
|
|
if ( defined( 'WP_LOAD_IMPORTERS' ) )
|
|
|
|
include( 'class-wc-admin-importers.php' );
|
|
|
|
}
|
|
|
|
|
2013-08-06 15:56:15 +00:00
|
|
|
/**
|
|
|
|
* Include admin files conditionally
|
|
|
|
*/
|
2013-07-24 16:01:36 +00:00
|
|
|
public function conditonal_includes() {
|
|
|
|
$screen = get_current_screen();
|
|
|
|
|
|
|
|
switch ( $screen->id ) {
|
|
|
|
case 'dashboard' :
|
2013-07-25 14:00:23 +00:00
|
|
|
include( 'class-wc-admin-dashboard.php' );
|
2013-07-24 16:01:36 +00:00
|
|
|
break;
|
|
|
|
case 'users' :
|
|
|
|
case 'user' :
|
|
|
|
case 'profile' :
|
2013-11-23 18:41:10 +00:00
|
|
|
case 'user-edit' :
|
2013-07-24 18:55:02 +00:00
|
|
|
include( 'class-wc-admin-profile.php' );
|
2013-07-24 16:01:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-06 15:56:15 +00:00
|
|
|
/**
|
|
|
|
* Prevent any user who cannot 'edit_posts' (subscribers, customers etc) from accessing admin
|
|
|
|
*/
|
|
|
|
public function prevent_admin_access() {
|
|
|
|
$prevent_access = false;
|
|
|
|
|
2013-09-24 14:21:40 +00:00
|
|
|
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' ) {
|
2013-08-06 15:56:15 +00:00
|
|
|
$prevent_access = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$prevent_access = apply_filters( 'woocommerce_prevent_admin_access', $prevent_access );
|
|
|
|
|
|
|
|
if ( $prevent_access ) {
|
2013-11-25 14:07:22 +00:00
|
|
|
wp_safe_redirect( get_permalink( wc_get_page_id( 'myaccount' ) ) );
|
2013-08-06 15:56:15 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Preview email template
|
|
|
|
* @return [type]
|
|
|
|
*/
|
|
|
|
public function preview_emails() {
|
|
|
|
if ( isset( $_GET['preview_woocommerce_mail'] ) ) {
|
|
|
|
if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'preview-mail') )
|
|
|
|
die( 'Security check' );
|
|
|
|
|
|
|
|
global $email_heading;
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
|
|
|
|
include( 'views/html-email-template-preview.php' );
|
|
|
|
|
|
|
|
$mailer = WC()->mailer();
|
|
|
|
$message = ob_get_clean();
|
2013-10-31 15:07:43 +00:00
|
|
|
$email_heading = __( 'HTML Email Template', 'woocommerce' );
|
2013-08-06 15:56:15 +00:00
|
|
|
|
|
|
|
echo $mailer->wrap_message( $email_heading, $message );
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
2014-02-05 15:02:30 +00:00
|
|
|
return new WC_Admin();
|