initial
This commit is contained in:
+24
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_SMTP\Connectors\Endpoints;
|
||||
|
||||
use Gravity_Forms\Gravity_Tools\Endpoints\Endpoint;
|
||||
|
||||
class Check_Background_Tasks_Endpoint extends Endpoint {
|
||||
|
||||
const ACTION_NAME = 'gravitysmtp_check_background_tasks';
|
||||
|
||||
protected $minimum_cap = 'manage_options';
|
||||
|
||||
protected function get_nonce_name() {
|
||||
return self::ACTION_NAME;
|
||||
}
|
||||
|
||||
public function handle() {
|
||||
if ( $this->validate() ) {
|
||||
echo 'ok';
|
||||
}
|
||||
die();
|
||||
}
|
||||
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_SMTP\Connectors\Endpoints;
|
||||
|
||||
use Gravity_Forms\Gravity_Tools\Endpoints\Endpoint;
|
||||
use Gravity_Forms\Gravity_SMTP\Users\Roles;
|
||||
|
||||
class Cleanup_Data_Endpoint extends Endpoint {
|
||||
|
||||
const PARAM_TARGET = 'target';
|
||||
|
||||
const ACTION_NAME = 'cleanup_data';
|
||||
|
||||
protected $minimum_cap = Roles::EDIT_INTEGRATIONS;
|
||||
|
||||
/**
|
||||
* @var Plugin_Opts_Data_Store;
|
||||
*/
|
||||
protected $data_store;
|
||||
|
||||
public function __construct( $data_store ) {
|
||||
$this->data_store = $data_store;
|
||||
}
|
||||
|
||||
protected function get_nonce_name() {
|
||||
return self::ACTION_NAME;
|
||||
}
|
||||
|
||||
private function reset_setup_wizard_data() {
|
||||
$this->data_store->save( Save_Plugin_Settings_Endpoint::PARAM_SETUP_WIZARD_SHOULD_DISPLAY, 'true' );
|
||||
$this->data_store->save( Save_Plugin_Settings_Endpoint::PARAM_LICENSE_KEY, '' );
|
||||
update_option( 'gravitysmtp_generic', '' );
|
||||
update_option( 'gravitysmtp_mailgun', '' );
|
||||
update_option( 'gravitysmtp_postmark', '' );
|
||||
update_option( 'gravitysmtp_sendgrid', '' );
|
||||
|
||||
wp_send_json_success( __( 'Setup wizard data reset.', 'gravitysmtp' ) );
|
||||
}
|
||||
|
||||
public function handle() {
|
||||
if ( ! $this->validate() ) {
|
||||
wp_send_json_error( __( 'Missing required parameters.', 'gravitysmtp' ), 400 );
|
||||
}
|
||||
|
||||
$target = filter_input( INPUT_POST, self::PARAM_TARGET );
|
||||
$target = htmlspecialchars( $target );
|
||||
|
||||
// handle data clean up or resets here
|
||||
|
||||
switch( $target ) {
|
||||
case 'setup_wizard':
|
||||
$this->reset_setup_wizard_data();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function validate() {
|
||||
if ( ! parent::validate() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $_REQUEST[ self::PARAM_TARGET ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_SMTP\Connectors\Endpoints;
|
||||
|
||||
use Gravity_Forms\Gravity_Tools\Endpoints\Endpoint;
|
||||
use Gravity_Forms\Gravity_SMTP\Models\Notifications_Model;
|
||||
use Gravity_Forms\Gravity_SMTP\Users\Roles;
|
||||
|
||||
class Get_Connector_Emails extends Endpoint {
|
||||
|
||||
const PARAM_CONNECTOR_NAME = 'connector_name';
|
||||
|
||||
const ACTION_NAME = 'get_connector_emails';
|
||||
|
||||
/**
|
||||
* @var Notifications_Model
|
||||
*/
|
||||
protected $notifications;
|
||||
|
||||
protected $minimum_cap = Roles::VIEW_NOTIFICATIONS_SETTINGS;
|
||||
|
||||
protected $required_params = array(
|
||||
self::PARAM_CONNECTOR_NAME,
|
||||
);
|
||||
|
||||
public function __construct( $notifications ) {
|
||||
$this->notifications = $notifications;
|
||||
}
|
||||
|
||||
protected function get_nonce_name() {
|
||||
return self::ACTION_NAME;
|
||||
}
|
||||
|
||||
public function handle() {
|
||||
if ( ! $this->validate() ) {
|
||||
wp_send_json_error( __( 'Missing required parameters.', 'gravitysmtp' ), 400 );
|
||||
}
|
||||
|
||||
$connector = rgpost( self::PARAM_CONNECTOR_NAME );
|
||||
$notifications_for_connector = $this->notifications->by_service( $connector );
|
||||
$emails = array();
|
||||
|
||||
if ( empty( $notifications_for_connector ) ) {
|
||||
wp_send_json_success( $emails );
|
||||
}
|
||||
|
||||
$notifications_for_connector = array_map( function ( $row ) use ( $connector ) {
|
||||
$notifications = rgar( $row, 'notifications' );
|
||||
$notifications = json_decode( $notifications, true );
|
||||
|
||||
$filtered = array_filter( $notifications, function ( $notification ) use ( $connector ) {
|
||||
return rgar( $notification, 'service' ) == $connector && is_email( rgar( $notification, 'from' ) );
|
||||
} );
|
||||
|
||||
return array_values( wp_list_pluck( $filtered, 'from' ) );
|
||||
}, $notifications_for_connector );
|
||||
|
||||
foreach ( $notifications_for_connector as $found_emails ) {
|
||||
$emails = array_merge( $emails, $found_emails );
|
||||
}
|
||||
|
||||
wp_send_json_success( $emails );
|
||||
}
|
||||
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_SMTP\Connectors\Endpoints;
|
||||
|
||||
use Gravity_Forms\Gravity_SMTP\Logging\Debug\Debug_Logger;
|
||||
use Gravity_Forms\Gravity_SMTP\Models\Event_Model;
|
||||
use Gravity_Forms\Gravity_SMTP\Models\Log_Details_Model;
|
||||
use Gravity_Forms\Gravity_SMTP\Users\Roles;
|
||||
use Gravity_Forms\Gravity_Tools\Endpoints\Endpoint;
|
||||
|
||||
class Get_Single_Email_Data_Endpoint extends Endpoint {
|
||||
|
||||
const PARAM_EVENT_ID = 'event_id';
|
||||
|
||||
const ACTION_NAME = 'get_single_email';
|
||||
|
||||
protected $minimum_cap = Roles::VIEW_EMAIL_LOG_DETAILS;
|
||||
|
||||
/**
|
||||
* @var Log_Details_Model
|
||||
*/
|
||||
protected $logs;
|
||||
|
||||
/**
|
||||
* @var Event_Model
|
||||
*/
|
||||
protected $emails;
|
||||
|
||||
protected $required_params = array(
|
||||
self::PARAM_EVENT_ID,
|
||||
);
|
||||
|
||||
public function __construct( $logs, $email ) {
|
||||
$this->logs = $logs;
|
||||
$this->emails = $email;
|
||||
}
|
||||
|
||||
protected function get_nonce_name() {
|
||||
return self::ACTION_NAME;
|
||||
}
|
||||
|
||||
public function handle() {
|
||||
if ( ! $this->validate() ) {
|
||||
wp_send_json_error( __( 'Missing required parameters.', 'gravitysmtp' ), 400 );
|
||||
}
|
||||
|
||||
$email = filter_input( INPUT_POST, self::PARAM_EVENT_ID, FILTER_SANITIZE_NUMBER_INT );
|
||||
|
||||
$data = $this->data( $email );
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
wp_send_json_success( $data );
|
||||
}
|
||||
|
||||
Debug_Logger::log_message(
|
||||
sprintf(
|
||||
/* translators: %d: event ID */
|
||||
__( 'Error retrieving data for event ID: %d.', 'gravitysmtp' ),
|
||||
$email
|
||||
),
|
||||
'error'
|
||||
);
|
||||
|
||||
wp_send_json_error(
|
||||
/* translators: %d: email ID */
|
||||
sprintf( __( 'Could not send get data for event ID: %d.', 'gravitysmtp' ), $email ),
|
||||
500
|
||||
);
|
||||
}
|
||||
|
||||
private function get_i18n() {
|
||||
return array(
|
||||
'error_alert_title' => esc_html__( 'Error Saving', 'gravitysmtp' ),
|
||||
'error_alert_generic_message' => esc_html__( 'Could not save; please check your logs.', 'gravitysmtp' ),
|
||||
'error_alert_close_text' => esc_html__( 'Close', 'gravitysmtp' ),
|
||||
'log_detail' => array(
|
||||
'top_heading' => esc_html__( 'View Email', 'gravitysmtp' ),
|
||||
'top_content' => esc_html__( 'Detailed log information for this email.', 'gravitysmtp' ),
|
||||
'action_button_view_email_label' => esc_html__( 'View Email', 'gravitysmtp' ),
|
||||
'action_button_resend_label' => esc_html__( 'Resend', 'gravitysmtp' ),
|
||||
'action_button_print_label' => esc_html__( 'Print', 'gravitysmtp' ),
|
||||
'action_button_export_label' => esc_html__( 'Export', 'gravitysmtp' ),
|
||||
'action_button_delete_label' => esc_html__( 'Delete Log Entry', 'gravitysmtp' ),
|
||||
'main_box_heading' => esc_html__( 'Email Log', 'gravitysmtp' ),
|
||||
'main_box_created_label' => esc_html__( 'Created', 'gravitysmtp' ),
|
||||
'main_box_from_label' => esc_html__( 'From', 'gravitysmtp' ),
|
||||
'main_box_to_label' => esc_html__( 'To', 'gravitysmtp' ),
|
||||
'main_box_subject_label' => esc_html__( 'Subject', 'gravitysmtp' ),
|
||||
'secondary_box_heading' => esc_html__( 'Technical Information', 'gravitysmtp' ),
|
||||
'sidebar_heading' => esc_html__( 'Status', 'gravitysmtp' ),
|
||||
'sidebar_status_label' => esc_html__( 'Status', 'gravitysmtp' ),
|
||||
'sidebar_date_service_label' => esc_html__( 'Service:', 'gravitysmtp' ),
|
||||
'sidebar_has_attachment_label' => esc_html__( 'Has attachment:', 'gravitysmtp' ),
|
||||
'sidebar_log_is_label' => esc_html__( 'Log ID:', 'gravitysmtp' ),
|
||||
'sidebar_source_label' => esc_html__( 'Source:', 'gravitysmtp' ),
|
||||
'sidebar_attachments_heading' => esc_html__( 'Attachments', 'gravitysmtp' ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function get_log_details( $id ) {
|
||||
return $this->logs->full_details( $id );
|
||||
}
|
||||
|
||||
public function data( $email_id ) {
|
||||
$details = $this->get_log_details( $email_id );
|
||||
|
||||
if ( empty( $details ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
return array(
|
||||
'log_detail' => $details,
|
||||
'i18n' => $this->get_i18n(),
|
||||
'endpoints' => array(),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_SMTP\Connectors\Endpoints;
|
||||
|
||||
use Gravity_Forms\Gravity_SMTP\Connectors\Connector_Base;
|
||||
use Gravity_Forms\Gravity_SMTP\Connectors\Connector_Factory;
|
||||
use Gravity_Forms\Gravity_SMTP\Logging\Debug\Debug_Logger;
|
||||
use Gravity_Forms\Gravity_SMTP\Data_Store\Plugin_Opts_Data_Store;
|
||||
use Gravity_Forms\Gravity_SMTP\Users\Roles;
|
||||
use Gravity_Forms\Gravity_Tools\Endpoints\Endpoint;
|
||||
|
||||
class Save_Connector_Settings_Endpoint extends Endpoint {
|
||||
|
||||
const PARAM_SETTINGS = 'settings';
|
||||
const PARAM_CONNECTOR_TYPE = 'connector_type';
|
||||
const PARAM_NO_VALIDATE = 'no_validate';
|
||||
|
||||
const SETTING_ENABLED_CONNECTOR = 'enabled_connector';
|
||||
const SETTING_PRIMARY_CONNECTOR = 'primary_connector';
|
||||
const SETTING_BACKUP_CONNECTOR = 'backup_connector';
|
||||
|
||||
const ACTION_NAME = 'save_connector_settings';
|
||||
|
||||
protected $minimum_cap = Roles::EDIT_INTEGRATIONS;
|
||||
|
||||
/**
|
||||
* @var Connector_Factory $connector_factory
|
||||
*/
|
||||
protected $connector_factory;
|
||||
|
||||
/**
|
||||
* @var Opts_Data_Store;
|
||||
*/
|
||||
protected $data_store;
|
||||
|
||||
/**
|
||||
* @var Plugin_Opts_Data_Store
|
||||
*/
|
||||
protected $plugin_data_store;
|
||||
|
||||
protected $required_params = array(
|
||||
self::PARAM_SETTINGS,
|
||||
self::PARAM_CONNECTOR_TYPE,
|
||||
);
|
||||
|
||||
public function __construct( $data_store, $plugin_data_store, $connector_factory ) {
|
||||
$this->data_store = $data_store;
|
||||
$this->plugin_data_store = $plugin_data_store;
|
||||
$this->connector_factory = $connector_factory;
|
||||
}
|
||||
|
||||
protected function get_nonce_name() {
|
||||
return self::ACTION_NAME;
|
||||
}
|
||||
|
||||
public function handle() {
|
||||
if ( ! $this->validate() ) {
|
||||
wp_send_json_error( __( 'Missing required parameters.', 'gravitysmtp' ), 400 );
|
||||
}
|
||||
|
||||
$settings = filter_input( INPUT_POST, self::PARAM_SETTINGS, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
||||
$type = filter_input( INPUT_POST, self::PARAM_CONNECTOR_TYPE );
|
||||
$no_validate = filter_has_var( INPUT_POST, self::PARAM_NO_VALIDATE );
|
||||
$type = htmlspecialchars( $type );
|
||||
$configured_key = sprintf( 'gsmtp_connector_configured_%s', $type );
|
||||
|
||||
$this->data_store->save_all( $settings, $type );
|
||||
delete_transient( $configured_key );
|
||||
|
||||
// Only continue if this connector needs to be validated/enabled in some way.
|
||||
if (
|
||||
! isset( $settings[ Connector_Base::SETTING_ENABLED ] ) &&
|
||||
! isset( $settings[ Connector_Base::SETTING_IS_PRIMARY ] ) &&
|
||||
! isset( $settings[ Connector_Base::SETTING_IS_BACKUP ] )
|
||||
) {
|
||||
wp_send_json_success( $settings );
|
||||
}
|
||||
|
||||
if ( isset( $settings[ Connector_Base::SETTING_ENABLED ] ) ) {
|
||||
$this->save_connector_status( $type, self::SETTING_ENABLED_CONNECTOR, $settings[ Connector_Base::SETTING_ENABLED ] );
|
||||
}
|
||||
|
||||
if ( isset( $settings[ Connector_Base::SETTING_IS_PRIMARY ] ) ) {
|
||||
$this->save_connector_status( $type, self::SETTING_PRIMARY_CONNECTOR, $settings[ Connector_Base::SETTING_IS_PRIMARY ] );
|
||||
}
|
||||
|
||||
if ( isset( $settings[ Connector_Base::SETTING_IS_BACKUP ] ) ) {
|
||||
$this->save_connector_status( $type, self::SETTING_BACKUP_CONNECTOR, $settings[ Connector_Base::SETTING_IS_BACKUP ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @var Connector_Base $connector
|
||||
*/
|
||||
$connector = $this->connector_factory->create( $type );
|
||||
$valid = $no_validate ? true : $connector->is_configured();
|
||||
|
||||
if ( is_wp_error( $valid ) ) {
|
||||
$error_message = $valid->get_error_message();
|
||||
Debug_Logger::log_message( sprintf(
|
||||
/* translators: %1$s is the connector, eg: SendGrid, %2$s is the error message */
|
||||
__( 'Error saving settings for %1$s: %2$s', 'gravitysmtp' ),
|
||||
$type,
|
||||
$error_message
|
||||
), 'error' );
|
||||
wp_send_json_error( $error_message, 500 );
|
||||
}
|
||||
|
||||
wp_send_json_success( $settings );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a connector's status (enabled, primary, backup) in the settings array.
|
||||
*
|
||||
* @param $type
|
||||
* @param $status_type
|
||||
* @param $enabled
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function save_connector_status( $type, $status_type, $enabled ) {
|
||||
$connector_values = $this->plugin_data_store->get( $status_type, array() );
|
||||
|
||||
if ( ! is_array( $connector_values ) ) {
|
||||
$connector_values = array();
|
||||
}
|
||||
|
||||
$connector_values[ $type ] = $enabled;
|
||||
$this->plugin_data_store->save( $status_type, $connector_values );
|
||||
}
|
||||
|
||||
}
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_SMTP\Connectors\Endpoints;
|
||||
|
||||
use Gravity_Forms\Gravity_SMTP\Users\Roles;
|
||||
use Gravity_Forms\Gravity_Tools\Endpoints\Endpoint;
|
||||
use Gravity_Forms\Gravity_Tools\License\License_Statuses;
|
||||
|
||||
class Save_Plugin_Settings_Endpoint extends Endpoint {
|
||||
|
||||
const PARAM_SETTINGS = 'settings';
|
||||
const PARAM_SETTING_KEY = 'key';
|
||||
const PARAM_SETTING_VALUE = 'value';
|
||||
|
||||
const PARAM_LICENSE_KEY = 'license_key';
|
||||
const PARAM_TEST_MODE = 'test_mode';
|
||||
const PARAM_EVENT_LOG_ENABLED = 'event_log_enabled';
|
||||
const PARAM_SAVE_EMAIL_BODY_ENABLED = 'save_email_body_enabled';
|
||||
const PARAM_SAVE_ATTACHMENTS_ENABLED = 'save_attachments_enabled';
|
||||
const PARAM_EVENT_LOG_RETENTION = 'event_log_retention';
|
||||
const PARAM_DEBUG_LOG_ENABLED = 'debug_log_enabled';
|
||||
const PARAM_DEBUG_LOG_RETENTION = 'debug_log_retention';
|
||||
const PARAM_USAGE_ANALYTICS = 'usage_analytics';
|
||||
const PARAM_PER_PAGE = 'activity_log_per_page';
|
||||
const PARAM_MAX_EVENT_RECORDS = 'max_event_records';
|
||||
const PARAM_NOTIFY_WHEN_EMAIL_SENDING_FAILS_ENABLED = 'notify_when_email_sending_fails_enabled';
|
||||
const PARAM_SLACK_ALERTS_ENABLED = 'slack_alerts_enabled';
|
||||
const PARAM_TWILIO_ALERTS_ENABLED = 'twilio_alerts_enabled';
|
||||
|
||||
const PARAM_NOTIFICATIONS_EMAIL_DIGEST_ENABLED = 'notifications_email_digest_enabled';
|
||||
const PARAM_NOTIFICATIONS_EMAIL_DIGEST_FREQUENCY = 'notifications_email_digest_frequency';
|
||||
|
||||
const PARAM_SETUP_WIZARD_SHOULD_DISPLAY = 'setup_wizard_should_display';
|
||||
|
||||
const ACTION_NAME = 'save_plugin_settings';
|
||||
|
||||
protected $minimum_cap = Roles::EDIT_GENERAL_SETTINGS;
|
||||
|
||||
/**
|
||||
* @var Plugin_Opts_Data_Store;
|
||||
*/
|
||||
protected $data_store;
|
||||
|
||||
/**
|
||||
* @var License_API_Connector;
|
||||
*/
|
||||
protected $api_connector;
|
||||
|
||||
protected $required_params = array();
|
||||
|
||||
public function __construct( $data_store, $api_connector ) {
|
||||
$this->data_store = $data_store;
|
||||
$this->api_connector = $api_connector;
|
||||
}
|
||||
|
||||
protected function get_nonce_name() {
|
||||
return self::ACTION_NAME;
|
||||
}
|
||||
|
||||
public function handle() {
|
||||
if ( ! $this->validate() ) {
|
||||
wp_send_json_error( __( 'Request must contain either an array of values to update, or a key and value to update individually.', 'gravitysmtp' ), 400 );
|
||||
}
|
||||
|
||||
$settings = filter_input( INPUT_POST, self::PARAM_SETTINGS, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
||||
|
||||
if ( ! empty( $settings ) ) {
|
||||
$this->handle_bulk_settings( $settings );
|
||||
} else {
|
||||
$this->handle_individual_setting();
|
||||
}
|
||||
}
|
||||
|
||||
protected function handle_bulk_settings( $settings ) {
|
||||
$this->data_store->save_all( $settings );
|
||||
$data = $settings;
|
||||
|
||||
if ( isset( $settings[ self::PARAM_LICENSE_KEY ] ) ) {
|
||||
$data = array_merge( $data, $this->handle_license_key( $settings[ self::PARAM_LICENSE_KEY ] ) );
|
||||
}
|
||||
|
||||
wp_send_json_success( $data );
|
||||
}
|
||||
|
||||
protected function handle_individual_setting() {
|
||||
$key = htmlspecialchars( filter_input( INPUT_POST, self::PARAM_SETTING_KEY ) );
|
||||
$value = isset( $_POST[ self::PARAM_SETTING_VALUE ] ) ? $_POST[ self::PARAM_SETTING_VALUE ] : null;
|
||||
|
||||
if ( is_array( $value ) ) {
|
||||
$value = filter_input( INPUT_POST, self::PARAM_SETTING_VALUE, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
||||
} else {
|
||||
$value = htmlspecialchars( $value );
|
||||
}
|
||||
|
||||
switch ( $key ) {
|
||||
case self::PARAM_LICENSE_KEY:
|
||||
$data = $this->handle_license_key_setting( $key, $value );
|
||||
break;
|
||||
default:
|
||||
$this->data_store->save( $key, $value );
|
||||
$data = array( $key => $value );
|
||||
break;
|
||||
}
|
||||
|
||||
do_action( 'gravitysmtp_save_plugin_setting', $key, $value );
|
||||
|
||||
wp_send_json_success( $data );
|
||||
}
|
||||
|
||||
protected function handle_license_key_setting( $key, $value ) {
|
||||
$this->data_store->save( $key, $value );
|
||||
$data = array( $key => $value );
|
||||
|
||||
return array_merge( $data, $this->handle_license_key( $value ) );
|
||||
}
|
||||
|
||||
protected function handle_license_key( $license_key ) {
|
||||
$key_is_empty = empty( $license_key );
|
||||
|
||||
if ( $key_is_empty ) {
|
||||
return array( 'license_is_valid' => null );
|
||||
}
|
||||
|
||||
$license_info = $this->api_connector->check_license( $license_key );
|
||||
|
||||
return array( 'license_is_valid' => License_Statuses::VALID_KEY === $license_info->get_status() );
|
||||
}
|
||||
|
||||
protected function validate() {
|
||||
if ( ! parent::validate() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
! isset( $_REQUEST[ self::PARAM_SETTINGS ] ) &&
|
||||
( ! isset( $_REQUEST[ self::PARAM_SETTING_KEY ] ) || ! isset( $_REQUEST[ self::PARAM_SETTING_VALUE ] ) )
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+258
@@ -0,0 +1,258 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_SMTP\Connectors\Endpoints;
|
||||
|
||||
use Gravity_Forms\Gravity_SMTP\Connectors\Connector_Factory;
|
||||
use Gravity_Forms\Gravity_SMTP\Data_Store\Plugin_Opts_Data_Store;
|
||||
use Gravity_Forms\Gravity_SMTP\Logging\Debug\Debug_Logger;
|
||||
use Gravity_Forms\Gravity_SMTP\Models\Event_Model;
|
||||
use Gravity_Forms\Gravity_SMTP\Models\Log_Details_Model;
|
||||
use Gravity_Forms\Gravity_SMTP\Users\Roles;
|
||||
use Gravity_Forms\Gravity_Tools\Endpoints\Endpoint;
|
||||
|
||||
class Send_Test_Endpoint extends Endpoint {
|
||||
|
||||
const PARAM_EMAIL = 'email';
|
||||
const PARAM_CONNECTOR_TYPE = 'connector_type';
|
||||
const PARAM_AS_HTML = 'as_html';
|
||||
const PARAM_FROM_EMAIL = 'from_email';
|
||||
|
||||
const ACTION_NAME = 'send_test';
|
||||
|
||||
protected $minimum_cap = Roles::VIEW_TOOLS_SENDATEST;
|
||||
|
||||
public $last_email_id = 0;
|
||||
|
||||
/**
|
||||
* @var Connector_Factory $connector_factory
|
||||
*/
|
||||
protected $connector_factory;
|
||||
|
||||
/**
|
||||
* @var Plugin_Opts_Data_Store
|
||||
*/
|
||||
protected $plugin_data;
|
||||
|
||||
/**
|
||||
* @var Event_Model
|
||||
*/
|
||||
protected $emails;
|
||||
|
||||
/**
|
||||
* @var Log_Details_Model
|
||||
*/
|
||||
protected $logs;
|
||||
|
||||
/**
|
||||
* @var Get_Single_Email_Data_Endpoint
|
||||
*/
|
||||
protected $email_endpoint;
|
||||
|
||||
protected $required_params = array(
|
||||
self::PARAM_EMAIL,
|
||||
self::PARAM_CONNECTOR_TYPE,
|
||||
self::PARAM_AS_HTML,
|
||||
self::PARAM_FROM_EMAIL,
|
||||
);
|
||||
|
||||
public function __construct( $connector_factory, $plugin_data_store, $emails_model, $log_model, $email_endpoint ) {
|
||||
$this->connector_factory = $connector_factory;
|
||||
$this->plugin_data = $plugin_data_store;
|
||||
$this->emails = $emails_model;
|
||||
$this->logs = $log_model;
|
||||
$this->email_endpoint = $email_endpoint;
|
||||
}
|
||||
|
||||
protected function get_nonce_name() {
|
||||
return self::ACTION_NAME;
|
||||
}
|
||||
|
||||
protected function get_test_email_markup( $as_html ) {
|
||||
if ( empty( $as_html ) ) {
|
||||
return esc_html__( 'Test Successful', 'gravitysmtp' ) . "\r\n\r\n" .
|
||||
esc_html__( 'Congratulations! Gravity SMTP is sending emails correctly!', 'gravitysmtp' ) . "\r\n" .
|
||||
esc_html__( 'Gravity SMTP is taking care of sending your emails, so now you can focus on the content of your emails and leave the technical details to us.', 'gravitysmtp' );
|
||||
}
|
||||
|
||||
$image_base_url = \Gravity_Forms\Gravity_SMTP\Gravity_SMTP::get_base_url() . '/assets/images/email-templates/';
|
||||
|
||||
return '<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Email Template</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background: #fff;
|
||||
font-family: inter, -apple-system, blinkmacsystemfont, \'Segoe UI\', roboto, oxygen-sans, ubuntu, cantarell, \'Helvetica Neue\', sans-serif;
|
||||
}
|
||||
|
||||
img {
|
||||
border: 0 none;
|
||||
height: auto;
|
||||
line-height: 100%;
|
||||
outline: none;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a img {
|
||||
border: 0 none;
|
||||
}
|
||||
|
||||
table, td {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
#bodyTable {
|
||||
height: 100% !important;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: 100% !important;
|
||||
}
|
||||
.wrapper {
|
||||
max-width: 680px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.content {
|
||||
padding: 20px 20px 200px;
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 480px) {
|
||||
.content {
|
||||
padding: 20px 20px 120px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table id="bodyTable" role="presentation" width="100%" align="center"
|
||||
style="background: url(\'' . $image_base_url . 'gravitysmtp-arrow-bg.png\') no-repeat top right / 514px 647px #fff; margin: 0;">
|
||||
<tr>
|
||||
<td>
|
||||
<table class="wrapper" role="presentation">
|
||||
<!-- Header with Logo -->
|
||||
<tr>
|
||||
<td style="padding: 70px 20px 32px; text-align: center;">
|
||||
<img src="' . $image_base_url . 'gravitysmtp-email-logo.png" alt="' . esc_html__( 'Logo', 'gravitysmtp' ) . '"
|
||||
style="display: block; margin: 0 auto; max-width: 200px">
|
||||
</td>
|
||||
</tr>
|
||||
<!-- Content Area -->
|
||||
<tr>
|
||||
<td class="content">
|
||||
<img src="' . $image_base_url . 'send-test/gravitysmtp-success.png" alt="' . esc_html__( 'Mail Icon', 'gravitysmtp' ) . '"
|
||||
style="display: block; margin: 0 auto; max-width: 308px">
|
||||
<h1 style="color: #242748; text-align: center; font-family: inter, -apple-system, blinkmacsystemfont, \'Segoe UI\', roboto, oxygen-sans, ubuntu, cantarell, \'Helvetica Neue\', sans-serif; font-size: 30px; font-style: normal; font-weight: 600; line-height: 30px; padding: 20px 0 32px; margin: 0;">' . esc_html__( 'Test Successful', 'gravitysmtp' ) . '</h1>
|
||||
<div
|
||||
style="border-radius: 3px; border: 1px solid #d5d7e9; box-shadow: 0px 2px 2px 0px rgba(58, 58, 87, 0.06);">
|
||||
<p style="margin: 0; padding: 12px 24px; background: #f6f9fc; font-family: inter, -apple-system, blinkmacsystemfont, \'Segoe UI\', roboto, oxygen-sans, ubuntu, cantarell, \'Helvetica Neue\', sans-serif; border-bottom: 1px solid #d5d7e9; color: #242748; font-size: 14px; font-style: normal; font-weight: 500; line-height: 18px;">' . esc_html__( 'Congratulations! Gravity SMTP is sending emails correctly!', 'gravitysmtp' ) . '</p>
|
||||
<p style="color: #5b5e80; background: #fff; margin: 0; padding: 16px 24px; font-family: inter, -apple-system, blinkmacsystemfont, \'Segoe UI\', roboto, oxygen-sans, ubuntu, cantarell, \'Helvetica Neue\', sans-serif; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px">' . esc_html__( 'Gravity SMTP is taking care of sending your emails, so now you can focus on the content of your emails and leave the technical details to us.', 'gravitysmtp' ) . '</p>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>';
|
||||
}
|
||||
|
||||
public function handle() {
|
||||
if ( ! $this->validate() ) {
|
||||
wp_send_json_error( __( 'Missing required parameters.', 'gravitysmtp' ), 400 );
|
||||
}
|
||||
|
||||
$this->override_error_handling();
|
||||
|
||||
$self = $this;
|
||||
|
||||
add_action( 'gravitysmtp_after_mail_created', function( $created_id ) use ( $self ) {
|
||||
$self->last_email_id = $created_id;
|
||||
}, 10, 1 );
|
||||
|
||||
$email = filter_input( INPUT_POST, self::PARAM_EMAIL, FILTER_SANITIZE_EMAIL );
|
||||
$connector = filter_input( INPUT_POST, self::PARAM_CONNECTOR_TYPE );
|
||||
$as_html = filter_input( INPUT_POST, self::PARAM_AS_HTML );
|
||||
$from_email = filter_input( INPUT_POST, self::PARAM_FROM_EMAIL, FILTER_SANITIZE_EMAIL );
|
||||
|
||||
$connector = htmlspecialchars( $connector );
|
||||
$as_html = htmlspecialchars( $as_html ) !== 'false';
|
||||
$from_email = $from_email ? $from_email : get_option( 'admin_email' );
|
||||
|
||||
$content_type = $as_html ? 'text/html' : 'text/plain';
|
||||
|
||||
$headers = array(
|
||||
'content-type' => 'Content-type: ' . $content_type,
|
||||
'from' => 'From: ' . $from_email,
|
||||
);
|
||||
|
||||
add_filter( 'gravitysmtp_connector_for_sending', function( $current_connector, $email_args ) use ( $connector ) {
|
||||
return array( 'force' => true, 'connector' => $connector );
|
||||
}, 8, 2 );
|
||||
|
||||
$success = wp_mail( array( 'email' => $email ), __( 'Test Email from Gravity SMTP', 'gravitysmtp' ), $this->get_test_email_markup( $as_html ), $headers, array() );
|
||||
|
||||
if ( $success === true ) {
|
||||
wp_send_json_success( array( 'email' => $email ) );
|
||||
}
|
||||
|
||||
$full_log = $this->get_full_log_data( $this->last_email_id );
|
||||
$issues = array();
|
||||
$log_copy = '';
|
||||
|
||||
if ( isset( $full_log['technical_information'] ) && is_array( $full_log['technical_information']['log'] ) ) {
|
||||
array_push( $issues, end( $full_log['technical_information']['log'] ) );
|
||||
$log_copy = implode( "\r\n", $full_log['technical_information']['log'] );
|
||||
}
|
||||
|
||||
$reasons = array();
|
||||
$steps = array();
|
||||
|
||||
if ( empty( $issues ) ) {
|
||||
$reasons = array(
|
||||
__( 'Incorrect plugin settings, such as invalid SMTP credentials or expired API key.', 'gravitysmtp' ),
|
||||
__( 'The SMTP server blocking the incoming connection.', 'gravitysmtp' ),
|
||||
__( 'Your web host rejecting the connection.', 'gravitysmtp' ),
|
||||
);
|
||||
|
||||
$steps = array(
|
||||
__( 'Triple check the plugin settings and ensure they are accurate, especially if you copy-pasted the values.', 'gravitysmtp' ),
|
||||
__( 'Contact your web hosting provider to verify if your server allows outside connections and if any firewall or security policies are in place that could interfere.', 'gravitysmtp' ),
|
||||
__( 'Consider using one of the other available integration types.', 'gravitysmtp' ),
|
||||
);
|
||||
}
|
||||
|
||||
$error_data = array(
|
||||
'error_message' => __( 'There was a problem sending the test email.', 'gravitysmtp' ),
|
||||
'issues' => $issues,
|
||||
'full_log' => $full_log,
|
||||
'log_copy' => $log_copy,
|
||||
'possible_reasons' => $reasons,
|
||||
'recommended_steps' => $steps,
|
||||
);
|
||||
|
||||
Debug_Logger::log_message(
|
||||
sprintf(
|
||||
__( 'Send a test error: %1$s', 'gravitysmtp' ),
|
||||
json_encode( $error_data )
|
||||
),
|
||||
'error'
|
||||
);
|
||||
|
||||
wp_send_json_error( $error_data, 500 );
|
||||
}
|
||||
|
||||
private function override_error_handling() {
|
||||
ini_set( 'display_errors', 0 );
|
||||
unset( $GLOBALS['wp_locale'] );
|
||||
}
|
||||
|
||||
private function get_full_log_data( $email_id ) {
|
||||
return $this->email_endpoint->get_log_details( $email_id );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user