PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 3.0.5
Admin Columns v3.0.5
7.1.4 7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Notice / Plugin.php
codepress-admin-columns / classes / Notice Last commit date
Plugin.php 8 years ago Review.php 8 years ago
Plugin.php
183 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 final class AC_Notice_Plugin {
8
9 /**
10 * @var string
11 */
12 private $plugin_basename;
13
14 /**
15 * @var string
16 */
17 private $message;
18
19 /**
20 * @var string
21 */
22 private $class;
23
24 /**
25 * @var string
26 */
27 private $icon;
28
29 /**
30 * @param string $plugin_basename
31 */
32 public function __construct( $plugin_basename ) {
33 $this->plugin_basename = $plugin_basename;
34 $this->set_type( 'warning' );
35 }
36
37 /**
38 * Check if the plugin has an update available
39 *
40 * @return bool
41 */
42 private function update_available() {
43 $current = get_site_transient( 'update_plugins' );
44
45 return isset( $current->response[ $this->plugin_basename ] );
46 }
47
48 public function hook_notice() {
49 add_action( 'after_plugin_row_' . $this->plugin_basename, array( $this, 'display_notice' ), 11 );
50 }
51
52 public function display_notice() {
53 $class = '';
54
55 if ( is_plugin_active( $this->plugin_basename ) ) {
56 $class .= ' active';
57
58 if ( $this->update_available() ) {
59 $class .= ' update';
60 }
61 }
62
63 ?>
64
65 <style>
66 .plugins tr[data-plugin='<?php echo $this->plugin_basename; ?>'] th,
67 .plugins tr[data-plugin='<?php echo $this->plugin_basename; ?>'] td {
68 box-shadow: none;
69 }
70
71 <?php if ( $this->icon ) : ?>
72 .plugins tr[data-plugin='<?php echo $this->plugin_basename; ?>'] .update-message p:before {
73 content: "<?php echo $this->icon ?>";
74 }
75
76 <?php endif; ?>
77 </style>
78
79 <tr class="plugin-update-tr <?php echo esc_attr( $class ); ?>" data-slug="<?php echo esc_attr( basename( $this->plugin_basename ) ); ?>" data-plugin="<?php echo esc_attr( $this->plugin_basename ); ?>">
80 <td colspan="3" class="plugin-update colspanchange">
81 <div class="update-message notice inline <?php echo esc_attr( $this->class ); ?>">
82 <p><?php echo $this->message; ?></p>
83 </div>
84 </td>
85 </tr>
86
87 <?php
88 }
89
90 /**
91 * Set the message of this notice. Only links allowed, other HTML is escaped
92 *
93 * @param string $message
94 *
95 * @return $this
96 */
97 public function set_message( $message ) {
98 $this->message = wp_kses( $message, array(
99 'strong' => array(),
100 'br' => array(),
101 'a' => array(
102 'class' => true,
103 'data' => true,
104 'href' => true,
105 'id' => true,
106 'title' => true,
107 ),
108 ) );
109
110 return $this;
111 }
112
113 private function get_predefined_type( $type ) {
114 $mapping = array(
115 'warning' => 'notice-warning|\f348',
116 'error' => 'notice-error|\f534',
117 'success' => 'updated-message notice-success|\f147',
118 'update' => 'notice-warning|\f463',
119 );
120
121 if ( array_key_exists( $type, $mapping ) ) {
122 $parts = explode( '|', $mapping[ $type ] );
123
124 return (object) array(
125 'class' => $parts[0] . ' notice-alt',
126 'icon' => $parts[1],
127 );
128 }
129
130 return false;
131 }
132
133 public function set_type( $type ) {
134 $type = $this->get_predefined_type( $type );
135
136 if ( $type ) {
137 $this->set_class( $type->class );
138 $this->set_icon( $type->icon );
139 }
140
141 return $this;
142 }
143
144 /**
145 * Set the color-scheme of the notice
146 *
147 * @param string $class
148 *
149 * @return $this
150 */
151 public function set_class( $class ) {
152 $type = $this->get_predefined_type( $class );
153
154 if ( $type ) {
155 $class = $type->class;
156 }
157
158 $this->class = $class;
159
160 return $this;
161 }
162
163 /**
164 * Set the icon of the notice. Defaults to 'update'
165 *
166 * @param string $icon
167 *
168 * @return $this
169 */
170 public function set_icon( $icon ) {
171 $type = $this->get_predefined_type( $icon );
172
173 if ( $type ) {
174 $icon = $type->icon;
175 }
176
177 $this->icon = $icon;
178
179 return $this;
180 }
181
182 }
183