Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#35265 closed defect (bug) (duplicate)

get_the_terms return on non-existing term

Reported by: tivnet Owned by:
Priority: normal Milestone:
Component: Taxonomy Version: 4.4
Severity: normal Keywords:
Cc: Focuses:

Description

<?php
function get_the_terms( $post, $taxonomy ) {
        if ( ! $post = get_post( $post ) )
                return false;

        $terms = get_object_term_cache( $post->ID, $taxonomy );
        if ( false === $terms ) {
                $terms = wp_get_object_terms( $post->ID, $taxonomy );

// ---------- PROPOSED (should we return WP_Error or false here?)

                if ( is_wp_error( $terms ) ) {
                        return $terms;
                }

// ----------

                $to_cache = array();

Attachments (1)

get_the_terms.patch (653 bytes ) - added by tivnet 11 years ago.
Patch returning WP_Error

Download all attachments as: .zip

Change History (10)

@tivnet
11 years ago

Patch returning WP_Error

#1 follow-up: @swissspidy
11 years ago

  • Component GeneralTaxonomy

Related: #34723

#2 follow-up: @tivnet
11 years ago

  • Component TaxonomyGeneral
* @return array|false|WP_Error Array of term objects on success, false if there are no terms
*                              or the post does not exist, WP_Error on failure.

This description suggests that false should be returned.

However, if I am not mistaken, I was getting WP_Error in this case before 4.4

#3 in reply to: ↑ 1 @tivnet
11 years ago

  • Resolutionduplicate
  • Status newclosed

Replying to swissspidy:

Related: #34723

Yep, that's the same case. Not sure, still, if need to return WP_Error as it was before (according to my tests).

Thank you!

#4 in reply to: ↑ 2 ; follow-up: @swissspidy
11 years ago

  • Milestone Awaiting Review

Replying to tivnet:

* @return array|false|WP_Error Array of term objects on success, false if there are no terms
*                              or the post does not exist, WP_Error on failure.

This description suggests that false should be returned.

However, if I am not mistaken, I was getting WP_Error in this case before 4.4

It clearly suggests that it returns either false or a WP_Error object, so I don't see a problem here.

There are is_wp_error checks later on and the get_the_terms filter clearly says that $terms can be a WP_Error object.

Long story short: Your patch prevents the get_the_terms filter being called, otherwise nothing else changes.

#5 in reply to: ↑ 4 @tivnet
11 years ago

Replying to swissspidy:

Long story short: Your patch prevents the get_the_terms filter being called, otherwise nothing else changes.

The main idea was to avoid notice on non-array.

#6 @tivnet
11 years ago

Specifically:

Notice: Trying to get property of non-object in wp-includes\category-template.php on line 1153

($term->data)

#7 follow-up: @boonebgorges
11 years ago

I'm pretty sure this is a duplicate of #34723, and should be fixed by [35850].

#8 in reply to: ↑ 7 @tivnet
11 years ago

Replying to boonebgorges:

I'm pretty sure this is a duplicate of #34723, and should be fixed by [35850].

Yes, 4.4.1 fixed this. Thanks

#9 @DrewAPicture
11 years ago

  • Component GeneralTaxonomy
Note: See TracTickets for help on using tickets.