Added login request
This commit is contained in:
@@ -0,0 +1,734 @@
|
||||
<?php
|
||||
/**
|
||||
* General Admin for Capability Manager.
|
||||
* Provides admin pages to create and manage roles and capabilities.
|
||||
*
|
||||
* @version $Rev: 198515 $
|
||||
* @author Jordi Canals, Kevin Behrens
|
||||
* @copyright Copyright (C) 2009, 2010 Jordi Canals, (C) 2012-2013 Kevin Behrens
|
||||
* @license GNU General Public License version 2
|
||||
* @link http://agapetry.net
|
||||
*
|
||||
|
||||
Copyright 2009, 2010 Jordi Canals <devel@jcanals.cat>
|
||||
Modifications Copyright 2012-2015, Kevin Behrens <kevin@agapetry.net>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
$roles = $this->roles;
|
||||
$default = $this->current;
|
||||
|
||||
if( defined('PP_ACTIVE') ) {
|
||||
require_once( dirname(__FILE__).'/pp-ui.php' );
|
||||
$pp_ui = new Capsman_PP_UI();
|
||||
$pp_metagroup_caps = $pp_ui->get_metagroup_caps( $default );
|
||||
} else
|
||||
$pp_metagroup_caps = array();
|
||||
?>
|
||||
<div class="wrap">
|
||||
<?php if( defined('PP_ACTIVE') ) :
|
||||
pp_icon();
|
||||
$style = 'style="height:60px;"';
|
||||
?>
|
||||
<?php else:
|
||||
$style = '';
|
||||
?>
|
||||
<div id="icon-capsman-admin" class="icon32"></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<h1 <?php echo $style;?>><?php _e('Roles and Capabilities', 'capsman-enhanced') ?></h1>
|
||||
|
||||
<form method="post" action="admin.php?page=<?php echo $this->ID ?>">
|
||||
<?php wp_nonce_field('capsman-general-manager'); ?>
|
||||
<fieldset>
|
||||
<table id="akmin">
|
||||
<tr>
|
||||
<td class="content">
|
||||
<dl>
|
||||
<dt><?php printf(__('Capabilities for %s', 'capsman-enhanced'), $roles[$default]); ?></dt>
|
||||
<dd>
|
||||
<div>
|
||||
<?php _e( 'View and modify capabilities WordPress associates with each role. Changes <strong>remain in the database</strong> even if you deactivate this plugin.', 'capsman-enhanced' ); ?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
if ( defined( 'PP_ACTIVE' ) ) {
|
||||
$pp_ui->show_capability_hints( $default );
|
||||
} else {
|
||||
global $capsman;
|
||||
$img_url = $capsman->mod_url . '/images/';
|
||||
|
||||
echo '<div style="margin-top:5px">';
|
||||
_e( "To further customize editing or viewing access, consider stepping up to <a href='#pp-more'>Press Permit</a>.", 'capsman-enhanced' );
|
||||
echo '</div>';
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
/* <![CDATA[ */
|
||||
jQuery(document).ready( function($) {
|
||||
$('a[href=#pp-more]').click( function() {
|
||||
$('#pp_features').show();
|
||||
return false;
|
||||
});
|
||||
$('a[href=#pp-hide]').click( function() {
|
||||
$('#pp_features').hide();
|
||||
return false;
|
||||
});
|
||||
});
|
||||
/* ]]> */
|
||||
</script>
|
||||
<style>
|
||||
#pp_features {display:none;border:1px solid #eee;padding:5px;text-align:center;min-width:600px}
|
||||
div.pp-logo { text-align: center }
|
||||
div.features-wrap { margin-left: auto; margin-right: auto; text-align: center; width: 540px; }
|
||||
ul.pp-features { list-style: none; padding-top:10px; text-align:left; margin-left: auto }
|
||||
ul.pp-features li:before { content: "\2713\0020"; }
|
||||
ul.pp-features li { padding-bottom: 5px }
|
||||
img.cme-play { margin-bottom: -3px; margin-left: 5px;}
|
||||
</style>
|
||||
|
||||
<?php /* play.png icon by Pavel: http://kde-look.org/usermanager/search.php?username=InFeRnODeMoN */ ?>
|
||||
|
||||
<br /><div id="pp_features"><div class="pp-logo"><a href="http://presspermit.com"><img src="<?php echo $img_url;?>pp-logo.png" /></a></div><div class="features-wrap"><ul class="pp-features">
|
||||
<li>
|
||||
<?php _e( "Automatically define type-specific capabilities for your custom post types and taxonomies", 'capsman-enhanced' );?>
|
||||
<a href="http://presspermit.com/tutorial/regulate-post-type-access" target="_blank"><img class="cme-play" src="<?php echo $img_url;?>play.png" /></a></li>
|
||||
|
||||
<li>
|
||||
<?php _e( "Assign standard WP roles supplementally for a specific post type", 'capsman-enhanced' );?>
|
||||
<a href="http://presspermit.com/tutorial/regulate-post-type-access" target="_blank"><img class="cme-play" src="<?php echo $img_url;?>play.png" /></a></li>
|
||||
|
||||
<li>
|
||||
<?php _e( "Assign custom WP roles supplementally for a specific post type <em>(Pro)</em>", 'capsman-enhanced' );?>
|
||||
<a href="http://presspermit.com/tutorial/custom-role-usage" target="_blank"><img class="cme-play" src="<?php echo $img_url;?>play.png" /></a></li>
|
||||
|
||||
<li>
|
||||
<?php _e( "Customize reading permissions per-category or per-post", 'capsman-enhanced' );?>
|
||||
<a href="http://presspermit.com/tutorial/category-exceptions" target="_blank"><img class="cme-play" src="<?php echo $img_url;?>play.png" /></a></li>
|
||||
|
||||
<li>
|
||||
<?php _e( "Customize editing permissions per-category or per-post <em>(Pro)</em>", 'capsman-enhanced' );?>
|
||||
<a href="http://presspermit.com/tutorial/page-editing-exceptions" target="_blank"><img class="cme-play" src="<?php echo $img_url;?>play.png" /></a></li>
|
||||
|
||||
<li>
|
||||
<?php _e( "Custom Post Visibility statuses, fully implemented throughout wp-admin <em>(Pro)</em>", 'capsman-enhanced' );?>
|
||||
<a href="http://presspermit.com/tutorial/custom-post-visibility" target="_blank"><img class="cme-play" src="<?php echo $img_url;?>play.png" /></a></li>
|
||||
|
||||
<li>
|
||||
<?php _e( "Custom Moderation statuses for access-controlled, multi-step publishing workflow <em>(Pro)</em>", 'capsman-enhanced' );?>
|
||||
<a href="http://presspermit.com/tutorial/multi-step-moderation" target="_blank"><img class="cme-play" src="<?php echo $img_url;?>play.png" /></a></li>
|
||||
|
||||
<li>
|
||||
<?php _e( "Regulate permissions for Edit Flow post statuses <em>(Pro)</em>", 'capsman-enhanced' );?>
|
||||
<a href="http://presspermit.com/tutorial/edit-flow-integration" target="_blank"><img class="cme-play" src="<?php echo $img_url;?>play.png" /></a></li>
|
||||
|
||||
<li>
|
||||
<?php _e( "Customize the moderated editing of published content with Revisionary or Post Forking <em>(Pro)</em>", 'capsman-enhanced' );?>
|
||||
<a href="http://presspermit.com/tutorial/published-content-revision" target="_blank"><img class="cme-play" src="<?php echo $img_url;?>play.png" /></a></li>
|
||||
|
||||
<li>
|
||||
<?php _e( "Grant Spectator, Participant or Moderator access to specific bbPress forums <em>(Pro)</em>", 'capsman-enhanced' );?>
|
||||
<a href="http://presspermit.com/tutorial/bbpress-exceptions" target="_blank"><img class="cme-play" src="<?php echo $img_url;?>play.png" /></a></li>
|
||||
|
||||
<li>
|
||||
<?php _e( "Grant supplemental content permissions to a BuddyPress group <em>(Pro)</em>", 'capsman-enhanced' );?>
|
||||
<a href="http://presspermit.com/tutorial/buddypress-content-permissions" target="_blank"><img class="cme-play" src="<?php echo $img_url;?>play.png" /></a></li>
|
||||
|
||||
<li>
|
||||
<?php _e( "WPML integration to mirror permissions to translations <em>(Pro)</em>", 'capsman-enhanced' );?>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<?php _e( "Member support forum", 'capsman-enhanced' );?>
|
||||
</li>
|
||||
|
||||
</ul></div>
|
||||
<?php
|
||||
echo '<div>';
|
||||
printf( __('%1$sgrab%2$s %3$s', 'capsman-enhanced'), '<strong>', '</strong>', '<span class="plugins update-message"><a href="' . cme_plugin_info_url('press-permit-core') . '" class="thickbox" title="' . sprintf( __('%s (free install)', 'capsman-enhanced'), 'Press Permit Core' ) . '">Press Permit Core</a></span>' );
|
||||
echo ' • ';
|
||||
printf( __('%1$sbuy%2$s %3$s', 'capsman-enhanced'), '<strong>', '</strong>', '<a href="http://presspermit.com" target="_blank" title="' . sprintf( __('%s info/purchase', 'capsman-enhanced'), 'Press Permit Pro' ) . '">Press Permit Pro</a>' );
|
||||
echo ' • ';
|
||||
echo '<a href="#pp-hide">hide</a>';
|
||||
echo '</div></div>';
|
||||
}
|
||||
|
||||
if ( MULTISITE ) {
|
||||
global $wp_roles;
|
||||
global $wpdb;
|
||||
|
||||
if ( ! empty($_REQUEST['cme_net_sync_role'] ) ) {
|
||||
switch_to_blog(1);
|
||||
wp_cache_delete( $wpdb->prefix . 'user_roles', 'options' );
|
||||
}
|
||||
|
||||
( method_exists( $wp_roles, 'for_site' ) ) ? $wp_roles->for_site() : $wp_roles->reinit();
|
||||
}
|
||||
|
||||
global $capsman;
|
||||
$capsman->reinstate_db_roles();
|
||||
|
||||
$current = get_role($default);
|
||||
|
||||
//print_r($current);
|
||||
|
||||
$rcaps = $current->capabilities;
|
||||
|
||||
// ========= Begin Kevin B mod ===========
|
||||
$is_administrator = current_user_can( 'administrator' );
|
||||
|
||||
$custom_types = get_post_types( array( '_builtin' => false ), 'names' );
|
||||
$custom_tax = get_taxonomies( array( '_builtin' => false ), 'names' );
|
||||
|
||||
$defined = array();
|
||||
$defined['type'] = get_post_types( array( 'public' => true ), 'object' );
|
||||
$defined['taxonomy'] = get_taxonomies( array( 'public' => true ), 'object' );
|
||||
|
||||
$unfiltered['type'] = apply_filters( 'pp_unfiltered_post_types', array('forum','topic','reply') ); // bbPress' dynamic role def requires additional code to enforce stored caps
|
||||
$unfiltered['taxonomy'] = apply_filters( 'pp_unfiltered_taxonomies', array( 'post_status', 'topic-tag' ) ); // avoid confusion with Edit Flow administrative taxonomy
|
||||
/*
|
||||
if ( ( count($custom_types) || count($custom_tax) ) && ( $is_administrator || current_user_can( 'manage_pp_settings' ) ) ) {
|
||||
$cap_properties[''] = array();
|
||||
$force_distinct_ui = true;
|
||||
}
|
||||
*/
|
||||
|
||||
$cap_properties['edit']['type'] = array( 'edit_posts' );
|
||||
|
||||
foreach( $defined['type'] as $type_obj ) {
|
||||
if ( 'attachment' != $type_obj->name ) {
|
||||
if ( isset( $type_obj->cap->create_posts ) && ( $type_obj->cap->create_posts != $type_obj->cap->edit_posts ) ) {
|
||||
$cap_properties['edit']['type'][]= 'create_posts';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$cap_properties['edit']['type'][]= 'edit_others_posts';
|
||||
$cap_properties['edit']['type'] = array_merge( $cap_properties['edit']['type'], array( 'publish_posts', 'edit_published_posts', 'edit_private_posts' ) );
|
||||
|
||||
$cap_properties['edit']['taxonomy'] = array( 'manage_terms' );
|
||||
|
||||
if ( ! defined( 'PP_ACTIVE' ) )
|
||||
$cap_properties['edit']['taxonomy'] = array_merge( $cap_properties['edit']['taxonomy'], array( 'edit_terms', 'assign_terms' ) );
|
||||
|
||||
$cap_properties['delete']['type'] = array( 'delete_posts', 'delete_others_posts' );
|
||||
$cap_properties['delete']['type'] = array_merge( $cap_properties['delete']['type'], array( 'delete_published_posts', 'delete_private_posts' ) );
|
||||
|
||||
if ( ! defined( 'PP_ACTIVE' ) )
|
||||
$cap_properties['delete']['taxonomy'] = array( 'delete_terms' );
|
||||
else
|
||||
$cap_properties['delete']['taxonomy'] = array();
|
||||
|
||||
$cap_properties['read']['type'] = array( 'read_private_posts' );
|
||||
$cap_properties['read']['taxonomy'] = array();
|
||||
|
||||
$stati = get_post_stati( array( 'internal' => false ) );
|
||||
|
||||
//if ( count($stati) > 5 ) {
|
||||
$cap_type_names = array(
|
||||
'' => __( ' ', 'capsman-enhanced' ),
|
||||
'read' => __( 'Reading', 'capsman-enhanced' ),
|
||||
'edit' => __( 'Editing Capabilities', 'capsman-enhanced' ),
|
||||
'delete' => __( 'Deletion Capabilities', 'capsman-enhanced' )
|
||||
);
|
||||
|
||||
//} else {
|
||||
|
||||
//}
|
||||
|
||||
$cap_tips = array(
|
||||
'read_private' => __( 'can read posts which are currently published with private visibility', 'capsman-enhanced' ),
|
||||
'edit' => __( 'has basic editing capability (but may need other capabilities based on post status and ownership)', 'capsman-enhanced' ),
|
||||
'edit_others' => __( 'can edit posts which were created by other users', 'capsman-enhanced' ),
|
||||
'edit_published' => __( 'can edit posts which are currently published', 'capsman-enhanced' ),
|
||||
'edit_private' => __( 'can edit posts which are currently published with private visibility', 'capsman-enhanced' ),
|
||||
'publish' => __( 'can make a post publicly visible', 'capsman-enhanced' ),
|
||||
'delete' => __( 'has basic deletion capability (but may need other capabilities based on post status and ownership)', 'capsman-enhanced' ),
|
||||
'delete_others' => __( 'can delete posts which were created by other users', 'capsman-enhanced' ),
|
||||
'delete_published' => __( 'can delete posts which are currently published', 'capsman-enhanced' ),
|
||||
'delete_private' => __( 'can delete posts which are currently published with private visibility', 'capsman-enhanced' ),
|
||||
);
|
||||
|
||||
$default_caps = array( 'read_private_posts', 'edit_posts', 'edit_others_posts', 'edit_published_posts', 'edit_private_posts', 'publish_posts', 'delete_posts', 'delete_others_posts', 'delete_published_posts', 'delete_private_posts',
|
||||
'read_private_pages', 'edit_pages', 'edit_others_pages', 'edit_published_pages', 'edit_private_pages', 'publish_pages', 'delete_pages', 'delete_others_pages', 'delete_published_pages', 'delete_private_pages',
|
||||
'manage_categories'
|
||||
);
|
||||
$type_caps = array();
|
||||
|
||||
// Role Scoper and PP1 adjust attachment access based only on user's capabilities for the parent post
|
||||
if ( defined('SCOPER_VERSION') || ( defined( 'PP_ACTIVE' ) && ! defined( 'PPC_VERSION' ) ) )
|
||||
unset( $defined['type']['attachment'] );
|
||||
|
||||
echo '<ul class="cme-listhoriz">';
|
||||
|
||||
// cap_types: read, edit, deletion
|
||||
foreach( array_keys($cap_properties) as $cap_type ) {
|
||||
echo '<li>';
|
||||
echo '<h3>' . $cap_type_names[$cap_type] . '</h3>';
|
||||
echo '<table class="cme-typecaps">';
|
||||
|
||||
foreach( array_keys($defined) as $item_type ) {
|
||||
if ( ( 'delete' == $cap_type ) && ( 'taxonomy' == $item_type ) ) {
|
||||
if ( defined('SCOPER_VERSION') || defined('PP_ACTIVE') )
|
||||
continue;
|
||||
|
||||
$any_term_deletion_caps = false;
|
||||
foreach( array_keys($defined['taxonomy']) as $_tax ) {
|
||||
if ( isset( $defined['taxonomy'][$_tax]->cap->delete_terms ) && ( 'manage_categories' != $defined['taxonomy'][$_tax]->cap->delete_terms ) && ! in_array( $_tax, $unfiltered['taxonomy'] ) ) {
|
||||
$any_term_deletion_caps = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $any_term_deletion_caps )
|
||||
continue;
|
||||
}
|
||||
|
||||
//if ( ! $cap_type ) {
|
||||
|
||||
//} else {
|
||||
echo '<th></th>';
|
||||
|
||||
if ( ! count( $cap_properties[$cap_type][$item_type] ) )
|
||||
continue;
|
||||
|
||||
// label cap properties
|
||||
foreach( $cap_properties[$cap_type][$item_type] as $prop ) {
|
||||
$prop = str_replace( '_posts', '', $prop );
|
||||
$prop = str_replace( '_pages', '', $prop );
|
||||
$prop = str_replace( '_terms', '', $prop );
|
||||
$tip = ( isset( $cap_tips[$prop] ) ) ? "title='{$cap_tips[$prop]}'" : '';
|
||||
$prop = str_replace( '_', '<br />', $prop );
|
||||
$th_class = ( 'taxonomy' == $item_type ) ? ' class="term-cap"' : ' class="post-cap"';
|
||||
echo "<th $tip{$th_class}>";
|
||||
echo ucwords($prop);
|
||||
echo '</th>';
|
||||
}
|
||||
|
||||
foreach( $defined[$item_type] as $key => $type_obj ) {
|
||||
if ( in_array( $key, $unfiltered[$item_type] ) )
|
||||
continue;
|
||||
|
||||
$row = "<tr class='cme_type_{$key}'>";
|
||||
|
||||
if ( $cap_type ) {
|
||||
if ( empty($force_distinct_ui) && empty( $cap_properties[$cap_type][$item_type] ) )
|
||||
continue;
|
||||
|
||||
$row .= "<td><a class='cap_type' href='#toggle_type_caps'>" . $type_obj->labels->name . '</a>';
|
||||
$row .= '<a href="#" class="neg-type-caps"> x </a>';
|
||||
$row .= '</td>';
|
||||
|
||||
$display_row = ! empty($force_distinct_ui);
|
||||
|
||||
foreach( $cap_properties[$cap_type][$item_type] as $prop ) {
|
||||
$td_classes = array();
|
||||
$checkbox = '';
|
||||
|
||||
if ( ! empty($type_obj->cap->$prop) && ( in_array( $type_obj->name, array( 'post', 'page' ) )
|
||||
|| ! in_array( $type_obj->cap->$prop, $default_caps )
|
||||
|| ( ( 'manage_categories' == $type_obj->cap->$prop ) && ( 'manage_terms' == $prop ) && ( 'category' == $type_obj->name ) ) ) ) {
|
||||
|
||||
// if edit_published or edit_private cap is same as edit_posts cap, don't display a checkbox for it
|
||||
if ( ( ! in_array( $prop, array( 'edit_published_posts', 'edit_private_posts', 'create_posts' ) ) || ( $type_obj->cap->$prop != $type_obj->cap->edit_posts ) )
|
||||
&& ( ! in_array( $prop, array( 'delete_published_posts', 'delete_private_posts' ) ) || ( $type_obj->cap->$prop != $type_obj->cap->delete_posts ) )
|
||||
) {
|
||||
$cap_name = $type_obj->cap->$prop;
|
||||
|
||||
if ( 'taxonomy' == $item_type )
|
||||
$td_classes []= "term-cap";
|
||||
else
|
||||
$td_classes []= "post-cap";
|
||||
|
||||
if ( ! empty($pp_metagroup_caps[$cap_name]) )
|
||||
$td_classes []='cm-has-via-pp';
|
||||
|
||||
if ( $is_administrator || current_user_can($cap_name) ) {
|
||||
if ( ! empty($pp_metagroup_caps[$cap_name]) ) {
|
||||
$title_text = sprintf( __( '%s: assigned by Permission Group', 'capsman-enhanced' ), $cap_name );
|
||||
} else {
|
||||
$title_text = $cap_name;
|
||||
}
|
||||
|
||||
$disabled = '';
|
||||
$checked = checked(1, ! empty($rcaps[$cap_name]), false );
|
||||
|
||||
$checkbox = '<input id=caps[' . $cap_name . '] type="checkbox" title="' . $title_text . '" name="caps[' . $cap_name . ']" value="1" ' . $checked . $disabled . ' />';
|
||||
$type_caps [$cap_name] = true;
|
||||
$display_row = true;
|
||||
}
|
||||
} else
|
||||
$td_classes []= "cap-unreg";
|
||||
|
||||
if ( isset($rcaps[$cap_name]) && empty($rcaps[$cap_name]) )
|
||||
$td_classes []= "cap-neg";
|
||||
} else
|
||||
$td_classes []= "cap-unreg";
|
||||
|
||||
$td_class = ( $td_classes ) ? 'class="' . implode(' ', $td_classes) . '"' : '';
|
||||
|
||||
$row .= "<td $td_class><span class='cap-x'>X</span>$checkbox";
|
||||
|
||||
if ( false !== strpos( $td_class, 'cap-neg' ) )
|
||||
$row .= '<input type="hidden" class="cme-negation-input" name="caps[' . $cap_name . ']" value="" />';
|
||||
|
||||
$row .= "</td>";
|
||||
}
|
||||
}
|
||||
|
||||
if ( $display_row ) {
|
||||
$row .= '</tr>';
|
||||
echo $row;
|
||||
}
|
||||
}
|
||||
//} // endif this iteration is for type caps checkbox display
|
||||
|
||||
} // end foreach item type
|
||||
|
||||
echo '</table>';
|
||||
|
||||
echo '</li>';
|
||||
}
|
||||
|
||||
echo '</ul>';
|
||||
|
||||
// clicking on post type name toggles corresponding checkbox selections
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
/* <![CDATA[ */
|
||||
jQuery(document).ready( function($) {
|
||||
$('a[href="#toggle_type_caps"]').click( function() {
|
||||
var chks = $(this).closest('tr').find('input');
|
||||
$(chks).prop( 'checked', ! $(chks).first().is(':checked') );
|
||||
return false;
|
||||
});
|
||||
});
|
||||
/* ]]> */
|
||||
</script>
|
||||
<?php
|
||||
|
||||
$core_caps = array_fill_keys( array( 'switch_themes', 'edit_themes', 'activate_plugins', 'edit_plugins', 'edit_users', 'edit_files', 'manage_options', 'moderate_comments',
|
||||
'manage_links', 'upload_files', 'import', 'unfiltered_html', 'read', 'delete_users', 'create_users', 'unfiltered_upload', 'edit_dashboard',
|
||||
'update_plugins', 'delete_plugins', 'install_plugins', 'update_themes', 'install_themes',
|
||||
'update_core', 'list_users', 'remove_users', 'add_users', 'promote_users', 'edit_theme_options', 'delete_themes', 'export' ), true );
|
||||
|
||||
ksort( $core_caps );
|
||||
|
||||
echo '<p> </p><h3>' . __( 'Other WordPress Core Capabilities', 'capsman-enhanced' ) . '</h3>';
|
||||
echo '<table width="100%" class="form-table cme-checklist"><tr>';
|
||||
|
||||
|
||||
$checks_per_row = get_option( 'cme_form-rows', 5 );
|
||||
$i = 0; $first_row = true;
|
||||
|
||||
foreach( array_keys($core_caps) as $cap_name ) {
|
||||
if ( ! $is_administrator && ! current_user_can($cap_name) )
|
||||
continue;
|
||||
|
||||
if ( $i == $checks_per_row ) {
|
||||
echo '</tr><tr>';
|
||||
$i = 0;
|
||||
}
|
||||
|
||||
if ( ! isset( $rcaps[$cap_name] ) )
|
||||
$class = 'cap-no';
|
||||
else
|
||||
$class = ( $rcaps[$cap_name] ) ? 'cap-yes' : 'cap-neg';
|
||||
|
||||
if ( ! empty($pp_metagroup_caps[$cap_name]) ) {
|
||||
$class .= ' cap-metagroup';
|
||||
$title_text = sprintf( __( '%s: assigned by Permission Group', 'capsman-enhanced' ), $cap_name );
|
||||
} else {
|
||||
$title_text = $cap_name;
|
||||
}
|
||||
|
||||
$disabled = '';
|
||||
$checked = checked(1, ! empty($rcaps[$cap_name]), false );
|
||||
?>
|
||||
<td class="<?php echo $class; ?>"><span class="cap-x">X</span><label for="caps[<?php echo $cap_name; ?>]" title="<?php echo $title_text;?>"><input id=caps[<?php echo $cap_name; ?>] type="checkbox" name="caps[<?php echo $cap_name; ?>]" value="1" <?php echo $checked . $disabled;?> />
|
||||
<span>
|
||||
<?php
|
||||
echo str_replace( '_', ' ', $cap_name );
|
||||
?>
|
||||
</span></label><a href="#" class="neg-cap"> x </a>
|
||||
<?php if ( false !== strpos( $class, 'cap-neg' ) ) :?>
|
||||
<input type="hidden" class="cme-negation-input" name="caps[<?php echo $cap_name; ?>]" value="" />
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
|
||||
<?php
|
||||
++$i;
|
||||
}
|
||||
|
||||
if ( $i == $checks_per_row ) {
|
||||
echo '</tr><tr>';
|
||||
$i = 0;
|
||||
} elseif ( ! $first_row ) {
|
||||
// Now close a wellformed table
|
||||
for ( $i; $i < $checks_per_row; $i++ ){
|
||||
echo '<td> </td>';
|
||||
}
|
||||
echo '</tr>';
|
||||
}
|
||||
?>
|
||||
|
||||
<tr class="cme-bulk-select">
|
||||
<td colspan="<?php echo $checks_per_row;?>">
|
||||
<span style="float:right">
|
||||
<input type="checkbox" class="cme-check-all" title="<?php _e('check/uncheck all', 'capsman-enhanced');?>"> <a class="cme-neg-all" href="#" title="<?php _e('negate all (storing as disabled capabilities)', 'capsman-enhanced');?>">X</a> <a class="cme-switch-all" href="#" title="<?php _e('negate none (add/remove all capabilities normally)', 'capsman-enhanced');?>">X</a>
|
||||
</span>
|
||||
</td></tr>
|
||||
|
||||
</table>
|
||||
|
||||
<?php
|
||||
echo '<p> </p><h3>' . __( 'Additional Capabilities', 'capsman-enhanced' ) . '</h3>';
|
||||
|
||||
?>
|
||||
<table width='100%' class="form-table cme-checklist">
|
||||
<tr>
|
||||
<?php
|
||||
$i = 0; $first_row = true;
|
||||
|
||||
$all_capabilities = apply_filters( 'capsman_get_capabilities', array_keys( $this->capabilities ), $this->ID );
|
||||
$all_capabilities = apply_filters( 'members_get_capabilities', $all_capabilities );
|
||||
|
||||
foreach( $all_capabilities as $cap_name ) {
|
||||
if ( ! isset($this->capabilities[$cap_name]) )
|
||||
$this->capabilities[$cap_name] = str_replace( '_', ' ', $cap_name );
|
||||
}
|
||||
|
||||
uasort( $this->capabilities, 'strnatcasecmp' ); // sort by array values, but maintain keys );
|
||||
|
||||
foreach ( $this->capabilities as $cap_name => $cap ) :
|
||||
if ( isset( $type_caps[$cap_name] ) || isset($core_caps[$cap_name]) )
|
||||
continue;
|
||||
|
||||
if ( ! $is_administrator && ! current_user_can($cap_name) )
|
||||
continue;
|
||||
|
||||
// ============ End Kevin B mod ===============
|
||||
|
||||
// Levels are not shown.
|
||||
if ( preg_match( '/^level_(10|[0-9])$/i', $cap_name ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $i == $checks_per_row ) {
|
||||
echo '</tr><tr>';
|
||||
$i = 0; $first_row = false;
|
||||
}
|
||||
|
||||
if ( ! isset( $rcaps[$cap_name] ) )
|
||||
$class = 'cap-no';
|
||||
else
|
||||
$class = ( $rcaps[$cap_name] ) ? 'cap-yes' : 'cap-neg';
|
||||
|
||||
if ( ! empty($pp_metagroup_caps[$cap_name]) ) {
|
||||
$class .= ' cap-metagroup';
|
||||
$title_text = sprintf( __( '%s: assigned by Permission Group', 'capsman-enhanced' ), $cap_name );
|
||||
} else {
|
||||
$title_text = $cap_name;
|
||||
}
|
||||
|
||||
$disabled = '';
|
||||
$checked = checked(1, ! empty($rcaps[$cap_name]), false );
|
||||
|
||||
if ( 'manage_capabilities' == $cap_name ) {
|
||||
if ( ! current_user_can('administrator') ) {
|
||||
continue;
|
||||
} elseif ( 'administrator' == $default ) {
|
||||
$class .= ' cap-locked';
|
||||
$lock_manage_caps_capability = true;
|
||||
$disabled = 'disabled="disabled"';
|
||||
}
|
||||
}
|
||||
?>
|
||||
<td class="<?php echo $class; ?>"><span class="cap-x">X</span><label for="caps[<?php echo $cap_name; ?>]" title="<?php echo $title_text;?>"><input id=caps[<?php echo $cap_name; ?>] type="checkbox" name="caps[<?php echo $cap_name; ?>]" value="1" <?php echo $checked . $disabled;?> />
|
||||
<span>
|
||||
<?php
|
||||
echo str_replace( '_', ' ', $cap );
|
||||
?>
|
||||
</span></label><a href="#" class="neg-cap"> x </a>
|
||||
<?php if ( false !== strpos( $class, 'cap-neg' ) ) :?>
|
||||
<input type="hidden" class="cme-negation-input" name="caps[<?php echo $cap_name; ?>]" value="" />
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<?php
|
||||
$i++;
|
||||
endforeach;
|
||||
|
||||
if ( ! empty($lock_manage_caps_capability) ) {
|
||||
echo '<input type="hidden" name="caps[manage_capabilities]" value="1" />';
|
||||
}
|
||||
|
||||
if ( $i == $checks_per_row ) {
|
||||
echo '</tr><tr>';
|
||||
$i = 0;
|
||||
} else {
|
||||
if ( ! $first_row ) {
|
||||
// Now close a wellformed table
|
||||
for ( $i; $i < $checks_per_row; $i++ ){
|
||||
echo '<td> </td>';
|
||||
}
|
||||
echo '</tr>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<tr class="cme-bulk-select">
|
||||
<td colspan="<?php echo $checks_per_row;?>">
|
||||
<span>
|
||||
<?php
|
||||
$level = ak_caps2level($rcaps);
|
||||
?>
|
||||
<?php _e('Level:', 'capsman-enhanced') ;?><select name="level">
|
||||
<?php for ( $l = $this->max_level; $l >= 0; $l-- ) {?>
|
||||
<option value="<?php echo $l; ?>" style="text-align:right;"<?php selected($level, $l); ?>> <?php echo $l; ?> </option>
|
||||
<?php }
|
||||
?>
|
||||
</select>
|
||||
</span>
|
||||
|
||||
<span style="float:right">
|
||||
<input type="checkbox" class="cme-check-all" title="<?php _e('check/uncheck all', 'capsman-enhanced');?>"> <a class="cme-neg-all" href="#" title="<?php _e('negate all (storing as disabled capabilities)', 'capsman-enhanced');?>">X</a> <a class="cme-switch-all" href="#" title="<?php _e('negate none (add/remove all capabilities normally)', 'capsman-enhanced');?>">X</a>
|
||||
</span>
|
||||
</td></tr>
|
||||
|
||||
</table>
|
||||
|
||||
<br />
|
||||
<?php if ( ! defined('PP_ACTIVE') || pp_get_option('display_hints') ) :?>
|
||||
<div class="cme-subtext">
|
||||
<?php _e( 'Note: Underscores replace spaces in stored capability name ("edit users" => "edit_users").', 'capsman-enhanced' ); ?>
|
||||
</div>
|
||||
<?php endif;?>
|
||||
</span>
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<?php
|
||||
$support_pp_only_roles = ( defined('PP_ACTIVE') ) ? $pp_ui->pp_only_roles_ui( $default ) : false;
|
||||
cme_network_role_ui( $default );
|
||||
?>
|
||||
|
||||
<p class="submit">
|
||||
<input type="hidden" name="action" value="update" />
|
||||
<input type="hidden" name="current" value="<?php echo $default; ?>" />
|
||||
<input type="submit" name="SaveRole" value="<?php _e('Save Changes', 'capsman-enhanced') ?>" class="button-primary" />
|
||||
|
||||
<?php if ( current_user_can('administrator') && 'administrator' != $default ) : ?>
|
||||
<a class="ak-delete" title="<?php echo esc_attr(__('Delete this role', 'capsman-enhanced')) ?>" href="<?php echo wp_nonce_url("admin.php?page={$this->ID}&action=delete&role={$default}", 'delete-role_' . $default); ?>" onclick="if ( confirm('<?php echo esc_js(sprintf(__("You are about to delete the %s role.\n 'Cancel' to stop, 'OK' to delete.", 'capsman-enhanced'), $roles[$default])); ?>') ) { return true;}return false;"><?php _e('Delete Role', 'capsman-enhanced')?></a>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<?php agp_admin_footer(); ?>
|
||||
<br />
|
||||
|
||||
</td>
|
||||
<td class="sidebar">
|
||||
<?php agp_admin_authoring($this->ID); ?>
|
||||
|
||||
<dl>
|
||||
<dt><?php if ( defined('WPLANG') && WPLANG ) _e('Select New Role', 'capsman-enhanced'); else echo('Select Role to View / Edit'); ?></dt>
|
||||
<dd style="text-align:center;">
|
||||
<p><select name="role">
|
||||
<?php
|
||||
foreach ( $roles as $role => $name ) {
|
||||
echo '<option value="' . $role .'"'; selected($default, $role); echo '> ' . $name . ' </option>';
|
||||
}
|
||||
?>
|
||||
</select><span style="margin-left:20px"><input type="submit" name="LoadRole" value="<?php if ( defined('WPLANG') && WPLANG ) _e('Change', 'capsman-enhanced'); else echo('Load'); ?>" class="button" /></span></p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<dl>
|
||||
<dt><?php _e('Create New Role', 'capsman-enhanced'); ?></dt>
|
||||
<dd style="text-align:center;">
|
||||
<?php $class = ( $support_pp_only_roles ) ? 'tight-text' : 'regular-text'; ?>
|
||||
<p><input type="text" name="create-name"" class="<?php echo $class;?>" placeholder="<?php _e('Name of new role', 'capsman-enhanced') ?>" />
|
||||
|
||||
<?php if( $support_pp_only_roles ) : ?>
|
||||
<label for="new_role_pp_only" title="<?php _e('Make role available for supplemental assignment to Permission Groups only', 'capsman-enhanced');?>"> <input type="checkbox" name="new_role_pp_only" id="new_role_pp_only" value="1"> <?php _e('hidden', 'capsman-enhanced'); ?> </label>
|
||||
<?php endif; ?>
|
||||
|
||||
<br />
|
||||
<input type="submit" name="CreateRole" value="<?php _e('Create', 'capsman-enhanced') ?>" class="button" />
|
||||
</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<dl>
|
||||
<dt><?php defined('WPLANG') && WPLANG ? _e('Copy this role to', 'capsman-enhanced') : printf( 'Copy %s Role', $roles[$default] ); ?></dt>
|
||||
<dd style="text-align:center;">
|
||||
<?php $class = ( $support_pp_only_roles ) ? 'tight-text' : 'regular-text'; ?>
|
||||
<p><input type="text" name="copy-name" class="<?php echo $class;?>" placeholder="<?php _e('Name of copied role', 'capsman-enhanced') ?>" />
|
||||
|
||||
<?php if( $support_pp_only_roles ) : ?>
|
||||
<label for="copy_role_pp_only" title="<?php _e('Make role available for supplemental assignment to Permission Groups only', 'capsman-enhanced');?>"> <input type="checkbox" name="copy_role_pp_only" id="copy_role_pp_only" value="1"> <?php _e('hidden', 'capsman-enhanced'); ?> </label>
|
||||
<?php endif; ?>
|
||||
|
||||
<br />
|
||||
<input type="submit" name="CopyRole" value="<?php _e('Copy', 'capsman-enhanced') ?>" class="button" />
|
||||
</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<dl>
|
||||
<dt><?php _e('Add Capability', 'capsman-enhanced'); ?></dt>
|
||||
<dd style="text-align:center;">
|
||||
<p><input type="text" name="capability-name" class="regular-text" placeholder="<?php _e('capability name', 'capsman-enhanced') ?>" /><br />
|
||||
<input type="submit" name="AddCap" value="<?php _e('Add to role', 'capsman-enhanced') ?>" class="button" /></p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<?php if ( defined('PP_ACTIVE') )
|
||||
$pp_ui->pp_types_ui( $defined );
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
function cme_network_role_ui( $default ) {
|
||||
if ( ! is_multisite() || ! is_super_admin() || ( 1 != get_current_blog_id() ) )
|
||||
return false;
|
||||
?>
|
||||
|
||||
<div style="float:right;margin-left:10px;margin-right:10px">
|
||||
<?php
|
||||
if ( ! $autocreate_roles = get_site_option( 'cme_autocreate_roles' ) )
|
||||
$autocreate_roles = array();
|
||||
|
||||
$checked = ( in_array( $default, $autocreate_roles ) ) ? 'checked="checked"': '';
|
||||
?>
|
||||
<div style="margin-bottom: 5px">
|
||||
<label for="cme_autocreate_role" title="<?php _e('Create this role definition in new (future) sites', 'capsman-enhanced');?>"><input type="checkbox" name="cme_autocreate_role" id="cme_autocreate_role" value="1" <?php echo $checked;?>> <?php _e('include in new sites', 'capsman-enhanced'); ?> </label>
|
||||
</div>
|
||||
<div>
|
||||
<label for="cme_net_sync_role" title="<?php echo esc_attr(__('Copy / update this role definition to all sites now', 'capsman-enhanced'));?>"><input type="checkbox" name="cme_net_sync_role" id="cme_net_sync_role" value="1"> <?php _e('sync role to all sites now', 'capsman-enhanced'); ?> </label>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
return true;
|
||||
}
|
||||
|
||||
function cme_plugin_info_url( $plugin_slug ) {
|
||||
return self_admin_url( "plugin-install.php?tab=plugin-information&plugin=$plugin_slug&TB_iframe=true&width=640&height=678" );
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
class Capsman_BackupHandler
|
||||
{
|
||||
var $cm;
|
||||
|
||||
function __construct( $manager_obj ) {
|
||||
if ( ! is_super_admin() && ! current_user_can( 'restore_roles' ) )
|
||||
wp_die( __( 'You do not have permission to restore roles.', 'capsman-enhanced' ) );
|
||||
|
||||
$this->cm = $manager_obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes backups and restores.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function processBackupTool ()
|
||||
{
|
||||
if ( isset($_POST['Perform']) ) {
|
||||
check_admin_referer('capsman-backup-tool');
|
||||
|
||||
global $wpdb;
|
||||
$wp_roles = $wpdb->prefix . 'user_roles';
|
||||
$cm_roles = 'capsman_backup';
|
||||
|
||||
switch ( $_POST['action'] ) {
|
||||
case 'backup':
|
||||
$roles = get_option($wp_roles);
|
||||
update_option($cm_roles, $roles);
|
||||
ak_admin_notify(__('New backup saved.', 'capsman-enhanced'));
|
||||
break;
|
||||
case 'restore':
|
||||
$roles = get_option($cm_roles);
|
||||
if ( $roles ) {
|
||||
update_option($wp_roles, $roles);
|
||||
ak_admin_notify(__('Roles and Capabilities restored from last backup.', 'capsman-enhanced'));
|
||||
} else {
|
||||
ak_admin_error(__('Restore failed. No backup found.', 'capsman-enhanced'));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets roles to WordPress defaults.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function backupToolReset ()
|
||||
{
|
||||
check_admin_referer('capsman-reset-defaults');
|
||||
|
||||
require_once(ABSPATH . 'wp-admin/includes/schema.php');
|
||||
|
||||
if ( ! function_exists('populate_roles') ) {
|
||||
ak_admin_error(__('Needed function to create default roles not found!', 'capsman-enhanced'));
|
||||
return;
|
||||
}
|
||||
|
||||
$roles = array_keys( ak_get_roles(true) );
|
||||
|
||||
foreach ( $roles as $role) {
|
||||
remove_role($role);
|
||||
}
|
||||
|
||||
populate_roles();
|
||||
$this->cm->setAdminCapability();
|
||||
|
||||
$msg = __('Roles and Capabilities reset to WordPress defaults', 'capsman-enhanced');
|
||||
|
||||
if ( function_exists( 'pp_populate_roles' ) ) {
|
||||
pp_populate_roles();
|
||||
} else {
|
||||
// force PP to repopulate roles
|
||||
$pp_ver = get_option( 'pp_c_version', true );
|
||||
if ( $pp_ver && is_array($pp_ver) ) {
|
||||
$pp_ver['version'] = ( preg_match( "/dev|alpha|beta|rc/i", $pp_ver['version'] ) ) ? '0.1-beta' : 0.1;
|
||||
} else {
|
||||
$pp_ver = array( 'version' => '0.1', 'db_version' => '1.0' );
|
||||
}
|
||||
|
||||
update_option( 'pp_c_version', $pp_ver );
|
||||
delete_option( 'ppperm_added_role_caps_10beta' );
|
||||
}
|
||||
|
||||
ak_admin_notify($msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* Capability Manager Backup Tool.
|
||||
* Provides backup and restore functionality to Capability Manager.
|
||||
*
|
||||
* @version $Rev: 198515 $
|
||||
* @author Jordi Canals
|
||||
* @copyright Copyright (C) 2009, 2010 Jordi Canals
|
||||
* @license GNU General Public License version 2
|
||||
* @link http://alkivia.org
|
||||
* @package Alkivia
|
||||
* @subpackage CapsMan
|
||||
*
|
||||
|
||||
Copyright 2009, 2010 Jordi Canals <devel@jcanals.cat>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
?>
|
||||
<div class="wrap">
|
||||
<div id="icon-capsman-admin" class="icon32"></div>
|
||||
<h2><?php _e('Backup Tool for Capability Manager', 'capsman-enhanced') ?></h2>
|
||||
|
||||
<form method="post" action="tools.php?page=<?php echo $this->ID ?>-tool">
|
||||
<?php wp_nonce_field('capsman-backup-tool'); ?>
|
||||
<fieldset>
|
||||
<table id="akmin">
|
||||
<tr>
|
||||
<td class="content">
|
||||
<dl>
|
||||
<dt><?php _e('Backup and Restore', 'capsman-enhanced'); ?></dt>
|
||||
<dd>
|
||||
<table width='100%' class="form-table">
|
||||
<tr>
|
||||
<th scope="row"><?php _e('Select action:', 'capsman-enhanced'); ?></th>
|
||||
<td>
|
||||
<select name="action">
|
||||
<option value="backup"> <?php _e('Backup roles and capabilities', 'capsman-enhanced'); ?> </option>
|
||||
<option value="restore"> <?php _e('Restore last saved backup', 'capsman-enhanced'); ?> </option>
|
||||
</select>
|
||||
<input type="submit" name="Perform" value="<?php _e('Do Action', 'capsman-enhanced') ?>" class="button-primary" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<dl>
|
||||
<dt><?php if ( defined('WPLANG') && WPLANG && ( 'en_EN' != WPLANG ) ) _e('Reset WordPress Defaults', 'capsman-enhanced'); else echo 'Reset Roles to WordPress Defaults';?></dt>
|
||||
<dd>
|
||||
<p style="text-align:center;"><strong><span style="color:red;"><?php _e('WARNING:', 'capsman-enhanced'); ?></span> <?php if ( defined('WPLANG') && WPLANG && ( 'en_EN' != WPLANG ) ) _e('Reseting default Roles and Capabilities will set them to the WordPress install defaults.', 'capsman-enhanced'); else echo 'This will delete and/or modify stored role definitions.'; ?></strong><br />
|
||||
<br />
|
||||
<?php
|
||||
_e('If you have installed any plugin that adds new roles or capabilities, these will be lost.', 'capsman-enhanced')?><br />
|
||||
<strong><?php if ( defined('WPLANG') && WPLANG && ( 'en_EN' != WPLANG ) ) _e('It is recommended to use this only as a last resource!'); else echo('It is recommended to use this only as a last resort!');?></strong></p>
|
||||
<p style="text-align:center;"><a class="ak-delete" title="<?php echo esc_attr(__('Reset Roles and Capabilities to WordPress defaults', 'capsman-enhanced')) ?>" href="<?php echo wp_nonce_url("tools.php?page={$this->ID}-tool&action=reset-defaults", 'capsman-reset-defaults'); ?>" onclick="if ( confirm('<?php echo esc_js(__("You are about to reset Roles and Capabilities to WordPress defaults.\n 'Cancel' to stop, 'OK' to reset.", 'capsman-enhanced')); ?>') ) { return true;}return false;"><?php _e('Reset to WordPress defaults', 'capsman-enhanced')?></a>
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<?php agp_admin_footer(); ?>
|
||||
|
||||
</td>
|
||||
|
||||
<td class="sidebar">
|
||||
<?php agp_admin_authoring($this->ID); ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
@@ -0,0 +1,365 @@
|
||||
<?php
|
||||
class CapsmanHandler
|
||||
{
|
||||
var $cm;
|
||||
|
||||
function __construct( $manager_obj ) {
|
||||
$this->cm = $manager_obj;
|
||||
}
|
||||
|
||||
function processAdminGeneral( $post ) {
|
||||
global $wp_roles;
|
||||
|
||||
// Create a new role.
|
||||
if ( ! empty($post['CreateRole']) ) {
|
||||
if ( $newrole = $this->createRole($post['create-name']) ) {
|
||||
ak_admin_notify(__('New role created.', 'capsman-enhanced'));
|
||||
$this->cm->current = $newrole;
|
||||
} else {
|
||||
if ( empty($post['create-name']) && ( ! defined('WPLANG') || ! WPLANG ) )
|
||||
ak_admin_error( 'Error: No role name specified.', 'capsman-enhanced' );
|
||||
else
|
||||
ak_admin_error(__('Error: Failed creating the new role.', 'capsman-enhanced'));
|
||||
}
|
||||
|
||||
// Copy current role to a new one.
|
||||
} elseif ( ! empty($post['CopyRole']) ) {
|
||||
$current = get_role($post['current']);
|
||||
if ( $newrole = $this->createRole($post['copy-name'], $current->capabilities) ) {
|
||||
ak_admin_notify(__('New role created.', 'capsman-enhanced'));
|
||||
$this->cm->current = $newrole;
|
||||
} else {
|
||||
if ( empty($post['copy-name']) && ( ! defined('WPLANG') || ! WPLANG ) )
|
||||
ak_admin_error( 'Error: No role name specified.', 'capsman-enhanced' );
|
||||
else
|
||||
ak_admin_error(__('Error: Failed creating the new role.', 'capsman-enhanced'));
|
||||
}
|
||||
|
||||
// Save role changes. Already saved at start with self::saveRoleCapabilities().
|
||||
} elseif ( ! empty($post['SaveRole']) ) {
|
||||
if ( MULTISITE ) {
|
||||
global $wp_roles;
|
||||
( method_exists( $wp_roles, 'for_site' ) ) ? $wp_roles->for_site() : $wp_roles->reinit();
|
||||
}
|
||||
|
||||
$this->saveRoleCapabilities($post['current'], $post['caps'], $post['level']);
|
||||
|
||||
if ( defined( 'PP_ACTIVE' ) ) { // log customized role caps for subsequent restoration
|
||||
// for bbPress < 2.2, need to log customization of roles following bbPress activation
|
||||
$plugins = ( function_exists( 'bbp_get_version' ) && version_compare( bbp_get_version(), '2.2', '<' ) ) ? array( 'bbpress.php' ) : array(); // back compat
|
||||
|
||||
if ( ! $customized_roles = get_option( 'pp_customized_roles' ) )
|
||||
$customized_roles = array();
|
||||
|
||||
$customized_roles[$post['role']] = (object) array( 'caps' => array_map( 'boolval', $post['caps'] ), 'plugins' => $plugins );
|
||||
update_option( 'pp_customized_roles', $customized_roles );
|
||||
|
||||
global $wpdb;
|
||||
$wpdb->query( "UPDATE $wpdb->options SET autoload = 'no' WHERE option_name = 'pp_customized_roles'" );
|
||||
}
|
||||
// Create New Capability and adds it to current role.
|
||||
} elseif ( ! empty($post['AddCap']) ) {
|
||||
if ( MULTISITE ) {
|
||||
global $wp_roles;
|
||||
( method_exists( $wp_roles, 'for_site' ) ) ? $wp_roles->for_site() : $wp_roles->reinit();
|
||||
}
|
||||
|
||||
$role = get_role($post['current']);
|
||||
$role->name = $post['current']; // bbPress workaround
|
||||
|
||||
if ( $newname = $this->createNewName($post['capability-name']) ) {
|
||||
$role->add_cap($newname['name']);
|
||||
$this->cm->message = __('New capability added to role.');
|
||||
|
||||
// for bbPress < 2.2, need to log customization of roles following bbPress activation
|
||||
$plugins = ( function_exists( 'bbp_get_version' ) && version_compare( bbp_get_version(), '2.2', '<' ) ) ? array( 'bbpress.php' ) : array(); // back compat
|
||||
|
||||
if ( ! $customized_roles = get_option( 'pp_customized_roles' ) )
|
||||
$customized_roles = array();
|
||||
|
||||
$customized_roles[$post['role']] = (object) array( 'caps' => array_merge( $role->capabilities, array( $newname['name'] => 1 ) ), 'plugins' => $plugins );
|
||||
update_option( 'pp_customized_roles', $customized_roles );
|
||||
|
||||
global $wpdb;
|
||||
$wpdb->query( "UPDATE $wpdb->options SET autoload = 'no' WHERE option_name = 'pp_customized_roles'" );
|
||||
} else {
|
||||
$this->cm->message = __('Incorrect capability name.');
|
||||
}
|
||||
|
||||
} elseif ( ! empty($post['update_filtered_types']) ) {
|
||||
if ( cme_update_pp_usage() ) {
|
||||
ak_admin_notify(__('Capability settings saved.', 'capsman-enhanced'));
|
||||
} else {
|
||||
ak_admin_error(__('Error saving capability settings.', 'capsman-enhanced'));
|
||||
}
|
||||
} else {
|
||||
// TODO: Implement exceptions. This must be a fatal error.
|
||||
ak_admin_error(__('Bad form received.', 'capsman-enhanced'));
|
||||
}
|
||||
|
||||
if ( ! empty($newrole) && defined('PP_ACTIVE') ) {
|
||||
if ( ( ! empty($post['CreateRole']) && ! empty( $_REQUEST['new_role_pp_only'] ) ) || ( ! empty($post['CopyRole']) && ! empty( $_REQUEST['copy_role_pp_only'] ) ) ) {
|
||||
$pp_only = (array) pp_get_option( 'supplemental_role_defs' );
|
||||
$pp_only[]= $newrole;
|
||||
pp_update_option( 'supplemental_role_defs', $pp_only );
|
||||
_cme_pp_default_pattern_role( $newrole );
|
||||
pp_refresh_options();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new role/capability name from user input name.
|
||||
* Name rules are:
|
||||
* - 2-40 charachers lenght.
|
||||
* - Only letters, digits, spaces and underscores.
|
||||
* - Must to start with a letter.
|
||||
*
|
||||
* @param string $name Name from user input.
|
||||
* @return array|false An array with the name and display_name, or false if not valid $name.
|
||||
*/
|
||||
private function createNewName( $name ) {
|
||||
// Allow max 40 characters, letters, digits and spaces
|
||||
$name = trim(substr($name, 0, 40));
|
||||
$pattern = '/^[a-zA-Z][a-zA-Z0-9 _]+$/';
|
||||
|
||||
if ( preg_match($pattern, $name) ) {
|
||||
$roles = ak_get_roles();
|
||||
|
||||
$name = strtolower($name);
|
||||
$name = str_replace(' ', '_', $name);
|
||||
if ( in_array($name, $roles) || array_key_exists($name, $this->cm->capabilities) ) {
|
||||
return false; // Already a role or capability with this name.
|
||||
}
|
||||
|
||||
$display = explode('_', $name);
|
||||
$display = array_map('ucfirst', $display);
|
||||
$display = implode(' ', $display);
|
||||
|
||||
return compact('name', 'display');
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new role.
|
||||
*
|
||||
* @param string $name Role name to create.
|
||||
* @param array $caps Role capabilities.
|
||||
* @return string|false Returns the name of the new role created or false if failed.
|
||||
*/
|
||||
private function createRole( $name, $caps = array() ) {
|
||||
if ( ! is_array($caps) )
|
||||
$caps = array();
|
||||
|
||||
$role = $this->createNewName($name);
|
||||
if ( ! is_array($role) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$new_role = add_role($role['name'], $role['display'], $caps);
|
||||
if ( is_object($new_role) ) {
|
||||
return $role['name'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves capability changes to roles.
|
||||
*
|
||||
* @param string $role_name Role name to change its capabilities
|
||||
* @param array $caps New capabilities for the role.
|
||||
* @return void
|
||||
*/
|
||||
private function saveRoleCapabilities( $role_name, $caps, $level ) {
|
||||
$this->cm->generateNames();
|
||||
$role = get_role($role_name);
|
||||
|
||||
// workaround to ensure db storage of customizations to bbp dynamic roles
|
||||
$role->name = $role_name;
|
||||
|
||||
$stored_role_caps = ( ! empty($role->capabilities) && is_array($role->capabilities) ) ? array_intersect( $role->capabilities, array(true, 1) ) : array();
|
||||
|
||||
$old_caps = array_intersect_key( $stored_role_caps, $this->cm->capabilities);
|
||||
$new_caps = ( is_array($caps) ) ? array_map('boolval', $caps) : array();
|
||||
$new_caps = array_merge($new_caps, ak_level2caps($level));
|
||||
|
||||
// Find caps to add and remove
|
||||
$add_caps = array_diff_key($new_caps, $old_caps);
|
||||
$del_caps = array_diff_key($old_caps, $new_caps);
|
||||
|
||||
$changed_caps = array();
|
||||
foreach( array_intersect_key( $new_caps, $old_caps ) as $cap_name => $cap_val ) {
|
||||
if ( $new_caps[$cap_name] != $old_caps[$cap_name] )
|
||||
$changed_caps[$cap_name] = $cap_val;
|
||||
}
|
||||
|
||||
$add_caps = array_merge( $add_caps, $changed_caps );
|
||||
|
||||
if ( ! $is_administrator = current_user_can('administrator') ) {
|
||||
unset($add_caps['manage_capabilities']);
|
||||
unset($del_caps['manage_capabilities']);
|
||||
}
|
||||
|
||||
if ( 'administrator' == $role_name && isset($del_caps['manage_capabilities']) ) {
|
||||
unset($del_caps['manage_capabilities']);
|
||||
ak_admin_error(__('You cannot remove Manage Capabilities from Administrators', 'capsman-enhanced'));
|
||||
}
|
||||
// Add new capabilities to role
|
||||
foreach ( $add_caps as $cap => $grant ) {
|
||||
if ( $is_administrator || current_user_can($cap) )
|
||||
$role->add_cap( $cap, $grant );
|
||||
}
|
||||
|
||||
// Remove capabilities from role
|
||||
foreach ( $del_caps as $cap => $grant) {
|
||||
if ( $is_administrator || current_user_can($cap) )
|
||||
$role->remove_cap($cap);
|
||||
}
|
||||
|
||||
if ( is_multisite() && is_super_admin() && ( 1 == get_current_blog_id() ) ) {
|
||||
if ( ! $autocreate_roles = get_site_option( 'cme_autocreate_roles' ) )
|
||||
$autocreate_roles = array();
|
||||
|
||||
$this_role_autocreate = ! empty($_REQUEST['cme_autocreate_role']);
|
||||
|
||||
if ( $this_role_autocreate && ! in_array( $role_name, $autocreate_roles ) ) {
|
||||
$autocreate_roles []= $role_name;
|
||||
update_site_option( 'cme_autocreate_roles', $autocreate_roles );
|
||||
}
|
||||
|
||||
if ( ! $this_role_autocreate && in_array( $role_name, $autocreate_roles ) ) {
|
||||
$autocreate_roles = array_diff( $autocreate_roles, array( $role_name ) );
|
||||
update_site_option( 'cme_autocreate_roles', $autocreate_roles );
|
||||
}
|
||||
|
||||
if ( ! empty($_REQUEST['cme_net_sync_role']) ) {
|
||||
// loop through all sites on network, creating or updating role def
|
||||
|
||||
global $wpdb, $wp_roles, $blog_id;
|
||||
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id" );
|
||||
$orig_blog_id = $blog_id;
|
||||
|
||||
$role_caption = $wp_roles->role_names[$role_name];
|
||||
|
||||
$new_caps = ( is_array($caps) ) ? array_map('boolval', $caps) : array();
|
||||
$new_caps = array_merge($new_caps, ak_level2caps($level) );
|
||||
|
||||
$admin_role = $wp_roles->get_role('administrator');
|
||||
$main_admin_caps = array_merge( $admin_role->capabilities, ak_level2caps(10) );
|
||||
|
||||
foreach ( $blog_ids as $id ) {
|
||||
if ( 1 == $id )
|
||||
continue;
|
||||
|
||||
switch_to_blog( $id );
|
||||
( method_exists( $wp_roles, 'for_site' ) ) ? $wp_roles->for_site() : $wp_roles->reinit();
|
||||
|
||||
if ( $blog_role = $wp_roles->get_role( $role_name ) ) {
|
||||
$stored_role_caps = ( ! empty($blog_role->capabilities) && is_array($blog_role->capabilities) ) ? array_intersect( $blog_role->capabilities, array(true, 1) ) : array();
|
||||
|
||||
$old_caps = array_intersect_key( $stored_role_caps, $this->cm->capabilities);
|
||||
|
||||
// Find caps to add and remove
|
||||
$add_caps = array_diff_key($new_caps, $old_caps);
|
||||
$del_caps = array_intersect_key( array_diff_key($old_caps, $new_caps), $main_admin_caps ); // don't mess with caps that are totally unused on main site
|
||||
|
||||
// Add new capabilities to role
|
||||
foreach ( $add_caps as $cap => $grant ) {
|
||||
$blog_role->add_cap( $cap, $grant );
|
||||
}
|
||||
|
||||
// Remove capabilities from role
|
||||
foreach ( $del_caps as $cap => $grant) {
|
||||
$blog_role->remove_cap($cap);
|
||||
}
|
||||
|
||||
} else {
|
||||
$wp_roles->add_role( $role_name, $role_caption, $new_caps );
|
||||
}
|
||||
|
||||
restore_current_blog();
|
||||
}
|
||||
|
||||
( method_exists( $wp_roles, 'for_site' ) ) ? $wp_roles->for_site() : $wp_roles->reinit();
|
||||
}
|
||||
} // endif multisite installation with super admin editing a main site role
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Deletes a role.
|
||||
* The role comes from the $_GET['role'] var and the nonce has already been checked.
|
||||
* Default WordPress role cannot be deleted and if trying to do it, throws an error.
|
||||
* Users with the deleted role, are moved to the WordPress default role.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function adminDeleteRole ()
|
||||
{
|
||||
global $wpdb, $wp_roles;
|
||||
|
||||
check_admin_referer('delete-role_' . $_GET['role']);
|
||||
|
||||
$this->cm->current = $_GET['role'];
|
||||
$default = get_option('default_role');
|
||||
if ( $default == $this->cm->current ) {
|
||||
ak_admin_error(sprintf(__('Cannot delete default role. You <a href="%s">have to change it first</a>.', 'capsman-enhanced'), 'options-general.php'));
|
||||
return;
|
||||
}
|
||||
|
||||
$query = "SELECT ID FROM {$wpdb->usermeta} INNER JOIN {$wpdb->users} "
|
||||
. "ON {$wpdb->usermeta}.user_id = {$wpdb->users}.ID "
|
||||
. "WHERE meta_key='{$wpdb->prefix}capabilities' AND meta_value LIKE '%{$this->cm->current}%';";
|
||||
|
||||
$users = $wpdb->get_results($query);
|
||||
|
||||
// Array of all roles except the one being deleted, for use below
|
||||
$role_names = array_diff_key( array_keys( $wp_roles->role_names ), array( $this->cm->current => true ) );
|
||||
|
||||
$count = 0;
|
||||
foreach ( $users as $u ) {
|
||||
$skip_role_set = false;
|
||||
|
||||
$user = new WP_User($u->ID);
|
||||
if ( $user->has_cap($this->cm->current) ) { // Check again the user has the deleting role
|
||||
|
||||
// Role may have been assigned supplementally. Don't move a user to default role if they still have one or more roles following the deletion.
|
||||
foreach( $role_names as $_role_name ) {
|
||||
if ( $user->has_cap($_role_name) ) {
|
||||
$skip_role_set = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $skip_role_set ) {
|
||||
$user->set_role($default);
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
remove_role($this->cm->current);
|
||||
unset($this->cm->roles[$this->cm->current]);
|
||||
|
||||
if ( $customized_roles = get_option( 'pp_customized_roles' ) ) {
|
||||
if ( isset( $customized_roles[$this->cm->current] ) ) {
|
||||
unset( $customized_roles[$this->cm->current] );
|
||||
update_option( 'pp_customized_roles', $customized_roles );
|
||||
}
|
||||
}
|
||||
|
||||
ak_admin_notify(sprintf(__('Role has been deleted. %1$d users moved to default role %2$s.', 'capsman-enhanced'), $count, $this->cm->roles[$default]));
|
||||
$this->cm->current = $default;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists('boolval') ) {
|
||||
function boolval( $val ) {
|
||||
return (bool) $val;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,478 @@
|
||||
<?php
|
||||
/**
|
||||
* Capability Manager.
|
||||
* Plugin to create and manage roles and capabilities.
|
||||
*
|
||||
* @version $Rev: 199485 $
|
||||
* @author Jordi Canals
|
||||
* @copyright Copyright (C) 2009, 2010 Jordi Canals; Copyright (C) 2012-2014 Kevin Behrens
|
||||
* @license GNU General Public License version 2
|
||||
* @link http://agapetry.net
|
||||
*
|
||||
|
||||
Copyright 2009, 2010 Jordi Canals <devel@jcanals.cat>
|
||||
Modifications Copyright 2012-2015 Kevin Behrens <kevin@agapetry.net>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
include_once ( AK_CLASSES . '/abstract/plugin.php' );
|
||||
|
||||
add_action( 'init', 'cme_update_pp_usage' ); // update early so resulting post type cap changes are applied for this request's UI construction
|
||||
|
||||
function cme_update_pp_usage() {
|
||||
if ( defined( 'PP_ACTIVE' ) && ( ! empty($_REQUEST['update_filtered_types']) || ! empty($_REQUEST['SaveRole']) ) ) {
|
||||
require_once( dirname(__FILE__).'/pp-handler.php' );
|
||||
return _cme_update_pp_usage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Class cmanCapsManager.
|
||||
* Sets the main environment for all Capability Manager components.
|
||||
*
|
||||
* @author Jordi Canals, Kevin Behrens
|
||||
* @link http://agapetry.net
|
||||
*/
|
||||
class CapabilityManager extends akPluginAbstract
|
||||
{
|
||||
/**
|
||||
* Array with all capabilities to be managed. (Depends on user caps).
|
||||
* The array keys are the capability, the value is its screen name.
|
||||
* @var array
|
||||
*/
|
||||
var $capabilities = array();
|
||||
|
||||
/**
|
||||
* Array with roles that can be managed. (Depends on user roles).
|
||||
* The array keys are the role name, the value is its translated name.
|
||||
* @var array
|
||||
*/
|
||||
var $roles = array();
|
||||
|
||||
/**
|
||||
* Current role we are managing
|
||||
* @var string
|
||||
*/
|
||||
var $current;
|
||||
|
||||
/**
|
||||
* Maximum level current manager can assign to a user.
|
||||
* @var int
|
||||
*/
|
||||
private $max_level;
|
||||
|
||||
private $log_db_role_objects = array();
|
||||
|
||||
var $message;
|
||||
|
||||
function __construct( $mod_file, $ID = '' ) {
|
||||
$this->ID = 'capsman';
|
||||
|
||||
parent::__construct( $mod_file, $ID );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates some filters at module load time.
|
||||
*
|
||||
* @see akPluginAbstract#moduleLoad()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function moduleLoad ()
|
||||
{
|
||||
// Only roles that a user can administer can be assigned to others.
|
||||
add_filter('editable_roles', array($this, 'filterEditRoles'));
|
||||
|
||||
// Users with roles that cannot be managed, are not allowed to be edited.
|
||||
add_filter('map_meta_cap', array(&$this, 'filterUserEdit'), 10, 4);
|
||||
|
||||
// ensure storage, retrieval of db-stored customizations to bbPress dynamic roles
|
||||
global $wpdb;
|
||||
$role_key = $wpdb->prefix . 'user_roles';
|
||||
add_filter( 'option_' . $role_key, array( &$this, 'log_db_roles' ), 0 );
|
||||
add_filter( 'option_' . $role_key, array( &$this, 'reinstate_db_roles' ), 50 );
|
||||
|
||||
add_filter( 'plugins_loaded', array( &$this, 'processRoleUpdate' ) );
|
||||
}
|
||||
|
||||
function log_db_roles( $passthru_roles ) {
|
||||
global $wp_roles;
|
||||
|
||||
if ( isset($wp_roles) )
|
||||
$this->log_db_role_objects = $wp_roles->role_objects;
|
||||
|
||||
return $passthru_roles;
|
||||
}
|
||||
|
||||
// note: this is only applied when accessing the cme role edit form
|
||||
function reinstate_db_roles( $passthru_roles = array() ) {
|
||||
global $wp_roles;
|
||||
|
||||
if ( $this->log_db_role_objects ) {
|
||||
$intersect = array_intersect_key( $wp_roles->role_objects, $this->log_db_role_objects );
|
||||
foreach( array_keys( $intersect ) as $key ) {
|
||||
if ( ! empty( $this->log_db_role_objects[$key]->capabilities ) )
|
||||
$wp_roles->role_objects[$key]->capabilities = $this->log_db_role_objects[$key]->capabilities;
|
||||
}
|
||||
}
|
||||
|
||||
return $passthru_roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates the plugin and sets the new capability 'Manage Capabilities'
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function pluginActivate ()
|
||||
{
|
||||
$this->setAdminCapability();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates Capability Manager to a new version
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function pluginUpdate ( $version )
|
||||
{
|
||||
$backup = get_option($this->ID . '_backup');
|
||||
if ( false === $backup ) { // No previous backup found. Save it!
|
||||
global $wpdb;
|
||||
$roles = get_option($wpdb->prefix . 'user_roles');
|
||||
update_option($this->ID . '_backup', $roles);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds admin panel menus. (At plugins loading time. This is before plugins_loaded).
|
||||
* User needs to have 'manage_capabilities' to access this menus.
|
||||
* This is set as an action in the parent class constructor.
|
||||
*
|
||||
* @hook action admin_menu
|
||||
* @return void
|
||||
*/
|
||||
public function adminMenus ()
|
||||
{
|
||||
// First we check if user is administrator and can 'manage_capabilities'.
|
||||
if ( current_user_can('administrator') && ! current_user_can('manage_capabilities') ) {
|
||||
$this->setAdminCapability();
|
||||
}
|
||||
|
||||
add_action( 'admin_menu', array( &$this, 'cme_menu' ), 20 );
|
||||
}
|
||||
|
||||
public function cme_menu() {
|
||||
$cap_name = ( is_super_admin() ) ? 'manage_capabilities' : 'restore_roles';
|
||||
add_management_page(__('Capability Manager', 'capsman-enhanced'), __('Capability Manager', 'capsman-enhanced'), $cap_name, $this->ID . '-tool', array($this, 'backupTool'));
|
||||
|
||||
if ( did_action( 'pp_admin_menu' ) ) { // Put Capabilities link on Permissions menu if Press Permit is active and user has access to it
|
||||
global $pp_admin;
|
||||
$menu_caption = ( defined('WPLANG') && WPLANG && ( 'en_EN' != WPLANG ) ) ? __('Capabilities', 'capsman-enhanced') : 'Role Capabilities';
|
||||
add_submenu_page( $pp_admin->get_menu('options'), __('Capability Manager', 'capsman-enhanced'), $menu_caption, 'manage_capabilities', $this->ID, array($this, 'generalManager') );
|
||||
} else {
|
||||
add_users_page( __('Capability Manager', 'capsman-enhanced'), __('Capabilities', 'capsman-enhanced'), 'manage_capabilities', $this->ID, array($this, 'generalManager'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the 'manage_capabilities' cap to the administrator role.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setAdminCapability ()
|
||||
{
|
||||
$admin = get_role('administrator');
|
||||
$admin->add_cap('manage_capabilities');
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters roles that can be shown in roles list.
|
||||
* This is mainly used to prevent an user admin to create other users with
|
||||
* higher capabilities.
|
||||
*
|
||||
* @hook 'editable_roles' filter.
|
||||
*
|
||||
* @param $roles List of roles to check.
|
||||
* @return array Restircted roles list
|
||||
*/
|
||||
function filterEditRoles ( $roles )
|
||||
{
|
||||
$this->generateNames();
|
||||
$valid = array_keys($this->roles);
|
||||
|
||||
foreach ( $roles as $role => $caps ) {
|
||||
if ( ! in_array($role, $valid) ) {
|
||||
unset($roles[$role]);
|
||||
}
|
||||
}
|
||||
|
||||
return $roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a user can be edited or not by current administrator.
|
||||
* Returns array('do_not_allow') if user cannot be edited.
|
||||
*
|
||||
* @hook 'map_meta_cap' filter
|
||||
*
|
||||
* @param array $caps Current user capabilities
|
||||
* @param string $cap Capability to check
|
||||
* @param int $user_id Current user ID
|
||||
* @param array $args For our purpose, we receive edited user id at $args[0]
|
||||
* @return array Allowed capabilities.
|
||||
*/
|
||||
function filterUserEdit ( $caps, $cap, $user_id, $args )
|
||||
{
|
||||
if ( ! in_array( $cap, array( 'edit_user', 'delete_user', 'promote_user', 'remove_user' ) ) || ( ! isset($args[0]) ) || $user_id == (int) $args[0] ) {
|
||||
return $caps;
|
||||
}
|
||||
|
||||
$user = new WP_User( (int) $args[0] );
|
||||
|
||||
$this->generateNames();
|
||||
|
||||
if ( defined( 'CME_LEGACY_USER_EDIT_FILTER' ) && CME_LEGACY_USER_EDIT_FILTER ) {
|
||||
$valid = array_keys($this->roles);
|
||||
|
||||
foreach ( $user->roles as $role ) {
|
||||
if ( ! in_array($role, $valid) ) {
|
||||
$caps = array('do_not_allow');
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
global $wp_roles;
|
||||
|
||||
foreach ( $user->roles as $role ) {
|
||||
$r = get_role( $role );
|
||||
$level = ak_caps2level($r->capabilities);
|
||||
|
||||
if ( ( ! $level ) && ( 'administrator' == $role ) )
|
||||
$level = 10;
|
||||
|
||||
if ( $level > $this->max_level ) {
|
||||
$caps = array('do_not_allow');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $caps;
|
||||
}
|
||||
|
||||
function processRoleUpdate() {
|
||||
$this->current = get_option('default_role'); // By default we manage the default role.
|
||||
|
||||
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && ( ! empty($_REQUEST['SaveRole']) || ! empty($_REQUEST['AddCap']) ) ) {
|
||||
if ( ! current_user_can('manage_capabilities') && ! current_user_can('administrator') ) {
|
||||
// TODO: Implement exceptions.
|
||||
wp_die('<strong>' .__('What do you think you\'re doing?!?', 'capsman-enhanced') . '</strong>');
|
||||
}
|
||||
|
||||
//$this->current = get_option('default_role'); // By default we manage the default role.
|
||||
|
||||
check_admin_referer('capsman-general-manager');
|
||||
$this->processAdminGeneral();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manages global settings admin.
|
||||
*
|
||||
* @hook add_submenu_page
|
||||
* @return void
|
||||
*/
|
||||
function generalManager () {
|
||||
if ( ! current_user_can('manage_capabilities') && ! current_user_can('administrator') ) {
|
||||
// TODO: Implement exceptions.
|
||||
wp_die('<strong>' .__('What do you think you\'re doing?!?', 'capsman-enhanced') . '</strong>');
|
||||
}
|
||||
|
||||
if ( 'POST' == $_SERVER['REQUEST_METHOD'] ) {
|
||||
if ( empty($_REQUEST['SaveRole']) && empty($_REQUEST['AddCap']) ) {
|
||||
check_admin_referer('capsman-general-manager');
|
||||
$this->processAdminGeneral();
|
||||
} elseif ( ! empty($_REQUEST['SaveRole']) ) {
|
||||
ak_admin_notify( $this->message ); // moved update operation to earlier action to avoid UI refresh issues. But outputting notification there breaks styling.
|
||||
} elseif ( ! empty($_REQUEST['AddCap']) ) {
|
||||
ak_admin_notify( $this->message );
|
||||
}
|
||||
}
|
||||
|
||||
$this->generateNames();
|
||||
$roles = array_keys($this->roles);
|
||||
|
||||
if ( isset($_GET['action']) && 'delete' == $_GET['action']) {
|
||||
require_once( dirname(__FILE__).'/handler.php' );
|
||||
$capsman_modify = new CapsmanHandler( $this );
|
||||
$capsman_modify->adminDeleteRole();
|
||||
}
|
||||
|
||||
if ( ! in_array($this->current, $roles) ) { // Current role has been deleted.
|
||||
$this->current = array_shift($roles);
|
||||
}
|
||||
|
||||
include ( AK_CMAN_LIB . '/admin.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes and saves the changes in the general capabilities form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function processAdminGeneral ()
|
||||
{
|
||||
if (! isset($_POST['action']) || 'update' != $_POST['action'] ) {
|
||||
// TODO: Implement exceptions. This must be a fatal error.
|
||||
ak_admin_error(__('Bad form Received', 'capsman-enhanced'));
|
||||
return;
|
||||
}
|
||||
|
||||
$post = stripslashes_deep($_POST);
|
||||
if ( empty ($post['caps']) ) {
|
||||
$post['caps'] = array();
|
||||
}
|
||||
|
||||
$this->current = $post['current'];
|
||||
|
||||
// Select a new role.
|
||||
if ( ! empty($post['LoadRole']) ) {
|
||||
$this->current = $post['role'];
|
||||
} else {
|
||||
require_once( dirname(__FILE__).'/handler.php' );
|
||||
$capsman_modify = new CapsmanHandler( $this );
|
||||
$capsman_modify->processAdminGeneral( $post );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function to create names.
|
||||
* Replaces underscores by spaces and uppercases the first letter.
|
||||
*
|
||||
* @access private
|
||||
* @param string $cap Capability name.
|
||||
* @return string The generated name.
|
||||
*/
|
||||
function _capNamesCB ( $cap )
|
||||
{
|
||||
$cap = str_replace('_', ' ', $cap);
|
||||
//$cap = ucfirst($cap);
|
||||
|
||||
return $cap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an array with the system capability names.
|
||||
* The key is the capability and the value the created screen name.
|
||||
*
|
||||
* @uses self::_capNamesCB()
|
||||
* @return void
|
||||
*/
|
||||
function generateSysNames ()
|
||||
{
|
||||
$this->max_level = 10;
|
||||
$this->roles = ak_get_roles(true);
|
||||
$caps = array();
|
||||
|
||||
foreach ( array_keys($this->roles) as $role ) {
|
||||
$role_caps = get_role($role);
|
||||
$caps = array_merge( $caps, (array) $role_caps->capabilities ); // user reported PHP 5.3.3 error without array cast
|
||||
}
|
||||
|
||||
$keys = array_keys($caps);
|
||||
$names = array_map(array($this, '_capNamesCB'), $keys);
|
||||
$this->capabilities = array_combine($keys, $names);
|
||||
|
||||
asort($this->capabilities);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an array with the user capability names.
|
||||
* If user has 'administrator' role, system roles are generated.
|
||||
* The key is the capability and the value the created screen name.
|
||||
* A user cannot manage more capabilities that has himself (Except for administrators).
|
||||
*
|
||||
* @uses self::_capNamesCB()
|
||||
* @return void
|
||||
*/
|
||||
function generateNames ()
|
||||
{
|
||||
if ( current_user_can('administrator') || ( is_multisite() && is_super_admin() ) ) {
|
||||
$this->generateSysNames();
|
||||
} else {
|
||||
global $user_ID;
|
||||
$user = new WP_User($user_ID);
|
||||
$this->max_level = ak_caps2level($user->allcaps);
|
||||
|
||||
$keys = array_keys($user->allcaps);
|
||||
$names = array_map(array($this, '_capNamesCB'), $keys);
|
||||
|
||||
$this->capabilities = ( $keys ) ? array_combine($keys, $names) : array();
|
||||
|
||||
$roles = ak_get_roles(true);
|
||||
unset($roles['administrator']);
|
||||
|
||||
if ( ( defined( 'CME_LEGACY_USER_EDIT_FILTER' ) && CME_LEGACY_USER_EDIT_FILTER ) || ( ! empty( $_REQUEST['page'] ) && 'capsman' == $_REQUEST['page'] ) ) {
|
||||
foreach ( $user->roles as $role ) { // Unset the roles from capability list.
|
||||
unset ( $this->capabilities[$role] );
|
||||
unset ( $roles[$role]); // User cannot manage his roles.
|
||||
}
|
||||
}
|
||||
|
||||
asort($this->capabilities);
|
||||
|
||||
foreach ( array_keys($roles) as $role ) {
|
||||
$r = get_role($role);
|
||||
$level = ak_caps2level($r->capabilities);
|
||||
|
||||
if ( $level > $this->max_level ) {
|
||||
unset($roles[$role]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->roles = $roles;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manages backup, restore and resset roles and capabilities
|
||||
*
|
||||
* @hook add_management_page
|
||||
* @return void
|
||||
*/
|
||||
function backupTool ()
|
||||
{
|
||||
if ( ! current_user_can('restore_roles') && ! is_super_admin() ) {
|
||||
// TODO: Implement exceptions.
|
||||
wp_die('<strong>' .__('What do you think you\'re doing?!?', 'capsman-enhanced') . '</strong>');
|
||||
}
|
||||
|
||||
if ( 'POST' == $_SERVER['REQUEST_METHOD'] ) {
|
||||
require_once( dirname(__FILE__).'/backup-handler.php' );
|
||||
$cme_backup_handler = new Capsman_BackupHandler( $this );
|
||||
$cme_backup_handler->processBackupTool();
|
||||
}
|
||||
|
||||
if ( isset($_GET['action']) && 'reset-defaults' == $_GET['action']) {
|
||||
require_once( dirname(__FILE__).'/backup-handler.php' );
|
||||
$cme_backup_handler = new Capsman_BackupHandler( $this );
|
||||
$cme_backup_handler->backupToolReset();
|
||||
}
|
||||
|
||||
include ( AK_CMAN_LIB . '/backup.php' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
add_action( 'wpmu_new_blog', '_cme_new_blog' );
|
||||
function _cme_new_blog( $new_blog_id ) {
|
||||
if ( $autocreate_roles = get_site_option( 'cme_autocreate_roles' ) ) {
|
||||
global $wp_roles, $blog_id;
|
||||
|
||||
$restore_blog_id = $blog_id;
|
||||
|
||||
switch_to_blog( 1 );
|
||||
( method_exists( $wp_roles, 'for_site' ) ) ? $wp_roles->for_site() : $wp_roles->reinit();
|
||||
|
||||
$main_site_caps = array();
|
||||
$role_captions = array();
|
||||
|
||||
$admin_role = $wp_roles->get_role('administrator');
|
||||
$main_admin_caps = $admin_role->capabilities;
|
||||
|
||||
if ( defined('PP_ACTIVE') )
|
||||
$main_pp_only = (array) pp_get_option( 'supplemental_role_defs' );
|
||||
//$pp_only[]= $newrole;
|
||||
|
||||
foreach( $autocreate_roles as $role_name ) {
|
||||
if ( $role = get_role( $role_name ) ) {
|
||||
$main_site_caps[$role_name] = $role->capabilities;
|
||||
$role_captions[$role_name] = $wp_roles->role_names[$role_name];
|
||||
}
|
||||
}
|
||||
|
||||
switch_to_blog($new_blog_id);
|
||||
( method_exists( $wp_roles, 'for_site' ) ) ? $wp_roles->for_site() : $wp_roles->reinit();
|
||||
|
||||
if ( defined('PP_ACTIVE') ) {
|
||||
pp_refresh_options();
|
||||
$blog_pp_only = (array) pp_get_option( 'supplemental_role_defs' );
|
||||
}
|
||||
|
||||
foreach( $main_site_caps as $role_name => $caps ) {
|
||||
if ( $blog_role = $wp_roles->get_role( $role_name ) ) {
|
||||
$stored_role_caps = ( ! empty($blog_role->capabilities) && is_array($blog_role->capabilities) ) ? array_intersect( $blog_role->capabilities, array(true, 1) ) : array();
|
||||
|
||||
// Find caps to add and remove
|
||||
$add_caps = array_diff_key($caps, $stored_role_caps);
|
||||
$del_caps = array_intersect_key( array_diff_key($stored_role_caps, $caps), $main_admin_caps ); // don't mess with caps that are totally unused on main site
|
||||
|
||||
// Add new capabilities to role
|
||||
foreach ( $add_caps as $cap => $grant )
|
||||
$blog_role->add_cap($cap);
|
||||
|
||||
// Remove capabilities from role
|
||||
foreach ( $del_caps as $cap => $grant)
|
||||
$blog_role->remove_cap($cap);
|
||||
} else {
|
||||
$wp_roles->add_role( $role_name, $role_captions[$role_name], $caps );
|
||||
}
|
||||
|
||||
if ( defined('PP_ACTIVE') ) {
|
||||
if ( in_array( $role_name, $main_pp_only ) ) {
|
||||
_cme_pp_default_pattern_role( $role_name );
|
||||
$blog_pp_only []= $role_name;
|
||||
} else
|
||||
array_diff( $blog_pp_only, array( $role_name ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( defined('PP_ACTIVE') )
|
||||
pp_update_option( 'supplemental_role_defs', $blog_pp_only );
|
||||
|
||||
switch_to_blog($restore_blog_id);
|
||||
( method_exists( $wp_roles, 'for_site' ) ) ? $wp_roles->for_site() : $wp_roles->reinit();
|
||||
|
||||
if ( defined('PP_ACTIVE') )
|
||||
pp_refresh_options();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
function _cme_update_pp_usage() {
|
||||
static $updated;
|
||||
if ( ! empty($updated) ) { return true; }
|
||||
|
||||
if ( ! current_user_can( 'pp_manage_settings' ) )
|
||||
return false;
|
||||
|
||||
if ( ! empty( $_REQUEST['update_filtered_types']) ) {
|
||||
// update Press Permit "Filtered Post Types". This determines whether type-specific capability definitions are forced
|
||||
$options = array( 'enabled_post_types', 'enabled_taxonomies' );
|
||||
|
||||
foreach( $options as $option_basename ) {
|
||||
if ( ! isset( $_POST["{$option_basename}-options"] ) )
|
||||
continue;
|
||||
|
||||
$unselected = array();
|
||||
$value = array();
|
||||
|
||||
foreach( $_POST["{$option_basename}-options"] as $key ) {
|
||||
if ( empty( $_POST["{$option_basename}-$key"] ) )
|
||||
$unselected[$key] = true;
|
||||
else
|
||||
$value[$key] = true;
|
||||
}
|
||||
|
||||
if ( $current = pp_get_option( $option_basename ) ) {
|
||||
if ( $current = array_diff_key( $current, $unselected ) )
|
||||
$value = array_merge( $current, $value ); // retain setting for any types which were previously enabled for filtering but are currently not registered
|
||||
}
|
||||
|
||||
$value = stripslashes_deep($value);
|
||||
pp_update_option( $option_basename, $value );
|
||||
|
||||
$updated = true;
|
||||
}
|
||||
|
||||
if ( pp_wp_ver( '3.5' ) ) {
|
||||
pp_update_option( 'define_create_posts_cap', ! empty($_REQUEST['pp_define_create_posts_cap']) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $_REQUEST['SaveRole']) ) {
|
||||
if ( ! empty( $_REQUEST['role'] ) ) {
|
||||
$pp_only = (array) pp_get_option( 'supplemental_role_defs' );
|
||||
|
||||
if ( empty($_REQUEST['pp_only_role']) )
|
||||
$pp_only = array_diff( $pp_only, array($_REQUEST['role']) );
|
||||
else
|
||||
$pp_only[]= $_REQUEST['role'];
|
||||
|
||||
pp_update_option( 'supplemental_role_defs', array_unique($pp_only) );
|
||||
_cme_pp_default_pattern_role( $_REQUEST['role'] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $updated ) {
|
||||
pp_refresh_options();
|
||||
}
|
||||
|
||||
return $updated;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
class Capsman_PP_UI {
|
||||
|
||||
function __construct() {
|
||||
|
||||
}
|
||||
|
||||
function get_metagroup_caps( $default ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( defined( 'PPC_VERSION' ) )
|
||||
$pp_supplemental_roles = $wpdb->get_col( "SELECT role_name FROM $wpdb->ppc_roles AS r INNER JOIN $wpdb->pp_groups AS g ON g.ID = r.agent_id AND r.agent_type = 'pp_group' WHERE g.metagroup_type = 'wp_role' AND g.metagroup_id = '$default'" );
|
||||
else
|
||||
$pp_supplemental_roles = $wpdb->get_col( "SELECT role_name FROM $wpdb->pp_roles AS r INNER JOIN $wpdb->pp_groups AS g ON g.ID = r.group_id AND r.group_type = 'pp_group' AND r.scope = 'site' WHERE g.metagroup_type = 'wp_role' AND g.metagroup_id = '$default'" );
|
||||
|
||||
$pp_filtered_types = pp_get_enabled_types('post');
|
||||
$pp_metagroup_caps = array();
|
||||
$pp_cap_caster = pp_init_cap_caster();
|
||||
|
||||
foreach( $pp_supplemental_roles as $_role_name ) {
|
||||
$role_specs = explode( ':', $_role_name );
|
||||
if ( empty($role_specs[2]) || ! in_array( $role_specs[2], $pp_filtered_types ) )
|
||||
continue;
|
||||
|
||||
// add all type-specific caps whose base property cap is included in this pattern role
|
||||
// i.e. If 'edit_posts' is in the pattern role, grant $type_obj->cap->edit_posts
|
||||
$pp_metagroup_caps = array_merge( $pp_metagroup_caps, array_fill_keys( $pp_cap_caster->get_typecast_caps( $_role_name, 'site' ), true ) );
|
||||
}
|
||||
|
||||
return $pp_metagroup_caps;
|
||||
}
|
||||
|
||||
function show_capability_hints( $default ) {
|
||||
if ( pp_get_option('display_hints') ) {
|
||||
$cme_id = 'capsman';
|
||||
|
||||
echo '<ul class="ul-disc" style="margin-top:10px">';
|
||||
|
||||
if ( defined( 'PPCE_VERSION' ) || ! defined( 'PPC_VERSION' ) || in_array( $default, array( 'subscriber', 'contributor', 'author', 'editor' ) ) ) {
|
||||
echo '<li>';
|
||||
if ( defined( 'PPCE_VERSION' ) || ! defined( 'PPC_VERSION' ) ) {
|
||||
if ( pp_get_option( 'advanced_options' ) )
|
||||
$parenthetical = ' (' . sprintf( __( 'see %1$sRole Usage%2$s: "Pattern Roles"', 'capsman-enhanced' ), "<a href='" . admin_url('admin.php?page=pp-role-usage') . "'>", '</a>' ) . ')';
|
||||
else
|
||||
$parenthetical = ' (' . sprintf( __( 'activate %1$sAdvanced settings%2$s, see Role Usage', 'capsman-enhanced' ), "<a href='" . admin_url('admin.php?page=pp-settings&pp_tab=advanced') . "'>", '</a>' ). ')';
|
||||
} else
|
||||
$parenthetical = '';
|
||||
|
||||
if ( defined( 'PPC_VERSION' ) )
|
||||
printf( __( '"Posts" capabilities selected here also define type-specific role assignment for Permission Groups%s.', $cme_id ), $parenthetical ) ;
|
||||
else
|
||||
printf( __( '"Posts" capabilities selected here also define type-specific role assignment for Permit Groups%s.', $cme_id ), $parenthetical ) ;
|
||||
|
||||
echo '</li>';
|
||||
}
|
||||
|
||||
$status_hint = '';
|
||||
if ( defined( 'PPC_VERSION' ) )
|
||||
if ( defined( 'PPS_VERSION' ) )
|
||||
$status_hint = sprintf( __( 'Capabilities for custom statuses can be manually added here (see Post Statuses > Status > Capability Mapping for applicable names). However, it is usually more convenient to use Permission Groups to assign a supplemental status-specific role.', $cme_id ), "<a href='" . admin_url('?page=pp-role-usage') . "'>", '</a>' ) ;
|
||||
elseif ( pp_get_option( 'display_extension_hints' ) )
|
||||
$status_hint = sprintf( __( 'Capabilities for custom statuses can be manually added here. Or activate the PP Custom Post Statuses extension to assign status-specific supplemental roles.', $cme_id ), "<a href='" . admin_url('?page=pp-role-usage') . "'>", '</a>' ) ;
|
||||
|
||||
elseif ( defined( 'PP_VERSION' ) )
|
||||
$status_hint = sprintf( __( 'Capabilities for custom statuses can be manually added to a role here (see Conditions > Status > Capability Mapping for applicable names). However, it is usually more convenient to use Permit Groups to assign a supplemental status-specific role.', $cme_id ), "<a href='" . admin_url('?page=pp-role-usage') . "'>", '</a>' ) ;
|
||||
|
||||
if ( $status_hint )
|
||||
echo "<li>$status_hint</li>";
|
||||
|
||||
echo '</ul>';
|
||||
}
|
||||
}
|
||||
|
||||
function pp_only_roles_ui( $default ) {
|
||||
$support_pp_only_roles = defined('PPC_VERSION') || version_compare( PP_VERSION, '1.0-beta1.4', '>=');
|
||||
?>
|
||||
|
||||
<?php if ( $support_pp_only_roles && ! in_array( $default, array( /*'subscriber', 'contributor', 'author', 'editor',*/ 'administrator' ) ) ) : ?>
|
||||
<div style="float:right">
|
||||
<?php
|
||||
pp_refresh_options();
|
||||
$pp_only = (array) pp_get_option( 'supplemental_role_defs' );
|
||||
$checked = ( in_array( $default, $pp_only ) ) ? 'checked="checked"': '';
|
||||
?>
|
||||
<label for="pp_only_role" title="<?php _e('Make role available for supplemental assignment to Permission Groups only', 'capsman-enhanced');?>"><input type="checkbox" name="pp_only_role" id="pp_only_role" value="1" <?php echo $checked;?>> <?php _e('hidden role', 'capsman-enhanced'); ?> </label>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
return $support_pp_only_roles;
|
||||
}
|
||||
|
||||
function pp_types_ui( $defined ) {
|
||||
if ( current_user_can( 'pp_manage_settings' ) ) :?>
|
||||
<dl>
|
||||
<dt><?php _e('Force Type-Specific Capabilities', 'capsman-enhanced'); ?></dt>
|
||||
<dd style="text-align:center;">
|
||||
<?php
|
||||
$caption = __( 'Force unique capability names for:', 'capsman-enhanced' );
|
||||
echo "<p>$caption</p>";
|
||||
|
||||
if ( pp_get_option( 'display_hints' ) ) :?>
|
||||
<div class="cme-subtext" style="margin-top:0">
|
||||
<?php _e( '(PP Filtered Post Types, Taxonomies)', 'capsman-enhanced' );?>
|
||||
</div>
|
||||
<?php endif;
|
||||
|
||||
echo "<table style='width:100%'><tr>";
|
||||
|
||||
$unfiltered['type'] = apply_filters( 'pp_unfiltered_post_types', array('forum','topic','reply') ); // bbPress' dynamic role def requires additional code to enforce stored caps
|
||||
$unfiltered['taxonomy'] = apply_filters( 'pp_unfiltered_taxonomies', array( 'post_status', 'topic-tag' ) ); // avoid confusion with Edit Flow administrative taxonomy
|
||||
$hidden['type'] = apply_filters( 'pp_hidden_post_types', array() );
|
||||
$hidden['taxonomy'] = apply_filters( 'pp_hidden_taxonomies', array() );
|
||||
|
||||
foreach( array_keys($defined) as $item_type ) {
|
||||
echo '<td style="width:50%">';
|
||||
$option_name = ( 'taxonomy' == $item_type ) ? 'enabled_taxonomies' : 'enabled_post_types';
|
||||
|
||||
$enabled = pp_get_option( $option_name );
|
||||
|
||||
foreach( $defined[$item_type] as $key => $type_obj ) {
|
||||
if ( ! $key )
|
||||
continue;
|
||||
|
||||
if ( in_array( $key, $unfiltered[$item_type] ) )
|
||||
continue;
|
||||
|
||||
$id = "$option_name-" . $key;
|
||||
?>
|
||||
<div style="text-align:left">
|
||||
<?php if ( ! empty( $hidden[$item_type][$key] ) ) :?>
|
||||
<input name="<?php echo($id);?>" type="hidden" id="<?php echo($id);?>" value="1" />
|
||||
<input name="<?php echo("{$option_name}-options[]");?>" type="hidden" value="<?php echo($key)?>" />
|
||||
|
||||
<?php else: ?>
|
||||
<div class="agp-vspaced_input">
|
||||
<label for="<?php echo($id);?>" title="<?php echo($key);?>">
|
||||
<input name="<?php echo("{$option_name}-options[]");?>" type="hidden" value="<?php echo($key)?>" />
|
||||
<input name="<?php echo($id);?>" type="checkbox" id="<?php echo($id);?>" value="1" <?php checked('1', ! empty($enabled[$key]) );?> /> <?php echo($type_obj->label);?>
|
||||
|
||||
<?php
|
||||
echo ('</label></div>');
|
||||
|
||||
endif; // displaying checkbox UI
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
echo '</td>';
|
||||
}
|
||||
?>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php if( pp_wp_ver( '3.5' ) ) :
|
||||
$define_create_posts_cap = pp_get_option( 'define_create_posts_cap' );
|
||||
?>
|
||||
<div>
|
||||
<label for="pp_define_create_posts_cap">
|
||||
<input name="pp_define_create_posts_cap" type="checkbox" id="pp_define_create_posts_cap" value="1" <?php checked('1', $define_create_posts_cap );?> /> <?php _e('Use create_posts capability');?>
|
||||
</label>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<input type="submit" name="update_filtered_types" value="<?php _e('Update', 'capsman-enhanced') ?>" class="button" />
|
||||
</dd>
|
||||
</dl>
|
||||
<?php endif;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user