/** * @param array $values * @return array|WP_Error */ public function prepare_settings_options_values($values) { $conf = array('host' => trim($values['host']), 'username' => trim($values['username']), 'password' => trim($values['password']), 'secure' => $values['secure'], 'port' => trim($values['port'])); if (empty($conf['username'])) { return new WP_Error('empty_username', __('Username cannot be empty', 'fw')); } if (empty($conf['password'])) { return new WP_Error('empty_password', __('Password cannot be empty', 'fw')); } if (!fw_is_valid_domain_name($conf['host'])) { return new WP_Error('invalid_host', __('Invalid host', 'fw')); } if (!in_array($conf['secure'], array('ssl', 'tls'))) { $conf['secure'] = false; } // in case the port is missing or invalid if (empty($conf['port']) || !is_numeric($conf['port'])) { $conf['port'] = 25; if ($conf['secure']) { if ($conf['secure'] === 'ssl') { $conf['port'] = 465; } elseif ($conf['secure'] === 'tls') { $conf['port'] = 587; } } } return $conf; }
/** * @deprecated */ public function get_prepared_config() { trigger_error('Deprecated', E_USER_WARNING); $settings = $this->config; if (!$settings || empty($settings['general']['from_name']) || empty($settings['general']['from_address'])) { return false; } $conf = false; $method = trim($settings['method']); switch ($method) { case 'wpmail': $conf = array(); break; case 'smtp': $smtp_settings = $settings['smtp']; $host = trim($smtp_settings['host']); $username = trim($smtp_settings['username']); $password = trim($smtp_settings['password']); if ($username && $password && fw_is_valid_domain_name($host)) { $conf = array('host' => $host, 'username' => $username, 'password' => $password, 'secure' => $smtp_settings['secure'], 'port' => trim($smtp_settings['port'])); if (!in_array($conf['secure'], array('ssl', 'tls'))) { $conf['secure'] = false; } // in case the port is missing or invalid if (empty($conf['port']) || !is_numeric($conf['port'])) { $conf['port'] = $conf['secure'] ? 465 : 25; } } break; } // add general settings if (false !== $conf) { $conf = array_merge($conf, array('from_address' => trim($settings['general']['from_address']), 'from_name' => trim($settings['general']['from_name']), '_method' => $method)); } return $conf; }