Make WordPress Core

Opened 8 months ago

Closed 6 months ago

Last modified 6 months ago

#60668 closed enhancement (fixed)

Missing translation in login_header() first parameter

Reported by: juliobox's profile juliobox Owned by: audrasjb's profile audrasjb
Milestone: 6.6 Priority: normal
Severity: minor Version: 2.1
Component: Login and Registration Keywords: good-first-bug has-patch commit
Focuses: Cc:

Description

Hey there

Actuel code from WP (wp-login.php):

<?php
function login_header( $title = 'Log In', $message = '', $wp_error = null ) {

The $title here will be print as is, in any language. WordPress uses it the right way by always passing a translatable string as first param, but since there is a default value, some plugins can use it without it (and they do it, i've check wpdirectory, more than 1M install, 7 plugins are doing it).

So we cannot remove the default value or we will break the world in half, we have to choose between this:

<?php
function login_header( $title = 'Log In', $message = '', $wp_error = null ) {
    if ( 'Log In' === $title ) {
        $title = __( 'Log In' );
    }

or

<?php
function login_header( $title = null, $message = '', $wp_error = null ) {
    if ( is_null( $title ) ) {
        $title = __( 'Log In' );
    }

We can also use a ternary test to do it, as you want, the point is, what is the default value now?
In both cases and same as now you can still pass "" to print nothing and it's OK.
By using null as default and passing "Log In" as param you will print a non translated string "Log In" (in any language).
By using "Log In" as default and passing "Log In" as param you will print a correctly translated string "Se connecter" (here in french).

Thanks

Attachments (2)

60668.phpdoc.diff��� (1.2 KB) - added by skithund 6 months ago.
60668.phpdoc.2.diff (1.2 KB) - added by skithund 6 months ago.

Download all attachments as: .zip

Change History (14)

#1 @swissspidy
8 months ago

  • Component changed from I18N to Login and Registration
  • Keywords good-first-bug added
  • Milestone changed from Awaiting Review to Future Release
  • Version set to 2.1

A null check looks reasonable to me.

<?php
if ( null === $title ) {
        $title = __( 'Log In' );
}

This ticket was mentioned in PR #6209 on WordPress/wordpress-develop by @mainetenance.


8 months ago
#2

  • Keywords has-patch added; needs-patch removed

#3 @audrasjb
8 months ago

  • Milestone changed from Future Release to 6.6
  • Owner set to audrasjb
  • Status changed from new to accepted

The proposed PR looks good to me. Thank you @mainetenance and congrats for your first patch.

Moving to milestone 6.6.

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


6 months ago

#5 @rajinsharwar
6 months ago

I was wondering if the null check should be defined at the start of the function before "global...", or if will it even make any difference.

#6 @audrasjb
6 months ago

  • Keywords commit added

It wouldn't make any difference :)
Let's ship this one as proposed.

#8 @audrasjb
6 months ago

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

Committed in [58209].

#9 @skithund
6 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

$title is now nullable

#10 @audrasjb
6 months ago

Good point, thanks!

#11 @audrasjb
6 months ago

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

In 58220:

Login and Registration: login_header() docblock update after [58209].

This changeset indicates that the $title parameter is now nullable.

Follow-up to [58209].

Props skithund.
Fixes #60668.

#12 @SergeyBiryukov
6 months ago

In 58224:

Docs: Clarify that the $wp_error parameter of login_header() is nullable.

Follow-up to [7991], [25701], [28792], [43457], [58209], [58220].

See #60668, #60699.

Note: See TracTickets for help on using tickets.