PluginProbe
Groups – Memberships and Access Control / 3.9.0
Groups – Memberships and Access Control v3.9.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 1.13.1 1.2.0 All 129 releases
groups / lib / admin / class-groups-admin.php

class-groups-admin.php in Groups – Memberships and Access Control 3.9.0, at lib/admin/class-groups-admin.php

328 lines 10.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * class-groups-admin.php
4 *
5 * Copyright (c) 2011 "kento" Karim Rahimpur www.itthinx.com
6 *
7 * This code is released under the GNU General Public License.
8 * See COPYRIGHT.txt and LICENSE.txt.
9 *
10 * This code is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * This header and all notices must be kept intact.
16 *
17 * @author Karim Rahimpur
18 * @package groups
19 * @since groups 1.0.0
20 */
21
22 if ( !defined( 'ABSPATH' ) ) {
23 exit;
24 }
25
26 /**
27 * Groups admin sections initialization.
28 */
29 class Groups_Admin {
30
31 /**
32 * The position of the Groups menu.
33 *
34 * @var int
35 */
36 const MENU_POSITION = 38;
37
38 /**
39 * Holds admin messages.
40 *
41 * @var string
42 */
43 private static $messages = array();
44
45 /**
46 * Sets up action hooks.
47 */
48 public static function init() {
49 add_action( 'admin_init', array( __CLASS__, 'admin_init' ) );
50 add_action( 'admin_notices', array( __CLASS__, 'admin_notices' ) );
51 add_action( 'admin_head', array( __CLASS__, 'admin_head' ) );
52 add_action( 'admin_menu', array( __CLASS__, 'admin_menu' ) );
53 add_action( 'network_admin_menu', array( __CLASS__, 'network_admin_menu' ) );
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 );
56 }
57
58 /**
59 * Hooks into admin_init.
60 *
61 * @see Groups_Admin::admin_menu()
62 * @see Groups_Admin::admin_print_styles()
63 * @link http://codex.wordpress.org/Function_Reference/wp_enqueue_script#Load_scripts_only_on_plugin_pages
64 */
65 public static function admin_init() {
66 global $groups_version;
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 );
70 require_once GROUPS_VIEWS_LIB . '/class-groups-uie.php';
71 }
72
73 /**
74 * Loads styles for the Groups admin section.
75 *
76 * @see Groups_Admin::admin_menu()
77 */
78 public static function admin_print_styles() {
79 wp_enqueue_style( 'groups_admin' );
80 }
81
82 /**
83 * Loads scripts.
84 */
85 public static function admin_print_scripts() {
86 global $groups_version;
87 // wp_enqueue_script( 'groups-admin', GROUPS_PLUGIN_URL . 'js/groups-admin.js', array( ), $groups_version );
88 Groups_UIE::enqueue( 'select' );
89 }
90
91 /**
92 * Add a message to the list of messages displayed in the admin sections.
93 * The message is filtered using wp_filter_kses() and wrapped in a div
94 * with class 'updated' for messages of type 'info' and 'error' for
95 * those of type 'error'.
96 *
97 * @param string $message the message
98 * @param string $type type of message, defaults to 'info'
99 *
100 * @uses wp_filter_kses()
101 */
102 public static function add_message( $message, $type = 'info' ) {
103 if ( is_string( $message ) ) {
104 $class = 'updated';
105 switch( $type ) {
106 case 'error' :
107 $class = 'error';
108 }
109 self::$messages[] = '<div class="'.$class.'">' . balanceTags( stripslashes( wp_filter_kses( $message ) ), true ) . '</div>';
110 }
111 }
112
113 /**
114 * Returns the list of messages as a string.
115 * An empty string is returned if there are no messages.
116 *
117 * @return string
118 */
119 public static function render_messages() {
120 $output = '';
121 if ( !empty( self::$messages ) ) {
122 $output .= '<div class="groups messages">';
123 $output .= implode( '', self::$messages ); // messages are already escaped when added using self::add_message()
124 $output .= '</div>';
125 }
126 return $output;
127 }
128
129 /**
130 * Prints admin notices.
131 */
132 public static function admin_notices() {
133 global $groups_admin_messages;
134 if ( !empty( $groups_admin_messages ) ) {
135 foreach ( $groups_admin_messages as $msg ) {
136 echo $msg; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
137 }
138 }
139 }
140
141 /**
142 * Use a context-sensitive menu item title.
143 */
144 public static function admin_head() {
145 global $submenu;
146 if ( isset( $submenu['groups-admin'] ) ) {
147 $submenu['groups-admin'][0][0] = _x( 'Groups', 'menu item title', 'groups' );
148 }
149 }
150
151 /**
152 * Admin menu.
153 */
154 public static function admin_menu() {
155
156 include_once GROUPS_ADMIN_LIB . '/groups-admin-groups.php';
157 include_once GROUPS_ADMIN_LIB . '/groups-admin-capabilities.php';
158 include_once GROUPS_ADMIN_LIB . '/groups-admin-options.php';
159 include_once GROUPS_ADMIN_LIB . '/groups-admin-add-ons.php';
160
161 $pages = array();
162
163 // main
164 $page = add_menu_page(
165 _x( 'Groups', 'page-title', 'groups' ),
166 'Groups', // don't translate, reasons: a) Groups menu title consistency and b) http://core.trac.wordpress.org/ticket/18857 translation affects $screen->id
167 GROUPS_ADMINISTER_GROUPS,
168 'groups-admin',
169 apply_filters( 'groups_add_menu_page_function', 'groups_admin_groups' ),
170 'none', // @since 2.16.0 CSS icon from SVG
171 self::MENU_POSITION
172 );
173 $pages[] = $page;
174 add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'admin_print_styles' ) );
175 add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'admin_print_scripts' ) );
176
177 if ( isset( $_POST[GROUPS_ADMIN_OPTIONS_NONCE] ) && wp_verify_nonce( $_POST[GROUPS_ADMIN_OPTIONS_NONCE], 'admin' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
178 $show_tree_view = !empty( $_POST[GROUPS_SHOW_TREE_VIEW] );
179 } else {
180 $show_tree_view = Groups_Options::get_option( GROUPS_SHOW_TREE_VIEW, GROUPS_SHOW_TREE_VIEW_DEFAULT );
181 }
182
183 if ( $show_tree_view ) {
184 include_once GROUPS_ADMIN_LIB . '/groups-admin-tree-view.php';
185 $page = add_submenu_page(
186 'groups-admin',
187 __( 'Tree', 'groups' ),
188 __( 'Tree', 'groups' ),
189 GROUPS_ACCESS_GROUPS,
190 'groups-admin-tree-view',
191 apply_filters( 'groups_add_submenu_page_function', 'groups_admin_tree_view' )
192 );
193 $pages[] = $page;
194 add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'admin_print_styles' ) );
195 add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'admin_print_scripts' ) );
196 }
197
198 // capabilities
199 $page = add_submenu_page(
200 'groups-admin',
201 __( 'Groups Capabilities', 'groups' ),
202 __( 'Capabilities', 'groups' ),
203 GROUPS_ADMINISTER_GROUPS,
204 'groups-admin-capabilities',
205 apply_filters( 'groups_add_submenu_page_function', 'groups_admin_capabilities' )
206 );
207 $pages[] = $page;
208 add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'admin_print_styles' ) );
209 add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'admin_print_scripts' ) );
210
211 // options
212 $page = add_submenu_page(
213 'groups-admin',
214 __( 'Groups options', 'groups' ),
215 __( 'Options', 'groups' ),
216 GROUPS_ADMINISTER_OPTIONS,
217 'groups-admin-options',
218 apply_filters( 'groups_add_submenu_page_function', 'groups_admin_options' )
219 );
220 $pages[] = $page;
221 add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'admin_print_styles' ) );
222 add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'admin_print_scripts' ) );
223
224 // add-ons
225 $page = add_submenu_page(
226 'groups-admin',
227 __( 'Groups Add-Ons', 'groups' ),
228 __( 'Add-Ons', 'groups' ),
229 GROUPS_ACCESS_GROUPS,
230 'groups-admin-add-ons',
231 apply_filters( 'groups_add_submenu_page_function', 'groups_admin_add_ons' )
232 );
233 $pages[] = $page;
234 add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'admin_print_styles' ) );
235 add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'admin_print_scripts' ) );
236
237 do_action( 'groups_admin_menu', $pages );
238 }
239
240 /**
241 * Network admin menu.
242 */
243 public static function network_admin_menu() {
244
245 include_once GROUPS_ADMIN_LIB . '/groups-admin-options.php';
246
247 $pages = array();
248
249 // main
250 $page = add_menu_page(
251 _x( 'Groups', 'Network menu page title', 'groups' ),
252 'Groups', // don't translate, see note on same in self::admin_menu()
253 GROUPS_ADMINISTER_GROUPS,
254 'groups-network-admin',
255 apply_filters( 'groups_add_menu_page_function', 'groups_network_admin_options' ),
256 'none' // @since 2.16.0 CSS icon from SVG
257 );
258 $pages[] = $page;
259 add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'admin_print_styles' ) );
260 add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'admin_print_scripts' ) );
261
262 do_action( 'groups_network_admin_menu', $pages );
263 }
264
265 /**
266 * Adds plugin links.
267 *
268 * @param array $links
269 * @param array $links with additional links
270 *
271 * @return array
272 */
273 public static function plugin_action_links( $links ) {
274 if ( Groups_User::current_user_can( GROUPS_ADMINISTER_OPTIONS ) ) {
275 array_unshift(
276 $links,
277 '<a href="' . get_admin_url( null, 'admin.php?page=groups-admin-options' ) . '">' .
278 _x( 'Options', 'Plugin action link', 'groups' ) .
279 '</a>'
280 );
281 }
282 if ( Groups_User::current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
283 array_unshift(
284 $links,
285 '<a href="' . get_admin_url( null, 'admin.php?page=groups-admin' ) . '">' .
286 _x( 'Groups', 'Plugin action link', 'groups' ) .
287 '</a>'
288 );
289 }
290 return $links;
291 }
292
293 /**
294 * Prints a warning when data is deleted on deactivation.
295 *
296 * @param string $plugin_file
297 * @param array $plugin_data
298 * @param string $status
299 */
300 public static function after_plugin_row( $plugin_file, $plugin_data, $status ) {
301 if ( $plugin_file == plugin_basename( GROUPS_FILE ) ) {
302 $delete_data = Groups_Options::get_option( 'groups_delete_data', false );
303 $delete_network_data = Groups_Options::get_option( 'groups_network_delete_data', false );
304 if (
305 ( is_plugin_active( $plugin_file ) && $delete_data && Groups_User::current_user_can( 'install_plugins' ) ) ||
306 ( is_plugin_active_for_network( $plugin_file ) && $delete_network_data && Groups_User::current_user_can( 'manage_network_plugins' ) )
307 ) {
308 echo '<tr class="active">';
309 echo '<td>&nbsp;</td>';
310 echo '<td colspan="2">';
311 echo '<div style="border: 2px solid #dc3232; padding: 1em">';
312 echo '<p>';
313 echo '<strong>';
314 echo esc_html__( 'Warning!', 'groups' );
315 echo '</strong>';
316 echo '</p>';
317 echo '<p>';
318 echo esc_html__( 'Groups is configured to delete its plugin data on deactivation.', 'groups' );
319 echo '</p>';
320 echo '</div>';
321 echo '</td>';
322 echo '</tr>';
323 }
324 }
325 }
326 }
327 Groups_Admin::init();
328