2011-08-10 17:11:11 +00:00
< ? php
2012-03-20 13:22:35 +00:00
/**
* Plugin Name : WooCommerce
* Plugin URI : http :// www . woothemes . com / woocommerce /
* Description : An e - commerce toolkit that helps you sell anything . Beautifully .
2013-05-02 11:29:20 +00:00
* Version : 2.1 - bleeding
2012-03-20 13:22:35 +00:00
* Author : WooThemes
* Author URI : http :// woothemes . com
2012-12-18 12:04:33 +00:00
* Requires at least : 3.5
2012-12-13 15:27:47 +00:00
* Tested up to : 3.5
2012-08-07 08:38:08 +00:00
*
2012-03-20 13:22:35 +00:00
* Text Domain : woocommerce
2012-12-28 10:54:02 +00:00
* Domain Path : / i18n / languages /
2012-08-07 08:38:08 +00:00
*
2012-03-20 13:22:35 +00:00
* @ package WooCommerce
* @ category Core
* @ author WooThemes
*/
2012-04-16 12:52:28 +00:00
2012-05-24 11:20:11 +00:00
if ( ! defined ( 'ABSPATH' ) ) exit ; // Exit if accessed directly
2011-08-10 17:11:11 +00:00
2012-05-24 11:20:11 +00:00
if ( ! class_exists ( 'Woocommerce' ) ) {
2011-12-08 12:50:50 +00:00
2011-09-04 00:02:44 +00:00
/**
2011-12-09 17:01:56 +00:00
* Main WooCommerce Class
*
* Contains the main functions for WooCommerce , stores variables , and handles error messages
*
2012-08-14 19:42:38 +00:00
* @ class Woocommerce
2012-12-30 15:51:37 +00:00
* @ version 2.0 . 0
2012-08-14 14:13:08 +00:00
* @ since 1.4
* @ package WooCommerce
* @ author WooThemes
2011-09-06 11:11:22 +00:00
*/
2012-01-21 09:01:41 +00:00
class Woocommerce {
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
/**
* @ var string
*/
2013-05-02 11:29:20 +00:00
public $version = '2.1-bleeding' ;
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
/**
* @ var string
*/
2012-12-14 21:19:40 +00:00
public $plugin_url ;
2012-08-14 14:13:08 +00:00
/**
* @ var string
*/
2012-12-14 21:19:40 +00:00
public $plugin_path ;
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
/**
* @ var string
*/
2012-12-14 21:19:40 +00:00
public $template_url ;
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
/**
* @ var array
*/
2012-12-14 21:19:40 +00:00
public $errors = array ();
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
/**
* @ var array
*/
2012-12-14 21:19:40 +00:00
public $messages = array ();
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
/**
* @ var WC_Query
*/
2012-12-14 21:19:40 +00:00
public $query ;
2012-08-14 14:13:08 +00:00
/**
* @ var WC_Customer
*/
2012-12-14 21:19:40 +00:00
public $customer ;
2012-08-14 14:13:08 +00:00
2012-11-22 13:00:25 +00:00
/**
* @ var WC_Product_Factory
*/
2012-12-14 21:19:40 +00:00
public $product_factory ;
2012-11-22 13:00:25 +00:00
2012-08-14 14:13:08 +00:00
/**
* @ var WC_Cart
*/
2012-12-14 21:19:40 +00:00
public $cart ;
2012-08-14 14:13:08 +00:00
/**
* @ var WC_Countries
*/
2012-12-14 21:19:40 +00:00
public $countries ;
2012-08-14 14:13:08 +00:00
/**
* @ var WC_Email
*/
2012-12-14 21:19:40 +00:00
public $woocommerce_email ;
2011-12-09 17:01:56 +00:00
2012-08-14 14:13:08 +00:00
/**
* @ var WC_Checkout
*/
2012-12-14 21:19:40 +00:00
public $checkout ;
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
/**
* @ var WC_Integrations
*/
2012-12-14 21:19:40 +00:00
public $integrations ;
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
/**
* @ var array
*/
2011-12-09 19:55:09 +00:00
private $_body_classes = array ();
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
/**
* @ var string
*/
2011-12-09 17:01:56 +00:00
private $_inline_js = '' ;
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2011-12-09 17:01:56 +00:00
/**
2012-08-14 14:13:08 +00:00
* WooCommerce Constructor .
2011-12-09 17:01:56 +00:00
*
2012-08-14 14:13:08 +00:00
* @ access public
* @ return void
2011-12-09 17:01:56 +00:00
*/
2012-12-14 21:19:40 +00:00
public function __construct () {
2011-12-11 15:20:34 +00:00
2012-12-31 18:25:09 +00:00
// Auto-load classes on demand
2013-03-27 11:04:51 +00:00
if ( function_exists ( " __autoload " ) ) {
spl_autoload_register ( " __autoload " );
}
2012-12-31 18:25:09 +00:00
spl_autoload_register ( array ( $this , 'autoload' ) );
2012-02-01 21:49:08 +00:00
// Define version constant
define ( 'WOOCOMMERCE_VERSION' , $this -> version );
2012-02-28 08:37:42 +00:00
2012-12-12 12:52:35 +00:00
// Installation
2013-03-05 18:50:44 +00:00
register_activation_hook ( __FILE__ , array ( $this , 'activate' ) );
2012-12-12 12:52:35 +00:00
2013-03-06 11:59:24 +00:00
// Updates
add_action ( 'admin_init' , array ( $this , 'update' ), 5 );
2012-12-12 12:52:35 +00:00
2011-12-09 17:01:56 +00:00
// Include required files
$this -> includes ();
2012-08-07 08:38:08 +00:00
2013-02-13 12:38:15 +00:00
// Init API
$this -> api = new WC_API ();
2012-12-31 18:25:09 +00:00
// Hooks
2013-04-04 16:31:06 +00:00
add_filter ( 'plugin_action_links_' . plugin_basename ( __FILE__ ), array ( $this , 'action_links' ) );
2012-12-31 18:25:09 +00:00
add_filter ( 'woocommerce_shipping_methods' , array ( $this , 'core_shipping' ) );
add_filter ( 'woocommerce_payment_gateways' , array ( $this , 'core_gateways' ) );
add_action ( 'widgets_init' , array ( $this , 'register_widgets' ) );
2012-12-15 11:53:32 +00:00
add_action ( 'init' , array ( $this , 'init' ), 0 );
add_action ( 'init' , array ( $this , 'include_template_functions' ), 25 );
add_action ( 'after_setup_theme' , array ( $this , 'compatibility' ) );
2012-08-07 08:38:08 +00:00
2012-03-20 18:59:12 +00:00
// Loaded action
do_action ( 'woocommerce_loaded' );
2011-10-03 08:14:07 +00:00
}
2011-12-09 17:01:56 +00:00
2013-04-04 16:31:06 +00:00
/**
* action_links function .
*
* @ access public
* @ param mixed $links
* @ return void
*/
public function action_links ( $links ) {
$plugin_links = array (
'<a href="' . admin_url ( 'admin.php?page=woocommerce_settings' ) . '">' . __ ( 'Settings' , 'woocommerce' ) . '</a>' ,
2013-04-17 09:16:31 +00:00
'<a href="http://docs.woothemes.com/documentation/plugins/woocommerce/">' . __ ( 'Docs' , 'woocommerce' ) . '</a>' ,
2013-04-04 16:31:06 +00:00
'<a href="http://support.woothemes.com/">' . __ ( 'Premium Support' , 'woocommerce' ) . '</a>' ,
);
return array_merge ( $plugin_links , $links );
}
2012-12-31 18:25:09 +00:00
/**
2013-01-07 17:23:09 +00:00
* Auto - load in - accessible properties on demand .
2012-12-31 18:25:09 +00:00
*
* @ access public
* @ param mixed $key
* @ return mixed
*/
public function __get ( $key ) {
if ( 'payment_gateways' == $key ) {
2013-01-07 17:23:09 +00:00
return $this -> payment_gateways ();
2012-12-31 18:25:09 +00:00
}
elseif ( 'shipping' == $key ) {
2013-01-07 17:23:09 +00:00
return $this -> shipping ();
2012-12-31 18:25:09 +00:00
}
return false ;
}
/**
* Auto - load WC classes on demand to reduce memory consumption .
*
* @ access public
* @ param mixed $class
* @ return void
*/
public function autoload ( $class ) {
$class = strtolower ( $class );
if ( strpos ( $class , 'wc_gateway_' ) === 0 ) {
$path = $this -> plugin_path () . '/classes/gateways/' . trailingslashit ( substr ( str_replace ( '_' , '-' , $class ), 11 ) );
$file = 'class-' . str_replace ( '_' , '-' , $class ) . '.php' ;
2013-01-23 19:29:23 +00:00
if ( is_readable ( $path . $file ) ) {
2013-03-06 10:28:23 +00:00
include_once ( $path . $file );
2012-12-31 18:25:09 +00:00
return ;
}
} elseif ( strpos ( $class , 'wc_shipping_' ) === 0 ) {
$path = $this -> plugin_path () . '/classes/shipping/' . trailingslashit ( substr ( str_replace ( '_' , '-' , $class ), 12 ) );
$file = 'class-' . str_replace ( '_' , '-' , $class ) . '.php' ;
2013-01-23 19:29:23 +00:00
if ( is_readable ( $path . $file ) ) {
2013-03-06 10:28:23 +00:00
include_once ( $path . $file );
2012-12-31 18:25:09 +00:00
return ;
}
} elseif ( strpos ( $class , 'wc_shortcode_' ) === 0 ) {
$path = $this -> plugin_path () . '/classes/shortcodes/' ;
$file = 'class-' . str_replace ( '_' , '-' , $class ) . '.php' ;
2013-01-23 19:29:23 +00:00
if ( is_readable ( $path . $file ) ) {
2013-03-06 10:28:23 +00:00
include_once ( $path . $file );
2012-12-31 18:25:09 +00:00
return ;
}
}
if ( strpos ( $class , 'wc_' ) === 0 ) {
$path = $this -> plugin_path () . '/classes/' ;
$file = 'class-' . str_replace ( '_' , '-' , $class ) . '.php' ;
2013-01-23 19:29:23 +00:00
if ( is_readable ( $path . $file ) ) {
2013-03-06 10:28:23 +00:00
include_once ( $path . $file );
2012-12-31 18:25:09 +00:00
return ;
}
}
}
2012-08-14 14:13:08 +00:00
2012-12-12 12:52:35 +00:00
/**
* activate function .
*
* @ access public
* @ return void
*/
2012-12-14 21:19:40 +00:00
public function activate () {
2013-03-05 18:50:44 +00:00
if ( woocommerce_get_page_id ( 'shop' ) < 1 )
update_option ( '_wc_needs_pages' , 1 );
2012-12-12 12:52:35 +00:00
$this -> install ();
}
2013-03-06 11:59:24 +00:00
/**
* update function .
*
* @ access public
* @ return void
*/
public function update () {
if ( ! defined ( 'IFRAME_REQUEST' ) && ( get_option ( 'woocommerce_version' ) != $this -> version || get_option ( 'woocommerce_db_version' ) != $this -> version ) )
$this -> install ();
}
2012-12-12 12:52:35 +00:00
/**
* upgrade function .
*
* @ access public
* @ return void
*/
function install () {
include_once ( 'admin/woocommerce-admin-install.php' );
2013-03-01 16:03:10 +00:00
set_transient ( '_wc_activation_redirect' , 1 , 60 * 60 );
2013-03-05 18:50:44 +00:00
do_install_woocommerce ();
2012-12-12 12:52:35 +00:00
}
2011-12-09 17:01:56 +00:00
/**
2012-12-31 18:25:09 +00:00
* Include required core files used in admin and on the frontend .
2012-08-14 14:13:08 +00:00
*
* @ access public
* @ return void
*/
2011-12-09 17:01:56 +00:00
function includes () {
2012-12-31 18:25:09 +00:00
if ( is_admin () )
$this -> admin_includes ();
if ( defined ( 'DOING_AJAX' ) )
$this -> ajax_includes ();
if ( ! is_admin () || defined ( 'DOING_AJAX' ) )
$this -> frontend_includes ();
// Functions
2013-03-06 10:28:23 +00:00
include_once ( 'woocommerce-core-functions.php' ); // Contains core functions for the front/back end
2012-12-31 18:25:09 +00:00
2013-03-13 11:58:56 +00:00
// API Class
include_once ( 'classes/class-wc-api.php' );
2012-12-31 18:25:09 +00:00
// Include abstract classes
2013-03-06 10:28:23 +00:00
include_once ( 'classes/abstracts/abstract-wc-product.php' ); // Products
2013-04-09 09:38:40 +00:00
include_once ( 'classes/abstracts/abstract-wc-settings-api.php' ); // Settings API (for gateways, shipping, and integrations)
2013-03-06 10:28:23 +00:00
include_once ( 'classes/abstracts/abstract-wc-shipping-method.php' ); // A Shipping method
2013-04-09 09:38:40 +00:00
include_once ( 'classes/abstracts/abstract-wc-payment-gateway.php' ); // A Payment gateway
2013-03-06 10:28:23 +00:00
include_once ( 'classes/abstracts/abstract-wc-integration.php' ); // An integration with a service
2012-12-31 18:25:09 +00:00
// Classes (used on all pages)
2013-04-09 09:38:40 +00:00
include_once ( 'classes/class-wc-product-factory.php' ); // Product factory
include_once ( 'classes/class-wc-countries.php' ); // Defines countries and states
2013-03-06 10:28:23 +00:00
include_once ( 'classes/class-wc-integrations.php' ); // Loads integrations
2013-04-09 09:38:40 +00:00
include_once ( 'classes/class-wc-cache-helper.php' ); // Cache Helper
2012-12-31 18:25:09 +00:00
// Include Core Integrations - these are included sitewide
2013-03-06 10:28:23 +00:00
include_once ( 'classes/integrations/google-analytics/class-wc-google-analytics.php' );
include_once ( 'classes/integrations/sharethis/class-wc-sharethis.php' );
include_once ( 'classes/integrations/sharedaddy/class-wc-sharedaddy.php' );
2012-05-08 15:23:09 +00:00
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2011-12-09 17:01:56 +00:00
/**
2012-08-14 14:13:08 +00:00
* Include required admin files .
*
* @ access public
* @ return void
*/
2012-12-14 21:19:40 +00:00
public function admin_includes () {
2013-03-06 10:28:23 +00:00
include_once ( 'admin/woocommerce-admin-init.php' ); // Admin section
2011-10-03 08:14:07 +00:00
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2011-12-09 17:01:56 +00:00
/**
2012-08-14 14:13:08 +00:00
* Include required ajax files .
*
* @ access public
* @ return void
*/
2012-12-14 21:19:40 +00:00
public function ajax_includes () {
2013-03-06 10:28:23 +00:00
include_once ( 'woocommerce-ajax.php' ); // Ajax functions for admin and the front-end
2011-10-03 08:14:07 +00:00
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2011-12-09 17:01:56 +00:00
/**
2012-08-14 14:13:08 +00:00
* Include required frontend files .
*
* @ access public
* @ return void
*/
2012-12-14 21:19:40 +00:00
public function frontend_includes () {
2012-12-31 18:25:09 +00:00
// Functions
2013-03-06 10:28:23 +00:00
include_once ( 'woocommerce-hooks.php' ); // Template hooks used on the front-end
include_once ( 'woocommerce-functions.php' ); // Contains functions for various front-end events
2012-12-31 18:25:09 +00:00
// Classes
2013-03-06 10:28:23 +00:00
include_once ( 'classes/class-wc-query.php' ); // The main store queries
include_once ( 'classes/class-wc-cart.php' ); // The main cart class
include_once ( 'classes/class-wc-tax.php' ); // Tax class
include_once ( 'classes/class-wc-customer.php' ); // Customer class
include_once ( 'classes/abstracts/abstract-wc-session.php' ); // Abstract for session implementations
include_once ( 'classes/class-wc-session-handler.php' ); // WC Session class
include_once ( 'classes/class-wc-shortcodes.php' ); // Shortcodes class
2011-10-03 08:14:07 +00:00
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2011-12-09 17:01:56 +00:00
/**
2012-08-14 14:13:08 +00:00
* Function used to Init WooCommerce Template Functions - This makes them pluggable by plugins and themes .
*
* @ access public
* @ return void
*/
2012-12-14 21:19:40 +00:00
public function include_template_functions () {
2013-03-06 10:28:23 +00:00
include_once ( 'woocommerce-template.php' );
2011-12-09 19:55:09 +00:00
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2012-12-31 18:25:09 +00:00
/**
* core_gateways function .
*
* @ access public
* @ param mixed $methods
* @ return void
*/
function core_gateways ( $methods ) {
$methods [] = 'WC_Gateway_BACS' ;
$methods [] = 'WC_Gateway_Cheque' ;
$methods [] = 'WC_Gateway_COD' ;
$methods [] = 'WC_Gateway_Mijireh' ;
$methods [] = 'WC_Gateway_Paypal' ;
return $methods ;
}
/**
* core_shipping function .
*
* @ access public
* @ param mixed $methods
* @ return void
*/
function core_shipping ( $methods ) {
$methods [] = 'WC_Shipping_Flat_Rate' ;
$methods [] = 'WC_Shipping_Free_Shipping' ;
$methods [] = 'WC_Shipping_International_Delivery' ;
$methods [] = 'WC_Shipping_Local_Delivery' ;
$methods [] = 'WC_Shipping_Local_Pickup' ;
return $methods ;
}
/**
* register_widgets function .
*
* @ access public
* @ return void
*/
function register_widgets () {
// Include - no need to use autoload as WP loads them anyway
2013-03-06 10:28:23 +00:00
include_once ( 'classes/widgets/class-wc-widget-cart.php' );
include_once ( 'classes/widgets/class-wc-widget-featured-products.php' );
include_once ( 'classes/widgets/class-wc-widget-layered-nav.php' );
include_once ( 'classes/widgets/class-wc-widget-layered-nav-filters.php' );
include_once ( 'classes/widgets/class-wc-widget-price-filter.php' );
include_once ( 'classes/widgets/class-wc-widget-product-categories.php' );
include_once ( 'classes/widgets/class-wc-widget-product-search.php' );
include_once ( 'classes/widgets/class-wc-widget-product-tag-cloud.php' );
include_once ( 'classes/widgets/class-wc-widget-recent-products.php' );
include_once ( 'classes/widgets/class-wc-widget-top-rated-products.php' );
include_once ( 'classes/widgets/class-wc-widget-recent-reviews.php' );
include_once ( 'classes/widgets/class-wc-widget-recently-viewed.php' );
include_once ( 'classes/widgets/class-wc-widget-best-sellers.php' );
include_once ( 'classes/widgets/class-wc-widget-onsale.php' );
include_once ( 'classes/widgets/class-wc-widget-random-products.php' );
2012-12-31 18:25:09 +00:00
// Register widgets
register_widget ( 'WC_Widget_Recent_Products' );
register_widget ( 'WC_Widget_Featured_Products' );
register_widget ( 'WC_Widget_Product_Categories' );
register_widget ( 'WC_Widget_Product_Tag_Cloud' );
register_widget ( 'WC_Widget_Cart' );
register_widget ( 'WC_Widget_Layered_Nav' );
register_widget ( 'WC_Widget_Layered_Nav_Filters' );
register_widget ( 'WC_Widget_Price_Filter' );
register_widget ( 'WC_Widget_Product_Search' );
register_widget ( 'WC_Widget_Top_Rated_Products' );
register_widget ( 'WC_Widget_Recent_Reviews' );
register_widget ( 'WC_Widget_Recently_Viewed' );
register_widget ( 'WC_Widget_Best_Sellers' );
register_widget ( 'WC_Widget_Onsale' );
register_widget ( 'WC_Widget_Random_Products' );
}
2011-12-09 19:55:09 +00:00
/**
2012-08-14 14:13:08 +00:00
* Init WooCommerce when WordPress Initialises .
*
* @ access public
* @ return void
*/
2012-12-14 21:19:40 +00:00
public function init () {
2012-10-10 09:21:04 +00:00
//Before init action
do_action ( 'before_woocommerce_init' );
2012-11-13 23:22:53 +00:00
2012-03-20 13:20:08 +00:00
// Set up localisation
$this -> load_plugin_textdomain ();
// Variables
$this -> template_url = apply_filters ( 'woocommerce_template_url' , 'woocommerce/' );
// Load class instances
2012-11-22 13:00:25 +00:00
$this -> product_factory = new WC_Product_Factory (); // Product Factory to create new product instances
2012-03-20 13:20:08 +00:00
$this -> countries = new WC_Countries (); // Countries class
2012-04-30 19:50:35 +00:00
$this -> integrations = new WC_Integrations (); // Integrations class
2012-08-07 08:38:08 +00:00
2012-03-20 13:20:08 +00:00
// Classes/actions loaded for the frontend and for ajax requests
2012-03-20 14:32:29 +00:00
if ( ! is_admin () || defined ( 'DOING_AJAX' ) ) {
2012-08-07 08:38:08 +00:00
2012-09-30 19:11:32 +00:00
// Session class, handles session data for customers - can be overwritten if custom handler is needed
2013-01-15 19:51:19 +00:00
$session_class = apply_filters ( 'woocommerce_session_handler' , 'WC_Session_Handler' );
2012-09-30 19:11:32 +00:00
$this -> session = new $session_class ();
2012-03-20 13:20:08 +00:00
// Class instances
$this -> cart = new WC_Cart (); // Cart class, stores the cart contents
2012-09-07 17:26:13 +00:00
$this -> customer = new WC_Customer (); // Customer class, handles data such as customer location
2012-03-20 13:20:08 +00:00
$this -> query = new WC_Query (); // Query class, handles front-end queries and loops
2012-12-31 18:25:09 +00:00
$this -> shortcodes = new WC_Shortcodes (); // Shortcodes class, controls all frontend shortcodes
2012-08-07 08:38:08 +00:00
2012-03-20 13:20:08 +00:00
// Load messages
$this -> load_messages ();
2012-03-20 14:32:29 +00:00
2012-03-20 13:20:08 +00:00
// Hooks
2013-03-07 16:33:44 +00:00
add_action ( 'get_header' , array ( $this , 'init_checkout' ) );
2012-12-15 11:53:32 +00:00
add_filter ( 'template_include' , array ( $this , 'template_loader' ) );
add_filter ( 'comments_template' , array ( $this , 'comments_template_loader' ) );
add_filter ( 'wp_redirect' , array ( $this , 'redirect' ), 1 , 2 );
add_action ( 'wp_enqueue_scripts' , array ( $this , 'frontend_scripts' ) );
add_action ( 'wp_print_scripts' , array ( $this , 'check_jquery' ), 25 );
add_action ( 'wp_head' , array ( $this , 'generator' ) );
add_action ( 'wp_head' , array ( $this , 'wp_head' ) );
add_filter ( 'body_class' , array ( $this , 'output_body_class' ) );
2013-01-09 14:15:25 +00:00
add_filter ( 'post_class' , array ( $this , 'post_class' ), 20 , 3 );
2012-12-15 11:53:32 +00:00
add_action ( 'wp_footer' , array ( $this , 'output_inline_js' ), 25 );
2012-12-31 13:03:56 +00:00
// HTTPS urls with SSL on
2013-03-28 15:49:02 +00:00
$filters = array ( 'post_thumbnail_html' , 'widget_text' , 'wp_get_attachment_url' , 'wp_get_attachment_image_attributes' , 'wp_get_attachment_url' , 'option_stylesheet_url' , 'option_template_url' , 'script_loader_src' , 'style_loader_src' , 'template_directory_uri' , 'stylesheet_directory_uri' , 'site_url' );
2012-12-31 13:03:56 +00:00
foreach ( $filters as $filter )
add_filter ( $filter , array ( $this , 'force_ssl' ) );
2012-03-20 14:32:29 +00:00
}
2012-03-20 13:20:08 +00:00
2012-03-20 14:08:29 +00:00
// Actions
2012-12-15 11:53:32 +00:00
add_action ( 'the_post' , array ( $this , 'setup_product_data' ) );
add_action ( 'admin_footer' , array ( $this , 'output_inline_js' ), 25 );
2012-03-20 14:08:29 +00:00
// Email Actions
$email_actions = array ( 'woocommerce_low_stock' , 'woocommerce_no_stock' , 'woocommerce_product_on_backorder' , 'woocommerce_order_status_pending_to_processing' , 'woocommerce_order_status_pending_to_completed' , 'woocommerce_order_status_pending_to_on-hold' , 'woocommerce_order_status_failed_to_processing' , 'woocommerce_order_status_failed_to_completed' , 'woocommerce_order_status_pending_to_processing' , 'woocommerce_order_status_pending_to_on-hold' , 'woocommerce_order_status_completed' , 'woocommerce_new_customer_note' );
2012-08-07 08:38:08 +00:00
2012-11-13 23:22:53 +00:00
foreach ( $email_actions as $action )
2012-12-15 11:53:32 +00:00
add_action ( $action , array ( $this , 'send_transactional_email' ) );
2012-03-20 14:32:29 +00:00
2011-12-11 14:40:25 +00:00
// Register globals for WC environment
$this -> register_globals ();
2011-12-09 19:55:09 +00:00
// Init WooCommerce taxonomies
$this -> init_taxonomy ();
2012-08-07 08:38:08 +00:00
2011-12-09 19:55:09 +00:00
// Init Images sizes
$this -> init_image_sizes ();
2012-08-07 08:38:08 +00:00
2012-02-19 17:12:42 +00:00
// Init action
2011-12-09 19:55:09 +00:00
do_action ( 'woocommerce_init' );
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2013-01-07 17:23:09 +00:00
/**
* During checkout , ensure gateways and shipping classes are loaded so they can hook into the respective pages .
*
* @ access public
* @ return void
*/
public function init_checkout () {
if ( is_checkout () || is_order_received_page () ) {
$this -> payment_gateways ();
$this -> shipping ();
}
}
2012-02-15 20:42:00 +00:00
/**
2012-12-30 13:48:27 +00:00
* Load Localisation files .
*
* Note : the first - loaded translation file overrides any following ones if the same translation is present
2012-08-14 14:13:08 +00:00
*
* @ access public
* @ return void
*/
2012-12-14 21:19:40 +00:00
public function load_plugin_textdomain () {
2012-12-30 13:48:27 +00:00
$locale = apply_filters ( 'plugin_locale' , get_locale (), 'woocommerce' );
$formal = 'yes' == get_option ( 'woocommerce_informal_localisation_type' ) ? 'informal' : 'formal' ;
load_textdomain ( 'woocommerce' , WP_LANG_DIR . " /woocommerce/woocommerce- $locale .mo " );
2012-12-30 13:56:23 +00:00
// Load admin specific MO files
if ( is_admin () ) {
2012-12-31 13:03:56 +00:00
load_textdomain ( 'woocommerce' , WP_LANG_DIR . " /woocommerce/woocommerce-admin- $locale .mo " );
load_textdomain ( 'woocommerce' , $this -> plugin_path () . " /i18n/languages/woocommerce-admin- $locale .mo " );
2012-12-30 13:56:23 +00:00
}
2012-12-30 13:48:27 +00:00
load_plugin_textdomain ( 'woocommerce' , false , dirname ( plugin_basename ( __FILE__ ) ) . " /i18n/languages/ $formal " );
load_plugin_textdomain ( 'woocommerce' , false , dirname ( plugin_basename ( __FILE__ ) ) . " /i18n/languages " );
2012-02-15 20:42:00 +00:00
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2012-03-20 18:59:12 +00:00
/**
2012-08-14 14:13:08 +00:00
* Load a template .
2012-08-07 08:38:08 +00:00
*
2012-03-20 18:59:12 +00:00
* Handles template usage so that we can use our own templates instead of the themes .
*
2012-08-07 08:38:08 +00:00
* Templates are in the 'templates' folder . woocommerce looks for theme
2013-03-03 17:07:31 +00:00
* overrides in / theme / woocommerce / by default
2012-03-20 18:59:12 +00:00
*
2012-08-07 08:38:08 +00:00
* For beginners , it also looks for a woocommerce . php template first . If the user adds
* this to the theme ( containing a woocommerce () inside ) this will be used for all
2012-03-20 18:59:12 +00:00
* woocommerce templates .
2012-08-14 14:13:08 +00:00
*
* @ access public
* @ param mixed $template
* @ return string
2012-03-20 18:59:12 +00:00
*/
2012-12-14 21:19:40 +00:00
public function template_loader ( $template ) {
2012-08-07 08:38:08 +00:00
2012-06-14 10:08:50 +00:00
$find = array ( 'woocommerce.php' );
$file = '' ;
2012-08-07 08:38:08 +00:00
2012-03-20 18:59:12 +00:00
if ( is_single () && get_post_type () == 'product' ) {
2012-08-07 08:38:08 +00:00
2012-03-20 18:59:12 +00:00
$file = 'single-product.php' ;
$find [] = $file ;
$find [] = $this -> template_url . $file ;
2012-06-14 10:08:50 +00:00
} elseif ( is_tax ( 'product_cat' ) || is_tax ( 'product_tag' ) ) {
2012-08-07 08:38:08 +00:00
2012-03-20 18:59:12 +00:00
$term = get_queried_object ();
2012-08-07 08:38:08 +00:00
2012-03-20 18:59:12 +00:00
$file = 'taxonomy-' . $term -> taxonomy . '.php' ;
$find [] = 'taxonomy-' . $term -> taxonomy . '-' . $term -> slug . '.php' ;
$find [] = $this -> template_url . 'taxonomy-' . $term -> taxonomy . '-' . $term -> slug . '.php' ;
$find [] = $file ;
$find [] = $this -> template_url . $file ;
2012-08-07 08:38:08 +00:00
2012-06-14 10:08:50 +00:00
} elseif ( is_post_type_archive ( 'product' ) || is_page ( woocommerce_get_page_id ( 'shop' ) ) ) {
2012-08-07 08:38:08 +00:00
2012-03-20 18:59:12 +00:00
$file = 'archive-product.php' ;
$find [] = $file ;
$find [] = $this -> template_url . $file ;
2012-08-07 08:38:08 +00:00
2012-03-20 18:59:12 +00:00
}
2012-08-07 08:38:08 +00:00
2012-03-20 18:59:12 +00:00
if ( $file ) {
$template = locate_template ( $find );
if ( ! $template ) $template = $this -> plugin_path () . '/templates/' . $file ;
}
2012-08-07 08:38:08 +00:00
2012-03-20 18:59:12 +00:00
return $template ;
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
/**
* comments_template_loader function .
*
* @ access public
* @ param mixed $template
* @ return string
*/
2012-12-14 21:19:40 +00:00
public function comments_template_loader ( $template ) {
2012-12-31 13:03:56 +00:00
if ( get_post_type () !== 'product' )
return $template ;
2012-08-07 08:38:08 +00:00
2012-12-31 13:03:56 +00:00
if ( file_exists ( STYLESHEETPATH . '/' . $this -> template_url . 'single-product-reviews.php' ))
2012-08-07 08:38:08 +00:00
return STYLESHEETPATH . '/' . $this -> template_url . 'single-product-reviews.php' ;
2013-04-03 17:50:39 +00:00
elseif ( file_exists ( TEMPLATEPATH . '/' . $this -> template_url . 'single-product-reviews.php' ))
return TEMPLATEPATH . '/' . $this -> template_url . 'single-product-reviews.php' ;
2012-03-20 18:59:12 +00:00
else
return $this -> plugin_path () . '/templates/single-product-reviews.php' ;
2012-08-07 08:38:08 +00:00
}
2012-08-14 14:13:08 +00:00
2011-12-11 14:40:25 +00:00
/**
2012-08-14 14:13:08 +00:00
* Register WC environment globals .
*
* @ access public
* @ return void
*/
2012-12-14 21:19:40 +00:00
public function register_globals () {
2011-12-11 14:40:25 +00:00
$GLOBALS [ 'product' ] = null ;
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2011-12-11 14:40:25 +00:00
/**
2012-08-14 14:13:08 +00:00
* When the_post is called , get product data too .
*
* @ access public
* @ param mixed $post
* @ return WC_Product
*/
2012-12-14 21:19:40 +00:00
public function setup_product_data ( $post ) {
2012-03-27 12:20:47 +00:00
if ( is_int ( $post ) ) $post = get_post ( $post );
2012-03-20 13:22:35 +00:00
if ( $post -> post_type !== 'product' ) return ;
unset ( $GLOBALS [ 'product' ] );
2012-11-21 18:07:45 +00:00
$GLOBALS [ 'product' ] = get_product ( $post );
2012-12-31 18:25:09 +00:00
return $GLOBALS [ 'product' ];
2011-12-11 14:40:25 +00:00
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2011-12-09 17:01:56 +00:00
/**
2012-08-14 14:13:08 +00:00
* Add Compatibility for various bits .
*
* @ access public
* @ return void
*/
2012-12-14 21:19:40 +00:00
public function compatibility () {
2011-12-09 17:01:56 +00:00
// Post thumbnail support
2012-12-13 12:40:24 +00:00
if ( ! current_theme_supports ( 'post-thumbnails' , 'product' ) ) {
2011-12-09 17:01:56 +00:00
add_theme_support ( 'post-thumbnails' );
remove_post_type_support ( 'post' , 'thumbnail' );
remove_post_type_support ( 'page' , 'thumbnail' );
2012-03-20 13:22:35 +00:00
} else {
2011-12-09 17:01:56 +00:00
add_post_type_support ( 'product' , 'thumbnail' );
2012-03-20 13:22:35 +00:00
}
2012-08-07 08:38:08 +00:00
2011-12-09 17:01:56 +00:00
// IIS
2012-03-20 13:22:35 +00:00
if ( ! isset ( $_SERVER [ 'REQUEST_URI' ] ) ) {
$_SERVER [ 'REQUEST_URI' ] = substr ( $_SERVER [ 'PHP_SELF' ], 1 );
2012-08-07 08:38:08 +00:00
if ( isset ( $_SERVER [ 'QUERY_STRING' ] ) )
2012-03-20 13:22:35 +00:00
$_SERVER [ 'REQUEST_URI' ] .= '?' . $_SERVER [ 'QUERY_STRING' ];
2011-12-09 17:01:56 +00:00
}
2012-08-07 08:38:08 +00:00
2012-04-23 12:41:11 +00:00
// NGINX Proxy
if ( ! isset ( $_SERVER [ 'REMOTE_ADDR' ] ) && isset ( $_SERVER [ 'HTTP_REMOTE_ADDR' ] ) )
$_SERVER [ 'REMOTE_ADDR' ] = $_SERVER [ 'HTTP_REMOTE_ADDR' ];
2012-08-07 08:38:08 +00:00
2012-04-23 12:41:11 +00:00
if ( ! isset ( $_SERVER [ 'HTTPS' ] ) && ! empty ( $_SERVER [ 'HTTP_HTTPS' ] ) )
$_SERVER [ 'HTTPS' ] = $_SERVER [ 'HTTP_HTTPS' ];
2012-08-07 08:38:08 +00:00
2012-07-18 17:07:36 +00:00
// Support for hosts which don't use HTTPS, and use HTTP_X_FORWARDED_PROTO
2012-08-07 08:38:08 +00:00
if ( ! isset ( $_SERVER [ 'HTTPS' ] ) && ! empty ( $_SERVER [ 'HTTP_X_FORWARDED_PROTO' ] ) && $_SERVER [ 'HTTP_X_FORWARDED_PROTO' ] == 'https' )
2012-07-18 17:07:36 +00:00
$_SERVER [ 'HTTPS' ] = '1' ;
2011-12-09 17:01:56 +00:00
}
2011-12-09 19:55:09 +00:00
2012-08-14 14:13:08 +00:00
2011-12-09 17:01:56 +00:00
/**
2012-08-14 14:13:08 +00:00
* Output generator to aid debugging .
*
* @ access public
* @ return void
*/
2012-12-14 21:19:40 +00:00
public function generator () {
2012-10-16 13:35:17 +00:00
echo " \n \n " . '<!-- WooCommerce Version -->' . " \n " . '<meta name="generator" content="WooCommerce ' . esc_attr ( $this -> version ) . '" />' . " \n \n " ;
2012-02-27 13:14:33 +00:00
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2012-02-27 13:14:33 +00:00
/**
2012-08-14 14:13:08 +00:00
* Add body classes .
*
* @ access public
* @ return void
*/
2012-12-14 21:19:40 +00:00
public function wp_head () {
2013-02-10 23:02:52 +00:00
2012-12-30 15:51:37 +00:00
if ( is_woocommerce () ) {
$this -> add_body_class ( 'woocommerce' );
$this -> add_body_class ( 'woocommerce-page' );
return ;
}
2012-08-07 08:38:08 +00:00
2012-12-30 15:51:37 +00:00
if ( is_checkout () || is_order_received_page () ) {
$this -> add_body_class ( 'woocommerce-checkout' );
$this -> add_body_class ( 'woocommerce-page' );
return ;
}
2012-08-07 08:38:08 +00:00
2012-12-30 15:51:37 +00:00
if ( is_cart () ) {
$this -> add_body_class ( 'woocommerce-cart' );
$this -> add_body_class ( 'woocommerce-page' );
return ;
}
2012-08-07 08:38:08 +00:00
2012-12-30 15:51:37 +00:00
if ( is_account_page () ) {
$this -> add_body_class ( 'woocommerce-account' );
$this -> add_body_class ( 'woocommerce-page' );
return ;
}
2013-02-10 23:02:52 +00:00
2011-08-10 17:11:11 +00:00
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2011-12-09 17:01:56 +00:00
/**
2012-08-14 14:13:08 +00:00
* Init WooCommerce taxonomies .
*
* @ access public
* @ return void
*/
2012-12-14 21:19:40 +00:00
public function init_taxonomy () {
2012-08-07 08:38:08 +00:00
2012-11-13 23:22:53 +00:00
if ( post_type_exists ( 'product' ) )
2012-10-10 09:21:04 +00:00
return ;
2012-08-07 08:38:08 +00:00
2011-12-09 17:01:56 +00:00
/**
* Slugs
**/
2012-10-10 09:21:04 +00:00
$permalinks = get_option ( 'woocommerce_permalinks' );
$shop_page_id = woocommerce_get_page_id ( 'shop' );
2012-11-13 23:22:53 +00:00
2012-10-10 09:21:04 +00:00
// Base slug is also used for the product post type archive
$base_slug = $shop_page_id > 0 && get_page ( $shop_page_id ) ? get_page_uri ( $shop_page_id ) : 'shop' ;
2012-11-13 23:22:53 +00:00
2012-10-10 09:21:04 +00:00
// Get bases
$product_category_slug = empty ( $permalinks [ 'category_base' ] ) ? _x ( 'product-category' , 'slug' , 'woocommerce' ) : $permalinks [ 'category_base' ];
$product_tag_slug = empty ( $permalinks [ 'tag_base' ] ) ? _x ( 'product-tag' , 'slug' , 'woocommerce' ) : $permalinks [ 'tag_base' ];
2013-03-12 14:39:57 +00:00
$product_attribute_base = empty ( $permalinks [ 'attribute_base' ] ) ? '' : trailingslashit ( $permalinks [ 'attribute_base' ] );
2012-10-10 09:21:04 +00:00
$product_permalink = empty ( $permalinks [ 'product_base' ] ) ? _x ( 'product' , 'slug' , 'woocommerce' ) : $permalinks [ 'product_base' ];
2012-11-13 23:22:53 +00:00
if ( $product_permalink )
2012-10-14 12:06:37 +00:00
$rewrite = array ( 'slug' => untrailingslashit ( $product_permalink ), 'with_front' => false , 'feeds' => true );
2012-10-10 09:21:04 +00:00
else
$rewrite = false ;
2012-11-13 23:22:53 +00:00
2012-10-10 09:21:04 +00:00
$show_in_menu = current_user_can ( 'manage_woocommerce' ) ? 'woocommerce' : true ;
2012-08-07 08:38:08 +00:00
2011-12-09 17:01:56 +00:00
/**
* Taxonomies
**/
2012-08-08 15:57:32 +00:00
do_action ( 'woocommerce_register_taxonomy' );
2013-03-23 21:33:19 +00:00
$admin_only_query_var = is_admin ();
2012-08-07 08:38:08 +00:00
2011-12-09 17:01:56 +00:00
register_taxonomy ( 'product_type' ,
2013-02-06 09:52:07 +00:00
apply_filters ( 'woocommerce_taxonomy_objects_product_type' , array ( 'product' ) ),
apply_filters ( 'woocommerce_taxonomy_args_product_type' , array (
2011-12-09 17:01:56 +00:00
'hierarchical' => false ,
2012-05-08 23:53:23 +00:00
'update_count_callback' => '_update_post_term_count' ,
2011-12-09 17:01:56 +00:00
'show_ui' => false ,
'show_in_nav_menus' => false ,
'query_var' => $admin_only_query_var ,
'rewrite' => false
2013-02-06 09:52:07 +00:00
) )
2011-12-09 17:01:56 +00:00
);
register_taxonomy ( 'product_cat' ,
2013-02-06 09:52:07 +00:00
apply_filters ( 'woocommerce_taxonomy_objects_product_cat' , array ( 'product' ) ),
apply_filters ( 'woocommerce_taxonomy_args_product_cat' , array (
2012-01-31 16:21:29 +00:00
'hierarchical' => true ,
2012-11-28 15:03:22 +00:00
'update_count_callback' => '_woocommerce_term_recount' ,
2012-01-05 11:31:22 +00:00
'label' => __ ( 'Product Categories' , 'woocommerce' ),
2011-12-09 17:01:56 +00:00
'labels' => array (
2012-01-05 11:31:22 +00:00
'name' => __ ( 'Product Categories' , 'woocommerce' ),
'singular_name' => __ ( 'Product Category' , 'woocommerce' ),
2012-07-26 14:33:02 +00:00
'menu_name' => _x ( 'Categories' , 'Admin menu name' , 'woocommerce' ),
2012-01-05 11:31:22 +00:00
'search_items' => __ ( 'Search Product Categories' , 'woocommerce' ),
'all_items' => __ ( 'All Product Categories' , 'woocommerce' ),
'parent_item' => __ ( 'Parent Product Category' , 'woocommerce' ),
'parent_item_colon' => __ ( 'Parent Product Category:' , 'woocommerce' ),
'edit_item' => __ ( 'Edit Product Category' , 'woocommerce' ),
'update_item' => __ ( 'Update Product Category' , 'woocommerce' ),
'add_new_item' => __ ( 'Add New Product Category' , 'woocommerce' ),
'new_item_name' => __ ( 'New Product Category Name' , 'woocommerce' )
2011-12-09 17:01:56 +00:00
),
'show_ui' => true ,
'query_var' => true ,
2012-01-09 13:14:36 +00:00
'capabilities' => array (
2012-09-20 15:35:15 +00:00
'manage_terms' => 'manage_product_terms' ,
'edit_terms' => 'edit_product_terms' ,
'delete_terms' => 'delete_product_terms' ,
'assign_terms' => 'assign_product_terms' ,
2012-01-09 13:14:36 +00:00
),
2013-01-12 10:53:24 +00:00
'rewrite' => array (
'slug' => $product_category_slug ,
'with_front' => false ,
'hierarchical' => true ,
//'ep_mask' => EP_CATEGORIES
),
2013-02-06 09:52:07 +00:00
) )
2011-12-09 17:01:56 +00:00
);
2012-08-07 08:38:08 +00:00
2011-12-09 17:01:56 +00:00
register_taxonomy ( 'product_tag' ,
2013-02-06 09:52:07 +00:00
apply_filters ( 'woocommerce_taxonomy_objects_product_tag' , array ( 'product' ) ),
apply_filters ( 'woocommerce_taxonomy_args_product_tag' , array (
2011-12-09 17:01:56 +00:00
'hierarchical' => false ,
2012-11-28 15:03:22 +00:00
'update_count_callback' => '_woocommerce_term_recount' ,
2012-01-05 11:31:22 +00:00
'label' => __ ( 'Product Tags' , 'woocommerce' ),
2011-12-09 17:01:56 +00:00
'labels' => array (
2012-07-26 14:33:02 +00:00
'name' => __ ( 'Product Tags' , 'woocommerce' ),
2012-01-05 11:31:22 +00:00
'singular_name' => __ ( 'Product Tag' , 'woocommerce' ),
2012-06-07 08:06:33 +00:00
'menu_name' => _x ( 'Tags' , 'Admin menu name' , 'woocommerce' ),
2012-01-05 11:31:22 +00:00
'search_items' => __ ( 'Search Product Tags' , 'woocommerce' ),
'all_items' => __ ( 'All Product Tags' , 'woocommerce' ),
'parent_item' => __ ( 'Parent Product Tag' , 'woocommerce' ),
'parent_item_colon' => __ ( 'Parent Product Tag:' , 'woocommerce' ),
'edit_item' => __ ( 'Edit Product Tag' , 'woocommerce' ),
'update_item' => __ ( 'Update Product Tag' , 'woocommerce' ),
'add_new_item' => __ ( 'Add New Product Tag' , 'woocommerce' ),
'new_item_name' => __ ( 'New Product Tag Name' , 'woocommerce' )
2011-12-09 17:01:56 +00:00
),
'show_ui' => true ,
'query_var' => true ,
2012-01-09 13:14:36 +00:00
'capabilities' => array (
2012-09-20 15:35:15 +00:00
'manage_terms' => 'manage_product_terms' ,
'edit_terms' => 'edit_product_terms' ,
'delete_terms' => 'delete_product_terms' ,
'assign_terms' => 'assign_product_terms' ,
2012-01-09 13:14:36 +00:00
),
2012-10-10 09:21:04 +00:00
'rewrite' => array ( 'slug' => $product_tag_slug , 'with_front' => false ),
2013-02-06 09:52:07 +00:00
) )
2011-12-09 17:01:56 +00:00
);
2012-08-07 08:38:08 +00:00
2011-12-09 17:01:56 +00:00
register_taxonomy ( 'product_shipping_class' ,
2013-02-06 10:15:58 +00:00
apply_filters ( 'woocommerce_taxonomy_objects_product_shipping_class' , array ( 'product' , 'product_variation' ) ),
2013-02-06 09:52:07 +00:00
apply_filters ( 'woocommerce_taxonomy_args_product_shipping_class' , array (
2011-12-09 17:01:56 +00:00
'hierarchical' => true ,
'update_count_callback' => '_update_post_term_count' ,
2012-01-05 11:31:22 +00:00
'label' => __ ( 'Shipping Classes' , 'woocommerce' ),
2011-12-09 17:01:56 +00:00
'labels' => array (
2012-01-05 11:31:22 +00:00
'name' => __ ( 'Shipping Classes' , 'woocommerce' ),
'singular_name' => __ ( 'Shipping Class' , 'woocommerce' ),
2012-06-07 08:06:33 +00:00
'menu_name' => _x ( 'Shipping Classes' , 'Admin menu name' , 'woocommerce' ),
2012-01-05 11:31:22 +00:00
'search_items' => __ ( 'Search Shipping Classes' , 'woocommerce' ),
'all_items' => __ ( 'All Shipping Classes' , 'woocommerce' ),
'parent_item' => __ ( 'Parent Shipping Class' , 'woocommerce' ),
'parent_item_colon' => __ ( 'Parent Shipping Class:' , 'woocommerce' ),
'edit_item' => __ ( 'Edit Shipping Class' , 'woocommerce' ),
'update_item' => __ ( 'Update Shipping Class' , 'woocommerce' ),
'add_new_item' => __ ( 'Add New Shipping Class' , 'woocommerce' ),
'new_item_name' => __ ( 'New Shipping Class Name' , 'woocommerce' )
2011-12-09 17:01:56 +00:00
),
'show_ui' => true ,
'show_in_nav_menus' => false ,
'query_var' => $admin_only_query_var ,
2012-01-09 13:14:36 +00:00
'capabilities' => array (
2012-09-20 15:35:15 +00:00
'manage_terms' => 'manage_product_terms' ,
'edit_terms' => 'edit_product_terms' ,
'delete_terms' => 'delete_product_terms' ,
'assign_terms' => 'assign_product_terms' ,
2012-01-09 13:14:36 +00:00
),
2011-12-09 17:01:56 +00:00
'rewrite' => false ,
2013-02-06 09:52:07 +00:00
) )
2011-12-09 17:01:56 +00:00
);
2012-08-07 08:38:08 +00:00
2011-12-09 17:01:56 +00:00
register_taxonomy ( 'shop_order_status' ,
2013-02-06 10:15:58 +00:00
apply_filters ( 'woocommerce_taxonomy_objects_shop_order_status' , array ( 'shop_order' ) ),
2013-02-06 09:52:07 +00:00
apply_filters ( 'woocommerce_taxonomy_args_shop_order_status' , array (
2012-02-27 15:02:44 +00:00
'hierarchical' => false ,
2011-12-09 17:01:56 +00:00
'update_count_callback' => '_update_post_term_count' ,
'show_ui' => false ,
'show_in_nav_menus' => false ,
'query_var' => $admin_only_query_var ,
'rewrite' => false ,
2013-02-06 09:52:07 +00:00
) )
2011-12-09 17:01:56 +00:00
);
2012-08-07 08:38:08 +00:00
$attribute_taxonomies = $this -> get_attribute_taxonomies ();
2012-03-20 13:22:35 +00:00
if ( $attribute_taxonomies ) {
foreach ( $attribute_taxonomies as $tax ) {
2012-08-07 08:38:08 +00:00
2012-12-05 15:01:29 +00:00
$name = $this -> attribute_taxonomy_name ( $tax -> attribute_name );
2011-12-09 17:01:56 +00:00
$hierarchical = true ;
2012-03-20 13:22:35 +00:00
if ( $name ) {
2012-08-07 08:38:08 +00:00
2011-12-09 17:01:56 +00:00
$label = ( isset ( $tax -> attribute_label ) && $tax -> attribute_label ) ? $tax -> attribute_label : $tax -> attribute_name ;
2012-08-07 08:38:08 +00:00
2012-10-09 14:57:02 +00:00
$show_in_nav_menus = apply_filters ( 'woocommerce_attribute_show_in_nav_menus' , false , $name );
2012-08-07 08:38:08 +00:00
2011-12-09 17:01:56 +00:00
register_taxonomy ( $name ,
2013-02-06 10:15:58 +00:00
apply_filters ( 'woocommerce_taxonomy_objects_' . $name , array ( 'product' ) ),
2013-02-06 09:52:07 +00:00
apply_filters ( 'woocommerce_taxonomy_args_' . $name , array (
2011-12-09 17:01:56 +00:00
'hierarchical' => $hierarchical ,
2012-05-08 23:53:23 +00:00
'update_count_callback' => '_update_post_term_count' ,
2011-12-09 17:01:56 +00:00
'labels' => array (
'name' => $label ,
'singular_name' => $label ,
2012-01-05 11:31:22 +00:00
'search_items' => __ ( 'Search' , 'woocommerce' ) . ' ' . $label ,
'all_items' => __ ( 'All' , 'woocommerce' ) . ' ' . $label ,
'parent_item' => __ ( 'Parent' , 'woocommerce' ) . ' ' . $label ,
'parent_item_colon' => __ ( 'Parent' , 'woocommerce' ) . ' ' . $label . ':' ,
'edit_item' => __ ( 'Edit' , 'woocommerce' ) . ' ' . $label ,
'update_item' => __ ( 'Update' , 'woocommerce' ) . ' ' . $label ,
'add_new_item' => __ ( 'Add New' , 'woocommerce' ) . ' ' . $label ,
'new_item_name' => __ ( 'New' , 'woocommerce' ) . ' ' . $label
2011-12-09 17:01:56 +00:00
),
'show_ui' => false ,
'query_var' => true ,
2012-09-20 15:35:15 +00:00
'capabilities' => array (
'manage_terms' => 'manage_product_terms' ,
'edit_terms' => 'edit_product_terms' ,
'delete_terms' => 'delete_product_terms' ,
'assign_terms' => 'assign_product_terms' ,
),
2011-12-09 17:01:56 +00:00
'show_in_nav_menus' => $show_in_nav_menus ,
2012-12-05 15:01:29 +00:00
'rewrite' => array ( 'slug' => $product_attribute_base . sanitize_title ( $tax -> attribute_name ), 'with_front' => false , 'hierarchical' => $hierarchical ),
2013-02-06 09:52:07 +00:00
) )
2011-12-09 17:01:56 +00:00
);
2012-08-07 08:38:08 +00:00
2012-03-20 13:22:35 +00:00
}
2012-08-07 08:38:08 +00:00
}
2012-03-20 13:22:35 +00:00
}
2012-08-07 08:38:08 +00:00
2011-12-09 17:01:56 +00:00
/**
* Post Types
**/
2012-08-08 15:57:32 +00:00
do_action ( 'woocommerce_register_post_type' );
2012-11-13 23:22:53 +00:00
2011-12-09 17:01:56 +00:00
register_post_type ( " product " ,
2012-11-13 23:22:53 +00:00
apply_filters ( 'woocommerce_register_post_type_product' ,
2012-09-21 16:01:22 +00:00
array (
'labels' => array (
'name' => __ ( 'Products' , 'woocommerce' ),
'singular_name' => __ ( 'Product' , 'woocommerce' ),
'menu_name' => _x ( 'Products' , 'Admin menu name' , 'woocommerce' ),
'add_new' => __ ( 'Add Product' , 'woocommerce' ),
'add_new_item' => __ ( 'Add New Product' , 'woocommerce' ),
'edit' => __ ( 'Edit' , 'woocommerce' ),
'edit_item' => __ ( 'Edit Product' , 'woocommerce' ),
'new_item' => __ ( 'New Product' , 'woocommerce' ),
'view' => __ ( 'View Product' , 'woocommerce' ),
'view_item' => __ ( 'View Product' , 'woocommerce' ),
'search_items' => __ ( 'Search Products' , 'woocommerce' ),
'not_found' => __ ( 'No Products found' , 'woocommerce' ),
'not_found_in_trash' => __ ( 'No Products found in trash' , 'woocommerce' ),
'parent' => __ ( 'Parent Product' , 'woocommerce' )
),
'description' => __ ( 'This is where you can add new products to your store.' , 'woocommerce' ),
'public' => true ,
'show_ui' => true ,
'capability_type' => 'product' ,
'map_meta_cap' => true ,
'publicly_queryable' => true ,
'exclude_from_search' => false ,
2013-03-03 17:07:31 +00:00
'hierarchical' => false , // Hierarchical causes memory issues - WP loads all records!
2012-10-10 09:21:04 +00:00
'rewrite' => $rewrite ,
2012-09-21 16:01:22 +00:00
'query_var' => true ,
'supports' => array ( 'title' , 'editor' , 'excerpt' , 'thumbnail' , 'comments' , 'custom-fields' , 'page-attributes' ),
'has_archive' => $base_slug ,
'show_in_nav_menus' => true
)
2011-12-09 17:01:56 +00:00
)
);
2012-08-07 08:38:08 +00:00
2012-08-09 10:50:15 +00:00
// Sort out attachment urls (removed, breaks pagination) no alternatives add_rewrite_rule( '^' . $attachment_base . '([^/]*)/([^/]*)/([^/]*)/?', 'index.php?attachment=$matches[3]', 'top' );
2012-08-07 08:38:08 +00:00
2011-12-09 17:01:56 +00:00
register_post_type ( " product_variation " ,
2012-11-13 23:22:53 +00:00
apply_filters ( 'woocommerce_register_post_type_product_variation' ,
2012-09-21 16:01:22 +00:00
array (
'labels' => array (
'name' => __ ( 'Variations' , 'woocommerce' ),
'singular_name' => __ ( 'Variation' , 'woocommerce' ),
'add_new' => __ ( 'Add Variation' , 'woocommerce' ),
'add_new_item' => __ ( 'Add New Variation' , 'woocommerce' ),
'edit' => __ ( 'Edit' , 'woocommerce' ),
'edit_item' => __ ( 'Edit Variation' , 'woocommerce' ),
'new_item' => __ ( 'New Variation' , 'woocommerce' ),
'view' => __ ( 'View Variation' , 'woocommerce' ),
'view_item' => __ ( 'View Variation' , 'woocommerce' ),
'search_items' => __ ( 'Search Variations' , 'woocommerce' ),
'not_found' => __ ( 'No Variations found' , 'woocommerce' ),
'not_found_in_trash' => __ ( 'No Variations found in trash' , 'woocommerce' ),
'parent' => __ ( 'Parent Variation' , 'woocommerce' )
),
2013-05-06 20:42:59 +00:00
'public' => false ,
2012-09-21 16:01:22 +00:00
'show_ui' => false ,
'capability_type' => 'product' ,
'map_meta_cap' => true ,
'publicly_queryable' => false ,
'exclude_from_search' => true ,
'hierarchical' => false ,
'rewrite' => false ,
2013-05-06 20:42:59 +00:00
'query_var' => false ,
2012-09-21 16:01:22 +00:00
'supports' => array ( 'title' , 'editor' , 'custom-fields' , 'page-attributes' , 'thumbnail' ),
'show_in_nav_menus' => false
)
2011-12-09 17:01:56 +00:00
)
);
2012-08-07 08:38:08 +00:00
2012-06-07 08:06:33 +00:00
$menu_name = _x ( 'Orders' , 'Admin menu name' , 'woocommerce' );
2012-07-23 12:56:05 +00:00
if ( $order_count = woocommerce_processing_order_count () ) {
$menu_name .= " <span class='awaiting-mod update-plugins count- $order_count '><span class='processing-count'> " . number_format_i18n ( $order_count ) . " </span></span> " ;
2012-06-07 08:06:33 +00:00
}
2011-12-09 17:01:56 +00:00
register_post_type ( " shop_order " ,
2012-11-13 23:22:53 +00:00
apply_filters ( 'woocommerce_register_post_type_shop_order' ,
2012-09-21 16:01:22 +00:00
array (
'labels' => array (
'name' => __ ( 'Orders' , 'woocommerce' ),
'singular_name' => __ ( 'Order' , 'woocommerce' ),
'add_new' => __ ( 'Add Order' , 'woocommerce' ),
'add_new_item' => __ ( 'Add New Order' , 'woocommerce' ),
'edit' => __ ( 'Edit' , 'woocommerce' ),
'edit_item' => __ ( 'Edit Order' , 'woocommerce' ),
'new_item' => __ ( 'New Order' , 'woocommerce' ),
'view' => __ ( 'View Order' , 'woocommerce' ),
'view_item' => __ ( 'View Order' , 'woocommerce' ),
'search_items' => __ ( 'Search Orders' , 'woocommerce' ),
'not_found' => __ ( 'No Orders found' , 'woocommerce' ),
'not_found_in_trash' => __ ( 'No Orders found in trash' , 'woocommerce' ),
'parent' => __ ( 'Parent Orders' , 'woocommerce' ),
'menu_name' => $menu_name
),
'description' => __ ( 'This is where store orders are stored.' , 'woocommerce' ),
2013-04-08 16:54:16 +00:00
'public' => false ,
2012-09-21 16:01:22 +00:00
'show_ui' => true ,
'capability_type' => 'shop_order' ,
'map_meta_cap' => true ,
'publicly_queryable' => false ,
'exclude_from_search' => true ,
'show_in_menu' => $show_in_menu ,
'hierarchical' => false ,
'show_in_nav_menus' => false ,
'rewrite' => false ,
2013-04-08 16:54:16 +00:00
'query_var' => false ,
2012-09-21 16:01:22 +00:00
'supports' => array ( 'title' , 'comments' , 'custom-fields' ),
'has_archive' => false ,
)
2011-12-09 17:01:56 +00:00
)
);
2012-08-07 08:38:08 +00:00
2011-12-09 17:01:56 +00:00
register_post_type ( " shop_coupon " ,
2012-09-21 16:01:22 +00:00
apply_filters ( 'woocommerce_register_post_type_shop_coupon' ,
array (
'labels' => array (
'name' => __ ( 'Coupons' , 'woocommerce' ),
'singular_name' => __ ( 'Coupon' , 'woocommerce' ),
'menu_name' => _x ( 'Coupons' , 'Admin menu name' , 'woocommerce' ),
'add_new' => __ ( 'Add Coupon' , 'woocommerce' ),
'add_new_item' => __ ( 'Add New Coupon' , 'woocommerce' ),
'edit' => __ ( 'Edit' , 'woocommerce' ),
'edit_item' => __ ( 'Edit Coupon' , 'woocommerce' ),
'new_item' => __ ( 'New Coupon' , 'woocommerce' ),
'view' => __ ( 'View Coupons' , 'woocommerce' ),
'view_item' => __ ( 'View Coupon' , 'woocommerce' ),
'search_items' => __ ( 'Search Coupons' , 'woocommerce' ),
'not_found' => __ ( 'No Coupons found' , 'woocommerce' ),
'not_found_in_trash' => __ ( 'No Coupons found in trash' , 'woocommerce' ),
'parent' => __ ( 'Parent Coupon' , 'woocommerce' )
),
'description' => __ ( 'This is where you can add new coupons that customers can use in your store.' , 'woocommerce' ),
2013-05-06 20:42:59 +00:00
'public' => false ,
2012-09-21 16:01:22 +00:00
'show_ui' => true ,
'capability_type' => 'shop_coupon' ,
'map_meta_cap' => true ,
'publicly_queryable' => false ,
'exclude_from_search' => true ,
'show_in_menu' => $show_in_menu ,
'hierarchical' => false ,
'rewrite' => false ,
'query_var' => false ,
'supports' => array ( 'title' ),
'show_in_nav_menus' => false
)
2011-12-09 17:01:56 +00:00
)
);
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2011-12-09 17:01:56 +00:00
/**
2012-08-14 14:13:08 +00:00
* Init images .
*
* @ access public
* @ return void
2011-12-09 17:01:56 +00:00
*/
2012-12-14 21:19:40 +00:00
public function init_image_sizes () {
2012-11-27 15:37:01 +00:00
$shop_thumbnail = $this -> get_image_size ( 'shop_thumbnail' );
$shop_catalog = $this -> get_image_size ( 'shop_catalog' );
$shop_single = $this -> get_image_size ( 'shop_single' );
add_image_size ( 'shop_thumbnail' , $shop_thumbnail [ 'width' ], $shop_thumbnail [ 'height' ], $shop_thumbnail [ 'crop' ] );
add_image_size ( 'shop_catalog' , $shop_catalog [ 'width' ], $shop_catalog [ 'height' ], $shop_catalog [ 'crop' ] );
add_image_size ( 'shop_single' , $shop_single [ 'width' ], $shop_single [ 'height' ], $shop_single [ 'crop' ] );
2011-12-09 17:01:56 +00:00
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2011-12-09 17:01:56 +00:00
/**
2012-08-14 14:13:08 +00:00
* Register / queue frontend scripts .
*
* @ access public
* @ return void
2011-12-09 17:01:56 +00:00
*/
2012-12-14 21:19:40 +00:00
public function frontend_scripts () {
2012-08-12 12:15:27 +00:00
global $post ;
2012-07-17 14:09:18 +00:00
$suffix = defined ( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' ;
2013-02-25 10:32:13 +00:00
$lightbox_en = get_option ( 'woocommerce_enable_lightbox' ) == 'yes' ? true : false ;
2012-07-17 14:09:18 +00:00
$chosen_en = get_option ( 'woocommerce_enable_chosen' ) == 'yes' ? true : false ;
2013-02-25 10:32:13 +00:00
$ajax_cart_en = get_option ( 'woocommerce_enable_ajax_add_to_cart' ) == 'yes' ? true : false ;
2012-07-17 14:09:18 +00:00
$frontend_script_path = $this -> plugin_url () . '/assets/js/frontend/' ;
2012-08-07 08:38:08 +00:00
2013-03-03 17:07:31 +00:00
// Register any scripts for later use, or used as dependencies
2013-04-05 12:17:39 +00:00
wp_register_script ( 'chosen' , $this -> plugin_url () . '/assets/js/chosen/chosen.jquery' . $suffix . '.js' , array ( 'jquery' ), '0.9.11' , true );
wp_register_script ( 'jquery-blockui' , $this -> plugin_url () . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js' , array ( 'jquery' ), '2.50' , true );
2012-10-17 13:32:25 +00:00
wp_register_script ( 'jquery-placeholder' , $this -> plugin_url () . '/assets/js/jquery-placeholder/jquery.placeholder' . $suffix . '.js' , array ( 'jquery' ), $this -> version , true );
2012-08-24 17:34:31 +00:00
wp_register_script ( 'wc-add-to-cart-variation' , $frontend_script_path . 'add-to-cart-variation' . $suffix . '.js' , array ( 'jquery' ), $this -> version , true );
wp_register_script ( 'wc-single-product' , $frontend_script_path . 'single-product' . $suffix . '.js' , array ( 'jquery' ), $this -> version , true );
2013-01-28 10:59:19 +00:00
wp_register_script ( 'jquery-cookie' , $this -> plugin_url () . '/assets/js/jquery-cookie/jquery.cookie' . $suffix . '.js' , array ( 'jquery' ), '1.3.1' , true );
2012-08-07 08:38:08 +00:00
2012-07-17 14:09:18 +00:00
// Queue frontend scripts conditionally
2013-02-25 10:32:13 +00:00
if ( $ajax_cart_en )
2012-08-24 17:34:31 +00:00
wp_enqueue_script ( 'wc-add-to-cart' , $frontend_script_path . 'add-to-cart' . $suffix . '.js' , array ( 'jquery' ), $this -> version , true );
2012-08-07 08:38:08 +00:00
2012-07-17 14:09:18 +00:00
if ( is_cart () )
2012-08-24 17:34:31 +00:00
wp_enqueue_script ( 'wc-cart' , $frontend_script_path . 'cart' . $suffix . '.js' , array ( 'jquery' ), $this -> version , true );
2012-08-07 08:38:08 +00:00
2013-02-25 10:32:13 +00:00
if ( is_checkout () ) {
if ( $chosen_en ) {
wp_enqueue_script ( 'wc-chosen' , $frontend_script_path . 'chosen-frontend' . $suffix . '.js' , array ( 'chosen' ), $this -> version , true );
wp_enqueue_style ( 'woocommerce_chosen_styles' , $this -> plugin_url () . '/assets/css/chosen.css' );
}
2012-07-17 14:09:18 +00:00
2013-02-25 10:32:13 +00:00
wp_enqueue_script ( 'wc-checkout' , $frontend_script_path . 'checkout' . $suffix . '.js' , array ( 'jquery' , 'woocommerce' ), $this -> version , true );
}
2012-08-07 08:38:08 +00:00
2012-08-12 12:15:27 +00:00
if ( $lightbox_en && ( is_product () || ( ! empty ( $post -> post_content ) && strstr ( $post -> post_content , '[product_page' ) ) ) ) {
2013-04-05 12:17:39 +00:00
wp_enqueue_script ( 'prettyPhoto' , $this -> plugin_url () . '/assets/js/prettyPhoto/jquery.prettyPhoto' . $suffix . '.js' , array ( 'jquery' ), '3.1.5' , true );
2013-01-30 16:18:36 +00:00
wp_enqueue_script ( 'prettyPhoto-init' , $this -> plugin_url () . '/assets/js/prettyPhoto/jquery.prettyPhoto.init' . $suffix . '.js' , array ( 'jquery' ), $this -> version , true );
wp_enqueue_style ( 'woocommerce_prettyPhoto_css' , $this -> plugin_url () . '/assets/css/prettyPhoto.css' );
2012-03-18 13:35:02 +00:00
}
2012-08-07 08:38:08 +00:00
2013-02-25 10:32:13 +00:00
if ( is_product () )
wp_enqueue_script ( 'wc-single-product' );
2012-08-07 08:38:08 +00:00
2012-07-17 14:09:18 +00:00
// Global frontend scripts
2013-02-26 12:15:12 +00:00
wp_enqueue_script ( 'woocommerce' , $frontend_script_path . 'woocommerce' . $suffix . '.js' , array ( 'jquery' , 'jquery-blockui' ), $this -> version , true );
wp_enqueue_script ( 'wc-cart-fragments' , $frontend_script_path . 'cart-fragments' . $suffix . '.js' , array ( 'jquery' , 'jquery-cookie' ), $this -> version , true );
2012-12-12 10:33:16 +00:00
wp_enqueue_script ( 'jquery-placeholder' );
2012-08-07 08:38:08 +00:00
2012-07-17 14:09:18 +00:00
// Variables for JS scripts
2011-12-09 17:01:56 +00:00
$woocommerce_params = array (
2012-12-10 13:11:05 +00:00
'countries' => json_encode ( $this -> countries -> get_allowed_country_states () ),
'plugin_url' => $this -> plugin_url (),
'ajax_url' => $this -> ajax_url (),
2012-12-13 15:53:36 +00:00
'ajax_loader_url' => apply_filters ( 'woocommerce_ajax_loader_url' , $this -> plugin_url () . '/assets/images/ajax-loader@2x.gif' ),
2012-12-10 13:11:05 +00:00
'i18n_select_state_text' => esc_attr__ ( 'Select an option…' , 'woocommerce' ),
'i18n_required_rating_text' => esc_attr__ ( 'Please select a rating' , 'woocommerce' ),
'i18n_no_matching_variations_text' => esc_attr__ ( 'Sorry, no products matched your selection. Please choose a different combination.' , 'woocommerce' ),
'i18n_required_text' => esc_attr__ ( 'required' , 'woocommerce' ),
'i18n_view_cart' => esc_attr__ ( 'View Cart →' , 'woocommerce' ),
'review_rating_required' => get_option ( 'woocommerce_review_rating_required' ),
'update_order_review_nonce' => wp_create_nonce ( " update-order-review " ),
'apply_coupon_nonce' => wp_create_nonce ( " apply-coupon " ),
'option_guest_checkout' => get_option ( 'woocommerce_enable_guest_checkout' ),
'checkout_url' => add_query_arg ( 'action' , 'woocommerce-checkout' , $this -> ajax_url () ),
'is_checkout' => is_page ( woocommerce_get_page_id ( 'checkout' ) ) ? 1 : 0 ,
'update_shipping_method_nonce' => wp_create_nonce ( " update-shipping-method " ),
'cart_url' => get_permalink ( woocommerce_get_page_id ( 'cart' ) ),
2013-02-10 23:02:52 +00:00
'cart_redirect_after_add' => get_option ( 'woocommerce_cart_redirect_after_add' )
2011-12-09 17:01:56 +00:00
);
2012-08-07 08:38:08 +00:00
if ( is_checkout () || is_cart () )
2011-12-15 23:24:02 +00:00
$woocommerce_params [ 'locale' ] = json_encode ( $this -> countries -> get_country_locale () );
2012-08-07 08:38:08 +00:00
2012-07-17 14:09:18 +00:00
wp_localize_script ( 'woocommerce' , 'woocommerce_params' , apply_filters ( 'woocommerce_params' , $woocommerce_params ) );
2012-12-31 13:03:56 +00:00
// CSS Styles
2013-05-14 17:28:36 +00:00
if ( ! defined ( 'WOOCOMMERCE_USE_CSS' ) )
define ( 'WOOCOMMERCE_USE_CSS' , true );
2012-12-31 13:03:56 +00:00
2013-05-14 17:28:36 +00:00
if ( WOOCOMMERCE_USE_CSS ) {
2013-05-15 16:47:27 +00:00
$css = file_exists ( get_stylesheet_directory () . '/woocommerce/style.css' ) ? get_stylesheet_directory_uri () . '/woocommerce/style.css' : $this -> plugin_url () . '/assets/css/woocommerce.css' ;
$css_layout = file_exists ( get_stylesheet_directory () . '/woocommerce/style-layout.css' ) ? get_stylesheet_directory_uri () . '/woocommerce/style-layout.css' : $this -> plugin_url () . '/assets/css/woocommerce-layout.css' ;
$css_smallscreen = file_exists ( get_stylesheet_directory () . '/woocommerce/style-smallscreen.css' ) ? get_stylesheet_directory_uri () . '/woocommerce/style-smallscreen.css' : $this -> plugin_url () . '/assets/css/woocommerce-smallscreen.css' ;
2013-05-09 14:39:35 +00:00
2013-05-14 17:28:36 +00:00
wp_enqueue_style ( 'woocommerce_frontend_styles_layout' , $css_layout );
2013-05-15 16:47:27 +00:00
wp_enqueue_style ( 'woocommerce_frontend_styles_smallscreen' , $css_smallscreen , '' , '' , 'only screen and (max-width: ' . apply_filters ( 'woocommerce_smallscreen_breakpoint' , $breakpoint = '768px' ) . ' )' );
wp_enqueue_style ( 'woocommerce_frontend_styles' , $css );
2013-05-13 15:02:18 +00:00
}
2012-08-25 08:47:32 +00:00
}
2012-11-13 23:22:53 +00:00
2012-08-25 08:47:32 +00:00
/**
* WC requires jQuery 1.7 since it uses functions like . on () for events .
* If , by the time wp_print_scrips is called , jQuery is outdated ( i . e not
2012-11-13 23:22:53 +00:00
* using the version in core ) we need to deregister it and register the
2012-08-25 08:47:32 +00:00
* core version of the file .
2012-11-13 23:22:53 +00:00
*
2012-08-25 08:47:32 +00:00
* @ access public
* @ return void
*/
2012-12-14 21:19:40 +00:00
public function check_jquery () {
2012-08-25 08:47:32 +00:00
global $wp_scripts ;
2012-11-13 23:22:53 +00:00
2012-08-25 08:47:32 +00:00
// Enforce minimum version of jQuery
2013-05-01 13:32:47 +00:00
if ( ! empty ( $wp_scripts -> registered [ 'jquery' ] -> ver ) && ! empty ( $wp_scripts -> registered [ 'jquery' ] -> src ) && $wp_scripts -> registered [ 'jquery' ] -> ver < '1.7' ) {
2012-08-25 08:47:32 +00:00
wp_deregister_script ( 'jquery' );
wp_register_script ( 'jquery' , '/wp-includes/js/jquery/jquery.js' , array (), '1.7' );
wp_enqueue_script ( 'jquery' );
}
2011-12-09 17:01:56 +00:00
}
2012-08-07 08:38:08 +00:00
/** Load Instances on demand **********************************************/
2011-12-09 21:55:49 +00:00
/**
2012-08-14 14:13:08 +00:00
* Get Checkout Class .
*
* @ access public
* @ return WC_Checkout
2011-12-09 21:55:49 +00:00
*/
2012-12-14 21:19:40 +00:00
public function checkout () {
2013-01-07 17:23:09 +00:00
if ( empty ( $this -> checkout ) )
2012-01-27 16:38:39 +00:00
$this -> checkout = new WC_Checkout ();
2013-01-07 17:23:09 +00:00
2012-01-12 00:54:45 +00:00
return $this -> checkout ;
2011-12-09 21:55:49 +00:00
}
2012-08-07 08:38:08 +00:00
2013-01-07 17:23:09 +00:00
/**
* Get gateways class
*
* @ access public
* @ return WC_Payment_Gateways
*/
public function payment_gateways () {
if ( empty ( $this -> payment_gateways ) )
$this -> payment_gateways = new WC_Payment_Gateways ();
return $this -> payment_gateways ;
}
/**
* Get shipping class
*
* @ access public
* @ return WC_Shipping
*/
public function shipping () {
if ( empty ( $this -> shipping ) )
$this -> shipping = new WC_Shipping ();
return $this -> shipping ;
}
2012-08-14 14:13:08 +00:00
2011-12-09 21:55:49 +00:00
/**
2012-08-14 14:13:08 +00:00
* Get Logging Class .
*
* @ access public
* @ return WC_Logger
2011-12-09 21:55:49 +00:00
*/
2012-12-14 21:19:40 +00:00
public function logger () {
2012-01-27 16:38:39 +00:00
return new WC_Logger ();
2011-12-09 21:55:49 +00:00
}
2012-08-07 08:38:08 +00:00
2012-01-13 00:46:56 +00:00
/**
2012-08-14 14:13:08 +00:00
* Get Validation Class .
*
* @ access public
* @ return WC_Validation
2012-01-13 00:46:56 +00:00
*/
2012-12-14 21:19:40 +00:00
public function validation () {
2012-01-27 16:38:39 +00:00
return new WC_Validation ();
2012-01-13 00:46:56 +00:00
}
2012-07-10 15:52:52 +00:00
2011-12-10 17:28:32 +00:00
/**
2012-08-14 14:13:08 +00:00
* Init the mailer and call the notifications for the current filter .
*
* @ access public
* @ param array $args ( default : array ())
* @ return void
2011-12-10 17:28:32 +00:00
*/
2012-12-14 21:19:40 +00:00
public function send_transactional_email ( $args = array () ) {
2011-12-10 17:28:32 +00:00
$this -> mailer ();
2012-09-17 00:53:17 +00:00
do_action ( current_filter () . '_notification' , $args );
2011-12-10 17:28:32 +00:00
}
2012-08-07 08:38:08 +00:00
2012-07-10 15:52:52 +00:00
/**
2012-08-14 14:13:08 +00:00
* Email Class .
*
* @ access public
* @ return WC_Email
2012-07-10 15:52:52 +00:00
*/
2012-12-14 21:19:40 +00:00
public function mailer () {
2012-09-30 19:15:39 +00:00
if ( empty ( $this -> woocommerce_email ) ) {
2012-09-17 00:53:17 +00:00
$this -> woocommerce_email = new WC_Emails ();
2012-03-20 13:22:35 +00:00
}
2011-12-10 17:28:32 +00:00
return $this -> woocommerce_email ;
}
2011-12-09 17:01:56 +00:00
2011-12-09 21:55:49 +00:00
/** Helper functions ******************************************************/
2012-08-07 08:38:08 +00:00
2011-12-09 21:55:49 +00:00
/**
2012-08-14 14:13:08 +00:00
* Get the plugin url .
*
* @ access public
* @ return string
2011-12-09 21:55:49 +00:00
*/
2012-12-14 21:19:40 +00:00
public function plugin_url () {
2013-05-19 06:24:03 +00:00
if ( isset ( $this -> plugin_url ) ) return $this -> plugin_url ;
2013-04-04 16:39:52 +00:00
return $this -> plugin_url = untrailingslashit ( plugins_url ( '/' , __FILE__ ) );
2011-12-09 21:55:49 +00:00
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2011-12-09 21:55:49 +00:00
/**
2012-08-14 14:13:08 +00:00
* Get the plugin path .
*
* @ access public
* @ return string
2011-12-09 21:55:49 +00:00
*/
2012-12-14 21:19:40 +00:00
public function plugin_path () {
2013-05-19 06:24:03 +00:00
if ( isset ( $this -> plugin_path ) ) return $this -> plugin_path ;
2012-08-07 08:38:08 +00:00
2012-04-11 10:02:35 +00:00
return $this -> plugin_path = untrailingslashit ( plugin_dir_path ( __FILE__ ) );
2012-03-29 00:50:20 +00:00
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2012-03-29 00:50:20 +00:00
/**
2012-08-14 14:13:08 +00:00
* Get Ajax URL .
*
* @ access public
* @ return string
2012-08-07 08:38:08 +00:00
*/
2012-12-14 21:19:40 +00:00
public function ajax_url () {
2012-10-12 11:53:37 +00:00
return admin_url ( 'admin-ajax.php' , 'relative' );
2012-08-07 08:38:08 +00:00
}
2012-08-14 14:13:08 +00:00
2011-12-09 21:55:49 +00:00
/**
2013-02-13 12:38:15 +00:00
* Return the WC API URL for a given request
2012-08-14 14:13:08 +00:00
*
* @ access public
2013-02-13 12:38:15 +00:00
* @ param mixed $request
2013-03-01 18:47:25 +00:00
* @ param mixed $ssl ( default : null )
* @ return string
2013-02-13 12:38:15 +00:00
*/
2013-03-01 18:47:25 +00:00
public function api_request_url ( $request , $ssl = null ) {
2013-03-28 15:49:02 +00:00
if ( is_null ( $ssl ) ) {
$scheme = parse_url ( get_option ( 'home' ), PHP_URL_SCHEME );
} elseif ( $ssl ) {
$scheme = 'https' ;
} else {
$scheme = 'http' ;
}
2013-03-01 18:47:25 +00:00
2013-03-28 15:49:02 +00:00
return esc_url_raw ( trailingslashit ( home_url ( '/wc-api/' . $request , $scheme ) ) );
2013-02-13 12:38:15 +00:00
}
/**
* force_ssl function .
*
* @ access public
* @ param mixed $content
* @ return void
2011-12-09 21:55:49 +00:00
*/
2012-12-14 21:19:40 +00:00
public function force_ssl ( $content ) {
2012-03-20 13:22:35 +00:00
if ( is_ssl () ) {
if ( is_array ( $content ) )
2012-12-15 11:53:32 +00:00
$content = array_map ( array ( $this , 'force_ssl' ) , $content );
2012-08-07 08:38:08 +00:00
else
2012-03-20 13:22:35 +00:00
$content = str_replace ( 'http:' , 'https:' , $content );
}
2011-12-09 21:55:49 +00:00
return $content ;
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2011-12-09 21:55:49 +00:00
/**
2012-08-14 14:13:08 +00:00
* Get an image size .
2011-12-09 21:55:49 +00:00
*
* Variable is filtered by woocommerce_get_image_size_ { image_size }
2012-08-14 14:13:08 +00:00
*
* @ access public
* @ param mixed $image_size
* @ return string
2011-12-09 21:55:49 +00:00
*/
2012-12-14 21:19:40 +00:00
public function get_image_size ( $image_size ) {
2012-11-27 16:22:47 +00:00
2012-11-27 15:37:01 +00:00
// Only return sizes we define in settings
if ( ! in_array ( $image_size , array ( 'shop_thumbnail' , 'shop_catalog' , 'shop_single' ) ) )
return apply_filters ( 'woocommerce_get_image_size_' . $image_size , '' );
2012-12-10 11:33:26 +00:00
$size = get_option ( $image_size . '_image_size' , array () );
2012-11-27 16:22:47 +00:00
2012-11-27 15:37:01 +00:00
$size [ 'width' ] = isset ( $size [ 'width' ] ) ? $size [ 'width' ] : '300' ;
$size [ 'height' ] = isset ( $size [ 'height' ] ) ? $size [ 'height' ] : '300' ;
$size [ 'crop' ] = isset ( $size [ 'crop' ] ) ? $size [ 'crop' ] : 1 ;
return apply_filters ( 'woocommerce_get_image_size_' . $image_size , $size );
2011-12-09 21:55:49 +00:00
}
/** Messages ****************************************************************/
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
/**
* Load Messages .
*
* @ access public
* @ return void
2011-12-09 21:55:49 +00:00
*/
2012-12-14 21:19:40 +00:00
public function load_messages () {
2012-09-07 17:26:13 +00:00
$this -> errors = $this -> session -> errors ;
$this -> messages = $this -> session -> messages ;
unset ( $this -> session -> errors , $this -> session -> messages );
2012-08-07 08:38:08 +00:00
2012-02-22 16:36:23 +00:00
// Load errors from querystring
2012-09-07 17:26:13 +00:00
if ( isset ( $_GET [ 'wc_error' ] ) )
2012-02-22 16:36:23 +00:00
$this -> add_error ( esc_attr ( $_GET [ 'wc_error' ] ) );
2011-12-09 21:55:49 +00:00
}
2011-12-09 17:01:56 +00:00
2012-08-14 14:13:08 +00:00
2011-12-09 21:55:49 +00:00
/**
2012-08-14 14:13:08 +00:00
* Add an error .
*
* @ access public
* @ param string $error
* @ return void
2011-12-09 21:55:49 +00:00
*/
2012-12-14 21:19:40 +00:00
public function add_error ( $error ) {
2012-08-14 14:13:08 +00:00
$this -> errors [] = apply_filters ( 'woocommerce_add_error' , $error );
}
2012-08-07 08:38:08 +00:00
2011-12-09 21:55:49 +00:00
/**
2012-08-14 14:13:08 +00:00
* Add a message .
*
* @ access public
* @ param string $message
* @ return void
2011-12-09 21:55:49 +00:00
*/
2012-12-14 21:19:40 +00:00
public function add_message ( $message ) {
2012-08-14 14:13:08 +00:00
$this -> messages [] = apply_filters ( 'woocommerce_add_message' , $message );
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
/**
* Clear messages and errors from the session data .
*
* @ access public
* @ return void
*/
2012-12-14 21:19:40 +00:00
public function clear_messages () {
2011-12-09 21:55:49 +00:00
$this -> errors = $this -> messages = array ();
2012-09-07 17:26:13 +00:00
unset ( $this -> session -> errors , $this -> session -> messages );
2011-12-09 21:55:49 +00:00
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2011-12-09 21:55:49 +00:00
/**
2012-08-14 14:13:08 +00:00
* error_count function .
*
* @ access public
* @ return int
2011-12-09 21:55:49 +00:00
*/
2012-12-14 21:19:40 +00:00
public function error_count () {
2012-08-14 14:13:08 +00:00
return sizeof ( $this -> errors );
}
2012-08-07 08:38:08 +00:00
2011-12-09 21:55:49 +00:00
/**
2012-08-14 14:13:08 +00:00
* Get message count .
*
* @ access public
* @ return int
2011-12-09 21:55:49 +00:00
*/
2012-12-14 21:19:40 +00:00
public function message_count () {
2012-08-14 14:13:08 +00:00
return sizeof ( $this -> messages );
}
2012-08-07 08:38:08 +00:00
2012-02-08 15:20:32 +00:00
/**
2012-08-14 14:13:08 +00:00
* Get errors .
*
* @ access public
* @ return array
2012-02-08 15:20:32 +00:00
*/
2012-12-14 21:19:40 +00:00
public function get_errors () {
2012-08-14 14:13:08 +00:00
return ( array ) $this -> errors ;
}
2012-08-07 08:38:08 +00:00
2012-02-08 15:20:32 +00:00
/**
2012-08-14 14:13:08 +00:00
* Get messages .
*
* @ access public
* @ return array
2012-02-08 15:20:32 +00:00
*/
2012-12-14 21:19:40 +00:00
public function get_messages () {
2012-08-14 14:13:08 +00:00
return ( array ) $this -> messages ;
}
2012-08-07 08:38:08 +00:00
2011-12-09 21:55:49 +00:00
/**
2012-08-14 14:13:08 +00:00
* Output the errors and messages .
*
* @ access public
* @ return void
2011-12-09 21:55:49 +00:00
*/
2012-12-14 21:19:40 +00:00
public function show_messages () {
2012-08-14 14:13:08 +00:00
woocommerce_show_messages ();
}
2012-08-07 08:38:08 +00:00
2012-01-27 18:31:30 +00:00
/**
2012-08-14 14:13:08 +00:00
* Set session data for messages .
*
* @ access public
* @ return void
2012-01-27 18:31:30 +00:00
*/
2012-12-14 21:19:40 +00:00
public function set_messages () {
2012-09-07 17:26:13 +00:00
$this -> session -> errors = $this -> errors ;
$this -> session -> messages = $this -> messages ;
2012-01-27 18:31:30 +00:00
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2011-12-09 21:55:49 +00:00
/**
2012-08-14 14:13:08 +00:00
* Redirection hook which stores messages into session data .
*
* @ access public
* @ param mixed $location
* @ param mixed $status
* @ return string
2011-12-09 21:55:49 +00:00
*/
2012-12-14 21:19:40 +00:00
public function redirect ( $location , $status ) {
2012-01-27 18:31:30 +00:00
$this -> set_messages ();
2012-08-07 08:38:08 +00:00
2012-03-20 13:22:35 +00:00
return apply_filters ( 'woocommerce_redirect' , $location );
2011-12-09 21:55:49 +00:00
}
2012-08-07 08:38:08 +00:00
2011-12-09 21:55:49 +00:00
/** Attribute Helpers ****************************************************************/
2012-08-14 14:13:08 +00:00
/**
* Get attribute taxonomies .
*
* @ access public
* @ return object
2011-12-09 21:55:49 +00:00
*/
2012-12-14 21:19:40 +00:00
public function get_attribute_taxonomies () {
2012-12-19 20:42:25 +00:00
$transient_name = 'wc_attribute_taxonomies' ;
if ( false === ( $attribute_taxonomies = get_transient ( $transient_name ) ) ) {
global $wpdb ;
$attribute_taxonomies = $wpdb -> get_results ( " SELECT * FROM " . $wpdb -> prefix . " woocommerce_attribute_taxonomies " );
set_transient ( $transient_name , $attribute_taxonomies );
}
return apply_filters ( 'woocommerce_attribute_taxonomies' , $attribute_taxonomies );
2011-12-09 21:55:49 +00:00
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
/**
* Get a product attributes name .
*
* @ access public
* @ param mixed $name
* @ return string
2011-12-09 21:55:49 +00:00
*/
2012-12-14 21:19:40 +00:00
public function attribute_taxonomy_name ( $name ) {
2012-12-05 15:01:29 +00:00
return 'pa_' . woocommerce_sanitize_taxonomy_name ( $name );
2011-12-09 21:55:49 +00:00
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2011-12-09 21:55:49 +00:00
/**
2012-08-14 14:13:08 +00:00
* Get a product attributes label .
*
* @ access public
* @ param mixed $name
* @ return string
2011-12-09 21:55:49 +00:00
*/
2012-12-14 21:19:40 +00:00
public function attribute_label ( $name ) {
2011-12-09 21:55:49 +00:00
global $wpdb ;
2012-08-07 08:38:08 +00:00
2012-03-20 13:22:35 +00:00
if ( strstr ( $name , 'pa_' ) ) {
2012-12-05 15:01:29 +00:00
$name = woocommerce_sanitize_taxonomy_name ( str_replace ( 'pa_' , '' , $name ) );
2011-12-09 21:55:49 +00:00
2013-04-16 13:41:23 +00:00
$label = $wpdb -> get_var ( $wpdb -> prepare ( " SELECT attribute_label FROM { $wpdb -> prefix } woocommerce_attribute_taxonomies WHERE attribute_name = %s; " , $name ) );
2012-08-07 08:38:08 +00:00
2012-12-05 15:01:29 +00:00
if ( ! $label )
$label = ucfirst ( $name );
2012-03-20 13:22:35 +00:00
} else {
2012-03-21 14:26:53 +00:00
$label = $name ;
2012-03-20 13:22:35 +00:00
}
2012-03-21 14:26:53 +00:00
2012-03-23 21:06:49 +00:00
return apply_filters ( 'woocommerce_attribute_label' , $label , $name );
2011-12-09 21:55:49 +00:00
}
2012-11-13 23:22:53 +00:00
2012-10-09 14:57:02 +00:00
/**
* Get a product attributes orderby setting .
*
* @ access public
* @ param mixed $name
* @ return string
*/
2012-12-14 21:19:40 +00:00
public function attribute_orderby ( $name ) {
2012-10-09 14:57:02 +00:00
global $wpdb ;
$name = str_replace ( 'pa_' , '' , sanitize_title ( $name ) );
$orderby = $wpdb -> get_var ( $wpdb -> prepare ( " SELECT attribute_orderby FROM " . $wpdb -> prefix . " woocommerce_attribute_taxonomies WHERE attribute_name = %s; " , $name ) );
return apply_filters ( 'woocommerce_attribute_orderby' , $orderby , $name );
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2012-03-05 14:43:55 +00:00
/**
2012-08-14 14:13:08 +00:00
* Get an array of product attribute taxonomies .
*
* @ access public
* @ return array
2012-03-05 14:43:55 +00:00
*/
2012-12-14 21:19:40 +00:00
public function get_attribute_taxonomy_names () {
2012-03-05 14:43:55 +00:00
$taxonomy_names = array ();
2012-08-07 08:38:08 +00:00
$attribute_taxonomies = $this -> get_attribute_taxonomies ();
2012-03-05 14:43:55 +00:00
if ( $attribute_taxonomies ) {
2012-03-20 13:22:35 +00:00
foreach ( $attribute_taxonomies as $tax ) {
2012-12-05 15:01:29 +00:00
$taxonomy_names [] = $this -> attribute_taxonomy_name ( $tax -> attribute_name );
2012-03-05 14:43:55 +00:00
}
}
return $taxonomy_names ;
}
2012-08-07 08:38:08 +00:00
2011-12-09 21:55:49 +00:00
/** Coupon Helpers ********************************************************/
2012-08-07 08:38:08 +00:00
2011-12-09 21:55:49 +00:00
/**
2012-08-14 14:13:08 +00:00
* Get coupon types .
*
* @ access public
* @ return array
2011-12-09 21:55:49 +00:00
*/
2012-12-14 21:19:40 +00:00
public function get_coupon_discount_types () {
2012-12-30 15:51:37 +00:00
if ( ! isset ( $this -> coupon_discount_types ) ) {
2012-03-20 13:22:35 +00:00
$this -> coupon_discount_types = apply_filters ( 'woocommerce_coupon_discount_types' , array (
2012-10-16 09:45:33 +00:00
'fixed_cart' => __ ( 'Cart Discount' , 'woocommerce' ),
'percent' => __ ( 'Cart % Discount' , 'woocommerce' ),
'fixed_product' => __ ( 'Product Discount' , 'woocommerce' ),
'percent_product' => __ ( 'Product % Discount' , 'woocommerce' )
2012-03-20 13:22:35 +00:00
) );
}
2011-12-09 21:55:49 +00:00
return $this -> coupon_discount_types ;
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
2011-12-09 21:55:49 +00:00
/**
2012-08-14 14:13:08 +00:00
* Get a coupon type ' s name .
*
* @ access public
* @ param string $type ( default : '' )
* @ return string
2011-12-09 21:55:49 +00:00
*/
2012-12-14 21:19:40 +00:00
public function get_coupon_discount_type ( $type = '' ) {
2011-12-09 21:55:49 +00:00
$types = ( array ) $this -> get_coupon_discount_types ();
2012-03-20 13:22:35 +00:00
if ( isset ( $types [ $type ] ) ) return $types [ $type ];
2011-12-09 21:55:49 +00:00
}
2012-08-07 08:38:08 +00:00
2011-12-09 19:55:09 +00:00
/** Nonces ****************************************************************/
2012-08-07 08:38:08 +00:00
2011-12-09 19:55:09 +00:00
/**
2012-08-14 14:13:08 +00:00
* Return a nonce field .
*
* @ access public
* @ param mixed $action
* @ param bool $referer ( default : true )
* @ param bool $echo ( default : true )
* @ return void
2011-12-09 19:55:09 +00:00
*/
2012-12-14 21:19:40 +00:00
public function nonce_field ( $action , $referer = true , $echo = true ) {
2012-08-14 14:13:08 +00:00
return wp_nonce_field ( 'woocommerce-' . $action , '_n' , $referer , $echo );
}
2012-08-07 08:38:08 +00:00
2011-12-09 19:55:09 +00:00
/**
2012-08-14 14:13:08 +00:00
* Return a url with a nonce appended .
*
* @ access public
* @ param mixed $action
* @ param string $url ( default : '' )
* @ return string
2011-12-09 19:55:09 +00:00
*/
2012-12-14 21:19:40 +00:00
public function nonce_url ( $action , $url = '' ) {
2012-08-14 14:13:08 +00:00
return add_query_arg ( '_n' , wp_create_nonce ( 'woocommerce-' . $action ), $url );
}
2012-08-07 08:38:08 +00:00
2011-12-09 19:55:09 +00:00
/**
2012-08-14 14:13:08 +00:00
* Check a nonce and sets woocommerce error in case it is invalid .
2012-08-07 08:38:08 +00:00
*
2012-08-14 14:13:08 +00:00
* To fail silently , set the error_message to an empty string
2012-08-07 08:38:08 +00:00
*
2012-08-14 14:13:08 +00:00
* @ access public
* @ param string $name the nonce name
* @ param string $action then nonce action
* @ param string $method the http request method _POST , _GET or _REQUEST
* @ param string $error_message custom error message , or false for default message , or an empty string to fail silently
* @ return bool
2011-12-09 19:55:09 +00:00
*/
2012-12-14 21:19:40 +00:00
public function verify_nonce ( $action , $method = '_POST' , $error_message = false ) {
2012-08-07 08:38:08 +00:00
2011-12-09 19:55:09 +00:00
$name = '_n' ;
$action = 'woocommerce-' . $action ;
2012-08-07 08:38:08 +00:00
2012-10-16 09:45:33 +00:00
if ( $error_message === false ) $error_message = __ ( 'Action failed. Please refresh the page and retry.' , 'woocommerce' );
2012-08-07 08:38:08 +00:00
2012-03-20 13:22:35 +00:00
if ( ! in_array ( $method , array ( '_GET' , '_POST' , '_REQUEST' ) ) ) $method = '_POST' ;
2012-08-07 08:38:08 +00:00
2012-03-20 13:22:35 +00:00
if ( isset ( $_REQUEST [ $name ] ) && wp_verify_nonce ( $_REQUEST [ $name ], $action ) ) return true ;
2012-08-07 08:38:08 +00:00
2012-03-20 13:22:35 +00:00
if ( $error_message ) $this -> add_error ( $error_message );
2012-08-07 08:38:08 +00:00
2011-12-09 19:55:09 +00:00
return false ;
}
2012-08-07 08:38:08 +00:00
2012-04-11 20:07:46 +00:00
/** Shortcode Helpers *********************************************************/
2012-08-07 08:38:08 +00:00
2011-12-09 19:55:09 +00:00
/**
2012-04-11 20:07:46 +00:00
* Shortcode Wrapper
2012-08-14 14:13:08 +00:00
*
* @ access public
* @ param mixed $function
* @ param array $atts ( default : array ())
* @ return string
2011-12-09 19:55:09 +00:00
*/
2012-12-14 21:19:40 +00:00
public function shortcode_wrapper (
2012-11-13 23:22:53 +00:00
$function ,
2012-11-13 23:39:52 +00:00
$atts = array (),
2012-11-13 23:22:53 +00:00
$wrapper = array (
2012-11-15 17:46:24 +00:00
'class' => 'woocommerce' ,
2012-11-13 23:22:53 +00:00
'before' => null ,
'after' => null
)
){
2011-12-09 19:55:09 +00:00
ob_start ();
2012-11-13 23:22:53 +00:00
2012-11-15 17:46:24 +00:00
$before = empty ( $wrapper [ 'before' ] ) ? '<div class="' . $wrapper [ 'class' ] . '">' : $wrapper [ 'before' ];
$after = empty ( $wrapper [ 'after' ] ) ? '</div>' : $wrapper [ 'after' ];
2012-11-27 16:22:47 +00:00
2012-11-15 17:46:24 +00:00
echo $before ;
call_user_func ( $function , $atts );
echo $after ;
2012-11-13 23:22:53 +00:00
2012-11-15 17:46:24 +00:00
return ob_get_clean ();
2011-12-09 19:55:09 +00:00
}
2012-04-11 20:07:46 +00:00
2011-12-09 19:55:09 +00:00
/** Transients ************************************************************/
2012-08-07 08:38:08 +00:00
2011-12-09 19:55:09 +00:00
/**
2012-08-14 14:13:08 +00:00
* Clear all transients cache for product data .
*
* @ access public
* @ param int $post_id ( default : 0 )
* @ return void
2011-12-09 19:55:09 +00:00
*/
2012-12-14 21:19:40 +00:00
public function clear_product_transients ( $post_id = 0 ) {
2011-12-09 19:55:09 +00:00
global $wpdb ;
2012-11-13 23:22:53 +00:00
2012-10-11 09:22:03 +00:00
$post_id = absint ( $post_id );
2012-11-13 23:22:53 +00:00
2012-10-11 09:22:03 +00:00
$wpdb -> show_errors ();
2012-11-13 23:22:53 +00:00
2012-10-11 09:22:03 +00:00
// Clear core transients
2012-11-13 23:22:53 +00:00
$transients_to_clear = array (
'wc_products_onsale' ,
'wc_hidden_product_ids' ,
2012-12-19 20:42:25 +00:00
'wc_hidden_product_ids_search' ,
2012-12-30 15:02:24 +00:00
'wc_attribute_taxonomies' ,
2013-01-02 12:12:40 +00:00
'wc_term_counts'
2012-10-11 09:22:03 +00:00
);
2012-11-13 23:22:53 +00:00
2012-10-11 09:22:03 +00:00
foreach ( $transients_to_clear as $transient ) {
delete_transient ( 'wc_products_onsale' );
2012-12-30 15:02:24 +00:00
$wpdb -> query ( $wpdb -> prepare ( " DELETE FROM ` $wpdb->options ` WHERE `option_name` = %s OR `option_name` = %s " , '_transient_' . $transient , '_transient_timeout_' . $transient ) );
2012-10-11 09:22:03 +00:00
}
2012-11-13 23:22:53 +00:00
2012-10-11 09:22:03 +00:00
// Clear transients for which we don't have the name
2012-12-30 15:02:24 +00:00
$wpdb -> query ( " DELETE FROM ` $wpdb->options ` WHERE `option_name` LIKE ('_transient_wc_uf_pid_%') OR `option_name` LIKE ('_transient_timeout_wc_uf_pid_%') " );
$wpdb -> query ( " DELETE FROM ` $wpdb->options ` WHERE `option_name` LIKE ('_transient_wc_ln_count_%') OR `option_name` LIKE ('_transient_timeout_wc_ln_count_%') " );
$wpdb -> query ( " DELETE FROM ` $wpdb->options ` WHERE `option_name` LIKE ('_transient_wc_ship_%') OR `option_name` LIKE ('_transient_timeout_wc_ship_%') " );
2012-11-13 23:22:53 +00:00
2012-10-11 09:22:03 +00:00
// Clear product specific transients
2012-11-13 23:22:53 +00:00
$post_transients_to_clear = array (
'wc_product_children_ids_' ,
'wc_product_total_stock_' ,
2012-12-30 15:02:24 +00:00
'wc_average_rating_' ,
2013-01-12 10:53:24 +00:00
'wc_rating_count_' ,
2012-12-30 15:02:24 +00:00
'woocommerce_product_type_' , // No longer used
'wc_product_type_' , // No longer used
2012-10-11 09:22:03 +00:00
);
2012-11-13 23:22:53 +00:00
2012-10-11 09:22:03 +00:00
if ( $post_id > 0 ) {
2012-11-13 23:22:53 +00:00
2012-10-11 09:22:03 +00:00
foreach ( $post_transients_to_clear as $transient ) {
delete_transient ( $transient . $post_id );
2012-12-30 15:02:24 +00:00
$wpdb -> query ( $wpdb -> prepare ( " DELETE FROM ` $wpdb->options ` WHERE `option_name` = %s OR `option_name` = %s " , '_transient_' . $transient . $post_id , '_transient_timeout_' . $transient . $post_id ) );
2012-10-11 09:22:03 +00:00
}
2012-11-13 23:22:53 +00:00
2012-10-11 09:22:03 +00:00
clean_post_cache ( $post_id );
2012-11-13 23:22:53 +00:00
2012-03-20 13:22:35 +00:00
} else {
2012-11-13 23:22:53 +00:00
2012-10-11 09:22:03 +00:00
foreach ( $post_transients_to_clear as $transient ) {
2012-12-30 15:02:24 +00:00
$wpdb -> query ( $wpdb -> prepare ( " DELETE FROM ` $wpdb->options ` WHERE `option_name` LIKE %s OR `option_name` LIKE %s " , '_transient_' . $transient . '%' , '_transient_timeout_' . $transient . '%' ) );
2012-10-11 09:22:03 +00:00
}
2012-11-13 23:22:53 +00:00
2012-03-20 13:22:35 +00:00
}
2011-12-09 19:55:09 +00:00
}
2012-08-07 08:38:08 +00:00
2011-12-09 19:55:09 +00:00
/** Body Classes **********************************************************/
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
/**
* Add a class to the webpage body .
*
* @ access public
* @ param string $class
* @ return void
*/
2012-12-14 21:19:40 +00:00
public function add_body_class ( $class ) {
2012-04-19 07:14:48 +00:00
$this -> _body_classes [] = sanitize_html_class ( strtolower ( $class ) );
2011-12-09 19:55:09 +00:00
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
/**
* Output classes on the body tag .
*
* @ access public
* @ param mixed $classes
* @ return array
*/
2012-12-14 21:19:40 +00:00
public function output_body_class ( $classes ) {
2012-03-20 13:22:35 +00:00
if ( sizeof ( $this -> _body_classes ) > 0 ) $classes = array_merge ( $classes , $this -> _body_classes );
2012-08-07 08:38:08 +00:00
2012-03-20 13:22:35 +00:00
if ( is_singular ( 'product' ) ) {
$key = array_search ( 'singular' , $classes );
if ( $key !== false ) unset ( $classes [ $key ] );
}
2012-08-07 08:38:08 +00:00
2011-12-09 19:55:09 +00:00
return $classes ;
}
2013-01-09 14:15:25 +00:00
/** Post Classes **********************************************************/
/**
* Adds extra post classes for products
*
2013-02-08 15:36:28 +00:00
* @ since 2.0
2013-01-09 14:15:25 +00:00
* @ access public
* @ param array $classes
* @ param string | array $class
* @ param int $post_id
* @ return array
*/
public function post_class ( $classes , $class , $post_id ) {
$product = get_product ( $post_id );
if ( $product ) {
if ( $product -> is_on_sale () ) {
$classes [] = 'sale' ;
}
if ( $product -> is_featured () ) {
$classes [] = 'featured' ;
}
2013-01-27 08:31:38 +00:00
$classes [] = $product -> stock_status ;
2013-01-09 14:15:25 +00:00
}
return $classes ;
}
2012-08-07 08:38:08 +00:00
2011-12-09 19:55:09 +00:00
/** Inline JavaScript Helper **********************************************/
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
/**
* Add some JavaScript inline to be output in the footer .
*
* @ access public
* @ param string $code
* @ return void
*/
2012-12-14 21:19:40 +00:00
public function add_inline_js ( $code ) {
2012-10-17 15:42:57 +00:00
$this -> _inline_js .= " \n " . $code . " \n " ;
2011-12-09 19:55:09 +00:00
}
2012-08-07 08:38:08 +00:00
2012-08-14 14:13:08 +00:00
/**
* Output any queued inline JS .
*
* @ access public
* @ return void
*/
2012-12-14 21:19:40 +00:00
public function output_inline_js () {
2012-08-14 14:13:08 +00:00
if ( $this -> _inline_js ) {
2012-08-07 08:38:08 +00:00
2011-12-09 19:55:09 +00:00
echo " <!-- WooCommerce JavaScript--> \n <script type= \" text/javascript \" > \n jQuery(document).ready(function( $ ) { " ;
2012-11-13 23:22:53 +00:00
2012-10-17 15:42:57 +00:00
// Sanitize
$this -> _inline_js = wp_check_invalid_utf8 ( $this -> _inline_js );
2012-10-23 17:21:11 +00:00
$this -> _inline_js = preg_replace ( '/&#(x)?0*(?(1)27|39);?/i' , " ' " , $this -> _inline_js );
2012-10-17 15:42:57 +00:00
$this -> _inline_js = str_replace ( " \r " , '' , $this -> _inline_js );
2012-11-13 23:22:53 +00:00
2012-10-17 15:42:57 +00:00
// Output
2011-12-09 19:55:09 +00:00
echo $this -> _inline_js ;
2012-08-07 08:38:08 +00:00
2011-12-09 19:55:09 +00:00
echo " }); \n </script> \n " ;
2012-08-07 08:38:08 +00:00
2011-12-15 16:36:11 +00:00
$this -> _inline_js = '' ;
2012-03-20 13:22:35 +00:00
}
2011-12-09 19:55:09 +00:00
}
2013-04-09 09:38:40 +00:00
/** Deprecated functions *********************************************************/
/**
* Sets a constant preventing some caching plugins from caching a page . Used on dynamic pages .
*
* @ deprecated 2.0 . 0 No longer needed - Cache Helper class sets up nocache automatically .
* @ access public
* @ return void
*/
public function nocache () {
_deprecated_function ( 'Woocommerce::nocache' , '2.0.6' );
}
/**
* mfunc_wrapper function .
*
* Wraps a function in mfunc to keep it dynamic .
*
* If running WP Super Cache this checks for late_init ( because functions calling this require WP to be loaded )
*
* @ deprecated 2.0 . 0 No longer needed - cart fragments are cache friendly .
* @ access public
* @ param mixed $function
* @ return void
*/
public function mfunc_wrapper ( $mfunction , $function , $args ) {
global $wp_super_cache_late_init ;
_deprecated_function ( 'Woocommerce::mfunc_wrapper' , '2.0.0' );
if ( is_null ( $wp_super_cache_late_init ) || $wp_super_cache_late_init == 1 ) {
echo '<!--mfunc ' . $mfunction . ' -->' ;
$function ( $args );
echo '<!--/mfunc-->' ;
} else {
$function ( $args );
}
}
2011-12-09 17:01:56 +00:00
}
2011-11-06 15:45:22 +00:00
2011-12-09 17:01:56 +00:00
/**
* Init woocommerce class
*/
2012-01-21 09:01:41 +00:00
$GLOBALS [ 'woocommerce' ] = new Woocommerce ();
2011-11-06 15:45:22 +00:00
2013-03-23 21:33:19 +00:00
} // class_exists check