/**
  * Manages CSS relationship classes applied to Shopp elements appearing in a WordPress navigation menu
  *
  * @author Jonathan Davis
  * @since 1.2
  *
  * @param array $menuitems The provided WordPress menu items
  * @return array Updated menu items with proper relationship classes
  **/
 public function menus($menuitems)
 {
     $is_shopp_page = is_shopp_page();
     $keymap = array();
     $parents = array();
     foreach ($menuitems as $key => $item) {
         $page = false;
         // Remove the faulty wp_page_menu (deprecated) class for Shopp pages
         if ($is_shopp_page && in_array('current_page_parent', $item->classes)) {
             unset($item->classes[array_search('current_page_parent', $item->classes)]);
         }
         // Otherwise, skip dealing with any non-Shopp page
         if (ShoppPages::QUERYVAR == $item->type) {
             // Determine the queried Shopp page object name
             $Page = ShoppPages()->requested();
             if ($Page && !is_shopp_collection()) {
                 $page = $Page->name();
             }
             // Set the catalog as current page parent
             if ('catalog' == $item->object && ($is_shopp_page || is_shopp_product())) {
                 $item->classes[] = 'current-page-parent';
             }
             $keymap[$item->db_id] = $key;
         }
         if ('shopp_collection' == $item->type) {
             $page = get_query_var($item->type);
             $keymap[$item->db_id] = $key;
         }
         if ($page == $item->object) {
             $item->classes[] = 'current-page-item';
             $item->classes[] = 'current-menu-item';
             $parents[] = $item->menu_item_parent;
         }
     }
     foreach ((array) $parents as $parentid) {
         if (!isset($keymap[$parentid])) {
             continue;
         }
         $parent = $menuitems[$keymap[$parentid]];
         $parent->classes[] = 'current-menu-parent';
         $parent->classes[] = 'current-page-parent';
         $parent->classes[] = 'current-menu-ancestor';
         $parent->classes[] = 'current-page-ancestor';
         $ancestor = $parent;
         while (0 != $ancestor->menu_item_parent) {
             $ancestor = $menuitems[$keymap[$ancestor->menu_item_parent]];
             $ancestor->classes[] = 'current-menu-ancestor';
             $ancestor->classes[] = 'current-page-ancestor';
         }
     }
     return $menuitems;
 }
Exemple #2
0
 public function content($content)
 {
     global $wp_query;
     // Test that this is the main query and it is a product
     if (!$wp_query->is_main_query() || !is_shopp_product()) {
         return $content;
     }
     $Product = ShoppProduct();
     $templates = array('product.php');
     if (isset($Product->id) && !empty($Product->id)) {
         array_unshift($templates, 'product-' . $Product->id . '.php');
     }
     if (isset($Product->slug) && !empty($Product->slug)) {
         array_unshift($templates, 'product-' . $Product->slug . '.php');
     }
     // Load product summary data, before checking inventory
     if (!isset($Product->summed)) {
         $Product->load_data(array('summary'));
     }
     if (Shopp::str_true($Product->inventory) && $Product->stock < 1) {
         array_unshift($templates, 'product-outofstock.php');
     }
     ob_start();
     locate_shopp_template($templates, true);
     $content = ob_get_contents();
     ob_end_clean();
     return ShoppStorefront::wrapper($content);
 }
Exemple #3
0
/**
 * Determines if the current request is for a single Shopp product
 *
 * @api
 * @since 1.3
 *
 * @param WP_Query $wp_query (optional) will use the global wp_query by default if false, or the WP_Query object to evaluation
 * @return boolean
 **/
function is_single_product($wp_query = false)
{
    if (false === $wp_query) {
        global $wp_the_query;
        $wp_query =& $wp_the_query;
    }
    return is_shopp_product($wp_query) && $wp_query->is_single();
}
Exemple #4
0
 /**
  * Checks if the current page is a product page
  *
  * @api `shopp('storefront.is-product')`
  * @since 1.1
  *
  * @param string          $result  The output
  * @param array           $options The options
  * @param ShoppStorefront $O       The working object
  * @return bool True if it is the product page, false otherwise
  **/
 public static function is_product($result, $options, $O)
 {
     return is_shopp_product();
 }