2013-07-24 16:01:36 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Setup menus in WP admin.
|
|
|
|
*
|
2014-11-30 06:52:32 +00:00
|
|
|
* @author WooThemes
|
|
|
|
* @category Admin
|
|
|
|
* @package WooCommerce/Admin
|
2014-09-16 02:32:34 +00:00
|
|
|
* @version 2.2.3
|
2013-07-24 16:01:36 +00:00
|
|
|
*/
|
|
|
|
|
2014-09-16 02:32:34 +00:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit; // Exit if accessed directly
|
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
|
|
|
|
if ( ! class_exists( 'WC_Admin_Menus' ) ) :
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WC_Admin_Menus Class
|
|
|
|
*/
|
|
|
|
class WC_Admin_Menus {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook in tabs.
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
|
|
|
// Add menus
|
|
|
|
add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 );
|
|
|
|
add_action( 'admin_menu', array( $this, 'reports_menu' ), 20 );
|
|
|
|
add_action( 'admin_menu', array( $this, 'settings_menu' ), 50 );
|
|
|
|
add_action( 'admin_menu', array( $this, 'status_menu' ), 60 );
|
|
|
|
|
2014-04-29 13:03:10 +00:00
|
|
|
if ( apply_filters( 'woocommerce_show_addons_page', true ) ) {
|
2013-08-06 13:04:24 +00:00
|
|
|
add_action( 'admin_menu', array( $this, 'addons_menu' ), 70 );
|
2014-04-29 13:03:10 +00:00
|
|
|
}
|
2013-08-06 13:04:24 +00:00
|
|
|
|
2013-07-24 16:01:36 +00:00
|
|
|
add_action( 'admin_head', array( $this, 'menu_highlight' ) );
|
|
|
|
add_filter( 'menu_order', array( $this, 'menu_order' ) );
|
|
|
|
add_filter( 'custom_menu_order', array( $this, 'custom_menu_order' ) );
|
2014-09-19 07:06:28 +00:00
|
|
|
|
|
|
|
// Add endpoints custom URLs in Appearance > Menus > Pages
|
2014-10-17 13:42:35 +00:00
|
|
|
add_action('admin_init', array( $this, 'add_nav_menu_meta_boxes' ) );
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add menu items
|
|
|
|
*/
|
|
|
|
public function admin_menu() {
|
2014-06-08 20:33:11 +00:00
|
|
|
global $menu;
|
2013-07-24 16:01:36 +00:00
|
|
|
|
2014-09-16 02:32:34 +00:00
|
|
|
if ( current_user_can( 'manage_woocommerce' ) ) {
|
|
|
|
$menu[] = array( '', 'read', 'separator-woocommerce', '', 'wp-menu-separator woocommerce' );
|
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
|
2014-11-18 12:42:54 +00:00
|
|
|
add_menu_page( __( 'WooCommerce', 'woocommerce' ), __( 'WooCommerce', 'woocommerce' ), 'manage_woocommerce', 'woocommerce', null, null, '55.5' );
|
2013-07-24 16:01:36 +00:00
|
|
|
|
2014-11-04 19:49:15 +00:00
|
|
|
add_submenu_page( 'edit.php?post_type=product', __( 'Shipping Classes', 'woocommerce' ), __( 'Shipping Classes', 'woocommerce' ), 'manage_product_terms', 'edit-tags.php?taxonomy=product_shipping_class&post_type=product' );
|
|
|
|
|
2014-09-16 02:32:34 +00:00
|
|
|
add_submenu_page( 'edit.php?post_type=product', __( 'Attributes', 'woocommerce' ), __( 'Attributes', 'woocommerce' ), 'manage_product_terms', 'product_attributes', array( $this, 'attributes_page' ) );
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add menu item
|
|
|
|
*/
|
|
|
|
public function reports_menu() {
|
2013-10-22 16:26:18 +00:00
|
|
|
add_submenu_page( 'woocommerce', __( 'Reports', 'woocommerce' ), __( 'Reports', 'woocommerce' ) , 'view_woocommerce_reports', 'wc-reports', array( $this, 'reports_page' ) );
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add menu item
|
|
|
|
*/
|
|
|
|
public function settings_menu() {
|
2013-10-22 16:26:18 +00:00
|
|
|
$settings_page = add_submenu_page( 'woocommerce', __( 'WooCommerce Settings', 'woocommerce' ), __( 'Settings', 'woocommerce' ) , 'manage_woocommerce', 'wc-settings', array( $this, 'settings_page' ) );
|
2013-07-24 16:01:36 +00:00
|
|
|
|
|
|
|
add_action( 'load-' . $settings_page, array( $this, 'settings_page_init' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads gateways and shipping methods into memory for use within settings.
|
|
|
|
*/
|
|
|
|
public function settings_page_init() {
|
2013-07-26 14:36:28 +00:00
|
|
|
WC()->payment_gateways();
|
|
|
|
WC()->shipping();
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add menu item
|
|
|
|
*/
|
|
|
|
public function status_menu() {
|
2013-10-22 16:26:18 +00:00
|
|
|
add_submenu_page( 'woocommerce', __( 'WooCommerce Status', 'woocommerce' ), __( 'System Status', 'woocommerce' ) , 'manage_woocommerce', 'wc-status', array( $this, 'status_page' ) );
|
2013-10-23 15:52:58 +00:00
|
|
|
register_setting( 'woocommerce_status_settings_fields', 'woocommerce_status_options' );
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 13:04:24 +00:00
|
|
|
/**
|
|
|
|
* Addons menu item
|
|
|
|
*/
|
|
|
|
public function addons_menu() {
|
2013-10-22 16:26:18 +00:00
|
|
|
add_submenu_page( 'woocommerce', __( 'WooCommerce Add-ons/Extensions', 'woocommerce' ), __( 'Add-ons', 'woocommerce' ) , 'manage_woocommerce', 'wc-addons', array( $this, 'addons_page' ) );
|
2013-08-06 13:04:24 +00:00
|
|
|
}
|
|
|
|
|
2013-07-24 16:01:36 +00:00
|
|
|
/**
|
|
|
|
* Highlights the correct top level admin menu item for post type add screens.
|
|
|
|
*/
|
|
|
|
public function menu_highlight() {
|
|
|
|
global $menu, $submenu, $parent_file, $submenu_file, $self, $post_type, $taxonomy;
|
|
|
|
|
2015-01-07 00:08:24 +00:00
|
|
|
$to_highlight_types = array( 'shop_order', 'shop_coupon' );
|
2013-07-24 16:01:36 +00:00
|
|
|
|
|
|
|
if ( isset( $post_type ) ) {
|
|
|
|
if ( in_array( $post_type, $to_highlight_types ) ) {
|
|
|
|
$submenu_file = 'edit.php?post_type=' . esc_attr( $post_type );
|
|
|
|
$parent_file = 'woocommerce';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( 'product' == $post_type ) {
|
|
|
|
$screen = get_current_screen();
|
|
|
|
|
|
|
|
if ( $screen->base == 'edit-tags' && taxonomy_is_product_attribute( $taxonomy ) ) {
|
2013-10-22 15:46:59 +00:00
|
|
|
$submenu_file = 'product_attributes';
|
2013-07-24 16:01:36 +00:00
|
|
|
$parent_file = 'edit.php?post_type=' . esc_attr( $post_type );
|
|
|
|
}
|
2014-11-04 19:49:15 +00:00
|
|
|
|
|
|
|
// Fix the highlight of shipping classes menu
|
|
|
|
if ( 'product_shipping_class' == $screen->taxonomy && $parent_file == 'edit.php?post_type=product' ) {
|
|
|
|
$submenu_file = 'edit-tags.php?taxonomy=product_shipping_class&post_type=product';
|
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isset( $submenu['woocommerce'] ) && isset( $submenu['woocommerce'][1] ) ) {
|
|
|
|
$submenu['woocommerce'][0] = $submenu['woocommerce'][1];
|
|
|
|
unset( $submenu['woocommerce'][1] );
|
|
|
|
}
|
|
|
|
|
2014-09-16 22:03:50 +00:00
|
|
|
if ( isset( $submenu['woocommerce'] ) && current_user_can( 'manage_woocommerce' ) ) {
|
2014-09-16 02:32:34 +00:00
|
|
|
foreach ( $submenu['woocommerce'] as $key => $menu_item ) {
|
|
|
|
if ( 0 === strpos( $menu_item[0], _x( 'Orders', 'Admin menu name', 'woocommerce' ) ) ) {
|
2013-07-24 16:01:36 +00:00
|
|
|
|
2014-09-16 02:32:34 +00:00
|
|
|
$menu_name = _x( 'Orders', 'Admin menu name', 'woocommerce' );
|
2013-11-25 13:54:52 +00:00
|
|
|
if ( $order_count = wc_processing_order_count() ) {
|
2014-09-16 02:32:34 +00:00
|
|
|
$menu_name .= ' <span class="awaiting-mod update-plugins count-' . $order_count . '"><span class="processing-count">' . number_format_i18n( $order_count ) . '</span></span>';
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
2014-09-16 02:32:34 +00:00
|
|
|
$submenu['woocommerce'][ $key ] [0] = $menu_name;
|
2013-07-24 16:01:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reorder the WC menu items in admin.
|
|
|
|
*
|
|
|
|
* @param mixed $menu_order
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function menu_order( $menu_order ) {
|
|
|
|
// Initialize our custom order array
|
|
|
|
$woocommerce_menu_order = array();
|
|
|
|
|
|
|
|
// Get the index of our custom separator
|
|
|
|
$woocommerce_separator = array_search( 'separator-woocommerce', $menu_order );
|
|
|
|
|
|
|
|
// Get index of product menu
|
|
|
|
$woocommerce_product = array_search( 'edit.php?post_type=product', $menu_order );
|
|
|
|
|
|
|
|
// Loop through menu order and do some rearranging
|
2014-09-16 02:32:34 +00:00
|
|
|
foreach ( $menu_order as $index => $item ) {
|
2013-07-24 16:01:36 +00:00
|
|
|
|
2014-09-16 02:32:34 +00:00
|
|
|
if ( ( ( 'woocommerce' ) == $item ) ) {
|
2013-07-24 16:01:36 +00:00
|
|
|
$woocommerce_menu_order[] = 'separator-woocommerce';
|
|
|
|
$woocommerce_menu_order[] = $item;
|
|
|
|
$woocommerce_menu_order[] = 'edit.php?post_type=product';
|
|
|
|
unset( $menu_order[$woocommerce_separator] );
|
|
|
|
unset( $menu_order[$woocommerce_product] );
|
2014-09-16 02:32:34 +00:00
|
|
|
} elseif ( !in_array( $item, array( 'separator-woocommerce' ) ) ) {
|
2013-07-24 16:01:36 +00:00
|
|
|
$woocommerce_menu_order[] = $item;
|
2014-09-16 02:32:34 +00:00
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
|
2014-09-16 02:32:34 +00:00
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
|
|
|
|
// Return order
|
|
|
|
return $woocommerce_menu_order;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-16 02:32:34 +00:00
|
|
|
* Custom menu order
|
|
|
|
*
|
2013-07-24 16:01:36 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function custom_menu_order() {
|
2014-11-17 14:15:01 +00:00
|
|
|
return current_user_can( 'manage_woocommerce' );
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Init the reports page
|
|
|
|
*/
|
|
|
|
public function reports_page() {
|
2014-03-20 11:10:25 +00:00
|
|
|
WC_Admin_Reports::output();
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Init the settings page
|
|
|
|
*/
|
|
|
|
public function settings_page() {
|
2013-07-26 14:36:28 +00:00
|
|
|
WC_Admin_Settings::output();
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Init the attributes page
|
|
|
|
*/
|
|
|
|
public function attributes_page() {
|
2014-06-04 10:16:19 +00:00
|
|
|
WC_Admin_Attributes::output();
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-08-06 13:04:24 +00:00
|
|
|
* Init the status page
|
2013-07-24 16:01:36 +00:00
|
|
|
*/
|
|
|
|
public function status_page() {
|
2014-06-04 10:16:19 +00:00
|
|
|
WC_Admin_Status::output();
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
2013-08-06 13:04:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Init the addons page
|
|
|
|
*/
|
|
|
|
public function addons_page() {
|
2014-06-04 10:16:19 +00:00
|
|
|
WC_Admin_Addons::output();
|
2013-08-06 13:04:24 +00:00
|
|
|
}
|
2014-09-19 07:06:28 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-17 13:42:35 +00:00
|
|
|
* Add custom nav meta box
|
2014-09-19 07:06:28 +00:00
|
|
|
*
|
2014-10-17 13:42:35 +00:00
|
|
|
* Adapted from http://www.johnmorrisonline.com/how-to-add-a-fully-functional-custom-meta-box-to-wordpress-navigation-menus/
|
2014-09-19 07:06:28 +00:00
|
|
|
*/
|
2014-10-17 13:42:35 +00:00
|
|
|
public function add_nav_menu_meta_boxes() {
|
|
|
|
add_meta_box( 'woocommerce_endpoints_nav_link', __( 'WooCommerce Endpoints', 'woocommerce' ), array( $this, 'nav_menu_links' ), 'nav-menus', 'side', 'low' );
|
|
|
|
}
|
2014-09-19 07:06:28 +00:00
|
|
|
|
2014-10-17 13:42:35 +00:00
|
|
|
public function nav_menu_links() {
|
|
|
|
$exclude = array( 'view-order', 'add-payment-method', 'order-pay', 'order-received' );
|
|
|
|
?>
|
|
|
|
<div id="posttype-woocommerce-endpoints" class="posttypediv">
|
2014-11-30 06:52:32 +00:00
|
|
|
<div id="tabs-panel-woocommerce-endpoints" class="tabs-panel tabs-panel-active">
|
|
|
|
<ul id="woocommerce-endpoints-checklist" class="categorychecklist form-no-clear">
|
|
|
|
<?php
|
|
|
|
$i = -1;
|
|
|
|
foreach ( WC()->query->query_vars as $key => $value ) {
|
|
|
|
if ( in_array( $key, $exclude ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
<li>
|
|
|
|
<label class="menu-item-title">
|
|
|
|
<input type="checkbox" class="menu-item-checkbox" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-object-id]" value="<?php echo esc_attr( $i ); ?>" /> <?php echo esc_html( $key ); ?>
|
|
|
|
</label>
|
|
|
|
<input type="hidden" class="menu-item-type" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-type]" value="custom" />
|
|
|
|
<input type="hidden" class="menu-item-title" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-title]" value="<?php echo esc_html( $key ); ?>" />
|
|
|
|
<input type="hidden" class="menu-item-url" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-url]" value="<?php echo esc_url( wc_get_endpoint_url( $key, '', get_permalink( wc_get_page_id( 'myaccount' ) ) ) ); ?>" />
|
|
|
|
<input type="hidden" class="menu-item-classes" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-classes]" />
|
|
|
|
</li>
|
|
|
|
<?php
|
|
|
|
$i --;
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<p class="button-controls">
|
|
|
|
<span class="list-controls">
|
|
|
|
<a href="<?php echo admin_url( 'nav-menus.php?page-tab=all&selectall=1#posttype-woocommerce-endpoints' ); ?>" class="select-all"><?php _e( 'Select All', 'woocommerce' ); ?></a>
|
|
|
|
</span>
|
|
|
|
<span class="add-to-menu">
|
|
|
|
<input type="submit" class="button-secondary submit-add-to-menu right" value="<?php _e( 'Add to Menu', 'woocommerce' ); ?>" name="add-post-type-menu-item" id="submit-posttype-woocommerce-endpoints">
|
|
|
|
<span class="spinner"></span>
|
|
|
|
</span>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<?php
|
2014-09-19 07:06:28 +00:00
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
endif;
|
|
|
|
|
2014-06-27 23:08:30 +00:00
|
|
|
return new WC_Admin_Menus();
|