WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 2 years ago

#21133 closed enhancement (fixed)

Add body classes and 'login_body_class' filter to wp-login.php

Reported by: husobj Owned by: nacin
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.4
Component: General Keywords: has-patch
Focuses: Cc:

Description

The body class for the login page is hardcoded and simply outputs 'login' no matter what the context - ie login, register, forgotten password etc.

It would make more sense to add additional classes for the context and also make it filterable so that styling can be tweaked for register/login/forgotten password etc - I wrote this patch in response to requirements I had to style the register layout differently to the login.

My attached patch adds additional classes for the context.
(It retains the 'login' class throughout - this is required anyway for backwards compatibility)

It also adds a new filter 'login_body_class' in a similar way to 'body_class' and 'admin_body_class'

Attachments (5)

21133.patch (1.2 KB) - added by husobj 3 years ago.
21133.2.patch (1.9 KB) - added by SergeyBiryukov 3 years ago.
21133.3.diff (2.7 KB) - added by kobenland 3 years ago.
21133.4.patch (2.8 KB) - added by SergeyBiryukov 3 years ago.
21133.diff (1.1 KB) - added by nacin 2 years ago.

Download all attachments as: .zip

Change History (15)

@husobj3 years ago

@SergeyBiryukov3 years ago

comment:1 @SergeyBiryukov3 years ago

To reduce code duplication, 21133.2.patch introduces _get_login_action() and mirrors admin_body_class filter a bit closer.

comment:2 @husobj3 years ago

Yep, that's definitely more tidy

comment:3 @SergeyBiryukov3 years ago

  • Milestone changed from Awaiting Review to 3.5

@kobenland3 years ago

comment:4 @kobenland3 years ago

Talking about tidiness, I like the body_class() implementation a lot more than how it's done in the admin.
21133.3.diff picks up Sergey's _get_login_action(), too.

@SergeyBiryukov3 years ago

comment:5 @SergeyBiryukov3 years ago

21133.4.patch adds a missing !is_array( $class ) check before preg_split().

comment:6 @kobenland3 years ago

Uh, good eye! Wonder where that went :)

@nacin2 years ago

comment:7 @nacin2 years ago

I think we can keep this much simpler. admin_body_class is weird because it doesn't deal with an array of classes, but we could make it deal with an array here. How about 21133.diff?

comment:8 follow-up: @husobj2 years ago

I definitely prefer the array approach like the body_class filter.

Is using the global $action variable preferable to the _get_login_action() in previous patches? It's certainly more tidy

Maybe just needs an 'rtl' class adding too using is_rtl() like previous patches.

Other than that I like nacin's patch

comment:9 in reply to: ↑ 8 @nacin2 years ago

Replying to husobj:

Is using the global $action variable preferable to the _get_login_action() in previous patches? It's certainly more tidy

wp-login.php is a pretty messy file as it is. Checking the global seemed the least intrusive way to do this.

Maybe just needs an 'rtl' class adding too using is_rtl() like previous patches.

I'm fine with that.

comment:10 @nacin2 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In [22000]:

Add a login_body_class filter to login_header(). fixes #21133.

Note: See TracTickets for help on using tickets.