Using WordPress ‘populate_roles_160()’ PHP function

The populate_roles_160() WordPress PHP function creates the roles for WordPress 2.0.

Usage

populate_roles_160();

Parameters

  • None

More information

See WordPress Developer Resources: populate_roles_160

Examples

Creating Default Roles for WordPress 2.0

This example demonstrates how to use the populate_roles_160() function to create the default roles for a WordPress 2.0 installation.

// Create default roles for WordPress 2.0
populate_roles_160();

Adding New Roles to WordPress 2.0

This example shows how to use the populate_roles_160() function to create new roles in a WordPress 2.0 site.

// Create default roles for WordPress 2.0
populate_roles_160();

// Add new custom roles
add_role('editor2', 'Secondary Editor', array(
    'read' => true,
    'edit_posts' => true,
    'delete_posts' => false,
));

Checking if Default Roles Exist in WordPress 2.0

This example demonstrates how to use the populate_roles_160() function to create the default roles for WordPress 2.0 and then check if a specific role exists.

// Create default roles for WordPress 2.0
populate_roles_160();

// Check if the 'editor' role exists
$role_exists = get_role('editor');
if ($role_exists) {
    echo 'The editor role exists.';
} else {
    echo 'The editor role does not exist.';
}

Modifying Existing Roles in WordPress 2.0

This example shows how to use the populate_roles_160() function to create the default roles for WordPress 2.0 and then modify an existing role’s capabilities.

// Create default roles for WordPress 2.0
populate_roles_160();

// Modify the 'author' role capabilities
$author_role = get_role('author');
$author_role->add_cap('edit_published_posts');

Removing Default Roles in WordPress 2.0

This example demonstrates how to use the populate_roles_160() function to create the default roles for WordPress 2.0 and then remove a specific role.

// Create default roles for WordPress 2.0
populate_roles_160();

// Remove the 'contributor' role
remove_role('contributor');