【问题标题】:How to create Forgot password user endpoint API in WordPress?如何在 WordPress 中创建忘记密码用户端点 API?
【发布时间】:2022-11-23 19:14:00
【问题描述】:

我们如何使用自定义代码为忘记密码的用户端点 API 生成密码?

【问题讨论】:

    标签: wordpress wordpress-rest-api


    【解决方案1】:

    我使用了这个插件:bdv密码重置

    您可以简单地重置密码并设置新密码。我举了一些代码的例子:

    重设密码:

    $.ajax({
      url: '/wp-json/bdpwr/v1/reset-password',
      method: 'POST',
      data: {
        email: 'example@example.com',
      },
      success: function( response ) {
        console.log( response );
      },
      error: function( response ) {
        console.log( response );
      },
    });
    

    设置新密码:

    $.ajax({
      url: '/wp-json/bdpwr/v1/set-password',
      method: 'POST',
      data: {
        email: 'example@example.com',
        code: '1234',
        password: 'Pa$$word1',
      },
      success: function( response ) {
        console.log( response );
      },
      error: function( response ) {
        console.log( response );
      },
    });
    

    【讨论】:

      【解决方案2】:
      function custom_random_password( $password) {
        // here you make your password generation
        $password = 'your-password';
        return $password; 
      }
      add_filter( 'random_password', 'custom_random_password' );
      

      【讨论】:

        猜你喜欢
        • 2014-06-19
        • 2020-03-15
        • 2014-06-27
        • 2020-04-08
        • 2015-11-16
        • 1970-01-01
        • 2020-11-14
        • 1970-01-01
        相关资源
        最近更新 更多