PluginProbe
SpinupWP / 1.1
SpinupWP v1.1
trunk 1.0 1.0.1 1.0.2 1.0.3 1.1 1.1.1 1.1.2 1.2 1.3 1.4 1.4.1 1.4.2 1.5 1.5.1 1.6 1.7 1.7.1 1.8.0 1.9.0 1.9.1
spinupwp / src / AdminBar.php

AdminBar.php in SpinupWP 1.1, at src/AdminBar.php

60 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace DeliciousBrains\SpinupWp;
4
5 class AdminBar {
6
7 /**
8 * @var array
9 */
10 private $items = array();
11
12 /**
13 * Init
14 */
15 public function init() {
16 add_action( 'admin_bar_menu', array( $this, 'render' ), 100 );
17 }
18
19 /**
20 * Render the admin bar menu.
21 *
22 * @param $wp_admin_bar
23 */
24 public function render( $wp_admin_bar ) {
25 if ( empty( $this->items ) ) {
26 return;
27 }
28
29 if ( ! current_user_can( apply_filters( 'spinupwp_purge_cache_capability', 'manage_options' ) ) ) {
30 return;
31 }
32
33 $wp_admin_bar->add_node( array(
34 'id' => 'spinupwp',
35 'title' => 'SpinupWP',
36 ) );
37
38 foreach ( $this->items as $item ) {
39 $wp_admin_bar->add_node( array(
40 'parent' => 'spinupwp',
41 'id' => strtolower( str_replace( '', '-', $item['title'] ) ),
42 'title' => $item['title'],
43 'href' => wp_nonce_url( add_query_arg( 'spinupwp_action', $item['action'], admin_url() ), $item['action'] ),
44 ) );
45 }
46 }
47
48 /**
49 * Add an item to the admin bar.
50 *
51 * @param string $title
52 * @param string $action
53 */
54 public function add_item( $title, $action ) {
55 $this->items[] = array(
56 'title' => $title,
57 'action' => $action,
58 );
59 }
60 }