| 1 |
<?php |
| 2 |
|
| 3 |
namespace EmailKit\Promotional\Onboard; |
| 4 |
|
| 5 |
use \EmailKit\Traits\Singleton; |
| 6 |
use \EmailKit\Promotional\Onboard\Classes\PluginDataSender; |
| 7 |
use \EmailKit\Promotional\Util; |
| 8 |
|
| 9 |
defined( 'ABSPATH' ) || exit; |
| 10 |
|
| 11 |
class Onboard { |
| 12 |
|
| 13 |
use Singleton; |
| 14 |
protected $optionKey = 'emailkit_onboard_status'; |
| 15 |
protected $optionValue = 'onboarded'; |
| 16 |
|
| 17 |
const CONTACT_LIST_ID = 2; |
| 18 |
const ENVIRONMENT_ID = 2; |
| 19 |
|
| 20 |
public function views() { |
| 21 |
?> |
| 22 |
<div class="emailkit-onboard-dashboard"> |
| 23 |
<div class="emailkit_container"> |
| 24 |
<form action="" method="POST" id="emailkit-admin-settings-form"> |
| 25 |
<?php |
| 26 |
include self::get_dir().'views/layout-onboard.php'; |
| 27 |
?> |
| 28 |
</form> |
| 29 |
</div> |
| 30 |
</div> |
| 31 |
<?php |
| 32 |
} |
| 33 |
|
| 34 |
public static function get_dir() { |
| 35 |
return EMAILKIT_DIR . 'Promotional/Onboard/'; |
| 36 |
} |
| 37 |
|
| 38 |
public static function get_url(){ |
| 39 |
return EMAILKIT_URL . 'Promotional/Onboard/'; |
| 40 |
} |
| 41 |
|
| 42 |
public function init() { |
| 43 |
|
| 44 |
new Classes\Ajax; |
| 45 |
|
| 46 |
if ( get_option( $this->optionKey ) ) { |
| 47 |
//phpcs:disable WordPress.Security.NonceVerification -- its just checking emailkit-onboard-steps is finished or not. |
| 48 |
if(isset($_GET['emailkit-onboard-steps'])) { |
| 49 |
wp_safe_redirect($this->get_plugin_url()); |
| 50 |
} |
| 51 |
return true; |
| 52 |
} |
| 53 |
|
| 54 |
add_action('emailkit/admin/after_save', [$this, 'ajax_action']); |
| 55 |
|
| 56 |
$param = isset( $_GET['emailkit-onboard-steps'] ) ? sanitize_text_field(wp_unslash($_GET['emailkit-onboard-steps'])) : null; |
| 57 |
$requestUri = ( isset( $_GET['post_type'] ) ? sanitize_text_field(wp_unslash($_GET['post_type'])) : '' ) . ( isset( $_GET['page'] ) ? sanitize_text_field(wp_unslash($_GET['page'])) : '' ); |
| 58 |
//phpcs:enable |
| 59 |
if ( strpos( $requestUri, 'emailkit' ) !== false && is_admin() ) { |
| 60 |
if ( $param !== 'loaded' && ! get_option( $this->optionKey ) ) { |
| 61 |
wp_safe_redirect( $this->get_onboard_url() ); |
| 62 |
exit; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
return true; |
| 67 |
} |
| 68 |
|
| 69 |
public function ajax_action(){ |
| 70 |
$this->finish_onboard(); |
| 71 |
if( isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])),'ajax-nonce')){ |
| 72 |
|
| 73 |
if ( isset( $_POST['settings']['tut_term'] ) && sanitize_text_field(wp_unslash($_POST['settings']['tut_term'])) == 'user_agreed' ) { |
| 74 |
PluginDataSender::instance()->send( 'diagnostic-data' ); // send non-sensitive diagnostic data and details about plugin usage. |
| 75 |
} |
| 76 |
|
| 77 |
if ( isset( $_POST['settings']['newsletter_email'] ) && !empty($_POST['settings']['newsletter_email'])) { |
| 78 |
$data = [ |
| 79 |
'email' => sanitize_text_field(wp_unslash($_POST['settings']['newsletter_email'])), |
| 80 |
'environment_id' => Onboard::ENVIRONMENT_ID, |
| 81 |
'contact_list_id' => Onboard::CONTACT_LIST_ID, |
| 82 |
]; |
| 83 |
|
| 84 |
$response = PluginDataSender::instance()->sendAutomizyData( 'email-subscribe', $data); |
| 85 |
Util::emailkit_content_renderer(print_r($response)); |
| 86 |
exit; |
| 87 |
} |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
private function get_onboard_url() { |
| 92 |
return add_query_arg( |
| 93 |
array( |
| 94 |
'page' => 'emailkit-menu-settings', |
| 95 |
'emailkit-onboard-steps' => 'loaded', |
| 96 |
'emailkit-onboard-steps-nonce' => wp_create_nonce('emailkit-onboard-steps-action') |
| 97 |
), |
| 98 |
admin_url( 'admin.php' ) |
| 99 |
); |
| 100 |
} |
| 101 |
|
| 102 |
public function redirect_onboard() { |
| 103 |
if (is_null(get_option( $this->optionKey ) )) { |
| 104 |
wp_safe_redirect( $this->get_onboard_url() ); |
| 105 |
exit; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
private static function get_plugin_url() { |
| 110 |
return add_query_arg( |
| 111 |
array( |
| 112 |
'page' => 'emailkit-menu-settings', |
| 113 |
), |
| 114 |
admin_url( 'admin.php' ) |
| 115 |
); |
| 116 |
} |
| 117 |
|
| 118 |
public function finish_onboard() { |
| 119 |
if ( ! get_option( $this->optionKey ) ) { |
| 120 |
add_option( $this->optionKey, $this->optionValue ); |
| 121 |
} |
| 122 |
} |
| 123 |
} |