AbstractAutomationEmbed.php
5 months ago
Automation.php
2 years ago
AutomationAnalytics.php
2 months ago
AutomationEditor.php
2 months ago
AutomationFlowEmbed.php
6 months ago
AutomationPreviewEmbed.php
2 months ago
AutomationTemplates.php
2 years ago
CustomFields.php
2 months ago
DynamicSegments.php
2 months ago
ExperimentalFeatures.php
3 years ago
FormEditor.php
2 weeks ago
Forms.php
2 months ago
Help.php
2 months ago
Homepage.php
2 years ago
Landingpage.php
2 years ago
Logs.php
1 month ago
NewsletterEditor.php
2 months ago
Newsletters.php
2 months ago
Settings.php
5 months ago
StaticSegments.php
2 months ago
Subscribers.php
2 weeks ago
SubscribersExport.php
3 years ago
SubscribersImport.php
2 months ago
Tags.php
3 months ago
Upgrade.php
1 year ago
WelcomeWizard.php
2 months ago
WooCommerceSetup.php
2 months ago
index.php
3 years ago
WelcomeWizard.php
95 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\AdminPages\Pages; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\AdminPages\PageRenderer; |
| 9 | use MailPoet\Config\Menu; |
| 10 | use MailPoet\Config\ServicesChecker; |
| 11 | use MailPoet\Settings\SettingsController; |
| 12 | use MailPoet\WooCommerce\Helper as WooCommerceHelper; |
| 13 | use MailPoet\WP\Functions as WPFunctions; |
| 14 | |
| 15 | class WelcomeWizard { |
| 16 | const TRACK_LOADDED_VIA_WOOCOMMERCE_SETTING_NAME = 'send_event_that_wizard_was_loaded_via_woocommerce'; |
| 17 | const TRACK_LOADDED_VIA_WOOCOMMERCE_MARKETING_DASHBOARD_SETTING_NAME = 'wizard_loaded_via_woocommerce_marketing_dashboard'; |
| 18 | |
| 19 | /** @var PageRenderer */ |
| 20 | private $pageRenderer; |
| 21 | |
| 22 | /** @var SettingsController */ |
| 23 | private $settings; |
| 24 | |
| 25 | /** @var WPFunctions */ |
| 26 | private $wp; |
| 27 | |
| 28 | /** @var WooCommerceHelper */ |
| 29 | private $wooCommerceHelper; |
| 30 | |
| 31 | /** @var ServicesChecker */ |
| 32 | private $servicesChecker; |
| 33 | |
| 34 | public function __construct( |
| 35 | PageRenderer $pageRenderer, |
| 36 | SettingsController $settings, |
| 37 | WooCommerceHelper $wooCommerceHelper, |
| 38 | WPFunctions $wp, |
| 39 | ServicesChecker $servicesChecker |
| 40 | ) { |
| 41 | $this->pageRenderer = $pageRenderer; |
| 42 | $this->settings = $settings; |
| 43 | $this->wooCommerceHelper = $wooCommerceHelper; |
| 44 | $this->wp = $wp; |
| 45 | $this->servicesChecker = $servicesChecker; |
| 46 | } |
| 47 | |
| 48 | public function render() { |
| 49 | if (wp_doing_ajax()) return; |
| 50 | |
| 51 | $loadedViaWooCommerce = $this->settings->get(WelcomeWizard::TRACK_LOADDED_VIA_WOOCOMMERCE_SETTING_NAME, false); |
| 52 | |
| 53 | if (!$loadedViaWooCommerce && isset($_GET['mailpoet_wizard_loaded_via_woocommerce'])) { |
| 54 | // This setting is used to send an event to Mixpanel in another request as, before completing the wizard, Mixpanel is not enabled. |
| 55 | $this->settings->set(WelcomeWizard::TRACK_LOADDED_VIA_WOOCOMMERCE_SETTING_NAME, 1); |
| 56 | } |
| 57 | |
| 58 | $loadedViaWooCommerceMarketingDashboard = $this->settings->get(WelcomeWizard::TRACK_LOADDED_VIA_WOOCOMMERCE_MARKETING_DASHBOARD_SETTING_NAME, false); |
| 59 | |
| 60 | if (!$loadedViaWooCommerceMarketingDashboard && isset($_GET['mailpoet_wizard_loaded_via_woocommerce_marketing_dashboard'])) { |
| 61 | // This setting is used to send an event to Mixpanel in another request as, before completing the wizard, Mixpanel is not enabled. |
| 62 | $this->settings->set(WelcomeWizard::TRACK_LOADDED_VIA_WOOCOMMERCE_MARKETING_DASHBOARD_SETTING_NAME, 1); |
| 63 | } |
| 64 | |
| 65 | |
| 66 | $premiumKeyValid = $this->servicesChecker->isPremiumKeyValid(false); |
| 67 | // force MSS key check even if the method isn't active |
| 68 | $mpApiKeyValid = $this->servicesChecker->isMailPoetAPIKeyValid(false, true); |
| 69 | |
| 70 | $data = [ |
| 71 | 'finish_wizard_url' => $this->wp->adminUrl('admin.php?page=' . Menu::MAIN_PAGE_SLUG), |
| 72 | 'admin_email' => $this->wp->getOption('admin_email'), |
| 73 | 'current_wp_user' => $this->wp->wpGetCurrentUser()->to_array(), |
| 74 | 'show_customers_import' => $this->wooCommerceHelper->getCustomersCount() > 0, |
| 75 | 'settings' => $this->getSettings(), |
| 76 | 'premium_key_valid' => !empty($premiumKeyValid), |
| 77 | 'mss_key_valid' => !empty($mpApiKeyValid), |
| 78 | 'has_tracking_settings' => $this->settings->hasSavedValue('analytics') && $this->settings->hasSavedValue('3rd_party_libs'), |
| 79 | 'welcome_wizard_current_step' => $this->settings->get('welcome_wizard_current_step', ''), |
| 80 | ]; |
| 81 | $this->pageRenderer->displayPage('welcome_wizard.html', $data); |
| 82 | } |
| 83 | |
| 84 | private function getSettings(): array { |
| 85 | $settings = $this->settings->getAll(); |
| 86 | |
| 87 | $user = $this->wp->wpGetCurrentUser(); |
| 88 | $settings['sender'] = [ |
| 89 | 'name' => $user->display_name, // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps |
| 90 | 'address' => $user->user_email, // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps |
| 91 | ]; |
| 92 | return $settings; |
| 93 | } |
| 94 | } |
| 95 |