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

I am a Senior Lecturer in front- and backend web programming at the Multimedia Design and Communication Programme at Business Academy Aaarhus.

I speak several languages: PHP, Python, MySQL, JavaScript, Nodejs, HTML, CSS, and … Danish.

Background: MA it, interaction and multimedia – MA Literature history – BA Art History.