From d24a3940de32d9395749f0e0e27cb6bd8b8555af Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 10 Sep 2013 02:28:11 +0000 Subject: [PATCH] Make sure the queried object is non-null before accessing its properties. Props markoheijnen, ryan. Fixes #21394. Built from https://develop.svn.wordpress.org/trunk@25310 git-svn-id: http://core.svn.wordpress.org/trunk@25272 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/category-template.php | 10 ++++++---- wp-includes/general-template.php | 25 +++++++++++++++++-------- wp-includes/link-template.php | 8 +++++--- wp-includes/template.php | 3 ++- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index ca58200d61..f04180c62c 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -465,7 +465,7 @@ function wp_list_categories( $args = '' ) { if ( empty( $r['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) { $current_term_object = get_queried_object(); - if ( $r['taxonomy'] == $current_term_object->taxonomy ) + if ( $current_term_object && $r['taxonomy'] === $current_term_object->taxonomy ) $r['current_category'] = get_queried_object_id(); } @@ -1037,10 +1037,12 @@ function tag_description( $tag = 0 ) { * @return string Term description, available. */ function term_description( $term = 0, $taxonomy = 'post_tag' ) { - if ( !$term && ( is_tax() || is_tag() || is_category() ) ) { + if ( ! $term && ( is_tax() || is_tag() || is_category() ) ) { $term = get_queried_object(); - $taxonomy = $term->taxonomy; - $term = $term->term_id; + if ( $term ) { + $taxonomy = $term->taxonomy; + $term = $term->term_id; + } } $description = get_term_field( 'description', $term, $taxonomy ); return is_wp_error( $description ) ? '' : $description; diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index 598ccefdf4..e42ccc9505 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -592,14 +592,17 @@ function wp_title($sep = '»', $display = true, $seplocation = '') { // If there's a taxonomy if ( is_tax() ) { $term = get_queried_object(); - $tax = get_taxonomy( $term->taxonomy ); - $title = single_term_title( $tax->labels->name . $t_sep, false ); + if ( $term ) { + $tax = get_taxonomy( $term->taxonomy ); + $title = single_term_title( $tax->labels->name . $t_sep, false ); + } } // If there's an author if ( is_author() ) { $author = get_queried_object(); - $title = $author->display_name; + if ( $author ) + $title = $author->display_name; } // Post type archives with has_archive should override terms. @@ -1692,13 +1695,17 @@ function feed_links_extra( $args = array() ) { } elseif ( is_category() ) { $term = get_queried_object(); - $title = sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], $term->name ); - $href = get_category_feed_link( $term->term_id ); + if ( $term ) { + $title = sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], $term->name ); + $href = get_category_feed_link( $term->term_id ); + } } elseif ( is_tag() ) { $term = get_queried_object(); - $title = sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $term->name ); - $href = get_tag_feed_link( $term->term_id ); + if ( $term ) { + $title = sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $term->name ); + $href = get_tag_feed_link( $term->term_id ); + } } elseif ( is_author() ) { $author_id = intval( get_query_var('author') ); @@ -1709,7 +1716,9 @@ function feed_links_extra( $args = array() ) { $href = get_search_feed_link(); } elseif ( is_post_type_archive() ) { $title = sprintf( $args['posttypetitle'], get_bloginfo('name'), $args['separator'], post_type_archive_title( '', false ) ); - $href = get_post_type_archive_feed_link( get_queried_object()->name ); + $post_type_obj = get_queried_object(); + if ( $post_type_obj ) + $href = get_post_type_archive_feed_link( $post_type_obj->name ); } if ( isset($title) && isset($href) ) diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index dd2a217c31..26e37ce4ed 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -713,12 +713,14 @@ function get_edit_term_link( $term_id, $taxonomy, $object_type = '' ) { * @return string HTML content. */ function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) { - if ( is_null( $term ) ) { + if ( is_null( $term ) ) $term = get_queried_object(); - } + + if ( ! $term ) + return; $tax = get_taxonomy( $term->taxonomy ); - if ( !current_user_can($tax->cap->edit_terms) ) + if ( ! current_user_can( $tax->cap->edit_terms ) ) return; if ( empty( $link ) ) diff --git a/wp-includes/template.php b/wp-includes/template.php index 78557e8a48..9ae769e090 100644 --- a/wp-includes/template.php +++ b/wp-includes/template.php @@ -256,7 +256,8 @@ function get_page_template() { if ( ! $pagename && $id ) { // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object $post = get_queried_object(); - $pagename = $post->post_name; + if ( $post ) + $pagename = $post->post_name; } $templates = array();