Make WordPress Core

Opened 3 months ago

Closed 3 months ago

#63039 closed defect (bug) (fixed)

Incorrect type for the $public parameter in 'robots_txt' filter

Reported by: sergeybiryukov's profile SergeyBiryukov Owned by: audrasjb's profile audrasjb
Milestone: 6.8 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch commit
Focuses: docs Cc:

Description

In the robots_txt filter, the $public parameter is documented as bool. However, in practice it's a string, either '0' or '1', retrieved from get_option( 'blog_public' ).

We should either cast the value to bool for the filter, to match the documented type, or correct the documentation.

Attachments (2)

63039.patch (495 bytes) - added by shailu25 3 months ago.
Patch Added.
63039-alternative.patch (502 bytes) - added by shailu25 3 months ago.
Added Alternative Patch.

Download all attachments as: .zip

Change History (7)

@shailu25
3 months ago

Patch Added.

@shailu25
3 months ago

Added Alternative Patch.

#1 @shailu25
3 months ago

  • Keywords has-patch added

#3 @kapilpaul
3 months ago

Since we are already checking $public as a boolean in other functions, it makes more sense to cast it to bool before passing it to the filter. This ensures consistency, prevents potential type issues, and aligns with the documented type. Updating the documentation instead of casting might introduce inconsistencies in how we handle this value across different functions.

#4 @audrasjb
3 months ago

  • Keywords commit added
  • Owner set to audrasjb
  • Status changed from new to accepted

Yes, sounds better to cas it to bool.
Self assigning for commit.

#5 @audrasjb
3 months ago

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

In 59946:

General: Cast $public param to bool in do_robots().

This changeset properly casts the $public variable into bool in do_robots() for better consistency between code and docs.

Props SergeyBiryukov, shailu25, kapilpaul.
Fixes #63039.

Note: See TracTickets for help on using tickets.