showHeader = $array['showHeader'] ?? true; $self->showHeading = $array['showHeading'] ?? true; $self->heading = $array['heading'] ?? __('Support Our Cause', 'give'); $self->showDescription = $array['showDescription'] ?? true; $self->description = $array['description'] ?? __( 'Help our organization by donating today! Donations go to making a difference for our cause.', 'give' ); $self->formTitle = $array['formTitle'] ?? __('Donation Form', 'give'); $self->donateButtonCaption = $array['donateButtonCaption'] ?? __('Donate now', 'give'); $self->enableDonationGoal = $array['enableDonationGoal'] ?? false; $self->enableAutoClose = $array['enableAutoClose'] ?? false; $self->goalSource = ! empty($array['goalSource']) && GoalSource::isValid($array['goalSource']) ? new GoalSource($array['goalSource']) : GoalSource::FORM(); $self->goalType = ! empty($array['goalType']) && GoalType::isValid($array['goalType']) ? new GoalType( $array['goalType'] ) : GoalType::AMOUNT(); $self->goalProgressType = ! empty($array['goalProgressType']) && GoalProgressType::isValid($array['goalProgressType']) ? new GoalProgressType($array['goalProgressType']) : GoalProgressType::ALL_TIME(); $self->goalStartDate = $array['goalStartDate'] ?? ''; $self->goalEndDate = $array['goalEndDate'] ?? ''; $self->designId = isset($array['designId']) ? sanitize_html_class($array['designId']) : null; $self->inheritCampaignColors = $array['inheritCampaignColors'] ?? false; $self->primaryColor = self::sanitizeHexColorOrDefault($array['primaryColor'] ?? '#2d802f', '#2d802f'); $self->secondaryColor = self::sanitizeHexColorOrDefault($array['secondaryColor'] ?? '#f49420', '#f49420'); $self->goalAmount = $array['goalAmount'] ?? 0; $self->registrationNotification = $array['registrationNotification'] ?? false; $self->customCss = wp_strip_all_tags($array['customCss'] ?? ''); $self->pageSlug = $array['pageSlug'] ?? ''; $self->goalAchievedMessage = $array['goalAchievedMessage'] ?? __( 'Thank you to all our donors, we have met our fundraising goal.', 'give' ); $self->receiptHeading = $array['receiptHeading'] ?? __( 'Hey {first_name}, thanks for your donation!', 'give' ); $self->receiptDescription = $array['receiptDescription'] ?? __( '{first_name}, your contribution means a lot and will be put to good use in making a difference. We’ve sent your donation receipt to {email}.', 'give' ); $self->enableReceiptConfirmationPage = $array['enableReceiptConfirmationPage'] ?? false; $self->formStatus = ! empty($array['formStatus']) ? new DonationFormStatus( $array['formStatus'] ) : DonationFormStatus::DRAFT(); $self->formGridCustomize = $array['formGridCustomize'] ?? false; $self->formGridRedirectUrl = $array['formGridRedirectUrl'] ?? ''; $self->formGridDonateButtonText = $array['formGridDonateButtonText'] ?? ''; $self->formGridHideDocumentationLink = $array['formGridHideDocumentationLink'] ?? false; $self->emailTemplateOptions = $array['emailTemplateOptions'] ?? []; $self->emailOptionsStatus = $array['emailOptionsStatus'] ?? 'global'; $self->emailTemplate = $array['emailTemplate'] ?? 'default'; $self->emailFromName = $array['emailFromName'] ?? ''; $self->emailFromEmail = $array['emailFromEmail'] ?? ''; $self->emailLogo = $array['emailLogo'] ?? ''; $self->offlineDonationsCustomize = $array['offlineDonationsCustomize'] ?? false; $self->offlineDonationsInstructions = $array['offlineDonationsInstructions'] ?? ''; $self->multiStepFirstButtonText = $array['multiStepFirstButtonText'] ?? __('Donate now', 'give'); $self->multiStepNextButtonText = $array['multiStepNextButtonText'] ?? __('Continue', 'give'); $self->pdfSettings = isset($array['pdfSettings']) && is_array( $array['pdfSettings'] ) ? $array['pdfSettings'] : []; $self->designSettingsImageUrl = $array['designSettingsImageUrl'] ?? ''; $self->designSettingsImageAlt = $array['designSettingsImageAlt'] ?? $self->formTitle; $self->designSettingsImageStyle = ! empty($array['designSettingsImageStyle']) ? new DesignSettingsImageStyle( $array['designSettingsImageStyle'] ) : DesignSettingsImageStyle::BACKGROUND(); $self->designSettingsLogoUrl = $array['designSettingsLogoUrl'] ?? ''; $self->designSettingsLogoPosition = ! empty($array['designSettingsLogoPosition']) ? new DesignSettingsLogoPosition( $array['designSettingsLogoPosition'] ) : DesignSettingsLogoPosition::LEFT(); $self->designSettingsSectionStyle = ! empty($array['designSettingsSectionStyle']) ? new DesignSettingsSectionStyle( $array['designSettingsSectionStyle'] ) : DesignSettingsSectionStyle::DEFAULT(); $self->designSettingsTextFieldStyle = ! empty($array['designSettingsTextFieldStyle']) ? new DesignSettingsTextFieldStyle( $array['designSettingsTextFieldStyle'] ) : DesignSettingsTextFieldStyle::DEFAULT(); $self->designSettingsImageColor = $array['designSettingsImageColor'] ?? ''; $self->designSettingsImageOpacity = $array['designSettingsImageOpacity'] ?? ''; $self->formExcerpt = $array['formExcerpt'] ?? ''; $self->currencySwitcherSettings = isset($array['currencySwitcherSettings']) && is_array( $array['currencySwitcherSettings'] ) ? $array['currencySwitcherSettings'] : []; return $self; } /** * Sanitize a color string to a valid hex color, falling back to the provided default. * * @since 4.14.6 */ private static function sanitizeHexColorOrDefault(string $raw, string $default): string { return sanitize_hex_color($raw) ?? $default; } /** * @since 3.0.0 */ public static function fromJson(string $json): self { return self::fromArray( json_decode($json, true) ); } /** * @since 3.0.0 */ public function toArray(): array { return get_object_vars($this); } /** * @since 4.1.0 Add goalSource * @since 3.2.0 Remove call to addSlashesRecursive method for emailTemplateOptions in favor of SanitizeDonationFormPreviewRequest class * @since 3.0.0 */ public function toJson($options = 0): string { return json_encode( array_merge( $this->toArray(), [ 'goalSource' => $this->goalSource ? $this->goalSource->getValue() : GoalSource::FORM()->getValue(), 'goalType' => $this->goalType ? $this->goalType->getValue() : null, ] ) ); } }