public static function init_features_actions() { $result_msg = ''; if (isset($_REQUEST['bt_save_field'])) { $field_name = trim(strip_tags(addslashes($_REQUEST['field_name']))); if (isset($_REQUEST['field_id']) && $_REQUEST['field_id'] > 0) { $field_id = trim($_REQUEST['field_id']); $count_field_name = WC_Compare_Data::get_count("field_name = '" . $field_name . "' AND id != '" . $field_id . "'"); if ($field_name != '' && $count_field_name == 0) { $result = WC_Compare_Data::update_row($_REQUEST); if (isset($_REQUEST['field_cats']) && count((array) $_REQUEST['field_cats']) > 0) { foreach ($_REQUEST['field_cats'] as $cat_id) { $check_existed = WC_Compare_Categories_Fields_Data::get_count("cat_id='" . $cat_id . "' AND field_id='" . $field_id . "'"); if ($check_existed == 0) { WC_Compare_Categories_Fields_Data::insert_row($cat_id, $field_id); } } WC_Compare_Categories_Fields_Data::delete_row("field_id='" . $field_id . "' AND cat_id NOT IN(" . implode(',', $_REQUEST['field_cats']) . ")"); } else { WC_Compare_Categories_Fields_Data::delete_row("field_id='" . $field_id . "'"); } $result_msg = '<div class="updated" id="result_msg"><p>' . __('Compare Feature Successfully edited', 'woo_cp') . '.</p></div>'; } else { $result_msg = '<div class="error" id="result_msg"><p>' . __('Nothing edited! You already have a Compare Feature with that name. Use the Features Search function to find it. Use unique names to edit each Compare Feature.', 'woo_cp') . '</p></div>'; } } else { $count_field_name = WC_Compare_Data::get_count("field_name = '" . $field_name . "'"); if ($field_name != '' && $count_field_name == 0) { $field_id = WC_Compare_Data::insert_row($_REQUEST); if ($field_id > 0) { WC_Compare_Categories_Fields_Data::delete_row("field_id='" . $field_id . "'"); if (isset($_REQUEST['field_cats']) && count((array) $_REQUEST['field_cats']) > 0) { foreach ($_REQUEST['field_cats'] as $cat_id) { WC_Compare_Categories_Fields_Data::insert_row($cat_id, $field_id); } } $result_msg = '<div class="updated" id="result_msg"><p>' . __('Compare Feature Successfully created', 'woo_cp') . '.</p></div>'; } else { $result_msg = '<div class="error" id="result_msg"><p>' . __('Compare Feature Error created', 'woo_cp') . '.</p></div>'; } } else { $result_msg = '<div class="error" id="result_msg"><p>' . __('Nothing created! You already have a Compare Feature with that name. Use the Features Search function to find it. Use unique names to create each Compare Feature.', 'woo_cp') . '</p></div>'; } } } elseif (isset($_REQUEST['bt_delete'])) { $list_fields_delete = $_REQUEST['un_fields']; if (is_array($list_fields_delete) && count($list_fields_delete) > 0) { foreach ($list_fields_delete as $field_id) { WC_Compare_Data::delete_row($field_id); WC_Compare_Categories_Fields_Data::delete_row("field_id='" . $field_id . "'"); } $result_msg = '<div class="updated" id="result_msg"><p>' . __('Compare Feature successfully deleted', 'woo_cp') . '.</p></div>'; } else { $result_msg = '<div class="updated" id="result_msg"><p>' . __('Please select item(s) to delete', 'woo_cp') . '.</p></div>'; } } if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'field-delete') { $field_id = trim($_REQUEST['field_id']); if (isset($_REQUEST['cat_id']) && $_REQUEST['cat_id'] > 0) { WC_Compare_Categories_Fields_Data::delete_row("field_id='" . $field_id . "' AND cat_id='" . $_REQUEST['cat_id'] . "'"); $result_msg = '<div class="updated" id="result_msg"><p>' . __('Compare Feature successfully removed', 'woo_cp') . '.</p></div>'; } else { WC_Compare_Data::delete_row($field_id); WC_Compare_Categories_Fields_Data::delete_row("field_id='" . $field_id . "'"); $result_msg = '<div class="updated" id="result_msg"><p>' . __('Compare Feature successfully deleted', 'woo_cp') . '.</p></div>'; } } return $result_msg; }
public static function delete_rows($items = array()) { if (is_array($items) && count($items) > 0) { foreach ($items as $field_id) { WC_Compare_Data::delete_row($field_id); } } }