| 1 |
<?php |
| 2 |
/** |
| 3 |
* Our action to enqueue our Admin JavaScript. |
| 4 |
* |
| 5 |
* @package ForceRefresh |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace JordanLeven\Plugins\ForceRefresh; |
| 9 |
|
| 10 |
/** |
| 11 |
* Hook used to enqueue CSS and JS. |
| 12 |
* |
| 13 |
* @return void |
| 14 |
*/ |
| 15 |
add_action( |
| 16 |
'admin_head', |
| 17 |
function () { |
| 18 |
// Include the admin JS. |
| 19 |
add_script( 'force-refresh-main-admin-js', '/dist/js/force-refresh-main-admin.js', true ); |
| 20 |
// Create the data we're going to localize to the script. |
| 21 |
$localized_data = array(); |
| 22 |
// Add the API URL for the script. |
| 23 |
$localized_data['api_url'] = get_stylesheet_directory_uri(); |
| 24 |
// Add the API URL for the script. |
| 25 |
$localized_data['site_id'] = get_current_blog_id(); |
| 26 |
// Create a nonce for the user. |
| 27 |
$localized_data['nonce'] = wp_create_nonce( WP_FORCE_REFRESH_ACTION ); |
| 28 |
// Add the ID of the handlebars notice. |
| 29 |
$localized_data['handlebars_admin_notice_template_id'] = |
| 30 |
WP_FORCE_REFRESH_HANDLEBARS_ADMIN_NOTICE_TEMPLATE_ID; |
| 31 |
// Add the refresh interval. |
| 32 |
$localized_data['refresh_interval'] = get_option( |
| 33 |
WP_FORCE_REFRESH_OPTION_REFRESH_INTERVAL_IN_SECONDS, |
| 34 |
WP_FORCE_REFRESH_OPTION_REFRESH_INTERVAL_IN_SECONDS_DEFAULT |
| 35 |
); |
| 36 |
// Localize the data. |
| 37 |
wp_localize_script( |
| 38 |
'force-refresh-main-admin-js', |
| 39 |
'force_refresh_local_js', |
| 40 |
$localized_data |
| 41 |
); |
| 42 |
// Now that it's registered, enqueue the script. |
| 43 |
wp_enqueue_script( 'force-refresh-main-admin-js' ); |
| 44 |
} |
| 45 |
); |
| 46 |
|