WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 4 weeks ago

Last modified 41 hours ago

#35449 closed enhancement (fixed)

Add ability to filter back to blog link on login page

Reported by: ebinnion Owned by: adamsilverstein
Milestone: 5.7 Priority: normal
Severity: normal Version:
Component: Login and Registration Keywords: has-patch has-screenshots commit has-dev-note
Focuses: Cc:

Description

There is currently not a way to filter the "Back to {site_name_here}" link at the bottom of the /wp-login.php page.

Depending on context, a user may want to change the text that is displayed in that link as well as the link itself. One example would be that on WordPress.com, we use this wording: "Return to {site_name_here}".

I propose that we add a filter that will allow developers to customize that link depending on context.

Attachments (7)

35449.diff (1021 bytes) - added by ebinnion 5 years ago.
Adds back_to_blog_link filter to login footer.
35449.2.diff (1.0 KB) - added by adamsilverstein 5 years ago.
35449.3.diff (1.1 KB) - added by audrasjb 2 months ago.
Refreshes the patch against trunk and recent string changes
Capture d’écran 2020-12-18 à 00.40.08.png (73.6 KB) - added by audrasjb 2 months ago.
Before 35449.3.diff
Capture d’écran 2020-12-18 à 00.40.26.png (70.5 KB) - added by audrasjb 2 months ago.
After 35449.3.diff using the new filter
after-screenshot-back-to-home.png (66.8 KB) - added by hellofromTonya 6 weeks ago.
After applying '← Back to home' to the filter
35449.1.diff (1.1 KB) - added by audrasjb 5 weeks ago.
Add display param to get_bloginfo( 'title' )

Download all attachments as: .zip

Change History (27)

@ebinnion
5 years ago

Adds back_to_blog_link filter to login footer.

#1 @ebinnion
5 years ago

  • Keywords has-patch added

#2 @adamsilverstein
5 years ago

  • Keywords dev-feedback added
  • Owner set to adamsilverstein
  • Status changed from new to assigned

@ebinnion Thanks for the patch! This seems like a useful enhancement.

In 35449.2.diff I did a tiny bit of cleanup:

  • removed title attribute from link, we are trying not to use those and are even actively removing their existing use from core, see #24766
  • removed escaping from translations, these are considered trusted in core
  • added a translator comment so the context of %s is clear
  • slight update to the filter description to mach how other filters are described
  • regenerate from trunk folder (up one level)
Last edited 5 years ago by adamsilverstein (previous) (diff)

#3 @DrewAPicture
5 years ago

  • Milestone changed from Awaiting Review to Future Release

@adamsilverstein: 35449.2.diff introduces an inconsistency in changing the default "Back to %s" string to "Return to %s" while naming the filter "back_to_blog_link". We should probably pick one :-)

#4 @chriscct7
5 years ago

  • Version trunk deleted

#5 @adamsilverstein
3 months ago

  • Milestone set to 5.7

@audrasjb
2 months ago

Refreshes the patch against trunk and recent string changes

#6 follow-up: @audrasjb
2 months ago

  • Keywords has-screenshots added

35449.3.diff refreshes the patch against trunk and against some string changes that happened in WP 5.6.

I tested it using the following snippet:

<?php
function my_login_site_html_link( $link ) {
        return '<a href="' . esc_url( home_url( '/' ) ) . '">' . __( 'Back to the website', 'my-theme' ) . '</a>';
}
add_filter( 'login_site_html_link', 'my_login_site_html_link', 10, 1 );

Works fine (see before/after screenshots below).

My only concern is about the name of the filter. Any thought?

@audrasjb
2 months ago

Before 35449.3.diff

@audrasjb
2 months ago

After 35449.3.diff using the new filter

#7 in reply to: ↑ 6 @hellofromTonya
6 weeks ago

Replying to audrasjb:

My only concern is about the name of the filter. Any thought?

The filter is filtering the HTML link <a> element for going back to the root of the website. And it's on the login page.

I think 'login_site_html_link' concisely captures what is being filtered.

@hellofromTonya
6 weeks ago

After applying '&larr; Back to home' to the filter

#8 @hellofromTonya
6 weeks ago

  • Keywords dev-feedback removed

Tested. Works for me ✅

Used this testing code:

<?php
add_filter(
        'login_site_html_link',
        function () {
                return sprintf(
                        '<a href="%s">%s</a>',
                        esc_url( home_url( '/' ) ),
                        /* translators: %s: Site title. */
                        esc_html_x( '&larr; Back to home', 'site' )
                );
        }
);

@audrasjb the patch escapes the URL, but not the translated string.

<?php
_x( '&larr; Go to %s', 'site' )

Shouldn't this be changed to?

<?php
esc_html_x( '&larr; Go to %s', 'site' )

#9 @audrasjb
6 weeks ago

  • Keywords commit added

Hey @hellofromTonya thanks for testing the patch!
There is no need to escape Core translation strings, as Core translations are validated by trusted editors (General Translation Editors of each Locale) :)

Given the patch has been tested, let's mark this for commit

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


5 weeks ago

#11 @sabernhardt
5 weeks ago

  • Keywords needs-refresh added

Small change: get_bloginfo() needs the display context (see #26811).

get_bloginfo( 'title', 'display' )

#12 @audrasjb
5 weeks ago

  • Keywords commit removed

@audrasjb
5 weeks ago

Add display param to get_bloginfo( 'title' )

#13 @audrasjb
5 weeks ago

  • Keywords commit added; needs-refresh removed

Thanks @sabernhardt, this is a good enhancement too. Patch updated accordingly.

#14 @adamsilverstein
4 weeks ago

35449.1.diff looks good! I'll give this a final test suite run and get it committed.

#16 @adamsilverstein
4 weeks ago

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

In 50117:

Login: Enable filtering the back to blog link.

Add a new login_site_html_link filter that developers can use to adjust the "Go to site" link displayed in the login page footer.

Props ebinnion, DrewAPicture, audrasjb, hellofromTonya, sabernhardt. 
Fixes #35449.

#17 @adamsilverstein
4 weeks ago

  • Keywords needs-dev-note added

#18 @adamsilverstein
4 weeks ago

Marking this "needs dev note" to make sure we document this filter in the release notes.

#20 @audrasjb
41 hours ago

  • Keywords has-dev-note added; needs-dev-note removed
Note: See TracTickets for help on using tickets.