Exemplo n.º 1
0
 /**
  * Remove a location
  *
  * @return void
  */
 public function location_remove()
 {
     $this->verify_nonce('erp-nonce');
     $location_id = isset($_POST['id']) ? intval($_POST['id']) : 0;
     if ($location_id) {
         Company_Locations::find($location_id)->delete();
     }
     $this->send_success();
 }
Exemplo n.º 2
0
 /**
  * @param array $args
  *
  * @return \WP_Error
  */
 public function create_location($args = [])
 {
     $defaults = array('id' => 0, 'name' => '', 'address_1' => '', 'address_2' => '', 'city' => '', 'state' => '', 'zip' => '', 'country' => '');
     $fields = wp_parse_args($args, $defaults);
     $location_id = intval($fields['id']);
     unset($fields['id']);
     // validation
     if (empty($fields['name'])) {
         return new \WP_Error('no-name', __('No location name provided.', 'wp-erp'));
     }
     if (empty($fields['address_1'])) {
         return new \WP_Error('no-address_1', __('No address provided.', 'wp-erp'));
     }
     if (empty($fields['country'])) {
         return new \WP_Error('no-country', __('No country provided.', 'wp-erp'));
     }
     $location = new Company_Locations();
     if (!$location_id) {
         $location->create($fields);
         do_action('erp_company_location_new', $location->id, $fields);
     } else {
         $location->find($location_id)->update($fields);
         do_action('erp_company_location_updated', $location_id, $fields);
     }
 }