Avoid PHP notices in Media Library if an attachment parent does not exist. props trepmal, viniciusmassuchetto, alex-ye, adamsilverstein for initial patches. fixes #22312. fixes #23154.

git-svn-id: http://core.svn.wordpress.org/trunk@24182 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2013-05-07 11:46:35 +00:00
parent d55dfbf477
commit 23479edf3f
2 changed files with 6 additions and 8 deletions

View File

@ -302,13 +302,11 @@ foreach ( $columns as $column_name => $column_display_name ) {
break;
case 'parent':
if ( $post->post_parent > 0 ) {
if ( get_post( $post->post_parent ) ) {
$title =_draft_or_post_title( $post->post_parent );
}
if ( $post->post_parent > 0 && get_post( $post->post_parent ) ) {
$title = _draft_or_post_title( $post->post_parent );
?>
<td <?php echo $attributes ?>><strong>
<?php if( current_user_can( 'edit_post', $post->post_parent ) ) { ?>
<?php if ( current_user_can( 'edit_post', $post->post_parent ) ) { ?>
<a href="<?php echo get_edit_post_link( $post->post_parent ); ?>">
<?php echo $title ?></a><?php
} else {
@ -320,7 +318,7 @@ foreach ( $columns as $column_name => $column_display_name ) {
} else {
?>
<td <?php echo $attributes ?>><?php _e( '(Unattached)' ); ?><br />
<?php if( $user_can_edit ) {?>
<?php if ( $user_can_edit ) { ?>
<a class="hide-if-no-js"
onclick="findPosts.open( 'media[]','<?php echo $post->ID ?>' ); return false;"
href="#the-list">

View File

@ -301,9 +301,9 @@ function get_attachment_link( $post = null, $leavename = false ) {
$link = false;
$post = get_post( $post );
$parent = ( $post->post_parent > 0 && $post->post_parent != $post->ID ) ? get_post( $post->post_parent ) : false;
if ( $wp_rewrite->using_permalinks() && ( $post->post_parent > 0 ) && ( $post->post_parent != $post->ID ) ) {
$parent = get_post($post->post_parent);
if ( $wp_rewrite->using_permalinks() && $parent ) {
if ( 'page' == $parent->post_type )
$parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front
else