Oz Web Services
  • Home
  • WP
  • PHP
  • JS
  • CSS
  • SCSS
  • HTML
  • XML
  • JSON
  • SQL
  • .htaccess
  • Apache
  • Nginx
  • INI
  • HTTP
  • Diff
Search shortcode

WP: add_role() remove_role()

May 29, 2014
// Only need to load a page once to get this into db, then comment out (or place in theme/plugin activation)
// WP Codex: http://codex.wordpress.org/Roles_and_Capabilities
$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
	)
);
if ( null !== $result ) {
	echo 'Yay! New role created!';
} else {
	echo 'Oh... the basic_contributor role already exists.';
}

// Or remove a role
remove_role( 'basic_contributor' );
Oz Web Services
Copyright © 2015-2025 All Rights Reserved