Adgangskontrol i WP

Denne lille stump kode er meget nyttig:

if ( !current_user_can( 'publish_posts' ) )  {
		wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
	}

Her er WP listen over brugerrettigheder: user_can “Roles and Capabilities” på Codex.

En række af WPs hooks skriver “capability”. Hvis fx en Contributor skal have adgang til noget, så kan capability være edit_posts. Enkelt og praktisk.

 

Published by

Per Thykjaer Jensen

- Code is the heart of all multimedia productions. Code can animate your creative visions.
Per Thykjaer Jensen teaches multimedia programming at Aarhus Buisiness Academy. He is MA it, interaction design and multimedia, MA literature history and BA art history.