* Author URI: http://www.gaslightmedia.com
* License: All right reserved
*/
+define('GLM_NEW_CAPABILITY', 'glmquicksite_edit_client');
+define('BUILT_IN_CAPABILITY', 'edit_posts');
add_action( 'admin_menu', 'glmQuickSite_add_admin_menu' );
add_action( 'admin_init', 'glmQuickSite_settings_init' );
register_activation_hook(__FILE__, 'glmQuickSite_install_plugin_data');
register_deactivation_hook(__FILE__, 'glmQuickSite_remove_plugin_data');
+function add_capability() {
+ $roles = get_editable_roles();
+ foreach ($GLOBALS['wp_roles']->role_objects as $key => $role) {
+ if (isset($roles[$key]) && $role->has_cap(BUILT_IN_CAPABILITY)) {
+ $role->add_cap(GLM_NEW_CAPABILITY);
+ }
+ }
+}
+
+function remove_capability() {
+ $roles = get_editable_roles();
+ foreach ($GLOBALS['wp_roles']->role_objects as $key => $role) {
+ if (isset($roles[$key]) && $role->has_cap(GLM_NEW_CAPABILITY)) {
+ $role->remove_cap(GLM_NEW_CAPABILITY);
+ }
+ }
+}
+
function glmQuickSite_install_plugin_data(){
+ add_capability();
// [status_US] array of states and their abbr.
$states_US[''] = '-- Select --';// {{{
$states_US['AL'] = 'Alabama';
}
function glmQuickSite_remove_plugin_data() {
+ remove_capability();
delete_option( 'glmquicksite_settings' );
delete_option( 'glmquicksite_states' );
+
}
function glmQuickSite_add_admin_menu( ) {
- add_menu_page( 'Gaslight Client Info', 'GLM Client Info', 'delete_posts', 'glmquicksite', 'glmquicksite_options_page' );
+ add_menu_page( 'Gaslight Client Info', 'GLM Client Info', GLM_NEW_CAPABILITY, 'glmquicksite', 'glmquicksite_options_page' );
}
function glmQuickSite_settings_init( ) {
-
register_setting( 'pluginPage', 'glmQuickSite_settings' );
add_filter('option_page_capability_pluginPage', 'glmQuickSite_option_page_capability');
}
function glmQuickSite_option_page_capability($capability) {
- return 'edit_posts';
+ return GLM_NEW_CAPABILITY;
}
function glmquicksite_options_page( ) {
+ if (current_user_can(GLM_NEW_CAPABILITY)) {
?>
<div class="wrap">
</form>
</div>
<?php
+ } else {
+ ?>
+ <div class="wrap"><p>You do not have permission to edit Client Info</p></div>
+ <?php
+ }
}
?>