Reputation: 1181
The Question:
How do you create a custom role defautly applied to new sites on a network?
I'm trying to greatly reduce freedom on newly created network sites.
Here is an example:
add_role('basic_user', 'Basic User', array(
'read' => true, // True allows that capability
'edit_posts' => true,
'delete_posts' => false,
));
I had thought simply adding this line to my network plugins (to the activate-hooked process) would be enough to see this role available in the network sites. But its not.
I'm aware of the Members plugin, but I'd like to have full control of this feature without relying on a plugin.
Upvotes: 1
Views: 1329
Reputation: 26065
For this kind of network custom settings, we use Must Use Plugins.
Create the folder /wp-content/mu-plugins/
and drop a PHP file there (it doesn't even need a plugin header; and there's no activation/deactivation, it's always active):
<?php
/**
* Plugin Name: Basic contributor role
* Plugin Description: Network wide default role
*/
add_action( 'init', function()
{
$result = add_role(
'basic_contributor',
__( 'Basic Contributor' ),
array(
'read' => true, // true allows this capability
'edit_posts' => true,
'delete_posts' => false, // Use false to explicitly deny
)
);
});
In the add_role()
documentation page, there's a mention to this very method: adding an init
action in a mu-plugin
.
Upvotes: 1