| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\DonationForms\AsyncData\Actions; |
| 4 |
|
| 5 |
/** |
| 6 |
* @since 3.16.0 |
| 7 |
*/ |
| 8 |
class LoadAsyncDataAssets |
| 9 |
{ |
| 10 |
/** |
| 11 |
* @since 3.16.0 |
| 12 |
*/ |
| 13 |
public function __invoke() |
| 14 |
{ |
| 15 |
LoadAsyncDataAssets::registerAssets(); |
| 16 |
LoadAsyncDataAssets::enqueueAssets(); |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* @since 3.16.0 |
| 21 |
*/ |
| 22 |
public static function handleName(): string |
| 23 |
{ |
| 24 |
return 'givewp-form-donations-async-data'; |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* @since 3.16.0 |
| 29 |
*/ |
| 30 |
public static function registerAssets() |
| 31 |
{ |
| 32 |
wp_register_style( |
| 33 |
LoadAsyncDataAssets::handleName(), |
| 34 |
GIVE_PLUGIN_URL . 'build/assets/dist/css/give-donation-forms-load-async-data.css', |
| 35 |
[], |
| 36 |
GIVE_VERSION |
| 37 |
); |
| 38 |
|
| 39 |
wp_register_script( |
| 40 |
LoadAsyncDataAssets::handleName(), |
| 41 |
GIVE_PLUGIN_URL . 'build/assets/dist/js/give-donation-forms-load-async-data.js', |
| 42 |
[], |
| 43 |
GIVE_VERSION, |
| 44 |
true |
| 45 |
); |
| 46 |
|
| 47 |
wp_localize_script(LoadAsyncDataAssets::handleName(), 'GiveDonationFormsAsyncData', |
| 48 |
[ |
| 49 |
'ajaxUrl' => admin_url('admin-ajax.php'), |
| 50 |
'ajaxNonce' => wp_create_nonce('GiveDonationFormsAsyncDataAjaxNonce'), |
| 51 |
'scriptDebug' => defined('SCRIPT_DEBUG') && SCRIPT_DEBUG, |
| 52 |
'throttlingEnabled' => ! defined('GIVE_ASYNC_DATA_THROTTLING') || GIVE_ASYNC_DATA_THROTTLING, |
| 53 |
] |
| 54 |
); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* @since 3.16.0 |
| 59 |
*/ |
| 60 |
public static function enqueueAssets() |
| 61 |
{ |
| 62 |
wp_enqueue_style(LoadAsyncDataAssets::handleName()); |
| 63 |
wp_enqueue_script(LoadAsyncDataAssets::handleName()); |
| 64 |
} |
| 65 |
} |
| 66 |
|