options = PostmanOptions::getInstance(); } /** * Fires on the admin_init method */ public function on_admin_init() { $this->registerSettings(); } /** * Register and add settings */ private function registerSettings() { // only administrators should be able to trigger this if ( PostmanUtils::isAdmin() ) { $sanitizer = new PostmanInputSanitizer(); register_setting( PostmanAdminController::SETTINGS_GROUP_NAME, PostmanOptions::POSTMAN_OPTIONS, array( $sanitizer, 'sanitize', ) ); // Sanitize add_settings_section( 'transport_section', __( 'Transport', 'post-smtp' ), array( $this, 'printTransportSectionInfo', ), 'transport_options' ); add_settings_field( PostmanOptions::TRANSPORT_TYPE, _x( 'Type', '(i.e.) What kind is it?', 'post-smtp' ), array( $this, 'transport_type_callback', ), 'transport_options', 'transport_section' ); add_settings_field( 'smtp_mailers', __( 'Mailer Type', 'post-smtp' ), array( $this, 'smtp_mailer_callback', ), 'transport_options', 'transport_section' ); // the Message From section add_settings_section( PostmanAdminController::MESSAGE_FROM_SECTION, _x( 'From Address', 'The Message Sender Email Address', 'post-smtp' ), array( $this, 'printMessageFromSectionInfo', ), PostmanAdminController::MESSAGE_FROM_OPTIONS ); add_settings_field( PostmanOptions::MESSAGE_SENDER_EMAIL, __( 'Email Address', 'post-smtp' ), array( $this, 'from_email_callback', ), PostmanAdminController::MESSAGE_FROM_OPTIONS, PostmanAdminController::MESSAGE_FROM_SECTION ); add_settings_field( PostmanOptions::PREVENT_MESSAGE_SENDER_EMAIL_OVERRIDE, '', array( $this, 'prevent_from_email_override_callback', ), PostmanAdminController::MESSAGE_FROM_OPTIONS, PostmanAdminController::MESSAGE_FROM_SECTION ); add_settings_field( PostmanOptions::MESSAGE_SENDER_NAME, __( 'Name', 'post-smtp' ), array( $this, 'sender_name_callback', ), PostmanAdminController::MESSAGE_FROM_OPTIONS, PostmanAdminController::MESSAGE_FROM_SECTION ); add_settings_field( PostmanOptions::PREVENT_MESSAGE_SENDER_NAME_OVERRIDE, '', array( $this, 'prevent_from_name_override_callback', ), PostmanAdminController::MESSAGE_FROM_OPTIONS, PostmanAdminController::MESSAGE_FROM_SECTION ); // the Additional Addresses section add_settings_section( PostmanAdminController::MESSAGE_SECTION, __( 'Additional Email Addresses', 'post-smtp' ), array( $this, 'printMessageSectionInfo', ), PostmanAdminController::MESSAGE_OPTIONS ); add_settings_field( PostmanOptions::REPLY_TO, __( 'Reply-To', 'post-smtp' ), array( $this, 'reply_to_callback', ), PostmanAdminController::MESSAGE_OPTIONS, PostmanAdminController::MESSAGE_SECTION ); add_settings_field( PostmanOptions::FORCED_TO_RECIPIENTS, __( 'To Recipient(s)', 'post-smtp' ), array( $this, 'to_callback', ), PostmanAdminController::MESSAGE_OPTIONS, PostmanAdminController::MESSAGE_SECTION ); add_settings_field( PostmanOptions::FORCED_CC_RECIPIENTS, __( 'Carbon Copy Recipient(s)', 'post-smtp' ), array( $this, 'cc_callback', ), PostmanAdminController::MESSAGE_OPTIONS, PostmanAdminController::MESSAGE_SECTION ); add_settings_field( PostmanOptions::FORCED_BCC_RECIPIENTS, __( 'Blind Carbon Copy Recipient(s)', 'post-smtp' ), array( $this, 'bcc_callback', ), PostmanAdminController::MESSAGE_OPTIONS, PostmanAdminController::MESSAGE_SECTION ); // the Additional Headers section add_settings_section( PostmanAdminController::MESSAGE_HEADERS_SECTION, __( 'Additional Headers', 'post-smtp' ), array( $this, 'printAdditionalHeadersSectionInfo', ), PostmanAdminController::MESSAGE_HEADERS_OPTIONS ); add_settings_field( PostmanOptions::ADDITIONAL_HEADERS, __( 'Custom Headers', 'post-smtp' ), array( $this, 'headers_callback', ), PostmanAdminController::MESSAGE_HEADERS_OPTIONS, PostmanAdminController::MESSAGE_HEADERS_SECTION ); // Fallback // the Email Validation section add_settings_section( PostmanAdminController::EMAIL_VALIDATION_SECTION, __( 'Validation', 'post-smtp' ), array( $this, 'printEmailValidationSectionInfo', ), PostmanAdminController::EMAIL_VALIDATION_OPTIONS ); add_settings_field( PostmanOptions::ENVELOPE_SENDER, __( 'Email Address', 'post-smtp' ), array( $this, 'disable_email_validation_callback', ), PostmanAdminController::EMAIL_VALIDATION_OPTIONS, PostmanAdminController::EMAIL_VALIDATION_SECTION ); // the Logging section add_settings_section( PostmanAdminController::LOGGING_SECTION, __( 'Email Log Settings', 'post-smtp' ), array( $this, 'printLoggingSectionInfo', ), PostmanAdminController::LOGGING_OPTIONS ); add_settings_field( 'logging_status', __( 'Enable Logging', 'post-smtp' ), array( $this, 'loggingStatusInputField', ), PostmanAdminController::LOGGING_OPTIONS, PostmanAdminController::LOGGING_SECTION ); add_settings_field( 'logging_max_entries', __( 'Maximum Log Entries', 'post-smtp' ), array( $this, 'loggingMaxEntriesInputField', ), PostmanAdminController::LOGGING_OPTIONS, PostmanAdminController::LOGGING_SECTION ); add_settings_field( PostmanOptions::TRANSCRIPT_SIZE, __( 'Maximum Transcript Size', 'post-smtp' ), array( $this, 'transcriptSizeInputField', ), PostmanAdminController::LOGGING_OPTIONS, PostmanAdminController::LOGGING_SECTION ); // the Network section add_settings_section( PostmanAdminController::NETWORK_SECTION, __( 'Network Settings', 'post-smtp' ), array( $this, 'printNetworkSectionInfo', ), PostmanAdminController::NETWORK_OPTIONS ); add_settings_field( 'connection_timeout', _x( 'TCP Connection Timeout (sec)', 'Configuration Input Field', 'post-smtp' ), array( $this, 'connection_timeout_callback', ), PostmanAdminController::NETWORK_OPTIONS, PostmanAdminController::NETWORK_SECTION ); add_settings_field( 'read_timeout', _x( 'TCP Read Timeout (sec)', 'Configuration Input Field', 'post-smtp' ), array( $this, 'read_timeout_callback', ), PostmanAdminController::NETWORK_OPTIONS, PostmanAdminController::NETWORK_SECTION ); // the Advanced section add_settings_section( PostmanAdminController::ADVANCED_SECTION, _x( 'Miscellaneous Settings', 'Configuration Section Title', 'post-smtp' ), array( $this, 'printAdvancedSectionInfo', ), PostmanAdminController::ADVANCED_OPTIONS ); add_settings_field( PostmanOptions::LOG_LEVEL, _x( 'PHP Log Level', 'Configuration Input Field', 'post-smtp' ), array( $this, 'log_level_callback', ), PostmanAdminController::ADVANCED_OPTIONS, PostmanAdminController::ADVANCED_SECTION ); add_settings_field( PostmanOptions::RUN_MODE, _x( 'Delivery Mode', 'Configuration Input Field', 'post-smtp' ), array( $this, 'runModeCallback', ), PostmanAdminController::ADVANCED_OPTIONS, PostmanAdminController::ADVANCED_SECTION ); add_settings_field( PostmanOptions::STEALTH_MODE, _x( 'Stealth Mode', 'This mode removes the Postman X-Mailer signature from emails', 'post-smtp' ), array( $this, 'stealthModeCallback', ), PostmanAdminController::ADVANCED_OPTIONS, PostmanAdminController::ADVANCED_SECTION ); add_settings_field( PostmanOptions::TEMPORARY_DIRECTORY, __( 'Temporary Directory', 'post-smtp' ), array( $this, 'temporaryDirectoryCallback', ), PostmanAdminController::ADVANCED_OPTIONS, PostmanAdminController::ADVANCED_SECTION ); // Notifications add_settings_section( PostmanAdminController::NOTIFICATIONS_SECTION, _x( 'Notifications Settings', 'Configuration Section Title', 'post-smtp' ), array( $this, 'printNotificationsSectionInfo', ), PostmanAdminController::NOTIFICATIONS_OPTIONS ); add_settings_field( PostmanOptions::NOTIFICATION_SERVICE, _x( 'Notification Service', 'Configuration Input Field', 'post-smtp' ), array( $this, 'notification_service_callback', ), PostmanAdminController::NOTIFICATIONS_OPTIONS, PostmanAdminController::NOTIFICATIONS_SECTION ); // Pushover add_settings_section( 'pushover_credentials', _x( 'Pushover Credentials', 'Configuration Section Title', 'post-smtp' ), array( $this, 'printNotificationsSectionInfo', ), PostmanAdminController::NOTIFICATIONS_PUSHOVER_CRED ); add_settings_field( PostmanOptions::PUSHOVER_USER, _x( 'Pushover User Key', 'Configuration Input Field', 'post-smtp' ), array( $this, 'pushover_user_callback', ), PostmanAdminController::NOTIFICATIONS_PUSHOVER_CRED, 'pushover_credentials' ); add_settings_field( PostmanOptions::PUSHOVER_TOKEN, _x( 'Pushover App Token', 'Configuration Input Field', 'post-smtp' ), array( $this, 'pushover_token_callback', ), PostmanAdminController::NOTIFICATIONS_PUSHOVER_CRED, 'pushover_credentials' ); // Slack add_settings_section( 'slack_credentials', _x( 'Slack Credentials', 'Configuration Section Title', 'post-smtp' ), array( $this, 'printNotificationsSectionInfo', ), PostmanAdminController::NOTIFICATIONS_SLACK_CRED ); add_settings_field( PostmanOptions::SLACK_TOKEN, _x( 'Slack Webhook', 'Configuration Input Field', 'post-smtp' ), array( $this, 'slack_token_callback', ), PostmanAdminController::NOTIFICATIONS_SLACK_CRED, 'slack_credentials' ); add_settings_field( PostmanOptions::NOTIFICATION_USE_CHROME, _x( 'Push to chrome extension', 'Configuration Input Field', 'post-smtp' ), array( $this, 'notification_use_chrome_callback', ), PostmanAdminController::NOTIFICATIONS_OPTIONS, PostmanAdminController::NOTIFICATIONS_SECTION ); add_settings_field( PostmanOptions::NOTIFICATION_CHROME_UID, _x( 'Chrome Extension UID', 'Configuration Input Field', 'post-smtp' ), array( $this, 'notification_chrome_uid_callback', ), PostmanAdminController::NOTIFICATIONS_OPTIONS, PostmanAdminController::NOTIFICATIONS_SECTION ); } } /** * Print the Transport section info */ public function printTransportSectionInfo() { print __( 'Choose SMTP or a vendor-specific API:', 'post-smtp' ); } public function printLoggingSectionInfo() { print __( 'Configure the delivery audit log:', 'post-smtp' ); } /** * Print the Section text */ public function printMessageFromSectionInfo() { print sprintf( __( 'This address, like the letterhead printed on a letter, identifies the sender to the recipient. Change this when you are sending on behalf of someone else, for example to use Google\'s Send Mail As feature. Other plugins, especially Contact Forms, may override this field to be your visitor\'s address.', 'post-smtp' ), 'https://support.google.com/mail/answer/22370?hl=en' ); } /** * Print the Section text */ public function printMessageSectionInfo() { print __( 'Separate multiple to/cc/bcc recipients with commas.', 'post-smtp' ); } /** * Print the Section text */ public function printNetworkSectionInfo() { print __( 'Increase the timeouts if your host is intermittenly failing to send mail. Be careful, this also correlates to how long your user must wait if the mail server is unreachable.', 'post-smtp' ); } /** * Print the Section text */ public function printAdvancedSectionInfo() { } /** * Print the Section text */ public function printNotificationsSectionInfo() { } /** * Print the Section text */ public function printAdditionalHeadersSectionInfo() { print __( 'Specify custom headers (e.g. X-MC-Tags: wordpress-site-A), one per line. Use custom headers with caution as they can negatively affect your Spam score.', 'post-smtp' ); } /** * Print the Email Validation Description */ public function printEmailValidationSectionInfo() { print __( 'E-mail addresses can be validated before sending e-mail, however this may fail with some newer domains.', 'post-smtp' ); } /** * Get the settings option array and print one of its values */ public function transport_type_callback() { $transportType = $this->options->getTransportType(); printf( ''; } /** * Get the settings option array and print one of its values */ public function smtp_mailer_callback() { $smtp_mailers = PostmanOptions::SMTP_MAILERS; $current_smtp_mailer = $this->options->getSmtpMailer(); printf( ''; ?>

PHPMailer only if you see wp_mail conflict message, conflicts when another plugin is activated, and sometimes spam issues.', 'post-smtp' ); ?>

', null !== $this->options->getMessageSenderName() ? esc_attr( $this->options->getMessageSenderName() ) : '' ); } /** */ public function prevent_from_name_override_callback() { $enforced = $this->options->isPluginSenderNameEnforced(); printf( ' %s', $enforced ? 'checked="checked"' : '', __( 'Prevent plugins and themes from changing this', 'post-smtp' ) ); } /** * Get the settings option array and print one of its values */ public function from_email_callback() { printf( '', null !== $this->options->getMessageSenderEmail() ? esc_attr( $this->options->getMessageSenderEmail() ) : '', __( 'Required', 'post-smtp' ) ); } /** * Print the Section text */ public function printMessageSenderSectionInfo() { print sprintf( __( 'This address, like the return address printed on an envelope, identifies the account owner to the SMTP server.', 'post-smtp' ), 'https://support.google.com/mail/answer/22370?hl=en' ); } /** * Get the settings option array and print one of its values */ public function prevent_from_email_override_callback() { $enforced = $this->options->isPluginSenderEmailEnforced(); printf( ' %s', $enforced ? 'checked="checked"' : '', __( 'Prevent plugins and themes from changing this', 'post-smtp' ) ); } /** * Shows the Mail Logging enable/disabled option */ public function loggingStatusInputField() { // isMailLoggingAllowed $disabled = ''; if ( ! $this->options->isMailLoggingAllowed() ) { $disabled = 'disabled="disabled" '; } printf( '' ); } public function loggingMaxEntriesInputField() { printf( '', PostmanOptions::MAIL_LOG_MAX_ENTRIES, $this->options->getMailLoggingMaxEntries() ); } public function transcriptSizeInputField() { $inputOptionsSlug = PostmanOptions::POSTMAN_OPTIONS; $inputTranscriptSlug = PostmanOptions::TRANSCRIPT_SIZE; $inputValue = $this->options->getTranscriptSize(); $inputDescription = __( 'Change this value if you can\'t see the beginning of the transcript because your messages are too big.', 'post-smtp' ); printf( '
%4$s', $inputOptionsSlug, $inputTranscriptSlug, $inputValue, $inputDescription ); } /** * Get the settings option array and print one of its values */ public function reply_to_callback() { printf( '', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::REPLY_TO, null !== $this->options->getReplyTo() ? esc_attr( $this->options->getReplyTo() ) : '' ); } /** * Get the settings option array and print one of its values */ public function to_callback() { printf( '', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::FORCED_TO_RECIPIENTS, null !== $this->options->getForcedToRecipients() ? esc_attr( $this->options->getForcedToRecipients() ) : '' ); } /** * Get the settings option array and print one of its values */ public function cc_callback() { printf( '', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::FORCED_CC_RECIPIENTS, null !== $this->options->getForcedCcRecipients() ? esc_attr( $this->options->getForcedCcRecipients() ) : '' ); } /** * Get the settings option array and print one of its values */ public function bcc_callback() { printf( '', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::FORCED_BCC_RECIPIENTS, null !== $this->options->getForcedBccRecipients() ? esc_attr( $this->options->getForcedBccRecipients() ) : '' ); } /** * Get the settings option array and print one of its values */ public function headers_callback() { printf( '', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::ADDITIONAL_HEADERS, null !== $this->options->getAdditionalHeaders() ? esc_attr( $this->options->getAdditionalHeaders() ) : '' ); } /** */ public function disable_email_validation_callback() { $disabled = $this->options->isEmailValidationDisabled(); printf( ' %4$s', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::DISABLE_EMAIL_VALIDAITON, $disabled ? 'checked="checked"' : '', __( 'Disable e-mail validation', 'post-smtp' ) ); } /** * Get the settings option array and print one of its values */ public function log_level_callback() { $inputDescription = sprintf( __( 'Log Level specifies the level of detail written to the WordPress Debug log - view the log with Debug.', 'post-smtp' ), 'https://codex.wordpress.org/Debugging_in_WordPress', 'https://wordpress.org/plugins/debug/' ); printf( '
%s', $inputDescription ); } public function notification_service_callback() { $inputDescription = __( 'Select the notification service you want to recieve alerts about failed emails.' ); printf( '
%s', $inputDescription ); } public function notification_use_chrome_callback() { $value = $this->options->useChromeExtension(); printf( '', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::NOTIFICATION_USE_CHROME, $value ? 'checked="checked"' : '' ); } public function notification_chrome_uid_callback() { printf( '', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::NOTIFICATION_CHROME_UID, PostmanUtils::obfuscatePassword( $this->options->getNotificationChromeUid() ) ); } public function pushover_user_callback() { printf( '', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::PUSHOVER_USER, $this->options->getPushoverUser() ); } public function pushover_token_callback() { printf( '', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::PUSHOVER_TOKEN, $this->options->getPushoverToken() ); } public function slack_token_callback() { printf( '', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::SLACK_TOKEN, $this->options->getSlackToken() ); echo '' . __( 'Get your webhook URL here', 'post-smtp' ) . ''; } private function printSelectOption( $label, $optionKey, $currentKey ) { $optionPattern = ''; printf( $optionPattern, $optionKey, $optionKey == $currentKey ? 'selected="selected"' : '', $label ); } public function runModeCallback() { $inputDescription = __( 'Delivery mode offers options useful for developing or testing.', 'post-smtp' ); printf( '
%s', $inputDescription ); } public function stealthModeCallback() { printf( ' %4$s', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::STEALTH_MODE, $this->options->isStealthModeEnabled() ? 'checked="checked"' : '', __( 'Remove the Postman X-Header signature from messages', 'post-smtp' ) ); } public function temporaryDirectoryCallback() { $inputDescription = __( 'Lockfiles are written here to prevent users from triggering an OAuth 2.0 token refresh at the same time.' ); printf( '', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::TEMPORARY_DIRECTORY, $this->options->getTempDirectory() ); if ( PostmanState::getInstance()->isFileLockingEnabled() ) { printf( ' %s
%s', __( 'Valid', 'post-smtp' ), $inputDescription ); } else { printf( ' %s
%s', __( 'Invalid', 'post-smtp' ), $inputDescription ); } } /** * Get the settings option array and print one of its values */ public function connection_timeout_callback() { printf( '', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::CONNECTION_TIMEOUT, $this->options->getConnectionTimeout() ); } /** * Get the settings option array and print one of its values */ public function read_timeout_callback() { printf( '', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::READ_TIMEOUT, $this->options->getReadTimeout() ); } /** * Get the settings option array and print one of its values */ public function port_callback( $args ) { printf( '', null !== $this->options->getPort() ? esc_attr( $this->options->getPort() ) : '', isset( $args ['style'] ) ? $args ['style'] : '', __( 'Required', 'post-smtp' ) ); } }