Plugin Directory


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • woo-bulk-editor/trunk/ext/bulk/bulk.php

    r2844667 r2970262  
    11<?php
    22if (!defined('ABSPATH')) {
    33    exit; // Exit if accessed directly
    44}
    55
    66final class WOOBE_BULK extends WOOBE_EXT {
    77
    88    protected $slug = 'bulk'; //unique
    99    public $text_keys = array();
    1010    public $num_keys = array();
    1111    public $other_keys = array();
    1212
    1313    public function __construct() {
    1414
    1515        $this->init_bulk_keys();
    1616
    1717        add_action('woobe_ext_scripts', array($this, 'woobe_ext_scripts'), 1);
    1818        add_action('woobe_tools_panel_buttons_end', array($this, 'woobe_tools_panel_buttons_end'), 1);
    1919
    2020        //ajax
    2121        add_action('wp_ajax_woobe_bulk_products_count', array($this, 'woobe_bulk_products_count'), 1);
    2222        add_action('wp_ajax_woobe_bulk_products', array($this, 'woobe_bulk_products'), 1);
    2323        add_action('wp_ajax_woobe_bulk_finish', array($this, 'woobe_bulk_finish'), 1);
    2424        add_action('wp_ajax_woobe_bulk_draw_gallery_btn', array($this, 'woobe_bulk_draw_gallery_btn'), 1);
    2525        add_action('wp_ajax_woobe_bulk_draw_download_files_btn', array($this, 'woobe_bulk_draw_download_files_btn'), 1);
    2626        add_action('wp_ajax_woobe_bulk_draw_cross_sells_btn', array($this, 'woobe_bulk_draw_cross_sells_btn'), 1);
    2727        add_action('wp_ajax_woobe_bulk_draw_upsell_ids_btn', array($this, 'woobe_bulk_draw_upsell_ids_btn'), 1);
    2828        add_action('wp_ajax_woobe_bulk_draw_grouped_ids_btn', array($this, 'woobe_bulk_draw_grouped_ids_btn'), 1);
    2929        add_action('wp_ajax_woobe_bulk_get_att_terms', array($this, 'woobe_bulk_get_att_terms'), 1);
    3030
    3131        add_action('wp_ajax_woobe_bulk_delete_products_count', array($this, 'woobe_bulk_delete_products_count'), 1);
    3232        add_action('wp_ajax_woobe_bulk_delete_products', array($this, 'woobe_bulk_delete_products'), 1);
    3333
    3434        add_action('woobe_bulk_going', array($this, 'woobe_bulk_going'), 10, 2);
    3535
    3636        //tabs
    3737        $this->add_tab($this->slug, 'top_panel', esc_html__('Bulk Edit', 'woo-bulk-editor'), 'pencil');
    3838        add_action('woobe_ext_top_panel_' . $this->slug, array($this, 'woobe_ext_panel'), 1);
    3939    }
    4040
    4141    public function woobe_ext_scripts() {
    4242        wp_enqueue_script('woobe_ext_' . $this->slug, $this->get_ext_link() . 'assets/js/' . $this->slug . '.js', array(), WOOBE_VERSION);
    4343        wp_enqueue_style('woobe_ext_' . $this->slug, $this->get_ext_link() . 'assets/css/' . $this->slug . '.css', array(), WOOBE_VERSION);
    4444        ?>
    4545        <script>
    4646            lang.<?php echo $this->slug ?> = {};
    4747            lang.<?php echo $this->slug ?>.want_to_bulk = "<?php echo esc_html__('Will be edited next:', 'woo-bulk-editor') ?>";
    4848            lang.<?php echo $this->slug ?>.want_to_delete = "<?php echo esc_html__('Sure? Delete products?', 'woo-bulk-editor') ?>";
    4949            lang.<?php echo $this->slug ?>.deleting = "<?php echo esc_html__('Bulk deleting', 'woo-bulk-editor') ?>";
    5050            lang.<?php echo $this->slug ?>.deleted = "<?php echo esc_html__('Product(s) deleted!', 'woo-bulk-editor') ?>";
    5151            lang.<?php echo $this->slug ?>.bulking = "<?php echo esc_html__('Bulk editing', 'woo-bulk-editor') ?> ...";
    5252            lang.<?php echo $this->slug ?>.bulked = "<?php echo esc_html__('Product(s) edited! Table redrawing ...', 'woo-bulk-editor') ?>";
    5353            lang.<?php echo $this->slug ?>.bulked2 = "<?php echo esc_html__('Product(s) edited!', 'woo-bulk-editor') ?>";
    5454            lang.<?php echo $this->slug ?>.bulk_is_going = "<?php echo esc_html__('ATTENTION: Bulk operation is going!', 'woo-bulk-editor') ?>";
    5555        </script>
    5656        <?php
    5757    }
    5858
    5959    public function woobe_tools_panel_buttons_end() {
    6060        global $WOOBE;
    6161        ?>
    6262        &nbsp;|&nbsp;<span>
    6363            <?php echo WOOBE_HELPER::draw_advanced_switcher(0, 'woobe_bind_editing', '', array('true' => esc_html__('binded editing', 'woo-bulk-editor'), 'false' => esc_html__('binded editing', 'woo-bulk-editor')), array('true' => 1, 'false' => 0), 'js_check_woobe_bind_editing', 'woobe_bind_editing'); ?>
    6464
    6565            <?php
    6666            $bind_tooltip = '';
    6767            if ($WOOBE->show_notes) {
    6868                $fields = $WOOBE->settings->get_fields();
    6969                if (!empty($fields)) {
    7070                    $bind_tooltip = [];
    7171                    foreach ($fields as $field_key => $f) {
    7272                        if ($f['direct']) {
    7373                            $t = strip_tags($f['title']);
    7474                            if (!empty($t) AND $field_key != 'ID') {
    7575                                $bind_tooltip[] = $t;
    7676                            }
    7777                        }
    7878                    }
    7979
    8080                    $bind_tooltip = sprintf(esc_html__('In FREE version of the plugin you can change only next fields: %s', 'woo-bulk-editor'), implode(', ', $bind_tooltip));
    8181                }
    8282            }
    8383            ?>
    8484
    8585            <?php echo WOOBE_HELPER::draw_tooltip(esc_html__('In this mode to the all selected products will be set the value of a product field which been edited', 'woo-bulk-editor') . '. ' . $bind_tooltip) ?>
    8686
    8787        </span>
    8888        <?php
    8989    }
    9090
    9191    public function woobe_ext_panel() {
    9292        $data = array();
    9393        $data['shop_manager_visibility'] = $this->settings->get_shop_manager_visibility();
    9494        $data['text_keys'] = $this->text_keys;
    9595        $data['num_keys'] = $this->num_keys;
    9696        $data['other_keys'] = $this->other_keys;
    9797        $data['settings_fields'] = $this->settings->get_fields();
    9898        echo WOOBE_HELPER::render_html($this->get_ext_path() . 'views/panel.php', $data);
    9999    }
    100100
    101101    //ajax
    102102    public function woobe_bulk_products_count() {
    103103        if (!current_user_can('manage_woocommerce')) {
    104104            die('0');
    105105        }
    106106
     107        if (!isset($_REQUEST['bulk_form_nonce']) || !wp_verify_nonce($_REQUEST['bulk_form_nonce'], 'woobe_bulk_form_nonce')) {
     108            die('0');
     109        }   
    107110        //***
    108111
    109112        $bulk_data = array();
    110113
    111114        if (!isset($_REQUEST['woobe_bind_editing'])) {
    112115            parse_str($_REQUEST['bulk_data'], $bulk_data);
    113116
    114117            $bulk_data = WOOBE_HELPER::sanitize_array($bulk_data);
    115118        } else {
    116119            //binded editing operation works
    117120            if (is_array($_REQUEST['val'])) {
    118121                $value = WOOBE_HELPER::sanitize_array($_REQUEST['val']);
    119122            } else {
    120123                $value = wp_kses($_REQUEST['val'], wp_kses_allowed_html('post'));
    121124                $value = str_replace("&amp;", "&", $value);
    122125            }
    123126
    124127
    125128            $field_key = sanitize_text_field($_REQUEST['field']);
    126129
    127130            //***
    128131
    129132            $bulk_data['woobe_bulk'] = array(
    130133                'is' => array(
    131134                    $field_key => 1
    132135                ),
    133136                $field_key => array(
    134137                    'value' => $value,
    135138                    'behavior' => sanitize_text_field($_REQUEST['behavior'])
    136139                )
    137140            );
    138141        }
    139142
    140143
    141144        $this->storage->set_val('woobe_bulk_' . WOOBE_HELPER::sanitize_bulk_key($_REQUEST['bulk_key']), $bulk_data['woobe_bulk']);
    142145
    143146        if (!isset($_REQUEST['no_filter'])) {
    144147            //get count of filtered - doesn work if bulk for checked products
    145148            $products = $this->products->gets(array(
    146149                'fields' => 'ids',
    147150                'no_found_rows' => true
    148151            ));
    149152            echo json_encode($products->posts);
    150153        }
    151154
    152155        //***
    153156
    154157        do_action('woobe_bulk_started', WOOBE_HELPER::sanitize_bulk_key($_REQUEST['bulk_key']));
    155158
    156159        exit;
    157160    }
    158161
    159162    public function woobe_bulk_delete_products_count() {
    160163        if (!current_user_can('manage_woocommerce')) {
    161164            die('0');
    162165        }
    163 
     166        if (!isset($_REQUEST['bulk_form_nonce']) || !wp_verify_nonce($_REQUEST['bulk_form_nonce'], 'woobe_bulk_form_nonce')) {
     167            die('0');
     168        }   
    164169        $bulk_data = array();
    165170
    166171        if (!isset($_REQUEST['woobe_bind_editing'])) {
    167172            parse_str($_REQUEST['bulk_data'], $bulk_data);
    168173            $bulk_data = WOOBE_HELPER::sanitize_array($bulk_data);
    169174        } else {
    170175            //binded editing operation works
    171176            if (is_array($_REQUEST['val'])) {
    172177                $value = WOOBE_HELPER::sanitize_array($_REQUEST['val']);
    173178            } else {
    174179                $value = wp_kses($_REQUEST['val'], wp_kses_allowed_html('post'));
    175180            }
    176181
    177182            $field_key = sanitize_text_field($_REQUEST['field']);
    178183
    179184            //***
    180185
    181186            $bulk_data['woobe_bulk'] = array(
    182187                'is' => array(
    183188                    $field_key => 1
    184189                ),
    185190                $field_key => array(
    186191                    'value' => $value,
    187192                    'behavior' => sanitize_text_field($_REQUEST['behavior'])
    188193                )
    189194            );
    190195        }
    191196
    192197
    193198        $this->storage->set_val('woobe_bulk_' . WOOBE_HELPER::sanitize_bulk_key($_REQUEST['bulk_key']), $bulk_data['woobe_bulk']);
    194199
    195200        if (!isset($_REQUEST['no_filter'])) {
    196201            //get count of filtered - doesn work if bulk for checked products
    197202            $products = $this->products->gets(array(
    198203                'fields' => 'ids',
    199204                'no_found_rows' => true
    200205            ));
    201206            echo json_encode($products->posts);
    202207        }
    203208
    204209        exit;
    205210    }
    206211
    207212    public function woobe_bulk_delete_products() {
    208213        if (!current_user_can('manage_woocommerce')) {
    209214            die('0');
    210215        }
    211216        if (!isset($_REQUEST['products_ids'])) {
    212217            die('0');
    213218        }
     219       
     220        if (!isset($_REQUEST['bulk_form_nonce']) || !wp_verify_nonce($_REQUEST['bulk_form_nonce'], 'woobe_bulk_form_nonce')) {
     221            die('0');
     222        }       
    214223
    215224        if (is_array($_REQUEST['products_ids'])) {
    216225            $is_variations_solo = intval($_REQUEST['woobe_show_variations']);
    217226
    218227            $products_ids = array_map(function ($item) {
    219228                return intval($item); //sanitize intval
    220229            }, $_REQUEST['products_ids']);
    221230
    222231            //as we want to change variations only but have ids of parents - lets get variations ids
    223232            if ($is_variations_solo AND!empty($products_ids)) {
    224233                $vars_ids = array();
    225234                foreach ($products_ids as $product_id) {
    226235                    $product = $this->products->get_product($product_id);
    227236                    if ($product->is_type('variable')) {
    228237                        $children = $product->get_children();
    229238                        if (!empty($children)) {
    230239                            $vars_ids = array_merge($vars_ids, $children);
    231240                        }
    232241                    }
    233242                }
    234243                $products_ids = array_unique(array_merge($products_ids, $vars_ids));
    235244            }
    236245            $woobe_bulk = $this->storage->get_val('woobe_bulk_' . WOOBE_HELPER::sanitize_bulk_key($_REQUEST['bulk_key']));
    237246
    238247            foreach ($products_ids as $id) {
    239248                if ($is_variations_solo) {
    240249
    241250                    //lets check that currenct variation has the same attributes combination
    242251                    if (isset($woobe_bulk['combination_attributes']) AND!empty($woobe_bulk['combination_attributes'])) {
    243252
    244253                        $variation = $this->products->get_product($id);
    245254                        $attributes = $variation->get_attributes();
    246255
    247256                        //***
    248257
    249258                        $go = FALSE;
    250259
    251260                        //***
    252261
    253262                        if (!empty($attributes)) {
    254263                            foreach ($woobe_bulk['combination_attributes'] as $comb) {
    255264                                //lets look is $attributes the same set of attributes as in $comb
    256265                                $ak_att = array_keys($attributes);
    257266                                $ak_cv = array_keys($comb);
    258267
    259268                                //fix for non-latin symbols
    260269                                if (!empty($ak_att)) {
    261270                                    $ak_att = array_map('urldecode', $ak_att);
    262271                                }
    263272
    264273                                //fix for non-latin symbols
    265274                                if (!empty($ak_cv)) {
    266275                                    $ak_cv = array_map('urldecode', $ak_cv);
    267276                                }
    268277
    269278                                sort($ak_att);
    270279                                sort($ak_cv);
    271280
    272281                                if ($ak_att === $ak_cv) {
    273                                     $av_att = array_values($attributes);
    274                                     $av_cv = array_values($comb);
     282                               
     283                                    $new_attributes = $attributes;
     284                                    $new_comb = $comb;                                         
     285                                    if (in_array('-1',$comb)){
     286                                        $delete_keys = array_keys($comb, '-1',);
     287
     288                                        foreach ($delete_keys as $d_key) {
     289                                            if (isset($new_attributes[$d_key])) {
     290                                                unset($new_attributes[$d_key]);
     291                                                unset($new_comb[$d_key]);
     292                                            }
     293                                        }
     294
     295                                    }
     296                                   
     297                                    $av_att = array_values($new_attributes);
     298                                    $av_cv = array_values($new_comb);
    275299
    276300                                    //fix for non-latin symbols
    277301                                    if (!empty($ak_att)) {
    278302                                        $av_att = array_map('urldecode', $av_att);
    279303                                    }
    280304
    281305
    282306                                    if (!empty($av_cv)) {
    283307                                        $av_cv = array_map('urldecode', $av_cv);
    284308                                    }
    285309
    286310                                    sort($av_att);
    287311                                    sort($av_cv);
     312                                   
    288313                                    if ($av_att === $av_cv) {
    289314                                        $go = TRUE;
    290315                                        break;
    291316                                    }
    292317                                }
    293318                            }
    294319                        }
    295320
    296321                        //***
    297322
    298323                        if (!$go) {
    299324                            continue;
    300325                        }
    301326                    }
    302327                }
    303328                //wp_delete_post($id,false);
    304329                wp_trash_post(intval($id));
    305330            }
    306331        } else {
    307332            die('0');
    308333        }
    309334
    310335        die(json_encode($_REQUEST['products_ids']));
    311336        exit;
    312337    }
    313338
    314339    //ajax
    315340    public function woobe_bulk_products() {
    316341        if (!current_user_can('manage_woocommerce')) {
    317342            die('0');
    318343        }
    319344
    320345        if (!isset($_REQUEST['products_ids'])) {
    321346            die('0');
    322347        }
    323 
     348        if (!isset($_REQUEST['bulk_form_nonce']) || !wp_verify_nonce($_REQUEST['bulk_form_nonce'], 'woobe_bulk_form_nonce')) {
     349            die('0');
     350        }   
    324351        //***
    325352
    326353        $fields = $this->settings->get_fields();
    327354        $woobe_bulk = $this->storage->get_val('woobe_bulk_' . WOOBE_HELPER::sanitize_bulk_key($_REQUEST['bulk_key']));
    328355        //key for history bulk opearation, not related to products keys
    329356        $_REQUEST['woobe_bulk_key'] = WOOBE_HELPER::sanitize_bulk_key($_REQUEST['bulk_key']);
    330357
    331358        $is_variations_solo = intval($_REQUEST['woobe_show_variations']);
    332359        $products_ids = $_REQUEST['products_ids']; //sanitize in cycle below
    333360        //***
    334361        //as we want to change variations only but have ids of parents - lets get variations ids
    335362        if ($is_variations_solo AND!empty($products_ids)) {
    336363            $vars_ids = array();
    337364            foreach ($products_ids as $product_id) {
    338365                $product_id = intval($product_id); //sanitize
    339366
    340367                $product = $this->products->get_product($product_id);
    341368                if ($product->is_type('variable')) {
    342369                    $children = $product->get_children();
    343370                    if (!empty($children)) {
    344371                        $vars_ids = array_merge($vars_ids, $children);
    345372                    }
    346373                }
    347374            }
    348375
    349376            $products_ids = array_unique(array_merge($products_ids, $vars_ids));
    350377        }
    351378
    352379        //***
    353380
    354381        if (isset($woobe_bulk['is']) AND!empty($woobe_bulk['is']) AND!empty($products_ids)) {
    355382
    356383            //***
    357384
    358385            foreach ($woobe_bulk['is'] as $field_key => $is) {
    359386
    360387                if ($fields[$field_key]['edit_view'] === 'calendar') {
    361388
    362389
    363390                    if (!is_int($woobe_bulk[$field_key]['value']) AND (isset($fields[$field_key]["field_type"]) AND $fields[$field_key]["field_type"] == "meta")) {
    364391                        $woobe_bulk[$field_key]['value'] = strtotime($woobe_bulk[$field_key]['value']); // - wrong way
    365392                    } else {
    366393                        $woobe_bulk[$field_key]['value'] = $this->products->normalize_calendar_date($woobe_bulk[$field_key]['value'], $field_key);
    367394                    }
    368395                }
    369396
    370397                //***
    371398                //speedfix
    372399                wp_defer_term_counting(false);
    373400                wp_defer_comment_counting(true);
    374401
    375402                //***
    376403
    377404                if (intval($is) === 1) {
    378405
    379406                    foreach ($products_ids as $product_id) {
    380407
    381408                        if ($is_variations_solo) {
    382409                            //if enabled editing of variations only parent-products are ignored
    383410                            $product = $this->products->get_product($product_id);
    384411                            if (!$product->is_type('variation')) {
    385412                                continue;
    386413                            }
    387414
    388415                            //lets check that currenct variation has the same attributes combination
    389416                            if (isset($woobe_bulk['combination_attributes']) AND!empty($woobe_bulk['combination_attributes'])) {
    390417
    391418                                $variation = $this->products->get_product($product_id);
    392419                                $attributes = $variation->get_attributes();
    393420
    394421                                //***
    395422
    396423                                $go = FALSE;
    397424
    398425                                //***
    399426
    400427                                if (!empty($attributes)) {
    401428                                    foreach ($woobe_bulk['combination_attributes'] as $comb) {
    402429                                        //lets look is $attributes the same set of attributes as in $comb
    403430                                        $ak_att = array_keys($attributes);
    404431                                        $ak_cv = array_keys($comb);
    405432                                       
    406433                                        //fix for non-latin symbols
    407434                                        if (!empty($ak_att)) {
    408435                                            $ak_att = array_map('urldecode', $ak_att);
    409436                                        }
    410437
    411438                                        //fix for non-latin symbols
    412439                                        if (!empty($ak_cv)) {
    413440                                            $ak_cv = array_map('urldecode', $ak_cv);
    414441                                        }
    415442
    416443                                        sort($ak_att);
    417444                                        sort($ak_cv);
    418445
    419446                                        if ($ak_att === $ak_cv) {
    420447                                            $new_attributes = $attributes;
    421448                                            $new_comb = $comb;                                         
    422449                                            if (in_array('-1',$comb)){
    423450                                                $delete_keys = array_keys($comb, '-1',);
    424451                                               
    425452                                                foreach ($delete_keys as $d_key) {
    426453                                                    if (isset($new_attributes[$d_key])) {
    427454                                                        unset($new_attributes[$d_key]);
    428455                                                        unset($new_comb[$d_key]);
    429456                                                    }
    430457                                                }
    431458                                               
    432459                                            }
    433460                                           
    434461                                            $av_att = array_values($new_attributes);
    435462                                            $av_cv = array_values($new_comb);
    436463
    437464                                            //fix for non-latin symbols
    438465                                            if (!empty($ak_att)) {
    439466                                                $av_att = array_map('urldecode', $av_att);
    440467                                            }
    441468
    442469                                            if (!empty($av_cv)) {
    443470                                                $av_cv = array_map('urldecode', $av_cv);
    444471                                            }
    445472
    446473                                            sort($av_att);
    447474                                            sort($av_cv);
    448475                                            if ($av_att === $av_cv) {
    449476                                                $go = TRUE;
    450477                                                break;
    451478                                            }
    452479                                        }
    453480                                    }
    454481                                }
    455482
    456483                                //***
    457484
    458485                                if (!$go) {
    459486                                    continue;
    460487                                }
    461488                            }
    462489                        }
    463490
    464491                        //***
    465492
    466493
    467494                        switch ($field_key) {
    468495                            case 'post_title':
    469496                            case 'post_content':
    470497                            case 'post_excerpt':
    471498                            case 'post_name':
    472499                            case 'purchase_note':
    473500                            case 'sku':
    474501                            case 'tax_class':
    475502                            case 'backorders':
    476503                            case 'sold_individually':
    477504                            case 'reviews_allowed':
    478505                            case 'product_url':
    479506                            case 'button_text':
    480507                                $this->_process_text_data($woobe_bulk, $field_key, $product_id);
    481508                                break;
    482509
    483510                            case 'post_status':
    484511                            case 'stock_status':
    485512                            case 'manage_stock':
    486513                            case 'tax_status':
    487514                            case 'catalog_visibility':
    488515                            case 'product_type':
    489516                            case 'featured':
    490517                            case 'virtual':
    491518                            case 'downloadable':
    492519                            case 'download_files':
    493520                            case 'gallery':
    494521                            case 'upsell_ids':
    495522                            case 'cross_sell_ids':
    496523                            case 'grouped_ids':
    497524                            case 'post_date':
    498525                                if (intval($woobe_bulk[$field_key]['value']) !== -1) {
    499526                                    $this->products->update_page_field($product_id, $field_key, $woobe_bulk[$field_key]['value']);
    500527                                }
    501528                                break;
    502529                            case 'attribute_visibility':
    503530
    504531                                if (!isset($woobe_bulk[$field_key]['value']) OR!is_array($woobe_bulk[$field_key]['value'])) {
    505532
    506533                                    $woobe_bulk[$field_key]['value'] = array();
    507534                                }
    508535                                if (!isset($woobe_bulk[$field_key]['visible'])) {
    509536                                    $woobe_bulk[$field_key]['visible'] = 1;
    510537                                }
    511538                                $this->products->set_product_attributes_visible($product_id, $woobe_bulk[$field_key]['value'], $woobe_bulk[$field_key]['visible']);
    512539
    513540                                break;
    514541                            case 'regular_price':
    515542                            case 'sale_price':
    516543                            case 'stock_quantity':
    517544                            case 'download_expiry':
    518545                            case 'download_limit':
    519546                            case 'date_on_sale_from':
    520547                            case 'date_on_sale_to':
    521548                            case 'weight':
    522549                            case 'length':
    523550                            case 'width':
    524551                            case 'height':
    525552                            case 'product_shipping_class':
    526553                            case 'menu_order':
    527554                            case 'post_author':
    528555                            case 'total_sales':
    529556                            case 'review_count':
    530557                            case 'average_rating':
    531558                                $this->_process_number_data($woobe_bulk, $field_key, $product_id);
    532559                                break;
    533560
    534561                            default:
    535562                                break;
    536563                        }
    537564
    538565                        //***
    539566
    540567                        if (isset($fields[$field_key]) AND $fields[$field_key]['field_type'] === 'taxonomy') {
    541568                            //if (!empty($woobe_bulk[$field_key]['value'])) {
    542569                            do_action('woobe_before_update_page_field', $field_key, $product_id, 0); //for the History
    543570                            if (!isset($woobe_bulk[$field_key]['behavior'])) {
    544571                                $woobe_bulk[$field_key]['behavior'] = "";
    545572                            }
    546573                            switch ($woobe_bulk[$field_key]['behavior']) {
    547574                                case 'append':
    548575                                    if (is_taxonomy_hierarchical($field_key)) {
    549576                                        wp_set_post_terms($product_id, $woobe_bulk[$field_key]['value'], $field_key, true);
    550577                                    } else {
    551578                                        //product_tag for example
    552579                                        foreach ($woobe_bulk[$field_key]['value'] as $term_id) {
    553580                                            $t = get_term_by('id', $term_id, $field_key);
    554581                                            wp_set_post_terms($product_id, $t->slug, $field_key, true);
    555582                                        }
    556583                                    }
    557584                                    break;
    558585                                case 'replace':
    559586                                case 'new':
    560587                                    if (is_taxonomy_hierarchical($field_key)) {
    561588                                        wp_set_post_terms($product_id, $woobe_bulk[$field_key]['value'], $field_key, false);
    562589                                    } else {
    563590                                        //product_tag for example
    564591                                        $append = false; //clean previous by first one then append
    565592                                        if (!empty($woobe_bulk[$field_key]['value']) AND is_array($woobe_bulk[$field_key]['value'])) {
    566593                                            foreach ($woobe_bulk[$field_key]['value'] as $term_id) {
    567594                                                $t = get_term_by('id', $term_id, $field_key);
    568595                                                wp_set_post_terms($product_id, $t->slug, $field_key, $append);
    569596                                                $append = true;
    570597                                            }
    571598                                        }
    572599                                    }
    573600                                    break;
    574601                                case 'remove':
    575602                                    foreach ($woobe_bulk[$field_key]['value'] as $term_id) {
    576603                                        $t = get_term_by('id', $term_id, $field_key);
    577604                                        wp_remove_object_terms($product_id, $t->slug, $field_key);
    578605                                    }
    579606                                    break;
    580607                            }
    581608                            //}
    582609                        }
    583610
    584611                        //***
    585612
    586613                        if (isset($fields[$field_key]) AND $fields[$field_key]['field_type'] === 'attribute') {
    587614                            if (!isset($woobe_bulk[$field_key]['value'])) {
    588615                                $woobe_bulk[$field_key]['value'] = '';
    589616                            }
    590617                            do_action('woobe_before_update_page_field', $field_key, $product_id, 0); //for the History
    591618                            $this->products->set_product_attributes($product_id, $field_key, $woobe_bulk[$field_key]['value'], $woobe_bulk[$field_key]['behavior']);
    592619                        }
    593620
    594621                        //***
    595622
    596623                        if (isset($fields[$field_key]) AND $fields[$field_key]['field_type'] === 'meta') {
    597624                            switch ($fields[$field_key]['type']) {
    598625                                case 'string':
    599626
    600627                                    //if data is serialized in ine string
    601628                                    if ($fields[$field_key]['edit_view'] == 'meta_popup_editor') {
    602629                                        if (!is_array($woobe_bulk[$field_key]['value'])) {
    603630
    604631                                            //if not else parsed
    605632                                            parse_str($woobe_bulk[$field_key]['value'], $meta_val);
    606633
    607634                                            $woobe_bulk[$field_key]['value'] = $this->products->process_jsoned_meta_data($meta_val);
    608635                                        }
    609636                                    }
    610637                                    //***
    611638                                    if ($fields[$field_key]['edit_view'] == 'gallery_popup_editor') {
    612639                   
    613640                                        if (!is_array($woobe_bulk[$field_key]['value'])) {
    614641                                            //if not else parsed
    615642                                            parse_str($woobe_bulk[$field_key]['value'], $meta_val);
    616643                                            if (!empty($meta_val['woobe_gallery_images'])) {
    617644                                                $woobe_bulk[$field_key]['value'] = $meta_val;
    618645                                            }
    619646                                        }
    620647                                       
    621648                                    }
    622649                                    //***
    623650
    624651                                    if ($fields[$field_key]['edit_view'] !== 'switcher') {
    625652                                        $this->_process_text_data($woobe_bulk, $field_key, $product_id);
    626653                                    } else {
    627654                                        if (intval($woobe_bulk[$field_key]['value']) !== -1) {
    628655                                            $this->products->update_page_field($product_id, $field_key, intval($woobe_bulk[$field_key]['value']));
    629656                                        }
    630657                                    }
    631658                                    break;
    632659
    633660                                case 'number':
    634661                                    $this->_process_number_data($woobe_bulk, $field_key, $product_id);
    635662                                    break;
    636663
    637664                                default:
    638665                                    break;
    639666                            }
    640667                        }
    641668                    }
    642669                }
    643670            }
    644671
    645672            do_action('woobe_bulk_going', sanitize_text_field($_REQUEST['woobe_bulk_key']), count($products_ids));
    646673        }
    647674
    648675
    649676
    650677        die('done');
    651678    }
    652679
    653680    public function woobe_bulk_going($bulk_key, $products_count) {
    654681        $count_key = 'woobe_bulk_' . strtolower($bulk_key) . '_count';
    655682        $count_now = intval($this->storage->get_val($count_key));
    656683        $this->storage->set_val($count_key, $products_count + $count_now);
    657684    }
    658685
    659686    private function _process_text_data($woobe_bulk, $field_key, $product_id) {
    660687        //if (!empty($woobe_bulk[$field_key]['value'])) {
    661688        $val = $this->products->get_post_field($product_id, $field_key);
    662689        $woobe_bulk[$field_key]['value'] = $this->products->string_macros($woobe_bulk[$field_key]['value'], $field_key, $product_id);
    663690        switch ($woobe_bulk[$field_key]['behavior']) {
    664691            case 'append':
    665692                $val = $this->products->string_replacer($val . $woobe_bulk[$field_key]['value'], $product_id);
    666693                break;
    667694            case 'prepend':
    668695                $val = $this->products->string_replacer($woobe_bulk[$field_key]['value'] . $val, $product_id);
    669696                break;
    670697            case 'new':
    671698                $val = $this->products->string_replacer($woobe_bulk[$field_key]['value'], $product_id);
    672699                break;
    673700            case 'replace':
    674701                $replace_to = $this->products->string_replacer($woobe_bulk[$field_key]['replace_to'], $product_id);
    675702                $replace_from = $this->products->string_replacer($woobe_bulk[$field_key]['value'], $product_id);
    676703
    677704                //fix  for  apostrophe
    678705                $replace_from = str_replace("\'", "'", $replace_from);
    679706
    680707                if ($woobe_bulk[$field_key]['case'] == 'ignore') {
    681708                    $val = str_ireplace($replace_from, $replace_to, $val);
    682709                } else {
    683710                    $val = str_replace($replace_from, $replace_to, $val);
    684711                    /*
    685712                     * https://stackoverflow.com/questions/19317493/php-preg-replace-case-insensitive-match-with-case-sensitive-replacement
    686713                      $val = preg_replace_callback('/\b' . $replace_from . '\b/i', function($matches) use ($replace_to) {
    687714                      $i = 0;
    688715                      return join('', array_map(function($char) use ($matches, &$i) {
    689716                      return ctype_lower($matches[0][$i++]) ? strtolower($char) : strtoupper($char);
    690717                      }, str_split($replace_to)));
    691718                      }, $val);
    692719                     *
    693720                     */
    694721                }
    695722
    696723                break;
    697724        }
    698725
    699726        //***
    700727        $empty_exceptions = array('tax_class'); //setting empty values is possible with this fields
    701728
    702729        $can = true; //!empty($val);
    703730
    704731        if (in_array($field_key, $empty_exceptions)) {
    705732            $can = true;
    706733        }
    707734
    708735        if ($can) {
    709736           
    710737            $val = $this->products->update_page_field($product_id, $field_key, $val);
    711738        }
    712739        //}
    713740    }
    714741
    715742    private function _process_number_data($woobe_bulk, $field_key, $product_id) {
    716743        if ($woobe_bulk[$field_key]['behavior'] != 'new') {
    717744            $val = floatval($this->products->get_post_field($product_id, $field_key));
    718745        }
    719746
    720747        //***
    721748
    722749        switch ($woobe_bulk[$field_key]['behavior']) {
    723750            case 'new':
    724751                $val = floatval($woobe_bulk[$field_key]['value']);
    725752                break;
    726753
    727754            case 'invalue':
    728755                $val += floatval($woobe_bulk[$field_key]['value']);
    729756                break;
    730757
    731758            case 'devalue':
    732759                $val -= floatval($woobe_bulk[$field_key]['value']);
    733760                break;
    734761
    735762            case 'inpercent':
    736763                $val = $val + $val * floatval($woobe_bulk[$field_key]['value']) / 100;
    737764                break;
    738765
    739766            case 'depercent':
    740767                $val = $val - $val * floatval($woobe_bulk[$field_key]['value']) / 100;
    741768                break;
    742769
    743770            case 'devalue_regular_price':
    744771                //for sale_price only
    745                 $val = $this->products->get_post_field($product_id, 'regular_price') - floatval($woobe_bulk[$field_key]['value']);
     772                $val = floatval($this->products->get_post_field($product_id, 'regular_price')) - floatval($woobe_bulk[$field_key]['value']);
    746773                break;
    747774
    748775            case 'depercent_regular_price':
    749776                //for sale_price only
    750                 $val = $this->products->get_post_field($product_id, 'regular_price');
     777                $val = floatval($this->products->get_post_field($product_id, 'regular_price'));
    751778                $val = $val - $val * floatval($woobe_bulk[$field_key]['value']) / 100;
    752779                break;
    753780
    754781            case 'invalue_sale_price':
    755782                //for regular_price only
    756                 $val = $this->products->get_post_field($product_id, 'sale_price') + floatval($woobe_bulk[$field_key]['value']);
     783                $val = floatval($this->products->get_post_field($product_id, 'sale_price') + floatval($woobe_bulk[$field_key]['value']));
    757784                break;
    758785
    759786            case 'inpercent_sale_price':
    760787                //for regular_price only
    761                 $val = $this->products->get_post_field($product_id, 'sale_price');
     788                $val =  floatval($this->products->get_post_field($product_id, 'sale_price'));
    762789                $val = $val + $val * floatval($woobe_bulk[$field_key]['value']) / 100;
    763790                break;
    764791        }
    765792
    766793        if (isset($_REQUEST['num_formula_action']) AND isset($_REQUEST['num_formula_value']) AND $_REQUEST['num_formula_value'] != '-1') {
    767794            $v_key = esc_textarea($_REQUEST['num_formula_value']);
    768795            $action = esc_textarea($_REQUEST['num_formula_action']);
    769796            $v_data = floatval(get_post_meta($product_id, $v_key, true));
    770797
    771798            switch ($action) {
    772799                case '-':
    773800                    $val = $val - $v_data;
    774801                    break;
    775802                case '*':
    776803                    $val = $val * $v_data;
    777804                    break;
    778805                case '/':
    779806                    if ($v_data == 0) {
    780807                        $v_data = 1;
    781808                    }
    782809                    $val = $val / $v_data;
    783810                    break;
    784811
    785812                default:
    786813                    $val = $val + $v_data;
    787814                    break;
    788815            }
    789816        }
    790817       
    791818        if (isset($_REQUEST['num_rand_data']) && is_array($_REQUEST['num_rand_data'])) {
    792819            $rand_data = wc_clean($_REQUEST['num_rand_data']);
    793820            if (isset($rand_data['from']) && isset($rand_data['to']) && ($rand_data['from'] != $rand_data['to']) && ($rand_data['from'] < $rand_data['to'])) {
    794821                $from = (float)$rand_data['from'];
    795822                $to = (float)$rand_data['to'];
    796823                $decimal = 1;
    797824                if (isset($rand_data['decimal'])) {
    798825                    $decimal = (int)$rand_data['decimal'];
    799826                }
    800827                $action = '+';
    801828                if (isset($rand_data['action'])) {
    802829                    $action = $rand_data['action'];
    803830                }
    804831               
    805832                $rand_val = rand($from * $decimal, $to * $decimal)/$decimal;
    806833                switch ($action) {
    807834                    case '-':
    808835                        $val = $val - $rand_val;
    809836                        break;
    810837                    case '*':
    811838                        $val = $val * $rand_val;
    812839                        break;
    813840                    case '/':
    814841                        if ($rand_val == 0) {
    815842                            $rand_val = 1;
    816843                        }
    817844                        $val = $val / $rand_val;
    818845                        break;
    819846
    820847                    default:
    821848                        $val = $val + $rand_val;
    822849                        break;
    823850                }               
    824851               
    825852            }
    826853        }
    827854
    828855        //***
    829856
    830857        $convert = TRUE;
    831858        if ($field_key == 'sale_price') {
    832859            //sale price CAN NOT be more OR even equal to the regular price
    833860            if ($val >= $this->products->get_post_field($product_id, 'regular_price')) {
    834861                $convert = FALSE;
    835862            }
    836863            //to delete sale price
    837864            if ($val <= 0) {
    838865                $val = -1;
    839866                $val = $this->products->update_page_field($product_id, $field_key, $val);
    840867                $convert = FALSE;
    841868            }
    842869        }
    843870
    844871        //***
    845872
    846873        if ($convert) {
    847874            $val = $this->products->update_page_field($product_id, $field_key, floatval($val));
    848875        }
    849876    }
    850877
    851878    public function woobe_bulk_finish() {
    852879        do_action('woobe_bulk_finished', WOOBE_HELPER::sanitize_bulk_key($_REQUEST['bulk_key']));
    853880        $count_key = 'woobe_bulk_' . WOOBE_HELPER::sanitize_bulk_key($_REQUEST['bulk_key']) . '_count';
    854881        die($this->storage->get_val($count_key) . '');
    855882    }
    856883
    857884    private function init_bulk_keys() {
    858885
    859886        $fields = woobe_get_fields();
    860887
    861888        $this->text_keys = array(
    862889            'post_title' => array(
    863890                'title' => esc_html__('title', 'woo-bulk-editor'),
    864891                'css_classes' => isset($fields['post_title']['css_classes']) ? $fields['post_title']['css_classes'] : ''
    865892            ),
    866893            'post_content' => array(
    867894                'title' => esc_html__('description', 'woo-bulk-editor'),
    868895                'css_classes' => isset($fields['post_content']['css_classes']) ? $fields['post_content']['css_classes'] : ''
    869896            ),
    870897            'post_excerpt' => array(
    871898                'title' => esc_html__('short description', 'woo-bulk-editor'),
    872899                'css_classes' => isset($fields['post_excerpt']['css_classes']) ? $fields['post_excerpt']['css_classes'] : ''
    873900            ),
    874901            'post_name' => array(
    875902                'title' => esc_html__('product slug', 'woo-bulk-editor'),
    876903                'css_classes' => isset($fields['post_name']['css_classes']) ? $fields['post_name']['css_classes'] : ''
    877904            ),
    878905            'sku' => array(
    879906                'title' => esc_html__('SKU', 'woo-bulk-editor'),
    880907                'css_classes' => isset($fields['sku']['css_classes']) ? $fields['sku']['css_classes'] : ''
    881908            )
    882909        );
    883910
    884911        $this->other_keys = array(
    885912            'post_status' => array(
    886913                'title' => esc_html__('post status', 'woo-bulk-editor'),
    887914                'options' => $fields['post_status']['select_options'],
    888915                'direct' => $fields['post_status']['direct'],
    889916                'css_classes' => isset($fields['post_status']['css_classes']) ? $fields['post_status']['css_classes'] : ''
    890917            ),
    891918            'stock_status' => array(
    892919                'title' => esc_html__('stock status', 'woo-bulk-editor'),
    893920                'options' => $fields['stock_status']['select_options'],
    894921                'direct' => $fields['stock_status']['direct'],
    895922                'css_classes' => isset($fields['stock_status']['css_classes']) ? $fields['stock_status']['css_classes'] : ''
    896923            ),
    897924            'tax_status' => array(
    898925                'title' => esc_html__('tax status', 'woo-bulk-editor'),
    899926                'options' => $fields['tax_status']['select_options'],
    900927                'direct' => $fields['tax_status']['direct'],
    901928                'css_classes' => isset($fields['tax_status']['css_classes']) ? $fields['tax_status']['css_classes'] : ''
    902929            ),
    903930            'catalog_visibility' => array(
    904931                'title' => esc_html__('catalog visibility', 'woo-bulk-editor'),
    905932                'options' => $fields['catalog_visibility']['select_options'],
    906933                'direct' => $fields['catalog_visibility']['direct'],
    907934                'css_classes' => isset($fields['catalog_visibility']['css_classes']) ? $fields['catalog_visibility']['css_classes'] : ''
    908935            ),
    909936            'product_type' => array(
    910937                'title' => esc_html__('product type', 'woo-bulk-editor'),
    911938                'options' => $fields['product_type']['select_options'],
    912939                'direct' => $fields['product_type']['direct'],
    913940                'css_classes' => isset($fields['product_type']['css_classes']) ? $fields['product_type']['css_classes'] : ''
    914941            ),
    915942            'featured' => array(
    916943                'title' => esc_html__('featured', 'woo-bulk-editor'),
    917944                'options' => $fields['featured']['select_options'],
    918945                'direct' => $fields['featured']['direct'],
    919946                'css_classes' => isset($fields['featured']['css_classes']) ? $fields['featured']['css_classes'] : ''
    920947            ),
    921948        );
    922949        //***
    923950
    924951        $options1 = array(
    925952            'invalue' => esc_html__('increase by value', 'woo-bulk-editor'),
    926953            'devalue' => esc_html__('decrease by value', 'woo-bulk-editor'),
    927954            'inpercent' => esc_html__('increase by %', 'woo-bulk-editor'),
    928955            'depercent' => esc_html__('decrease by %', 'woo-bulk-editor'),
    929956            'new' => esc_html__('set new', 'woo-bulk-editor')
    930957        );
    931958
    932959        $options2 = array(
    933960            'invalue' => esc_html__('increase by value', 'woo-bulk-editor'),
    934961            'devalue' => esc_html__('decrease by value', 'woo-bulk-editor'),
    935962            'delete' => esc_html__('delete', 'woo-bulk-editor'),
    936963            'new' => esc_html__('set new', 'woo-bulk-editor')
    937964        );
    938965
    939966        //***
    940967
    941968        $this->num_keys = array(
    942969            'regular_price' => array(
    943970                'title' => esc_html__('regular price', 'woo-bulk-editor'),
    944971                'direct' => $fields['regular_price']['direct'],
    945972                'options' => array(
    946973                    'invalue' => esc_html__('increase by value', 'woo-bulk-editor'),
    947974                    'devalue' => esc_html__('decrease by value', 'woo-bulk-editor'),
    948975                    'inpercent' => esc_html__('increase by %', 'woo-bulk-editor'),
    949976                    'depercent' => esc_html__('decrease by %', 'woo-bulk-editor'),
    950977                    'inpercent_sale_price' => esc_html__('sale price plus %', 'woo-bulk-editor'),
    951978                    'invalue_sale_price' => esc_html__('sale price plus value', 'woo-bulk-editor'),
    952979                    'new' => esc_html__('set new', 'woo-bulk-editor')
    953980                ),
    954981                'css_classes' => isset($fields['regular_price']['css_classes']) ? $fields['regular_price']['css_classes'] : ''
    955982            ),
    956983            'sale_price' => array(
    957984                'title' => esc_html__('sale price', 'woo-bulk-editor'),
    958985                'direct' => $fields['sale_price']['direct'],
    959986                'options' => array(
    960987                    'invalue' => esc_html__('increase by value', 'woo-bulk-editor'),
    961988                    'devalue' => esc_html__('decrease by value', 'woo-bulk-editor'),
    962989                    'inpercent' => esc_html__('increase by %', 'woo-bulk-editor'),
    963990                    'depercent' => esc_html__('decrease by %', 'woo-bulk-editor'),
    964991                    'depercent_regular_price' => esc_html__('regular price minus %', 'woo-bulk-editor'),
    965992                    'devalue_regular_price' => esc_html__('regular price minus value', 'woo-bulk-editor'),
    966993                    'new' => esc_html__('set new', 'woo-bulk-editor')
    967994                ),
    968995                'css_classes' => isset($fields['sale_price']['css_classes']) ? $fields['sale_price']['css_classes'] : ''
    969996            ),
    970997            'stock_quantity' => array(
    971998                'title' => esc_html__('in stock quantity', 'woo-bulk-editor'),
    972999                'direct' => $fields['stock_quantity']['direct'],
    9731000                'options' => $options2,
    9741001                'css_classes' => isset($fields['stock_quantity']['css_classes']) ? $fields['stock_quantity']['css_classes'] : ''
    9751002            ),
    9761003            'download_expiry' => array(
    9771004                'title' => esc_html__('download expiry', 'woo-bulk-editor'),
    9781005                'direct' => $fields['download_expiry']['direct'],
    9791006                'options' => $options2,
    9801007                'css_classes' => isset($fields['download_expiry']['css_classes']) ? $fields['download_expiry']['css_classes'] : ''
    9811008            ),
    9821009            'download_limit' => array(
    9831010                'title' => esc_html__('download limit', 'woo-bulk-editor'),
    9841011                'direct' => $fields['download_limit']['direct'],
    9851012                'options' => $options2,
    9861013                'css_classes' => isset($fields['download_limit']['css_classes']) ? $fields['download_limit']['css_classes'] : ''
    9871014            )
    9881015        );
    9891016    }
    9901017
    9911018    //ajax
    9921019    public function woobe_bulk_draw_gallery_btn() {
    9931020        $images = [];
    9941021        parse_str($_REQUEST['images'], $images); //sanitize below in array_map
    9951022        $data = array();
    9961023        $woobe_gallery_images = isset($images['woobe_gallery_images']) ? $images['woobe_gallery_images'] : array();
    9971024        //sanitizing to intval
    9981025        $woobe_gallery_images = array_map(function ($item) {
    9991026            return intval($item); //sanitize intval
    10001027        }, $woobe_gallery_images);
    10011028
    10021029        $data['html'] = WOOBE_HELPER::draw_gallery_popup_editor_btn(sanitize_text_field($_REQUEST['field']), 0, $woobe_gallery_images);
    10031030        $data['images_ids'] = implode(',', $woobe_gallery_images); //for any case, but now we not need it because updating of products applies by serialized data
    10041031
    10051032
    10061033        die(json_encode($data));
    10071034    }
    10081035
    10091036    //ajax
    10101037    public function woobe_bulk_draw_download_files_btn() {
    10111038        $files = [];
    10121039        parse_str($_REQUEST['files'], $files);
    10131040        $files = WOOBE_HELPER::sanitize_array($files);
    10141041        $count = 0;
    10151042
    10161043        if (isset($files['_wc_file_names'])) {
    10171044            $count = count($files['_wc_file_names']);
    10181045        }
    10191046
    10201047        echo WOOBE_HELPER::draw_downloads_popup_editor_btn(sanitize_text_field($_REQUEST['field']), 0, $count);
    10211048
    10221049        exit;
    10231050    }
    10241051
    10251052    //ajax
    10261053    public function woobe_bulk_draw_cross_sells_btn() {
    10271054        $products = [];
    10281055        parse_str($_REQUEST['products'], $products);
    10291056
    10301057        $ids = array();
    10311058        if (isset($products['woobe_prod_ids'])) {
    10321059            $ids = $products['woobe_prod_ids'];
    10331060        }
    10341061
    10351062        $ids = array_map(function ($item) {
    10361063            return intval($item); //sanitize intval
    10371064        }, $ids);
    10381065
    10391066        echo WOOBE_HELPER::draw_cross_sells_popup_editor_btn(sanitize_text_field($_REQUEST['field']), 0, $ids);
    10401067
    10411068        exit;
    10421069    }
    10431070
    10441071    //ajax
    10451072    public function woobe_bulk_draw_upsell_ids_btn() {
    10461073        $products = [];
    10471074        parse_str($_REQUEST['products'], $products);
    10481075
    10491076        $ids = array();
    10501077        if (isset($products['woobe_prod_ids'])) {
    10511078            $ids = array_map(function ($item) {
    10521079                return intval($item); //sanitize intval
    10531080            }, $products['woobe_prod_ids']);
    10541081        }
    10551082
    10561083        echo WOOBE_HELPER::draw_upsells_popup_editor_btn($_REQUEST['field'], 0, $ids);
    10571084
    10581085        exit;
    10591086    }
    10601087
    10611088    //ajax
    10621089    public function woobe_bulk_draw_grouped_ids_btn() {
    10631090        $products = [];
    10641091        parse_str($_REQUEST['products'], $products); //sanitize below
    10651092
    10661093        $ids = array();
    10671094        if (isset($products['woobe_prod_ids'])) {
    10681095            $ids = array_map(function ($item) {
    10691096                return intval($item); //sanitize intval
    10701097            }, $products['woobe_prod_ids']);
    10711098        }
    10721099
    10731100        echo WOOBE_HELPER::draw_grouped_popup_editor_btn(sanitize_text_field($_REQUEST['field']), 0, $ids);
    10741101
    10751102        exit;
    10761103    }
    10771104
    10781105    //ajax
    10791106    public function woobe_bulk_get_att_terms() {
    10801107
    10811108        $drop_downs = '';
    10821109        if (!empty($_REQUEST['attributes'])) {
    10831110            foreach ($_REQUEST['attributes'] as $pa) {
    10841111                $pa = sanitize_text_field($pa); //sanitize attribute name
    10851112
    10861113                $terms = WOOBE_HELPER::get_taxonomies_terms_hierarchy($pa);
    10871114                if (!empty($terms)) {
    10881115                    $options = array();
    10891116                    $options[''] = esc_html__('not selected', 'woo-bulk-editor');
    10901117                    $options['-1'] = esc_html__('Any', 'woo-bulk-editor');
    10911118                    foreach ($terms as $t) {
    10921119                        $options[$t['slug']] = $t['name'];
    10931120                    }
    10941121
    10951122                    $drop_downs .= WOOBE_HELPER::draw_select(array(
    10961123                                'field' => 0,
    10971124                                'product_id' => 0,
    10981125                                'class' => '',
    10991126                                'options' => $options,
    11001127                                'name' => 'woobe_bulk[combination_attributes][' . sanitize_text_field($_REQUEST['hash_key']) . '][' . $pa . ']'
    11011128                    ));
    11021129                }
    11031130            }
    11041131        }
    11051132
    11061133        die($drop_downs);
    11071134    }
    11081135
    11091136}
Note: See TracChangeset for help on using the changeset viewer.