Skip to content

Commit

Permalink
Merge pull request #495 from infinum/feature/nationbuilder-improvements
Browse files Browse the repository at this point in the history
6.1.3
  • Loading branch information
iruzevic authored Feb 10, 2025
2 parents f72b1d2 + c53d804 commit ea20e2c
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 24 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.

This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a CHANGELOG](https://keepachangelog.com/).

## [6.1.3]

### Added

- Nationbuilder now supports tags.
- Range slider now supports custom input value with single submit option.

### Fixed

- Disabled button in admin.

## [6.1.2]

### Added
Expand Down Expand Up @@ -1102,6 +1113,7 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a

- Initial production release.

[6.1.3]: https://github.com/infinum/eightshift-forms/compare/6.1.2...6.1.3
[6.1.2]: https://github.com/infinum/eightshift-forms/compare/6.1.1...6.1.2
[6.1.1]: https://github.com/infinum/eightshift-forms/compare/6.1.0...6.1.1
[6.1.0]: https://github.com/infinum/eightshift-forms/compare/6.0.0...6.1.0
Expand Down
2 changes: 1 addition & 1 deletion eightshift-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Description: Eightshift Forms is a complete form builder plugin that utilizes modern Block editor features with multiple third-party integrations, bringing your project to a new level.
* Author: WordPress team @Infinum
* Author URI: https://eightshift.com/
* Version: 6.1.2
* Version: 6.1.3
* Text Domain: eightshift-forms
*
* @package EightshiftForms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class="<?php echo esc_attr("{$sectionClass}__menu-link " . Helpers::selector($in
title="<?php echo esc_html($desc); ?>"
>
<span class="<?php echo esc_attr("{$sectionClass}__menu-link-wrap"); ?>">
<?php echo wp_kses_post($icon); ?>
<?php echo $icon; // phpcs:ignore Eightshift.Security.HelpersEscape.OutputNotEscaped ?>
<?php echo esc_html($label); ?>
</span>
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#wpadminbar #wp-admin-bar-es-forms > a > svg { // stylelint-disable-line selector-max-specificity
color: #FF6900;
margin-inline-start: 0.625rem;
vertical-align: sub;
vertical-align: middle;
}
4 changes: 2 additions & 2 deletions src/Blocks/components/card-inline/card-inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ class="<?php echo esc_attr($cardInlineClass); ?>"
<?php if ($cardInlineIcon) { ?>
<?php if ($cardInlineTitleLink) { ?>
<a href="<?php echo esc_url($cardInlineTitleLink); ?>" class="<?php echo esc_attr("{$componentClass}__icon"); ?>">
<?php echo wp_kses_post($cardInlineIcon); ?>
<?php echo $cardInlineIcon; // phpcs:ignore Eightshift.Security.HelpersEscape.OutputNotEscaped ?>
</a>
<?php } else { ?>
<div class="<?php echo esc_attr("{$componentClass}__icon"); ?>">
<?php echo wp_kses_post($cardInlineIcon); ?>
<?php echo $cardInlineIcon; // phpcs:ignore Eightshift.Security.HelpersEscape.OutputNotEscaped ?>
</div>
<?php } ?>
<?php } ?>
Expand Down
5 changes: 5 additions & 0 deletions src/Blocks/components/form/assets/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -2001,6 +2001,11 @@ export class Form {

target.value = value;
this.utils.setManualRangeValue(formId, name, value.toString());

// Used only on frontend for single submit.
if (!this.state.getStateConfigIsAdmin() && this.state.getStateFormConfigUseSingleSubmit(formId)) {
debounce(this.formSubmit(formId), 100);
}
};

/**
Expand Down
12 changes: 5 additions & 7 deletions src/Blocks/components/submit/submit-admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ button {
padding: 0.75rem 1rem;
border-radius: 0.5rem;

&.es-form-is-disabled {
pointer-events: none;
opacity: 0.5;
}

&--global {
inline-size: auto;
}
Expand Down Expand Up @@ -97,10 +102,3 @@ button {
}
}
}

.es-form-is-disabled {
.es-submit {
pointer-events: none;
opacity: 0.5;
}
}
7 changes: 6 additions & 1 deletion src/Blocks/components/submit/submit.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use EightshiftForms\Helpers\FormsHelper;
use EightshiftFormsVendor\EightshiftLibs\Helpers\Helpers;
use EightshiftFormsVendor\EightshiftFormsUtils\Helpers\UtilsGeneralHelper;
use EightshiftFormsVendor\EightshiftFormsUtils\Helpers\UtilsHelper;

$manifest = Helpers::getManifestByDir(__DIR__);

Expand Down Expand Up @@ -55,10 +56,14 @@ class="' . esc_attr($submitClass) . '"
';

if ($submitButtonAsLink) {
$submitLinkClass = Helpers::classnames([
Helpers::selector($submitIsDisabled, UtilsHelper::getStateSelector('isDisabled')),
]);

$button = '
<a
href="' . esc_url($submitButtonAsLinkUrl) . '"
class="' . esc_attr($submitClass) . '"
class="' . esc_attr("{$submitClass} {$submitLinkClass}") . '"
><span class="' . esc_attr(FormsHelper::getTwPart($twClasses, $submitButtonTwParent, 'inner', "{$componentClass}__inner")) . '">' . $submitIconContent . ' ' . esc_html($submitValue) . '</span></a>
' . $additionalContent . '
';
Expand Down
18 changes: 17 additions & 1 deletion src/CronJobs/NationbuilderJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,28 @@ public function getJobCallback()
}

unset($jobs[$type][$listId]);
}
}

if ($type === 'tags') {
foreach ($job as $tagId => $signupIds) {
foreach ($signupIds as $signupId) {
$tagResponse = $this->nationbuilderClient->postTag((string) $tagId, $signupId);

if ($tagResponse[UtilsConfig::IARD_CODE] < UtilsConfig::API_RESPONSE_CODE_SUCCESS && $tagResponse[UtilsConfig::IARD_CODE] > UtilsConfig::API_RESPONSE_CODE_SUCCESS_RANGE) {
$formDetails[UtilsConfig::FD_RESPONSE_OUTPUT_DATA] = $tagResponse;

\update_option(UtilsSettingsHelper::getOptionName(SettingsNationbuilder::SETTINGS_NATIONBUILDER_CRON_KEY), $jobs);
$this->formSubmitMailer->sendFallbackIntegrationEmail($formDetails);
}
}

unset($jobs[$type][$tagId]);
}
}
}

\update_option(UtilsSettingsHelper::getOptionName(SettingsNationbuilder::SETTINGS_NATIONBUILDER_CRON_KEY), $jobs);

// Turn of OAuth after cron job is done.
\delete_option(UtilsSettingsHelper::getOptionName(SettingsNationbuilder::SETTINGS_NATIONBUILDER_OAUTH_ALLOW_KEY));
}
Expand Down
1 change: 1 addition & 0 deletions src/Hooks/FiltersSettingsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ public function getSettingsFiltersData(): array
'cache' => [
NationbuilderClient::CACHE_NATIONBUILDER_CUSTOM_FIELDS_TRANSIENT_NAME,
NationbuilderClient::CACHE_NATIONBUILDER_LISTS_TRANSIENT_NAME,
NationbuilderClient::CACHE_NATIONBUILDER_TAGS_TRANSIENT_NAME,
],
'emailTemplateTags' => [
'nationbuilderSignupId' => 'id',
Expand Down
132 changes: 127 additions & 5 deletions src/Integrations/Nationbuilder/NationbuilderClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class NationbuilderClient implements NationbuilderClientInterface
*/
public const CACHE_NATIONBUILDER_LISTS_TRANSIENT_NAME = 'es_nationbuilder_lists_cache';

/**
* Transient cache name for tags.
*/
public const CACHE_NATIONBUILDER_TAGS_TRANSIENT_NAME = 'es_nationbuilder_tags_cache';

/**
* Instance variable for Oauth.
*
Expand Down Expand Up @@ -108,7 +113,6 @@ public function getCustomFields(bool $hideUpdateTime = true): array
*/
public function getLists(bool $hideUpdateTime = true): array
{

$output = \get_transient(self::CACHE_NATIONBUILDER_LISTS_TRANSIENT_NAME) ?: []; // phpcs:ignore WordPress.PHP.DisallowShortTernary.Found

// Prevent cache.
Expand Down Expand Up @@ -146,6 +150,52 @@ public function getLists(bool $hideUpdateTime = true): array
return $output;
}

/**
* Return tags.
*
* @param bool $hideUpdateTime Determine if update time will be in the output or not.
*
* @return array<string, mixed>
*/
public function getTags(bool $hideUpdateTime = true): array
{
$output = \get_transient(self::CACHE_NATIONBUILDER_TAGS_TRANSIENT_NAME) ?: []; // phpcs:ignore WordPress.PHP.DisallowShortTernary.Found

// Prevent cache.
if (UtilsDeveloperHelper::isDeveloperSkipCacheActive()) {
$output = [];
}

// Check if form exists in cache.
if (!$output) {
$items = $this->getNationbuilderCustomApiData('signup_tags');

if ($items) {
foreach ($items as $item) {
$id = $item['id'] ?? '';

$output[$id] = [
'id' => $id,
'title' => $item['attributes']['name'] ?? '',
];
}

$output[ClientInterface::TRANSIENT_STORED_TIME] = [
'id' => ClientInterface::TRANSIENT_STORED_TIME,
'title' => \current_datetime()->format('Y-m-d H:i:s'),
];

\set_transient(self::CACHE_NATIONBUILDER_TAGS_TRANSIENT_NAME, $output, SettingsCache::CACHE_TRANSIENTS_TIMES['integration']);
}
}

if ($hideUpdateTime) {
unset($output[ClientInterface::TRANSIENT_STORED_TIME]);
}

return $output;
}

/**
* API request to post application.
*
Expand Down Expand Up @@ -210,11 +260,22 @@ public function postApplication(array $params, array $files, string $formId): ar
// On success return output.
if ($code >= UtilsConfig::API_RESPONSE_CODE_SUCCESS && $code <= UtilsConfig::API_RESPONSE_CODE_SUCCESS_RANGE) {
$list = UtilsSettingsHelper::getSettingValue(SettingsNationbuilder::SETTINGS_NATIONBUILDER_LIST_KEY, $formId);
$tags = \explode(UtilsConfig::DELIMITER, UtilsSettingsHelper::getSettingValue(SettingsNationbuilder::SETTINGS_NATIONBUILDER_TAGS_KEY, $formId));

if ($list) {
$listsJobs = UtilsSettingsHelper::getOptionValueGroup(SettingsNationbuilder::SETTINGS_NATIONBUILDER_CRON_KEY);
$listsJobs['list'][$list][] = $body['data']['id'] ?? '';
\update_option(UtilsSettingsHelper::getSettingName(SettingsNationbuilder::SETTINGS_NATIONBUILDER_CRON_KEY), $listsJobs);
if ($list || $tags) {
$job = UtilsSettingsHelper::getOptionValueGroup(SettingsNationbuilder::SETTINGS_NATIONBUILDER_CRON_KEY);

if ($list) {
$job['list'][$list][] = $body['data']['id'] ?? '';
}

if ($tags) {
foreach ($tags as $tag) {
$job['tags'][$tag][] = $body['data']['id'] ?? '';
}
}

\update_option(UtilsSettingsHelper::getSettingName(SettingsNationbuilder::SETTINGS_NATIONBUILDER_CRON_KEY), $job);
}

return UtilsApiHelper::getIntegrationSuccessInternalOutput($details);
Expand Down Expand Up @@ -288,6 +349,67 @@ public function postList(string $listId, string $signupId): array
return UtilsApiHelper::getIntegrationErrorInternalOutput($details);
}

/**
* API request to post tag.
*
* @param string $tagId Tag id.
* @param string $signupId Signup id.
*
* @return array<string, mixed>
*/
public function postTag(string $tagId, string $signupId): array
{
$url = $this->getBaseUrl('signup_taggings');

$body = [
'data' => [
'type' => 'signup_taggings',
'attributes' => [
'signup_id' => $signupId,
'tag_id' => $tagId,
],
]
];

$response = \wp_remote_post(
$url,
[
'headers' => $this->getHeaders(),
'body' => \wp_json_encode($body),
]
);

$details = UtilsApiHelper::getIntegrationApiReponseDetails(
SettingsNationbuilder::SETTINGS_TYPE_KEY,
$response,
$url,
$body,
[],
'',
'',
UtilsSettingsHelper::isOptionCheckboxChecked(SettingsNationbuilder::SETTINGS_NATIONBUILDER_SKIP_INTEGRATION_KEY, SettingsNationbuilder::SETTINGS_NATIONBUILDER_SKIP_INTEGRATION_KEY)
);

$code = $details[UtilsConfig::IARD_CODE];
$body = $details[UtilsConfig::IARD_BODY];

if ($this->oauthNationbuilder->hasTokenExpired($body)) {
$refreshToken = $this->oauthNationbuilder->getRefreshToken();

if ($refreshToken) {
return $this->postTag($tagId, $signupId);
}
}

// On success return output.
if ($code >= UtilsConfig::API_RESPONSE_CODE_SUCCESS && $code <= UtilsConfig::API_RESPONSE_CODE_SUCCESS_RANGE) {
return UtilsApiHelper::getIntegrationSuccessInternalOutput($details);
}

// Output error.
return UtilsApiHelper::getIntegrationErrorInternalOutput($details);
}

/**
* Map service messages with our own.
*
Expand Down
23 changes: 21 additions & 2 deletions src/Integrations/Nationbuilder/NationbuilderClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,32 @@ public function getCustomFields(bool $hideUpdateTime = true): array;
*/
public function getLists(bool $hideUpdateTime = true): array;

/**
* Return Tags.
*
* @param bool $hideUpdateTime Determine if update time will be in the output or not.
*
* @return array<string, mixed>
*/
public function getTags(bool $hideUpdateTime = true): array;

/**
* API request to post list.
*
* @param string $id List id.
* @param string $listId List id.
* @param string $signupId Signup id.
*
* @return array<string, mixed>
*/
public function postList(string $listId, string $signupId): array;

/**
* API request to post tag.
*
* @param string $tagId Tag id.
* @param string $signupId Signup id.
*
* @return array<string, mixed>
*/
public function postList(string $id, string $signupId): array;
public function postTag(string $tagId, string $signupId): array;
}
4 changes: 2 additions & 2 deletions src/Integrations/Nationbuilder/OauthNationbuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function getAccessToken(string $code): bool
*/
public function getRefreshToken(): bool
{
if ($this->refreshTokenRetryCounter >= 5) {
if ($this->refreshTokenRetryCounter >= 3) {
return false;
}

Expand All @@ -162,7 +162,7 @@ public function getRefreshToken(): bool
*/
public function hasTokenExpired(array $body): bool
{
return ($body['data'] ?? '') === 'token_expired';
return ($body['code'] ?? '') === 'token_expired';
}

/**
Expand Down
Loading

0 comments on commit ea20e2c

Please sign in to comment.