| 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 |
/** |
| 23 |
* Show edit capability form. |
| 24 |
* @param int $capability_id capability id |
| 25 |
*/ |
| 26 |
function groups_admin_capabilities_edit( $capability_id ) { |
| 27 |
|
| 28 |
global $wpdb; |
| 29 |
|
| 30 |
if ( !current_user_can( GROUPS_ADMINISTER_GROUPS ) ) { |
| 31 |
wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) ); |
| 32 |
} |
| 33 |
|
| 34 |
$capability = Groups_Capability::read( intval( $capability_id ) ); |
| 35 |
|
| 36 |
if ( empty( $capability ) ) { |
| 37 |
wp_die( __( 'No such capability.', GROUPS_PLUGIN_DOMAIN ) ); |
| 38 |
} |
| 39 |
|
| 40 |
$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
| 41 |
$current_url = remove_query_arg( 'action', $current_url ); |
| 42 |
$current_url = remove_query_arg( 'capability_id', $current_url ); |
| 43 |
|
| 44 |
$capability_capability = isset( $_POST['capability-field'] ) ? $_POST['capability-field'] : $capability->capability; |
| 45 |
$description = isset( $_POST['description-field'] ) ? $_POST['description-field'] : $capability->description; |
| 46 |
|
| 47 |
$capability_readonly = ( $capability->capability !== Groups_Post_Access::READ_POST_CAPABILITY ) ? "" : ' readonly="readonly" '; |
| 48 |
|
| 49 |
$output = |
| 50 |
'<div class="manage-capabilities">' . |
| 51 |
'<div>' . |
| 52 |
'<h2>' . |
| 53 |
__( 'Edit a capability', GROUPS_PLUGIN_DOMAIN ) . |
| 54 |
'</h2>' . |
| 55 |
'</div>' . |
| 56 |
|
| 57 |
'<form id="edit-capability" action="' . $current_url . '" method="post">' . |
| 58 |
'<div class="capability edit">' . |
| 59 |
'<input id="capability-id-field" name="capability-id-field" type="hidden" value="' . esc_attr( intval( $capability_id ) ) . '"/>' . |
| 60 |
|
| 61 |
'<div class="field">' . |
| 62 |
'<label for="capability-field" class="field-label first required">' .__( 'Capability', GROUPS_PLUGIN_DOMAIN ) . '</label>' . |
| 63 |
'<input ' . $capability_readonly . ' id="capability-field" name="capability-field" class="capability-field" type="text" value="' . esc_attr( $capability_capability ) . '"/>' . |
| 64 |
'</div>' . |
| 65 |
|
| 66 |
'<div class="field">' . |
| 67 |
'<label for="description-field" class="field-label description-field">' .__( 'Description', GROUPS_PLUGIN_DOMAIN ) . '</label>' . |
| 68 |
'<textarea id="description-field" name="description-field" rows="5" cols="45">' . wp_filter_nohtml_kses( $description ) . '</textarea>' . |
| 69 |
'</div>' . |
| 70 |
|
| 71 |
'<div class="field">' . |
| 72 |
wp_nonce_field( 'capabilities-edit', GROUPS_ADMIN_GROUPS_NONCE, true, false ) . |
| 73 |
'<input type="submit" value="' . __( 'Save', GROUPS_PLUGIN_DOMAIN ) . '"/>' . |
| 74 |
'<input type="hidden" value="edit" name="action"/>' . |
| 75 |
'<a class="cancel" href="' . $current_url . '">' . __( 'Cancel', GROUPS_PLUGIN_DOMAIN ) . '</a>' . |
| 76 |
'</div>' . |
| 77 |
'</div>' . // .capability.edit |
| 78 |
'</form>' . |
| 79 |
'</div>'; // .manage-capabilities |
| 80 |
|
| 81 |
echo $output; |
| 82 |
|
| 83 |
Groups_Help::footer(); |
| 84 |
} // function groups_admin_capabilities_edit |
| 85 |
|
| 86 |
/** |
| 87 |
* Handle edit form submission. |
| 88 |
*/ |
| 89 |
function groups_admin_capabilities_edit_submit() { |
| 90 |
|
| 91 |
if ( !current_user_can( GROUPS_ADMINISTER_GROUPS ) ) { |
| 92 |
wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) ); |
| 93 |
} |
| 94 |
|
| 95 |
if ( !wp_verify_nonce( $_POST[GROUPS_ADMIN_GROUPS_NONCE], 'capabilities-edit' ) ) { |
| 96 |
wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) ); |
| 97 |
} |
| 98 |
|
| 99 |
$capability_id = isset( $_POST['capability-id-field'] ) ? $_POST['capability-id-field'] : null; |
| 100 |
$capability = Groups_Capability::read( $capability_id ); |
| 101 |
if ( $capability ) { |
| 102 |
$capability_id = $capability->capability_id; |
| 103 |
if ( $capability->capability !== Groups_Post_Access::READ_POST_CAPABILITY ) { |
| 104 |
$capability = isset( $_POST['capability-field'] ) ? $_POST['capability-field'] : null; |
| 105 |
} else { |
| 106 |
$capability = Groups_Post_Access::READ_POST_CAPABILITY; |
| 107 |
} |
| 108 |
$description = isset( $_POST['description-field'] ) ? $_POST['description-field'] : ''; |
| 109 |
return Groups_Capability::update( compact( "capability_id", "capability", "description" ) ); |
| 110 |
} else { |
| 111 |
return false; |
| 112 |
} |
| 113 |
|
| 114 |
} // function groups_admin_capabilities_edit_submit |
| 115 |
|