2011-12-12 16:34:56 +00:00
< ? php
/**
* WooCommerce Admin
2012-08-01 12:43:46 +00:00
*
2011-12-12 16:34:56 +00:00
* Main admin file which loads all settings panels and sets up admin menus .
*
* @ author WooThemes
* @ category Admin
2012-08-14 12:21:34 +00:00
* @ package WooCommerce / Admin
* @ version 1.6 . 4
2011-12-12 16:34:56 +00:00
*/
2012-10-15 10:32:24 +00:00
if ( ! defined ( 'ABSPATH' ) ) exit ; // Exit if accessed directly
2012-08-15 18:15:06 +00:00
/**
* Functions for the product post type
*/
2012-08-14 12:21:34 +00:00
include_once ( 'post-types/product.php' );
2012-08-15 18:15:06 +00:00
/**
* Functions for the shop_coupon post type
*/
2012-08-14 12:21:34 +00:00
include_once ( 'post-types/shop_coupon.php' );
2012-08-15 18:15:06 +00:00
/**
* Functions for the shop_order post type
*/
2012-08-14 12:21:34 +00:00
include_once ( 'post-types/shop_order.php' );
2012-08-15 18:15:06 +00:00
/**
* Hooks in admin
*/
2012-08-14 12:21:34 +00:00
include_once ( 'woocommerce-admin-hooks.php' );
2012-08-15 18:15:06 +00:00
/**
* Functions in admin
*/
2012-08-14 12:21:34 +00:00
include_once ( 'woocommerce-admin-functions.php' );
2012-08-15 18:15:06 +00:00
/**
* Functions for handling taxonomies
*/
2012-08-14 12:21:34 +00:00
include_once ( 'woocommerce-admin-taxonomies.php' );
2011-12-12 16:34:56 +00:00
/**
2012-08-14 12:21:34 +00:00
* Setup the Admin menu in WordPress
2012-08-01 12:43:46 +00:00
*
2012-08-14 12:21:34 +00:00
* @ access public
* @ return void
2011-12-12 16:34:56 +00:00
*/
function woocommerce_admin_menu () {
2012-05-28 00:22:42 +00:00
global $menu , $woocommerce ;
2012-08-01 12:43:46 +00:00
if ( current_user_can ( 'manage_woocommerce' ) )
2012-05-28 00:22:42 +00:00
$menu [] = array ( '' , 'read' , 'separator-woocommerce' , '' , 'wp-menu-separator woocommerce' );
2012-08-01 12:43:46 +00:00
2012-10-16 09:45:33 +00:00
$main_page = add_menu_page ( __ ( 'WooCommerce' , 'woocommerce' ), __ ( 'WooCommerce' , 'woocommerce' ), 'manage_woocommerce' , 'woocommerce' , 'woocommerce_settings_page' , null , '55.5' );
2012-08-01 12:43:46 +00:00
2012-10-16 09:45:33 +00:00
$reports_page = add_submenu_page ( 'woocommerce' , __ ( 'Reports' , 'woocommerce' ), __ ( 'Reports' , 'woocommerce' ) , 'view_woocommerce_reports' , 'woocommerce_reports' , 'woocommerce_reports_page' );
2012-08-01 12:43:46 +00:00
2012-10-16 09:45:33 +00:00
add_submenu_page ( 'edit.php?post_type=product' , __ ( 'Attributes' , 'woocommerce' ), __ ( 'Attributes' , 'woocommerce' ), 'manage_product_terms' , 'woocommerce_attributes' , 'woocommerce_attributes_page' );
2012-08-01 12:43:46 +00:00
2012-03-23 16:28:27 +00:00
add_action ( 'load-' . $main_page , 'woocommerce_admin_help_tab' );
add_action ( 'load-' . $reports_page , 'woocommerce_admin_help_tab' );
2012-08-01 12:43:46 +00:00
2012-08-22 18:22:22 +00:00
$print_css_on = apply_filters ( 'woocommerce_screen_ids' , array ( 'toplevel_page_woocommerce' , 'woocommerce_page_woocommerce_settings' , 'woocommerce_page_woocommerce_reports' , 'woocommerce_page_woocommerce_status' , 'product_page_woocommerce_attributes' , 'edit-tags.php' , 'edit.php' , 'index.php' , 'post-new.php' , 'post.php' ) );
2012-08-01 12:43:46 +00:00
foreach ( $print_css_on as $page )
add_action ( 'admin_print_styles-' . $page , 'woocommerce_admin_css' );
2012-03-23 16:28:27 +00:00
}
2012-08-14 12:21:34 +00:00
add_action ( 'admin_menu' , 'woocommerce_admin_menu' , 9 );
/**
* Setup the Admin menu in WordPress - later priority so they appear last
*
* @ access public
* @ return void
*/
2012-05-21 08:25:34 +00:00
function woocommerce_admin_menu_after () {
2012-10-16 09:45:33 +00:00
add_submenu_page ( 'woocommerce' , __ ( 'WooCommerce Settings' , 'woocommerce' ), __ ( 'Settings' , 'woocommerce' ) , 'manage_woocommerce' , 'woocommerce_settings' , 'woocommerce_settings_page' );
add_submenu_page ( 'woocommerce' , __ ( 'WooCommerce Status' , 'woocommerce' ), __ ( 'System Status' , 'woocommerce' ) , 'manage_woocommerce' , 'woocommerce_status' , 'woocommerce_status_page' );
2012-05-21 08:25:34 +00:00
}
2012-08-14 12:21:34 +00:00
add_action ( 'admin_menu' , 'woocommerce_admin_menu_after' , 50 );
2012-03-19 19:29:04 +00:00
/**
* Highlights the correct top level admin menu item for post type add screens .
2012-08-14 12:21:34 +00:00
*
* @ access public
* @ return void
2012-03-19 19:29:04 +00:00
*/
function woocommerce_admin_menu_highlight () {
2012-07-23 12:56:05 +00:00
global $menu , $submenu , $parent_file , $submenu_file , $self , $post_type , $taxonomy ;
2012-03-19 19:29:04 +00:00
2012-05-04 09:20:56 +00:00
$to_highlight_types = array ( 'shop_order' , 'shop_coupon' );
2012-03-19 19:29:04 +00:00
if ( isset ( $post_type ) ) {
2012-05-04 09:20:56 +00:00
if ( in_array ( $post_type , $to_highlight_types ) ) {
2012-10-16 15:22:07 +00:00
$submenu_file = 'edit.php?post_type=' . esc_attr ( $post_type );
2012-03-19 19:29:04 +00:00
$parent_file = 'woocommerce' ;
}
2012-04-16 15:45:39 +00:00
2012-05-04 09:20:56 +00:00
if ( 'product' == $post_type ) {
$screen = get_current_screen ();
2012-04-16 15:45:39 +00:00
2012-05-04 09:20:56 +00:00
if ( $screen -> base == 'edit-tags' && 'pa_' == substr ( $taxonomy , 0 , 3 ) ) {
$submenu_file = 'woocommerce_attributes' ;
2012-10-16 15:22:07 +00:00
$parent_file = 'edit.php?post_type=' . esc_attr ( $post_type );
2012-05-04 09:20:56 +00:00
}
2012-04-16 15:45:39 +00:00
}
2012-03-19 19:29:04 +00:00
}
2012-08-01 12:43:46 +00:00
2012-10-01 10:43:52 +00:00
if ( isset ( $submenu [ 'woocommerce' ] ) && isset ( $submenu [ 'woocommerce' ][ 2 ] ) ) {
2012-07-31 14:04:05 +00:00
$submenu [ 'woocommerce' ][ 0 ] = $submenu [ 'woocommerce' ][ 2 ];
unset ( $submenu [ 'woocommerce' ][ 2 ] );
}
2012-08-01 12:43:46 +00:00
2012-07-23 12:56:05 +00:00
// Sort out Orders menu when on the top level
2012-10-01 10:43:52 +00:00
if ( ! current_user_can ( 'manage_woocommerce' ) ) {
2012-07-23 12:56:05 +00:00
foreach ( $menu as $key => $menu_item ) {
if ( strpos ( $menu_item [ 0 ], _x ( 'Orders' , 'Admin menu name' , 'woocommerce' ) ) === 0 ) {
2012-08-01 12:43:46 +00:00
2012-07-23 12:56:05 +00:00
$menu_name = _x ( 'Orders' , 'Admin menu name' , 'woocommerce' );
$menu_name_count = '' ;
if ( $order_count = woocommerce_processing_order_count () ) {
$menu_name_count = " <span class='awaiting-mod update-plugins count- $order_count '><span class='processing-count'> " . number_format_i18n ( $order_count ) . " </span></span> " ;
}
2012-08-01 12:43:46 +00:00
2012-07-23 12:56:05 +00:00
$menu [ $key ][ 0 ] = $menu_name . $menu_name_count ;
$submenu [ 'edit.php?post_type=shop_order' ][ 5 ][ 0 ] = $menu_name ;
break ;
}
}
}
2012-03-19 19:29:04 +00:00
}
2012-08-14 12:21:34 +00:00
add_action ( 'admin_head' , 'woocommerce_admin_menu_highlight' );
2012-02-15 17:31:44 +00:00
/**
2012-10-18 09:33:02 +00:00
* woocommerce_admin_notices_styles function .
2012-11-27 16:22:47 +00:00
*
2012-08-14 12:21:34 +00:00
* @ access public
* @ return void
2012-02-15 17:31:44 +00:00
*/
function woocommerce_admin_notices_styles () {
2012-08-01 12:43:46 +00:00
2012-10-18 13:47:21 +00:00
if ( get_option ( 'woocommerce_updated' ) == 1 || get_option ( 'woocommerce_needs_update' ) == 1 || get_option ( 'woocommerce_installed' ) == 1 ) {
2012-03-01 00:02:17 +00:00
wp_enqueue_style ( 'woocommerce-activation' , plugins_url ( '/assets/css/activation.css' , dirname ( __FILE__ ) ) );
2012-10-18 09:33:02 +00:00
add_action ( 'admin_notices' , 'woocommerce_admin_install_notices' );
}
2012-11-27 16:22:47 +00:00
2012-10-18 09:33:02 +00:00
}
2012-08-01 12:43:46 +00:00
2012-10-18 09:33:02 +00:00
add_action ( 'admin_print_styles' , 'woocommerce_admin_notices_styles' );
/**
* woocommerce_admin_install_notices function .
2012-11-27 16:22:47 +00:00
*
2012-10-18 09:33:02 +00:00
* @ access public
* @ return void
*/
function woocommerce_admin_install_notices () {
global $woocommerce ;
2012-11-27 16:22:47 +00:00
2012-10-18 09:33:02 +00:00
if ( get_option ( 'woocommerce_needs_update' ) == 1 ) {
2012-11-27 16:22:47 +00:00
2012-10-18 13:47:21 +00:00
include ( 'includes/notice-update.php' );
2012-11-27 16:22:47 +00:00
2012-10-18 13:47:21 +00:00
} elseif ( get_option ( 'woocommerce_updated' ) == 1 ) {
2012-11-27 16:22:47 +00:00
2012-10-18 13:47:21 +00:00
include ( 'includes/notice-updated.php' );
2012-11-27 16:22:47 +00:00
2012-10-18 13:47:21 +00:00
update_option ( 'woocommerce_updated' , 0 );
update_option ( 'woocommerce_installed' , 0 );
2012-11-27 16:22:47 +00:00
2012-10-18 13:47:21 +00:00
} elseif ( get_option ( 'woocommerce_installed' ) == 1 ) {
2012-11-27 16:22:47 +00:00
2012-10-18 09:33:02 +00:00
if ( get_option ( 'skip_install_woocommerce_pages' ) != 1 && woocommerce_get_page_id ( 'shop' ) < 1 && ! isset ( $_GET [ 'install_woocommerce_pages' ] ) && ! isset ( $_GET [ 'skip_install_woocommerce_pages' ] ) ) {
2012-11-27 16:22:47 +00:00
2012-10-18 09:33:02 +00:00
include ( 'includes/notice-install.php' );
2012-11-27 16:22:47 +00:00
2012-11-20 13:03:45 +00:00
} elseif ( ! isset ( $_GET [ 'page' ] ) || $_GET [ 'page' ] != 'woocommerce_settings' ) {
2012-11-27 16:22:47 +00:00
2012-10-18 09:33:02 +00:00
include ( 'includes/notice-installed.php' );
2012-11-27 16:22:47 +00:00
2012-10-18 09:33:02 +00:00
update_option ( 'woocommerce_installed' , 0 );
2012-11-27 16:22:47 +00:00
2012-02-15 23:45:55 +00:00
}
2012-11-27 16:22:47 +00:00
2012-02-17 23:47:45 +00:00
}
}
2011-12-12 16:34:56 +00:00
/**
2012-08-14 12:21:34 +00:00
* Include some admin files conditonally .
*
* @ access public
* @ return void
2011-12-12 16:34:56 +00:00
*/
function woocommerce_admin_init () {
2012-02-20 14:29:51 +00:00
global $pagenow , $typenow ;
2012-08-01 12:43:46 +00:00
2012-01-12 00:54:45 +00:00
ob_start ();
2012-08-01 12:43:46 +00:00
2012-08-14 12:21:34 +00:00
if ( $typenow == 'post' && isset ( $_GET [ 'post' ] ) && ! empty ( $_GET [ 'post' ] ) ) {
2012-02-20 14:29:51 +00:00
$typenow = $post -> post_type ;
2012-08-14 12:21:34 +00:00
} elseif ( empty ( $typenow ) && ! empty ( $_GET [ 'post' ] ) ) {
$post = get_post ( $_GET [ 'post' ] );
2012-02-20 14:29:51 +00:00
$typenow = $post -> post_type ;
2012-08-14 12:21:34 +00:00
}
2011-12-12 16:34:56 +00:00
2012-08-14 12:21:34 +00:00
if ( $pagenow == 'index.php' ) {
2012-08-01 12:43:46 +00:00
2011-12-12 16:34:56 +00:00
include_once ( 'woocommerce-admin-dashboard.php' );
2012-08-01 12:43:46 +00:00
2012-08-14 12:21:34 +00:00
} elseif ( $pagenow == 'admin.php' && isset ( $_GET [ 'import' ] ) ) {
2012-08-01 12:43:46 +00:00
2011-12-12 16:34:56 +00:00
include_once ( 'woocommerce-admin-import.php' );
2012-08-01 12:43:46 +00:00
2012-08-14 12:21:34 +00:00
} elseif ( $pagenow == 'post-new.php' || $pagenow == 'post.php' || $pagenow == 'edit.php' ) {
2012-08-01 12:43:46 +00:00
include_once ( 'post-types/writepanels/writepanels-init.php' );
2012-08-14 12:21:34 +00:00
if ( in_array ( $typenow , array ( 'product' , 'shop_coupon' , 'shop_order' ) ) )
add_action ( 'admin_print_styles' , 'woocommerce_admin_help_tab' );
2012-08-01 12:43:46 +00:00
2012-08-14 12:21:34 +00:00
} elseif ( $pagenow == 'users.php' || $pagenow == 'user-edit.php' || $pagenow == 'profile.php' ) {
2012-08-01 12:43:46 +00:00
2011-12-21 23:44:08 +00:00
include_once ( 'woocommerce-admin-users.php' );
2012-08-01 12:43:46 +00:00
2012-02-20 14:29:51 +00:00
}
2012-11-27 16:22:47 +00:00
2012-09-10 11:26:26 +00:00
// Register importers
if ( defined ( 'WP_LOAD_IMPORTERS' ) ) {
include_once ( 'importers/importers-init.php' );
}
2011-12-12 16:34:56 +00:00
}
2012-08-14 12:21:34 +00:00
add_action ( 'admin_init' , 'woocommerce_admin_init' );
2012-01-30 19:24:52 +00:00
2011-12-12 16:34:56 +00:00
/**
2012-08-14 12:21:34 +00:00
* Include and display the settings page .
*
* @ access public
* @ return void
2011-12-12 16:34:56 +00:00
*/
function woocommerce_settings_page () {
include_once ( 'woocommerce-admin-settings.php' );
woocommerce_settings ();
}
2012-08-14 12:21:34 +00:00
/**
* Include and display the reports page .
*
* @ access public
* @ return void
*/
2011-12-12 16:34:56 +00:00
function woocommerce_reports_page () {
include_once ( 'woocommerce-admin-reports.php' );
woocommerce_reports ();
}
2012-08-14 12:21:34 +00:00
/**
* Include and display the attibutes page .
*
* @ access public
* @ return void
*/
2011-12-12 16:34:56 +00:00
function woocommerce_attributes_page () {
include_once ( 'woocommerce-admin-attributes.php' );
woocommerce_attributes ();
}
2012-08-14 12:21:34 +00:00
/**
* Include and display the status page .
*
* @ access public
* @ return void
*/
2012-05-21 08:25:34 +00:00
function woocommerce_status_page () {
include_once ( 'woocommerce-admin-status.php' );
woocommerce_status ();
2012-03-23 16:28:27 +00:00
}
2011-12-12 16:34:56 +00:00
2012-08-14 12:21:34 +00:00
2012-10-18 13:47:21 +00:00
/**
* update_woocommerce function .
2012-11-27 16:22:47 +00:00
*
2012-10-18 13:47:21 +00:00
* @ access public
* @ return void
*/
function update_woocommerce () {
if ( ! empty ( $_GET [ 'do_update_woocommerce' ] ) ) {
include_once ( 'woocommerce-admin-update.php' );
do_update_woocommerce ();
update_option ( 'woocommerce_updated' , 1 );
update_option ( 'woocommerce_needs_update' , 0 );
}
}
add_action ( 'admin_init' , 'update_woocommerce' );
2012-01-18 11:53:34 +00:00
/**
2012-08-14 12:21:34 +00:00
* Include and add help tabs to WordPress admin .
*
* @ access public
* @ return void
2012-01-18 11:53:34 +00:00
*/
function woocommerce_admin_help_tab () {
include_once ( 'woocommerce-admin-content.php' );
woocommerce_admin_help_tab_content ();
}
2012-08-01 12:43:46 +00:00
2012-08-14 12:21:34 +00:00
2011-12-12 16:34:56 +00:00
/**
2012-08-14 12:21:34 +00:00
* Include admin scripts and styles .
*
* @ access public
* @ return void
2011-12-12 16:34:56 +00:00
*/
function woocommerce_admin_scripts () {
2012-05-08 19:30:18 +00:00
global $woocommerce , $pagenow , $post , $wp_query ;
2012-08-01 12:43:46 +00:00
2012-10-17 13:32:25 +00:00
$suffix = defined ( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' ;
2012-08-01 12:43:46 +00:00
2011-12-12 16:34:56 +00:00
// Register scripts
2012-10-17 13:32:25 +00:00
wp_register_script ( 'woocommerce_admin' , $woocommerce -> plugin_url () . '/assets/js/admin/woocommerce_admin' . $suffix . '.js' , array ( 'jquery' , 'jquery-blockui' , 'jquery-placeholder' , 'jquery-ui-widget' , 'jquery-ui-core' , 'jquery-tiptip' ), $woocommerce -> version );
2012-11-27 16:22:47 +00:00
2012-10-17 13:32:25 +00:00
wp_register_script ( 'jquery-blockui' , $woocommerce -> plugin_url () . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js' , array ( 'jquery' ), $woocommerce -> version , true );
2012-11-27 16:22:47 +00:00
2012-10-17 13:32:25 +00:00
wp_register_script ( 'jquery-placeholder' , $woocommerce -> plugin_url () . '/assets/js/jquery-placeholder/jquery.placeholder' . $suffix . '.js' , array ( 'jquery' ), $woocommerce -> version , true );
2012-11-27 16:22:47 +00:00
2012-10-17 13:32:25 +00:00
wp_register_script ( 'jquery-tiptip' , $woocommerce -> plugin_url () . '/assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js' , array ( 'jquery' ), $woocommerce -> version , true );
2012-11-27 16:22:47 +00:00
2012-08-24 17:34:31 +00:00
wp_register_script ( 'jquery-ui-datepicker' , $woocommerce -> plugin_url () . '/assets/js/admin/ui-datepicker.js' , array ( 'jquery' , 'jquery-ui-core' ), $woocommerce -> version );
2012-11-27 16:22:47 +00:00
2012-08-24 17:34:31 +00:00
wp_register_script ( 'woocommerce_writepanel' , $woocommerce -> plugin_url () . '/assets/js/admin/write-panels' . $suffix . '.js' , array ( 'jquery' , 'jquery-ui-datepicker' ), $woocommerce -> version );
2012-11-27 16:22:47 +00:00
2012-08-24 17:34:31 +00:00
wp_register_script ( 'ajax-chosen' , $woocommerce -> plugin_url () . '/assets/js/chosen/ajax-chosen.jquery' . $suffix . '.js' , array ( 'jquery' , 'chosen' ), $woocommerce -> version );
2012-11-27 16:22:47 +00:00
2012-08-24 17:34:31 +00:00
wp_register_script ( 'chosen' , $woocommerce -> plugin_url () . '/assets/js/chosen/chosen.jquery' . $suffix . '.js' , array ( 'jquery' ), $woocommerce -> version );
2012-08-01 12:43:46 +00:00
2011-12-12 16:34:56 +00:00
// Get admin screen id
$screen = get_current_screen ();
// WooCommerce admin pages
2012-08-22 18:22:22 +00:00
if ( in_array ( $screen -> id , apply_filters ( 'woocommerce_screen_ids' , array ( 'toplevel_page_woocommerce' , 'woocommerce_page_woocommerce_settings' , 'woocommerce_page_woocommerce_reports' , 'edit-shop_order' , 'edit-shop_coupon' , 'shop_coupon' , 'shop_order' , 'edit-product' , 'product' ) ) ) ) :
2012-08-01 12:43:46 +00:00
2011-12-12 16:34:56 +00:00
wp_enqueue_script ( 'woocommerce_admin' );
2012-10-17 13:32:25 +00:00
wp_enqueue_script ( 'farbtastic' );
2012-03-06 15:46:53 +00:00
wp_enqueue_script ( 'ajax-chosen' );
2011-12-18 13:41:42 +00:00
wp_enqueue_script ( 'chosen' );
2012-03-26 17:30:00 +00:00
wp_enqueue_script ( 'jquery-ui-sortable' );
2012-12-10 15:36:53 +00:00
wp_enqueue_script ( 'jquery-ui-autocomplete' );
2011-12-12 16:34:56 +00:00
endif ;
2012-08-01 12:43:46 +00:00
2011-12-12 16:34:56 +00:00
// Edit product category pages
if ( in_array ( $screen -> id , array ( 'edit-product_cat' ) )) :
2012-08-01 12:43:46 +00:00
2012-12-18 21:56:01 +00:00
wp_enqueue_media ();
2012-08-01 12:43:46 +00:00
2011-12-12 16:34:56 +00:00
endif ;
// Product/Coupon/Orders
if ( in_array ( $screen -> id , array ( 'shop_coupon' , 'shop_order' , 'product' ))) :
2012-08-01 12:43:46 +00:00
2011-12-12 16:34:56 +00:00
wp_enqueue_script ( 'woocommerce_writepanel' );
wp_enqueue_script ( 'jquery-ui-datepicker' );
2012-12-18 21:56:01 +00:00
wp_enqueue_media ();
2012-03-06 15:46:53 +00:00
wp_enqueue_script ( 'ajax-chosen' );
2011-12-18 13:41:42 +00:00
wp_enqueue_script ( 'chosen' );
2012-10-04 17:09:18 +00:00
wp_enqueue_script ( 'plupload-all' );
2012-08-01 12:43:46 +00:00
$woocommerce_witepanel_params = array (
2012-11-10 16:18:20 +00:00
'remove_item_notice' => __ ( 'Are you sure you want to remove the selected items? If you have previously reduced this item\'s stock, or this order was submitted by a customer, you will need to manually restore the item\'s stock.' , 'woocommerce' ),
2012-10-18 17:56:28 +00:00
'remove_item_meta' => __ ( 'Remove this item meta?' , 'woocommerce' ),
2012-10-16 09:45:33 +00:00
'remove_attribute' => __ ( 'Remove this attribute?' , 'woocommerce' ),
'name_label' => __ ( 'Name' , 'woocommerce' ),
'remove_label' => __ ( 'Remove' , 'woocommerce' ),
'click_to_toggle' => __ ( 'Click to toggle' , 'woocommerce' ),
'values_label' => __ ( 'Value(s)' , 'woocommerce' ),
'text_attribute_tip' => __ ( 'Enter some text, or some attributes by pipe (|) separating values.' , 'woocommerce' ),
'visible_label' => __ ( 'Visible on the product page' , 'woocommerce' ),
'used_for_variations_label' => __ ( 'Used for variations' , 'woocommerce' ),
'new_attribute_prompt' => __ ( 'Enter a name for the new attribute term:' , 'woocommerce' ),
2012-11-13 14:54:34 +00:00
'calc_totals' => __ ( 'Calculate totals based on order items, discounts, and shipping?' , 'woocommerce' ),
2012-10-16 14:46:21 +00:00
'calc_line_taxes' => __ ( 'Calculate line taxes? This will calculate taxes based on the customers country. If no billing/shipping is set it will use the store base country.' , 'woocommerce' ),
'copy_billing' => __ ( 'Copy billing information to shipping information? This will remove any currently entered shipping information.' , 'woocommerce' ),
'load_billing' => __ ( 'Load the customer\'s billing information? This will remove any currently entered billing information.' , 'woocommerce' ),
'load_shipping' => __ ( 'Load the customer\'s shipping information? This will remove any currently entered shipping information.' , 'woocommerce' ),
2012-10-16 09:45:33 +00:00
'featured_label' => __ ( 'Featured' , 'woocommerce' ),
2012-10-16 15:22:07 +00:00
'prices_include_tax' => esc_attr ( get_option ( 'woocommerce_prices_include_tax' ) ),
'round_at_subtotal' => esc_attr ( get_option ( 'woocommerce_tax_round_at_subtotal' ) ),
2012-10-16 09:45:33 +00:00
'no_customer_selected' => __ ( 'No customer selected' , 'woocommerce' ),
2011-12-12 16:34:56 +00:00
'plugin_url' => $woocommerce -> plugin_url (),
'ajax_url' => admin_url ( 'admin-ajax.php' ),
2012-10-18 17:56:28 +00:00
'order_item_nonce' => wp_create_nonce ( " order-item " ),
2012-04-08 23:57:38 +00:00
'add_attribute_nonce' => wp_create_nonce ( " add-attribute " ),
2012-11-26 17:27:55 +00:00
'save_attributes_nonce' => wp_create_nonce ( " save-attributes " ),
2012-01-13 21:25:39 +00:00
'calc_totals_nonce' => wp_create_nonce ( " calc-totals " ),
2011-12-12 16:34:56 +00:00
'get_customer_details_nonce' => wp_create_nonce ( " get-customer-details " ),
2012-07-31 17:26:25 +00:00
'search_products_nonce' => wp_create_nonce ( " search-products " ),
2011-12-12 16:34:56 +00:00
'calendar_image' => $woocommerce -> plugin_url () . '/assets/images/calendar.png' ,
2012-11-27 16:22:47 +00:00
'post_id' => $post -> ID ,
2012-10-16 15:22:07 +00:00
'currency_format_num_decimals' => absint ( get_option ( 'woocommerce_price_num_decimals' ) ),
2012-09-20 13:43:52 +00:00
'currency_format_symbol' => get_woocommerce_currency_symbol (),
2012-10-16 15:22:07 +00:00
'currency_format_decimal_sep' => esc_attr ( stripslashes ( get_option ( 'woocommerce_price_decimal_sep' ) ) ),
'currency_format_thousand_sep' => esc_attr ( stripslashes ( get_option ( 'woocommerce_price_thousand_sep' ) ) ),
'currency_format' => esc_attr ( str_replace ( array ( '%1$s' , '%2$s' ), array ( '%s' , '%v' ), get_woocommerce_price_format () ) ) // For accounting JS
2011-12-12 16:34:56 +00:00
);
2012-08-01 12:43:46 +00:00
2011-12-12 16:34:56 +00:00
wp_localize_script ( 'woocommerce_writepanel' , 'woocommerce_writepanel_params' , $woocommerce_witepanel_params );
2012-08-01 12:43:46 +00:00
2011-12-12 16:34:56 +00:00
endif ;
2012-08-01 12:43:46 +00:00
2012-06-10 17:15:02 +00:00
// Term ordering - only when sorting by term_order
2012-07-16 19:21:44 +00:00
if ( ( strstr ( $screen -> id , 'edit-pa_' ) || ( ! empty ( $_GET [ 'taxonomy' ] ) && in_array ( $_GET [ 'taxonomy' ], apply_filters ( 'woocommerce_sortable_taxonomies' , array ( 'product_cat' ) ) ) ) ) && ! isset ( $_GET [ 'orderby' ] ) ) :
2011-12-12 16:34:56 +00:00
2012-08-24 17:34:31 +00:00
wp_register_script ( 'woocommerce_term_ordering' , $woocommerce -> plugin_url () . '/assets/js/admin/term-ordering.js' , array ( 'jquery-ui-sortable' ), $woocommerce -> version );
2011-12-12 16:34:56 +00:00
wp_enqueue_script ( 'woocommerce_term_ordering' );
2012-08-01 12:43:46 +00:00
2012-10-16 15:22:07 +00:00
$taxonomy = isset ( $_GET [ 'taxonomy' ] ) ? woocommerce_clean ( $_GET [ 'taxonomy' ] ) : '' ;
2012-08-01 12:43:46 +00:00
$woocommerce_term_order_params = array (
2011-12-12 16:34:56 +00:00
'taxonomy' => $taxonomy
);
2012-08-01 12:43:46 +00:00
2011-12-12 16:34:56 +00:00
wp_localize_script ( 'woocommerce_term_ordering' , 'woocommerce_term_ordering_params' , $woocommerce_term_order_params );
2012-08-01 12:43:46 +00:00
2011-12-12 16:34:56 +00:00
endif ;
2012-08-01 12:43:46 +00:00
2012-05-08 19:30:18 +00:00
// Product sorting - only when sorting by menu order on the products page
2012-06-10 07:48:29 +00:00
if ( current_user_can ( 'edit_others_pages' ) && $screen -> id == 'edit-product' && isset ( $wp_query -> query [ 'orderby' ] ) && $wp_query -> query [ 'orderby' ] == 'menu_order title' ) {
2012-08-01 12:43:46 +00:00
2012-05-08 19:30:18 +00:00
wp_enqueue_script ( 'woocommerce_product_ordering' , $woocommerce -> plugin_url () . '/assets/js/admin/product-ordering.js' , array ( 'jquery-ui-sortable' ), '1.0' , true );
2012-08-01 12:43:46 +00:00
2012-05-08 19:30:18 +00:00
}
2011-12-12 16:34:56 +00:00
// Reports pages
2012-08-22 18:22:22 +00:00
if ( $screen -> id == apply_filters ( 'woocommerce_reports_screen_id' , 'woocommerce_page_woocommerce_reports' ) ) {
2011-12-12 16:34:56 +00:00
wp_enqueue_script ( 'jquery-ui-datepicker' );
wp_enqueue_script ( 'flot' , $woocommerce -> plugin_url () . '/assets/js/admin/jquery.flot' . $suffix . '.js' , 'jquery' , '1.0' );
wp_enqueue_script ( 'flot-resize' , $woocommerce -> plugin_url () . '/assets/js/admin/jquery.flot.resize' . $suffix . '.js' , array ( 'jquery' , 'flot' ), '1.0' );
2012-08-01 12:43:46 +00:00
2012-08-14 12:21:34 +00:00
}
2011-12-12 16:34:56 +00:00
}
2012-08-14 12:21:34 +00:00
add_action ( 'admin_enqueue_scripts' , 'woocommerce_admin_scripts' );
2011-12-12 16:34:56 +00:00
/**
2012-08-14 12:21:34 +00:00
* Queue WooCommerce CSS .
*
* @ access public
* @ return void
2011-12-12 16:34:56 +00:00
*/
function woocommerce_admin_css () {
2012-12-28 19:11:58 +00:00
global $woocommerce , $typenow , $post , $wp_scripts ;
2011-12-12 16:34:56 +00:00
2012-12-28 19:11:58 +00:00
if ( $typenow == 'post' && ! empty ( $_GET [ 'post' ] ) ) {
2011-12-12 16:34:56 +00:00
$typenow = $post -> post_type ;
2012-12-28 19:11:58 +00:00
} elseif ( empty ( $typenow ) && ! empty ( $_GET [ 'post' ] ) ) {
$post = get_post ( $_GET [ 'post' ] );
2011-12-12 16:34:56 +00:00
$typenow = $post -> post_type ;
2012-12-28 19:11:58 +00:00
}
2012-08-01 12:43:46 +00:00
2012-12-28 19:11:58 +00:00
if ( $typenow == '' || $typenow == " product " || $typenow == " shop_order " || $typenow == " shop_coupon " ) {
2011-12-12 16:34:56 +00:00
wp_enqueue_style ( 'woocommerce_admin_styles' , $woocommerce -> plugin_url () . '/assets/css/admin.css' );
2012-12-28 19:11:58 +00:00
$jquery_version = isset ( $wp_scripts -> registered [ 'jquery-ui-core' ] -> ver ) ? $wp_scripts -> registered [ 'jquery-ui-core' ] -> ver : '1.9.2' ;
wp_enqueue_style ( 'jquery-ui-style' , '//ajax.googleapis.com/ajax/libs/jqueryui/' . $jquery_version . '/themes/smoothness/jquery-ui.css' );
}
2012-08-01 12:43:46 +00:00
2011-12-12 16:34:56 +00:00
wp_enqueue_style ( 'farbtastic' );
2012-08-01 12:43:46 +00:00
2011-12-12 16:34:56 +00:00
do_action ( 'woocommerce_admin_css' );
}
2012-08-14 12:21:34 +00:00
2012-03-07 11:59:23 +00:00
/**
2012-08-14 12:21:34 +00:00
* Queue admin menu icons CSS .
2012-08-01 12:43:46 +00:00
*
2012-08-14 12:21:34 +00:00
* @ access public
* @ return void
2012-03-07 11:59:23 +00:00
*/
function woocommerce_admin_menu_styles () {
global $woocommerce ;
wp_enqueue_style ( 'woocommerce_admin_menu_styles' , $woocommerce -> plugin_url () . '/assets/css/menu.css' );
}
2012-08-14 12:21:34 +00:00
2012-03-07 11:59:23 +00:00
add_action ( 'admin_print_styles' , 'woocommerce_admin_menu_styles' );
2011-12-12 16:34:56 +00:00
/**
2012-08-14 12:21:34 +00:00
* Reorder the WC menu items in admin .
*
* @ access public
* @ param mixed $menu_order
* @ return void
2011-12-12 16:34:56 +00:00
*/
function woocommerce_admin_menu_order ( $menu_order ) {
2012-08-01 12:43:46 +00:00
2011-12-12 16:34:56 +00:00
// Initialize our custom order array
$woocommerce_menu_order = array ();
// Get the index of our custom separator
$woocommerce_separator = array_search ( 'separator-woocommerce' , $menu_order );
2012-08-01 12:43:46 +00:00
2011-12-12 16:34:56 +00:00
// Get index of product menu
$woocommerce_product = array_search ( 'edit.php?post_type=product' , $menu_order );
// Loop through menu order and do some rearranging
foreach ( $menu_order as $index => $item ) :
if ( ( ( 'woocommerce' ) == $item ) ) :
$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 ] );
elseif ( ! in_array ( $item , array ( 'separator-woocommerce' ) ) ) :
$woocommerce_menu_order [] = $item ;
endif ;
endforeach ;
2012-08-01 12:43:46 +00:00
2011-12-12 16:34:56 +00:00
// Return order
return $woocommerce_menu_order ;
}
2012-08-14 12:21:34 +00:00
2011-12-12 16:34:56 +00:00
add_action ( 'menu_order' , 'woocommerce_admin_menu_order' );
2012-08-14 12:21:34 +00:00
/**
* woocommerce_admin_custom_menu_order function .
*
* @ access public
* @ return void
*/
2011-12-12 16:34:56 +00:00
function woocommerce_admin_custom_menu_order () {
2012-08-14 12:21:34 +00:00
if ( ! current_user_can ( 'manage_woocommerce' ) )
return false ;
2011-12-12 16:34:56 +00:00
return true ;
}
2012-08-14 12:21:34 +00:00
add_action ( 'custom_menu_order' , 'woocommerce_admin_custom_menu_order' );
2011-12-12 16:34:56 +00:00
/**
* Admin Head
2012-08-01 12:43:46 +00:00
*
2011-12-12 16:34:56 +00:00
* Outputs some styles in the admin < head > to show icons on the woocommerce admin pages
2012-08-14 12:21:34 +00:00
*
* @ access public
* @ return void
2011-12-12 16:34:56 +00:00
*/
function woocommerce_admin_head () {
global $woocommerce ;
2012-08-01 12:43:46 +00:00
2012-08-14 12:21:34 +00:00
if ( ! current_user_can ( 'manage_woocommerce' ) ) return false ;
2011-12-12 16:34:56 +00:00
?>
< style type = " text/css " >
< ? php if ( isset ( $_GET [ 'taxonomy' ]) && $_GET [ 'taxonomy' ] == 'product_cat' ) : ?>
. icon32 - posts - product { background - position : - 243 px - 5 px ! important ; }
< ? php elseif ( isset ( $_GET [ 'taxonomy' ]) && $_GET [ 'taxonomy' ] == 'product_tag' ) : ?>
. icon32 - posts - product { background - position : - 301 px - 5 px ! important ; }
< ? php endif ; ?>
</ style >
< ? php
}
2012-08-14 12:21:34 +00:00
2012-01-06 16:10:12 +00:00
add_action ( 'admin_head' , 'woocommerce_admin_head' );
2012-08-14 12:21:34 +00:00
2012-01-11 19:37:33 +00:00
/**
* Duplicate a product action
2012-08-14 12:21:34 +00:00
*
* @ access public
* @ return void
2012-01-11 19:37:33 +00:00
*/
function woocommerce_duplicate_product_action () {
include_once ( 'includes/duplicate_product.php' );
woocommerce_duplicate_product ();
2012-02-26 14:45:56 +00:00
}
2012-08-14 12:21:34 +00:00
add_action ( 'admin_action_duplicate_product' , 'woocommerce_duplicate_product_action' );
2012-02-26 14:45:56 +00:00
/**
* Post updated messages
2012-08-14 12:21:34 +00:00
*
* @ access public
* @ param mixed $messages
* @ return void
2012-02-26 14:45:56 +00:00
*/
function woocommerce_product_updated_messages ( $messages ) {
global $post , $post_ID ;
2012-08-01 12:43:46 +00:00
2012-02-26 14:45:56 +00:00
$messages [ 'product' ] = array (
0 => '' , // Unused. Messages start at index 1.
2012-10-16 09:45:33 +00:00
1 => sprintf ( __ ( 'Product updated. <a href="%s">View Product</a>' , 'woocommerce' ), esc_url ( get_permalink ( $post_ID ) ) ),
2 => __ ( 'Custom field updated.' , 'woocommerce' ),
3 => __ ( 'Custom field deleted.' , 'woocommerce' ),
4 => __ ( 'Product updated.' , 'woocommerce' ),
5 => isset ( $_GET [ 'revision' ]) ? sprintf ( __ ( 'Product restored to revision from %s' , 'woocommerce' ), wp_post_revision_title ( ( int ) $_GET [ 'revision' ], false ) ) : false ,
6 => sprintf ( __ ( 'Product published. <a href="%s">View Product</a>' , 'woocommerce' ), esc_url ( get_permalink ( $post_ID ) ) ),
7 => __ ( 'Product saved.' , 'woocommerce' ),
8 => sprintf ( __ ( 'Product submitted. <a target="_blank" href="%s">Preview Product</a>' , 'woocommerce' ), esc_url ( add_query_arg ( 'preview' , 'true' , get_permalink ( $post_ID ) ) ) ),
9 => sprintf ( __ ( 'Product scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Product</a>' , 'woocommerce' ),
2012-03-05 10:04:23 +00:00
date_i18n ( __ ( 'M j, Y @ G:i' , 'woocommerce' ), strtotime ( $post -> post_date ) ), esc_url ( get_permalink ( $post_ID ) ) ),
2012-10-16 09:45:33 +00:00
10 => sprintf ( __ ( 'Product draft updated. <a target="_blank" href="%s">Preview Product</a>' , 'woocommerce' ), esc_url ( add_query_arg ( 'preview' , 'true' , get_permalink ( $post_ID ) ) ) ),
2012-02-26 14:45:56 +00:00
);
2012-08-01 12:43:46 +00:00
2012-02-26 14:45:56 +00:00
$messages [ 'shop_order' ] = array (
0 => '' , // Unused. Messages start at index 1.
2012-10-16 09:45:33 +00:00
1 => __ ( 'Order updated.' , 'woocommerce' ),
2 => __ ( 'Custom field updated.' , 'woocommerce' ),
3 => __ ( 'Custom field deleted.' , 'woocommerce' ),
4 => __ ( 'Order updated.' , 'woocommerce' ),
5 => isset ( $_GET [ 'revision' ]) ? sprintf ( __ ( 'Order restored to revision from %s' , 'woocommerce' ), wp_post_revision_title ( ( int ) $_GET [ 'revision' ], false ) ) : false ,
6 => __ ( 'Order updated.' , 'woocommerce' ),
7 => __ ( 'Order saved.' , 'woocommerce' ),
8 => __ ( 'Order submitted.' , 'woocommerce' ),
9 => sprintf ( __ ( 'Order scheduled for: <strong>%1$s</strong>.' , 'woocommerce' ),
2012-03-05 10:04:23 +00:00
date_i18n ( __ ( 'M j, Y @ G:i' , 'woocommerce' ), strtotime ( $post -> post_date ) ) ),
2012-10-16 09:45:33 +00:00
10 => __ ( 'Order draft updated.' , 'woocommerce' )
2012-02-26 14:45:56 +00:00
);
$messages [ 'shop_coupon' ] = array (
0 => '' , // Unused. Messages start at index 1.
2012-10-16 09:45:33 +00:00
1 => __ ( 'Coupon updated.' , 'woocommerce' ),
2 => __ ( 'Custom field updated.' , 'woocommerce' ),
3 => __ ( 'Custom field deleted.' , 'woocommerce' ),
4 => __ ( 'Coupon updated.' , 'woocommerce' ),
5 => isset ( $_GET [ 'revision' ]) ? sprintf ( __ ( 'Coupon restored to revision from %s' , 'woocommerce' ), wp_post_revision_title ( ( int ) $_GET [ 'revision' ], false ) ) : false ,
6 => __ ( 'Coupon updated.' , 'woocommerce' ),
7 => __ ( 'Coupon saved.' , 'woocommerce' ),
8 => __ ( 'Coupon submitted.' , 'woocommerce' ),
9 => sprintf ( __ ( 'Coupon scheduled for: <strong>%1$s</strong>.' , 'woocommerce' ),
2012-03-05 10:04:23 +00:00
date_i18n ( __ ( 'M j, Y @ G:i' , 'woocommerce' ), strtotime ( $post -> post_date ) ) ),
2012-10-16 09:45:33 +00:00
10 => __ ( 'Coupon draft updated.' , 'woocommerce' )
2012-02-26 14:45:56 +00:00
);
2012-08-01 12:43:46 +00:00
2012-02-26 14:45:56 +00:00
return $messages ;
2012-07-11 14:53:40 +00:00
}
2012-08-14 12:21:34 +00:00
add_filter ( 'post_updated_messages' , 'woocommerce_product_updated_messages' );
2012-07-11 14:53:40 +00:00
/**
* Post updated messages
2012-08-14 12:21:34 +00:00
*
* @ access public
* @ param mixed $types
* @ return void
2012-07-11 14:53:40 +00:00
*/
function woocommerce_admin_comment_types_dropdown ( $types ) {
$types [ 'order_note' ] = __ ( 'Order notes' , 'woocommerce' );
return $types ;
2012-08-14 12:21:34 +00:00
}
2012-10-10 09:21:04 +00:00
add_filter ( 'admin_comment_types_dropdown' , 'woocommerce_admin_comment_types_dropdown' );
/**
* woocommerce_permalink_settings function .
2012-11-27 16:22:47 +00:00
*
2012-10-10 09:21:04 +00:00
* @ access public
* @ return void
*/
function woocommerce_permalink_settings () {
echo wpautop ( __ ( 'These settings control the permalinks used for products. These settings only apply when <strong>not using "default" permalinks above</strong>.' , 'woocommerce' ) );
$permalinks = get_option ( 'woocommerce_permalinks' );
$product_permalink = $permalinks [ 'product_base' ];
2012-11-27 16:22:47 +00:00
2012-10-10 09:21:04 +00:00
// Get shop page
$shop_page_id = woocommerce_get_page_id ( 'shop' );
$base_slug = ( $shop_page_id > 0 && get_page ( $shop_page_id ) ) ? get_page_uri ( $shop_page_id ) : _x ( 'shop' , 'default-slug' , 'woocommerce' );
$product_base = _x ( 'product' , 'default-slug' , 'woocommerce' );
2012-11-27 16:22:47 +00:00
2012-10-10 09:21:04 +00:00
$structures = array (
0 => '' ,
1 => '/' . trailingslashit ( $product_base ),
2 => '/' . trailingslashit ( $base_slug ),
3 => '/' . trailingslashit ( $base_slug ) . trailingslashit ( '%product_cat%' )
);
?>
< table class = " form-table " >
< tbody >
< tr >
< th >< label >< input name = " product_permalink " type = " radio " value = " <?php echo $structures[0] ; ?> " class = " wctog " < ? php checked ( $structures [ 0 ], $product_permalink ); ?> /> <?php _e( 'Default' ); ?></label></th>
< td >< code >< ? php echo home_url (); ?> /?product=sample-product</code></td>
</ tr >
< tr >
< th >< label >< input name = " product_permalink " type = " radio " value = " <?php echo $structures[1] ; ?> " class = " wctog " < ? php checked ( $structures [ 1 ], $product_permalink ); ?> /> <?php _e( 'Product', 'woocommerce' ); ?></label></th>
< td >< code >< ? php echo home_url (); ?> /<?php echo $product_base; ?>/sample-product/</code></td>
</ tr >
< ? php if ( $shop_page_id ) : ?>
< tr >
< th >< label >< input name = " product_permalink " type = " radio " value = " <?php echo $structures[2] ; ?> " class = " wctog " < ? php checked ( $structures [ 2 ], $product_permalink ); ?> /> <?php _e( 'Shop base', 'woocommerce' ); ?></label></th>
< td >< code >< ? php echo home_url (); ?> /<?php echo $base_slug; ?>/sample-product/</code></td>
</ tr >
< tr >
< th >< label >< input name = " product_permalink " type = " radio " value = " <?php echo $structures[3] ; ?> " class = " wctog " < ? php checked ( $structures [ 3 ], $product_permalink ); ?> /> <?php _e( 'Shop base with category', 'woocommerce' ); ?></label></th>
< td >< code >< ? php echo home_url (); ?> /<?php echo $base_slug; ?>/product-category/sample-product/</code></td>
</ tr >
< ? php endif ; ?>
< tr >
< th >< label >< input name = " product_permalink " id = " woocommerce_custom_selection " type = " radio " value = " custom " class = " tog " < ? php checked ( in_array ( $product_permalink , $structures ), false ); ?> />
< ? php _e ( 'Custom Base' , 'woocommerce' ); ?> </label></th>
< td >
2012-10-16 15:22:07 +00:00
< input name = " product_permalink_structure " id = " woocommerce_permalink_structure " type = " text " value = " <?php echo esc_attr( $product_permalink ); ?> " class = " regular-text code " > < span class = " description " >< ? php _e ( 'Enter a custom base to use. A base <strong>must</strong> be set or WordPress will use default instead.' , 'woocommerce' ); ?> </span>
2012-10-10 09:21:04 +00:00
</ td >
</ tr >
</ tbody >
</ table >
< script type = " text/javascript " >
jQuery ( function (){
jQuery ( 'input.wctog' ) . change ( function () {
jQuery ( '#woocommerce_permalink_structure' ) . val ( jQuery ( this ) . val () );
});
2012-11-27 16:22:47 +00:00
2012-10-10 09:21:04 +00:00
jQuery ( '#woocommerce_permalink_structure' ) . focus ( function (){
jQuery ( '#woocommerce_custom_selection' ) . click ();
});
});
</ script >
< ? php
}
/**
* woocommerce_permalink_settings_init function .
2012-11-27 16:22:47 +00:00
*
2012-10-10 09:21:04 +00:00
* @ access public
* @ return void
*/
function woocommerce_permalink_settings_init () {
// Add a section to the permalinks page
add_settings_section ( 'woocommerce-permalink' , __ ( 'Product permalink base' , 'woocommerce' ), 'woocommerce_permalink_settings' , 'permalink' );
2012-11-27 16:22:47 +00:00
2012-10-10 09:21:04 +00:00
// Add our settings
add_settings_field (
'woocommerce_product_category_slug' , // id
__ ( 'Product category base' , 'woocommerce' ), // setting title
'woocommerce_product_category_slug_input' , // display callback
'permalink' , // settings page
'optional' // settings section
);
add_settings_field (
'woocommerce_product_tag_slug' , // id
__ ( 'Product tag base' , 'woocommerce' ), // setting title
'woocommerce_product_tag_slug_input' , // display callback
'permalink' , // settings page
'optional' // settings section
);
add_settings_field (
'woocommerce_product_attribute_slug' , // id
__ ( 'Product attribute base' , 'woocommerce' ), // setting title
'woocommerce_product_attribute_slug_input' , // display callback
'permalink' , // settings page
'optional' // settings section
);
}
add_action ( 'admin_init' , 'woocommerce_permalink_settings_init' );
/**
* woocommerce_permalink_settings_save function .
2012-11-27 16:22:47 +00:00
*
2012-10-10 09:21:04 +00:00
* @ access public
* @ return void
*/
function woocommerce_permalink_settings_save () {
if ( ! is_admin () )
return ;
2012-11-27 16:22:47 +00:00
2012-10-10 09:21:04 +00:00
// We need to save the options ourselves; settings api does not trigger save for the permalinks page
if ( isset ( $_POST [ 'permalink_structure' ] ) || isset ( $_POST [ 'category_base' ] ) ) {
// Cat and tag bases
2012-10-16 15:22:07 +00:00
$woocommerce_product_category_slug = woocommerce_clean ( $_POST [ 'woocommerce_product_category_slug' ] );
$woocommerce_product_tag_slug = woocommerce_clean ( $_POST [ 'woocommerce_product_tag_slug' ] );
$woocommerce_product_attribute_slug = woocommerce_clean ( $_POST [ 'woocommerce_product_attribute_slug' ] );
2012-11-27 16:22:47 +00:00
2012-10-10 09:21:04 +00:00
$permalinks = get_option ( 'woocommerce_permalinks' );
2012-11-27 16:22:47 +00:00
if ( ! $permalinks )
2012-10-10 09:21:04 +00:00
$permalinks = array ();
2012-11-27 16:22:47 +00:00
2012-10-10 09:21:04 +00:00
$permalinks [ 'category_base' ] = untrailingslashit ( $woocommerce_product_category_slug );
$permalinks [ 'tag_base' ] = untrailingslashit ( $woocommerce_product_tag_slug );
$permalinks [ 'attribute_base' ] = untrailingslashit ( $woocommerce_product_attribute_slug );
2012-11-27 16:22:47 +00:00
2012-10-10 09:21:04 +00:00
// Product base
2012-10-16 15:22:07 +00:00
$product_permalink = woocommerce_clean ( $_POST [ 'product_permalink' ] );
2012-11-27 16:22:47 +00:00
2012-10-10 09:21:04 +00:00
if ( $product_permalink == 'custom' ) {
2012-10-16 15:22:07 +00:00
$product_permalink = woocommerce_clean ( $_POST [ 'product_permalink_structure' ] );
2012-10-10 09:21:04 +00:00
} elseif ( empty ( $product_permalink ) ) {
$product_permalink = false ;
}
2012-11-27 16:22:47 +00:00
2012-10-10 09:21:04 +00:00
$permalinks [ 'product_base' ] = untrailingslashit ( $product_permalink );
2012-11-27 16:22:47 +00:00
2012-10-10 09:21:04 +00:00
update_option ( 'woocommerce_permalinks' , $permalinks );
}
}
add_action ( 'before_woocommerce_init' , 'woocommerce_permalink_settings_save' );
/**
* woocommerce_product_category_slug_input function .
2012-11-27 16:22:47 +00:00
*
2012-10-10 09:21:04 +00:00
* @ access public
* @ return void
*/
function woocommerce_product_category_slug_input () {
$permalinks = get_option ( 'woocommerce_permalinks' );
?>
< input name = " woocommerce_product_category_slug " type = " text " class = " regular-text code " value = " <?php if ( isset( $permalinks['category_base'] ) ) echo esc_attr( $permalinks['category_base'] ); ?> " placeholder = " <?php echo _x('product-category', 'slug', 'woocommerce') ?> " />
< ? php
}
/**
* woocommerce_product_tag_slug_input function .
2012-11-27 16:22:47 +00:00
*
2012-10-10 09:21:04 +00:00
* @ access public
* @ return void
*/
function woocommerce_product_tag_slug_input () {
$permalinks = get_option ( 'woocommerce_permalinks' );
?>
< input name = " woocommerce_product_tag_slug " type = " text " class = " regular-text code " value = " <?php if ( isset( $permalinks['tag_base'] ) ) echo esc_attr( $permalinks['tag_base'] ); ?> " placeholder = " <?php echo _x('product-tag', 'slug', 'woocommerce') ?> " />
< ? php
}
/**
* woocommerce_product_attribute_slug_input function .
2012-11-27 16:22:47 +00:00
*
2012-10-10 09:21:04 +00:00
* @ access public
* @ return void
*/
function woocommerce_product_attribute_slug_input () {
$permalinks = get_option ( 'woocommerce_permalinks' );
?>
< input name = " woocommerce_product_attribute_slug " type = " text " class = " regular-text code " value = " <?php if ( isset( $permalinks['attribute_base'] ) ) echo esc_attr( $permalinks['attribute_base'] ); ?> " />< code >/ attribute - name / attribute /</ code >
< ? php
}