Skip to content

Commit

Permalink
refactor: display migration banner only on give pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ravinderk committed Aug 24, 2023
1 parent f4093b9 commit bcd8c06
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
7 changes: 5 additions & 2 deletions assets/src/js/plugins/give-api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,15 @@ const Give = {
/**
* Get global param
*
* @unreleased Return default value of global param if param not found.
* @since 2.2.4
*
* @return {object} WordPress localized global param.
*/
getGlobal: function() {
return ( 'undefined' === typeof give_global_vars ) ? give_vars : give_global_vars;
getGlobal: function () {
return ('undefined' === typeof give_global_vars)
? (window.give_vars || {})
: (window.give_global_vars || {});
},

/**
Expand Down
5 changes: 4 additions & 1 deletion src/DonationForms/V2/DonationFormsAdminPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public function highlightAllFormsMenuItem()

/**
* Load scripts
*
* @unreleased Set admin script and style dependencies to display PayPal Standard to Donations Migration banner.
*/
public function loadScripts()
{
Expand All @@ -87,14 +89,15 @@ public function loadScripts()
];

EnqueueScript::make('give-admin-donation-forms', 'assets/dist/js/give-admin-donation-forms.js')
->dependencies(['give-admin-scripts'])
->loadInFooter()
->registerTranslations()
->registerLocalizeData('GiveDonationForms', $data)->enqueue();

wp_enqueue_style(
'give-admin-ui-font',
'https://fonts.googleapis.com/css2?family=Open+Sans:[email protected]&display=swap',
[],
['give-admin-styles'],
null
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ public function setHook()
}

add_action('admin_enqueue_scripts', function () {
if (give_is_gateway_active(PayPalStandard::id())) {
wp_add_inline_script('give-admin-scripts', $this->getModalScript());
$isGivePage = ( isset($_GET['page']) && 'give-forms' === $_GET['page'] )
|| ( isset($_GET['post_type']) && 'give_forms' === $_GET['post_type'] );

if ($isGivePage && give_is_gateway_active(PayPalStandard::id())) {
add_action('admin_footer', function () {
wp_print_inline_script_tag($this->getModalScript());
});
}
});
}
Expand Down Expand Up @@ -84,15 +89,19 @@ public function getModalScript(): string
);

return <<<EOT
document.addEventListener("DOMContentLoaded", () => {
const dismissModalAjaxRequest = () => {
wp.ajax.post({
'give-action': 'dismiss_notices',
'notice_id': '$this->bannerId',
'dismissible_type': 'user',
'dismiss_interval': 'permanent',
'_wpnonce': '$nonce'
});
const givePayPalStandardToDonationsMigrationGlobalBanner = () => {
const dismissModalAjaxRequest = async () => {
const formData = new FormData();
formData.append('give-action', 'dismiss_notices');
formData.append('notice_id', '$this->bannerId');
formData.append('dismissible_type', 'user');
formData.append('dismiss_interval', 'permanent');
formData.append('_wpnonce', '$nonce');
await fetch(ajaxurl, {
method: 'POST',
body: formData,
})
};
new Give.modal.GiveConfirmModal( {
Expand Down Expand Up @@ -131,7 +140,9 @@ classes: {
}
}
} ).render();
});
};
givePayPalStandardToDonationsMigrationGlobalBanner();
EOT;
}

Expand Down

0 comments on commit bcd8c06

Please sign in to comment.