-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add mailchimp migration step
- Loading branch information
1 parent
b52e979
commit 1825f2e
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace Give\FormMigration\Steps; | ||
|
||
use Give\FormMigration\Contracts\FormMigrationStep; | ||
use Give\Framework\Blocks\BlockModel; | ||
use Give\Log\Log; | ||
|
||
class MailchimpSettings extends FormMigrationStep | ||
{ | ||
/** | ||
* @unreleased | ||
*/ | ||
public function process() | ||
{ | ||
$prevFormId = $this->formV2->id; | ||
|
||
$isFormEnabled = $this->getFormMetaValue($prevFormId, '_give_mailchimp_enable') === 'true'; | ||
$isFormDisabled = $this->getFormMetaValue($prevFormId, '_give_mailchimp_disable') === 'true'; | ||
$isGloballyEnabled = give_get_option( 'give_mailchimp_show_checkout_signup') === 'on'; | ||
|
||
if ($isFormDisabled || (!$isGloballyEnabled && !$isFormEnabled)) { | ||
return; | ||
} | ||
|
||
$block = BlockModel::make([ | ||
'name' => 'givewp/mailchimp', | ||
'attributes' => $this->getAttributes($prevFormId) | ||
]); | ||
|
||
$this->fieldBlocks->insertAfter('givewp/email', $block); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
private function getFormMetaValue(int $prevFormId, string $metaKey) | ||
{ | ||
$meta = give()->form_meta->get_meta($prevFormId, $metaKey, true); | ||
|
||
return $meta === '' ? null : $meta; | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
private function getAttributes($prevFormId): array | ||
{ | ||
return [ | ||
'label' => $this->getFormMetaValue($prevFormId, '_give_mailchimp_custom_label') ?? | ||
give_get_option('give_mailchimp_label', __('Subscribe to newsletter?')), | ||
|
||
'checked' => $this->getFormMetaValue($prevFormId, '_give_mailchimp_checked_default') ?? | ||
give_get_option('give_mailchimp_checked_default', true), | ||
|
||
'doubleOptIn' => $this->getFormMetaValue($prevFormId, '_give_mailchimp_double_opt_in') ?? | ||
give_get_option('give_mailchimp_double_opt_in', false), | ||
|
||
'subscriberTags' => $this->getFormMetaValue($prevFormId, '_give_mailchimp_tags') ?? [], | ||
|
||
'sendDonationData' => $this->getFormMetaValue($prevFormId, '_give_mailchimp_send_donation') ?? | ||
give_get_option('give_mailchimp_donation_data', true), | ||
|
||
'sendFFMData' => $this->getFormMetaValue($prevFormId, '_give_mailchimp_send_ffm') ?? | ||
give_get_option('give_mailchimp_ffm_pass_field', false), | ||
|
||
'defaultAudiences' => $this->getFormMetaValue($prevFormId, '_give_mailchimp') ?? | ||
give_get_option('give_mailchimp_list', []), | ||
|
||
]; | ||
} | ||
} |