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
This commit is contained in:
Scott Taylor 2013-09-10 02:28:11 +00:00
parent 3514c7d1c4
commit d24a3940de
4 changed files with 30 additions and 16 deletions

View File

@ -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;

View File

@ -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) )

View File

@ -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 ) )

View File

@ -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();