/** * @param array $post * @param array $files */ public function bind(array $post, array $files = array()) { parent::bind($post, $files); // Remove the old image. if (isset($post['ab_remove_logo']) && file_exists(get_option('ab_settings_company_logo_path'))) { unlink(get_option('ab_settings_company_logo_path')); update_option('ab_settings_company_logo_path', ''); update_option('ab_settings_company_logo_url', ''); } // And add new. if (isset($files['ab_settings_company_logo']) && $files['ab_settings_company_logo']['tmp_name']) { if (in_array($files['ab_settings_company_logo']['type'], array("image/gif", "image/jpeg", "image/png"))) { $uploaded = wp_handle_upload($files['ab_settings_company_logo'], array('test_form' => false)); if ($uploaded) { $editor = wp_get_image_editor($uploaded['file']); $editor->resize(200, 200); $editor->save($uploaded['file']); $this->data['ab_settings_company_logo_path'] = $uploaded['file']; $this->data['ab_settings_company_logo_url'] = $uploaded['url']; // Remove old image. if (file_exists(get_option('ab_settings_company_logo_path'))) { unlink(get_option('ab_settings_company_logo_path')); } } } } }
/** * Bind values to form. * * @param array $post * @param array $files */ public function bind(array $post, array $files = array()) { if (array_key_exists('category_id', $post) && !$post['category_id']) { $post['category_id'] = null; } parent::bind($post, $files); }
/** * @param array $post * @param array $files */ public function bind(array $post, array $files = array()) { parent::bind($post, $files); // remove the old image if (isset($post['ab_remove_logo']) && file_exists(get_option('ab_settings_company_logo_path'))) { unlink(get_option('ab_settings_company_logo_path')); update_option('ab_settings_company_logo_path', ''); update_option('ab_settings_company_logo_url', ''); } // and add new if (isset($files['ab_settings_company_logo']) && $files['ab_settings_company_logo']['tmp_name']) { if (in_array($files['ab_settings_company_logo']['type'], array("image/gif", "image/jpeg", "image/png"))) { $movefile = wp_handle_upload($files['ab_settings_company_logo'], array('test_form' => false)); if ($movefile) { $imageResize = new AB_ImageResize($movefile['file']); $imageResize->resizeImage(150, 150); $imageResize->saveImage($movefile['file']); $this->data['ab_settings_company_logo_path'] = $movefile['file']; $this->data['ab_settings_company_logo_url'] = $movefile['url']; // remove the old image if (file_exists(get_option('ab_settings_company_logo_path'))) { unlink(get_option('ab_settings_company_logo_path')); } } } } }