PluginProbe
Groups – Memberships and Access Control / 1.11.2
Groups – Memberships and Access Control v1.11.2
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.11.2, at lib/admin/groups-admin-capabilities-add.php

109 lines 4.0 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 if ( !defined( 'ABSPATH' ) ) {
23 exit;
24 }
25
26 /**
27 * Show add capability form.
28 */
29 function groups_admin_capabilities_add() {
30
31 global $wpdb;
32
33 if ( !current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
34 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
35 }
36
37 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
38 $current_url = remove_query_arg( 'paged', $current_url );
39 $current_url = remove_query_arg( 'action', $current_url );
40 $current_url = remove_query_arg( 'capability_id', $current_url );
41
42 $capability = isset( $_POST['capability-field'] ) ? $_POST['capability-field'] : '';
43 $description = isset( $_POST['description-field'] ) ? $_POST['description-field'] : '';
44
45 $capability_table = _groups_get_tablename( 'capability' );
46
47 $output =
48 '<div class="manage-capabilities wrap">' .
49 '<h1>' .
50 __( 'Add a new capability', GROUPS_PLUGIN_DOMAIN ) .
51 '</h1>' .
52 Groups_Admin::render_messages() .
53 '<form id="add-capability" action="' . esc_url( $current_url ) . '" method="post">' .
54 '<div class="capability new">' .
55
56 '<div class="field">' .
57 '<label for="capability-field" class="field-label first required">' .__( 'Capability', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
58 '<input id="name-field" name="capability-field" class="capability-field" type="text" value="' . esc_attr( stripslashes( $capability ) ) . '"/>' .
59 '</div>' .
60
61 '<div class="field">' .
62 '<label for="description-field" class="field-label description-field">' .__( 'Description', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
63 '<textarea id="description-field" name="description-field" rows="5" cols="45">' . stripslashes( wp_filter_nohtml_kses( $description ) ) . '</textarea>' .
64 '</div>' .
65
66 '<div class="field">' .
67 wp_nonce_field( 'capabilities-add', GROUPS_ADMIN_GROUPS_NONCE, true, false ) .
68 '<input class="button button-primary" type="submit" value="' . __( 'Add', GROUPS_PLUGIN_DOMAIN ) . '"/>' .
69 '<input type="hidden" value="add" name="action"/>' .
70 '<a class="cancel button" href="' . esc_url( $current_url ) . '">' . __( 'Cancel', GROUPS_PLUGIN_DOMAIN ) . '</a>' .
71 '</div>' .
72 '</div>' . // .capability.new
73 '</form>' .
74 '</div>'; // .manage-capabilities
75
76 echo $output;
77
78 } // function groups_admin_capabilities_add
79
80 /**
81 * Handle add capability form submission.
82 * @return int new capability's id or false if unsuccessful
83 */
84 function groups_admin_capabilities_add_submit() {
85
86 global $wpdb;
87
88 if ( !current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
89 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
90 }
91
92 if ( !wp_verify_nonce( $_POST[GROUPS_ADMIN_GROUPS_NONCE], 'capabilities-add' ) ) {
93 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
94 }
95
96 $capability = isset( $_POST['capability-field'] ) ? $_POST['capability-field'] : null;
97 $description = isset( $_POST['description-field'] ) ? $_POST['description-field'] : '';
98
99 $capability_id = Groups_Capability::create( compact( "capability", "description" ) );
100 if ( !$capability_id ) {
101 if ( empty( $capability ) ) {
102 Groups_Admin::add_message( __( 'The <em>Capability</em> must not be empty.', GROUPS_PLUGIN_DOMAIN ), 'error' );
103 } else if ( Groups_Capability::read_by_capability( $capability ) ) {
104 Groups_Admin::add_message( sprintf( __( 'The <em>%s</em> capability already exists.', GROUPS_PLUGIN_DOMAIN ), stripslashes( wp_filter_nohtml_kses( ( $capability ) ) ) ), 'error' );
105 }
106 }
107 return $capability_id;
108 } // function groups_admin_capabilities_add_submit
109