<?php
 class vB_Api_Unsubscribe extends vB_Api { public function unsubscribeEmail(int $userid, string $hash) : void { $lib = vB_Library::instance('unsubscribe'); $valid = $lib->verifyHash($userid, $hash); if ($valid) { $this->doUnsubscribeEmails($userid); $lib->trackEmailOptInOut($userid, vB_Library_Unsubscribe::EMAILOPTION_UNSUBSCRIBED); } } private function doUnsubscribeEmails(int $userid) : void { $userLib = vB_Library::instance('user'); $userInfo = [ 'emailnotification' => 0, 'trendingnotification' => 0 ]; $userOptions = [ 'options' => [ 'emailonpm' => 0, 'birthdayemail' => 0, 'adminemail' => 0, ], 'moderatorEmailNotificationOptions' => [ 'monitoredword' => 0, 'reportedpost' => 0, 'unapprovedpost' => 0, 'spampost' => 0, ], ]; $saveOptions = [ 'userfieldskiprequired' => true, 'skippasswordhistory' => true, 'skipactivationemail' => true, 'skipcoppa' => true, 'skipusernamechecks' => [ 'duplicate' => true, ], 'allowdisplayname' => true, ]; $userLib->save($userid, '', $userInfo, [], $userOptions, $saveOptions); } } 