PluginProbe
Groups – Memberships and Access Control / 1.10.3
Groups – Memberships and Access Control v1.10.3
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-edit.php

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

135 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * groups-admin-capability-edit.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 edit capability form.
28 * @param int $capability_id capability id
29 */
30 function groups_admin_capabilities_edit( $capability_id ) {
31
32 global $wpdb;
33
34 if ( !current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
35 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
36 }
37
38 $capability = Groups_Capability::read( intval( $capability_id ) );
39
40 if ( empty( $capability ) ) {
41 wp_die( __( 'No such capability.', GROUPS_PLUGIN_DOMAIN ) );
42 }
43
44 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
45 $current_url = remove_query_arg( 'action', $current_url );
46 $current_url = remove_query_arg( 'capability_id', $current_url );
47
48 $capability_capability = isset( $_POST['capability-field'] ) ? $_POST['capability-field'] : $capability->capability;
49 $description = isset( $_POST['description-field'] ) ? $_POST['description-field'] : $capability->description;
50
51 $capability_readonly = ( $capability->capability !== Groups_Post_Access::READ_POST_CAPABILITY ) ? "" : ' readonly="readonly" ';
52
53 $output =
54 '<div class="manage-capabilities wrap">' .
55 '<h1>' .
56 __( 'Edit a capability', GROUPS_PLUGIN_DOMAIN ) .
57 '</h1>' .
58
59 Groups_Admin::render_messages() .
60
61 '<form id="edit-capability" action="' . esc_url( $current_url ) . '" method="post">' .
62 '<div class="capability edit">' .
63 '<input id="capability-id-field" name="capability-id-field" type="hidden" value="' . esc_attr( intval( $capability_id ) ) . '"/>' .
64
65 '<div class="field">' .
66 '<label for="capability-field" class="field-label first required">' .__( 'Capability', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
67 '<input ' . $capability_readonly . ' id="capability-field" name="capability-field" class="capability-field" type="text" value="' . esc_attr( stripslashes( $capability_capability ) ) . '"/>' .
68 '</div>' .
69
70 '<div class="field">' .
71 '<label for="description-field" class="field-label description-field">' .__( 'Description', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
72 '<textarea id="description-field" name="description-field" rows="5" cols="45">' . stripslashes( wp_filter_nohtml_kses( $description ) ) . '</textarea>' .
73 '</div>' .
74
75 '<div class="field">' .
76 wp_nonce_field( 'capabilities-edit', GROUPS_ADMIN_GROUPS_NONCE, true, false ) .
77 '<input class="button button-primary" type="submit" value="' . __( 'Save', GROUPS_PLUGIN_DOMAIN ) . '"/>' .
78 '<input type="hidden" value="edit" name="action"/>' .
79 '<a class="cancel button" href="' . esc_url( $current_url ) . '">' . __( 'Cancel', GROUPS_PLUGIN_DOMAIN ) . '</a>' .
80 '</div>' .
81 '</div>' . // .capability.edit
82 '</form>' .
83 '</div>'; // .manage-capabilities
84
85 echo $output;
86 } // function groups_admin_capabilities_edit
87
88 /**
89 * Handle edit form submission.
90 */
91 function groups_admin_capabilities_edit_submit() {
92
93 $result = false;
94
95 if ( !current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
96 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
97 }
98
99 if ( !wp_verify_nonce( $_POST[GROUPS_ADMIN_GROUPS_NONCE], 'capabilities-edit' ) ) {
100 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
101 }
102
103 $capability_id = isset( $_POST['capability-id-field'] ) ? $_POST['capability-id-field'] : null;
104 $capability = Groups_Capability::read( $capability_id );
105 if ( $capability ) {
106 $capability_id = $capability->capability_id;
107 if ( $capability->capability !== Groups_Post_Access::READ_POST_CAPABILITY ) {
108 $capability_field = isset( $_POST['capability-field'] ) ? $_POST['capability-field'] : null;
109 } else {
110 $capability_field = Groups_Post_Access::READ_POST_CAPABILITY;
111 }
112 if ( !empty( $capability_field ) ) {
113 $update = true;
114 if ( $other_capability = Groups_Capability::read_by_capability( $capability_field ) ) {
115 if ( $other_capability->capability_id != $capability_id ) {
116 Groups_Admin::add_message( sprintf( __( 'The <em>%s</em> capability already exists and cannot be assigned to this one.', GROUPS_PLUGIN_DOMAIN ), stripslashes( wp_filter_nohtml_kses( $other_capability->capability ) ) ), 'error' );
117 $update = false;
118 }
119 }
120 if ( $update ) {
121 $description = isset( $_POST['description-field'] ) ? $_POST['description-field'] : '';
122 $capability_id = Groups_Capability::update( array( 'capability_id' => $capability_id, 'capability' => $capability_field, 'description' => $description ) );
123 if ( $capability_id ) {
124 $result = $capability_id;
125 } else {
126 Groups_Admin::add_message( sprintf( __( 'The <em>%s</em> capability could not be updated.', GROUPS_PLUGIN_DOMAIN ), stripslashes( wp_filter_nohtml_kses( $capability ) ) ), 'error' );
127 }
128 }
129 } else {
130 Groups_Admin::add_message( __( 'The <em>Capability</em> must not be empty.', GROUPS_PLUGIN_DOMAIN ), 'error' );
131 }
132 }
133 return $result;
134 } // function groups_admin_capabilities_edit_submit
135