| 1 |
<?php |
| 2 |
/** |
| 3 |
* The actions to register and enqueue all of our client-side JavaScript |
| 4 |
* to request site versions. |
| 5 |
* |
| 6 |
* @package ForceRefresh |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace JordanLeven\Plugins\ForceRefresh; |
| 10 |
|
| 11 |
use JordanLeven\Plugins\ForceRefresh\Api\Api_Handler_Client; |
| 12 |
use JordanLeven\Plugins\ForceRefresh\Services\Debug_Storage_Service; |
| 13 |
use JordanLeven\Plugins\ForceRefresh\Services\Options_Storage_Service; |
| 14 |
|
| 15 |
// Add the script for normal front-facing pages (non-admin). |
| 16 |
add_action( |
| 17 |
'wp_enqueue_scripts', |
| 18 |
function() { |
| 19 |
// Include the normal JS. |
| 20 |
add_script( 'force-refresh-js', '/dist/js/force-refresh.js', true ); |
| 21 |
// Localize the admin ajax URL. This doesn't sound like the best idea but WP is into |
| 22 |
// it (https://codex.wordpress.org/AJAX_in_Plugins). |
| 23 |
wp_localize_script( |
| 24 |
'force-refresh-js', |
| 25 |
'forceRefreshLocalizedData', |
| 26 |
array( |
| 27 |
// Get the ajax URL. |
| 28 |
'apiEndpoint' => Api_Handler_Client::get_rest_endpoint(), |
| 29 |
// Get the post ID. |
| 30 |
'postId' => get_the_ID(), |
| 31 |
'isDebugActive' => Debug_Storage_Service::debug_mode_is_active(), |
| 32 |
// Get the refresh interval. |
| 33 |
'refreshInterval' => Options_Storage_Service::get_refresh_interval(), |
| 34 |
) |
| 35 |
); |
| 36 |
// Now that it's registered, enqueue the script. |
| 37 |
wp_enqueue_script( 'force-refresh-js' ); |
| 38 |
} |
| 39 |
); |
| 40 |
|