PluginProbe ʕ •ᴥ•ʔ
Clear Cache Everywhere / 1.1.1
Clear Cache Everywhere v1.1.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 8 months ago js 8 months ago admin-bar.php 8 months ago clear-cache.php 8 months ago common.php 8 months ago index.php 8 months ago settings.php 8 months ago
admin-bar.php
93 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 // Add admin bar menu button
46 add_action( 'admin_bar_menu', [ $this, 'add_admin_bar_button' ], 100 );
47
48 // Enqueue scripts
49 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
50 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
51
52 } // End init()
53
54
55 /**
56 * Add a button to the admin bar
57 *
58 * @return void
59 */
60 public function add_admin_bar_button( $wp_admin_bar ) {
61 // Check if the user has the necessary permissions
62 if ( current_user_can( 'manage_options' ) ) {
63
64 // The clear cache url
65 $clear_cache_url = add_query_arg( [
66 (new Clear())->action_param => 1,
67 '_wpnonce' => wp_create_nonce( $this->nonce )
68 ] );
69
70 // Add a custom button
71 $wp_admin_bar->add_node( [
72 'id' => 'cceverywhere_adminbar_btn',
73 'title' => '<span class="ab-icon dashicons dashicons-editor-removeformatting" title="' . CCEVERYWHERE_NAME . '"></span><span class="ab-label">' . __( 'Clear Cache', 'clear-cache-everywhere' ) . '</span>',
74 'href' => $clear_cache_url,
75 'meta' => [
76 'class' => 'clear-cache-button'
77 ]
78 ] );
79 }
80 } // End add_admin_bar_button()
81
82
83 /**
84 * Enqueue scripts
85 *
86 * @return void
87 */
88 public function enqueue_scripts() {
89 // CSS
90 wp_enqueue_style( CCEVERYWHERE_TEXTDOMAIN . '-styles', CCEVERYWHERE_CSS_PATH . 'admin-bar.css', [], CCEVERYWHERE_VERSION );
91 } // End enqueue_scripts()
92 }
93