PluginProbe
Force Refresh / 2.12.0
Force Refresh v2.12.0
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 / admin / inc-refresh-ui-admin-bar.php

inc-refresh-ui-admin-bar.php in Force Refresh 2.12.0, at includes/actions/admin/inc-refresh-ui-admin-bar.php

66 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Our action that enables refreshing the site from the admin bar.
4 *
5 * @package ForceRefresh
6 */
7
8 namespace JordanLeven\Plugins\ForceRefresh;
9
10 use JordanLeven\Plugins\ForceRefresh\Services\Options_Storage_Service;
11
12 define( 'FILE_NAME_ADMIN_BAR', 'force-refresh-menu-bar' );
13 define( 'HTML_ID_REFRESH_FROM_MENUBAR', 'force-refresh__menu-bar' );
14 define( 'HTML_ID_REFRESH_NOTIFICATION_CONTAINER', 'force-refresh-notification-container' );
15
16 /**
17 * Function to determine whether or not to include admin bar HTML.
18 *
19 * @return bool True if the admin bar HTML should be rendered.
20 */
21 function render_admin_bar_html(): bool {
22 return user_can_request_force_refresh() && Options_Storage_Service::get_show_in_admin_bar();
23 }
24
25 /**
26 * Function to show the Force Refresh option in the WP Admin bar.
27 *
28 * @return void
29 */
30 function show_force_refresh_in_wp_admin_bar() {
31 // Globalize the WP Admin Bar object.
32 global $wp_admin_bar;
33
34 // If the user isn't able to request a refresh, then stop eval.
35 if ( ! render_admin_bar_html() || ! is_admin() ) {
36 return;
37 }
38
39 // Add the menu.
40 $wp_admin_bar->add_menu(
41 array(
42 'id' => 'force-refresh',
43 'title' => '<div id="' . HTML_ID_REFRESH_FROM_MENUBAR . '"></div>',
44 'href' => null,
45 )
46 );
47 }
48
49 add_action(
50 'wp_before_admin_bar_render',
51 __NAMESPACE__ . '\\show_force_refresh_in_wp_admin_bar',
52 999
53 );
54
55 add_action(
56 'in_admin_header',
57 function () {
58 // If the user isn't able to request a refresh, then stop eval.
59 if ( ! render_admin_bar_html() ) {
60 return;
61 }
62
63 echo '<div id="' . esc_html( HTML_ID_REFRESH_NOTIFICATION_CONTAINER ) . '"></div>';
64 }
65 );
66