[wp-trac] [WordPress Trac] #46846: Tight comparisons and use of Yoda conditions are not consistent

WordPress Trac noreply at wordpress.org
Sat Jun 28 22:48:25 UTC 2025


#46846: Tight comparisons and use of Yoda conditions are not consistent
------------------------------------------------+--------------------------
 Reporter:  subrataemfluence                    |       Owner:  (none)
     Type:  defect (bug)                        |      Status:  closed
 Priority:  normal                              |   Milestone:  Awaiting
                                                |  Review
Component:  Formatting                          |     Version:
 Severity:  normal                              |  Resolution:  worksforme
 Keywords:  has-patch dev-feedback 2nd-opinion  |     Focuses:  coding-
                                                |  standards
------------------------------------------------+--------------------------
Changes (by sabernhardt):

 * keywords:  has-patch dev-feedback => has-patch dev-feedback 2nd-opinion


Comment:

 > most if not all conditionals are now written as yoda conditions

 All the proposed comparisons are now strict, and most of them have
 switched to Yoda condition order.

 - [https://core.trac.wordpress.org/changeset/45887/trunk/src/wp-
 includes/formatting.php r45887]: strict comparison and Yoda condition in
 `iso8601_to_datetime()`
 - [https://core.trac.wordpress.org/changeset/47219/trunk/src/wp-
 includes/formatting.php r47219]: strict comparison and Yoda condition in
 `iso8601_timezone_to_offset()`, plus Yoda conditions for `antispambot()`
 and `sanitize_option()`
 - [https://core.trac.wordpress.org/changeset/47808/trunk/src/wp-
 includes/formatting.php r47808]: strict comparisons in
 `convert_smilies()`, `wp_trim_excerpt()`, `esc_url()`,
 `sanitize_option()`, and `wp_staticize_emoji()`
 - [https://core.trac.wordpress.org/changeset/55642/trunk/src/wp-
 includes/formatting.php r55642]: strict comparison in `wp_sprintf_l()`
 - r56325: strict comparison in `antispambot()`

 That still leaves two from the first patch. However, similar comparisons
 exist elsewhere in the same file.

 1. `if ( count( $matches ) === 0 )` on
 [https://core.trac.wordpress.org/browser/trunk/src/wp-
 includes/formatting.php?rev=60249&marks=3432#L3432 line 3432] for
 `translate_smiley()` is like
   - [https://core.trac.wordpress.org/browser/trunk/src/wp-
 includes/formatting.php?rev=60249&marks=1170#L1170 line 1170] for
 `utf8_uri_encode()`
   - [https://core.trac.wordpress.org/browser/trunk/src/wp-
 includes/formatting.php?rev=60249&marks=5344#L5344 line 5344] for
 `wp_sprintf_l()`
 2. `if ( strpos( $email, '@', 1 ) === false )` on
 [https://core.trac.wordpress.org/browser/trunk/src/wp-
 includes/formatting.php?rev=60249&marks=3558#L3558 line 3558] for
 `is_email()` matches
   - [https://core.trac.wordpress.org/browser/trunk/src/wp-
 includes/formatting.php?rev=60249&marks=3772#L3772 line 3772] for
 `sanitize_email()`

 In addition to those, I found
 - `if ( trim( $text ) === '' )` on
 [https://core.trac.wordpress.org/browser/trunk/src/wp-
 includes/formatting.php?rev=60249&marks=449#L449 line 449] for `wpautop()`
 - `if ( $force || (int) get_option( 'use_balanceTags' ) === 1 )` on
 [https://core.trac.wordpress.org/browser/trunk/src/wp-
 includes/formatting.php?rev=60249&marks=2544#L2544 line 2544] for
 `balanceTags()`
 - `if ( stripos( $text, 'target' ) === false || stripos( $text, '<a ' )
 === false || is_serialized( $text ) )` on
 [https://core.trac.wordpress.org/browser/trunk/src/wp-
 includes/formatting.php?rev=60249&marks=3312#L3312 line 3312] for
 `wp_targeted_link_rel()`, which
 [https://core.trac.wordpress.org/changeset/59120/trunk/src/wp-
 includes/formatting.php r59120] deprecated

 I'll upload a patch editing those 8 lines, in case it is worth reopening
 the ticket for any of them.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/46846#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list