PluginProbe ʕ •ᴥ•ʔ
Clear Cache Everywhere / 1.2.1
Clear Cache Everywhere v1.2.1
trunk 1.1.0 1.1.1 1.2.0 1.2.1 1.2.1.1 1.2.2
clear-cache-everywhere / inc / admin-bar.php
clear-cache-everywhere / inc Last commit date
css 3 months ago js 3 months ago admin-bar.php 3 months ago clear-cache.php 3 months ago common.php 3 months ago index.php 3 months ago settings.php 3 months ago
admin-bar.php
97 lines
1 <?php
2 /**
3 * Plugin settings
4 */
5
6
7 /**
8 * Define Namespaces
9 */
10 namespace Apos37\ClearCache;
11
12
13 /**
14 * Exit if accessed directly.
15 */
16 if ( !defined( 'ABSPATH' ) ) exit;
17
18
19 /**
20 * Instantiate the class
21 */
22 add_action( 'init', function() {
23 (new AdminBar())->init();
24 } );
25
26
27 /**
28 * The class
29 */
30 class AdminBar {
31
32 /**
33 * Nonce
34 *
35 * @var string
36 */
37 private $nonce = 'cceverywhere_nonce';
38
39
40 /**
41 * Load on init
42 */
43 public function init() {
44
45 // Allow developers to disable admin bar via filter
46 if ( apply_filters( 'cceverywhere_admin_bar_enabled', true ) === false ) {
47 return; // Skip admin bar entirely
48 }
49
50 // Add admin bar menu button
51 add_action( 'admin_bar_menu', [ $this, 'add_admin_bar_button' ], 100 );
52
53 // Enqueue scripts
54 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
55 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
56
57 } // End init()
58
59
60 /**
61 * Add a button to the admin bar
62 *
63 * @return void
64 */
65 public function add_admin_bar_button( $wp_admin_bar ) {
66 // Check if the user has the necessary permissions
67 if ( current_user_can( 'manage_options' ) ) {
68
69 // The clear cache url
70 $clear_cache_url = add_query_arg( [
71 (new Clear())->action_param => 1,
72 '_wpnonce' => wp_create_nonce( $this->nonce )
73 ] );
74
75 // Add a custom button
76 $wp_admin_bar->add_node( [
77 'id' => 'cceverywhere_adminbar_btn',
78 'title' => '<span class="ab-icon dashicons dashicons-editor-removeformatting" title="' . CCEVERYWHERE_NAME . '"></span><span class="ab-label">' . __( 'Clear Cache', 'clear-cache-everywhere' ) . '</span>',
79 'href' => $clear_cache_url,
80 'meta' => [
81 'class' => 'clear-cache-button'
82 ]
83 ] );
84 }
85 } // End add_admin_bar_button()
86
87
88 /**
89 * Enqueue scripts
90 *
91 * @return void
92 */
93 public function enqueue_scripts() {
94 wp_enqueue_style( CCEVERYWHERE_TEXTDOMAIN . '-admin-bar', CCEVERYWHERE_CSS_PATH . 'admin-bar.css', [], CCEVERYWHERE_SCRIPT_VERSION );
95 } // End enqueue_scripts()
96 }
97