Index: wp-includes/capabilities.php
===================================================================
--- wp-includes/capabilities.php	(revision 15261)
+++ wp-includes/capabilities.php	(working copy)
@@ -819,41 +819,42 @@
 		break;
 	case 'delete_post':
 		$author_data = get_userdata( $user_id );
-		//echo "post ID: {$args[0]}<br />";
 		$post = get_post( $args[0] );
-		$post_type = get_post_type_object( $post->post_type );
-		if ( $post_type && 'post' != $post_type->capability_type ) {
-			$args = array_merge( array( $post_type->cap->delete_post, $user_id ), $args );
-			return call_user_func_array( 'map_meta_cap', $args );
-		}
+		if ( ! empty( $post->ID ) ) {
+			$post_type = get_post_type_object( $post->post_type );
+			if ( $post_type && 'post' != $post_type->capability_type ) {
+				$args = array_merge( array( $post_type->cap->delete_post, $user_id ), $args );
+				return call_user_func_array( 'map_meta_cap', $args );
+			}
 
-		if ( '' != $post->post_author ) {
-			$post_author_data = get_userdata( $post->post_author );
-		} else {
-			//No author set yet so default to current user for cap checks
-			$post_author_data = $author_data;
-		}
+			if ( '' != $post->post_author ) {
+				$post_author_data = get_userdata( $post->post_author );
+			} else {
+				//No author set yet so default to current user for cap checks
+				$post_author_data = $author_data;
+			}
 
-		// If the user is the author...
-		if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
-			// If the post is published...
-			if ( 'publish' == $post->post_status ) {
-				$caps[] = 'delete_published_posts';
-			} elseif ( 'trash' == $post->post_status ) {
-				if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) )
+			// If the user is the author...
+			if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
+				// If the post is published...
+				if ( 'publish' == $post->post_status ) {
 					$caps[] = 'delete_published_posts';
+				} elseif ( 'trash' == $post->post_status ) {
+					if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) )
+						$caps[] = 'delete_published_posts';
+				} else {
+					// If the post is draft...
+					$caps[] = 'delete_posts';
+				}
 			} else {
-				// If the post is draft...
-				$caps[] = 'delete_posts';
+				// The user is trying to edit someone else's post.
+				$caps[] = 'delete_others_posts';
+				// The post is published, extra cap required.
+				if ( 'publish' == $post->post_status )
+					$caps[] = 'delete_published_posts';
+				elseif ( 'private' == $post->post_status )
+					$caps[] = 'delete_private_posts';
 			}
-		} else {
-			// The user is trying to edit someone else's post.
-			$caps[] = 'delete_others_posts';
-			// The post is published, extra cap required.
-			if ( 'publish' == $post->post_status )
-				$caps[] = 'delete_published_posts';
-			elseif ( 'private' == $post->post_status )
-				$caps[] = 'delete_private_posts';
 		}
 		break;
 	case 'delete_page':
@@ -896,99 +897,105 @@
 		// edit_others_posts
 	case 'edit_post':
 		$author_data = get_userdata( $user_id );
-		//echo "post ID: {$args[0]}<br />";
 		$post = get_post( $args[0] );
-		$post_type = get_post_type_object( $post->post_type );
-		if ( $post_type && 'post' != $post_type->capability_type ) {
-			$args = array_merge( array( $post_type->cap->edit_post, $user_id ), $args );
-			return call_user_func_array( 'map_meta_cap', $args );
-		}
-		$post_author_data = get_userdata( $post->post_author );
-		//echo "current user id : $user_id, post author id: " . $post_author_data->ID . "<br />";
-		// If the user is the author...
-		if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
-			// If the post is published...
-			if ( 'publish' == $post->post_status ) {
-				$caps[] = 'edit_published_posts';
-			} elseif ( 'trash' == $post->post_status ) {
-				if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) )
+		if ( ! empty( $post->ID ) ) {
+			$post_type = get_post_type_object( $post->post_type );
+			if ( $post_type && 'post' != $post_type->capability_type ) {
+				$args = array_merge( array( $post_type->cap->edit_post, $user_id ), $args );
+				return call_user_func_array( 'map_meta_cap', $args );
+			}
+			$post_author_data = get_userdata( $post->post_author );
+			
+			// If the user is the author...
+			if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
+				// If the post is published...
+				if ( 'publish' == $post->post_status ) {
 					$caps[] = 'edit_published_posts';
+				} elseif ( 'trash' == $post->post_status ) {
+					if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) )
+						$caps[] = 'edit_published_posts';
+				} else {
+					// If the post is draft...
+					$caps[] = 'edit_posts';
+				}
 			} else {
-				// If the post is draft...
-				$caps[] = 'edit_posts';
+				// The user is trying to edit someone else's post.
+				$caps[] = 'edit_others_posts';
+				// The post is published, extra cap required.
+				if ( 'publish' == $post->post_status )
+					$caps[] = 'edit_published_posts';
+				elseif ( 'private' == $post->post_status )
+					$caps[] = 'edit_private_posts';
 			}
-		} else {
-			// The user is trying to edit someone else's post.
-			$caps[] = 'edit_others_posts';
-			// The post is published, extra cap required.
-			if ( 'publish' == $post->post_status )
-				$caps[] = 'edit_published_posts';
-			elseif ( 'private' == $post->post_status )
-				$caps[] = 'edit_private_posts';
 		}
 		break;
 	case 'edit_page':
 		$author_data = get_userdata( $user_id );
-		//echo "post ID: {$args[0]}<br />";
 		$page = get_page( $args[0] );
-		$page_author_data = get_userdata( $page->post_author );
-		//echo "current user id : $user_id, page author id: " . $page_author_data->ID . "<br />";
-		// If the user is the author...
-		if ( is_object( $page_author_data ) && $user_id == $page_author_data->ID ) {
-			// If the page is published...
-			if ( 'publish' == $page->post_status ) {
-				$caps[] = 'edit_published_pages';
-			} elseif ( 'trash' == $page->post_status ) {
-				if ('publish' == get_post_meta($page->ID, '_wp_trash_meta_status', true) )
+		if ( ! empty( $page->ID ) ) {
+			$page_author_data = get_userdata( $page->post_author );
+			
+			// If the user is the author...
+			if ( is_object( $page_author_data ) && $user_id == $page_author_data->ID ) {
+				// If the page is published...
+				if ( 'publish' == $page->post_status ) {
 					$caps[] = 'edit_published_pages';
+				} elseif ( 'trash' == $page->post_status ) {
+					if ('publish' == get_post_meta($page->ID, '_wp_trash_meta_status', true) )
+						$caps[] = 'edit_published_pages';
+				} else {
+					// If the page is draft...
+					$caps[] = 'edit_pages';
+				}
 			} else {
-				// If the page is draft...
-				$caps[] = 'edit_pages';
+				// The user is trying to edit someone else's page.
+				$caps[] = 'edit_others_pages';
+				// The page is published, extra cap required.
+				if ( 'publish' == $page->post_status )
+					$caps[] = 'edit_published_pages';
+				elseif ( 'private' == $page->post_status )
+					$caps[] = 'edit_private_pages';
 			}
-		} else {
-			// The user is trying to edit someone else's page.
-			$caps[] = 'edit_others_pages';
-			// The page is published, extra cap required.
-			if ( 'publish' == $page->post_status )
-				$caps[] = 'edit_published_pages';
-			elseif ( 'private' == $page->post_status )
-				$caps[] = 'edit_private_pages';
 		}
 		break;
 	case 'read_post':
 		$post = get_post( $args[0] );
-		$post_type = get_post_type_object( $post->post_type );
-		if ( $post_type && 'post' != $post_type->capability_type ) {
-			$args = array_merge( array( $post_type->cap->read_post, $user_id ), $args );
-			return call_user_func_array( 'map_meta_cap', $args );
-		}
+		if ( ! empty( $post->ID ) ) {
+			$post_type = get_post_type_object( $post->post_type );
+			if ( $post_type && 'post' != $post_type->capability_type ) {
+				$args = array_merge( array( $post_type->cap->read_post, $user_id ), $args );
+				return call_user_func_array( 'map_meta_cap', $args );
+			}
 
-		if ( 'private' != $post->post_status ) {
-			$caps[] = 'read';
-			break;
+			if ( 'private' != $post->post_status ) {
+				$caps[] = 'read';
+				break;
+			}
+
+			$author_data = get_userdata( $user_id );
+			$post_author_data = get_userdata( $post->post_author );
+			if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID )
+				$caps[] = 'read';
+			else
+				$caps[] = 'read_private_posts';
 		}
-
-		$author_data = get_userdata( $user_id );
-		$post_author_data = get_userdata( $post->post_author );
-		if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID )
-			$caps[] = 'read';
-		else
-			$caps[] = 'read_private_posts';
 		break;
 	case 'read_page':
 		$page = get_page( $args[0] );
+		if ( ! empty( $page->ID ) ) {
 
-		if ( 'private' != $page->post_status ) {
-			$caps[] = 'read';
-			break;
+			if ( 'private' != $page->post_status ) {
+				$caps[] = 'read';
+				break;
+			}
+
+			$author_data = get_userdata( $user_id );
+			$page_author_data = get_userdata( $page->post_author );
+			if ( is_object( $page_author_data ) && $user_id == $page_author_data->ID )
+				$caps[] = 'read';
+			else
+				$caps[] = 'read_private_pages';
 		}
-
-		$author_data = get_userdata( $user_id );
-		$page_author_data = get_userdata( $page->post_author );
-		if ( is_object( $page_author_data ) && $user_id == $page_author_data->ID )
-			$caps[] = 'read';
-		else
-			$caps[] = 'read_private_pages';
 		break;
 	case 'unfiltered_upload':
 		if ( defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( !is_multisite() || is_super_admin() )  )
