PluginProbe
Edit Flow / 0.7.3
Edit Flow v0.7.3
0.11.1 0.11.0 0.7.2 0.7.3 0.7.4 0.7.5 0.7.6 0.8 0.8.1 0.8.2 0.9 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5 0.9.6 0.9.7 0.9.8 0.9.9 trunk 0.1.5 0.10.0 0.10.1 0.10.2 All 44 releases
edit-flow / modules / user-groups / user-groups.php

user-groups.php in Edit Flow 0.7.3, at modules/user-groups/user-groups.php

1,239 lines 45.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * class EF_User_Groups
4 *
5 * @todo all of them PHPdocs
6 * @todo Resolve whether the notifications component of this class should be moved to "subscriptions"
7 * @todo Decide whether it's functional to store user_ids in the term description array
8 * - Argument against: it's going to be expensive to look up usergroups for a user
9 *
10 */
11
12 if ( !class_exists( 'EF_User_Groups' ) ) {
13
14 class EF_User_Groups extends EF_Module {
15
16 var $module;
17
18 /**
19 * Keys for storing data
20 * - taxonomy_key - used for custom taxonomy
21 * - term_prefix - Used for custom taxonomy terms
22 */
23 const taxonomy_key = 'ef_usergroup';
24 const term_prefix = 'ef-usergroup-';
25
26 var $manage_usergroups_cap = 'edit_usergroups';
27
28 /**
29 * Register the module with Edit Flow but don't do anything else
30 *
31 * @since 0.7
32 */
33 function __construct( ) {
34 global $edit_flow;
35
36 $this->module_url = $this->get_module_url( __FILE__ );
37
38 // Register the User Groups module with Edit Flow
39 $args = array(
40 'title' => __( 'User Groups', 'edit-flow' ),
41 'short_description' => __( 'Organize your users into groups to mimic your organizational structure.', 'edit-flow' ),
42 'extended_description' => __( 'Configure user groups to organize all of the users on your site. Each user can be in many user groups and you can change them at any time.', 'edit-flow' ),
43 'module_url' => $this->module_url,
44 'img_url' => $this->module_url . 'lib/usergroups_s128.png',
45 'slug' => 'user-groups',
46 'default_options' => array(
47 'enabled' => 'on',
48 'post_types' => array(
49 'post' => 'on',
50 'page' => 'off',
51 ),
52 ),
53 'messages' => array(
54 'usergroup-added' => __( "User group created. Feel free to add users to the usergroup.", 'edit-flow' ),
55 'usergroup-updated' => __( "User group updated.", 'edit-flow' ),
56 'usergroup-missing' => __( "User group doesn't exist.", 'edit-flow' ),
57 'usergroup-deleted' => __( "User group deleted.", 'edit-flow' ),
58 ),
59 'configure_page_cb' => 'print_configure_view',
60 'configure_link_text' => __( 'Manage User Groups', 'edit-flow' ),
61 'autoload' => false,
62 'settings_help_tab' => array(
63 'id' => 'ef-user-groups-overview',
64 'title' => __('Overview', 'edit-flow'),
65 'content' => __('<p>For those with many people involved in the publishing process, user groups helps you keep them organized.</p><p>Currently, user groups are primarily used for subscribing a set of users to a post for notifications.</p>', 'edit-flow'),
66 ),
67 'settings_help_sidebar' => __( '<p><strong>For more information:</strong></p><p><a href="http://editflow.org/features/user-groups/">User Groups Documentation</a></p><p><a href="http://wordpress.org/tags/edit-flow?forum_id=10">Edit Flow Forum</a></p><p><a href="https://github.com/danielbachhuber/Edit-Flow">Edit Flow on Github</a></p>', 'edit-flow' ),
68 );
69 $this->module = $edit_flow->register_module( 'user_groups', $args );
70
71 }
72
73 /**
74 * Module startup
75 */
76
77 /**
78 * Initialize the rest of the stuff in the class if the module is active
79 *
80 * @since 0.7
81 */
82 function init() {
83
84 // Register the objects where we'll be storing data and relationships
85 $this->register_usergroup_objects();
86
87 $this->manage_usergroups_cap = apply_filters( 'ef_manage_usergroups_cap', $this->manage_usergroups_cap );
88
89 // Register our settings
90 add_action( 'admin_init', array( $this, 'register_settings' ) );
91
92 // Handle any adding, editing or saving
93 add_action( 'admin_init', array( $this, 'handle_add_usergroup' ) );
94 add_action( 'admin_init', array( $this, 'handle_edit_usergroup' ) );
95 add_action( 'admin_init', array( $this, 'handle_delete_usergroup' ) );
96 add_action( 'wp_ajax_inline_save_usergroup', array( $this, 'handle_ajax_inline_save_usergroup' ) );
97
98 // Usergroups can be managed from the User profile view
99 add_action( 'show_user_profile', array( $this, 'user_profile_page' ) );
100 add_action( 'edit_user_profile', array( $this, 'user_profile_page' ) );
101 add_action( 'user_profile_update_errors', array( $this, 'user_profile_update' ), 10, 3 );
102
103 // Javascript and CSS if we need it
104 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
105 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
106
107 }
108
109 /**
110 * Load the capabilities onto users the first time the module is run
111 *
112 * @since 0.7
113 */
114 function install() {
115
116 // Add necessary capabilities to allow management of user groups
117 $usergroup_roles = array(
118 'administrator' => array('edit_usergroups'),
119 );
120 foreach( $usergroup_roles as $role => $caps ) {
121 $this->add_caps_to_role( $role, $caps );
122 }
123
124 // Create our default usergroups
125 $default_usergroups = array(
126 array(
127 'name' => __( 'Copy Editors', 'edit-flow' ),
128 'description' => __( 'Making sure the quality is top-notch.', 'edit-flow' ),
129 ),
130 array(
131 'name' => __( 'Photographers', 'edit-flow' ),
132 'description' => __( 'Capturing the story visually.', 'edit-flow' ),
133 ),
134 array(
135 'name' => __( 'Reporters', 'edit-flow' ),
136 'description' => __( 'Out in the field, writing stories.', 'edit-flow' ),
137 ),
138 array(
139 'name' => __( 'Section Editors', 'edit-flow' ),
140 'description' => __( 'Providing feedback and direction.', 'edit-flow' ),
141 ),
142 );
143 foreach( $default_usergroups as $args ) {
144 $this->add_usergroup( $args );
145 }
146
147 }
148
149 /**
150 * Upgrade our data in case we need to
151 *
152 * @since 0.7
153 */
154 function upgrade( $previous_version ) {
155 global $edit_flow;
156
157 // Upgrade path to v0.7
158 if ( version_compare( $previous_version, '0.7' , '<' ) ) {
159 global $wpdb;
160
161 // Set all of the user group terms to our new taxonomy
162 $wpdb->update( $wpdb->term_taxonomy, array( 'taxonomy' => self::taxonomy_key ), array( 'taxonomy' => 'following_usergroups' ) );
163
164 // Get all of the users who are a part of user groups and assign them to their new user group values
165 $query = $wpdb->prepare( "SELECT * FROM $wpdb->usermeta WHERE meta_key='wp_ef_usergroups';" );
166 $usergroup_users = $wpdb->get_results( $query );
167
168 // Sort all of the users based on their usergroup(s)
169 $users_to_add = array();
170 foreach( (array)$usergroup_users as $usergroup_user ) {
171 if ( is_object( $usergroup_user ) )
172 $users_to_add[$usergroup_user->meta_value][] = (int)$usergroup_user->user_id;
173 }
174 // Add user IDs to each usergroup
175 foreach( $users_to_add as $usergroup_slug => $users_array ) {
176 $usergroup = $this->get_usergroup_by( 'slug', $usergroup_slug );
177 $this->add_users_to_usergroup( $users_array, $usergroup->term_id );
178 }
179 // Update the term slugs for each user group
180 $all_usergroups = $this->get_usergroups();
181 foreach( $all_usergroups as $usergroup ) {
182 $new_slug = str_replace( 'ef_', self::term_prefix, $usergroup->slug );
183 $this->update_usergroup( $usergroup->term_id, array( 'slug' => $new_slug ) );
184 }
185
186 // Delete all of the previous usermeta values
187 $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key='wp_ef_usergroups';" );
188
189 // Technically we've run this code before so we don't want to auto-install new data
190 $edit_flow->update_module_option( $this->module->name, 'loaded_once', true );
191
192 }
193
194 }
195
196 /**
197 * Individual Usergroups are stored using a custom taxonomy
198 * Posts are associated with usergroups based on taxonomy relationship
199 * User associations are stored serialized in the term's description field
200 *
201 * @since 0.7
202 *
203 * @uses register_taxonomy()
204 */
205 function register_usergroup_objects() {
206
207 // Load the currently supported post types so we only register against those
208 $supported_post_types = $this->get_post_types_for_module( $this->module );
209
210 // Use a taxonomy to manage relationships between posts and usergroups
211 $args = array(
212 'public' => false,
213 'rewrite' => false,
214 );
215 register_taxonomy( self::taxonomy_key, $supported_post_types, $args );
216 }
217
218 /**
219 * Enqueue necessary admin scripts
220 *
221 * @since 0.7
222 *
223 * @uses wp_enqueue_script()
224 */
225 function enqueue_admin_scripts() {
226
227 if ( $this->is_whitelisted_functional_view() || $this->is_whitelisted_settings_view( $this->module->name ) ) {
228 wp_enqueue_script( 'jquery-listfilterizer' );
229 wp_enqueue_script( 'jquery-quicksearch' );
230 wp_enqueue_script( 'edit-flow-user-groups-js', $this->module_url . 'lib/user-groups.js', array( 'jquery', 'jquery-listfilterizer', 'jquery-quicksearch' ), EDIT_FLOW_VERSION, true );
231 }
232
233 if ( $this->is_whitelisted_settings_view( $this->module->name ) )
234 wp_enqueue_script( 'edit-flow-user-groups-configure-js', $this->module_url . 'lib/user-groups-configure.js', array( 'jquery' ), EDIT_FLOW_VERSION, true );
235 }
236
237 /**
238 * Enqueue necessary admin styles, but only on the proper pages
239 *
240 * @since 0.7
241 *
242 * @uses wp_enqueue_style()
243 */
244 function enqueue_admin_styles() {
245
246
247 if ( $this->is_whitelisted_functional_view() || $this->is_whitelisted_settings_view() ) {
248 wp_enqueue_style( 'jquery-listfilterizer' );
249 wp_enqueue_style( 'edit-flow-user-groups-css', $this->module_url . 'lib/user-groups.css', false, EDIT_FLOW_VERSION );
250 }
251 }
252
253 /**
254 * Module ???
255 */
256
257 /**
258 * Handles a POST request to add a new Usergroup. Redirects to edit view after
259 * for admin to add users to usergroup
260 * Hooked into 'admin_init' and kicks out right away if no action
261 *
262 * @since 0.7
263 */
264 function handle_add_usergroup() {
265
266 if ( !isset( $_POST['submit'], $_POST['form-action'], $_GET['page'] )
267 || $_GET['page'] != $this->module->settings_slug || $_POST['form-action'] != 'add-usergroup' )
268 return;
269
270 if ( !wp_verify_nonce( $_POST['_wpnonce'], 'add-usergroup' ) )
271 wp_die( $this->module->messages['nonce-failed'] );
272
273 if ( !current_user_can( $this->manage_usergroups_cap ) )
274 wp_die( $this->module->messages['invalid-permissions'] );
275
276 // Sanitize all of the user-entered values
277 $name = strip_tags( trim( $_POST['name'] ) );
278 $description = strip_tags( trim( $_POST['description'] ) );
279
280 $_REQUEST['form-errors'] = array();
281
282 /**
283 * Form validation for adding new Usergroup
284 *
285 * Details
286 * - 'name' is a required field, but can't match an existing name or slug. Needs to be 40 characters or less
287 * - "description" can accept a limited amount of HTML, and is optional
288 */
289 // Field is required
290 if ( empty( $name ) )
291 $_REQUEST['form-errors']['name'] = __( 'Please enter a name for the user group.', 'edit-flow' );
292 // Check to ensure a term with the same name doesn't exist
293 if ( $this->get_usergroup_by( 'name', $name ) )
294 $_REQUEST['form-errors']['name'] = __( 'Name already in use. Please choose another.', 'edit-flow' );
295 // Check to ensure a term with the same slug doesn't exist
296 if ( $this->get_usergroup_by( 'slug', sanitize_title( $name ) ) )
297 $_REQUEST['form-errors']['name'] = __( 'Name conflicts with slug for another term. Please choose again.', 'edit-flow' );
298 if ( strlen( $name ) > 40 )
299 $_REQUEST['form-errors']['name'] = __( 'User group name cannot exceed 40 characters. Please try a shorter name.', 'edit-flow' );
300 // Kick out if there are any errors
301 if ( count( $_REQUEST['form-errors'] ) ) {
302 $_REQUEST['error'] = 'form-error';
303 return;
304 }
305
306 // Try to add the Usergroup
307 $args = array(
308 'name' => $name,
309 'description' => $description,
310 );
311 $usergroup = $this->add_usergroup( $args );
312 if ( is_wp_error( $usergroup ) )
313 wp_die( __( 'Error adding usergroup.', 'edit-flow' ) );
314
315 $args = array(
316 'action' => 'edit-usergroup',
317 'usergroup-id' => $usergroup->term_id,
318 'message' => 'usergroup-added'
319 );
320 $redirect_url = $this->get_link( $args );
321 wp_redirect( $redirect_url );
322 exit;
323 }
324
325 /**
326 * Handles a POST request to edit a Usergroup
327 * Hooked into 'admin_init' and kicks out right away if no action
328 *
329 * @since 0.7
330 */
331 function handle_edit_usergroup() {
332 if ( !isset( $_POST['submit'], $_POST['form-action'], $_GET['page'] )
333 || $_GET['page'] != $this->module->settings_slug || $_POST['form-action'] != 'edit-usergroup' )
334 return;
335
336 if ( !wp_verify_nonce( $_POST['_wpnonce'], 'edit-usergroup' ) )
337 wp_die( $this->module->messages['nonce-failed'] );
338
339 if ( !current_user_can( $this->manage_usergroups_cap ) )
340 wp_die( $this->module->messages['invalid-permissions'] );
341
342 if ( !$existing_usergroup = $this->get_usergroup_by( 'id', (int)$_POST['usergroup_id'] ) )
343 wp_die( $this->module->messsage['usergroup-error'] );
344
345 // Sanitize all of the user-entered values
346 $name = strip_tags( trim( $_POST['name'] ) );
347 $description = strip_tags( trim( $_POST['description'] ) );
348
349 $_REQUEST['form-errors'] = array();
350
351 /**
352 * Form validation for editing a Usergroup
353 *
354 * Details
355 * - 'name' is a required field, but can't match an existing name or slug. Needs to be 40 characters or less
356 * - "description" can accept a limited amount of HTML, and is optional
357 */
358 // Field is required
359 if ( empty( $name ) )
360 $_REQUEST['form-errors']['name'] = __( 'Please enter a name for the user group.', 'edit-flow' );
361 // Check to ensure a term with the same name doesn't exist
362 $search_term = $this->get_usergroup_by( 'name', $name );
363 if ( is_object( $search_term ) && $search_term->term_id != $existing_usergroup->term_id )
364 $_REQUEST['form-errors']['name'] = __( 'Name already in use. Please choose another.', 'edit-flow' );
365 // Check to ensure a term with the same slug doesn't exist
366 $search_term = $this->get_usergroup_by( 'slug', sanitize_title( $name ) );
367 if ( is_object( $search_term ) && $search_term->term_id != $existing_usergroup->term_id )
368 $_REQUEST['form-errors']['name'] = __( 'Name conflicts with slug for another term. Please choose again.', 'edit-flow' );
369 if ( strlen( $name ) > 40 )
370 $_REQUEST['form-errors']['name'] = __( 'User group name cannot exceed 40 characters. Please try a shorter name.', 'edit-flow' );
371 // Kick out if there are any errors
372 if ( count( $_REQUEST['form-errors'] ) ) {
373 $_REQUEST['error'] = 'form-error';
374 return;
375 }
376
377 // Try to edit the Usergroup
378 $args = array(
379 'name' => $name,
380 'description' => $description,
381 );
382 // Gracefully handle the case where all users have been unsubscribed from the user group
383 $users = isset( $_POST['usergroup_users'] ) ? (array)$_POST['usergroup_users'] : array();
384 array_map( 'intval', $users );
385 $usergroup = $this->update_usergroup( $existing_usergroup->term_id, $args, $users );
386 if ( is_wp_error( $usergroup ) )
387 wp_die( __( 'Error updating user group.', 'edit-flow' ) );
388
389 $args = array(
390 'message' => 'usergroup-updated',
391 );
392 $redirect_url = $this->get_link( $args );
393 wp_redirect( $redirect_url );
394 exit;
395 }
396
397 /**
398 * Handles a request to delete a Usergroup.
399 * Hooked into 'admin_init' and kicks out right away if no action
400 *
401 * @since 0.7
402 */
403 function handle_delete_usergroup() {
404 if ( !isset( $_GET['page'], $_GET['action'], $_GET['usergroup-id'] )
405 || $_GET['page'] != $this->module->settings_slug || $_GET['action'] != 'delete-usergroup' )
406 return;
407
408 if ( !wp_verify_nonce( $_GET['nonce'], 'delete-usergroup' ) )
409 wp_die( $this->module->messages['nonce-failed'] );
410
411 if ( !current_user_can( $this->manage_usergroups_cap ) )
412 wp_die( $this->module->messages['invalid-permissions'] );
413
414 $result = $this->delete_usergroup( (int)$_GET['usergroup-id'] );
415 if ( !$result || is_wp_error( $result ) )
416 wp_die( __( 'Error deleting user group.', 'edit-flow' ) );
417
418 $redirect_url = $this->get_link( array( 'message' => 'usergroup-deleted' ) );
419 wp_redirect( $redirect_url );
420 exit;
421 }
422
423 /**
424 * Handle the request to update a given Usergroup via inline edit
425 *
426 * @since 0.7
427 */
428 function handle_ajax_inline_save_usergroup() {
429
430 if ( !wp_verify_nonce( $_POST['inline_edit'], 'usergroups-inline-edit-nonce' ) )
431 die( $this->module->messages['nonce-failed'] );
432
433 if ( !current_user_can( $this->manage_usergroups_cap ) )
434 die( $this->module->messages['invalid-permissions'] );
435
436 $usergroup_id = (int) $_POST['usergroup_id'];
437 if ( !$existing_term = $this->get_usergroup_by( 'id', $usergroup_id ) )
438 die( $this->module->messsage['usergroup-error'] );
439
440 $name = strip_tags( trim( $_POST['name'] ) );
441 $description = strip_tags( trim( $_POST['description'] ) );
442
443 /**
444 * Form validation for editing Usergroup
445 */
446 // Check if name field was filled in
447 if ( empty( $name ) ) {
448 $change_error = new WP_Error( 'invalid', __( 'Please enter a name for the user group.', 'edit-flow' ) );
449 die( $change_error->get_error_message() );
450 }
451 // Check that the name doesn't exceed 40 chars
452 if ( strlen( $name ) > 40 ) {
453 $change_error = new WP_Error( 'invalid', __( 'User group name cannot exceed 40 characters. Please try a shorter name.' ) );
454 die( $change_error->get_error_message() );
455 }
456 // Check to ensure a term with the same name doesn't exist
457 $search_term = $this->get_usergroup_by( 'name', $name );
458 if ( is_object( $search_term ) && $search_term->term_id != $existing_term->term_id ) {
459 $change_error = new WP_Error( 'invalid', __( 'Name already in use. Please choose another.', 'edit-flow' ) );
460 die( $change_error->get_error_message() );
461 }
462 // Check to ensure a term with the same slug doesn't exist
463 $search_term = $this->get_usergroup_by( 'slug', sanitize_title( $name ) );
464 if ( is_object( $search_term ) && $search_term->term_id != $existing_term->term_id ) {
465 $change_error = new WP_Error( 'invalid', __( 'Name conflicts with slug for another term. Please choose again.', 'edit-flow' ) );
466 die( $change_error->get_error_message() );
467 }
468
469 // Prepare the term name and description for saving
470 $args = array(
471 'name' => $name,
472 'description' => $description,
473 );
474 $return = $this->update_usergroup( $existing_term->term_id, $args );
475 if( !is_wp_error( $return ) ) {
476 set_current_screen( 'edit-usergroup' );
477 $wp_list_table = new EF_Usergroups_List_Table();
478 $wp_list_table->prepare_items();
479 echo $wp_list_table->single_row( $return );
480 die();
481 } else {
482 $change_error = new WP_Error( 'invalid', sprintf( __( 'Could not update the user group: <strong>%s</strong>', 'edit-flow' ), $usergroup_name ) );
483 die( $change_error->get_error_message() );
484 }
485
486 }
487
488 /**
489 * Register settings for notifications so we can partially use the Settings API
490 * (We use the Settings API for form generation, but not saving)
491 *
492 * @since 0.7
493 * @uses add_settings_section(), add_settings_field()
494 */
495 function register_settings() {
496 add_settings_section( $this->module->options_group_name . '_general', false, '__return_false', $this->module->options_group_name );
497 add_settings_field( 'post_types', __( 'Add to these post types:', 'edit-flow' ), array( $this, 'settings_post_types_option' ), $this->module->options_group_name, $this->module->options_group_name . '_general' );
498 }
499
500 /**
501 * Choose the post types for Usergroups
502 *
503 * @since 0.7
504 */
505 function settings_post_types_option() {
506 global $edit_flow;
507 $edit_flow->settings->helper_option_custom_post_type( $this->module );
508 }
509
510 /**
511 * Validate data entered by the user
512 *
513 * @since 0.7
514 *
515 * @param array $new_options New values that have been entered by the user
516 * @return array $new_options Form values after they've been sanitized
517 */
518 function settings_validate( $new_options ) {
519
520
521 // Whitelist validation for the post type options
522 if ( !isset( $new_options['post_types'] ) )
523 $new_options['post_types'] = array();
524 $new_options['post_types'] = $this->clean_post_type_options( $new_options['post_types'], $this->module->post_type_support );
525
526 return $new_options;
527 }
528
529 /**
530 * Build a configuration view so we can manage our usergroups
531 *
532 * @since 0.7
533 */
534 function print_configure_view() {
535 global $edit_flow;
536
537 if ( isset( $_GET['action'], $_GET['usergroup-id'] ) && $_GET['action'] == 'edit-usergroup' ) :
538 /** Full page width view for editing a given usergroup **/
539 // Check whether the usergroup exists
540 $usergroup_id = (int)$_GET['usergroup-id'];
541 $usergroup = $this->get_usergroup_by( 'id', $usergroup_id );
542 if ( !$usergroup ) {
543 echo '<div class="error"><p>' . $this->module->messages['usergroup-missing'] . '</p></div>';
544 return;
545 }
546 $name = ( isset( $_POST['name'] ) ) ? stripslashes( $_POST['name'] ) : $usergroup->name;
547 $description = ( isset( $_POST['description'] ) ) ? stripslashes( $_POST['description'] ) : $usergroup->description;
548 ?>
549 <form method="post" action="<?php echo esc_url( $this->get_link( array( 'action' => 'edit-usergroup', 'usergroup-id' => $usergroup_id ) ) ); ?>">
550 <div id="col-right"><div class="col-wrap"><div id="ef-usergroup-users" class="form-wrap">
551 <h4><?php _e( 'Users', 'edit-flow' ); ?></h4>
552 <?php
553 $select_form_args = array(
554 'list_class' => 'ef-post_following_list',
555 'input_id' => 'usergroup_users'
556 );
557 ?>
558 <?php $this->users_select_form( $usergroup->user_ids , $select_form_args ); ?>
559 </div></div></div>
560 <div id="col-left"><div class="col-wrap"><div class="form-wrap">
561 <input type="hidden" name="form-action" value="edit-usergroup" />
562 <input type="hidden" name="usergroup_id" value="<?php echo esc_attr( $usergroup_id ); ?>" />
563 <?php
564 wp_original_referer_field();
565 wp_nonce_field( 'edit-usergroup' );
566 ?>
567 <div class="form-field form-required">
568 <label for="name"><?php _e( 'Name', 'edit-flow' ); ?></label>
569 <input name="name" id="name" type="text" value="<?php echo esc_attr( $name ); ?>" size="40" maxlength="40" aria-required="true" />
570 <?php $edit_flow->settings->helper_print_error_or_description( 'name', __( 'The name is used to identify the user group.', 'edit-flow' ) ); ?>
571 </div>
572 <div class="form-field">
573 <label for="description"><?php _e( 'Description', 'edit-flow' ); ?></label>
574 <textarea name="description" id="description" rows="5" cols="40"><?php echo esc_html( $description ); ?></textarea>
575 <?php $edit_flow->settings->helper_print_error_or_description( 'description', __( 'The description is primarily for administrative use, to give you some context on what the user group is to be used for.', 'edit-flow' ) ); ?>
576 </div>
577 <p class="submit">
578 <?php submit_button( __( 'Update User Group', 'edit-flow' ), 'primary', 'submit', false ); ?>
579 <a class="cancel-settings-link" href="<?php echo esc_url( $this->get_link() ); ?>"><?php _e( 'Cancel', 'edit-flow' ); ?></a>
580 </p>
581 </div></div></div>
582 </form>
583
584 <?php else :
585 /** Full page width view to allow adding a usergroup and edit the existing ones **/
586 $wp_list_table = new EF_Usergroups_List_Table();
587 $wp_list_table->prepare_items();
588 ?>
589 <script type="text/javascript">
590 var ef_confirm_delete_usergroup_string = "<?php _e( 'Are you sure you want to delete the user group?', 'edit-flow' ); ?>";
591 </script>
592 <div id="col-right"><div class="col-wrap">
593 <?php $wp_list_table->display(); ?>
594 </div></div>
595 <div id="col-left"><div class="col-wrap"><div class="form-wrap">
596 <h3 class="nav-tab-wrapper">
597 <a href="<?php echo esc_url( $this->get_link() ); ?>" class="nav-tab<?php if ( !isset( $_GET['action'] ) || $_GET['action'] != 'change-options' ) echo ' nav-tab-active'; ?>"><?php _e( 'Add New', 'edit-flow' ); ?></a>
598 <a href="<?php echo esc_url( $this->get_link( array( 'action' => 'change-options' ) ) ); ?>" class="nav-tab<?php if ( isset( $_GET['action'] ) && $_GET['action'] == 'change-options' ) echo ' nav-tab-active'; ?>"><?php _e( 'Options', 'edit-flow' ); ?></a>
599 </h3>
600 <?php if ( isset( $_GET['action'] ) && $_GET['action'] == 'change-options' ): ?>
601 <form class="basic-settings" action="<?php echo esc_url( $this->get_link( array( 'action' => 'change-options' ) ) ); ?>" method="post">
602 <?php settings_fields( $this->module->options_group_name ); ?>
603 <?php do_settings_sections( $this->module->options_group_name ); ?>
604 <?php echo '<input id="edit_flow_module_name" name="edit_flow_module_name" type="hidden" value="' . esc_attr( $this->module->name ) . '" />'; ?>
605 <?php submit_button(); ?>
606 </form>
607 <?php else: ?>
608 <?php /** Custom form for adding a new Usergroup **/ ?>
609 <form class="add:the-list:" action="<?php echo esc_url( $this->get_link() ); ?>" method="post" id="addusergroup" name="addusergroup">
610 <div class="form-field form-required">
611 <label for="name"><?php _e( 'Name', 'edit-flow' ); ?></label>
612 <input type="text" aria-required="true" id="name" name="name" maxlength="40" value="<?php if ( !empty( $_POST['name'] ) ) echo esc_attr( $_POST['name'] ); ?>" />
613 <?php $edit_flow->settings->helper_print_error_or_description( 'name', __( 'The name is used to identify the user group.', 'edit-flow' ) ); ?>
614 </div>
615 <div class="form-field">
616 <label for="description"><?php _e( 'Description', 'edit-flow' ); ?></label>
617 <textarea cols="40" rows="5" id="description" name="description"><?php if ( !empty( $_POST['description'] ) ) echo esc_html( $_POST['description'] ) ?></textarea>
618 <?php $edit_flow->settings->helper_print_error_or_description( 'description', __( 'The description is primarily for administrative use, to give you some context on what the user group is to be used for.', 'edit-flow' ) ); ?>
619 </div>
620 <?php wp_nonce_field( 'add-usergroup' ); ?>
621 <?php echo '<input id="form-action" name="form-action" type="hidden" value="add-usergroup" />'; ?>
622 <p class="submit"><?php submit_button( __( 'Add New User Group', 'edit-flow' ), 'primary', 'submit', false ); ?><a class="cancel-settings-link" href="<?php echo EDIT_FLOW_SETTINGS_PAGE; ?>"><?php _e( 'Back to Edit Flow', 'edit-flow' ); ?></a></p>
623 </form>
624 <?php endif; ?>
625 </div></div></div>
626 <?php $wp_list_table->inline_edit(); ?>
627 <?php endif;
628 }
629
630 /**
631 * Adds a form to the user profile page to allow adding usergroup selecting options
632 */
633 function user_profile_page() {
634 global $user_id, $profileuser;
635
636 if ( !$user_id || !current_user_can( $this->manage_usergroups_cap ) )
637 return;
638
639 // Assemble all necessary data
640 $usergroups = $this->get_usergroups();
641 $selected_usergroups = $this->get_usergroups_for_user( $user_id );
642 $usergroups_form_args = array( 'input_id' => 'ef_usergroups' );
643 ?>
644 <table id="ef-user-usergroups" class="form-table"><tbody><tr>
645 <th>
646 <h3><?php _e( 'Usergroups', 'edit-flow' ) ?></h3>
647 <?php if ( $user_id === wp_get_current_user()->ID ) : ?>
648 <p><?php _e( 'Select the user groups that you would like to be a part of:', 'edit-flow' ) ?></p>
649 <?php else : ?>
650 <p><?php _e( 'Select the user groups that this user should be a part of:', 'edit-flow' ) ?></p>
651 <?php endif; ?>
652 </th>
653 <td>
654 <?php $this->usergroups_select_form( $selected_usergroups, $usergroups_form_args ); ?>
655 <script type="text/javascript">
656 jQuery(document).ready(function(){
657 jQuery('#ef-user-usergroups ul').listFilterizer();
658 });
659 </script>
660 </td>
661 </tr></tbody></table>
662 <?php wp_nonce_field( 'ef_edit_profile_usergroups_nonce', 'ef_edit_profile_usergroups_nonce' ); ?>
663 <?php
664 }
665
666 /**
667 * Function called when a user's profile is updated
668 * Adds user to specified usergroups
669 *
670 * @since 0.7
671 *
672 * @param ???
673 * @param ???
674 * @param ???
675 * @return ???
676 */
677 function user_profile_update( $errors, $update, $user ) {
678
679 if ( !$update )
680 return array( &$errors, $update, &$user );
681
682 if ( current_user_can( $this->manage_usergroups_cap ) && wp_verify_nonce( $_POST['ef_edit_profile_usergroups_nonce'], 'ef_edit_profile_usergroups_nonce' ) ) {
683 // Sanitize the data and save
684 // Gracefully handle the case where the user was unsubscribed from all usergroups
685 $usergroups = isset( $_POST['ef_usergroups'] ) ? array_map( 'intval', (array)$_POST['ef_usergroups'] ) : array();
686 $all_usergroups = $this->get_usergroups();
687 foreach( $all_usergroups as $usergroup ) {
688 if ( in_array( $usergroup->term_id, $usergroups ) )
689 $this->add_user_to_usergroup( $user->ID, $usergroup->term_id );
690 else
691 $this->remove_user_from_usergroup( $user->ID, $usergroup->term_id );
692 }
693 }
694
695 return array( &$errors, $update, &$user );
696 }
697
698 /**
699 * Generate a link to one of the usergroups actions
700 *
701 * @since 0.7
702 *
703 * @param string $action Action we want the user to take
704 * @param array $args Any query args to add to the URL
705 * @return string $link Direct link to delete a usergroup
706 */
707 function get_link( $args = array() ) {
708 if ( !isset( $args['action'] ) )
709 $args['action'] = '';
710 if ( !isset( $args['page'] ) )
711 $args['page'] = $this->module->settings_slug;
712 // Add other things we may need depending on the action
713 switch( $args['action'] ) {
714 case 'delete-usergroup':
715 $args['nonce'] = wp_create_nonce( $args['action'] );
716 break;
717 default:
718 break;
719 }
720 return add_query_arg( $args, get_admin_url( null, 'admin.php' ) );
721 }
722
723 /**
724 * Displays a list of usergroups with checkboxes
725 *
726 * @since 0.7
727 *
728 * @param array $selected List of usergroup keys that should be checked
729 * @param array $args ???
730 */
731 function usergroups_select_form( $selected = array(), $args = null ) {
732
733 // TODO add $args for additional options
734 // e.g. showing members assigned to group (John Smith, Jane Doe, and 9 others)
735 // before <tag>, after <tag>, class, id names?
736 $defaults = array(
737 'list_class' => 'ef-post_following_list',
738 'list_id' => 'ef-following_usergroups',
739 'input_id' => 'following_usergroups'
740 );
741
742 $parsed_args = wp_parse_args( $args, $defaults );
743 extract( $parsed_args, EXTR_SKIP );
744 $usergroups = $this->get_usergroups();
745 if ( empty($usergroups) ) {
746 ?>
747 <p><?php _e('No user groups were found.', 'edit-flow') ?> <a href="<?php echo esc_url( $this->get_link() ); ?>" title="<?php _e('Add a new user group. Opens new window.', 'edit-flow' ) ?>" target="_blank"><?php _e( 'Add a User Group', 'edit-flow' ); ?></a></p>
748 <?php
749 } else {
750
751 ?>
752 <ul id="<?php echo $list_id ?>" class="<?php echo $list_class ?>">
753 <?php
754 foreach( $usergroups as $usergroup ) {
755 $checked = ( in_array( $usergroup->term_id, $selected ) ) ? ' checked="checked"' : '';
756 ?>
757 <li>
758 <label for="<?php echo $input_id . esc_attr( $usergroup->term_id ); ?>" title="<?php echo esc_attr($usergroup->description) ?>">
759 <input type="checkbox" id="<?php echo $input_id . esc_attr( $usergroup->term_id ) ?>" name="<?php echo $input_id ?>[]" value="<?php echo esc_attr( $usergroup->term_id ) ?>"<?php echo $checked ?> />
760 <span class="ef-usergroup_name"><?php echo esc_html( $usergroup->name ); ?></span>
761 <span class="ef-usergroup_description" title="<?php echo esc_attr($usergroup->description) ?>">
762 <?php echo (strlen($usergroup->description) >= 50) ? substr_replace(esc_html($usergroup->description), '...', 50) : esc_html($usergroup->description); ?>
763 </span>
764 </label>
765 </li>
766 <?php
767 }
768 ?>
769 </ul>
770 <?php
771 }
772 }
773
774 /**
775 * Core Usergroups Module Functionality
776 */
777
778 /**
779 * Get all of the registered usergroups. Returns an array of objects
780 *
781 * @since 0.7
782 *
783 * @param array $args Arguments to filter/sort by
784 * @return array|bool $usergroups Array of Usergroups with relevant data, false if none
785 */
786 function get_usergroups( $args = array() ) {
787
788 // We want empty terms by default
789 if ( !isset( $args['hide_empty'] ) )
790 $args['hide_empty'] = 0;
791
792 $usergroup_terms = get_terms( self::taxonomy_key, $args );
793 if ( !$usergroup_terms )
794 return false;
795
796 // Run the usergroups through get_usergroup_by() so we load users too
797 $usergroups = array();
798 foreach( $usergroup_terms as $usergroup_term ) {
799 $usergroups[] = $this->get_usergroup_by( 'id', $usergroup_term->term_id );
800 }
801 return $usergroups;
802 }
803
804 /**
805 * Get all of the data associated with a single usergroup
806 * Usergroup contains:
807 * - ID (key = term_id)
808 * - Slug (prefixed with our special key to avoid conflicts)
809 * - Name
810 * - Description
811 * - User IDs (array of IDs)
812 *
813 * @since 0.7
814 *
815 * @param string $field 'id', 'name', or 'slug'
816 * @param int|string $value Value for the search field
817 * @return object|array|WP_Error $usergroup Usergroup information as specified by $output
818 */
819 function get_usergroup_by( $field, $value ) {
820
821 $usergroup = get_term_by( $field, $value, self::taxonomy_key );
822
823 if ( !$usergroup || is_wp_error( $usergroup ) )
824 return $usergroup;
825
826 // We're using an encoded description field to store extra values
827 // Declare $user_ids ahead of time just in case it's empty
828 $usergroup->user_ids = array();
829 $unencoded_description = $this->get_unencoded_description( $usergroup->description );
830 if ( is_array( $unencoded_description ) ) {
831 foreach( $unencoded_description as $key => $value ) {
832 $usergroup->$key = $value;
833 }
834 }
835 return $usergroup;
836 }
837
838 /**
839 * Create a new usergroup containing:
840 * - Name
841 * - Slug (prefixed with our special key to avoid conflicts)
842 * - Description
843 * - Users
844 *
845 * @since 0.7
846 *
847 * @param array $args Name (optional), slug and description for the usergroup
848 * @param array $user_ids IDs for the users to be added to the Usergroup
849 * @return object|WP_Error $usergroup Object for the new Usergroup on success, WP_Error otherwise
850 */
851 function add_usergroup( $args = array(), $user_ids = array() ) {
852
853 if ( !isset( $args['name'] ) )
854 return new WP_Error( 'invalid', __( 'New user groups must have a name', 'edit-flow' ) );
855
856 $name = $args['name'];
857 $default = array(
858 'name' => '',
859 'slug' => self::term_prefix . sanitize_title( $name ),
860 'description' => '',
861 );
862 $args = array_merge( $default, $args );
863
864 // Encode our extra fields and then store them in the description field
865 $args_to_encode = array(
866 'description' => $args['description'],
867 'user_ids' => array_unique( $user_ids, SORT_NUMERIC ),
868 );
869 $encoded_description = $this->get_encoded_description( $args_to_encode );
870 $args['description'] = $encoded_description;
871 $usergroup = wp_insert_term( $name, self::taxonomy_key, $args );
872 if ( is_wp_error( $usergroup ) )
873 return $usergroup;
874
875 return $this->get_usergroup_by( 'id', $usergroup['term_id'] );
876 }
877
878 /**
879 * Update a usergroup with new data.
880 * Fields can include:
881 * - Name
882 * - Slug (prefixed with our special key, of course)
883 * - Description
884 * - Users
885 *
886 * @since 0.7
887 *
888 * @param int $id Unique ID for the usergroup
889 * @param array $args Usergroup meta to update (name, slug, description)
890 * @param array $users Users to be added to the Usergroup. If set, removes existing users first.
891 * @return object|WP_Error $usergroup Object for the updated Usergroup on success, WP_Error otherwise
892 */
893 function update_usergroup( $id, $args = array(), $users = null ) {
894
895 $existing_usergroup = $this->get_usergroup_by( 'id', $id );
896 if ( is_wp_error( $existing_usergroup ) )
897 return new WP_Error( 'invalid', __( "User group doesn't exist.", 'edit-flow' ) );
898
899 // Encode our extra fields and then store them in the description field
900 $args_to_encode = array();
901 $args_to_encode['description'] = ( isset( $args['description'] ) ) ? $args['description'] : $existing_usergroup->description;
902 $args_to_encode['user_ids'] = ( is_array( $users ) ) ? $users : $existing_usergroup->user_ids;
903 $args_to_encode['user_ids'] = array_unique( $args_to_encode['user_ids'], SORT_NUMERIC );
904 $encoded_description = $this->get_encoded_description( $args_to_encode );
905 $args['description'] = $encoded_description;
906
907 $usergroup = wp_update_term( $id, self::taxonomy_key, $args );
908 if ( is_wp_error( $usergroup ) )
909 return $usergroup;
910
911 return $this->get_usergroup_by( 'id', $usergroup['term_id'] );
912 }
913
914 /**
915 * Delete a usergroup based on its term ID
916 *
917 * @since 0.7
918 *
919 * @param int $id Unique ID for the Usergroup
920 * @param bool|WP_Error Returns true on success, WP_Error on failure
921 */
922 function delete_usergroup( $id ) {
923
924 $retval = wp_delete_term( $id, self::taxonomy_key );
925 return $retval;
926 }
927
928 /**
929 * Add an array of user logins or IDs to a given usergroup
930 *
931 * @since 0.7
932 *
933 * @param array $user_ids_or_logins User IDs or logins to be added to the usergroup
934 * @param int $id Usergroup to perform the action on
935 * @param bool $reset Delete all of the relationships before adding
936 * @return bool $success Whether or not we were successful
937 */
938 function add_users_to_usergroup( $user_ids_or_logins, $id, $reset = true ) {
939
940 if ( !is_array( $user_ids_or_logins ) )
941 return new WP_Error( 'invalid', __( "Invalid users variable. Should be array.", 'edit-flow' ) );
942
943 // To dump the existing users from a usergroup, we need to pass an empty array
944 $usergroup = $this->get_usergroup_by( 'id', $id );
945 if ( $reset ) {
946 $retval = $this->update_usergroup( $id, null, array() );
947 if ( is_wp_error( $retval ) )
948 return $retval;
949 }
950
951 // Add the new users one by one to an array we'll pass back to the usergroup
952 $new_users = array();
953 foreach ( (array)$user_ids_or_logins as $user_id_or_login ) {
954 if ( !is_numeric( $user_id_or_login ) )
955 $new_users[] = get_user_by( 'login', $user_id_or_login )->ID;
956 else
957 $new_users[] = (int)$user_id_or_login;
958 }
959 $retval = $this->update_usergroup( $id, null, $new_users );
960 if ( is_wp_error( $retval ) )
961 return $retval;
962 return true;
963 }
964
965 /**
966 * Add a given user to a Usergroup. Can use User ID or user login
967 *
968 * @since 0.7
969 *
970 * @param int|string $user_id_or_login User ID or login to be added to the Usergroups
971 * @param int|array $ids ID for the Usergroup(s)
972 * @return bool|WP_Error $retval Return true on success, WP_Error on error
973 */
974 function add_user_to_usergroup( $user_id_or_login, $ids ) {
975
976 if ( !is_numeric( $user_id_or_login ) )
977 $user_id = get_user_by( 'login', $user_id_or_login )->ID;
978 else
979 $user_id = (int)$user_id_or_login;
980
981 foreach( (array)$ids as $usergroup_id ) {
982 $usergroup = $this->get_usergroup_by( 'id', $usergroup_id );
983 $usergroup->user_ids[] = $user_id;
984 $retval = $this->update_usergroup( $usergroup_id, null, $usergroup->user_ids );
985 if ( is_wp_error( $retval ) )
986 return $retval;
987 }
988 return true;
989 }
990
991 /**
992 * Remove a given user from one or more usergroups
993 *
994 * @since 0.7
995 *
996 * @param int|string $user_id_or_login User ID or login to be removed from the Usergroups
997 * @param int|array $ids ID for the Usergroup(s)
998 * @return bool|WP_Error $retval Return true on success, WP_Error on error
999 */
1000 function remove_user_from_usergroup( $user_id_or_login, $ids ) {
1001
1002 if ( !is_numeric( $user_id_or_login ) )
1003 $user_id = get_user_by( 'login', $user_id_or_login )->ID;
1004 else
1005 $user_id = (int)$user_id_or_login;
1006
1007 // Remove the user from each usergroup specified
1008 foreach( (array)$ids as $usergroup_id ) {
1009 $usergroup = $this->get_usergroup_by( 'id', $usergroup_id );
1010 // @todo I bet there's a PHP function for this I couldn't look up at 35,000 over the Atlantic
1011 foreach( $usergroup->user_ids as $key => $usergroup_user_id ) {
1012 if ( $usergroup_user_id == $user_id )
1013 unset( $usergroup->user_ids[$key] );
1014 }
1015 $retval = $this->update_usergroup( $usergroup_id, null, $usergroup->user_ids );
1016 if ( is_wp_error( $retval ) )
1017 return $retval;
1018 }
1019 return true;
1020
1021 }
1022
1023 /**
1024 * Get all of the Usergroup ids or objects for a given user
1025 *
1026 * @since 0.7
1027 *
1028 * @param int|string $user_id_or_login User ID or login to search against
1029 * @param array $ids_or_objects Whether to retrieve an array of IDs or usergroup objects
1030 * @param array|bool $usergroup_objects_or_ids Array of usergroup 'ids' or 'objects', false if none
1031 */
1032 function get_usergroups_for_user( $user_id_or_login, $ids_or_objects = 'ids' ) {
1033
1034 if ( !is_numeric( $user_id_or_login ) )
1035 $user_id = get_user_by( 'login', $user_id_or_login )->ID;
1036 else
1037 $user_id = (int)$user_id_or_login;
1038
1039 // Unfortunately, the easiest way to do this is get all usergroups
1040 // and then loop through each one to see if the user ID is stored
1041 $all_usergroups = $this->get_usergroups();
1042 if ( !empty( $all_usergroups) ) {
1043 $usergroup_objects_or_ids = array();
1044 foreach( $all_usergroups as $usergroup ) {
1045 // Not in this usergroup, so keep going
1046 if ( !in_array( $user_id, $usergroup->user_ids ) )
1047 continue;
1048 if ( $ids_or_objects == 'ids' )
1049 $usergroup_objects_or_ids[] = (int)$usergroup->term_id;
1050 else if ( $ids_or_objects == 'objects' )
1051 $usergroup_objects_or_ids[] = $usergroup;
1052 }
1053 return $usergroup_objects_or_ids;
1054 } else {
1055 return false;
1056 }
1057 }
1058
1059 }
1060
1061 }
1062
1063
1064 if ( !class_exists( 'EF_Usergroups_List_Table' ) ) {
1065 /**
1066 * Usergroups uses WordPress' List Table API for generating the Usergroup management table
1067 *
1068 * @since 0.7
1069 */
1070 class EF_Usergroups_List_Table extends WP_List_Table
1071 {
1072
1073 var $callback_args;
1074
1075 function __construct() {
1076
1077 parent::__construct( array(
1078 'plural' => 'user groups',
1079 'singular' => 'user group',
1080 'ajax' => true
1081 ) );
1082
1083 }
1084
1085 /**
1086 * @todo Paginate if we have a lot of usergroups
1087 *
1088 * @since 0.7
1089 */
1090 function prepare_items() {
1091 global $edit_flow;
1092
1093 $columns = $this->get_columns();
1094 $hidden = array();
1095 $sortable = array();
1096
1097 $this->_column_headers = array( $columns, $hidden, $sortable );
1098
1099 $this->items = $edit_flow->user_groups->get_usergroups();
1100
1101 $this->set_pagination_args( array(
1102 'total_items' => count( $this->items ),
1103 'per_page' => count( $this->items ),
1104 ) );
1105 }
1106
1107 /**
1108 * Message to be displayed when there are no usergroups
1109 *
1110 * @since 0.7
1111 */
1112 function no_items() {
1113 _e( 'No user groups found.', 'edit-flow' );
1114 }
1115
1116 /**
1117 * Columns in our Usergroups table
1118 *
1119 * @since 0.7
1120 */
1121 function get_columns() {
1122
1123 $columns = array(
1124 'name' => __( 'Name', 'edit-flow' ),
1125 'description' => __( 'Description', 'edit-flow' ),
1126 'users' => __( 'Users in Group', 'edit-flow' ),
1127 );
1128
1129 return $columns;
1130 }
1131
1132 /**
1133 * Process the Usergroup column value for all methods that aren't registered
1134 *
1135 * @since 0.7
1136 */
1137 function column_default( $usergroup, $column_name ) {
1138
1139
1140 }
1141
1142 /**
1143 * Process the Usergroup name column value.
1144 * Displays the name of the Usergroup, and action links
1145 *
1146 * @since 0.7
1147 */
1148 function column_name( $usergroup ) {
1149 global $edit_flow;
1150
1151 // @todo direct edit link
1152 $output = '<strong><a href="' . esc_url( $edit_flow->user_groups->get_link( array( 'action' => 'edit-usergroup', 'usergroup-id' => $usergroup->term_id ) ) ) . '">' . esc_html( $usergroup->name ) . '</a></strong>';
1153
1154 $actions = array();
1155 $actions['edit edit-usergroup'] = sprintf( '<a href="%1$s">' . __( 'Edit', 'edit-flow' ) . '</a>', $edit_flow->user_groups->get_link( array( 'action' => 'edit-usergroup', 'usergroup-id' => $usergroup->term_id ) ) );
1156 $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __( 'Quick&nbsp;Edit' ) . '</a>';
1157 $actions['delete delete-usergroup'] = sprintf( '<a href="%1$s">' . __( 'Delete', 'edit-flow' ) . '</a>', $edit_flow->user_groups->get_link( array( 'action' => 'delete-usergroup', 'usergroup-id' => $usergroup->term_id ) ) );
1158
1159 $output .= $this->row_actions( $actions, false );
1160 $output .= '<div class="hidden" id="inline_' . $usergroup->term_id . '">';
1161 $output .= '<div class="name">' . esc_html( $usergroup->name ) . '</div>';
1162 $output .= '<div class="description">' . esc_html( $usergroup->description ) . '</div>';
1163 $output .= '</div>';
1164
1165 return $output;
1166
1167 }
1168
1169 /**
1170 * Handle the 'description' column for the table of Usergroups
1171 * Don't need to unencode this because we already did when the usergroup was loaded
1172 *
1173 * @since 0.7
1174 */
1175 function column_description( $usergroup ) {
1176 return esc_html( $usergroup->description );
1177 }
1178
1179 /**
1180 * Show the "Total Users" in a given usergroup
1181 *
1182 * @since 0.7
1183 */
1184 function column_users( $usergroup ) {
1185 global $edit_flow;
1186 return '<a href="' . esc_url( $edit_flow->user_groups->get_link( array( 'action' => 'edit-usergroup', 'usergroup-id' => $usergroup->term_id ) ) ) . '">' . count( $usergroup->user_ids ) . '</a>';
1187 }
1188
1189 /**
1190 * Prepare a single row of information about a usergroup
1191 *
1192 * @since 0.7
1193 */
1194 function single_row( $usergroup ) {
1195 static $row_class = '';
1196 $row_class = ( $row_class == '' ? ' class="alternate"' : '' );
1197
1198 echo '<tr id="usergroup-' . $usergroup->term_id . '"' . $row_class . '>';
1199 echo $this->single_row_columns( $usergroup );
1200 echo '</tr>';
1201 }
1202
1203 /**
1204 * If we use this form, we can have inline editing!
1205 *
1206 * @since 0.7
1207 */
1208 function inline_edit() {
1209 global $edit_flow;
1210 ?>
1211 <form method="get" action=""><table style="display: none"><tbody id="inlineedit">
1212 <tr id="inline-edit" class="inline-edit-row" style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange">
1213 <fieldset><div class="inline-edit-col">
1214 <h4><?php _e( 'Quick Edit' ); ?></h4>
1215 <label>
1216 <span class="title"><?php _e( 'Name', 'edit-flow' ); ?></span>
1217 <span class="input-text-wrap"><input type="text" name="name" class="ptitle" value="" maxlength="40" /></span>
1218 </label>
1219 <label>
1220 <span class="title"><?php _e( 'Description', 'edit-flow' ); ?></span>
1221 <span class="input-text-wrap"><input type="text" name="description" class="pdescription" value="" /></span>
1222 </label>
1223 </div></fieldset>
1224 <p class="inline-edit-save submit">
1225 <a accesskey="c" href="#inline-edit" title="<?php _e( 'Cancel' ); ?>" class="cancel button-secondary alignleft"><?php _e( 'Cancel' ); ?></a>
1226 <?php $update_text = __( 'Update User Group', 'edit-flow' ); ?>
1227 <a accesskey="s" href="#inline-edit" title="<?php echo esc_attr( $update_text ); ?>" class="save button-primary alignright"><?php echo $update_text; ?></a>
1228 <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
1229 <span class="error" style="display:none;"></span>
1230 <?php wp_nonce_field( 'usergroups-inline-edit-nonce', 'inline_edit', false ); ?>
1231 <br class="clear" />
1232 </p>
1233 </td></tr>
1234 </tbody></table></form>
1235 <?php
1236 }
1237
1238 }
1239 }