PluginProbe
Groups – Memberships and Access Control / 1.1.5
Groups – Memberships and Access Control v1.1.5
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-capabilities-add.php

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

100 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * groups-admin-capabilities-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.0.0
20 */
21
22 /**
23 * Show add capability form.
24 */
25 function groups_admin_capabilities_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( 'capability_id', $current_url );
37
38 $capability = isset( $_POST['capability-field'] ) ? $_POST['capability-field'] : '';
39 $description = isset( $_POST['description-field'] ) ? $_POST['description-field'] : '';
40
41 $capability_table = _groups_get_tablename( 'capability' );
42
43 $output =
44 '<div class="manage-capabilities">' .
45 '<div>' .
46 '<h2>' .
47 __( 'Add a new capability', GROUPS_PLUGIN_DOMAIN ) .
48 '</h2>' .
49 '</div>' .
50
51 '<form id="add-capability" action="' . $current_url . '" method="post">' .
52 '<div class="capability new">' .
53
54 '<div class="field">' .
55 '<label for="capability-field" class="field-label first required">' .__( 'Capability', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
56 '<input id="name-field" name="capability-field" class="capability-field" type="text" value="' . esc_attr( $capability ) . '"/>' .
57 '</div>' .
58
59 '<div class="field">' .
60 '<label for="description-field" class="field-label description-field">' .__( 'Description', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
61 '<textarea id="description-field" name="description-field" rows="5" cols="45">' . wp_filter_nohtml_kses( $description ) . '</textarea>' .
62 '</div>' .
63
64 '<div class="field">' .
65 wp_nonce_field( 'capabilities-add', GROUPS_ADMIN_GROUPS_NONCE, true, false ) .
66 '<input type="submit" value="' . __( 'Add', GROUPS_PLUGIN_DOMAIN ) . '"/>' .
67 '<input type="hidden" value="add" name="action"/>' .
68 '<a class="cancel" href="' . $current_url . '">' . __( 'Cancel', GROUPS_PLUGIN_DOMAIN ) . '</a>' .
69 '</div>' .
70 '</div>' . // .capability.new
71 '</form>' .
72 '</div>'; // .manage-capabilities
73
74 echo $output;
75
76 Groups_Help::footer();
77 } // function groups_admin_capabilities_add
78
79 /**
80 * Handle add capability form submission.
81 * @return int new capability's id or false if unsuccessful
82 */
83 function groups_admin_capabilities_add_submit() {
84
85 global $wpdb;
86
87 if ( !current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
88 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
89 }
90
91 if ( !wp_verify_nonce( $_POST[GROUPS_ADMIN_GROUPS_NONCE], 'capabilities-add' ) ) {
92 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
93 }
94
95 $capability = isset( $_POST['capability-field'] ) ? $_POST['capability-field'] : null;
96 $description = isset( $_POST['description-field'] ) ? $_POST['description-field'] : '';
97
98 return Groups_Capability::create( compact( "capability", "description" ) );
99 } // function groups_admin_capabilities_add_submit
100