显示密码功能最终会员专业表格

发布于 2025-01-29 02:09:11 字数 1725 浏览 1 评论 0原文

如何在我的表格中添加显示密码字段? 我在功能中尝试此代码,但没有工作 ADD_FILTER(“ um_confirm_user_password_form_edit_field”,“ um_user_password_ford_edit_field”,10,2); add_filter(“ um_user_password_form_edit_field”,“ um_user_password_form_edit_field”,10,2); 函数um_user_password_form_edit_field($ output,$ set_mode){

ob_start();
 ?>
<div id='um-field-show-passwords-<?php echo $set_mode;?>' style='text-align:right;display:block;'>
    <i class='um-faicon-eye-slash'></i>
    <a href='#'><?php _e("Show password","ultimate-member"); ?></a>
</div>
<script type='text/javascript'>
    jQuery('div[id="um-field-show-passwords-<?php echo $set_mode;?>"] a').click(function(){ 
     
        var $parent = jQuery(this).parent("div"); 
        var $form = jQuery(".um-<?php echo $set_mode;?> .um-form");

        $parent.find("i").toggleClass(function() {
            if ( jQuery( this ).hasClass( "um-faicon-eye-slash" ) ) {
                $parent.find("a").text('<?php _e("Hide password","ultimate-member"); ?>');
                jQuery( this ).removeClass( "um-faicon-eye-slash" )
                $form.find(".um-field-password").find("input[type=password]").attr("type","text");
               return "um-faicon-eye";
            }
             
            jQuery( this ).removeClass( "um-faicon-eye" );
            $parent.find("a").text('<?php _e("Show password","ultimate-member"); ?>');
            $form.find(".um-field-password").find("input[type=text]").attr("type","password");
          
            return "um-faicon-eye-slash";
        });

        return false; 

    });
</script>
<?php 
return $output.ob_get_clean();

}

How can I add show password field in my forms?
I try this code in my function but didn't work
add_filter("um_confirm_user_password_form_edit_field","um_user_password_form_edit_field", 10, 2 );
add_filter("um_user_password_form_edit_field","um_user_password_form_edit_field", 10, 2 );
function um_user_password_form_edit_field( $output, $set_mode ){

ob_start();
 ?>
<div id='um-field-show-passwords-<?php echo $set_mode;?>' style='text-align:right;display:block;'>
    <i class='um-faicon-eye-slash'></i>
    <a href='#'><?php _e("Show password","ultimate-member"); ?></a>
</div>
<script type='text/javascript'>
    jQuery('div[id="um-field-show-passwords-<?php echo $set_mode;?>"] a').click(function(){ 
     
        var $parent = jQuery(this).parent("div"); 
        var $form = jQuery(".um-<?php echo $set_mode;?> .um-form");

        $parent.find("i").toggleClass(function() {
            if ( jQuery( this ).hasClass( "um-faicon-eye-slash" ) ) {
                $parent.find("a").text('<?php _e("Hide password","ultimate-member"); ?>');
                jQuery( this ).removeClass( "um-faicon-eye-slash" )
                $form.find(".um-field-password").find("input[type=password]").attr("type","text");
               return "um-faicon-eye";
            }
             
            jQuery( this ).removeClass( "um-faicon-eye" );
            $parent.find("a").text('<?php _e("Show password","ultimate-member"); ?>');
            $form.find(".um-field-password").find("input[type=text]").attr("type","password");
          
            return "um-faicon-eye-slash";
        });

        return false; 

    });
</script>
<?php 
return $output.ob_get_clean();

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幸福%小乖 2025-02-05 02:09:11
<?php
add_filter( "um_confirm_user_password_form_edit_field", "um_user_password_form_edit_field", 10, 2 );
add_filter( "um_user_password_form_edit_field", "um_user_password_form_edit_field", 10, 2 );

function um_user_password_form_edit_field( $output, $set_mode ) {
    ob_start();
    ?>
    <div id='um-field-show-passwords-<?php echo $set_mode; ?>' style='text-align:right;display:block;'>
        <i class='um-faicon-eye-slash'></i>
        <a href='#'><?php _e( "Show password", "ultimate-member" ); ?></a>
    </div>
    <script type='text/javascript'>
        jQuery( document ).ready( function( $ ) {
            $( 'body' ).on( 'click', 'div#um-field-show-passwords-<?php echo $set_mode; ?> a', function() {
                var $parent = $( this ).parent( 'div' );
                var $form = $( '.um-<?php echo $set_mode; ?> .um-form' );

                $parent.find( 'i' ).toggleClass( function() {
                    if ( $( this ).hasClass( 'um-faicon-eye-slash' ) ) {
                        $parent.find( 'a' ).text( '<?php _e( "Hide password", "ultimate-member" ); ?>' );
                        $( this ).removeClass( 'um-faicon-eye-slash' )
                        $form.find( '.um-field-password' ).find( 'input[type=password]' ).attr( 'type', 'text' );
                        return 'um-faicon-eye';
                    }
                    $( this ).removeClass( 'um-faicon-eye' );
                    $parent.find( 'a' ).text( '<?php _e( "Show password", "ultimate-member" ); ?>' );
                    $form.find( '.um-field-password' ).find( 'input[type=text]' ).attr( 'type', 'password' );
                    return 'um-faicon-eye-slash';
                } );

                return false;
            } );
        } );
    </script>
    <?php
    return $output . ob_get_clean();
}

该代码旨在以WordPress中最终成员插件生成的形式为密码字段添加“显示密码”功能。这是代码所做的内容的分解:

两个过滤器钩子“ um_confirm_user_password_edit_field_field”和“ um_user_password_edit_field_field”,并用“ um_user_pass_password_edit_edit_field_field”功能定义并挂钩。假定这些过滤器钩被正确定义和钩在WordPress主题或插件中。

在“ um_user_password_form_edit_field”功能中,输出缓冲以OB_START()启动,以捕获生成的HTML。

创建了具有“ UM-Field-Show-Passwords” ID的元素,其中包含带有文本“显示密码”的图标和锚固链接。

包括一个JavaScript块来处理“显示密码”锚链接上的单击事件。它使用jQuery根据过滤器钩提供的$ set_mode参数来定位适当的DOM元素。

单击“显示密码”链接时,JavaScript代码通过将其类型属性从“密码”更改为“文本”,反之亦然。它还在显示密码时将锚链接的文本更新为“隐藏密码”,并在隐藏密码时“显示密码”。

然后,捕获的HTML输出和JavaScript代码将通过$输出参数和ob_get_clean()函数返回表单中的适当位置。

<?php
add_filter( "um_confirm_user_password_form_edit_field", "um_user_password_form_edit_field", 10, 2 );
add_filter( "um_user_password_form_edit_field", "um_user_password_form_edit_field", 10, 2 );

function um_user_password_form_edit_field( $output, $set_mode ) {
    ob_start();
    ?>
    <div id='um-field-show-passwords-<?php echo $set_mode; ?>' style='text-align:right;display:block;'>
        <i class='um-faicon-eye-slash'></i>
        <a href='#'><?php _e( "Show password", "ultimate-member" ); ?></a>
    </div>
    <script type='text/javascript'>
        jQuery( document ).ready( function( $ ) {
            $( 'body' ).on( 'click', 'div#um-field-show-passwords-<?php echo $set_mode; ?> a', function() {
                var $parent = $( this ).parent( 'div' );
                var $form = $( '.um-<?php echo $set_mode; ?> .um-form' );

                $parent.find( 'i' ).toggleClass( function() {
                    if ( $( this ).hasClass( 'um-faicon-eye-slash' ) ) {
                        $parent.find( 'a' ).text( '<?php _e( "Hide password", "ultimate-member" ); ?>' );
                        $( this ).removeClass( 'um-faicon-eye-slash' )
                        $form.find( '.um-field-password' ).find( 'input[type=password]' ).attr( 'type', 'text' );
                        return 'um-faicon-eye';
                    }
                    $( this ).removeClass( 'um-faicon-eye' );
                    $parent.find( 'a' ).text( '<?php _e( "Show password", "ultimate-member" ); ?>' );
                    $form.find( '.um-field-password' ).find( 'input[type=text]' ).attr( 'type', 'password' );
                    return 'um-faicon-eye-slash';
                } );

                return false;
            } );
        } );
    </script>
    <?php
    return $output . ob_get_clean();
}

The code is intended to add a "Show password" functionality to a password field in a form generated by the Ultimate Member plugin in WordPress. Here's a breakdown of what the code does:

Two filter hooks, "um_confirm_user_password_form_edit_field" and "um_user_password_form_edit_field", are defined and hooked with the "um_user_password_form_edit_field" function. These filter hooks are assumed to be properly defined and hooked in your WordPress theme or plugin.

Inside the "um_user_password_form_edit_field" function, output buffering is started with ob_start() to capture the generated HTML.

A element with an ID of "um-field-show-passwords" is created, which contains an icon and an anchor link with the text "Show password".

A JavaScript block is included to handle the click event on the "Show password" anchor link. It uses jQuery to target the appropriate DOM elements based on the $set_mode parameter provided by the filter hook.

When the "Show password" link is clicked, the JavaScript code toggles the visibility of the password field by changing its type attribute from "password" to "text" and vice versa. It also updates the text of the anchor link to "Hide password" when the password is shown, and "Show password" when the password is hidden.

The captured HTML output and JavaScript code are then returned to the appropriate location in the form via the $output parameter and ob_get_clean() function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文