예제 #1
0
 /**
  * Delete a department
  *
  * @return void
  */
 public function department_delete()
 {
     $this->verify_nonce('wp-erp-hr-nonce');
     // @TODO: check permission
     $id = isset($_POST['id']) ? intval($_POST['id']) : 0;
     if ($id) {
         $deleted = erp_hr_delete_department($id);
         if (is_wp_error($deleted)) {
             $this->send_error($deleted->get_error_message());
         }
         $this->send_success(__('Department has been deleted', 'wp-erp'));
     }
     $this->send_error(__('Something went worng!', 'wp-erp'));
 }
예제 #2
0
 /**
  * Department handle bulk action
  *
  * @since 0.1
  *
  * @return void [redirection]
  */
 public function department_bulk_action()
 {
     if (!$this->verify_current_page_screen('erp-hr-depts', 'bulk-departments')) {
         return;
     }
     $employee_table = new \WeDevs\ERP\HRM\Department_List_Table();
     $action = $employee_table->current_action();
     if ($action) {
         $redirect = remove_query_arg(array('_wp_http_referer', '_wpnonce', 'action', 'action2'), wp_unslash($_SERVER['REQUEST_URI']));
         $resp = [];
         switch ($action) {
             case 'delete_department':
                 if (isset($_GET['department_id']) && $_GET['department_id']) {
                     foreach ($_GET['department_id'] as $key => $dept_id) {
                         $resp[] = erp_hr_delete_department($dept_id);
                     }
                 }
                 if (in_array(false, $resp)) {
                     $redirect = add_query_arg(array('department_delete' => 'item_deleted'), $redirect);
                 }
                 wp_redirect($redirect);
                 exit;
         }
     }
 }