1 of 9

WordPress Plugin #3-1

May 28th, 2015

changwoo

2 of 9

Roles & Capabilities

Granting privileges.

WordPress used a User Levels system before 2.0 (long ago!)

User level is obsolete now.

Do not use.

3 of 9

Roles & Capabilities

Role: a capability preset

Capability: a task

there are many capabilities, but not so hard because they're very human-readable.

4 of 9

Roles & Capabilities

5 of 9

Roles & Capabilities

R&C is much flexible than LV.

You can add your own R&C.

Defining

per-user capabilities,

multiple roles: no problem.

6 of 9

Roles & Capabilities

add_role( $role, $display_name, $capabilities = array() )

remove_role( $role )

{WP_User, WP_Roles, WP_Role}::add_cap( $cap, $grant = true )

{WP_User, WP_Roles, WP_Role}::remove_cap( $cap )

7 of 9

Roles & Capabilities

function get_role( $role )

function user_can( $user, $capability )

function current_user_can( $capability )

8 of 9

Primitive Capabilities

  • Assigned to user roles
  • Generally plural
  • Always true or false, it is frozen.

9 of 9

Meta Capabilities

  • Dynamically generated by context
  • Generally singular
  • Added to primitive cap after map_meta_cap
  • One of following

'delete_page'

'delete_post'

'delete_user'

'edit_comment'

'promote_user'

'read_post'

'read_page'

'remove_user'

'edit_page'

'edit_post'

'edit_user'

'publish_post'