如何在不带插件的注册表上显示密码域

时间:2013-01-10 作者:Pavel K

我想在注册表上显示隐藏的密码字段。我发现这些字段已经存在于/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; ?>
我假设show\\u password\\u fields是一个函数,它返回一些值,因此我可以使用过滤器更改其行为。然后我将以下内容添加到我的函数中。php:

add_filter( \'show_password_fields\', function(){return true} );
但什么都没发生。可以用一条或两条线吗?提前感谢!

2 个回复
SO网友:shea

show_passwords_fields 实际上是一个过滤器!您可以使用匿名函数如上所述钩住它:

add_filter( \'show_password_fields\', function(){return true} );
您还可以编写函数,并将其用作回调:

function wpse_79994_show_password_fields() {
    return true;
}
add_filter( \'show_password_fields\', \'wpse_79994_show_password_fields\' );
但是,由于只返回布尔值(true或false),您可以这样做:

add_filter( \'show_password_fields\', \'__return_true\' );

现在,我明白所有关于过滤器的讨论实际上并不能解决你的问题。上面使用的代码应该有效,除非返回true. 正如您从apply_filters() 函数在问题的第一段代码中,true 实际上是默认值:you aren\'t actually changing anything!

如果你想知道apply_filters(\'show_password_fields\', true ) 如果为false,可以使用以下代码:

add_filter( \'show_password_fields\', \'__return_false\' );
<小时>Edit: 原因是,即使使用过滤器,apply_filters(\'show_password_fields\', true )still 返回false肯定是因为应用过滤器后,某个插件中的过滤器将其更改为false。您可以通过提高过滤器的优先级来覆盖此选项:

add_filter( \'show_password_fields\', \'__return_true\', 999 );

SO网友:Malay Solanki

您好,您可以使用此插件在注册中添加密码字段https://wordpress.org/plugins/as-password-field-in-default-registration-form/

结束

相关推荐

WP_GENERATE_PASSWORD设置密码,但无法使用创建的密码登录

Im创建了一个简单的登录/注册页面,其中包含了用户调节和引导wp,用于繁重的工作。我可以将新用户添加到数据库中,并创建密码并对其进行哈希运算,但当我使用该帐户登录时,密码将不起作用。我被难住了。。。有人看到我丢了什么吗?require_once( ABSPATH . WPINC . \'/registration.php\' ); $user_pass = wp_generate_password(); $userdata = array( \'user_pass\' =>