PluginProbe
Groups – Memberships and Access Control / 1.1.4
Groups – Memberships and Access Control v1.1.4
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
groups / lib / admin / groups-admin-groups-add.php

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

115 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * groups-admin-groups-add.php
4 *
5 * Copyright (c) "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.1.0
20 */
21
22 /**
23 * Show add group form.
24 */
25 function groups_admin_groups_add() {
26
27 global $wpdb;
28
29 if ( !current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
30 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
31 }
32
33 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
34 $current_url = remove_query_arg( 'paged', $current_url );
35 $current_url = remove_query_arg( 'action', $current_url );
36 $current_url = remove_query_arg( 'group_id', $current_url );
37
38 $parent_id = isset( $_POST['parent-id-field'] ) ? $_POST['parent-id-field'] : '';
39 $name = isset( $_POST['name-field'] ) ? $_POST['name-field'] : '';
40 $description = isset( $_POST['description-field'] ) ? $_POST['description-field'] : '';
41
42 $group_table = _groups_get_tablename( 'group' );
43 $parent_select = '<select name="parent-id-field">';
44 $parent_select .= '<option value="">--</option>';
45 $groups = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $group_table" ) );
46 foreach ( $groups as $group ) {
47 $parent_select .= '<option value="' . esc_attr( $group->group_id ) . '">' . wp_filter_nohtml_kses( $group->name ) . '</option>';
48 }
49 $parent_select .= '</select>';
50
51 $output =
52 '<div class="manage-groups">' .
53 '<div>' .
54 '<h2>' .
55 __( 'Add a new group', GROUPS_PLUGIN_DOMAIN ) .
56 '</h2>' .
57 '</div>' .
58
59 '<form id="add-group" action="' . $current_url . '" method="post">' .
60 '<div class="group new">' .
61
62 '<div class="field">' .
63 '<label for="name-field" class="field-label first required">' .__( 'Name', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
64 '<input id="name-field" name="name-field" class="namefield" type="text" value="' . esc_attr( $name ) . '"/>' .
65 '</div>' .
66
67 '<div class="field">' .
68 '<label for="parent-id-field" class="field-label">' .__( 'Parent', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
69 $parent_select .
70 '</div>' .
71
72 '<div class="field">' .
73 '<label for="description-field" class="field-label description-field">' .__( 'Description', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
74 '<textarea id="description-field" name="description-field" rows="5" cols="45">' . wp_filter_nohtml_kses( $description ) . '</textarea>' .
75 '</div>' .
76
77 '<div class="field">' .
78 wp_nonce_field( 'groups-add', GROUPS_ADMIN_GROUPS_NONCE, true, false ) .
79 '<input type="submit" value="' . __( 'Add', GROUPS_PLUGIN_DOMAIN ) . '"/>' .
80 '<input type="hidden" value="add" name="action"/>' .
81 '<a class="cancel" href="' . $current_url . '">' . __( 'Cancel', GROUPS_PLUGIN_DOMAIN ) . '</a>' .
82 '</div>' .
83 '</div>' . // .group.new
84 '</form>' .
85 '</div>'; // .manage-groups
86
87 echo $output;
88
89 Groups_Help::footer();
90 } // function groups_admin_groups_add
91
92 /**
93 * Handle add group form submission.
94 * @return int new group's id or false if unsuccessful
95 */
96 function groups_admin_groups_add_submit() {
97
98 global $wpdb;
99
100 if ( !current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
101 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
102 }
103
104 if ( !wp_verify_nonce( $_POST[GROUPS_ADMIN_GROUPS_NONCE], 'groups-add' ) ) {
105 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
106 }
107
108 $creator_id = get_current_user_id();
109 $datetime = date( 'Y-m-d H:i:s', time() );
110 $parent_id = isset( $_POST['parent-id-field'] ) ? $_POST['parent-id-field'] : null;
111 $description = isset( $_POST['description-field'] ) ? $_POST['description-field'] : '';
112 $name = isset( $_POST['name-field'] ) ? $_POST['name-field'] : null;
113 return Groups_Group::create( compact( "creator_id", "datetime", "parent_id", "description", "name" ) );
114 } // function groups_admin_groups_add_submit
115