settings = $settings; $this->subscriberActions = $subscriberActions; $this->wp = $wp; $this->subscriberHandler = $subscriberHandler; } public function extendForm() { $label = $this->settings->get( 'subscribe.on_register.label', __('Yes, please add me to your mailing list.', 'mailpoet') ); $form = '

'; $form = (string)$this->wp->applyFilters('mailpoet_register_form_extend', $form); // We control the template and $form can be considered safe. // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, WordPressDotOrg.sniffs.OutputEscaping.UnescapedOutputParameter print $form; } public function onMultiSiteRegister($result) { if (empty($result['errors']->errors)) { if ( isset($_POST['mailpoet']['subscribe_on_register']) && (bool)$_POST['mailpoet']['subscribe_on_register'] === true ) { $this->subscribeNewUser( $result['user_name'], $result['user_email'] ); } } return $result; } public function onRegister( $errors, $userLogin, $userEmail = null ) { if ( empty($errors->errors) && isset($_POST['mailpoet']['subscribe_on_register']) && (bool)$_POST['mailpoet']['subscribe_on_register'] === true ) { $this->subscribeNewUser( $userLogin, $userEmail ); } return $errors; } private function subscribeNewUser($name, $email) { $segmentIds = $this->settings->get( 'subscribe.on_register.segments', [] ); $this->subscriberActions->subscribe( [ 'email' => $email, 'first_name' => $name, ], $segmentIds ); /** * On multisite headers are already sent at this point, tracking will start * once the user has activated his account at a later stage. **/ if (!headers_sent()) { // start subscriber tracking (by email, we don't have WP user ID yet) $this->subscriberHandler->identifyByEmail($email); } } }