Пример #1
1
 /**
  *	Function called on plugin initialisation allowing to declare the new types needed by our plugin
  *	@see wpshop_products::create_wpshop_products_type();
  *	@see wpshop_categories::create_product_categories();
  */
 public static function add_new_wp_type()
 {
     $wpshop_shop_type = get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE);
     /*	Creation du type d'element Entité pour wpshop	*/
     wpshop_entities::create_wpshop_entities_type();
     add_action('add_meta_boxes', array('wpshop_entities', 'add_meta_boxes'));
     add_action('save_post', array('wpshop_entities', 'save_entity_type_custom_informations'));
     add_filter('manage_posts_columns', array('wpshop_entities', 'custom_columns_header'), 10, 2);
     add_filter('manage_posts_custom_column', array('wpshop_entities', 'custom_columns_content'), 10, 2);
     // 			add_action('quick_edit_custom_box', array('wpshop_attributes', 'quick_edit'), 10, 2);
     add_action('bulk_edit_custom_box', array('wpshop_attributes', 'bulk_edit'), 10, 2);
     /*	Creation des types personnalisé à partir des entités créées	*/
     wpshop_entities::create_wpshop_entities_custom_type();
     /*	Add wpshop product type and add a new meta_bow into product creation/edition interface for regrouping title and editor in order to sort interface	*/
     wpshop_products::create_wpshop_products_type();
     add_action('add_meta_boxes', array('wpshop_products', 'add_meta_boxes'));
     add_filter('post_link', array('wpshop_products', 'set_product_permalink'), 10, 3);
     add_filter('post_type_link', array('wpshop_products', 'set_product_permalink'), 10, 3);
     add_action('pre_get_posts', array('wpshop_products', 'set_product_request_by_name'));
     $product_class = new wpshop_products();
     add_action('save_post', array($product_class, 'save_product_custom_informations'));
     /*	Add wpshop product category term	*/
     wpshop_categories::create_product_categories();
     /*	Add wpshop message term	*/
     if ($wpshop_shop_type == 'sale') {
         /*	Add wpshop orders term	*/
         wpshop_orders::create_orders_type();
         add_action('add_meta_boxes', array('wpshop_orders', 'add_meta_boxes'));
         add_action('manage_' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '_posts_custom_column', array('wpshop_orders', 'orders_custom_columns'), 10, 2);
         add_filter('manage_edit-' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '_columns', array('wpshop_orders', 'orders_edit_columns'));
         add_action('restrict_manage_posts', array('wpshop_orders', 'list_table_filters'));
         add_filter('parse_query', array('wpshop_orders', 'list_table_filter_parse_query'));
     }
     $args = array('public' => true, '_builtin' => false);
     $output = 'objects';
     // names or objects, note names is the default
     $operator = 'or';
     // 'and' or 'or'
     $wp_types_original = get_post_types($args, $output, $operator);
     foreach ($wp_types_original as $type => $type_definition) {
         $wp_types[$type] = $type_definition->labels->name;
     }
     $to_exclude = unserialize(WPSHOP_INTERNAL_TYPES_TO_EXCLUDE);
     if (!empty($to_exclude)) {
         foreach ($to_exclude as $excluded_type) {
             if (isset($wp_types[$excluded_type])) {
                 unset($wp_types[$excluded_type]);
             }
         }
     }
     DEFINE('WPSHOP_INTERNAL_TYPES', serialize(array_merge($wp_types, array('users' => __('Users', 'wpshop')))));
 }
Пример #2
0
/**
 * Search element in database for shortcode insertion interface
 */
function ajax_wpshop_element_search()
{
    check_ajax_referer('wpshop_element_search', 'wpshop_ajax_nonce');
    $wpshop_element_searched = isset($_REQUEST['wpshop_element_searched']) ? wpshop_tools::varSanitizer($_REQUEST['wpshop_element_searched']) : null;
    $wpshop_element_type = isset($_REQUEST['wpshop_element_type']) ? wpshop_tools::varSanitizer($_REQUEST['wpshop_element_type']) : null;
    $wpshop_format_result = isset($_REQUEST['wpshop_format_result']) ? (bool) wpshop_tools::varSanitizer($_REQUEST['wpshop_format_result']) : true;
    switch ($wpshop_element_type) {
        case 'product':
        case WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT:
            $data = wpshop_products::product_list($wpshop_format_result, $wpshop_element_searched);
            break;
        case 'categories':
            $data = wpshop_categories::product_list_cats($wpshop_format_result, $wpshop_element_searched);
            break;
    }
    if ($wpshop_format_result) {
        $data = empty($data) ? __('No match', 'wpshop') : $data;
    } else {
        if (!empty($data)) {
            $temp_data = $data;
            unset($data);
            foreach ($temp_data as $post) {
                $data[$post->ID] = $post->ID . ' - ' . $post->post_title;
            }
        } else {
            $data = array();
        }
    }
    echo json_encode($data);
    die;
}
<?php 
        foreach ($category_tree as $sub_category_id => $sub_category_content) {
            $sub_category_definition = get_term($sub_category_id, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
            echo wpshop_categories::category_mini_output($sub_category_definition, $output_type);
        }
        ?>
					</div>
<?php 
    }
}
?>

<?php 
/*	Check what must be outputed on the page (Defined in plugin option)	*/
if (!is_array($wpshop_display_option['wpshop_display_cat_sheet_output']) || in_array('category_subproduct', $wpshop_display_option['wpshop_display_cat_sheet_output'])) {
    if (count(wpshop_categories::get_product_of_category($wp_query->queried_object->term_taxonomy_id)) > 0) {
        $category_has_content = true;
        $category_has_sub_content = true;
        echo do_shortcode('[wpshop_products cid="' . $wp_query->queried_object->term_id . '" type="' . $output_type . '"]');
    }
} elseif (is_array($wpshop_display_option['wpshop_display_cat_sheet_output']) && !in_array('category_subproduct', $wpshop_display_option['wpshop_display_cat_sheet_output'])) {
    $category_has_sub_content = true;
}
?>

<?php 
if (!$category_has_content || !$category_has_sub_content) {
    ?>
<!--	If there is nothing to output into this page -->
	<h2 class="category_content_part_title" ><?php 
    _e('There is nothing to output here', 'wpshop');
" >
	<a class="widget_category_title" href="<?php 
echo $link;
?>
" ><span><?php 
echo esc_html($category->name);
?>
</span></a>
<?php 
if ($category_state_class != 'wpshop_category_empty') {
    ?>
	<ul class="wpshop_categories_widget <?php 
    echo $category_class;
    ?>
" id="wpshop_categories_widget_<?php 
    echo $category->term_id;
    ?>
" >
<?php 
    echo wpshop_categories::category_tree_output($category->term_id, $instance);
    /*	Get the product of the current category	if the current category has no sub category*/
    global $category_has_sub_category;
    if (!$category_has_sub_category && $display_product == 'yes') {
        wpshop_products::get_product_of_category($category->slug, $category->term_id);
    }
    ?>
	</ul>
<?php 
}
?>
</li>
Пример #5
0
    /**
     * Traduit le shortcode et affiche une cat�gorie
     * @param array $atts : tableau de param�tre du shortcode
     * @return mixed
     **/
    public static function wpshop_category_func($atts)
    {
        global $wpdb;
        $string = '';
        if (!empty($atts['cid'])) {
            $atts['type'] = !empty($atts['type']) && in_array($atts['type'], array('grid', 'list')) ? $atts['type'] : 'grid';
            $cat_list = explode(',', $atts['cid']);
            if (count($cat_list) > 1 || !empty($atts['display']) && $atts['display'] == 'only_cat') {
                $string .= '
					<div class="wpshop_categories_' . $atts['type'] . '" >';
                foreach ($cat_list as $cat_id) {
                    $sub_category_def = get_term($cat_id, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
                    $string .= wpshop_categories::category_mini_output($sub_category_def, $atts['type']);
                }
                $string .= '
					</div>';
            } else {
                $sub_category_def = get_term($atts['cid'], WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
                if (empty($atts['display']) || $atts['display'] != 'only_products') {
                    $string .= wpshop_categories::category_mini_output($sub_category_def, $atts['type']);
                    $string .= '
					<div class="category_product_' . $atts['type'] . '" >
						<h2 class="category_content_part_title" >' . __('Category\'s product list', 'wpshop') . '</h2>';
                }
                $string .= wpshop_products::wpshop_products_func($atts);
                if (empty($atts['display']) || $atts['display'] != 'only_products') {
                    $string .= '</div>';
                }
            }
        } else {
            $string .= __('No categories found for display', 'wpshop');
        }
        return do_shortcode($string);
    }
 /**
  * Widget Output
  *
  * @param array $args
  * @param array $instance Widget values.
  */
 function widget($args, $instance)
 {
     $widget_content = '';
     /*	Get the default args from wordpress	*/
     extract($args);
     /*	Get the widget title from the admin configuration	*/
     $title = apply_filters('widget_title', empty($instance['title']) && $instance['title'] != 'vide' ? __('Catalog', 'wpshop') : ($instance['title'] == 'vide' ? '&nbsp;' : $instance['title']));
     /*	Get the widget's content	*/
     $widget_content = '<ul class="main_cat_tree_widget" >' . wpshop_categories::category_tree_output(0, $instance) . '</ul>';
     /*	Add the different element to the widget	*/
     $widget_content = $before_widget . $before_title . $title . $after_title . $widget_content . $after_widget;
     echo $widget_content;
 }
$type = isset($_GET['type']) ? wpshop_tools::varSanitizer($_GET['type']) : null;
$post_type = isset($_GET['post_type']) ? wpshop_tools::varSanitizer($_GET['post_type']) : null;
$display_option_display_type = true;
$display_option_grouped = true;
$display_search_form = true;
if (!empty($type)) {
    switch ($type) {
        case 'attribute_value':
            $display_option_grouped = false;
            $display_search_form = false;
            $display_option_grouped = false;
            $wpshop_wysiwyg_shortcode_inserter_shortcode_main_identifier = 'wpshop_att_val attid';
            $content = wpshop_attributes::get_attribute_list(null, $type, $post_type);
            break;
        case 'categories':
            $content = wpshop_categories::product_list_cats(true);
            $wpshop_wysiwyg_shortcode_inserter_shortcode_main_identifier = 'wpshop_category cid';
            ob_start();
            ?>
			<p><?php 
            _e('Shortcode options', 'wpshop');
            ?>
</p>
			<div id="wpshop_wysiwyg_shortcode_categorie_options_container" >
				<input type="checkbox" name="wpshop_wysiwyg_shortcode_options[]" id="wpshop_wysiwyg_shortcode_options_categorie_display_product" class="wpshop_wysiwyg_shortcode_options wpshop_wysiwyg_shortcode_options_categories_display_product" value="only_cat" checked ><label for="wpshop_wysiwyg_shortcode_options_categorie_display_product" > <?php 
            _e('Do not display product', 'wpshop');
            ?>
</label>
			</div>
<?php 
            $specific_options = ob_get_contents();
 /**
  * Save Products attribute values for Text attribute data for a products category
  * @param integer $category_id
  * @param std_object $attribute_def
  * @param array $current_category_child
  */
 function save_values_for_text_filterable_attribute($category_id, $attribute_def, $current_category_child)
 {
     $category_option = get_option('wpshop_product_category_' . $category_id);
     $category_product_ids = wpshop_categories::get_product_of_category($category_id);
     /** If there are sub-categories take all products of sub-categories **/
     $list_values = array();
     if (!empty($current_category_children)) {
         foreach ($current_category_children as $current_category_child) {
             $sub_categories_product_ids = wpshop_categories::get_product_of_category($current_category_child->term_taxonomy_id);
             if (!empty($sub_categories_product_ids)) {
                 foreach ($sub_categories_product_ids as $sub_categories_product_id) {
                     if (!in_array($sub_categories_product_id, $category_product_ids)) {
                         $category_product_ids[] = $sub_categories_product_id;
                     }
                 }
             }
         }
     }
     if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id])) {
         if (!empty($category_product_ids)) {
             $product_data = '';
             foreach ($category_product_ids as $category_product_id) {
                 $product_postmeta = get_post_meta($category_product_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true);
                 $product_data = !empty($product_postmeta[$attribute_def->code]) ? $product_postmeta[$attribute_def->code] : '';
                 if (!in_array($product_data, $list_values)) {
                     $list_values[] = $product_data;
                     if (!empty($product_data)) {
                         $category_option['wpshop_category_filterable_attributes'][$attribute_def->id][] = $product_data;
                     }
                 }
             }
         }
     }
     update_option('wpshop_product_category_' . $category_id, $category_option);
 }