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 +40 -123 2.1.13.2.1 View file →
@@ -1,144 +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.1.1
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 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.
24 +// phpcs:enable Generic.Files.LineLength
25 +
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.
17 30 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.
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.
20 35 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 );
29 -// All the post types to exclude force refreshing from
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.
30 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' );
31 43
32 -// Make sure we include the composer autoload file
33 -require_once __DIR__ . "/vendor/autoload.php";
34 -
35 -// Include the functions file
36 -require_once __DIR__ . "/includes/functions.php";
37 -
38 44 /**
39 - * 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.
40 47 *
41 - * @return string The full directory this plugin is located in (including the plugin directory)
42 - *
43 - * @version 2.0 Introducted in version 2.0
48 + * @return string The file path for this file
44 49 */
45 -function get_force_refresh_plugin_directory(){
46 -
47 - // Declare our plugin directory
48 - $plugin_directory = plugin_dir_path(__FILE__);
49 -
50 - return $plugin_directory;
50 +function get_main_plugin_file() {
51 + return __FILE__;
51 52 }
52 53
53 -/**
54 - * Function for getting the uri for this plugin
55 - *
56 - * @param string $file The optional file path you want to append to the urldecode(str)
57 - *
58 - * @return string The full url for the root of this plugin is located in (including the plugin directory)
59 - *
60 - * @version 2.0 Introducted in version 2.0
61 - */
62 -function get_force_refresh_plugin_url($file = null){
63 -
64 - // Declare our plugin directory
65 - $plugin_url = plugins_url($file, __FILE__);
66 -
67 - return $plugin_url;
68 -}
69 -
70 -// Add the menu where we'll configure the settings
71 -add_action( 'admin_menu', function(){
72 -
73 - add_submenu_page(
74 - 'tools.php',
75 - 'Force Refresh',
76 - 'Force Refresh',
77 - WP_FORCE_REFRESH_CAPABILITY,
78 - 'force_refresh',
79 - __NAMESPACE__ . '\\manage_force_refresh'
80 - );
81 -
82 -});
83 -
84 -// Add the action to add the Force Refresh capability to allow developers to customize which users and roles
85 -// can init a Force Refresh
86 -add_action("admin_init", function(){
87 -
88 - $role = get_role("administrator");
89 -
90 - $role->add_cap(WP_FORCE_REFRESH_CAPABILITY);
91 -
92 -});
93 -
94 -// Add the script for normal frontfacing pages (non-admin)
95 -add_action("wp_enqueue_scripts", function(){
96 -
97 - // Include the normal JS
98 - add_script("force-refresh-js", "/dist/js/force-refresh.js", true);
99 -
100 - // 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)
101 - wp_localize_script(
102 - "force-refresh-js",
103 - "force_refresh_js_object",
104 - array(
105 - // Get the ajax URL
106 - 'ajax_url' => admin_url( 'admin-ajax.php' ),
107 - // Get the post ID
108 - 'post_id' => get_the_ID(),
109 - // Get the refresh interval
110 - 'refresh_interval' => get_option( WP_FORCE_REFRESH_OPTION_REFRESH_INTERVAL_IN_SECONDS, WP_FORCE_REFRESH_OPTION_REFRESH_INTERVAL_IN_SECONDS_DEFAULT )
111 - )
112 - );
113 -
114 - // Now that it's registered, enqueue the script
115 - wp_enqueue_script("force-refresh-js");
116 -
117 -});
118 -
119 -// Add meta boxes for specific pages that we want to refresh
120 -add_action('add_meta_boxes', function(){
121 - // All post types
122 - $all_post_types = get_post_types();
123 - // Loop through all the post types
124 - foreach ($all_post_types as $post_type => $post_key) {
125 - // Get the post type attributes
126 - $post_type_attributes = get_post_type_object( $post_type );
127 - // The post types public attribute
128 - $post_type_is_public = $post_type_attributes->public;
129 - // Only add the box if the post type is public and we're not excluding
130 - // the post type
131 - if ( $post_type_is_public && !in_array($post_type, WP_FORCE_REFRESH_EXCLUDE_FROM_POST_TYPES )){
132 - // Add the box
133 - add_meta_box(
134 - 'force_refresh_specific_page_refresh',
135 - 'Force Refresh',
136 - __NAMESPACE__ . '\\force_refresh_specific_page_refresh_html',
137 - $post_type,
138 - 'side'
139 - );
140 - }
141 - }
142 -});
143 -
144 -?>
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';