Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 ! " ? $ % ^ &amp; ).'); ?></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
1  
"I want to show hidden password fields": what do you mean by that? Turn the fields into regular text fields? –  brasofilo Jan 10 '13 at 9:57

1 Answer 1

show_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 );
share|improve this answer
    
Thank you for fast reply, @bungeshea ! apply_filters actually calls the hook with specified parameters and returns result. I think result of apply_filters('show_password_fields', true) equals false, and this is a reason why password fields now are hidden. In your code must be two underscores '__return_false', and for my regret it also doesn't work. Could you please check if it works with your blog? –  Pavel K Jan 10 '13 at 9:30
    
You're right about using two underscores. See my updated answer for a possible solution to your issue –  bungeshea Jan 10 '13 at 9:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.