Make WordPress Core


Ignore:
Timestamp:
02/11/2006 09:56:02 AM (21 years ago)
Author:
ryan
Message:

Add new page caps now that pages can be draft or publish. Brings page caps to parity with posts. Add delete caps for posts and pages. fixes #2382 #2336 #2301

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/capabilities.php

    r3482 r3513  
    254254
    255255        switch ($cap) {
     256        case 'delete_post':
     257                $author_data = get_userdata($user_id);
     258                //echo "post ID: {$args[0]}<br/>";
     259                $post = get_post($args[0]);
     260                $post_author_data = get_userdata($post->post_author);
     261                //echo "current user id : $user_id, post author id: " . $post_author_data->ID . "<br/>";
     262                // If the user is the author...
     263                if ($user_id == $post_author_data->ID) {
     264                        // If the post is published...
     265                        if ($post->post_status == 'publish')
     266                                $caps[] = 'delete_published_posts';
     267                        else
     268                                // If the post is draft...
     269                                $caps[] = 'delete_posts';
     270                } else {
     271                        // The user is trying to edit someone else's post.
     272                        $caps[] = 'delete_others_posts';
     273                        // The post is published, extra cap required.
     274                        if ($post->post_status == 'publish')
     275                                $caps[] = 'delete_published_posts';
     276                }
     277                break;
     278        case 'delete_page':
     279                $author_data = get_userdata($user_id);
     280                //echo "post ID: {$args[0]}<br/>";
     281                $page = get_page($args[0]);
     282                $page_author_data = get_userdata($post->post_author);
     283                //echo "current user id : $user_id, page author id: " . $page_author_data->ID . "<br/>";
     284                // If the user is the author...
     285                if ($user_id == $page_author_data->ID) {
     286                        // If the page is published...
     287                        if ($page->post_status == 'publish')
     288                                $caps[] = 'delete_published_pages';
     289                        else
     290                                // If the page is draft...
     291                                $caps[] = 'delete_pages';
     292                } else {
     293                        // The user is trying to edit someone else's page.
     294                        $caps[] = 'delete_others_pages';
     295                        // The page is published, extra cap required.
     296                        if ($page->post_status == 'publish')
     297                                $caps[] = 'delete_published_pages';
     298                }
     299                break;
    256300                // edit_post breaks down to edit_posts, edit_published_posts, or
    257301                // edit_others_posts
    … …  
    267311                        if ($post->post_status == 'publish')
    268312                                $caps[] = 'edit_published_posts';
    269                         else if ($post->post_status == 'static')
    270                                 $caps[] = 'edit_pages';
    271313                        else
    272314                                // If the post is draft...
    273315                                $caps[] = 'edit_posts';
    274316                } else {
    275                         if ($post->post_status == 'static') {
    276                                 $caps[] = 'edit_pages';
    277                                 break;
    278                         }
    279 
    280317                        // The user is trying to edit someone else's post.
    281318                        $caps[] = 'edit_others_posts';
    … …  
    283320                        if ($post->post_status == 'publish')
    284321                                $caps[] = 'edit_published_posts';
     322                }
     323                break;
     324        case 'edit_page':
     325                $author_data = get_userdata($user_id);
     326                //echo "post ID: {$args[0]}<br/>";
     327                $page = get_page($args[0]);
     328                $page_author_data = get_userdata($post->post_author);
     329                //echo "current user id : $user_id, page author id: " . $page_author_data->ID . "<br/>";
     330                // If the user is the author...
     331                if ($user_id == $page_author_data->ID) {
     332                        // If the page is published...
     333                        if ($page->post_status == 'publish')
     334                                $caps[] = 'edit_published_pages';
     335                        else
     336                                // If the page is draft...
     337                                $caps[] = 'edit_pages';
     338                } else {
     339                        // The user is trying to edit someone else's page.
     340                        $caps[] = 'edit_others_pages';
     341                        // The page is published, extra cap required.
     342                        if ($page->post_status == 'publish')
     343                                $caps[] = 'edit_published_pages';
    285344                }
    286345                break;
Note: See TracChangeset for help on using the changeset viewer.