Index: wp-includes/capabilities.php
===================================================================
--- wp-includes/capabilities.php	(revision 16089)
+++ wp-includes/capabilities.php	(working copy)
@@ -824,41 +824,44 @@
 	case 'delete_page':
 		$author_data = get_userdata( $user_id );
 		$post = get_post( $args[0] );
-		$post_type = get_post_type_object( $post->post_type );
 
-		if ( 'delete_post' == $cap && $post_type && 'post' != $post_type->capability_type && ! $post_type->map_meta_cap ) {
-			$args = array_merge( array( $post_type->cap->delete_post, $user_id ), $args );
-			return call_user_func_array( 'map_meta_cap', $args );
-		}
+		if ( ! empty( $post->post_type ) ) {
+			$post_type = get_post_type_object( $post->post_type );
 
-		if ( '' != $post->post_author && post_type_supports( $post_type->name, 'author' ) ) {
-			$post_author_data = get_userdata( $post->post_author );
-		} else {
-			// No author set yet or post type doesn't support authors,
-			// so default to current user for cap checks.
-			$post_author_data = $author_data;
-		}
+			if ( 'delete_post' == $cap && $post_type && 'post' != $post_type->capability_type && ! $post_type->map_meta_cap ) {
+				$args = array_merge( array( $post_type->cap->delete_post, $user_id ), $args );
+				return call_user_func_array( 'map_meta_cap', $args );
+			}
 
-		// 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[] = $post_type->cap->delete_published_posts;
-			} elseif ( 'trash' == $post->post_status ) {
-				if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) )
+			if ( '' != $post->post_author && post_type_supports( $post_type->name, 'author' ) ) {
+				$post_author_data = get_userdata( $post->post_author );
+			} else {
+				// No author set yet or post type doesn't support authors,
+				// 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[] = $post_type->cap->delete_published_posts;
+				} elseif ( 'trash' == $post->post_status ) {
+					if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) )
+						$caps[] = $post_type->cap->delete_published_posts;
+				} else {
+					// If the post is draft...
+					$caps[] = $post_type->cap->delete_posts;
+				}
 			} else {
-				// If the post is draft...
-				$caps[] = $post_type->cap->delete_posts;
+				// The user is trying to edit someone else's post.
+				$caps[] = $post_type->cap->delete_others_posts;
+				// The post is published, extra cap required.
+				if ( 'publish' == $post->post_status )
+					$caps[] = $post_type->cap->delete_published_posts;
+				elseif ( 'private' == $post->post_status )
+					$caps[] = $post_type->cap->delete_private_posts;
 			}
-		} else {
-			// The user is trying to edit someone else's post.
-			$caps[] = $post_type->cap->delete_others_posts;
-			// The post is published, extra cap required.
-			if ( 'publish' == $post->post_status )
-				$caps[] = $post_type->cap->delete_published_posts;
-			elseif ( 'private' == $post->post_status )
-				$caps[] = $post_type->cap->delete_private_posts;
 		}
 		break;
 		// edit_post breaks down to edit_posts, edit_published_posts, or
@@ -867,79 +870,89 @@
 	case 'edit_page':
 		$author_data = get_userdata( $user_id );
 		$post = get_post( $args[0] );
-		$post_type = get_post_type_object( $post->post_type );
+		
+		if ( ! empty( $post->post_type ) ) {
 
-		if ( 'edit_post' == $cap && $post_type && 'post' != $post_type->capability_type && ! $post_type->map_meta_cap ) {
-			$args = array_merge( array( $post_type->cap->edit_post, $user_id ), $args );
-			return call_user_func_array( 'map_meta_cap', $args );
-		}
+			$post_type = get_post_type_object( $post->post_type );
 
-		if ( '' != $post->post_author && post_type_supports( $post_type->name, 'author' ) ) {
-			$post_author_data = get_userdata( $post->post_author );
-		} else {
-			// No author set yet or post type doesn't support authors,
-			// so default to current user for cap checks.
-			$post_author_data = $author_data;
-		}
+			if ( 'edit_post' == $cap && $post_type && 'post' != $post_type->capability_type && ! $post_type->map_meta_cap ) {
+				$args = array_merge( array( $post_type->cap->edit_post, $user_id ), $args );
+				return call_user_func_array( 'map_meta_cap', $args );
+			}
 
-		//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[] = $post_type->cap->edit_published_posts;
-			} elseif ( 'trash' == $post->post_status ) {
-				if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) )
+			if ( '' != $post->post_author && post_type_supports( $post_type->name, 'author' ) ) {
+				$post_author_data = get_userdata( $post->post_author );
+			} else {
+				// No author set yet or post type doesn't support authors,
+				// so default to current user for cap checks.
+				$post_author_data = $author_data;
+			}
+
+			//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[] = $post_type->cap->edit_published_posts;
+				} elseif ( 'trash' == $post->post_status ) {
+					if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) )
+						$caps[] = $post_type->cap->edit_published_posts;
+				} else {
+					// If the post is draft...
+					$caps[] = $post_type->cap->edit_posts;
+				}
 			} else {
-				// If the post is draft...
-				$caps[] = $post_type->cap->edit_posts;
+				// The user is trying to edit someone else's post.
+				$caps[] = $post_type->cap->edit_others_posts;
+				// The post is published, extra cap required.
+				if ( 'publish' == $post->post_status )
+					$caps[] = $post_type->cap->edit_published_posts;
+				elseif ( 'private' == $post->post_status )
+					$caps[] = $post_type->cap->edit_private_posts;
 			}
-		} else {
-			// The user is trying to edit someone else's post.
-			$caps[] = $post_type->cap->edit_others_posts;
-			// The post is published, extra cap required.
-			if ( 'publish' == $post->post_status )
-				$caps[] = $post_type->cap->edit_published_posts;
-			elseif ( 'private' == $post->post_status )
-				$caps[] = $post_type->cap->edit_private_posts;
 		}
 		break;
 	case 'read_post':
 	case 'read_page':
 		$author_data = get_userdata( $user_id );
 		$post = get_post( $args[0] );
-		$post_type = get_post_type_object( $post->post_type );
+		if ( ! empty( $post->post_type ) ) {
+			$post_type = get_post_type_object( $post->post_type );
 
-		if ( 'read_post' == $cap && $post_type && 'post' != $post_type->capability_type && ! $post_type->map_meta_cap ) {
-			$args = array_merge( array( $post_type->cap->read_post, $user_id ), $args );
-			return call_user_func_array( 'map_meta_cap', $args );
-		}
+			if ( 'read_post' == $cap && $post_type && 'post' != $post_type->capability_type && ! $post_type->map_meta_cap ) {
+				$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[] = $post_type->cap->read;
-			break;
-		}
+			if ( 'private' != $post->post_status ) {
+				$caps[] = $post_type->cap->read;
+				break;
+			}
 
-		if ( '' != $post->post_author && post_type_supports( $post_type->name, 'author' ) ) {
-			$post_author_data = get_userdata( $post->post_author );
-		} else {
-			// No author set yet or post type doesn't support authors,
-			// so default to current user for cap checks.
-			$post_author_data = $author_data;
+			if ( '' != $post->post_author && post_type_supports( $post_type->name, 'author' ) ) {
+				$post_author_data = get_userdata( $post->post_author );
+			} else {
+				// No author set yet or post type doesn't support authors,
+				// so default to current user for cap checks.
+				$post_author_data = $author_data;
+			}
+
+			if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID )
+				$caps[] = $post_type->cap->read;
+			else
+				$caps[] = $post_type->cap->read_private_posts;
 		}
-
-		if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID )
-			$caps[] = $post_type->cap->read;
-		else
-			$caps[] = $post_type->cap->read_private_posts;
 		break;
 	case 'edit_comment':
 		$comment = get_comment( $args[0] );
-		$post = get_post( $comment->comment_post_ID );
-		$post_type_object = get_post_type_object( $post->post_type );
 
-		$caps = map_meta_cap( $post_type_object->cap->edit_post, $user_id, $post->ID );
+		if ( ! empty( $comment->comment_post_ID ) ) {
+			$post = get_post( $comment->comment_post_ID );
+			if ( ! empty( $post->post_type ) ) {
+				$post_type_object = get_post_type_object( $post->post_type );
+				$caps = map_meta_cap( $post_type_object->cap->edit_post, $user_id, $post->ID );
+			}
+		}
 		break;
 	case 'unfiltered_upload':
 		if ( defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( !is_multisite() || is_super_admin( $user_id ) )  )
