PluginProbe
Force Refresh / 2.1.5
Force Refresh v2.1.5
3.2.1 3.2.0 3.1.2 3.1.1 3.1.0 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.11.0 2.11.1 2.12.0 All 54 releases
force-refresh / includes / actions / client / inc.refresh-js.php

inc.refresh-js.php in Force Refresh 2.1.5, at includes/actions/client/inc.refresh-js.php

39 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 // Add the script for normal front-facing pages (non-admin).
12 add_action(
13 'wp_enqueue_scripts',
14 function() {
15 // Include the normal JS.
16 add_script( 'force-refresh-js', '/dist/js/force-refresh.js', true );
17 // Localize the admin ajax URL. This doesn't sound like the best idea but WP is into
18 // it (https://codex.wordpress.org/AJAX_in_Plugins).
19 wp_localize_script(
20 'force-refresh-js',
21 'forceRefreshLocalizedData',
22 array(
23 // Get the ajax URL.
24 'apiUrl' => admin_url( 'admin-ajax.php' ),
25 // Get the post ID.
26 'postId' => get_the_ID(),
27 'nonce' => wp_create_nonce( WP_ACTION_GET_VERSION ),
28 // Get the refresh interval.
29 'refreshInterval' => get_option(
30 WP_FORCE_REFRESH_OPTION_REFRESH_INTERVAL_IN_SECONDS,
31 WP_FORCE_REFRESH_OPTION_REFRESH_INTERVAL_IN_SECONDS_DEFAULT
32 ),
33 )
34 );
35 // Now that it's registered, enqueue the script.
36 wp_enqueue_script( 'force-refresh-js' );
37 }
38 );
39