Ejemplo n.º 1
0
 /**
  * br_aapf_args_parser - extend $args based on passed filters
  *
  * @param array $args
  *
  * @return array
  */
 function br_aapf_args_parser($args = array())
 {
     $attributes_terms = $tax_query = array();
     $attributes = apply_filters('berocket_aapf_listener_get_attributes', br_aapf_get_attributes());
     $taxonomies = array();
     if (@$attributes) {
         foreach ($attributes as $k => $v) {
             $terms = get_terms(array($k), $args = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'id=>slug'));
             if ($terms) {
                 foreach ($terms as $term_id => $term_slug) {
                     $attributes_terms[$k][$term_id] = $term_slug;
                 }
             }
             unset($terms);
         }
     }
     unset($attributes);
     if (@$_POST['terms']) {
         foreach ($_POST['terms'] as $t) {
             if (!isset($taxonomies[$t[0]])) {
                 $taxonomies[$t[0]] = array();
             }
             $taxonomies[$t[0]][] = @$attributes_terms[$t[0]][$t[1]];
             $taxonomies_operator[$t[0]] = $t[2];
         }
     }
     unset($attributes_terms);
     $taxonomies = apply_filters('berocket_aapf_listener_taxonomies', @$taxonomies);
     $taxonomies_operator = apply_filters('berocket_aapf_listener_taxonomies_operator', @$taxonomies_operator);
     if (@$taxonomies) {
         $tax_query['relation'] = 'AND';
         if ($taxonomies) {
             foreach ($taxonomies as $k => $v) {
                 if ($taxonomies_operator[$k] == 'AND') {
                     $op = 'AND';
                 } else {
                     $op = 'IN';
                 }
                 $tax_query[] = array('taxonomy' => $k, 'field' => 'slug', 'terms' => $v, 'operator' => $op);
             }
         }
     }
     if (@$_POST['product_cat'] and $_POST['product_cat'] != '-1') {
         $tax_query[] = array('taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => strip_tags($_POST['product_cat']), 'operator' => 'IN');
     }
     $args['tax_query'] = $tax_query;
     $args['post_type'] = 'product';
     if (@$_POST['orderby']) {
         br_aapf_parse_order_by($args);
     }
     return $args;
 }
Ejemplo n.º 2
0
 /**
  * Output admin form
  *
  * @param array $instance
  *
  * @return string|void
  */
 function form($instance)
 {
     wp_enqueue_script('berocket_aapf_widget-admin-script', plugins_url('../js/admin.js', __FILE__), array('jquery'));
     wp_register_style('berocket_aapf_widget-style', plugins_url('../css/admin.css', __FILE__));
     wp_enqueue_style('berocket_aapf_widget-style');
     /* Set up some default widget settings. */
     $defaults = array('widget_type' => '', 'title' => '', 'attribute' => '', 'type' => '', 'operator' => '', 'product_cat' => '', 'height' => 'auto', 'scroll_theme' => 'dark');
     $defaults = apply_filters('berocket_aapf_form_defaults', $defaults);
     $instance = wp_parse_args((array) $instance, $defaults);
     $attributes = br_aapf_get_attributes();
     $categories = self::get_product_categories(@json_decode($instance['product_cat']));
     include AAPF_TEMPLATE_PATH . "admin.php";
 }