name; $description = isset( $_POST['description-field'] ) ? $_POST['description-field'] : $group->description; $parent_id = isset( $_POST['parent-id-field'] ) ? $_POST['parent-id-field'] : $group->parent_id; $group_table = _groups_get_tablename( 'group' ); $parent_select = ''; $name_readonly = ( $name !== Groups_Registered::REGISTERED_GROUP_NAME ) ? "" : ' readonly="readonly" '; $output .= '
'; $output .= '

'; $output .= __( 'Edit a group', 'groups' ); $output .= '

'; $output .= Groups_Admin::render_messages(); $output .= '
'; $output .= '
'; $output .= ''; $output .= '
'; $output .= ''; $output .= ''; $output .= '
'; $output .= '
'; $output .= ''; $output .= $parent_select; $output .= '
'; $output .= '
'; $output .= ''; $output .= ''; $output .= '
'; $capability_table = _groups_get_tablename( 'capability' ); $group_capability_table = _groups_get_tablename( 'group_capability' ); $group_capabilities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $capability_table WHERE capability_id IN ( SELECT capability_id FROM $group_capability_table WHERE group_id = %d )", Groups_Utility::id( $group_id ) ) ); $group_capabilities_array = array(); if ( count( $group_capabilities ) > 0 ) { foreach ( $group_capabilities as $group_capability ) { $group_capabilities_array[] = $group_capability->capability_id; } } $capabilities = $wpdb->get_results( "SELECT * FROM $capability_table ORDER BY capability" ); $output .= '
'; $output .= '
'; $output .= ''; $output .= '
'; // .select-capability-container $output .= '

'; $output .= __( 'The chosen capabilities are assigned to the group.', 'groups' ); $output .= '

'; $output .= '
'; // .field $output .= Groups_UIE::render_select( '.select.capability' ); $group_object = new Groups_Group( $group_id ); $group_capabilities = $group_object->capabilities; $group_capabilities_deep = $group_object->capabilities_deep; if ( ( ( !empty( $group_capabilities_deep ) ? count( $group_capabilities_deep ) : 0 ) - ( !empty( $group_capabilities ) ? count( $group_capabilities ) : 0 ) ) > 0 ) { usort( $group_capabilities_deep, array( 'Groups_Utility', 'cmp' ) ); $output .= '
'; $output .= __( 'Inherited capabilities:', 'groups' ); $output .= ' '; $inherited_caps = array(); foreach ( $group_capabilities_deep as $group_capability ) { $class = ''; if ( empty( $group_capabilities ) || !in_array( $group_capability, $group_capabilities ) ) { $inherited_caps[] = wp_filter_nohtml_kses( $group_capability->capability->capability ); } } $output .= implode( ' ', $inherited_caps ); $output .= '
'; } $output .= apply_filters( 'groups_admin_groups_edit_form_after_fields', '', $group_id ); $output .= '
'; $output .= wp_nonce_field( 'groups-edit', GROUPS_ADMIN_GROUPS_NONCE, true, false ); $output .= ''; $output .= ''; $output .= '' . __( 'Cancel', 'groups' ) . ''; $output .= '
'; $output .= '
'; // .group.edit $output .= '
'; $output .= '
'; // .manage-groups echo $output; } // function groups_admin_groups_edit /** * Handle edit form submission. */ function groups_admin_groups_edit_submit() { global $wpdb; if ( !current_user_can( GROUPS_ADMINISTER_GROUPS ) ) { wp_die( __( 'Access denied.', 'groups' ) ); } if ( !wp_verify_nonce( $_POST[GROUPS_ADMIN_GROUPS_NONCE], 'groups-edit' ) ) { wp_die( __( 'Access denied.', 'groups' ) ); } $group_id = isset( $_POST['group-id-field'] ) ? $_POST['group-id-field'] : null; $group = Groups_Group::read( $group_id ); if ( $group ) { $group_id = $group->group_id; if ( $group->name !== Groups_Registered::REGISTERED_GROUP_NAME ) { $name = isset( $_POST['name-field'] ) ? $_POST['name-field'] : null; } else { $name = Groups_Registered::REGISTERED_GROUP_NAME; } $parent_id = isset( $_POST['parent-id-field'] ) ? $_POST['parent-id-field'] : null; $description = isset( $_POST['description-field'] ) ? $_POST['description-field'] : ''; if ( empty( $name ) ) { Groups_Admin::add_message( __( 'The Name must not be empty.', 'groups' ), 'error' ); return false; } if ( $other_group = Groups_Group::read_by_name( $name ) ) { if ( $other_group->group_id != $group_id ) { Groups_Admin::add_message( sprintf( __( 'The %s group already exists and cannot be used to name this one.', 'groups' ), stripslashes( wp_filter_nohtml_kses( $other_group->name ) ) ), 'error' ); return false; } } $group_id = Groups_Group::update( compact( "group_id", "name", "parent_id", "description" ) ); if ( $group_id ) { $capability_table = _groups_get_tablename( "capability" ); $group_capability_table = _groups_get_tablename( "group_capability" ); $group_capabilities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $capability_table WHERE capability_id IN ( SELECT capability_id FROM $group_capability_table WHERE group_id = %d )", Groups_Utility::id( $group_id ) ) ); $group_capabilities_array = array(); foreach ( $group_capabilities as $group_capability ) { $group_capabilities_array[] = $group_capability->capability_id; } $caps = array(); if ( isset( $_POST['capability_ids'] ) ) { $caps = $_POST['capability_ids']; } // delete foreach( $group_capabilities_array as $group_cap ) { if ( !in_array( $group_cap, $caps ) ) { Groups_Group_Capability::delete( $group_id, $group_cap ); } } // add foreach( $caps as $cap ) { if ( !in_array( $cap, $group_capabilities_array ) ) { Groups_Group_Capability::create( array( 'group_id' => $group_id, 'capability_id' => $cap ) ); } } do_action( 'groups_admin_groups_edit_submit_success', $group_id ); } return $group_id; } else { return false; } } // function groups_admin_groups_edit_submit