Canonical: Check if the post type exists when attempting a canonical redirect.

This avoids a PHP notice if the post type is no longer registered.

Follow-up to [14595], [35480].

Props bobbingwide, hareesh-pillai.
Fixes #40309.

git-svn-id: https://develop.svn.wordpress.org/trunk@49924 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2021-01-03 17:54:48 +00:00
parent a6a021d037
commit 087ff2f8ef

View File

@ -148,7 +148,7 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) {
if ( $redirect_post ) {
$post_type_obj = get_post_type_object( $redirect_post->post_type );
if ( $post_type_obj->public && 'auto-draft' !== $redirect_post->post_status ) {
if ( $post_type_obj && $post_type_obj->public && 'auto-draft' !== $redirect_post->post_status ) {
$redirect_url = get_permalink( $redirect_post );
$redirect['query'] = _remove_qs_args_if_not_in_url(