You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add .wp-element-button class to Login/out form button output #50466
To remain consistent and provide theme authors the ability to style all types of buttons in theme.json elements, I recommend adding the .wp-element-button class to the output of the Login/out block. When that block is placed onto a page, and the Settings > Display login as form is selected, the output of the button is:
Was just coming here to report this. Aside from recreating the button styles, I copied over this code from the default comments form inputs and applied it:
We'd need to be able to add a class to the submit in wp_login_form(), then use wp_theme_get_element_class_name( 'button' ) like the post-comments-form does (but that's not possible in core).
You can currently set an ID, but not a class. I don't think we'd want to write to login_form_bottom, right?
It looks like login_form_bottom just appends HTML to the bottom of the form. The other consideration would be the HTML tag processor, but it doesn't currently support nested tags.
We probably need a default $args parameter we can pass in to avoid trying to hack it in via regex.
I don't think the tag processor can target something like the name or id attributes of an <input> element, so my code attempts to find the wrapping <p class="login-submit"> first. Then, targets the first <input>. I wouldn't normally like targeting the first <input> there, but it doesn't look like the wp_login_form() final output can be filtered before it gets to the block, so I feel like it should be reliable. Could definitely use some testing.
I don't think there is a PR linked to this issue, but I think we need to look into how to solve this problem.
The fundamental problem is that this block uses the wp_login_form() function for rendering, and the wp_login_form() function does not have an option to assign a class name to the submit button.
I think a few approaches could be:
Use WP_HTML_Tag_Processor to inject a class into the submit button
Add a class for the submit button to the wp_login_form() function's processing itself. That is, here.
Add an option to the wp_login_form() function to add a class name to the submit button.
Don't use the wp_login_form() function, create our own HTML for the block
In this issue, is it expected that the wp-element-button class will be added to classic themes as well? In other words, should the wp-element-button class be applied to the Submit button by default when the wp_login_form() function is used in a theme template?
Don't use the wp_login_form() function, create our own HTML for the block
I don't intend to use the form blocks for the Login/out block. I intend to output the exact same HTML that the wp_login_form() function would output, via the render_callback function.
A little off topic, but I thought it would be nice to have an option to temporarily switch the logged-in state on the block editor. Currently, only the text "Log out" is displayed and it is not possible to switch to a form:
Activity
richtabor commentedon May 9, 2023
Yikes, this form is rough all around. But yes, I agree with you here.
t-hamano commentedon May 11, 2023
I am wondering if it would be possible to apply the basic style to the input fields as well as the comment form, as shown below:
justintadlock commentedon Jun 28, 2023
Was just coming here to report this. Aside from recreating the button styles, I copied over this code from the default comments form inputs and applied it:
richtabor commentedon Jul 20, 2023
We'd need to be able to add a class to the submit in wp_login_form(), then use
wp_theme_get_element_class_name( 'button' )like the post-comments-form does (but that's not possible in core).You can currently set an ID, but not a class. I don't think we'd want to write to login_form_bottom, right?
justintadlock commentedon Jul 20, 2023
It looks like
login_form_bottomjust appends HTML to the bottom of the form. The other consideration would be the HTML tag processor, but it doesn't currently support nested tags.We probably need a default
$argsparameter we can pass in to avoid trying to hack it in via regex.justintadlock commentedon Feb 11, 2024
Had some time to tinker with this today and came up with a solution for adding the
.wp-element-buttonclass to the submit input/button.Note that this is running on WP 6.5/trunk and Gutenberg 17.7, and I haven't tested down to WP 6.4:
I don't think the tag processor can target something like the
nameoridattributes of an<input>element, so my code attempts to find the wrapping<p class="login-submit">first. Then, targets the first<input>. I wouldn't normally like targeting the first<input>there, but it doesn't look like thewp_login_form()final output can be filtered before it gets to the block, so I feel like it should be reliable. Could definitely use some testing.Adds the `.wp-element-form` class to login form button.
justintadlock commentedon Feb 29, 2024
Updated solution (props to @dmsnell for showing me how to do an advanced query here):
carolinan commentedon Jul 20, 2024
Is anything blocking this from being submitted as a PR? or is there an unlinked PR already?
t-hamano commentedon Jul 20, 2024
I don't think there is a PR linked to this issue, but I think we need to look into how to solve this problem.
The fundamental problem is that this block uses the
wp_login_form()function for rendering, and thewp_login_form()function does not have an option to assign a class name to the submit button.I think a few approaches could be:
WP_HTML_Tag_Processorto inject a class into the submit buttonwp_login_form()function's processing itself. That is, here.wp_login_form()function to add a class name to the submit button.wp_login_form()function, create our own HTML for the blockcarolinan commentedon Jul 29, 2024
I don't mind the HTML tag processor suggestion, but in my opinion the most flexible solution for theme developers would be
carolinan commentedon Jul 29, 2024
This trac ticket feels relevant for adding an option for a class name https://core.trac.wordpress.org/ticket/39927
carolinan commentedon Jul 29, 2024
Using the form blocks for the login form is not an option until these are stabilized.
t-hamano commentedon Jul 29, 2024
In this issue, is it expected that the
wp-element-buttonclass will be added to classic themes as well? In other words, should thewp-element-buttonclass be applied to the Submit button by default when thewp_login_form()function is used in a theme template?I don't intend to use the form blocks for the Login/out block. I intend to output the exact same HTML that the
wp_login_form()function would output, via therender_callbackfunction.A little off topic, but I thought it would be nice to have an option to temporarily switch the logged-in state on the block editor. Currently, only the text "Log out" is displayed and it is not possible to switch to a form: