PluginProbe
Groups – Memberships and Access Control / 4.7.1
Groups – Memberships and Access Control v4.7.1
4.7.1 4.7.0 4.6.0 4.5.0 4.4.0 4.3.0 trunk 1.0.0-beta-1 1.0.0-beta-2 1.0.0-beta-3 1.0.0-beta-3b 1.0.0-beta-3c 1.0.0-beta-3d 1.1.4 1.1.5 1.10.0 1.10.1 1.10.2 1.10.3 1.11.0 1.11.1 1.11.2 1.11.3 1.12.0 1.13.0 All 131 releases
← All changes | lib/admin/class-groups-admin.php +114 -52 1.11.34.7.1 View file →
@@ -29,15 +29,16 @@
29 29 class Groups_Admin {
30 30
31 31 /**
32 32 * The position of the Groups menu.
33 - *
33 + *
34 34 * @var int
35 35 */
36 - const MENU_POSITION = '38.381';
36 + const MENU_POSITION = 38;
37 37
38 38 /**
39 39 * Holds admin messages.
40 + *
40 41 * @var string
41 42 */
42 43 private static $messages = array();
43 44
@@ -50,12 +51,14 @@
50 51 add_action( 'admin_head', array( __CLASS__, 'admin_head' ) );
51 52 add_action( 'admin_menu', array( __CLASS__, 'admin_menu' ) );
52 53 add_action( 'network_admin_menu', array( __CLASS__, 'network_admin_menu' ) );
53 54 add_filter( 'plugin_action_links_'. plugin_basename( GROUPS_FILE ), array( __CLASS__, 'plugin_action_links' ) );
55 + add_action( 'after_plugin_row_' . plugin_basename( GROUPS_FILE ), array( __CLASS__, 'after_plugin_row' ), 10, 3 );
54 56 }
55 57
56 58 /**
57 59 * Hooks into admin_init.
60 + *
58 61 * @see Groups_Admin::admin_menu()
59 62 * @see Groups_Admin::admin_print_styles()
60 63 * @link http://codex.wordpress.org/Function_Reference/wp_enqueue_script#Load_scripts_only_on_plugin_pages
61 64 */
@@ -61,27 +64,48 @@
61 64 */
62 65 public static function admin_init() {
63 66 global $groups_version;
64 67 wp_register_style( 'groups_admin', GROUPS_PLUGIN_URL . 'css/groups_admin.css', array(), $groups_version );
68 + wp_register_style( 'groups_admin_post', GROUPS_PLUGIN_URL . 'css/groups_admin_post.css', array(), $groups_version );
69 + wp_register_style( 'groups_admin_user', GROUPS_PLUGIN_URL . 'css/groups_admin_user.css', array(), $groups_version );
65 70 require_once GROUPS_VIEWS_LIB . '/class-groups-uie.php';
71 + add_action( 'admin_enqueue_scripts', array( __CLASS__, 'admin_enqueue_scripts' ) );
66 72 }
67 73
68 74 /**
69 75 * Loads styles for the Groups admin section.
70 - *
76 + *
71 77 * @see Groups_Admin::admin_menu()
72 78 */
73 79 public static function admin_print_styles() {
74 - wp_enqueue_style( 'groups_admin' );
80 + if ( !wp_style_is( 'groups_admin' ) ) {
81 + wp_enqueue_style( 'groups_admin' );
82 + }
75 83 }
76 84
77 85 /**
86 + * Enqueue admin scripts and styles.
87 + *
88 + * @since 4.4.0
89 + *
90 + * @param string $hook_suffix the current admin page
91 + */
92 + public static function admin_enqueue_scripts( $hook_suffix ) {
93 + // Note that we keep using self::admin_print_styles() and self::admin_print_scripts() via actions registered in self::admin_menu().
94 + // So all extension-added children have these loaded automatically, rely on match.
95 + if ( strpos( $hook_suffix, '_page_groups-' ) !== false ) {
96 + if ( !wp_style_is( 'groups_admin' ) ) {
97 + wp_enqueue_style( 'groups_admin' );
98 + }
99 + Groups_UIE::enqueue( 'select' );
100 + }
101 + }
102 +
103 + /**
78 104 * Loads scripts.
79 105 */
80 106 public static function admin_print_scripts() {
81 - global $groups_version;
82 - // this one's currently empty
83 - //wp_enqueue_script( 'groups_admin', GROUPS_PLUGIN_URL . 'js/groups_admin.js', array( ), $groups_version );
107 + // wp_enqueue_script( 'groups-admin', GROUPS_PLUGIN_URL . 'js/groups-admin.js', array( ), $groups_version );
84 108 Groups_UIE::enqueue( 'select' );
85 109 }
86 110
87 111 /**
@@ -88,26 +112,29 @@
88 112 * Add a message to the list of messages displayed in the admin sections.
89 113 * The message is filtered using wp_filter_kses() and wrapped in a div
90 114 * with class 'updated' for messages of type 'info' and 'error' for
91 115 * those of type 'error'.
92 - *
116 + *
93 117 * @param string $message the message
94 118 * @param string $type type of message, defaults to 'info'
119 + *
95 120 * @uses wp_filter_kses()
96 121 */
97 122 public static function add_message( $message, $type = 'info' ) {
98 - $class = 'updated';
99 - switch( $type ) {
100 - case 'error' :
101 - $class = 'error';
123 + if ( is_string( $message ) ) {
124 + $class = 'updated';
125 + switch ( $type ) {
126 + case 'error' :
127 + $class = 'error';
128 + }
129 + self::$messages[] = '<div class="'.$class.'">' . balanceTags( stripslashes( wp_filter_kses( $message ) ), true ) . '</div>';
102 130 }
103 - self::$messages[] = '<div class="'.$class.'">' . balanceTags( stripslashes( wp_filter_kses( $message ) ), true ) . '</div>';
104 131 }
105 132
106 133 /**
107 134 * Returns the list of messages as a string.
108 135 * An empty string is returned if there are no messages.
109 - *
136 + *
110 137 * @return string
111 138 */
112 139 public static function render_messages() {
113 140 $output = '';
@@ -112,9 +139,9 @@
112 139 public static function render_messages() {
113 140 $output = '';
114 141 if ( !empty( self::$messages ) ) {
115 142 $output .= '<div class="groups messages">';
116 - $output .= implode( '', self::$messages );
143 + $output .= implode( '', self::$messages ); // messages are already escaped when added using self::add_message()
117 144 $output .= '</div>';
118 145 }
119 146 return $output;
120 147 }
@@ -125,9 +152,9 @@
125 152 public static function admin_notices() {
126 153 global $groups_admin_messages;
127 154 if ( !empty( $groups_admin_messages ) ) {
128 155 foreach ( $groups_admin_messages as $msg ) {
129 - echo $msg;
156 + echo $msg; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
130 157 }
131 158 }
132 159 }
133 160
@@ -136,9 +163,9 @@
136 163 */
137 164 public static function admin_head() {
138 165 global $submenu;
139 166 if ( isset( $submenu['groups-admin'] ) ) {
140 - $submenu['groups-admin'][0][0] = _x( 'Groups', 'menu item title', GROUPS_PLUGIN_DOMAIN );
167 + $submenu['groups-admin'][0][0] = _x( 'Groups', 'menu item title', 'groups' );
141 168 }
142 169 }
143 170
144 171 /**
@@ -145,89 +172,84 @@
145 172 * Admin menu.
146 173 */
147 174 public static function admin_menu() {
148 175
149 - include_once( GROUPS_ADMIN_LIB . '/groups-admin-groups.php');
150 - include_once( GROUPS_ADMIN_LIB . '/groups-admin-capabilities.php');
151 - include_once( GROUPS_ADMIN_LIB . '/groups-admin-options.php');
152 - include_once( GROUPS_ADMIN_LIB . '/groups-admin-add-ons.php');
176 + include_once GROUPS_ADMIN_LIB . '/groups-admin-groups.php';
177 + include_once GROUPS_ADMIN_LIB . '/groups-admin-capabilities.php';
178 + include_once GROUPS_ADMIN_LIB . '/groups-admin-options.php';
179 + include_once GROUPS_ADMIN_LIB . '/groups-admin-add-ons.php';
153 180
154 181 $pages = array();
155 182
156 183 // main
157 184 $page = add_menu_page(
158 - _x( 'Groups', 'page-title', GROUPS_PLUGIN_DOMAIN ),
185 + _x( 'Groups', 'page-title', 'groups' ),
159 186 'Groups', // don't translate, reasons: a) Groups menu title consistency and b) http://core.trac.wordpress.org/ticket/18857 translation affects $screen->id
160 187 GROUPS_ADMINISTER_GROUPS,
161 188 'groups-admin',
162 189 apply_filters( 'groups_add_menu_page_function', 'groups_admin_groups' ),
163 - GROUPS_PLUGIN_URL . '/images/groups.png',
190 + 'none', // @since 2.16.0 CSS icon from SVG
164 191 self::MENU_POSITION
165 192 );
166 193 $pages[] = $page;
167 - add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'admin_print_styles' ) );
168 - add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'admin_print_scripts' ) );
169 194
170 - if ( isset( $_POST[GROUPS_ADMIN_OPTIONS_NONCE] ) && wp_verify_nonce( $_POST[GROUPS_ADMIN_OPTIONS_NONCE], 'admin' ) ) {
171 - $show_tree_view = !empty( $_POST[GROUPS_SHOW_TREE_VIEW] );
195 + if ( groups_verify_post_nonce( GROUPS_ADMIN_OPTIONS_NONCE, 'admin' ) ) {
196 + $show_tree_view = !empty( groups_sanitize_post( GROUPS_SHOW_TREE_VIEW ) );
172 197 } else {
173 198 $show_tree_view = Groups_Options::get_option( GROUPS_SHOW_TREE_VIEW, GROUPS_SHOW_TREE_VIEW_DEFAULT );
174 199 }
175 200
176 201 if ( $show_tree_view ) {
177 - include_once( GROUPS_ADMIN_LIB . '/groups-admin-tree-view.php');
202 + include_once GROUPS_ADMIN_LIB . '/groups-admin-tree-view.php';
178 203 $page = add_submenu_page(
179 204 'groups-admin',
180 - __( 'Tree', GROUPS_PLUGIN_DOMAIN ),
181 - __( 'Tree', GROUPS_PLUGIN_DOMAIN ),
205 + __( 'Tree', 'groups' ),
206 + __( 'Tree', 'groups' ),
182 207 GROUPS_ACCESS_GROUPS,
183 208 'groups-admin-tree-view',
184 209 apply_filters( 'groups_add_submenu_page_function', 'groups_admin_tree_view' )
185 210 );
186 211 $pages[] = $page;
187 - add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'admin_print_styles' ) );
188 - add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'admin_print_scripts' ) );
189 212 }
190 213
191 214 // capabilities
192 215 $page = add_submenu_page(
193 216 'groups-admin',
194 - __( 'Groups Capabilities', GROUPS_PLUGIN_DOMAIN ),
195 - __( 'Capabilities', GROUPS_PLUGIN_DOMAIN ),
217 + __( 'Groups Capabilities', 'groups' ),
218 + __( 'Capabilities', 'groups' ),
196 219 GROUPS_ADMINISTER_GROUPS,
197 220 'groups-admin-capabilities',
198 221 apply_filters( 'groups_add_submenu_page_function', 'groups_admin_capabilities' )
199 222 );
200 223 $pages[] = $page;
201 - add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'admin_print_styles' ) );
202 - add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'admin_print_scripts' ) );
203 224
204 225 // options
205 226 $page = add_submenu_page(
206 227 'groups-admin',
207 - __( 'Groups options', GROUPS_PLUGIN_DOMAIN ),
208 - __( 'Options', GROUPS_PLUGIN_DOMAIN ),
228 + __( 'Groups options', 'groups' ),
229 + __( 'Options', 'groups' ),
209 230 GROUPS_ADMINISTER_OPTIONS,
210 231 'groups-admin-options',
211 232 apply_filters( 'groups_add_submenu_page_function', 'groups_admin_options' )
212 233 );
213 234 $pages[] = $page;
214 - add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'admin_print_styles' ) );
215 - add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'admin_print_scripts' ) );
216 235
217 236 // add-ons
218 237 $page = add_submenu_page(
219 238 'groups-admin',
220 - __( 'Groups Add-Ons', GROUPS_PLUGIN_DOMAIN ),
221 - __( 'Add-Ons', GROUPS_PLUGIN_DOMAIN ),
239 + __( 'Groups Add-Ons', 'groups' ),
240 + __( 'Add-Ons', 'groups' ),
222 241 GROUPS_ACCESS_GROUPS,
223 242 'groups-admin-add-ons',
224 243 apply_filters( 'groups_add_submenu_page_function', 'groups_admin_add_ons' )
225 244 );
226 245 $pages[] = $page;
227 - add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'admin_print_styles' ) );
228 - add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'admin_print_scripts' ) );
229 246
247 + foreach ( $pages as $page ) {
248 + add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'admin_print_styles' ) );
249 + add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'admin_print_scripts' ) );
250 + }
251 +
230 252 do_action( 'groups_admin_menu', $pages );
231 253 }
232 254
233 255 /**
@@ -234,20 +256,20 @@
234 256 * Network admin menu.
235 257 */
236 258 public static function network_admin_menu() {
237 259
238 - include_once( GROUPS_ADMIN_LIB . '/groups-admin-options.php');
260 + include_once GROUPS_ADMIN_LIB . '/groups-admin-options.php';
239 261
240 262 $pages = array();
241 263
242 264 // main
243 265 $page = add_menu_page(
244 - __( 'Groups', GROUPS_PLUGIN_DOMAIN ),
245 - __( 'Groups', GROUPS_PLUGIN_DOMAIN ),
266 + _x( 'Groups', 'Network menu page title', 'groups' ),
267 + 'Groups', // don't translate, see note on same in self::admin_menu()
246 268 GROUPS_ADMINISTER_GROUPS,
247 269 'groups-network-admin',
248 270 apply_filters( 'groups_add_menu_page_function', 'groups_network_admin_options' ),
249 - GROUPS_PLUGIN_URL . '/images/groups.png'
271 + 'none' // @since 2.16.0 CSS icon from SVG
250 272 );
251 273 $pages[] = $page;
252 274 add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'admin_print_styles' ) );
253 275 add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'admin_print_scripts' ) );
@@ -259,22 +281,62 @@
259 281 * Adds plugin links.
260 282 *
261 283 * @param array $links
262 284 * @param array $links with additional links
285 + *
286 + * @return array
263 287 */
264 288 public static function plugin_action_links( $links ) {
265 - if ( current_user_can( GROUPS_ADMINISTER_OPTIONS ) ) {
289 + if ( Groups_User::current_user_can( GROUPS_ADMINISTER_OPTIONS ) ) {
266 290 array_unshift(
267 291 $links,
268 - '<a href="' . get_admin_url( null, 'admin.php?page=groups-admin-options' ) . '">' . __( 'Options', GROUPS_PLUGIN_DOMAIN ) . '</a>'
292 + '<a href="' . get_admin_url( null, 'admin.php?page=groups-admin-options' ) . '">' .
293 + _x( 'Options', 'Plugin action link', 'groups' ) .
294 + '</a>'
269 295 );
270 296 }
271 - if ( current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
297 + if ( Groups_User::current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
272 298 array_unshift(
273 299 $links,
274 - '<a href="' . get_admin_url( null, 'admin.php?page=groups-admin' ) . '">' . __( 'Groups', GROUPS_PLUGIN_DOMAIN ) . '</a>'
300 + '<a href="' . get_admin_url( null, 'admin.php?page=groups-admin' ) . '">' .
301 + _x( 'Groups', 'Plugin action link', 'groups' ) .
302 + '</a>'
275 303 );
276 304 }
277 305 return $links;
306 + }
307 +
308 + /**
309 + * Prints a warning when data is deleted on deactivation.
310 + *
311 + * @param string $plugin_file
312 + * @param array $plugin_data
313 + * @param string $status
314 + */
315 + public static function after_plugin_row( $plugin_file, $plugin_data, $status ) {
316 + if ( $plugin_file == plugin_basename( GROUPS_FILE ) ) {
317 + $delete_data = Groups_Options::get_option( 'groups_delete_data', false );
318 + $delete_network_data = Groups_Options::get_option( 'groups_network_delete_data', false );
319 + if (
320 + ( is_plugin_active( $plugin_file ) && $delete_data && Groups_User::current_user_can( 'install_plugins' ) ) ||
321 + ( is_plugin_active_for_network( $plugin_file ) && $delete_network_data && Groups_User::current_user_can( 'manage_network_plugins' ) )
322 + ) {
323 + echo '<tr class="active">';
324 + echo '<td>&nbsp;</td>';
325 + echo '<td colspan="2">';
326 + echo '<div style="border: 2px solid #dc3232; padding: 1em">';
327 + echo '<p>';
328 + echo '<strong>';
329 + echo esc_html__( 'Warning!', 'groups' );
330 + echo '</strong>';
331 + echo '</p>';
332 + echo '<p>';
333 + echo esc_html__( 'Groups is configured to delete its plugin data on deactivation.', 'groups' );
334 + echo '</p>';
335 + echo '</div>';
336 + echo '</td>';
337 + echo '</tr>';
338 + }
339 + }
278 340 }
279 341 }
280 342 Groups_Admin::init();