I want to show hidden password fields on registration form. I found that these fields are already present in /wp-admin/user-new.php
<?php if ( apply_filters('show_password_fields', true) ) : ?>
<tr class="form-field form-required">
<th scope="row"><label for="pass1"><?php _e('Password'); ?> <span class="description"><?php /* translators: password input field */_e('(twice, required)'); ?></span></label></th>
<td><input name="pass1" type="password" id="pass1" autocomplete="off" />
<br />
<input name="pass2" type="password" id="pass2" autocomplete="off" />
<br />
<div id="pass-strength-result"><?php _e('Strength indicator'); ?></div>
<p class="description indicator-hint"><?php _e('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ & ).'); ?></p>
</td>
</tr>
<tr>
<th scope="row"><label for="send_password"><?php _e('Send Password?') ?></label></th>
<td><label for="send_password"><input type="checkbox" name="send_password" id="send_password" <?php checked( $new_user_send_password ); ?> /> <?php _e('Send this password to the new user by email.'); ?></label></td>
</tr>
<?php endif; ?>
I assumed that show_password_fields is a function, that returns some value, so I can change its behavior with filters. Then I add following to my functions.php:
add_filter( 'show_password_fields', function(){return true} );
but nothing happend. Is it possible to do it with one or two lines? Thanks in advance!
I want to show hidden password fields on registration form. I found that these fields are already present in /wp-admin/user-new.php
<?php if ( apply_filters('show_password_fields', true) ) : ?>
<tr class="form-field form-required">
<th scope="row"><label for="pass1"><?php _e('Password'); ?> <span class="description"><?php /* translators: password input field */_e('(twice, required)'); ?></span></label></th>
<td><input name="pass1" type="password" id="pass1" autocomplete="off" />
<br />
<input name="pass2" type="password" id="pass2" autocomplete="off" />
<br />
<div id="pass-strength-result"><?php _e('Strength indicator'); ?></div>
<p class="description indicator-hint"><?php _e('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ & ).'); ?></p>
</td>
</tr>
<tr>
<th scope="row"><label for="send_password"><?php _e('Send Password?') ?></label></th>
<td><label for="send_password"><input type="checkbox" name="send_password" id="send_password" <?php checked( $new_user_send_password ); ?> /> <?php _e('Send this password to the new user by email.'); ?></label></td>
</tr>
<?php endif; ?>
I assumed that show_password_fields is a function, that returns some value, so I can change its behavior with filters. Then I add following to my functions.php:
add_filter( 'show_password_fields', function(){return true} );
but nothing happend. Is it possible to do it with one or two lines? Thanks in advance!
Share Improve this question asked Jan 10, 2013 at 7:44 Pavel KPavel K 1012 silver badges7 bronze badges 1- 1 "I want to show hidden password fields": what do you mean by that? Turn the fields into regular text fields? – brasofilo Commented Jan 10, 2013 at 9:57
2 Answers
Reset to default 1show_passwords_fields
actually is a filter! You can hook into it as you did above, using an anonymous function:
add_filter( 'show_password_fields', function(){return true} );
You can also write a function, and use it as a callback:
function wpse_79994_show_password_fields() {
return true;
}
add_filter( 'show_password_fields', 'wpse_79994_show_password_fields' );
However, as are only returning a boolean (true or false) value, you can do it like so:
add_filter( 'show_password_fields', '__return_true' );
Now, I understand that all of this talk about filters doesn't actually solve your problem. The code you use above should, and does work, eccept you are returning true
. As you can see from the apply_filters()
function in the first piece of code in your question, true
is actually the default value: you aren't actually changing anything!
If you wanted the result of apply_filters('show_password_fields', true )
to be false, you can use this code:
add_filter( 'show_password_fields', '__return_false' );
Edit: The reason that, even with your filter, apply_filters('show_password_fields', true )
is still returning false must be because a filter in one of your plugins is changing it to false after your filter is applied. You can override this by increasing the priority of your filter:
add_filter( 'show_password_fields', '__return_true', 999 );
Hi You can user this plugin for add password field in registration https://wordpress/plugins/as-password-field-in-default-registration-form/
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744660146a4586410.html
评论列表(0条)