| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | Plugin Name: Restrict Page Editing |
|---|
| 4 | Description: Restricts users from editing Pages unless they have edit_others_pages capability |
|---|
| 5 | Version: 1.0 |
|---|
| 6 | Author: Owen Winkler |
|---|
| 7 | Author URI: http://www.asymptomatic.net |
|---|
| 8 | Plugin URI: http://redalt.com/wiki/Restrict+Page+Editing |
|---|
| 9 | */ |
|---|
| 10 | |
|---|
| 11 | class Restrict_Pages |
|---|
| 12 | { |
|---|
| 13 | function Restrict_Pages() |
|---|
| 14 | { |
|---|
| 15 | add_filter('user_has_cap', array(&$this, 'user_has_cap'), 10, 3); |
|---|
| 16 | add_filter('capabilities_list', array(&$this, 'capabilities_list')); |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | function user_has_cap() |
|---|
| 20 | { |
|---|
| 21 | global $post, $current_user; |
|---|
| 22 | $vargs = func_get_args(); |
|---|
| 23 | list($allcaps, $reqcaps, $args) = $vargs; |
|---|
| 24 | |
|---|
| 25 | if($allcaps['edit_others_pages'] == 1) return $allcaps; |
|---|
| 26 | |
|---|
| 27 | if(($reqcaps[0] == 'edit_pages') && (is_numeric($args[2]))){ |
|---|
| 28 | $post = get_post($args[2]); |
|---|
| 29 | if($post->post_author != $current_user->id) { |
|---|
| 30 | $allcaps = array(); |
|---|
| 31 | } |
|---|
| 32 | } |
|---|
| 33 | return $allcaps; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | function capabilities_list($caplist) |
|---|
| 37 | { |
|---|
| 38 | $caplist[] = 'edit_others_pages'; |
|---|
| 39 | return $caplist; |
|---|
| 40 | } |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | $restrict_pages = new Restrict_Pages(); |
|---|
| 44 | |
|---|
| 45 | ?> |
|---|