PluginProbe
Force Refresh / 3.2.1
Force Refresh v3.2.1
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
← All changes | filter-force-refresh.php +43 -117 2.0.03.2.1 View file →
@@ -1,135 +1,61 @@
1 1 <?php
2 +/**
3 + * The main init file for the Force Refresh plugin.
4 + *
5 + * @package ForceRefresh
6 + */
2 7
3 8 namespace JordanLeven\Plugins\ForceRefresh;
4 9
10 +// phpcs:disable Generic.Files.LineLength
11 +
5 12 /*
6 13 Plugin Name: Force Refresh
7 -Plugin URI:
14 +Plugin URI: https://github.com/jordanleven/force-refresh
8 15 Description: Force Refresh is a simple plugin that allows you to force a page refresh for users currently visiting your site.
9 -Version: 2.0.0
16 +Version: 3.2.1
17 +Requires at least: 5.9
18 +Requires PHP: 7.4
10 19 Author: Jordan Leven
11 20 Author URI: https://github.com/jordanleven
12 -Contributors:
21 +Contributors:
13 22 */
14 23
15 -// Define the name of the action for the refresh. This is used with the nonce to create a unique action
16 -// when admins request a refresh.
17 -define("WP_FORCE_REFRESH_ACTION", "wp_force_refresh");
18 -// Define the name of the capability used to invoke a refresh. This is used for developers who want to fine-tune
19 -// control of what types of users and roles can request a refresh.
20 -define("WP_FORCE_REFRESH_CAPABILITY", "invoke_force_refresh");
21 -// Define the ID for the Handlebars admin notice. This is used to add notifications to the admin screen when a user requests a refresh.
22 -define("WP_FORCE_REFRESH_HANDLEBARS_ADMIN_NOTICE_TEMPLATE_ID", "invoke_force_refresh");
23 -// Define the option for showing the Force Refresh button in the WordPress Admin Bar
24 -define("WP_FORCE_REFRESH_OPTION_SHOW_IN_WP_ADMIN_BAR", "force_refresh_show_in_wp_admin_bar");
25 -// Define the option for the refresh interval (how often the site should check for a new version)
26 -define("WP_FORCE_REFRESH_OPTION_REFRESH_INTERVAL_IN_SECONDS", "force_refresh_refresh_interval");
27 -// Define the default refresh interval
28 -define("WP_FORCE_REFRESH_OPTION_REFRESH_INTERVAL_IN_SECONDS_DEFAULT", 120);
24 +// phpcs:enable Generic.Files.LineLength
29 25
30 -// Make sure we include the composer autoload file
31 -require_once __DIR__ . "/library/vendor/autoload.php";
26 +// The absolute path to the plugin's root directory.
27 +define( 'WP_FORCE_REFRESH_PLUGIN_DIR', __DIR__ );
28 +// Define the name of the action for the refresh. This is used with the nonce to create a unique
29 +// action when admins request a refresh.
30 +define( 'WP_FORCE_REFRESH_ACTION', 'wp_force_refresh' );
31 +// The slug used for Force Refresh on the WordPress.org site.
32 +define( 'WP_FORCE_REFRESH_REPOSITORY_SLUG', 'force-refresh' );
33 +// Define the name of the capability used to invoke a refresh. This is used for developers who want
34 +// to fine-tune control of what types of users and roles can request a refresh.
35 +define( 'WP_FORCE_REFRESH_CAPABILITY', 'invoke_force_refresh' );
36 +// Define the option for whether or not debug mode is active.
37 +define( 'WP_FORCE_REFRESH_OPTION_DEBUG_ACTIVE_DATE', 'force_refresh_debug_active_date' );
38 +// All the post types to exclude force refreshing from.
39 +define( 'WP_FORCE_REFRESH_EXCLUDE_FROM_POST_TYPES', array( 'attachment' ) );
40 +// The action used by browsers to get the current site and page versions. This is used to generate
41 +// the nonce.
42 +define( 'WP_ACTION_GET_VERSION', 'wp_get_version' );
32 43
33 -// Include the functions file
34 -require_once __DIR__ . "/library/custom/functions.php";
35 -
36 44 /**
37 - * Function for getting the directory for this plugin
45 + * Function used to retrieve the main file used in the plugin. This function is
46 + * used frequently by functions that require the apex file used in a plugin.
38 47 *
39 - * @return string The full directory this plugin is located in (including the plugin directory)
40 - *
41 - * @version 2.0 Introducted in version 2.0
48 + * @return string The file path for this file
42 49 */
43 -function get_force_refresh_plugin_directory(){
44 -
45 - // Declare our plugin directory
46 - $plugin_directory = plugin_dir_path(__FILE__);
47 -
48 - return $plugin_directory;
50 +function get_main_plugin_file() {
51 + return __FILE__;
49 52 }
50 53
51 -/**
52 - * Function for getting the uri for this plugin
53 - *
54 - * @param string $file The optional file path you want to append to the urldecode(str)
55 - *
56 - * @return string The full url for the root of this plugin is located in (including the plugin directory)
57 - *
58 - * @version 2.0 Introducted in version 2.0
59 - */
60 -function get_force_refresh_plugin_url($file = null){
61 -
62 - // Declare our plugin directory
63 - $plugin_url = plugins_url($file, __FILE__);
64 -
65 - return $plugin_url;
66 -}
67 -
68 -// Add the menu where we'll configure the settings
69 -add_action( 'admin_menu', function(){
70 -
71 - add_submenu_page(
72 - 'tools.php',
73 - 'Force Refresh',
74 - 'Force Refresh',
75 - WP_FORCE_REFRESH_CAPABILITY,
76 - 'force_refresh',
77 - __NAMESPACE__ . '\\manage_force_refresh'
78 - );
79 -
80 -});
81 -
82 -// Add the action to add the Force Refresh capability to allow developers to customize which users and roles
83 -// can init a Force Refresh
84 -add_action("admin_init", function(){
85 -
86 - $role = get_role("administrator");
87 -
88 - $role->add_cap(WP_FORCE_REFRESH_CAPABILITY);
89 -
90 -});
91 -
92 -// Add the script for normal frontfacing pages (non-admin)
93 -add_action("wp_enqueue_scripts", function(){
94 -
95 - // Include the normal JS
96 - add_script("force-refresh-js", "/library/dist/js/force-refresh.built.min.js", true);
97 -
98 - // Localize the admin ajax URL. This doesn't sound like the best idea but WP is into it (https://codex.wordpress.org/AJAX_in_Plugins)
99 - wp_localize_script(
100 - "force-refresh-js",
101 - "force_refresh_js_object",
102 - array(
103 - // Get the ajax URL
104 - 'ajax_url' => admin_url( 'admin-ajax.php' ),
105 - // Get the post ID
106 - 'post_id' => get_the_ID(),
107 - // Get the refresh interval
108 - 'refresh_interval' => get_option( WP_FORCE_REFRESH_OPTION_REFRESH_INTERVAL_IN_SECONDS, WP_FORCE_REFRESH_OPTION_REFRESH_INTERVAL_IN_SECONDS_DEFAULT )
109 - )
110 - );
111 -
112 - // Now that it's registered, enqueue the script
113 - wp_enqueue_script("force-refresh-js");
114 -
115 -});
116 -
117 -// Add meta boxes for specific pages that we want to refresh
118 -add_action('add_meta_boxes', function(){
119 -
120 - // An array of all screens where we want to implement the meta box
121 - $screens = array("page", "post");
122 -
123 - foreach ($screens as $screen) {
124 - // Add the box
125 - add_meta_box(
126 - 'force_refresh_specific_page_refresh',
127 - 'Force Refresh',
128 - __NAMESPACE__ . '\\force_refresh_specific_page_refresh_html',
129 - $screen,
130 - 'side'
131 - );
132 - }
133 -});
134 -
135 -?>
54 +// Include the plugin autoload file.
55 +require_once __DIR__ . '/includes/autoload.php';
56 +// Include the functions file.
57 +require_once __DIR__ . '/includes/functions.php';
58 +// Register all of our actions.
59 +require_once __DIR__ . '/includes/actions/actions.php';
60 +// Include the API call functions.
61 +require_once __DIR__ . '/includes/api/api.php';