add_cap example


function populate_roles_160() {
    // Add roles.     add_role( 'administrator', 'Administrator' );
    add_role( 'editor', 'Editor' );
    add_role( 'author', 'Author' );
    add_role( 'contributor', 'Contributor' );
    add_role( 'subscriber', 'Subscriber' );

    // Add caps for Administrator role.     $role = get_role( 'administrator' );
    $role->add_cap( 'switch_themes' );
    $role->add_cap( 'edit_themes' );
    $role->add_cap( 'activate_plugins' );
    $role->add_cap( 'edit_plugins' );
    $role->add_cap( 'edit_users' );
    $role->add_cap( 'edit_files' );
    $role->add_cap( 'manage_options' );
    $role->add_cap( 'moderate_comments' );
    $role->add_cap( 'manage_categories' );
    $role->add_cap( 'manage_links' );
    $role->add_cap( 'upload_files' );
    $role->add_cap( 'import' );
    
/** * Assign role a capability. * * @since 2.0.0 * * @param string $cap Capability name. * @param bool $grant Whether role has capability privilege. */
    public function add_cap( $cap$grant = true ) {
        $this->capabilities[ $cap ] = $grant;
        wp_roles()->add_cap( $this->name, $cap$grant );
    }

    /** * Removes a capability from a role. * * @since 2.0.0 * * @param string $cap Capability name. */
    public function remove_cap( $cap ) {
        unset( $this->capabilities[ $cap ] );
        
Home | Imprint | This part of the site doesn't use cookies.