[wp-hackers] quick way to add dozen of new capabilities to existing role?
Andrew Nacin
wp at andrewnacin.com
Tue Sep 7 10:26:51 UTC 2010
On Tue, Sep 7, 2010 at 5:54 AM, Davit Barbakadze <jayarjo at gmail.com> wrote:
> Plugin creates two new custom post types with custom capabilities, is
> there a quick way to assign these capabilities to existing roles -
> administrator, editor?
Something like this:
$capabilities = array( ... );
foreach ( array( 'administrator', 'editor' ) as $role ) {
$role =& get_role( $role );
if ( ! $role )
continue;
foreach ( $capabilities as $cap )
$role->add_cap( $cap );
}
Caution, that probably triggers a boat-load of queries. add_cap() should
probably accept an array of capabilities to make that less taxing. (It only
runs on activation, though.)
Keep in mind you still need to handle meta capabilities yourself.
More information about the wp-hackers
mailing list