PageRenderTime 74ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/jigoshop.php

https://github.com/scottpoulin/jigoshop
PHP | 1236 lines | 746 code | 245 blank | 245 comment | 129 complexity | 8145f424368d2368abebf7c1c98345c9 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /**
  3. * ./////////////////////////////.
  4. * //////////////////////////////////
  5. * /////////// ///////////////////
  6. * //////// /////////////////////
  7. * ////// ////////////////////////
  8. * ///// ///////// ////////////
  9. * ////// ///////// /////////
  10. * ///////// ///////// ///////
  11. * /////////// ////////// /////
  12. * //////////////////////// //////
  13. * ///////////////////// /////////
  14. * /////////////////// ///////////
  15. * //////////////////////////////////
  16. * `//////////////////////////////`
  17. *
  18. *
  19. * Plugin Name: Jigoshop
  20. * Plugin URI: http://jigoshop.com/
  21. * Description: Jigoshop, a WordPress eCommerce plugin that works.
  22. * Author: Jigoshop
  23. * Author URI: http://jigoshop.com
  24. *
  25. * Version: 1.6.2
  26. * Requires at least: 3.4
  27. * Tested up to: 3.5.1
  28. *
  29. * Text Domain: jigoshop
  30. * Domain Path: /languages/
  31. *
  32. * DISCLAIMER
  33. *
  34. * Do not edit or add directly to this file if you wish to upgrade Jigoshop to newer
  35. * versions in the future. If you wish to customise Jigoshop core for your needs,
  36. * please use our GitHub repository to publish essential changes for consideration.
  37. *
  38. * @package Jigoshop
  39. * @category Core
  40. * @author Jigoshop
  41. * @copyright Copyright Š 2011-2013 Jigoshop.
  42. * @license http://jigoshop.com/license/commercial-edition
  43. */
  44. if ( !defined( "JIGOSHOP_VERSION" )) define( "JIGOSHOP_VERSION", 1303180) ;
  45. if ( !defined( "JIGOSHOP_OPTIONS" )) define( "JIGOSHOP_OPTIONS", 'jigoshop_options' );
  46. if ( !defined( 'JIGOSHOP_TEMPLATE_URL' ) ) define( 'JIGOSHOP_TEMPLATE_URL', 'jigoshop/' );
  47. if ( !defined( "PHP_EOL" )) define( "PHP_EOL", "\r\n" );
  48. /**
  49. * Include core files and classes
  50. **/
  51. include_once( 'classes/abstract/jigoshop_base.class.php' );
  52. include_once( 'classes/abstract/jigoshop_singleton.class.php' );
  53. include_once( 'classes/jigoshop_options.class.php' );
  54. include_once( 'classes/jigoshop_session.class.php' );
  55. include_once( 'classes/jigoshop_sanitize.class.php' );
  56. include_once( 'classes/jigoshop_validation.class.php' );
  57. include_once( 'classes/jigoshop_forms.class.php' );
  58. include_once( 'jigoshop_taxonomy.php' );
  59. include_once( 'classes/jigoshop_countries.class.php' );
  60. include_once( 'classes/jigoshop_customer.class.php' );
  61. include_once( 'classes/jigoshop_product.class.php' );
  62. include_once( 'classes/jigoshop_product_variation.class.php' );
  63. include_once( 'classes/jigoshop_order.class.php' );
  64. include_once( 'classes/jigoshop_orders.class.php' );
  65. include_once( 'classes/jigoshop_tax.class.php' );
  66. include_once( 'classes/jigoshop_shipping.class.php' );
  67. include_once( 'classes/jigoshop_coupons.class.php' );
  68. include_once( 'gateways/gateways.class.php' );
  69. include_once( 'gateways/gateway.class.php' );
  70. include_once( 'gateways/bank_transfer.php' );
  71. include_once( 'gateways/cheque.php' );
  72. include_once( 'gateways/cod.php' );
  73. include_once( 'gateways/paypal.php' );
  74. include_once( 'gateways/skrill.php' );
  75. include_once( 'shipping/shipping_method.class.php' );
  76. include_once( 'shipping/jigoshop_calculable_shipping.php' );
  77. include_once( 'shipping/flat_rate.php' );
  78. include_once( 'shipping/free_shipping.php' );
  79. include_once( 'shipping/local_pickup.php' );
  80. include_once( 'classes/jigoshop_query.class.php' );
  81. include_once( 'classes/jigoshop.class.php' );
  82. include_once( 'classes/jigoshop_cart.class.php' );
  83. include_once( 'classes/jigoshop_checkout.class.php' );
  84. include_once( 'classes/jigoshop_cron.class.php' );
  85. include_once( 'shortcodes/init.php' );
  86. include_once( 'widgets/init.php' );
  87. include_once( 'jigoshop_templates.php' );
  88. include_once( 'jigoshop_template_actions.php' );
  89. include_once( 'jigoshop_emails.php' );
  90. include_once( 'jigoshop_actions.php' );
  91. /**
  92. * IIS compat fix/fallback
  93. **/
  94. if ( ! isset( $_SERVER['REQUEST_URI'] )) {
  95. $_SERVER['REQUEST_URI'] = substr( $_SERVER['PHP_SELF'], 1 );
  96. if ( isset( $_SERVER['QUERY_STRING'] )) { $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; }
  97. }
  98. // Load administration & check if we need to install
  99. if ( is_admin() ) {
  100. include_once( 'admin/jigoshop-admin.php' );
  101. register_activation_hook( __FILE__, 'install_jigoshop' );
  102. }
  103. /**
  104. * Jigoshop Inits
  105. **/
  106. add_action( 'init', 'jigoshop_init', 0 );
  107. function jigoshop_init() {
  108. /* ensure nothing is output to the browser prior to this (other than headers) */
  109. ob_start();
  110. // http://www.geertdedeckere.be/article/loading-wordpress-language-files-the-right-way
  111. // this means that all Jigoshop extensions, shipping modules and gateways must load their text domains on the 'init' action hook
  112. //
  113. // Override default translations with custom .mo's found in wp-content/languages/jigoshop first.
  114. load_textdomain( 'jigoshop', WP_LANG_DIR.'/jigoshop/jigoshop-'.get_locale().'.mo' );
  115. load_plugin_textdomain( 'jigoshop', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
  116. // instantiate options -after- loading text domains
  117. $jigoshop_options = Jigoshop_Base::get_options();
  118. jigoshop_post_type(); // register taxonomies
  119. new jigoshop_cron(); // -after- text domains and Options instantiation allows settings translations
  120. jigoshop_set_image_sizes(); // called -after- our Options are loaded
  121. // add Singletons here so that the taxonomies are loaded before calling them.
  122. jigoshop_session::instance(); // Start sessions if they aren't already
  123. jigoshop::instance(); // Utility functions, uses sessions
  124. jigoshop_customer::instance(); // Customer class, sorts session data such as location
  125. // Jigoshop will instantiate gateways and shipping methods on this same 'init' action hook
  126. // with a very low priority to ensure text domains are loaded first prior to installing any external options
  127. jigoshop_shipping::instance(); // Shipping class. loads shipping methods
  128. jigoshop_payment_gateways::instance(); // Payment gateways class. loads payment methods
  129. jigoshop_cart::instance(); // Cart class, uses sessions
  130. if ( ! is_admin()) {
  131. /* Catalog Filters */
  132. add_filter( 'loop-shop-query', create_function( '', 'return array("orderby" => "' . $jigoshop_options->get_option('jigoshop_catalog_sort_orderby') . '","order" => "' . $jigoshop_options->get_option('jigoshop_catalog_sort_direction') . '");' ) );
  133. add_filter( 'loop_shop_columns' , create_function( '', 'return ' . $jigoshop_options->get_option('jigoshop_catalog_columns') . ';' ) );
  134. add_filter( 'loop_shop_per_page', create_function( '', 'return ' . $jigoshop_options->get_option('jigoshop_catalog_per_page') . ';' ) );
  135. jigoshop_catalog_query::instance(); // front end queries class
  136. }
  137. jigoshop_roles_init();
  138. }
  139. /**
  140. * Include template functions here with a low priority so they are pluggable by themes
  141. **/
  142. add_action( 'init', 'jigoshop_load_template_functions', 999 );
  143. function jigoshop_load_template_functions() {
  144. include_once( 'jigoshop_template_functions.php' );
  145. }
  146. function jigoshop_get_core_capabilities() {
  147. $capabilities = array();
  148. $capabilities['core'] = array(
  149. 'manage_jigoshop',
  150. 'view_jigoshop_reports',
  151. 'manage_jigoshop_orders',
  152. 'manage_jigoshop_coupons',
  153. 'manage_jigoshop_products'
  154. );
  155. $capability_types = array( 'product', 'shop_order', 'shop_coupon' );
  156. foreach( $capability_types as $capability_type ) {
  157. $capabilities[ $capability_type ] = array(
  158. // Post type
  159. "edit_{$capability_type}",
  160. "read_{$capability_type}",
  161. "delete_{$capability_type}",
  162. "edit_{$capability_type}s",
  163. "edit_others_{$capability_type}s",
  164. "publish_{$capability_type}s",
  165. "read_private_{$capability_type}s",
  166. "delete_{$capability_type}s",
  167. "delete_private_{$capability_type}s",
  168. "delete_published_{$capability_type}s",
  169. "delete_others_{$capability_type}s",
  170. "edit_private_{$capability_type}s",
  171. "edit_published_{$capability_type}s",
  172. // Terms
  173. "manage_{$capability_type}_terms",
  174. "edit_{$capability_type}_terms",
  175. "delete_{$capability_type}_terms",
  176. "assign_{$capability_type}_terms"
  177. );
  178. }
  179. return $capabilities;
  180. }
  181. function jigoshop_roles_init() {
  182. global $wp_roles;
  183. if ( class_exists('WP_Roles') )
  184. if ( ! isset( $wp_roles ) )
  185. $wp_roles = new WP_Roles();
  186. if ( is_object( $wp_roles ) ) {
  187. // Customer role
  188. add_role( 'customer', __('Customer', 'jigoshop'), array(
  189. 'read' => true,
  190. 'edit_posts' => false,
  191. 'delete_posts' => false
  192. ) );
  193. // Shop manager role
  194. add_role( 'shop_manager', __('Shop Manager', 'jigoshop'), array(
  195. 'read' => true,
  196. 'read_private_pages' => true,
  197. 'read_private_posts' => true,
  198. 'edit_users' => true,
  199. 'edit_posts' => true,
  200. 'edit_pages' => true,
  201. 'edit_published_posts' => true,
  202. 'edit_published_pages' => true,
  203. 'edit_private_pages' => true,
  204. 'edit_private_posts' => true,
  205. 'edit_others_posts' => true,
  206. 'edit_others_pages' => true,
  207. 'publish_posts' => true,
  208. 'publish_pages' => true,
  209. 'delete_posts' => true,
  210. 'delete_pages' => true,
  211. 'delete_private_pages' => true,
  212. 'delete_private_posts' => true,
  213. 'delete_published_pages' => true,
  214. 'delete_published_posts' => true,
  215. 'delete_others_posts' => true,
  216. 'delete_others_pages' => true,
  217. 'manage_categories' => true,
  218. 'manage_links' => true,
  219. 'moderate_comments' => true,
  220. 'unfiltered_html' => true,
  221. 'upload_files' => true,
  222. 'export' => true,
  223. 'import' => true,
  224. ) );
  225. $capabilities = jigoshop_get_core_capabilities();
  226. foreach( $capabilities as $cap_group ) {
  227. foreach( $cap_group as $cap ) {
  228. $wp_roles->add_cap( 'administrator', $cap );
  229. $wp_roles->add_cap( 'shop_manager', $cap );
  230. }
  231. }
  232. }
  233. }
  234. /**
  235. * Jigoshop Frontend Styles and Scripts
  236. **/
  237. add_action( 'template_redirect', 'jigoshop_frontend_scripts' );
  238. function jigoshop_frontend_scripts() {
  239. if ( ! is_jigoshop() && is_admin() ) return false;
  240. $jigoshop_options = Jigoshop_Base::get_options();
  241. /**
  242. * Frontend Styles
  243. *
  244. * For Jigoshop 1.3 or better there are 2 CSS related options
  245. * The ususal 'jigoshop_disable_css' must be off to use -any- Jigoshop CSS
  246. * otherwise the theme is expected to provide -all- CSS located wherever it likes, loaded by the theme
  247. * A user can also copy both frontend.less and frontend.css to a 'jigoshop' folder in the theme folder and
  248. * rename them to style.less and style.css and compile changes with SimpLESS
  249. * http://wearekiss.com/simpless
  250. * If Jigoshop finds this file, it will load -only- that file, or if not found will default to our frontend.css
  251. * A user can also with the second option 'jigoshop_frontend_with_theme_css' enabled, load -both- the default frontend.css
  252. * -and- any extra bits found in the same 'theme/jigoshop/style.css'
  253. * This allows only a few modifications to be added in after the default frontend.css
  254. * It will also allow for easier additions to frontend.css that get missed if themers don't upgrade their version.
  255. * With these 2 options, users should either provide the complete frontend.css (style.css in the theme jigoshop folder)
  256. * or just the few changes again in the style.css in the theme jigoshop folder and set the 2nd option accordingly
  257. */
  258. $frontend_css = jigoshop::assets_url() . '/assets/css/frontend.css';
  259. $theme_css = file_exists( get_stylesheet_directory() . '/jigoshop/style.css')
  260. ? get_stylesheet_directory_uri() . '/jigoshop/style.css'
  261. : jigoshop::assets_url() . '/assets/css/frontend.css';
  262. if ( $jigoshop_options->get_option( 'jigoshop_disable_css' ) == 'no' ) {
  263. if ( $jigoshop_options->get_option( 'jigoshop_frontend_with_theme_css' ) == 'yes' ) {
  264. wp_enqueue_style( 'jigoshop_frontend_styles', $frontend_css );
  265. }
  266. wp_enqueue_style( 'jigoshop_theme_styles', $theme_css );
  267. }
  268. if ( $jigoshop_options->get_option( 'jigoshop_disable_fancybox' ) == 'no' ) {
  269. wp_enqueue_style( 'jigoshop_fancybox_styles', jigoshop::assets_url() . '/assets/css/fancybox.css' );
  270. wp_enqueue_script( 'fancybox', jigoshop::assets_url().'/assets/js/jquery.fancybox-1.3.4.pack.js', array('jquery'));
  271. }
  272. wp_enqueue_style( 'jqueryui_styles', jigoshop::assets_url().'/assets/css/ui.css' );
  273. wp_enqueue_script( 'jqueryui', jigoshop::assets_url().'/assets/js/jquery-ui-1.9.2.min.js', array('jquery'), '1.9.2' );
  274. wp_enqueue_script( 'jigoshop_blockui', jigoshop::assets_url().'/assets/js/blockui.js', array('jquery'));
  275. wp_enqueue_script( 'jigoshop_frontend', jigoshop::assets_url().'/assets/js/jigoshop_frontend.js', array('jquery'));
  276. wp_enqueue_script( 'jigoshop_script', jigoshop::assets_url().'/assets/js/script.js', array('jquery'));
  277. /* Script.js variables */
  278. $jigoshop_params = array(
  279. 'ajax_url' => admin_url('admin-ajax.php'),
  280. 'assets_url' => jigoshop::assets_url(),
  281. 'checkout_url' => admin_url('admin-ajax.php?action=jigoshop-checkout'),
  282. 'countries' => json_encode(jigoshop_countries::$states),
  283. 'currency_symbol' => get_jigoshop_currency_symbol(),
  284. 'get_variation_nonce' => wp_create_nonce("get-variation"),
  285. 'load_fancybox' => $jigoshop_options->get_option( 'jigoshop_disable_fancybox' )=='no'?true:false,
  286. 'option_guest_checkout' => $jigoshop_options->get_option('jigoshop_enable_guest_checkout'),
  287. 'select_state_text' => __('Select a state&hellip;', 'jigoshop'),
  288. 'state_text' => __('state', 'jigoshop'),
  289. 'update_order_review_nonce' => wp_create_nonce("update-order-review"),
  290. 'billing_state' => jigoshop_customer::get_state(),
  291. 'shipping_state' => jigoshop_customer::get_shipping_state()
  292. );
  293. if ( isset( jigoshop_session::instance()->min_price ))
  294. $jigoshop_params['min_price'] = $_GET['min_price'];
  295. if ( isset( jigoshop_session::instance()->max_price ))
  296. $jigoshop_params['max_price'] = $_GET['max_price'];
  297. $jigoshop_params['is_checkout'] = ( is_page( jigoshop_get_page_id( 'checkout' )) || is_page( jigoshop_get_page_id( 'pay' )) );
  298. $jigoshop_params = apply_filters('jigoshop_params', $jigoshop_params);
  299. wp_localize_script( 'jigoshop_script', 'jigoshop_params', $jigoshop_params );
  300. }
  301. /**
  302. * Add a "Settings" link to the plugins.php page for Jigoshop
  303. **/
  304. add_filter( 'plugin_action_links', 'jigoshop_add_settings_link', 10, 2 );
  305. function jigoshop_add_settings_link( $links, $file ) {
  306. $this_plugin = plugin_basename( __FILE__ );
  307. if ( $file == $this_plugin ) {
  308. $settings_link = '<a href="admin.php?page=jigoshop_settings">' . __( 'Settings', 'jigoshop' ) . '</a>';
  309. array_unshift( $links, $settings_link );
  310. }
  311. return $links;
  312. }
  313. /**
  314. * Add post thumbnail support to WordPress if needed
  315. **/
  316. add_action( 'after_setup_theme', 'jigoshop_check_thumbnail_support', 99 );
  317. function jigoshop_check_thumbnail_support() {
  318. if ( ! current_theme_supports( 'post-thumbnails' ) ) {
  319. add_theme_support( 'post-thumbnails' );
  320. remove_post_type_support( 'post', 'thumbnail' );
  321. remove_post_type_support( 'page', 'thumbnail' );
  322. } else {
  323. add_post_type_support( 'product', 'thumbnail' );
  324. }
  325. }
  326. add_action( 'admin_enqueue_scripts', 'jigoshop_admin_styles' );
  327. function jigoshop_admin_styles() {
  328. /* Our setting icons */
  329. wp_enqueue_style( 'jigoshop_admin_icons_style', jigoshop::assets_url() . '/assets/css/admin-icons.css' );
  330. if ( ! jigoshop_is_admin_page() ) return false;
  331. wp_enqueue_style( 'jigoshop_admin_styles', jigoshop::assets_url() . '/assets/css/admin.css' );
  332. wp_enqueue_style( 'jigoshop-select2', jigoshop::assets_url() . '/assets/css/select2.css', '', '3.1', 'screen' );
  333. wp_enqueue_style( 'jquery-ui-jigoshop-styles', jigoshop::assets_url() . '/assets/css/jquery-ui-1.8.16.jigoshop.css' );
  334. wp_enqueue_style( 'thickbox' );
  335. }
  336. add_action( 'admin_print_scripts', 'jigoshop_admin_scripts' );
  337. function jigoshop_admin_scripts() {
  338. if ( !jigoshop_is_admin_page() ) return false;
  339. $pagenow = jigoshop_is_admin_page();
  340. wp_enqueue_script( 'jigoshop-select2', jigoshop::assets_url().'/assets/js/select2.min.js', array( 'jquery' ), '3.1' );
  341. wp_enqueue_script( 'jquery-ui-datepicker', jigoshop::assets_url().'/assets/js/jquery-ui-datepicker-1.8.16.min.js', array( 'jquery' ), '1.8.16' );
  342. wp_enqueue_script( 'jigoshop_blockui', jigoshop::assets_url() . '/assets/js/blockui.js', array( 'jquery' ), '2.4.6' );
  343. wp_enqueue_script( 'jigoshop_backend', jigoshop::assets_url() . '/assets/js/jigoshop_backend.js', array( 'jquery' ), '1.0' );
  344. wp_enqueue_script( 'thickbox' );
  345. if ( $pagenow == 'jigoshop_page_jigoshop_reports' || $pagenow == 'toplevel_page_jigoshop' ) {
  346. wp_enqueue_script('jquery_flot', jigoshop::assets_url().'/assets/js/jquery.flot.min.js', array( 'jquery' ), '1.0' );
  347. wp_enqueue_script('jquery_flot_pie', jigoshop::assets_url().'/assets/js/jquery.flot.pie.min.js', array( 'jquery' ), '1.0' );
  348. }
  349. /**
  350. * Disable autosaves on the order and coupon pages. Prevents the javascript alert when modifying.
  351. * `wp_deregister_script( 'autosave' )` would produce errors, so we use a filter instead.
  352. */
  353. if ( $pagenow == 'shop_order' || $pagenow == 'shop_coupon' )
  354. add_filter( 'script_loader_src', 'jigoshop_disable_autosave', 10, 2 );
  355. }
  356. //### Functions #########################################################
  357. /**
  358. * Set Jigoshop Product Image Sizes for WordPress based on Admin->Jigoshop->Settings->Images
  359. **/
  360. function jigoshop_set_image_sizes() {
  361. $jigoshop_options = Jigoshop_Base::get_options();
  362. $sizes = array(
  363. 'shop_tiny' => 'tiny',
  364. 'shop_thumbnail' => 'thumbnail',
  365. 'shop_small' => 'catalog',
  366. 'shop_large' => 'featured'
  367. );
  368. foreach ( $sizes as $size => $altSize )
  369. add_image_size(
  370. $size,
  371. $jigoshop_options->get_option('jigoshop_' . $size . '_w'),
  372. $jigoshop_options->get_option('jigoshop_' . $size . '_h'),
  373. ( $jigoshop_options->get_option( 'jigoshop_use_wordpress_' . $altSize . '_crop', 'no' ) == 'yes' )
  374. );
  375. /* The elephant in the room (._. ) */
  376. add_image_size( 'admin_product_list', 32, 32, $jigoshop_options->get_option( 'jigoshop_use_wordpress_tiny_crop', 'no' ) == 'yes' ? true : false );
  377. }
  378. /**
  379. * Get Jigoshop Product Image Size based on Admin->Jigoshop->Settings->Images
  380. * @param string $size - one of the 4 defined Jigoshop image sizes
  381. * @return array - an array containing the width and height of the required size
  382. * @since 0.9.9
  383. **/
  384. function jigoshop_get_image_size( $size ) {
  385. $jigoshop_options = Jigoshop_Base::get_options();
  386. if ( is_array( $size ) )
  387. return $size;
  388. switch ( $size ) :
  389. case 'admin_product_list':
  390. $image_size = array( 32, 32 );
  391. break;
  392. case 'shop_tiny':
  393. $image_size = array( $jigoshop_options->get_option('jigoshop_shop_tiny_w'), $jigoshop_options->get_option('jigoshop_shop_tiny_h') );
  394. break;
  395. case 'shop_thumbnail':
  396. $image_size = array( $jigoshop_options->get_option('jigoshop_shop_thumbnail_w'), $jigoshop_options->get_option('jigoshop_shop_thumbnail_h') );
  397. break;
  398. case 'shop_small':
  399. $image_size = array( $jigoshop_options->get_option('jigoshop_shop_small_w'), $jigoshop_options->get_option('jigoshop_shop_small_h') );
  400. break;
  401. case 'shop_large':
  402. $image_size = array( $jigoshop_options->get_option('jigoshop_shop_large_w'), $jigoshop_options->get_option('jigoshop_shop_large_h') );
  403. break;
  404. default:
  405. $image_size = array( $jigoshop_options->get_option('jigoshop_shop_small_w'), $jigoshop_options->get_option('jigoshop_shop_small_h') );
  406. break;
  407. endswitch;
  408. return $image_size;
  409. }
  410. function jigoshop_is_admin_page() {
  411. global $current_screen;
  412. if ( $current_screen->post_type == 'product' || $current_screen->post_type == 'shop_order' || $current_screen->post_type == 'shop_coupon' )
  413. return $current_screen->post_type;
  414. if ( strstr( $current_screen->id, 'jigoshop' ) )
  415. return $current_screen->id;
  416. return false;
  417. }
  418. function jigoshop_disable_autosave( $src, $handle ) {
  419. if ( 'autosave' != $handle ) return $src;
  420. return '';
  421. }
  422. /**
  423. * jigoshop_demo_store
  424. * Adds a demo store banner to the site
  425. */
  426. add_action( 'wp_footer', 'jigoshop_demo_store' );
  427. function jigoshop_demo_store() {
  428. if ( Jigoshop_Base::get_options()->get_option( 'jigoshop_demo_store' ) == 'yes' && is_jigoshop() ) :
  429. $bannner_text = apply_filters( 'jigoshop_demo_banner_text', __('This is a demo store for testing purposes &mdash; no orders shall be fulfilled.', 'jigoshop') );
  430. echo '<p class="demo_store">'.$bannner_text.'</p>';
  431. endif;
  432. }
  433. /**
  434. * jigoshop_sharethis
  435. * Adds social sharing code to footer
  436. */
  437. add_action( 'wp_footer', 'jigoshop_sharethis' );
  438. function jigoshop_sharethis() {
  439. $jigoshop_options = Jigoshop_Base::get_options();
  440. if (is_single() && $jigoshop_options->get_option('jigoshop_sharethis')) :
  441. if (is_ssl()) :
  442. $sharethis = 'https://ws.sharethis.com/button/buttons.js';
  443. else :
  444. $sharethis = 'http://w.sharethis.com/button/buttons.js';
  445. endif;
  446. echo '<script type="text/javascript">var switchTo5x=true;</script><script type="text/javascript" src="'.$sharethis.'"></script><script type="text/javascript">stLight.options({publisher:"'.$jigoshop_options->get_option('jigoshop_sharethis').'"});</script>';
  447. endif;
  448. }
  449. /**
  450. * Mail from name/email
  451. **/
  452. add_filter( 'wp_mail_from_name', 'jigoshop_mail_from_name' );
  453. function jigoshop_mail_from_name( $name ) {
  454. $name = get_bloginfo('name');
  455. $name = esc_attr($name);
  456. return $name;
  457. }
  458. /*
  459. add_filter( 'wp_mail_from', 'jigoshop_mail_from' );
  460. function jigoshop_mail_from( $email ) {
  461. $email = Jigoshop_Base::get_options()->get_option('jigoshop_email');
  462. return $email;
  463. }
  464. */
  465. /**
  466. * Allow product_cat in the permalinks for products.
  467. *
  468. * @param string $permalink The existing permalink URL.
  469. */
  470. add_filter( 'post_type_link', 'jigoshop_product_cat_filter_post_link', 10, 4 );
  471. function jigoshop_product_cat_filter_post_link( $permalink, $post, $leavename, $sample ) {
  472. if ($post->post_type!=='product') return $permalink;
  473. // Abort early if the placeholder rewrite tag isn't in the generated URL
  474. if ( false === strpos( $permalink, '%product_cat%' ) ) return $permalink;
  475. // Get the custom taxonomy terms in use by this post
  476. $terms = get_the_terms( $post->ID, 'product_cat' );
  477. if ( empty( $terms ) ) :
  478. // If no terms are assigned to this post, use a string instead
  479. $permalink = str_replace( '%product_cat%', _x('product', 'slug', 'jigoshop'), $permalink );
  480. else :
  481. // Replace the placeholder rewrite tag with the first term's slug
  482. $first_term = apply_filters( 'jigoshop_product_cat_permalink_terms', array_shift( $terms ), $terms);
  483. $permalink = str_replace( '%product_cat%', $first_term->slug, $permalink );
  484. endif;
  485. return $permalink;
  486. }
  487. /**
  488. * Evaluates to true only on the Shop page, not Product categories and tags
  489. * Note:is used to replace is_page( jigoshop_get_page_id( 'shop' ) )
  490. *
  491. * @return bool
  492. * @since 0.9.9
  493. */
  494. function is_shop() {
  495. return is_post_type_archive( 'product' ) || is_page( jigoshop_get_page_id('shop') );
  496. }
  497. /**
  498. * Evaluates to true only on the Category Pages
  499. *
  500. * @return bool
  501. * @since 0.9.9
  502. */
  503. function is_product_category() {
  504. return is_tax( 'product_cat' );
  505. }
  506. /**
  507. * Evaluates to true only on the Tag Pages
  508. *
  509. * @return bool
  510. * @since 0.9.9
  511. */
  512. function is_product_tag() {
  513. return is_tax( 'product_tag' );
  514. }
  515. /**
  516. * Evaluates to true only on the Single Product Page
  517. *
  518. * @return bool
  519. * @since 0.9.9
  520. */
  521. function is_product() {
  522. return is_singular( array('product') );
  523. }
  524. /**
  525. * Evaluates to true only on Shop, Product Category, and Product Tag pages
  526. *
  527. * @return bool
  528. * @since 0.9.9
  529. */
  530. function is_product_list() {
  531. $is_list = false;
  532. $is_list |= is_shop();
  533. $is_list |= is_product_tag();
  534. $is_list |= is_product_category();
  535. return $is_list;
  536. }
  537. /**
  538. * Evaluates to true for all Jigoshop pages
  539. *
  540. * @return bool
  541. * @since 0.9.9
  542. */
  543. function is_jigoshop() {
  544. $is_jigo = false;
  545. $is_jigo |= is_content_wrapped();
  546. $is_jigo |= is_account();
  547. $is_jigo |= is_cart();
  548. $is_jigo |= is_checkout();
  549. $is_jigo |= is_order_tracker();
  550. return $is_jigo;
  551. }
  552. /**
  553. * Evaluates to true only on the Shop, Category, Tag and Single Product Pages
  554. *
  555. * @return bool
  556. * @since 0.9.9.1
  557. */
  558. function is_content_wrapped() {
  559. $is_wrapped = false;
  560. $is_wrapped |= is_product_list();
  561. $is_wrapped |= is_product();
  562. return $is_wrapped;
  563. }
  564. /**
  565. * Jigoshop page IDs
  566. *
  567. * returns -1 if no page is found
  568. **/
  569. if (!function_exists('jigoshop_get_page_id')) {
  570. function jigoshop_get_page_id( $page ) {
  571. $jigoshop_options = Jigoshop_Base::get_options();
  572. $page = apply_filters('jigoshop_get_' . $page . '_page_id', $jigoshop_options->get_option('jigoshop_' . $page . '_page_id'));
  573. return ($page) ? $page : -1;
  574. }
  575. }
  576. /**
  577. * Evaluates to true only on the Order Tracking page
  578. *
  579. * @return bool
  580. * @since 0.9.9.1
  581. */
  582. function is_order_tracker() {
  583. return is_page( jigoshop_get_page_id('track_order'));
  584. }
  585. /**
  586. * Evaluates to true only on the Cart page
  587. *
  588. * @return bool
  589. * @since 0.9.8
  590. */
  591. function is_cart() {
  592. return is_page( jigoshop_get_page_id('cart'));
  593. }
  594. /**
  595. * Evaluates to true only on the Checkout or Pay pages
  596. *
  597. * @return bool
  598. * @since 0.9.8
  599. */
  600. function is_checkout() {
  601. return is_page( jigoshop_get_page_id('checkout')) | is_page( jigoshop_get_page_id('pay'));
  602. }
  603. /**
  604. * Evaluates to true only on the main Account or any sub-account pages
  605. *
  606. * @return bool
  607. * @since 0.9.9.1
  608. */
  609. function is_account() {
  610. $is_account = false;
  611. $is_account |= is_page( jigoshop_get_page_id('myaccount') );
  612. $is_account |= is_page( jigoshop_get_page_id('edit_address') );
  613. $is_account |= is_page( jigoshop_get_page_id('change_password') );
  614. $is_account |= is_page( jigoshop_get_page_id('view_order') );
  615. return $is_account;
  616. }
  617. if (!function_exists('is_ajax')) {
  618. function is_ajax() {
  619. if ( defined('DOING_AJAX') ) return true;
  620. return ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest' );
  621. }
  622. }
  623. function jigoshop_force_ssl() {
  624. if (is_checkout() && !is_ssl()) :
  625. wp_safe_redirect( str_replace('http:', 'https:', get_permalink(jigoshop_get_page_id('checkout'))), 301 );
  626. exit;
  627. endif;
  628. }
  629. if (!is_admin() && Jigoshop_Base::get_options()->get_option('jigoshop_force_ssl_checkout')=='yes') add_action( 'wp', 'jigoshop_force_ssl');
  630. function jigoshop_force_ssl_images( $content ) {
  631. if (is_ssl()) :
  632. if (is_array($content)) :
  633. $content = array_map('jigoshop_force_ssl_images', $content);
  634. else :
  635. $content = str_replace('http:', 'https:', $content);
  636. endif;
  637. endif;
  638. return $content;
  639. }
  640. add_filter('post_thumbnail_html', 'jigoshop_force_ssl_images');
  641. add_filter('widget_text', 'jigoshop_force_ssl_images');
  642. add_filter('wp_get_attachment_url', 'jigoshop_force_ssl_images');
  643. add_filter('wp_get_attachment_image_attributes', 'jigoshop_force_ssl_images');
  644. add_filter('wp_get_attachment_url', 'jigoshop_force_ssl_images');
  645. function jigoshop_force_ssl_urls( $url ) {
  646. if (is_ssl()) :
  647. $url = str_replace('http:', 'https:', $url);
  648. endif;
  649. return $url;
  650. }
  651. add_filter('option_siteurl', 'jigoshop_force_ssl_urls');
  652. add_filter('option_home', 'jigoshop_force_ssl_urls');
  653. add_filter('option_url', 'jigoshop_force_ssl_urls');
  654. add_filter('option_wpurl', 'jigoshop_force_ssl_urls');
  655. add_filter('option_stylesheet_url', 'jigoshop_force_ssl_urls');
  656. add_filter('option_template_url', 'jigoshop_force_ssl_urls');
  657. add_filter('script_loader_src', 'jigoshop_force_ssl_urls');
  658. add_filter('style_loader_src', 'jigoshop_force_ssl_urls');
  659. function get_jigoshop_currency_symbol() {
  660. $jigoshop_options = Jigoshop_Base::get_options();
  661. $currency = $jigoshop_options->get_option('jigoshop_currency');
  662. $symbols = jigoshop::currency_symbols();
  663. $currency_symbol = $symbols[$currency];
  664. return apply_filters('jigoshop_currency_symbol', $currency_symbol, $currency);
  665. }
  666. function jigoshop_price( $price, $args = array() ) {
  667. $jigoshop_options = Jigoshop_Base::get_options();
  668. extract(shortcode_atts(array(
  669. 'ex_tax_label' => 0, // 0 for no label, 1 for ex. tax, 2 for inc. tax
  670. 'with_currency' => true
  671. ), $args));
  672. $tax_label = '';
  673. if ($ex_tax_label === 1) {
  674. $tax_label = __(' <small>(ex. tax)</small>', 'jigoshop');
  675. } else if ($ex_tax_label === 2) {
  676. $tax_label = __(' <small>(inc. tax)</small>', 'jigoshop');
  677. } else {
  678. $tax_label = '';
  679. }
  680. $return = '';
  681. $price = number_format(
  682. (double) $price,
  683. (int) $jigoshop_options->get_option('jigoshop_price_num_decimals'),
  684. $jigoshop_options->get_option('jigoshop_price_decimal_sep'),
  685. $jigoshop_options->get_option('jigoshop_price_thousand_sep')
  686. );
  687. $return = $price;
  688. if ($with_currency) :
  689. $currency_pos = $jigoshop_options->get_option('jigoshop_currency_pos');
  690. $currency_symbol = get_jigoshop_currency_symbol();
  691. $currency_code = $jigoshop_options->get_option('jigoshop_currency');
  692. switch ($currency_pos) :
  693. case 'left' :
  694. $return = $currency_symbol . $price;
  695. break;
  696. case 'left_space' :
  697. $return = $currency_symbol . ' ' . $price;
  698. break;
  699. case 'right' :
  700. $return = $price . $currency_symbol;
  701. break;
  702. case 'right_space' :
  703. $return = $price . ' ' . $currency_symbol;
  704. break;
  705. case 'left_code' :
  706. $return = $currency_code . $price;
  707. break;
  708. case 'left_code_space' :
  709. $return = $currency_code . ' ' . $price;
  710. break;
  711. case 'right_code' :
  712. $return = $price . $currency_code;
  713. break;
  714. case 'right_code_space' :
  715. $return = $price . ' ' . $currency_code;
  716. break;
  717. case 'code_symbol' :
  718. $return = $currency_code . $price . $currency_symbol;
  719. break;
  720. case 'code_symbol_space' :
  721. $return = $currency_code . ' ' . $price . ' ' . $currency_symbol;
  722. break;
  723. case 'symbol_code' :
  724. $return = $currency_symbol . $price . $currency_code;
  725. break;
  726. case 'symbol_code_space' :
  727. $return = $currency_symbol . ' ' . $price . ' ' . $currency_code;
  728. break;
  729. endswitch;
  730. // only show tax label (ex. tax) if we are going to show the price with currency as well. Otherwise we just want the formatted price
  731. if ($jigoshop_options->get_option('jigoshop_calc_taxes')=='yes') $return .= $tax_label;
  732. endif;
  733. return apply_filters( 'jigoshop_price_display_filter', $return);
  734. }
  735. /** Show variation info if set */
  736. function jigoshop_get_formatted_variation( $variation = '', $flat = false ) {
  737. if ($variation && is_array($variation)) :
  738. $return = '';
  739. if (!$flat) :
  740. $return = '<dl class="variation">';
  741. endif;
  742. $varation_list = array();
  743. foreach ($variation as $name => $value) :
  744. $name = str_replace('tax_', '', $name);
  745. if ( taxonomy_exists( 'pa_'.$name )) :
  746. $terms = get_terms( 'pa_'.$name, array( 'orderby' => 'slug', 'hide_empty' => '0' ) );
  747. foreach ( $terms as $term ) :
  748. if ( $term->slug == $value ) $value = $term->name;
  749. endforeach;
  750. $name = get_taxonomy( 'pa_'.$name )->labels->name;
  751. $name = jigoshop_product::attribute_label('pa_'.$name);
  752. endif;
  753. if ($flat) :
  754. $varation_list[] = $name.': '.$value;
  755. else :
  756. $varation_list[] = '<dt>'.$name.':</dt><dd>'.$value.'</dd>';
  757. endif;
  758. endforeach;
  759. if ($flat) :
  760. $return .= implode(', ', $varation_list);
  761. else :
  762. $return .= implode('', $varation_list);
  763. endif;
  764. if (!$flat) :
  765. $return .= '</dl>';
  766. endif;
  767. return $return;
  768. endif;
  769. }
  770. // Remove pingbacks/trackbacks from Comments Feed
  771. // betterwp.net/wordpress-tips/remove-pingbackstrackbacks-from-comments-feed/
  772. add_filter('request', 'jigoshop_filter_request');
  773. function jigoshop_filter_request($qv) {
  774. if (isset($qv['feed']) && !empty($qv['withcomments']))
  775. {
  776. add_filter('comment_feed_where', 'jigoshop_comment_feed_where');
  777. }
  778. return $qv;
  779. }
  780. function jigoshop_comment_feed_where($cwhere) {
  781. $cwhere .= " AND comment_type != 'jigoshop' ";
  782. return $cwhere;
  783. }
  784. function jigoshop_let_to_num($v) {
  785. $l = substr($v, -1);
  786. $ret = substr($v, 0, -1);
  787. switch(strtoupper($l)){
  788. case 'P':
  789. $ret *= 1024;
  790. case 'T':
  791. $ret *= 1024;
  792. case 'G':
  793. $ret *= 1024;
  794. case 'M':
  795. $ret *= 1024;
  796. case 'K':
  797. $ret *= 1024;
  798. break;
  799. }
  800. return $ret;
  801. }
  802. function jigowatt_clean( $var ) {
  803. return strip_tags(stripslashes(trim($var)));
  804. }
  805. // Returns a float value
  806. function jigoshop_sanitize_num( $var ) {
  807. // TODO: as it stands, it doesn't allow negative values (-JAP-)
  808. // should be - preg_replace("/^[^[\-\+]0-9\.]/","",$var)
  809. // currently only used for prices in product-data-save.php
  810. return strip_tags(stripslashes(floatval(preg_replace("/^[^0-9\.]/","",$var))));
  811. }
  812. // Author: Sergey Biryukov
  813. // Plugin URI: http://wordpress.org/extend/plugins/allow-cyrillic-usernames/
  814. add_filter('sanitize_user', 'jigoshop_sanitize_user', 10, 3);
  815. function jigoshop_sanitize_user($username, $raw_username, $strict) {
  816. $username = wp_strip_all_tags( $raw_username );
  817. $username = remove_accents( $username );
  818. $username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username );
  819. $username = preg_replace( '/&.+?;/', '', $username ); // Kill entities
  820. if ( $strict )
  821. $username = preg_replace( '|[^a-z?-?0-9 _.\-@]|iu', '', $username );
  822. $username = trim( $username );
  823. $username = preg_replace( '|\s+|', ' ', $username );
  824. return $username;
  825. }
  826. add_action( 'wp_head', 'jigoshop_head_version' );
  827. function jigoshop_head_version() {
  828. echo "\n" . '<!-- Jigoshop Version: '.jigoshop::jigoshop_version().' -->' . "\n";
  829. }
  830. global $jigoshop_body_classes;
  831. add_action('wp_head', 'jigoshop_page_body_classes');
  832. function jigoshop_page_body_classes() {
  833. global $jigoshop_body_classes;
  834. $jigoshop_body_classes = (array) $jigoshop_body_classes;
  835. if ( is_order_tracker() ) jigoshop_add_body_class( array( 'jigoshop', 'jigoshop-tracker' ) );
  836. if ( is_checkout() ) jigoshop_add_body_class( array( 'jigoshop', 'jigoshop-checkout' ) );
  837. if ( is_cart() ) jigoshop_add_body_class( array( 'jigoshop', 'jigoshop-cart' ) );
  838. if ( is_page(jigoshop_get_page_id('thanks'))) jigoshop_add_body_class( array( 'jigoshop', 'jigoshop-thanks' ) );
  839. if ( is_page(jigoshop_get_page_id('pay'))) jigoshop_add_body_class( array( 'jigoshop', 'jigoshop-pay' ) );
  840. if ( is_account() ) jigoshop_add_body_class( array( 'jigoshop', 'jigoshop-myaccount' ) );
  841. }
  842. function jigoshop_add_body_class( $class = array() ) {
  843. global $jigoshop_body_classes;
  844. $jigoshop_body_classes = (array) $jigoshop_body_classes;
  845. $jigoshop_body_classes = array_unique( array_merge( $class, $jigoshop_body_classes ));
  846. }
  847. add_filter('body_class','jigoshop_body_class');
  848. function jigoshop_body_class($classes) {
  849. global $jigoshop_body_classes;
  850. $jigoshop_body_classes = (array) $jigoshop_body_classes;
  851. $classes = array_unique( array_merge( $classes, $jigoshop_body_classes ));
  852. return $classes;
  853. }
  854. //### Extra Review Field in comments #########################################################
  855. function jigoshop_add_comment_rating($comment_id) {
  856. if ( isset($_POST['rating']) ) :
  857. if (!$_POST['rating'] || $_POST['rating'] > 5 || $_POST['rating'] < 0) $_POST['rating'] = 5;
  858. add_comment_meta( $comment_id, 'rating', $_POST['rating'], true );
  859. endif;
  860. }
  861. add_action( 'comment_post', 'jigoshop_add_comment_rating', 1 );
  862. function jigoshop_check_comment_rating($comment_data) {
  863. // If posting a comment (not trackback etc) and not logged in
  864. if ( isset($_POST['rating']) && !jigoshop::verify_nonce('comment_rating') )
  865. wp_die( __('You have taken too long. Please go back and refresh the page.', 'jigoshop') );
  866. elseif ( isset($_POST['rating']) && empty($_POST['rating']) && $comment_data['comment_type']== '' ) {
  867. wp_die( __('Please rate the product.',"jigoshop") );
  868. exit;
  869. }
  870. return $comment_data;
  871. }
  872. add_filter('preprocess_comment', 'jigoshop_check_comment_rating', 0);
  873. //### Comments #########################################################
  874. function jigoshop_comments($comment, $args, $depth) {
  875. $GLOBALS['comment'] = $comment; global $post; ?>
  876. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
  877. <div id="comment-<?php comment_ID(); ?>" class="comment_container">
  878. <?php echo get_avatar( $comment, $size='60' ); ?>
  879. <div class="comment-text">
  880. <?php if ( $rating = get_comment_meta( $comment->comment_ID, 'rating', true ) ): ?>
  881. <div class="star-rating" title="<?php echo esc_attr( $rating ); ?>">
  882. <span style="width:<?php echo $rating*16; ?>px"><?php echo $rating; ?> <?php _e('out of 5', 'jigoshop'); ?></span>
  883. </div>
  884. <?php endif; ?>
  885. <?php if ($comment->comment_approved == '0') : ?>
  886. <p class="meta"><em><?php _e('Your comment is awaiting approval','jigoshop'); ?></em></p>
  887. <?php else : ?>
  888. <p class="meta">
  889. <?php _e('Rating by','jigoshop'); ?> <strong class="reviewer vcard"><span class="fn"><?php comment_author(); ?></span></strong> <?php _e('on','jigoshop'); ?> <?php echo date_i18n(get_option('date_format'), strtotime(get_comment_date('Y-m-d'))); ?>:
  890. </p>
  891. <?php endif; ?>
  892. <div class="description"><?php comment_text(); ?></div>
  893. <div class="clear"></div>
  894. </div>
  895. <div class="clear"></div>
  896. </div>
  897. <?php
  898. }
  899. //### Exclude order comments from front end #########################################################
  900. add_filter( 'comments_clauses', 'jigoshop_exclude_order_admin_comments', 10, 1);
  901. function jigoshop_exclude_order_admin_comments( $clauses ) {
  902. // NOTE: bit of a hack, tests if we're in the admin & its an ajax call
  903. // Don't hide when viewing orders in admin
  904. // TODO: removing the is_ajax() call for version 1.6, isn't working for some reason, order notes were not appearing in Admin
  905. if ( is_admin() ) {
  906. return $clauses;
  907. }
  908. // Hide all those comments which are of type jigoshop or order_note
  909. $clauses['where'] .= ' AND comment_type != "jigoshop"';
  910. $clauses['where'] .= ' AND comment_type != "order_note"'; // Removes order notes
  911. return $clauses;
  912. }
  913. /**
  914. * Support for Import/Export
  915. *
  916. * WordPress import should work - however, it fails to import custom product attribute taxonomies.
  917. * This code grabs the file before it is imported and ensures the taxonomies are created.
  918. **/
  919. function jigoshop_import_start() {
  920. global $wpdb;
  921. $jigoshop_options = Jigoshop_Base::get_options();
  922. $id = (int) $_POST['import_id'];
  923. $file = get_attached_file( $id );
  924. $parser = new WXR_Parser();
  925. $import_data = $parser->parse( $file );
  926. if (isset($import_data['posts'])) :
  927. $posts = $import_data['posts'];
  928. if ($posts && sizeof($posts)>0) foreach ($posts as $post) :
  929. if ($post['post_type']=='product') :
  930. if ($post['terms'] && sizeof($post['terms'])>0) :
  931. foreach ($post['terms'] as $term) :
  932. $domain = $term['domain'];
  933. if (strstr($domain, 'pa_')) :
  934. // Make sure it exists!
  935. if (!taxonomy_exists( $domain )) :
  936. $nicename = sanitize_title(str_replace('pa_', '', $domain));
  937. $exists_in_db = $wpdb->get_var( $wpdb->prepare( "SELECT attribute_id FROM ".$wpdb->prefix . "jigoshop_attribute_taxonomies WHERE attribute_name = %s;", $nicename ) );
  938. // Create the taxonomy
  939. if (!$exists_in_db) :
  940. $wpdb->insert( $wpdb->prefix . "jigoshop_attribute_taxonomies", array( 'attribute_name' => $nicename, 'attribute_type' => 'select' ), array( '%s', '%s' ) );
  941. endif;
  942. // Register the taxonomy now so that the import works!
  943. register_taxonomy( $domain,
  944. array('product'),
  945. array(
  946. 'hierarchical' => true,
  947. 'labels' => array(
  948. 'name' => $nicename,
  949. 'singular_name' => $nicename,
  950. 'search_items' => __( 'Search ', 'jigoshop') . $nicename,
  951. 'all_items' => __( 'All ', 'jigoshop') . $nicename,
  952. 'parent_item' => __( 'Parent ', 'jigoshop') . $nicename,
  953. 'parent_item_colon'=> __( 'Parent ', 'jigoshop') . $nicename . ':',
  954. 'edit_item' => __( 'Edit ', 'jigoshop') . $nicename,
  955. 'update_item' => __( 'Update ', 'jigoshop') . $nicename,
  956. 'add_new_item' => __( 'Add New ', 'jigoshop') . $nicename,
  957. 'new_item_name' => __( 'New ', 'jigoshop') . $nicename
  958. ),
  959. 'show_ui' => false,
  960. 'query_var'=> true,
  961. 'rewrite' => array( 'slug'=> sanitize_title($nicename), 'with_front'=> false, 'hierarchical'=> true ),
  962. )
  963. );
  964. $jigoshop_options->set_option('jigowatt_update_rewrite_rules', '1');
  965. endif;
  966. endif;
  967. endforeach;
  968. endif;
  969. endif;
  970. endforeach;
  971. endif;
  972. }
  973. add_action('import_start', 'jigoshop_import_start');
  974. if(!function_exists('jigoshop_log')){
  975. /**
  976. * Logs to the debug log when you enable wordpress debug mode.
  977. *
  978. * @param string $from_class is the name of the php file that you are logging from.
  979. * defaults to jigoshop if non is supplied.
  980. * @param mixed $message this can be a regular string, array or object
  981. */
  982. function jigoshop_log( $message, $from_class = 'jigoshop' ) {
  983. if( WP_DEBUG === true ) :
  984. if( is_array( $message ) || is_object( $message ) ) :
  985. error_log( $from_class . ': ' . print_r( $message, true ) );
  986. else :
  987. error_log( $from_class . ': ' . $message );
  988. endif;
  989. endif;
  990. }
  991. }