public function save_category_form($term_id) { // Run this method only once if ($this->save_count < 1) { $id = $this->args['id']; $data = Database::get_row($this->args['table'], 'cat_id', $term_id); foreach ($this->args['table']['structure'] as $name => $args) { $data[$name] = isset($_POST[$name]) ? $_POST[$name] : $data[$name]; } if (empty($data['cat_id'])) { $data['cat_id'] = $term_id; Database::insert_row($this->args['table'], $data); } else { Database::update_row($this->args['table'], 'cat_id', $term_id, $data); } $this->save_count++; } }
protected static function remove_from_database($email) { $email = strtolower($email); $data = Database::get_row(static::$table, 'email', $email); $status = 'error'; if (empty($data['email'])) { $status = 'not-found'; } else { $data['email'] = 'deleted-' . rand(9999, 99999999); $data['status'] = 'deleted'; $data['delete_date'] = date('Y-m-d', time()); $data['delete_time'] = date('H:i:s', time()); $email = ['sender' => !empty(get_option('mailing_list_settings_sender')) ? get_option('mailing_list_settings_sender') : get_bloginfo('admin_email'), 'recipient' => $email, 'subject' => 'Unsubscribe Confirmation', 'template' => 'unsubscribe.php']; new Email($email); $status = Database::update_row(static::$table, 'id', $data['id'], $data) ? 'success' : 'error'; } return $status; }
public function update() { $fields = $this->fields; if ($this->id == 0 && $fields['id'] != 0) { $this->id = $fields['id']; } unset($fields['id']); Database::update_row($this->getTable(), $this->id, $fields); }
public function save_meta_box() { // Run this method only once if ($this->save_count < 1) { if (in_array(get_post_type(), $this->args['post_type'])) { $prefix = $this->args['table']['prefix'] . '_'; $total = isset($_POST[$prefix . 'id']) ? count($_POST[$prefix . 'id']) : 1; $num = 0; if ($this->args['recursive']) { $num = 1; } if ($this->args['admin_menu']) { $num = 1; } // Loop through the posted data for ($i = $num; $i < $total; $i++) { // Delete data if (isset($_POST[$prefix . 'id']) && $_POST[$prefix . 'id'][$i] < 0) { $row_id = str_replace('-', '', $_POST[$prefix . 'id'][$i]); Database::delete_row($this->args['table'], 'id', $row_id); // Save data } else { $data = array(); foreach ($this->args['table']['structure'] as $column => $value) { $data[$column] = isset($_POST[$prefix . $column][$i]) ? $_POST[$prefix . $column][$i] : ''; } if (isset($_POST[$prefix . 'id'])) { $row_id = $_POST[$prefix . 'id'][$i]; if (!empty($row_id)) { Database::update_row($this->args['table'], 'id', $row_id, $data); } else { Database::insert_row($this->args['table'], $data); } } } } } } $this->save_count++; }