From e2d9939e57e09a3be893b03bec7564ca14a32a4f Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 29 Jul 2014 01:40:24 +0000 Subject: [PATCH] Avoid PHP notices in Media Library if an attachment parent post type no longer exists. Synchronize the 'edit_post' capability check between the list table and the media grid. fixes #27446. git-svn-id: https://develop.svn.wordpress.org/trunk@29320 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/class-wp-media-list-table.php | 2 +- src/wp-includes/media-template.php | 6 +++++- src/wp-includes/media.php | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/wp-admin/includes/class-wp-media-list-table.php b/src/wp-admin/includes/class-wp-media-list-table.php index 4104f24c47..91c72c71b1 100644 --- a/src/wp-admin/includes/class-wp-media-list-table.php +++ b/src/wp-admin/includes/class-wp-media-list-table.php @@ -370,7 +370,7 @@ foreach ( $columns as $column_name => $column_display_name ) { $parent_type = get_post_type_object( $parent->post_type ); ?> > - post_parent ) && $parent_type && $parent_type->show_ui ) { ?> + show_ui && current_user_can( 'edit_post', $post->post_parent ) ) { ?> <# } #>
diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index b4f24e6cf0..bf663b2335 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -2636,7 +2636,10 @@ function wp_prepare_attachment_for_js( $attachment ) { if ( $attachment->post_parent ) { $post_parent = get_post( $attachment->post_parent ); - $response['uploadedToLink'] = get_edit_post_link( $attachment->post_parent, 'raw' ); + $parent_type = get_post_type_object( $post_parent->post_type ); + if ( $parent_type && $parent_type->show_ui && current_user_can( 'edit_post', $attachment->post_parent ) ) { + $response['uploadedToLink'] = get_edit_post_link( $attachment->post_parent, 'raw' ); + } $response['uploadedToTitle'] = $post_parent->post_title ? $post_parent->post_title : __( '(No title)' ); }