Avoid a PHP notice in get_page_template_slug() if the page does not exist. props tollmanz. fixes #24250.

git-svn-id: https://develop.svn.wordpress.org/trunk@24191 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2013-05-07 18:44:22 +00:00
parent feaea4cc26
commit b26b0cc0de

View File

@ -1275,13 +1275,13 @@ function is_page_template( $template = '' ) {
* *
* @since 3.4.0 * @since 3.4.0
* *
* @param int $post_id The page ID to check. Defaults to the current post, when used in the loop. * @param int $post_id Optional. The page ID to check. Defaults to the current post, when used in the loop.
* @return string|bool Page template filename. Returns an empty string when the default page template * @return string|bool Page template filename. Returns an empty string when the default page template
* is in use. Returns false if the post is not a page. * is in use. Returns false if the post is not a page.
*/ */
function get_page_template_slug( $post_id = null ) { function get_page_template_slug( $post_id = null ) {
$post = get_post( $post_id ); $post = get_post( $post_id );
if ( 'page' != $post->post_type ) if ( ! $post || 'page' != $post->post_type )
return false; return false;
$template = get_post_meta( $post->ID, '_wp_page_template', true ); $template = get_post_meta( $post->ID, '_wp_page_template', true );
if ( ! $template || 'default' == $template ) if ( ! $template || 'default' == $template )