/wp-content/plugins/marketpress/marketpress.php
PHP | 7392 lines | 5719 code | 1072 blank | 601 comment | 1222 complexity | fe95a7a5d81366f9494cf760be831ea9 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-3.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- Plugin Name: MarketPress
- Version: 2.8.1
- Plugin URI: http://premium.wpmudev.org/project/e-commerce/
- Description: The complete WordPress ecommerce plugin - works perfectly with BuddyPress and Multisite too to create a social marketplace, where you can take a percentage! Activate the plugin, adjust your settings then add some products to your store.
- Author: Aaron Edwards (Incsub)
- Author URI: http://uglyrobot.com
- Text Domain: mp
- WDP ID: 144
-
- Copyright 2009-2013 Incsub (http://incsub.com)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License (Version 2 - GPLv2) as published by
- the Free Software Foundation.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
- class MarketPress {
-
- var $version = '2.8.1';
- var $location;
- var $plugin_dir = '';
- var $plugin_url = '';
- var $product_template;
- var $product_taxonomy_template;
- var $product_list_template;
- var $store_template;
- var $checkout_template;
- var $orderstatus_template;
- var $language = '';
- var $checkout_error = false;
- var $cart_cache = false;
- var $is_shop_page = false;
- var $global_cart = false;
- var $skip_shipping_notice = false;
- var $weight_printed = false;
-
- function MarketPress() {
- $this->__construct();
- }
-
- function __construct() {
- //setup our variables
- $this->init_vars();
-
- //install plugin
- register_activation_hook( __FILE__, array($this, 'install') );
-
- //load dashboard notice
- include_once( $this->plugin_dir . 'dash-notice/wpmudev-dash-notification.php' );
-
- //load template functions
- require_once( $this->plugin_dir . 'template-functions.php' );
-
- //load shortcodes
- include_once( $this->plugin_dir . 'marketpress-shortcodes.php' );
-
- //load stats
- include_once( $this->plugin_dir . 'marketpress-stats.php' );
-
- //load sitewide features if WPMU
- if (is_multisite()) {
- include_once( $this->plugin_dir . 'marketpress-ms.php' );
- $network_settings = get_site_option( 'mp_network_settings' );
- if ( $network_settings['global_cart'] )
- $this->global_cart = true;
- }
-
- //localize the plugin
- add_action( 'plugins_loaded', array(&$this, 'localization'), 9 );
-
- //load APIs and plugins
- add_action( 'plugins_loaded', array(&$this, 'load_plugins') );
-
- //load importers
- add_action( 'plugins_loaded', array(&$this, 'load_importers') );
-
- //custom post type
- add_action( 'init', array(&$this, 'register_custom_posts'), 0 ); //super high priority
- add_filter( 'request', array(&$this, 'handle_edit_screen_filter') );
-
- //edit products page
- add_filter( 'manage_product_posts_columns', array(&$this, 'edit_products_columns') );
- add_action( 'manage_posts_custom_column', array(&$this, 'edit_products_custom_columns') );
- add_action( 'restrict_manage_posts', array(&$this, 'edit_products_filter') );
-
- add_filter( 'post_row_actions', array(&$this, 'edit_products_custom_row_actions'), 10, 2);
- add_filter( 'admin_action_copy-product', array(&$this, 'edit_products_copy_action') );
-
- //manage orders page
- add_filter( 'manage_product_page_marketpress-orders_columns', array(&$this, 'manage_orders_columns') );
- add_action( 'manage_posts_custom_column', array(&$this, 'manage_orders_custom_columns') );
-
- //Plug admin pages
- add_action( 'admin_menu', array(&$this, 'add_menu_items') );
- add_action( 'admin_print_styles', array(&$this, 'admin_css') );
- add_action( 'admin_print_scripts', array(&$this, 'admin_script_post') );
- add_action( 'admin_notices', array(&$this, 'admin_nopermalink_warning') );
- add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array(&$this, 'plugin_action_link'), 10, 2);
- add_action( 'wp_ajax_mp-hide-help', array(&$this, 'hide_help') );
-
- //Meta boxes
- add_action( 'add_meta_boxes_product', array(&$this, 'meta_boxes') );
- add_action( 'wp_insert_post', array(&$this, 'save_product_meta'), 10, 2 );
- add_filter( 'enter_title_here', array(&$this, 'filter_title') );
-
- //Templates and Rewrites
- add_action( 'wp', array(&$this, 'load_store_templates') );
- add_action( 'template_redirect', array(&$this, 'load_store_theme') );
- add_action( 'pre_get_posts', array(&$this, 'remove_canonical') );
- add_filter( 'rewrite_rules_array', array(&$this, 'add_rewrite_rules') );
- add_filter( 'query_vars', array(&$this, 'add_queryvars') );
- add_action( 'option_rewrite_rules', array(&$this, 'check_rewrite_rules') );
- add_action( 'init', array(&$this, 'flush_rewrite_check') );
- if ( !defined('MP_HIDE_MENUS') ) { //allows you to hide MP menus
- add_filter( 'wp_list_pages', array(&$this, 'filter_list_pages'), 10, 2 );
- add_filter( 'wp_nav_menu_objects', array(&$this, 'filter_nav_menu'), 10, 2 );
- }
-
- //Payment gateway returns
- add_action( 'pre_get_posts', array(&$this, 'handle_gateway_returns'), 1 );
-
- //Store cart handling
- add_action( 'template_redirect', array(&$this, 'store_script') ); //only on front pages
- /* use both actions so logged in and not logged in users can send this AJAX request */
- add_action( 'wp_ajax_nopriv_mp-update-cart', array(&$this, 'update_cart') );
- add_action( 'wp_ajax_mp-update-cart', array(&$this, 'update_cart') );
- add_action( 'wp_ajax_mp-province-field', 'mp_province_field' ); //province field callback for shipping form
- add_action( 'wp_ajax_nopriv_mp-province-field', 'mp_province_field' );
- add_action( 'wp_ajax_mp-orders-export', array(&$this, 'export_orders_csv') );
- add_action( 'wp_logout', array(&$this, 'logout_clear_session') ); //see http://premium.wpmudev.org/forums/topic/security-issue-with-marketpress
-
- add_action( 'wp_ajax_nopriv_get_products_list', array(&$this, 'get_products_list') );
- add_action( 'wp_ajax_get_products_list', array(&$this, 'get_products_list') );
-
- //Relies on post thumbnails for products
- add_action( 'after_setup_theme', array(&$this, 'post_thumbnails'), 9999 );
-
- //Add widgets
- if (!$this->get_setting('disable_cart', 0))
- add_action( 'widgets_init', create_function('', 'return register_widget("MarketPress_Shopping_Cart");') );
-
- add_action( 'widgets_init', create_function('', 'return register_widget("MarketPress_Product_List");') );
- add_action( 'widgets_init', create_function('', 'return register_widget("MarketPress_Categories_Widget");') );
- add_action( 'widgets_init', create_function('', 'return register_widget("MarketPress_Tag_Cloud_Widget");') );
-
- // Edit profile
- add_action( 'profile_update', array(&$this, 'user_profile_update') );
- add_action( 'edit_user_profile', array(&$this, 'user_profile_fields') );
- add_action( 'show_user_profile', array(&$this, 'user_profile_fields') );
-
- //update install script if necessary
- if (get_option('mp_version') != $this->version) {
- $this->install();
- }
- }
-
- function install() {
- $old_settings = get_option('mp_settings');
- $old_version = get_option('mp_version');
-
- //our default settings
- $default_settings = array (
- 'base_country' => 'US',
- 'tax' => array (
- 'rate' => 0,
- 'tax_shipping' => 1,
- 'tax_inclusive' => 0
- ),
- 'currency' => 'USD',
- 'curr_symbol_position' => 1,
- 'curr_decimal' => 1,
- 'disable_cart' => 0,
- 'hide_popup' => 0,
- 'inventory_threshhold' => 3,
- 'max_downloads' => 5,
- 'force_login' => 0,
- 'ga_ecommerce' => 'none',
- 'special_instructions' => 0,
- 'store_theme' => 'icons',
- 'show_img' => 1,
- 'product_img_height' => 150,
- 'product_img_width' => 150,
- 'list_img_height' => 150,
- 'list_img_width' => 150,
- 'show_excerpt' => 1,
- 'per_page' => 20,
- 'order_by' => 'title',
- /* Translators: change default slugs here */
- 'slugs' => array (
- 'store' => __('store', 'mp'),
- 'products' => __('products', 'mp'),
- 'cart' => __('shopping-cart', 'mp'),
- 'orderstatus' => __('order-status', 'mp'),
- 'category' => __('category', 'mp'),
- 'tag' => __('tag', 'mp')
- ),
- 'product_button_type' => 'addcart',
- 'show_quantity' => 1,
- 'product_img_size' => 'medium',
- 'show_lightbox' => 1,
- 'list_view' => 'grid',
- 'list_button_type' => 'addcart',
- 'show_thumbnail' => 1,
- 'list_img_size' => 'thumbnail',
- 'paginate' => 1,
- 'show_filters' => 1,
- 'order' => 'DESC',
- 'show_purchase_breadcrumbs' => 1,
- 'shipping' => array (
- 'allowed_countries' => array ('CA', 'US'),
- 'method' => 'flat-rate',
- 'system' => 'english'
- ),
- 'gateways' => array (
- 'paypal-express' => array (
- 'locale' => 'US',
- 'currency' => 'USD',
- 'mode' => 'sandbox'
- ),
- 'paypal-chained' => array (
- 'currency' => 'USD',
- 'mode' => 'sandbox'
- )
- ),
- 'msg' => array (
- 'product_list' => '',
- 'order_status' => __('<p>If you have any questions about your order please do not hesitate to contact us.</p>', 'mp'),
- 'cart' => '',
- 'shipping' => __('<p>Please enter your shipping information in the form below to proceed with your order.</p>', 'mp'),
- 'checkout' => '',
- 'confirm_checkout' => __('<p>You are almost done! Please do a final review of your order to make sure everything is correct then click the "Confirm Payment" button.</p>', 'mp'),
- 'success' => __('<p>Thank you for your order! We appreciate your business, and please come back often to check out our new products.</p>', 'mp')
- ),
- 'store_email' => get_option("admin_email"),
- 'email' => array (
- 'new_order_subject' => __('Your Order Confirmation (ORDERID)', 'mp'),
- 'new_order_txt' => __("Thank you for your order CUSTOMERNAME!
-
- Your order has been received, and any items to be shipped will be processed as soon as possible. Please refer to your Order ID (ORDERID) whenever contacting us.
- Here is a confirmation of your order details:
-
- Order Information:
- ORDERINFO
-
- Shipping Information:
- SHIPPINGINFO
-
- Payment Information:
- PAYMENTINFO
-
- ORDERNOTES
-
- You can track the latest status of your order here: TRACKINGURL
-
- Thanks again!", 'mp'),
- 'shipped_order_subject' => __('Your Order Has Been Shipped! (ORDERID)', 'mp'),
- 'shipped_order_txt' => __("Dear CUSTOMERNAME,
-
- Your order has been shipped! Depending on the shipping method and your location it should be arriving shortly. Please refer to your Order ID (ORDERID) whenever contacting us.
- Here is a confirmation of your order details:
-
- Order Information:
- ORDERINFO
-
- Shipping Information:
- SHIPPINGINFO
-
- Payment Information:
- PAYMENTINFO
-
- ORDERNOTES
-
- You can track the latest status of your order here: TRACKINGURL
-
- Thanks again!", 'mp')
- )
- );
-
- //filter default settings
- $default_settings = apply_filters( 'mp_default_settings', $default_settings );
- $settings = wp_parse_args( (array)$old_settings, $default_settings );
- update_option( 'mp_settings', $settings );
-
- //2.1.4 update
- if ( version_compare($old_version, '2.1.4', '<') )
- $this->update_214();
-
- //only run these on first install
- if ( empty($old_settings) ) {
-
- //define settings that don't need to autoload for efficiency
- add_option( 'mp_coupons', '', '', 'no' );
- add_option( 'mp_store_page', '', '', 'no' );
-
- //create store page
- add_action( 'admin_init', array(&$this, 'create_store_page') );
-
- //add cart widget to first sidebar
- add_action( 'widgets_init', array(&$this, 'add_default_widget'), 11 );
- }
-
- //add action to flush rewrite rules after we've added them for the first time
- update_option('mp_flush_rewrite', 1);
-
- update_option( 'mp_version', $this->version );
- }
-
- //run on 2.1.4 update to fix price sorts
- function update_214() {
- global $wpdb;
-
- $posts = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'product'");
-
- foreach ($posts as $post_id) {
- $meta = get_post_custom($post_id);
- //unserialize
- foreach ($meta as $key => $val) {
- $meta[$key] = maybe_unserialize($val[0]);
- if (!is_array($meta[$key]) && $key != "mp_is_sale" && $key != "mp_track_inventory" && $key != "mp_product_link" && $key != "mp_file" && $key != "mp_price_sort")
- $meta[$key] = array($meta[$key]);
- }
-
- //fix price sort field if missing
- if ( empty($meta["mp_price_sort"]) && is_array($meta["mp_price"]) ) {
- if ( $meta["mp_is_sale"] && $meta["mp_sale_price"][0] )
- $sort_price = $meta["mp_sale_price"][0];
- else
- $sort_price = $meta["mp_price"][0];
- update_post_meta($post_id, 'mp_price_sort', $sort_price);
- }
- }
- }
-
- function localization() {
- // Load up the localization file if we're using WordPress in a different language
- // Place it in this plugin's "languages" folder and name it "mp-[value in wp-config].mo"
- if ($this->location == 'mu-plugins')
- load_muplugin_textdomain( 'mp', '/marketpress-includes/languages/' );
- else if ($this->location == 'subfolder-plugins')
- load_plugin_textdomain( 'mp', false, '/marketpress/marketpress-includes/languages/' );
- else if ($this->location == 'plugins')
- load_plugin_textdomain( 'mp', false, '/marketpress-includes/languages/' );
-
- //setup language code for jquery datepicker translation
- $temp_locales = explode('_', get_locale());
- $this->language = ($temp_locales[0]) ? $temp_locales[0] : 'en';
- }
-
- function init_vars() {
- //setup proper directories
- if (defined('WP_PLUGIN_URL') && defined('WP_PLUGIN_DIR') && file_exists(WP_PLUGIN_DIR . '/marketpress/' . basename(__FILE__))) {
- $this->location = 'subfolder-plugins';
- $this->plugin_dir = WP_PLUGIN_DIR . '/marketpress/marketpress-includes/';
- $this->plugin_url = plugins_url( '/marketpress-includes/', __FILE__ );
- } else if (defined('WP_PLUGIN_URL') && defined('WP_PLUGIN_DIR') && file_exists(WP_PLUGIN_DIR . '/' . basename(__FILE__))) {
- $this->location = 'plugins';
- $this->plugin_dir = WP_PLUGIN_DIR . '/marketpress-includes/';
- $this->plugin_url = plugins_url( '/marketpress-includes/', __FILE__ );
- } else if (is_multisite() && defined('WPMU_PLUGIN_URL') && defined('WPMU_PLUGIN_DIR') && file_exists(WPMU_PLUGIN_DIR . '/' . basename(__FILE__))) {
- $this->location = 'mu-plugins';
- $this->plugin_dir = WPMU_PLUGIN_DIR . '/marketpress-includes/';
- $this->plugin_url = WPMU_PLUGIN_URL . '/marketpress-includes/';
- } else {
- wp_die(__('There was an issue determining where MarketPress is installed. Please reinstall.', 'mp'));
- }
-
- //load data structures
- require_once( $this->plugin_dir . 'marketpress-data.php' );
-
- }
-
- /* Only load code that needs BuddyPress to run once BP is loaded and initialized. */
- function load_bp_features() {
- include_once( $this->plugin_dir . 'marketpress-bp.php' );
- }
-
- function load_importers() {
- include_once( $this->plugin_dir . 'marketpress-importers.php' );
- }
-
- function load_plugins() {
- if (is_network_admin() || !$this->get_setting('disable_cart')) {
- //load shipping plugin API
- require_once( $this->plugin_dir . 'marketpress-shipping.php' );
- $this->load_shipping_plugins();
-
- //load gateway plugin API
- require_once( $this->plugin_dir . 'marketpress-gateways.php' );
- $this->load_gateway_plugins();
- }
- }
-
- function load_shipping_plugins() {
-
- //save shipping method. Put here to be before plugin is loaded
- if (isset($_POST['shipping_settings'])) {
- $settings = get_option('mp_settings');
- $settings['shipping']['method'] = $_POST['mp']['shipping']['method'];
- $settings['shipping']['calc_methods'] = isset($_POST['mp']['shipping']['calc_methods']) ? $_POST['mp']['shipping']['calc_methods'] : array();
- update_option('mp_settings', $settings);
- }
-
- //get shipping plugins dir
- $dir = $this->plugin_dir . 'plugins-shipping/';
-
- //search the dir for files
- $shipping_plugins = array();
- if ( !is_dir( $dir ) )
- return;
- if ( ! $dh = opendir( $dir ) )
- return;
- while ( ( $plugin = readdir( $dh ) ) !== false ) {
- if ( substr( $plugin, -4 ) == '.php' )
- $shipping_plugins[] = $dir . $plugin;
- }
- closedir( $dh );
- sort( $shipping_plugins );
-
- //include them suppressing errors
- foreach ($shipping_plugins as $file)
- @include_once( $file );
-
- //allow plugins from an external location to register themselves
- do_action('mp_load_shipping_plugins');
-
- //load chosen plugin class
- global $mp_shipping_plugins, $mp_shipping_active_plugins;
- $shipping = $this->get_setting('shipping');
-
- if ($this->get_setting('shipping->method') == 'calculated') {
- //load just the calculated ones
- foreach ((array)$mp_shipping_plugins as $code => $plugin) {
- if ($plugin[2]) {
- if ( isset($shipping['calc_methods'][$code]) && class_exists($plugin[0]) && !$plugin[3] )
- $mp_shipping_active_plugins[$code] = new $plugin[0];
- }
- }
- } else {
- //load only and all calculated ones
- $class = $mp_shipping_plugins[$shipping['method']][0];
- if (class_exists($class))
- $mp_shipping_active_plugins[$shipping['method']] = new $class;
- }
- }
-
- function load_gateway_plugins() {
-
- //save settings from screen. Put here to be before plugin is loaded
- if (isset($_POST['gateway_settings'])) {
- $settings = get_option('mp_settings');
-
- //see if there are checkboxes checked
- if ( isset( $_POST['mp']['gateways']['allowed'] ) ) {
- $settings['gateways']['allowed'] = $_POST['mp']['gateways']['allowed'];
- } else {
- //blank array if no checkboxes
- $settings['gateways']['allowed'] = array();
- }
-
- update_option('mp_settings', $settings);
- }
-
- //get gateway plugins dir
- $dir = $this->plugin_dir . 'plugins-gateway/';
-
- //search the dir for files
- $gateway_plugins = array();
- if ( !is_dir( $dir ) )
- return;
- if ( ! $dh = opendir( $dir ) )
- return;
- while ( ( $plugin = readdir( $dh ) ) !== false ) {
- if ( substr( $plugin, -4 ) == '.php' )
- $gateway_plugins[] = $dir . '/' . $plugin;
- }
- closedir( $dh );
- sort( $gateway_plugins );
-
- //include them suppressing errors
- foreach ($gateway_plugins as $file)
- include( $file );
-
- //allow plugins from an external location to register themselves
- do_action('mp_load_gateway_plugins');
-
- //load chosen plugin classes
- global $mp_gateway_plugins, $mp_gateway_active_plugins;
- $gateways = $this->get_setting('gateways');
- $network_settings = get_site_option( 'mp_network_settings' );
-
- foreach ((array)$mp_gateway_plugins as $code => $plugin) {
- $class = $plugin[0];
- //if global cart is enabled force it
- if ( $this->global_cart ) {
- if ( $code == $network_settings['global_gateway'] && class_exists($class) ) {
- $mp_gateway_active_plugins[] = new $class;
- break;
- }
- } else {
- if ( isset( $gateways['allowed'] ) && in_array($code, (array)$gateways['allowed']) && class_exists($class) && !$plugin[3] )
- $mp_gateway_active_plugins[] = new $class;
- }
- }
- }
-
- /*
- * function get_setting
- * @param string $key A setting key, or -> separated list of keys to go multiple levels into an array
- * @param mixed $default Returns when setting is not set
- *
- * an easy way to get to our settings array without undefined indexes
- */
- function get_setting($key, $default = null) {
- $settings = get_option( 'mp_settings' );
- $keys = explode('->', $key);
- array_map('trim', $keys);
- if (count($keys) == 1)
- $setting = isset($settings[$keys[0]]) ? $settings[$keys[0]] : $default;
- else if (count($keys) == 2)
- $setting = isset($settings[$keys[0]][$keys[1]]) ? $settings[$keys[0]][$keys[1]] : $default;
- else if (count($keys) == 3)
- $setting = isset($settings[$keys[0]][$keys[1]][$keys[2]]) ? $settings[$keys[0]][$keys[1]][$keys[2]] : $default;
- else if (count($keys) == 4)
- $setting = isset($settings[$keys[0]][$keys[1]][$keys[2]][$keys[3]]) ? $settings[$keys[0]][$keys[1]][$keys[2]][$keys[3]] : $default;
-
- return apply_filters( "mp_setting_".implode('', $keys), $setting, $default );
- }
-
- function update_setting($key, $value) {
- $settings = get_option( 'mp_settings' );
- $settings[$key] = $value;
- return update_option('mp_settings', $settings);
- }
-
- function handle_gateway_returns($wp_query) {
- if ( is_admin() ) return;
-
- //listen for gateway IPN returns and tie them in to proper gateway plugin
- if(!empty($wp_query->query_vars['paymentgateway'])) {
- do_action( 'mp_handle_payment_return_' . $wp_query->query_vars['paymentgateway'] );
- // exit();
- }
- }
-
- function remove_canonical($wp_query) {
- if ( is_admin() ) return;
-
- //stop canonical problems with virtual pages redirecting
- $page = get_query_var('pagename');
- if ($page == 'cart' || $page == 'orderstatus' || $page == 'product_list') {
- remove_action('template_redirect', 'redirect_canonical');
- }
- }
-
- function admin_nopermalink_warning() {
- //warns admins if permalinks are not enabled on the blog
- if ( current_user_can('manage_options') && !get_option('permalink_structure') )
- echo '<div class="error"><p>'.__('You must enable Pretty Permalinks</a> to use MarketPress - <a href="options-permalink.php">Enable now »</a>', 'mp').'</p></div>';
- }
-
- function plugin_action_link($links, $file) {
- // the anchor tag and href to the URL we want. For a "Settings" link, this needs to be the url of your settings page
- $settings_link = '<a href="' . admin_url('edit.php?post_type=product&page=marketpress') . '">' . __('Settings', 'mp') . '</a>';
- // add the link to the list
- array_unshift($links, $settings_link);
- return $links;
- }
-
- function add_menu_items() {
- //only process the manage orders page for editors and above and if orders hasn't been disabled
- if (current_user_can('edit_others_posts') && !$this->get_setting('disable_cart')) {
- $num_posts = wp_count_posts('mp_order'); //get pending order count
- $count = $num_posts->order_received + $num_posts->order_paid;
- if ( $count > 0 )
- $count_output = ' <span class="update-plugins"><span class="updates-count count-' . $count . '">' . $count . '</span></span>';
- else
- $count_output = '';
- $orders_page = add_submenu_page('edit.php?post_type=product', __('Manage Orders', 'mp'), __('Manage Orders', 'mp') . $count_output, 'edit_others_posts', 'marketpress-orders', array(&$this, 'orders_page'));
- }
-
- $page = add_submenu_page('edit.php?post_type=product', __('Store Settings', 'mp'), __('Store Settings', 'mp'), 'manage_options', 'marketpress', array(&$this, 'admin_page'));
- add_action( 'admin_print_scripts-' . $page, array(&$this, 'admin_script_settings') );
- add_action( 'admin_print_styles-' . $page, array(&$this, 'admin_css_settings') );
-
- add_action( "load-{$page}", array( &$this, 'add_help_tab' ) );
- }
-
- function add_help_tab() {
- get_current_screen()->add_help_tab( array(
- 'id' => 'marketpress-help',
- 'title' => 'MarketPress Instructions',
- 'content' => '<iframe src="http://premium.wpmudev.org/wdp-un.php?action=help&id=144" width="100%" height="600px"></iframe>'
- ) );
- }
-
- function admin_css() {
- wp_enqueue_style( 'mp-admin-css', $this->plugin_url . 'css/marketpress.css', false, $this->version);
- }
-
- //enqeue js on custom post edit screen
- function admin_script_post() {
- global $current_screen;
- if ($current_screen->id == 'product')
- wp_enqueue_script( 'mp-post', $this->plugin_url . 'js/post-screen.js', array('jquery'), $this->version);
- }
-
- //enqeue css on product settings screen
- function admin_css_settings() {
- wp_enqueue_style( 'jquery-datepicker-css', $this->plugin_url . 'datepicker/css/ui-lightness/datepicker.css', false, $this->version);
- wp_enqueue_style( 'jquery-colorpicker-css', $this->plugin_url . 'colorpicker/css/colorpicker.css', false, $this->version);
- }
-
- //enqeue js on product settings screen
- function admin_script_settings() {
- wp_enqueue_script( 'jquery-colorpicker', $this->plugin_url . 'colorpicker/js/colorpicker.js', array('jquery'), $this->version);
- wp_enqueue_script( 'jquery-datepicker', $this->plugin_url . 'datepicker/js/datepicker.min.js', array('jquery', 'jquery-ui-core'), $this->version);
-
- //only load languages for datepicker if not english (or it will show Chinese!)
- if ($this->language != 'en')
- wp_enqueue_script( 'jquery-datepicker-i18n', $this->plugin_url . 'datepicker/js/datepicker-i18n.min.js', array('jquery', 'jquery-ui-core', 'jquery-datepicker'), $this->version);
-
- if (intval($this->get_setting('hide_popup')) < 3) {
- wp_enqueue_script( 'mp-need-help', $this->plugin_url . 'js/need-help.js', array('jquery'), $this->version);
- $new_count = intval($this->get_setting('hide_popup')) + 1;
- $this->update_setting('hide_popup', $new_count);
- }
- }
-
- //ties into the ajax request to disable help popup if clicked
- function hide_help() {
- $this->update_setting('hide_popup', 3);
- }
-
- //ajax cart handling for store frontend
- function store_script() {
- //setup ajax cart javascript
- wp_enqueue_script( 'mp-ajax-js', $this->plugin_url . 'js/ajax-cart.js', array('jquery'), $this->version );
-
- // declare the variables we need to access in js
- wp_localize_script( 'mp-ajax-js', 'MP_Ajax', array( 'ajaxUrl' => admin_url( 'admin-ajax.php', (is_ssl() ? 'https': 'http') ), 'emptyCartMsg' => __('Are you sure you want to remove all items from your cart?', 'mp'), 'successMsg' => __('Item(s) Added!', 'mp'), 'imgUrl' => $this->plugin_url.'images/loading.gif', 'addingMsg' => __('Adding to your cart...', 'mp'), 'outMsg' => __('In Your Cart', 'mp'), 'show_filters' => $this->get_setting('show_filters') ) );
- }
-
- //loads the jquery lightbox plugin
- function enqueue_lightbox() {
- if ( !$this->get_setting('show_lightbox') )
- return;
-
- wp_enqueue_style( 'jquery-lightbox', $this->plugin_url . 'lightbox/style/lumebox.css', false, $this->version );
- wp_enqueue_script( 'jquery-lightbox', $this->plugin_url . 'lightbox/js/jquery.lumebox.min.js', array('jquery'), $this->version, true );
-
- // declare the variables we need to access in js
- $js_vars = array( 'graphicsDir' => $this->plugin_url . 'lightbox/style/' );
- wp_localize_script( 'jquery-lightbox', 'lumeboxOptions', $js_vars );
- }
-
- //if cart widget is not in a sidebar, add it to the top of the first sidebar. Only runs at initial install
- function add_default_widget() {
- if (!is_active_widget(false, false, 'mp_cart_widget')) {
- $sidebars_widgets = wp_get_sidebars_widgets();
- if ( is_array($sidebars_widgets) ) {
- foreach ( $sidebars_widgets as $sidebar => $widgets ) {
- if ( 'wp_inactive_widgets' == $sidebar )
- continue;
-
- if ( is_array($widgets) ) {
- array_unshift($widgets, 'mp_cart_widget-1');
- $sidebars_widgets[$sidebar] = $widgets;
- wp_set_sidebars_widgets( $sidebars_widgets );
- $settings = array();
- $settings[1] = array( 'title' => __('Shopping Cart', 'mp'), 'custom_text' => '', 'show_thumbnail' => 1, 'size' => 25 );
- $settings['_multiwidget'] = 1;
- update_option( 'widget_mp_cart_widget', $settings );
- return true;
- }
- }
- }
- }
- }
-
- //creates the store page on install and updates
- function create_store_page($old_slug = false) {
- global $wpdb;
-
- //remove old page if updating
- if ($old_slug && $old_slug != $this->get_setting('slugs->store')) {
- $old_post_id = $wpdb->get_var("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = '$old_slug' AND post_type = 'page'");
- $old_post = get_post($old_post_id);
-
- $old_post->post_name = $this->get_setting('slugs->store');
- wp_update_post($old_post);
- }
-
- //insert new page if not existing
- $page_count = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->posts . " WHERE post_name = '" . $this->get_setting('slugs->store') . "' AND post_type = 'page'");
- if ( !$page_count ) {
-
- //default page content
- $content = '<p>' . __('Welcome to our online store! Feel free to browse around:', 'mp') . '</p>';
- $content .= '[mp_store_navigation]';
- $content .= '<p>' . __('Check out our most popular products:', 'mp') . '</p>';
- $content .= '[mp_popular_products]';
- $content .= '<p>' . __('Browse by category:', 'mp') . '</p>';
- $content .= '[mp_list_categories]';
- $content .= '<p>' . __('Browse by tag:', 'mp') . '</p>';
- $content .= '[mp_tag_cloud]';
-
- $id = wp_insert_post( array('post_title' => __('Store', 'mp'), 'post_name' => $this->get_setting('slugs->store'), 'post_status' => 'publish', 'post_type' => 'page', 'post_content' => $content ) );
- update_option('mp_store_page', $id);
- }
- }
-
- function register_custom_posts() {
- ob_start();
-
- // Register custom taxonomy
- register_taxonomy( 'product_category', 'product', apply_filters( 'mp_register_product_category', array("hierarchical" => true, 'label' => __('Product Categories', 'mp'), 'singular_label' => __('Product Category', 'mp'), 'rewrite' => array('slug' => $this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->products') . '/' . $this->get_setting('slugs->category'))) ) );
- register_taxonomy( 'product_tag', 'product', apply_filters( 'mp_register_product_tag', array("hierarchical" => false, 'label' => __('Product Tags', 'mp'), 'singular_label' => __('Product Tag', 'mp'), 'rewrite' => array('slug' => $this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->products') . '/' . $this->get_setting('slugs->tag'))) ) );
-
- // Register custom product post type
- $supports = array( 'title', 'editor', 'author', 'excerpt', 'revisions', 'thumbnail' );
- $args = array (
- 'labels' => array('name' => __('Products', 'mp'),
- 'singular_name' => __('Product', 'mp'),
- 'add_new' => __('Create New', 'mp'),
- 'add_new_item' => __('Create New Product', 'mp'),
- 'edit_item' => __('Edit Products', 'mp'),
- 'edit' => __('Edit', 'mp'),
- 'new_item' => __('New Product', 'mp'),
- 'view_item' => __('View Product', 'mp'),
- 'search_items' => __('Search Products', 'mp'),
- 'not_found' => __('No Products Found', 'mp'),
- 'not_found_in_trash' => __('No Products found in Trash', 'mp'),
- 'view' => __('View Product', 'mp')
- ),
- 'description' => __('Products for your MarketPress store.', 'mp'),
- 'menu_icon' => $this->plugin_url . 'images/marketpress-icon.png',
- 'public' => true,
- 'show_ui' => true,
- 'publicly_queryable' => true,
- 'capability_type' => 'page',
- 'hierarchical' => false,
- 'rewrite' => array('slug' => $this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->products'), 'with_front' => false), // Permalinks format
- 'query_var' => true,
- 'supports' => $supports
- );
- register_post_type( 'product' , apply_filters( 'mp_register_post_type', $args ) );
-
- //register the orders post type
- register_post_type( 'mp_order', array(
- 'labels' => array('name' => __('Orders', 'mp'),
- 'singular_name' => __('Order', 'mp'),
- 'edit' => __('Edit', 'mp'),
- 'view_item' => __('View Order', 'mp'),
- 'search_items' => __('Search Orders', 'mp'),
- 'not_found' => __('No Orders Found', 'mp')
- ),
- 'description' => __('Orders from your MarketPress store.', 'mp'),
- 'public' => false,
- 'show_ui' => false,
- 'capability_type' => apply_filters( 'mp_orders_capability', 'page' ),
- 'hierarchical' => false,
- 'rewrite' => false,
- 'query_var' => false,
- 'supports' => array()
- ) );
-
- //register custom post statuses for our orders
- register_post_status( 'order_received', array(
- 'label' => __('Received', 'mp'),
- 'label_count' => array( __('Received <span class="count">(%s)</span>', 'mp'), __('Received <span class="count">(%s)</span>', 'mp') ),
- 'post_type' => 'mp_order',
- 'public' => false
- ) );
- register_post_status( 'order_paid', array(
- 'label' => __('Paid', 'mp'),
- 'label_count' => array( __('Paid <span class="count">(%s)</span>', 'mp'), __('Paid <span class="count">(%s)</span>', 'mp') ),
- 'post_type' => 'mp_order',
- 'public' => false
- ) );
- register_post_status( 'order_shipped', array(
- 'label' => __('Shipped', 'mp'),
- 'label_count' => array( __('Shipped <span class="count">(%s)</span>', 'mp'), __('Shipped <span class="count">(%s)</span>', 'mp') ),
- 'post_type' => 'mp_order',
- 'public' => false
- ) );
- register_post_status( 'order_closed', array(
- 'label' => __('Closed', 'mp'),
- 'label_count' => array( __('Closed <span class="count">(%s)</span>', 'mp'), __('Closed <span class="count">(%s)</span>', 'mp') ),
- 'post_type' => 'mp_order',
- 'public' => false
- ) );
- register_post_status( 'trash', array(
- 'label' => _x( 'Trash', 'post' ),
- 'label_count' => _n_noop( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>' ),
- 'show_in_admin_status_list' => true,
- 'post_type' => 'mp_order',
- 'public' => false
- ) );
- }
-
- //necessary to mod array directly rather than with add_theme_support() to play nice with other themes. See http://www.wptavern.com/forum/plugins-hacks/1751-need-help-enabling-post-thumbnails-custom-post-type.html
- function post_thumbnails() {
- global $_wp_theme_features;
-
- if( !isset( $_wp_theme_features['post-thumbnails'] ) )
- $_wp_theme_features['post-thumbnails'] = array( array( 'product' ) );
- else if ( is_array( $_wp_theme_features['post-thumbnails'] ) )
- $_wp_theme_features['post-thumbnails'][0][] = 'product';
- }
-
- // This function clears the rewrite rules and forces them to be regenerated
- function flush_rewrite_check() {
- if ( get_option('mp_flush_rewrite') ) {
- flush_rewrite_rules();
- delete_option('mp_flush_rewrite');
- }
- }
-
- function add_rewrite_rules($rules) {
- $new_rules = array();
-
- //product list
- $new_rules[$this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->products') . '/?$'] = 'index.php?pagename=product_list';
- $new_rules[$this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->products') . '/page/?([0-9]{1,})/?$'] = 'index.php?pagename=product_list&paged=$matches[1]';
-
- //checkout page
- $new_rules[$this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->cart') . '/?$'] = 'index.php?pagename=cart';
- $new_rules[$this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->cart') . '/([^/]+)/?$'] = 'index.php?pagename=cart&checkoutstep=$matches[1]';
-
- //order status page
- $new_rules[$this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->orderstatus') . '/?$'] = 'index.php?pagename=orderstatus';
- $new_rules[$this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->orderstatus') . '/([^/]+)/?$'] = 'index.php?pagename=orderstatus&order_id=$matches[1]';
-
- //ipn handling for payment gateways
- $new_rules[$this->get_setting('slugs->store') . '/payment-return/(.+)'] = 'index.php?paymentgateway=$matches[1]';
-
- return array_merge($new_rules, $rules);
- }
-
- //unfortunately some plugins flush rewrites before the init hook so they kill custom post type rewrites. This function verifies they are in the final array and flushes if not
- function check_rewrite_rules($value) {
-
- //prevent an infinite loop by only
- if ( ! post_type_exists( 'product' ) )
- return $value;
-
- if ( is_array($value) && !in_array('index.php?product=$matches[1]&paged=$matches[2]', $value) ) {
- flush_rewrite_rules();
- } else {
- return $value;
- }
- }
-
- function add_queryvars($vars) {
- // This function add the checkout queryvars to the list that WordPress is looking for.
- if(!in_array('checkoutstep', $vars))
- $vars[] = 'checkoutstep';
-
- if(!in_array('order_id', $vars))
- $vars[] = 'order_id';
-
- if(!in_array('paymentgateway', $vars))
- $vars[] = 'paymentgateway';
-
- return $vars;
- }
-
- function start_session() {
- //start the sessions for cart handling
- if (session_id() == "")
- session_start();
- }
-
- function logout_clear_session() {
- $this->start_session();
-
- //clear personal info
- unset($_SESSION['mp_shipping_info']);
- unset($_SESSION['mp_billing_info']);
-
- //remove coupon code
- if (is_multisite()) {
- global $blog_id;
- unset($_SESSION['mp_cart_coupon_' . $blog_id]);
- } else {
- unset($_SESSION['mp_cart_coupon']);
- }
- }
-
- //scans post type at template_redirect to apply custom themeing to products
- function load_store_templates() {
- global $wp_query, $mp_wpmu, $mp_gateway_active_plugins;
-
- //only filter public side
- if (is_admin()) return;
-
- //load proper theme for single product page display
- if ($wp_query->is_single && $wp_query->query_vars['post_type'] == 'product') {
-
- //check for custom theme templates
- $product_name = get_query_var('product');
- $product_id = (int) $wp_query->get_queried_object_id();
-
- //serve download if it exists
- $this->serve_download($product_id);
-
- $templates = array();
- if ( $product_name )
- $templates[] = "mp_product-$product_name.php";
- if ( $product_id )
- $templates[] = "mp_product-$product_id.php";
- $templates[] = "mp_product.php";
-
- //if custom template exists load it
- if ($this->product_template = locate_template($templates)) {
- add_filter( 'template_include', array(&$this, 'custom_product_template') );
- } else {
- //otherwise load the page template and use our own theme
- $wp_query->is_single = null;
- $wp_query->is_page = 1;
- add_filter( 'the_content', array(&$this, 'product_theme'), 99 );
-
- //genesis fixes
- remove_action( 'genesis_post_content', 'genesis_do_post_image' );
- remove_action( 'genesis_post_content', 'genesis_do_post_content' );
- add_action('genesis_post_content', 'the_content');
- }
-
- $this->is_shop_page = true;
-
- //enqueue lightbox on single product page
- $this->enqueue_lightbox();
-
- }
-
- //load proper theme for main store page
- $slugs = $this->get_setting('slugs');
- if ($wp_query->query_vars['pagename'] == $this->get_setting('slugs->store')) {
-
- //check for custom theme template
- $templates = array("mp_store.php");
-
- //if custom template exists load it
- if ($this->store_template = locate_template($templates)) {
- add_filter( 'template_include', array(&$this, 'custom_store_template') );
- } else {
- //otherwise load the page template and use our own theme
- add_filter( 'the_content', array(&$this, 'store_theme'), 99 );
- }
-
- $this->is_shop_page = true;
- }
-
- //load proper theme for checkout page
- if ($wp_query->query_vars['pagename'] == 'cart') {
-
- //init session for store pages
- $this->start_session();
-
- //process cart updates
- $this->update_cart();
-
- //if global cart is on forward to main site checkout
- if ( $this->global_cart && is_object($mp_wpmu) && !$mp_wpmu->is_main_site() ) {
- wp_redirect( mp_cart_link(false, true) );
- exit;
- }
-
- // Redirect to https if forced to use SSL by a payment gateway
- if (get_query_var('checkoutstep')) {
- foreach ((array)$mp_gateway_active_plugins as $plugin) {
- if ($plugin->force_ssl) {
- if ( !is_ssl() ) {
- wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
- exit();
- }
- }
- }
- }
-
- //force login if required
- if (!is_user_logged_in() && $this->get_setting('force_login') && get_query_var('checkoutstep')) {
- wp_redirect( wp_login_url( mp_checkout_step_url( get_query_var('checkoutstep') ) ) );
- exit();
- }
-
- //setup shopping cart javascript
- wp_enqueue_script( 'mp-store-js', $this->plugin_url . 'js/store.js', array('jquery'), $this->version );
-
- //check for custom theme template
- $templates = array("mp_cart.php");
-
- //if custom template exists load it
- if ($this->checkout_template = locate_template($templates)) {
- add_filter( 'template_include', array(&$this, 'custom_checkout_template') );
- add_filter( 'single_post_title', array(&$this, 'page_title_output'), 99 );
- add_filter( 'bp_page_title', array(&$this, 'page_title_output'), 99 );
- add_filter( 'wp_title', array(&$this, 'wp_title_output'), 19, 3 );
- } else {
- //otherwise load the page template and use our own theme
- add_filter( 'single_post_title', array(&$this, 'page_title_output'), 99 );
- add_filter( 'the_title', array(&$this, 'page_title_output'), 99 );
- add_filter( 'bp_page_title', array(&$this, 'page_title_output'), 99 );
- add_filter( 'wp_title', array(&$this, 'wp_title_output'), 19, 3 );
- add_filter( 'the_content', array(&$this, 'checkout_theme'), 99 );
- }
-
- $wp_query->is_page = 1;
- $wp_query->is_singular = 1;
- $wp_query->is_404 = null;
- $wp_query->post_count = 1;
-
- $this->is_shop_page = true;
- }
-
- //load proper theme for order status page
- if ($wp_query->query_vars['pagename'] == 'orderstatus') {
-
- //check for custom theme template
- $templates = array("mp_orderstatus.php");
-
- //if custom template exists load it
- if ($this->orderstatus_template = locate_template($templates)) {
- add_filter( 'template_include', array(&$this, 'custom_orderstatus_template') );
- add_filter( 'single_post_title', array(&$this, 'page_title_output'), 99 );
- add_filter( 'bp_page_title', array(&$this, 'page_title_output'), 99 );
- add_filter( 'wp_title', array(&$this, 'wp_title_output'), 19, 3 );
- } else {
- //otherwise load the page template and use our own theme
- add_filter( 'single_post_title', array(&$this, 'page_title_output'), 99 );
- add_filter( 'the_title', array(&$this, 'page_title_output'), 99 );
- add_filter( 'bp_page_title', array(&$this, 'page_title_output'), 99 );
- add_filter( 'wp_title', array(&$this, 'wp_title_output'), 19, 3 );
- add_filter( 'the_content', array(&$this, 'orderstatus_theme'), 99 );
- }
-
- $wp_query->is_page = 1;
- $wp_query->is_singular = 1;
- $wp_query->is_404 = null;
- $wp_query->post_count = 1;
-
- $this->is_shop_page = true;
- }
-
- //load proper theme for product listings
- if ($wp_query->query_vars['pagename'] == 'product_list') {
-
- //check for custom theme template
- $templates = array("mp_productlist.php");
-
- //if custom template exists load it
- if ($this->product_list_template = locate_template($templates)) {
-
- //call a custom query posts for this listing
- //setup pagination
- if ($this->get_setting('paginate')) {
- //figure out perpage
- $paginate_query = '&posts_per_page='.$this->get_setting('per_page');
-
- //figure out page
- if ($wp_query->query_vars['paged'])
- $paginate_query .= '&paged='.intval($wp_query->query_vars['paged']);
- } else {
- $paginate_query = '&nopaging=true';
- }
-
- //get order by
- if ($this->get_setting('order_by') == 'price')
- $order_by_query = '&meta_key=mp_price&orderby=mp_price';
- else if ($this->get_setting('order_by') == 'sales')
- $order_by_query = '&meta_key=mp_sales_count&orderby=mp_sales_count';
- else
- $order_by_query = '&orderby='.$this->get_setting('order_by');
-
- //get order direction
- $order_query = '&order='.$this->get_setting('order');
-
- //The Query
- query_posts('post_type=product' . $paginate_query . $order_by_query . $order_query);
-
- add_filter( 'template_include', array(&$this, 'custom_product_list_template') );
- add_filter( 'single_post_title', array(&$this, 'page_title_output'), 99 );
- add_filter( 'bp_page_title', array(&$this, 'page_title_output'), 99 );
- add_filter( 'wp_title', array(&$this, 'wp_title_output'), 19, 3 );
- } else {
- //otherwise load the page template and use our own theme
- add_filter( 'single_post_title', array(&$this, 'page_title_output'), 99 );
- add_filter( 'the_title', array(&$this, 'page_title_output'), 99 );
- add_filter( 'bp_page_title', array(&$this, 'page_title_output'), 99 );
- add_filter( 'wp_title', array(&$this, 'wp_title_output'), 19, 3 );
- add_filter( 'the_content', array(&$this, 'product_list_theme'), 99 );
- add_filter( 'the_excerpt', array(&$this, 'product_list_theme'), 99 );
-
- //genesis fixes
- remove_action( 'genesis_post_content', 'genesis_do_post_image' );
- remove_action( 'genesis_post_content', 'genesis_do_post_content' );
- add_action('genesis_post_content', 'the_content');
- }
-
- $wp_query->is_page = 1;
- //$wp_query->is_singular = 1;
- $wp_query->is_404 = null;
- $wp_query->post_count = 1;
-
- $this->is_shop_page = true;
- }
-
- //load proper theme for product category or tag listings
- if ( isset( $wp_query->query_vars['taxonomy'] ) && ( $wp_query->query_vars['taxonomy'] == 'product_category' || $wp_query->query_vars['taxonomy'] == 'product_tag' ) ) {
- $templates = array();
-
- if ($wp_query->query_vars['taxonomy'] == 'product_category') {
-
- $cat_name = get_query_var('product_category');
- $cat_id = absint( $wp_query->get_queried_object_id() );
- if ( $cat_name )
- $templates[] = "mp_category-$cat_name.php";
- if ( $cat_id )
- $templates[] = "mp_category-$cat_id.php";
- $templates[] = "mp_category.php";
-
- } else if ($wp_query->query_vars['taxonomy'] == 'product_tag') {
-
- $tag_name = get_query_var('product_tag');
- $tag_id = absint( $wp_query->get_queried_object_id() );
- if ( $tag_name )
- $templates[] = "mp_tag-$tag_name.php";
- if ( $tag_id )
- $templates[] = "mp_tag-$tag_id.php";
- $templates[] = "mp_tag.php";
-
- }
-
- //defaults
- $templates[] = "mp_taxonomy.php";
- $templates[] = "mp_productlist.php";
-
- if ( !is_admin() && isset($_GET['product_category']) && is_numeric($_GET['product_category']) ) {
- $link = get_term_link( (int)get_query_var($wp_query->query_vars['taxonomy']), $wp_query->query_vars['taxonomy'] );
- wp_redirect($link);
- exit;
- }
-
- //if custom template exists load it
- if ($this->product_taxonomy_template = locate_template($templates)) {
-
- //call a custom query posts for this listing
- $taxonomy_query = '&' . $wp_query->query_vars['taxonomy'] . '=' . get_query_var($wp_query->query_vars['taxonomy']);
-
- //setup pagination
- if ($this->get_setting('paginate')) {
- //figure out perpage
- $paginate_query = '&posts_per_page='.$this->get_setting('per_page');
-
- //figure out page
- if ($wp_query->query_vars['paged'])
- $paginate_query .= '&paged='.intval($wp_query->query_vars['paged']);
- } else {
- $paginate_query = '&nopaging=true';
- }
-
- //get order by
- if ($this->get_setting('order_by') == 'price')
- $order_by_query = '&meta_key=mp_price&orderby=mp_price';
- else if ($this->get_setting('order_by') == 'sales')
- $order_by_query = '&meta_key=mp_sales_count&orderby=mp_sales_count';
- else
- $order_by_query = '&orderby='.$this->get_setting('order_by');
-
- //get order direction
- $order_query = '&order='.$this->get_setting('order');
-
- //The Query
- query_posts('post_type=product' . $taxonomy_query . $paginate_query . $order_by_query . $order_query);
-
- add_filter( 'template_include', array(&$this, 'custom_product_taxonomy_template'));
- add_filter( 'single_post_title', array(&$this, 'page_title_output'), 99 );
- add_filter( 'bp_page_title', array(&$this, 'page_title_output'), 99 );
- add_filter( 'wp_title', array(&$this, 'wp_title_output'), 19, 3 );
- } else {
- //otherwise load the page template and use our own list theme. We don't use theme's taxonomy as not enough control
- $wp_query->is_page = 1;
- //$wp_query->is_singular = 1;
- $wp_query->is_404 = n…
Large files files are truncated, but you can click here to view the full file