Make WordPress Core

Opened 9 years ago

Closed 4 years ago

#33756 closed defect (bug) (fixed)

Improve docs for sanitize_title()

Reported by: ericlewis's profile ericlewis Owned by: psdtohtmlguru's profile psdtohtmlguru
Milestone: 5.5 Priority: normal
Severity: normal Version:
Component: Formatting Keywords: good-first-bug has-patch
Focuses: docs Cc:

Description

It's not immediately clear what sanitize_title() does. Adding doc modifications.

Attachments (5)

33756.diff (1.4 KB) - added by ericlewis 9 years ago.
33756.2.diff (1.5 KB) - added by swissspidy 9 years ago.
33756.3.diff (1.9 KB) - added by gma992 8 years ago.
Rephrasing what sanitize_title() does
33756.4.diff (1.9 KB) - added by gma992 8 years ago.
Rephrased again, special characters are replaced too.
33756.5.diff (846 bytes) - added by ebinnion 7 years ago.
5th attempt at solution

Download all attachments as: .zip

Change History (27)

@ericlewis
9 years ago

@swissspidy
9 years ago

#1 @swissspidy
9 years ago

After looking at the PHP Documentation Standards I made some small adjustments to your patch, adding/removing newlines and backticks where necessary.

#2 @DrewAPicture
9 years ago

  • Owner set to DrewAPicture
  • Status changed from new to reviewing

#3 @wonderboymusic
9 years ago

Sanitizes a string for use as a slug in a URL. is incomplete. Also sanitizes for use as HTML id or class attribute value. There may be other uses...

#4 @DrewAPicture
9 years ago

  • Owner changed from DrewAPicture to swissspidy

See comment:3 for other use cases we need to cover.

#5 @DrewAPicture
9 years ago

  • Milestone changed from 4.4 to Future Release

Still some work left here. Let's move it off the milestone until there's a consensus on the best way to document the intent vs the actual usage of these functions. I'd probably suggest going the route of describing the literal characters removed or accepted for any of these formatting functions – since they tend to get used in all sorts of contexts unrelated to the original intent.

#6 @swissspidy
9 years ago

  • Keywords needs-patch good-first-bug added; has-patch removed
  • Owner swissspidy deleted

#7 follow-up: @psdtohtmlguru
9 years ago

@DrewAPicture Can i have this ticket please?

#8 in reply to: ↑ 7 @swissspidy
9 years ago

Replying to psdtohtmlguru:

@DrewAPicture Can i have this ticket please?

A ticket does not belong to anybody, so feel free to submit a patch as you like :)

#9 @DrewAPicture
9 years ago

  • Owner set to DrewAPicture
  • Status changed from reviewing to accepted

#10 @DrewAPicture
9 years ago

  • Owner changed from DrewAPicture to psdtohtmlguru
  • Status changed from accepted to assigned

Assigning to mark the good-first-bug as "claimed".

#11 @SergeyBiryukov
8 years ago

@psdtohtmlguru, still interested in making a patch?

#12 @psdtohtmlguru
8 years ago

@SergeyBiryukov Yes, i will submit soon.

Last edited 8 years ago by psdtohtmlguru (previous) (diff)

#13 @swissspidy
8 years ago

There's a tutorial for working with patches in the handbook: https://make.wordpress.org/core/handbook/tutorials/working-with-patches/

After creating a patch file you can upload it here to this ticket.

#14 @sjmur
8 years ago

Interested in taking this and finishing it. What are we trying to say at this point? Not sure on the language from reading comments.

`

Last edited 8 years ago by sjmur (previous) (diff)

@gma992
8 years ago

Rephrasing what sanitize_title() does

#15 follow-up: @gma992
8 years ago

@wonderboymusic

Sanitizes a string for use as a slug in a URL. is incomplete. Also sanitizes for use as HTML id or class attribute value. There may be other uses...

Not sure if I'm missing something here, but basically sanitize_title() strip tags, removes accents and replace special characters, right? I'm not really sure what you mean with id or class attribute value.

@gma992
8 years ago

Rephrased again, special characters are replaced too.

#16 in reply to: ↑ 15 @shulard
8 years ago

Maybe it's just that the sanitize_title function is sometimes used to generate an id or class from a string to ensure that non authorized characters are not used... Maybe useful only when generating attributes from inputed text.

Replying to gma992:

@wonderboymusic

Sanitizes a string for use as a slug in a URL. is incomplete. Also sanitizes for use as HTML id or class attribute value. There may be other uses...

Not sure if I'm missing something here, but basically sanitize_title() strip tags, removes accents and replace special characters, right? I'm not really sure what you mean with id or class attribute value.

This ticket was mentioned in Slack in #core by welcher. View the logs.


7 years ago

@ebinnion
7 years ago

5th attempt at solution

#18 @ebinnion
7 years ago

  • Keywords has-patch added; needs-patch removed

@tim1602 and I worked on another possible solution at contributor day at WordCamp DFW 2017.

Since some of the pushback in early patches seemed to be that we weren't handling all of the cases of sanitize_title(), for example how it's used in URLs in some cases, and attributes in others... It seemed like it might be best to stay ambiguous and then mention URLs and attributes as examples.

We also tried to expand on the long description by mentioning the sanitize_title filter and the default output.

This ticket was mentioned in Slack in #core by sergey. View the logs.


5 years ago

#20 @SergeyBiryukov
5 years ago

  • Milestone changed from Future Release to 5.5

#21 @whyisjake
4 years ago

  • Component changed from Posts, Post Types to Formatting

#22 @whyisjake
4 years ago

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

In 48432:

Formatting: Improve the docblock for sanitize_title().

Since sanitize title is largely used for html attributes, or post slugs, make note that accents will be removed and that the string will be limited to alphanumeric characters, underscores, and dashes.

Fixes #33756.
Props ericlewis, swissspidy, wonderboymusic, psdtohtmlguru, DrewAPicture, SergeyBiryukov, sjmur, gma992, shulard, ebinnion, whyisjake.

Note: See TracTickets for help on using tickets.