WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/17/2010 12:35:48 PM (10 years ago)
Author:
dd32
Message:

post_type edit_cap and edit_type_cap awareness for wp-admin/includes/post.php

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/post.php

    r13535 r13729  
    146146    $post_ID = (int) $post_data['post_ID'];
    147147
    148     if ( 'page' == $post_data['post_type'] ) {
    149         if ( !current_user_can( 'edit_page', $post_ID ) )
     148    $ptype = get_post_type_object($post_data['post_type']);
     149    if ( !current_user_can( $ptype->edit_cap, $post_ID ) ) {
     150        if ( 'page' == $post_data['post_type'] )
    150151            wp_die( __('You are not allowed to edit this page.' ));
    151     } else {
    152         if ( !current_user_can( 'edit_post', $post_ID ) )
     152        else
    153153            wp_die( __('You are not allowed to edit this post.' ));
    154154    }
     
    237237        $post_data = &$_POST;
    238238
    239     if ( isset($post_data['post_type']) && 'page' == $post_data['post_type'] ) {
    240         if ( ! current_user_can( 'edit_pages' ) )
    241             wp_die( __('You are not allowed to edit pages.') );
    242     } else {
    243         if ( ! current_user_can( 'edit_posts' ) )
    244             wp_die( __('You are not allowed to edit posts.') );
     239    if ( isset($post_data['post_type']) )
     240        $ptype = get_post_type_object($post_data['post_type']);
     241    else
     242        $ptype = get_post_type_object('post');
     243
     244    if ( !current_user_can( $ptype->edit_type_cap, $post_ID ) ) {
     245        if ( 'page' == $ptype->name )
     246            wp_die( __('You are not allowed to edit pages.'));
     247        else
     248            wp_die( __('You are not allowed to edit posts.'));
    245249    }
    246250
     
    483487    global $user_ID;
    484488
    485     if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
    486         if ( !current_user_can( 'edit_pages' ) )
     489
     490    if ( isset($_POST['post_type']) )
     491        $ptype = get_post_type_object($_POST['post_type']);
     492    else
     493        $ptype = get_post_type_object('post');
     494
     495    if ( !current_user_can( $ptype->edit_type_cap, $post_ID ) ) {
     496        if ( 'page' == $ptype->name )
    487497            return new WP_Error( 'edit_pages', __( 'You are not allowed to create pages on this blog.' ) );
    488     } else {
    489         if ( !current_user_can( 'edit_posts' ) )
     498        else
    490499            return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this blog.' ) );
    491500    }
Note: See TracChangeset for help on using the changeset viewer.