Skip to content

Commit

Permalink
Feature: Embed Donation Form button (#7080)
Browse files Browse the repository at this point in the history
Co-authored-by: Ante Laca <[email protected]>
  • Loading branch information
alaca authored Dec 4, 2023
1 parent b52e979 commit 9cbe9d3
Show file tree
Hide file tree
Showing 13 changed files with 846 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function render(array $attributes)
$embedId = $blockAttributes->blockId ?? '';

$viewUrl = $this->getViewUrl($donationForm, $embedId);
$formUrl = esc_url(add_query_arg(['p' => $blockAttributes->formId], site_url('?post_type=give_forms')));

$formUrl = add_query_arg(['p' => $blockAttributes->formId], site_url('?post_type=give_forms'));

Expand Down
7 changes: 2 additions & 5 deletions src/DonationForms/Shortcodes/GiveFormShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@ public function __invoke(string $output, array $atts): string
return $output;
}

$formFormat = $atts['display_style'];
$openFormButton = $atts['continue_button_title'];

$controller = new BlockRenderController();
$blockAttributes = [
'formId' => $formId,
'blockId' => 'give-form-shortcode-' . self::$instance,
'formFormat' => $formFormat,
'openFormButton' => $openFormButton
'formFormat' => $atts['display_style'] ?? null,
'openFormButton' => $atts['continue_button_title'] ?? null
];

$output = $controller->render($blockAttributes);
Expand Down
69 changes: 33 additions & 36 deletions src/DonationForms/V2/DonationFormsAdminPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,44 +124,41 @@ public function loadScripts()
}

/**
* Load scripts for the edit v2 form page
* Load migration onboarding scripts
* @unreleased
*
* @since 3.0.0
* @return void
*/
public function loadEditFormScripts()
{
$data = [
'supportedAddons' => $this->getSupportedAddons(),
'supportedGateways' => $this->getSupportedGateways(),
'migrationApiRoot' => $this->migrationApiRoot,
'apiNonce' => $this->apiNonce,
'isMigrated' => _give_is_form_migrated((int)$_GET['post'])
];

EnqueueScript::make('give-edit-v2form', 'assets/dist/js/give-edit-v2form.js')
->loadInFooter()
->registerTranslations()
->registerLocalizeData('GiveDonationForms', $data)
->enqueue();

wp_enqueue_style('givewp-design-system-foundation');
}

public function loadAddFormScripts()
public function loadMigrationScripts()
{
$data = [
'supportedAddons' => $this->getSupportedAddons(),
'supportedGateways' => $this->getSupportedGateways(),
];

EnqueueScript::make('give-add-v2form', 'assets/dist/js/give-add-v2form.js')
->loadInFooter()
->registerTranslations()
->registerLocalizeData('GiveDonationForms', $data)
->enqueue();
if ($this->isShowingAddV2FormPage()) {
EnqueueScript::make('give-add-v2form', 'assets/dist/js/give-add-v2form.js')
->loadInFooter()
->registerTranslations()
->registerLocalizeData('GiveDonationForms', [
'supportedAddons' => $this->getSupportedAddons(),
'supportedGateways' => $this->getSupportedGateways(),
])
->enqueue();

wp_enqueue_style('givewp-design-system-foundation');
}

wp_enqueue_style('givewp-design-system-foundation');
if ($this->isShowingEditV2FormPage()) {
EnqueueScript::make('give-edit-v2form', 'assets/dist/js/give-edit-v2form.js')
->loadInFooter()
->registerTranslations()
->registerLocalizeData('GiveDonationForms', [
'supportedAddons' => $this->getSupportedAddons(),
'supportedGateways' => $this->getSupportedGateways(),
'migrationApiRoot' => $this->migrationApiRoot,
'apiNonce' => $this->apiNonce,
'isMigrated' => _give_is_form_migrated((int)$_GET['post'])
])
->enqueue();

wp_enqueue_style('givewp-design-system-foundation');
}
}

/**
Expand Down Expand Up @@ -276,9 +273,9 @@ public static function isShowing(): bool
*
* @return bool
*/
public static function isShowingEditV2FormPage(): bool
private function isShowingEditV2FormPage(): bool
{
return ! isset($_GET['page']) && isset($_GET['action']) && $_GET['action'] === 'edit';
return isset($_GET['action']) && $_GET['action'] === 'edit' && $GLOBALS['post']->post_type === 'give_forms';
}

/**
Expand All @@ -288,7 +285,7 @@ public static function isShowingEditV2FormPage(): bool
*
* @return bool
*/
public static function isShowingAddV2FormPage(): bool
private function isShowingAddV2FormPage(): bool
{
return ! isset($_GET['page']) && isset($_GET['post_type']) && $_GET['post_type'] === 'give_forms';
}
Expand Down
9 changes: 1 addition & 8 deletions src/DonationForms/V2/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,7 @@ public function boot()

// Onboarding
Hooks::addAction('submitpost_box', DonationFormsAdminPage::class, 'renderMigrationGuideBox');

if (DonationFormsAdminPage::isShowingEditV2FormPage()) {
Hooks::addAction('admin_enqueue_scripts', DonationFormsAdminPage::class, 'loadEditFormScripts');
}

if (DonationFormsAdminPage::isShowingAddV2FormPage()) {
Hooks::addAction('admin_enqueue_scripts', DonationFormsAdminPage::class, 'loadAddFormScripts');
}
Hooks::addAction('admin_enqueue_scripts', DonationFormsAdminPage::class, 'loadMigrationScripts');

add_action('wp_ajax_givewp_show_onboarding_banner', static function () {
add_user_meta(get_current_user_id(), 'givewp-show-onboarding-banner', time(), true);
Expand Down
Loading

0 comments on commit 9cbe9d3

Please sign in to comment.