Make sure you’re adding and removing roles on plugin activation/deactivation.
add_role()
only adds a role if it doesn’t already exist. So if you already added the developer role without the capability to add administrators, calling add_role() again won’t re-add the role. You have to remove the role first.
<?php
/**
* Plugin Name: Stackexchange Sample
*/
//* Don't access this file directly
defined( 'ABSPATH' ) or die();
//* Add role for developer that has the same capabilities as administrators
register_activation_hook( __FILE__ , 'wpse_106269_activation' );
function wpse_106269_activation() {
$admin_role = get_role( 'administrator' );
add_role( 'developer', __( 'Developer' ), $admin_role->capabilities );
}
//* Remove developer role
register_deactivation_hook( __FILE__ , 'wpse_106269_deactivation' );
function wpse_106269_activation() {
remove_role( 'developer' );
}
Deactivate and re-activate your plugin and the developer role should have the same capabilities as the administrator role.