Make WordPress Core

Ticket #2301: restrict_pages.php

File restrict_pages.php, 1.0 KB (added by ringmaster, 21 years ago)

A plugin better handled in core, not exactly sure how well it works.

Line 
1<?php
2/*
3Plugin Name: Restrict Page Editing
4Description: Restricts users from editing Pages unless they have edit_others_pages capability
5Version: 1.0
6Author: Owen Winkler
7Author URI: http://www.asymptomatic.net
8Plugin URI: http://redalt.com/wiki/Restrict+Page+Editing
9*/
10
11class 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?>