/** * @param array $post * @param array $files */ public function bind(array $post, array $files = array()) { if (isset($post['wp_user_id']) && !$post['wp_user_id']) { $post['wp_user_id'] = null; } parent::bind($post); if (isset($files['avatar']) && $files['avatar']['tmp_name']) { if (in_array($files['avatar']['type'], array("image/gif", "image/jpeg", "image/png"))) { $movefile = wp_handle_upload($files['avatar'], array('test_form' => false)); if ($movefile) { $imageResize = new AB_ImageResize($movefile['file']); $imageResize->resizeImage(80, 80); $imageResize->saveImage($movefile['file'], 80); $this->data['avatar_path'] = $movefile['file']; $this->data['avatar_url'] = $movefile['url']; } } } }
/** * @param array $post * @param array $files */ public function bind(array $post, array $files = array()) { parent::bind($post); if (isset($files['avatar']) && $files['avatar']['tmp_name']) { if (in_array($files['avatar']['type'], array("image/gif", "image/jpeg", "image/png"))) { $uploaded = wp_handle_upload($files['avatar'], array('test_form' => false)); if ($uploaded) { $editor = wp_get_image_editor($uploaded['file']); $editor->resize(200, 200); $editor->save($uploaded['file']); $this->data['avatar_path'] = $uploaded['file']; $this->data['avatar_url'] = $uploaded['url']; // Remove old image. $staff = new AB_Staff(); $staff->load($post['id']); if (file_exists($staff->get('avatar_path'))) { unlink($staff->get('avatar_path')); } } } } }