Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#44466 closed enhancement (fixed)

Have a method to check if a taxonomy is viewable

Reported by: andizer's profile andizer Owned by: pento's profile pento
Milestone: 5.1 Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: has-unit-tests has-patch
Focuses: Cc:

Description

I was in need of a function that checks if a given taxonomy is viewable. In WordPress there is already a similar function to check this for a post type (is_post_type_viewable).

I think it would be useful to have this for taxonomies as well. Like is_taxonomy_viewable

Attachments (6)

44466.diff (993 bytes) - added by andizer 6 years ago.
44466-2.diff (666 bytes) - added by andizer 6 years ago.
44466-unittests.diff (1.4 KB) - added by andizer 6 years ago.
44466-3.diff (1.8 KB) - added by andizer 6 years ago.
Implements the function where possible
44466.2.diff (3.1 KB) - added by flixos90 6 years ago.
44466.3.diff (3.1 KB) - added by andizer 6 years ago.
Updated the @since

Download all attachments as: .zip

Change History (17)

#1 follow-up: @flixos90
6 years ago

  • Keywords needs-patch needs-unit-tests good-first-bug added
  • Milestone changed from Awaiting Review to 5.0

This makes complete sense to me, for both parity and solving a common use-case universally. Let's introduce is_taxonomy_viewable().

This should be an easy thing, before we implement it though, I'm wondering about is_post_type_viewable(): Why does it use $public for built-in post types and $publicly_queryable for all the others? I feel like it would make more sense if it only looked at $publicly_queryable in all cases.

@andizer
6 years ago

#2 in reply to: ↑ 1 @SergeyBiryukov
6 years ago

Replying to flixos90:

I'm wondering about is_post_type_viewable(): Why does it use $public for built-in post types and $publicly_queryable for all the others?

Because publicly_queryable is false for pages, but they're still considered viewable. See [33666] and [18234] for some more context.

#3 @flixos90
6 years ago

  • Keywords has-patch added; needs-patch removed
  • Owner set to andizer
  • Status changed from new to assigned

Thanks for the patch @andizer!

I think two small changes are needed:

  • For taxonomies, we only need to check publicly_queryable in any case. The only reason is_post_type_viewable() contains the extra logic is because of the special case of pages being public but not publicly queryable. This doesn't exist for taxonomies in core, so we can simplify here.
  • We don't need the isset() checks as these properties always are set on taxonomy objects.

Let me know if you wanna work on unit tests for this as well. For now I'll assign it to you for further iteration.

@andizer
6 years ago

#4 @birgire
6 years ago

  • Keywords has-unit-tests added; needs-unit-tests removed

@andizer
6 years ago

Implements the function where possible

@flixos90
6 years ago

#5 @flixos90
6 years ago

In 44466.2.diff I assembled the previous patches into one. Everything worked perfectly, I just made a few changes:

  • Got rid of the one usage in the REST API controller. While it technically works, that code is getting values for taxonomy properties, so publicly_queryable should continue to simply get its value.
  • Added 5.0.0 version number to the function.
  • Added missing call to parent setUp() method in the test class.

#6 @flixos90
6 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 43386:

Taxonomy: Introduce is_taxonomy_viewable().

This utility function allows for easy detection whether terms for a taxonomy are considered publicly viewable.

Props andizer.
Fixes #44466.

#7 @johnbillion
6 years ago

  • Keywords needs-patch added; good-first-bug has-patch removed
  • Milestone changed from 5.0 to 5.1
  • Resolution fixed deleted
  • Status changed from closed to reopened

@since needs updating

@andizer
6 years ago

Updated the @since

#8 @andizer
6 years ago

@johnbillion I've just updated the patch

#9 @andizer
6 years ago

  • Keywords has-patch added; needs-patch removed

#10 @pento
6 years ago

  • Owner changed from andizer to pento
  • Status changed from reopened to assigned

#11 @pento
6 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 44447:

Docs: Update @since for is_taxonomy_viewable().

Props andizer.
Fixes #44466.

Note: See TracTickets for help on using tickets.