dtkwt62022 2013-10-31 14:46
浏览 19
已采纳

预先填充wp-login.php用户名

I have a WP site whereby i send customers an email with a link to /my-quotes/ this then, has the following code:

<?
if (!is_user_logged_in()): ?>
<meta http-equiv="refresh" content="0;URL=<? echo wp_login_url(get_permalink()); ?>">
<? endif; ?>

What i want to do is, give the link in the email like: /my-quotes/?login=myusername

and that 'myusername' is the login fields value to save the user re-typing it.

I've had a look in wp-login.php and cant work out where to populate the login fields using $_GET, can anyone advise on a solution?

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • douyan4958 2013-10-31 14:51
    关注

    You should do it by hooking in to the login_form action, rather than modifying wp-login.php, which will get overwritten at next update.

    You can add this code to your theme's functions.php file:

    // As part of WP login form construction, call our function
    add_filter ( 'login_form', 'login_form_prepop' );
    
    function login_form_prepop(){
        // Output jQuery to pre-fill the box
    
        if ( isset( $_REQUEST['myusername'] ) ) { // Make sure a username was passed
    ?>
    <!-- Small jQuery script to set the value of the input field to your variable -->
    
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready( function(){
        $("#user_login").val( '<?php echo( $_REQUEST['myusername'] ); ?>' );
    });
    </script>
    <?php
        }
    }
    

    Then update your code to include the variable:

    <?
    if (!is_user_logged_in()): ?>
    <meta http-equiv="refresh" content="0;URL=<? echo wp_login_url(get_permalink()); ?>?myusername=username">
    <? endif; ?>
    

    If the jQuery footprint is too much, you can achieve the same with JavaScript:

    <script type="text/javascript">
    var el = document.getElementById("user_login");
    el.value = "<?php echo( $_REQUEST['myusername'] ); ?>";
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)