Changeset 10373 for trunk/src/bp-groups/bp-groups-admin.php
- Timestamp:
- 11/22/2015 04:58:34 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/bp-groups-admin.php
r10360 r10373 18 18 if ( !class_exists( 'WP_List_Table' ) ) require( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); 19 19 20 // per_page screen option. Has to be hooked in extremely early.20 // The per_page screen option. Has to be hooked in extremely early. 21 21 if ( is_admin() && ! empty( $_REQUEST['page'] ) && 'bp-groups' == $_REQUEST['page'] ) 22 22 add_filter( 'set-screen-option', 'bp_groups_admin_screen_options', 10, 3 ); … … 29 29 function bp_groups_add_admin_menu() { 30 30 31 // Add our screen 31 // Add our screen. 32 32 $hook = add_menu_page( 33 33 _x( 'Groups', 'Admin Groups page title', 'buddypress' ), … … 53 53 * 54 54 * @param array $custom_menus Array of BP top-level menu items. 55 *56 55 * @return array Menu item array, with Groups added. 57 56 */ … … 76 75 global $bp_groups_list_table; 77 76 78 // Build redirection URL 77 // Build redirection URL. 79 78 $redirect_to = remove_query_arg( array( 'action', 'action2', 'gid', 'deleted', 'error', 'updated', 'success_new', 'error_new', 'success_modified', 'error_modified' ), $_SERVER['REQUEST_URI'] ); 80 79 81 // Decide whether to load the dev version of the CSS and JavaScript 80 // Decide whether to load the dev version of the CSS and JavaScript. 82 81 $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : 'min.'; 83 82 … … 93 92 do_action( 'bp_groups_admin_load', $doaction ); 94 93 95 // Edit screen 94 // Edit screen. 96 95 if ( 'do_delete' == $doaction && ! empty( $_GET['gid'] ) ) { 97 96 … … 112 111 113 112 } elseif ( 'edit' == $doaction && ! empty( $_GET['gid'] ) ) { 114 // columns screen option113 // Columns screen option. 115 114 add_screen_option( 'layout_columns', array( 'default' => 2, 'max' => 2, ) ); 116 115 … … 123 122 ) ); 124 123 125 // Help panel - sidebar links 124 // Help panel - sidebar links. 126 125 get_current_screen()->set_help_sidebar( 127 126 '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' . … … 142 141 do_action( 'bp_groups_admin_meta_boxes' ); 143 142 144 // Enqueue JavaScript files 143 // Enqueue JavaScript files. 145 144 wp_enqueue_script( 'postbox' ); 146 145 wp_enqueue_script( 'dashboard' ); 147 146 148 // Index screen 147 // Index screen. 149 148 } else { 150 // Create the Groups screen list table 149 // Create the Groups screen list table. 151 150 $bp_groups_list_table = new BP_Groups_List_Table(); 152 151 153 // per_page screen option152 // The per_page screen option. 154 153 add_screen_option( 'per_page', array( 'label' => _x( 'Groups', 'Groups per page (screen options)', 'buddypress' )) ); 155 154 156 // Help panel - overview text 155 // Help panel - overview text. 157 156 get_current_screen()->add_help_tab( array( 158 157 'id' => 'bp-groups-overview', … … 171 170 ) ); 172 171 173 // Help panel - sidebar links 172 // Help panel - sidebar links. 174 173 get_current_screen()->set_help_sidebar( 175 174 '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' . … … 180 179 $bp = buddypress(); 181 180 182 // Enqueue CSS and JavaScript 181 // Enqueue CSS and JavaScript. 183 182 wp_enqueue_script( 'bp_groups_admin_js', $bp->plugin_url . "bp-groups/admin/js/admin.{$min}js", array( 'jquery', 'wp-ajax-response', 'jquery-ui-autocomplete' ), bp_get_version(), true ); 184 183 wp_localize_script( 'bp_groups_admin_js', 'BP_Group_Admin', array( … … 195 194 196 195 if ( $doaction && 'save' == $doaction ) { 197 // Get group ID 196 // Get group ID. 198 197 $group_id = isset( $_REQUEST['gid'] ) ? (int) $_REQUEST['gid'] : ''; 199 198 … … 203 202 ), $redirect_to ); 204 203 205 // Check this is a valid form submission 204 // Check this is a valid form submission. 206 205 check_admin_referer( 'edit-group_' . $group_id ); 207 206 208 // Get the group from the database 207 // Get the group from the database. 209 208 $group = groups_get_group( 'group_id=' . $group_id ); 210 209 211 // If the group doesn't exist, just redirect back to the index 210 // If the group doesn't exist, just redirect back to the index. 212 211 if ( empty( $group->slug ) ) { 213 212 wp_redirect( $redirect_to ); … … 215 214 } 216 215 217 // Check the form for the updated properties 218 219 // Store errors 216 // Check the form for the updated properties. 217 // Store errors. 220 218 $error = 0; 221 219 $success_new = $error_new = $success_modified = $error_modified = array(); 222 220 223 221 // Group name and description are handled with 224 // groups_edit_base_group_details() 222 // groups_edit_base_group_details(). 225 223 if ( !groups_edit_base_group_details( $group_id, $_POST['bp-groups-name'], $_POST['bp-groups-description'], 0 ) ) { 226 224 $error = $group_id; 227 225 228 // using negative integers for different error messages... eek!226 // Using negative integers for different error messages... eek! 229 227 if ( empty( $_POST['bp-groups-name'] ) && empty( $_POST['bp-groups-description'] ) ) { 230 228 $error = -3; … … 236 234 } 237 235 238 // Enable discussion forum 236 // Enable discussion forum. 239 237 $enable_forum = ( isset( $_POST['group-show-forum'] ) ) ? 1 : 0; 240 238 … … 263 261 } 264 262 265 // Process new members 263 // Process new members. 266 264 $user_names = array(); 267 265 … … 276 274 277 275 // Make sure the user exists before attempting 278 // to add to the group 276 // to add to the group. 279 277 $user = get_user_by( 'slug', $un ); 280 278 … … 291 289 } 292 290 293 // Process member role changes 291 // Process member role changes. 294 292 if ( ! empty( $_POST['bp-groups-role'] ) && ! empty( $_POST['bp-groups-existing-role'] ) ) { 295 293 296 294 // Before processing anything, make sure you're not 297 // attempting to remove the all user admins 295 // attempting to remove the all user admins. 298 296 $admin_count = 0; 299 297 foreach ( (array) $_POST['bp-groups-role'] as $new_role ) { … … 311 309 } else { 312 310 313 // Process only those users who have had their roles changed 311 // Process only those users who have had their roles changed. 314 312 foreach ( (array) $_POST['bp-groups-role'] as $user_id => $new_role ) { 315 313 … … 321 319 case 'mod' : 322 320 // Admin to mod is a demotion. Demote to 323 // member, then fall through 321 // member, then fall through. 324 322 if ( 'admin' == $existing_role ) { 325 323 groups_demote_member( $user_id, $group_id ); … … 328 326 case 'admin' : 329 327 // If the user was banned, we must 330 // unban first 328 // unban first. 331 329 if ( 'banned' == $existing_role ) { 332 330 groups_unban_member( $user_id, $group_id ); … … 334 332 335 333 // At this point, each existing_role 336 // is a member, so promote 334 // is a member, so promote. 337 335 $result = groups_promote_member( $user_id, $group_id, $new_role ); 338 336 … … 362 360 } 363 361 364 // Store the success or failure 362 // Store the success or failure. 365 363 if ( $result ) { 366 364 $success_modified[] = $user_id; … … 382 380 do_action( 'bp_group_admin_edit_after', $group_id ); 383 381 384 // Create the redirect URL 385 382 // Create the redirect URL. 386 383 if ( $error ) { 387 // This means there was an error updating group details 384 // This means there was an error updating group details. 388 385 $redirect_to = add_query_arg( 'error', (int) $error, $redirect_to ); 389 386 } else { 390 // Group details were update successfully 387 // Group details were update successfully. 391 388 $redirect_to = add_query_arg( 'updated', 1, $redirect_to ); 392 389 } … … 438 435 * @param string $option Screen option name. 439 436 * @param string $new_value Screen option form value. 440 *441 437 * @return string Option value. False to abandon update. 442 438 */ … … 445 441 return $value; 446 442 447 // Per page 443 // Per page. 448 444 $new_value = (int) $new_value; 449 445 if ( $new_value < 1 || $new_value > 999 ) … … 459 455 */ 460 456 function bp_groups_admin() { 461 // Decide whether to load the index or edit screen 457 // Decide whether to load the index or edit screen. 462 458 $doaction = bp_admin_list_table_current_bulk_action(); 463 459 464 // Display the single group edit screen 460 // Display the single group edit screen. 465 461 if ( 'edit' == $doaction && ! empty( $_GET['gid'] ) ) { 466 462 bp_groups_admin_edit(); 467 463 468 // Display the group deletion confirmation screen 464 // Display the group deletion confirmation screen. 469 465 } elseif ( 'delete' == $doaction && ! empty( $_GET['gid'] ) ) { 470 466 bp_groups_admin_delete(); 471 467 472 // Otherwise, display the groups index screen 468 // Otherwise, display the groups index screen. 473 469 } else { 474 470 bp_groups_admin_index(); … … 488 484 $messages = array(); 489 485 490 // If the user has just made a change to a group, build status messages 486 // If the user has just made a change to a group, build status messages. 491 487 if ( !empty( $_REQUEST['no_admins'] ) || ! empty( $_REQUEST['error'] ) || ! empty( $_REQUEST['updated'] ) || ! empty( $_REQUEST['error_new'] ) || ! empty( $_REQUEST['success_new'] ) || ! empty( $_REQUEST['error_modified'] ) || ! empty( $_REQUEST['success_modified'] ) ) { 492 488 $no_admins = ! empty( $_REQUEST['no_admins'] ) ? 1 : 0; … … 546 542 $is_error = ! empty( $no_admins ) || ! empty( $errors ) || ! empty( $error_new ) || ! empty( $error_modified ); 547 543 548 // Get the group from the database 544 // Get the group from the database. 549 545 $group = groups_get_group( 'group_id=' . $_GET['gid'] ); 550 546 … … 552 548 $group_name = isset( $group->name ) ? apply_filters( 'bp_get_group_name', $group->name ) : ''; 553 549 554 // Construct URL for form 550 // Construct URL for form. 555 551 $form_url = remove_query_arg( array( 'action', 'deleted', 'no_admins', 'error', 'error_new', 'success_new', 'error_modified', 'success_modified' ), $_SERVER['REQUEST_URI'] ); 556 552 $form_url = add_query_arg( 'action', 'save', $form_url ); … … 576 572 </h1> 577 573 578 <?php // If the user has just made a change to an group, display the status messages ?>574 <?php // If the user has just made a change to an group, display the status messages. ?> 579 575 <?php if ( !empty( $messages ) ) : ?> 580 576 <div id="moderated" class="<?php echo ( $is_error ) ? 'error' : 'updated'; ?>"><p><?php echo implode( "</p><p>", $messages ); ?></p></div> … … 652 648 'include' => $group_ids, 653 649 'show_hidden' => true, 654 'per_page' => null, // Return all results 650 'per_page' => null, // Return all results. 655 651 ) ); 656 652 657 // Create a new list of group ids, based on those that actually exist 653 // Create a new list of group ids, based on those that actually exist. 658 654 $gids = array(); 659 655 foreach ( $groups['groups'] as $group ) { … … 697 693 $messages = array(); 698 694 699 // If the user has just made a change to a group, build status messages 695 // If the user has just made a change to a group, build status messages. 700 696 if ( ! empty( $_REQUEST['deleted'] ) ) { 701 697 $deleted = ! empty( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 0; … … 706 702 } 707 703 708 // Prepare the group items for display 704 // Prepare the group items for display. 709 705 $bp_groups_list_table->prepare_items(); 710 706 … … 733 729 </h1> 734 730 735 <?php // If the user has just made a change to an group, display the status messages ?>731 <?php // If the user has just made a change to an group, display the status messages. ?> 736 732 <?php if ( !empty( $messages ) ) : ?> 737 733 <div id="moderated" class="<?php echo ( ! empty( $_REQUEST['error'] ) ) ? 'error' : 'updated'; ?>"><p><?php echo implode( "<br/>\n", $messages ); ?></p></div> 738 734 <?php endif; ?> 739 735 740 <?php // Display each group on its own row ?>736 <?php // Display each group on its own row. ?> 741 737 <?php $bp_groups_list_table->views(); ?> 742 738 … … 800 796 * 801 797 * @since 1.7.0 798 * 799 * @param BP_Groups_Group $item The BP_Groups_Group object for the current group. 802 800 */ 803 801 function bp_groups_admin_edit_metabox_add_new_members( $item ) { … … 821 819 // Pull up a list of group members, so we can separate out the types 822 820 // We'll also keep track of group members here to place them into a 823 // JavaScript variable, which will help with group member autocomplete 821 // JavaScript variable, which will help with group member autocomplete. 824 822 $members = array( 825 823 'admin' => array(), … … 851 849 } 852 850 853 // Echo out the JavaScript variable 851 // Echo out the JavaScript variable. 854 852 echo '<script type="text/javascript">var group_id = "' . esc_js( $item->id ) . '";</script>'; 855 853 856 // Loop through each member type 854 // Loop through each member type. 857 855 foreach ( $members as $member_type => $type_users ) : ?> 858 856 … … 1008 1006 * @param BP_Group_Member_Query $query A BP_Group_Member_Query object. 1009 1007 * @param string $member_type member|mod|admin|banned. 1010 *1011 1008 * @return string Pagination links HTML. 1012 1009 */ … … 1018 1015 } 1019 1016 1020 // The key used to paginate this member type in the $_GET global 1017 // The key used to paginate this member type in the $_GET global. 1021 1018 $qs_key = $member_type . '_page'; 1022 1019 $url_base = remove_query_arg( array( $qs_key, 'updated', 'success_modified' ), $_SERVER['REQUEST_URI'] ); … … 1025 1022 $per_page = 10; // @todo Make this customizable? 1026 1023 1027 // Don't show anything if there's no pagination 1024 // Don't show anything if there's no pagination. 1028 1025 if ( 1 === $page && $query->total_users <= $per_page ) { 1029 1026 return $pagination; … … 1065 1062 * 1066 1063 * @param array $user_ids Array of user IDs. 1067 *1068 1064 * @return array Array of user_logins corresponding to $user_ids. 1069 1065 */ … … 1087 1083 function bp_groups_admin_autocomplete_handler() { 1088 1084 1089 // Bail if user user shouldn't be here, or is a large network 1085 // Bail if user user shouldn't be here, or is a large network. 1090 1086 if ( ! current_user_can( 'bp_moderate' ) || ( is_multisite() && wp_is_large_network( 'users' ) ) ) { 1091 1087 wp_die( -1 ); … … 1112 1108 1113 1109 $matches[] = array( 1114 // translators: 1: user_login, 2: user_email1110 // Translators: 1: user_login, 2: user_email. 1115 1111 'label' => sprintf( __( '%1$s (%2$s)', 'buddypress' ), $user->name, $user->ID ), 1116 1112 'value' => $user->ID, … … 1133 1129 * The type of view currently being displayed. 1134 1130 * 1135 * e.g. "All", "Pending", "Approved", "Spam"...1131 * E.g. "All", "Pending", "Approved", "Spam"... 1136 1132 * 1137 1133 * @since 1.7.0 … … 1186 1182 $screen = get_current_screen(); 1187 1183 1188 // Option defaults 1184 // Option defaults. 1189 1185 $include_id = false; 1190 1186 $search_terms = false; 1191 1187 1192 // Set current page 1188 // Set current page. 1193 1189 $page = $this->get_pagenum(); 1194 1190 1195 // Set per page from the screen options 1191 // Set per page from the screen options. 1196 1192 $per_page = $this->get_items_per_page( str_replace( '-', '_', "{$screen->id}_per_page" ) ); 1197 1193 … … 1202 1198 } 1203 1199 1204 // Order by - default to newest 1200 // Order by - default to newest. 1205 1201 $orderby = 'last_activity'; 1206 1202 if ( ! empty( $_REQUEST['orderby'] ) ) { … … 1229 1225 $include_id = (int) $_REQUEST['gid']; 1230 1226 1231 // Set the current view 1227 // Set the current view. 1232 1228 if ( isset( $_GET['group_status'] ) && in_array( $_GET['group_status'], array( 'public', 'private', 'hidden' ) ) ) { 1233 1229 $this->view = $_GET['group_status']; 1234 1230 } 1235 1231 1236 // We'll use the ids of group types for the 'include' param 1232 // We'll use the ids of group types for the 'include' param. 1237 1233 $this->group_type_ids = BP_Groups_Group::get_group_type_ids(); 1238 1234 1239 // Pass a dummy array if there are no groups of this type 1235 // Pass a dummy array if there are no groups of this type. 1240 1236 $include = false; 1241 1237 if ( 'all' != $this->view && isset( $this->group_type_ids[ $this->view ] ) ) { … … 1243 1239 } 1244 1240 1245 // Get group type counts for display in the filter tabs 1241 // Get group type counts for display in the filter tabs. 1246 1242 $this->group_counts = array(); 1247 1243 foreach ( $this->group_type_ids as $group_type => $group_ids ) { … … 1270 1266 } 1271 1267 1272 // Set raw data to display 1268 // Set raw data to display. 1273 1269 $this->items = $groups; 1274 1270 1275 // Store information needed for handling table pagination 1271 // Store information needed for handling table pagination. 1276 1272 $this->set_pagination_args( array( 1277 1273 'per_page' => $per_page, … … 1307 1303 */ 1308 1304 protected function get_default_primary_column_name() { 1309 // comment column is mapped to Group's name1305 // Comment column is mapped to Group's name. 1310 1306 return 'comment'; 1311 1307 } … … 1324 1320 * 1325 1321 * @since 1.7.0 1326 */1322 */ 1327 1323 public function display() { 1328 1324 $this->display_tablenav( 'top' ); ?> … … 1498 1494 * @since 2.3.4 Visibility set to public for compatibility with WP < 4.0.0. 1499 1495 * 1500 * @param array $actions The list of actions1501 * @param bool $always_visible Whether the actions should be always visible1496 * @param array $actions The list of actions. 1497 * @param bool $always_visible Whether the actions should be always visible. 1502 1498 * @return string 1503 1499 */ … … 1559 1555 public function column_comment( $item = array() ) { 1560 1556 1561 // Preorder items: Edit | Delete | View 1557 // Preorder items: Edit | Delete | View. 1562 1558 $actions = array( 1563 1559 'edit' => '', … … 1566 1562 ); 1567 1563 1568 // We need the group object for some BP functions 1564 // We need the group object for some BP functions. 1569 1565 $item_obj = (object) $item; 1570 1566 1571 // Build actions URLs 1567 // Build actions URLs. 1572 1568 $base_url = bp_get_admin_url( 'admin.php?page=bp-groups&gid=' . $item['id'] ); 1573 1569 $delete_url = wp_nonce_url( $base_url . "&action=delete", 'bp-groups-delete' ); … … 1585 1581 $group_name = apply_filters_ref_array( 'bp_get_group_name', array( $item['name'] ), $item ); 1586 1582 1587 // Rollover actions 1588 1589 // Edit 1583 // Rollover actions. 1584 // Edit. 1590 1585 $actions['edit'] = sprintf( '<a href="%s">%s</a>', esc_url( $edit_url ), __( 'Edit', 'buddypress' ) ); 1591 1586 1592 // Delete 1587 // Delete. 1593 1588 $actions['delete'] = sprintf( '<a href="%s">%s</a>', esc_url( $delete_url ), __( 'Delete', 'buddypress' ) ); 1594 1589 1595 // Visit 1590 // Visit. 1596 1591 $actions['view'] = sprintf( '<a href="%s">%s</a>', esc_url( $view_url ), __( 'View', 'buddypress' ) ); 1597 1592 … … 1606 1601 $actions = apply_filters( 'bp_groups_admin_comment_row_actions', array_filter( $actions ), $item ); 1607 1602 1608 // Get group name and avatar 1603 // Get group name and avatar. 1609 1604 $avatar = ''; 1610 1605 … … 1659 1654 1660 1655 // @todo This should be abstracted out somewhere for the whole 1661 // Groups component 1656 // Groups component. 1662 1657 switch ( $status ) { 1663 1658 case 'public' : … … 1732 1727 * @param array $item Information about the current row. 1733 1728 * @param string $column_name The column name. 1734 *1735 1729 * @return string 1736 1730 */
Note: See TracChangeset
for help on using the changeset viewer.