Permalinks: Prevent attachment pages 404ing following [49563].

This largely reverts [49563] due to attachment pages returning 404: File not found errors when they use the `inherit` status.

Permalink changes to attachment pages are retained when they are descendants of trashed or deleted posts.

Props Toro_Unit, helen, johnbillion, peterwilsoncc.
Fixes #51776.
See #5272.


Built from https://develop.svn.wordpress.org/trunk@49622


git-svn-id: http://core.svn.wordpress.org/trunk@49360 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson
2020-11-17 03:29:12 +00:00
parent 03eba7beb2
commit 30b79ebd28
3 changed files with 5 additions and 53 deletions

View File

@@ -164,7 +164,10 @@ function get_permalink( $post = 0, $leavename = false ) {
*/
$permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename );
if ( $permalink && ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ), true ) ) {
if (
$permalink &&
! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future', 'trash' ), true )
) {
$category = '';
if ( strpos( $permalink, '%category%' ) !== false ) {
@@ -420,17 +423,6 @@ function get_attachment_link( $post = null, $leavename = false ) {
$parent = false;
}
if ( $parent ) {
$parent_status_obj = get_post_status_object( get_post_status( $post->post_parent ) );
if (
! is_post_type_viewable( get_post_type( $post->post_parent ) ) ||
$parent_status_obj->internal ||
$parent_status_obj->protected
) {
$parent = false;
}
}
if ( $wp_rewrite->using_permalinks() && $parent ) {
if ( 'page' === $parent->post_type ) {
$parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front.