redandblue/rnb-ajax-login 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

redandblue/rnb-ajax-login

Composer 安装命令:

composer require redandblue/rnb-ajax-login

包简介

Plugin makes /wp-login.php AJAX accessible.

README 文档

README

The plugin basically hooks up to 'login_init', and listens to requests which have a Response-Type header set to 'json'. It also checks for $_REQUEST['RESPONSE_TYPE'], if for some reason you can't set the request headers.

Installing

The best way to install is using Composer.

composer require redandblue/rnb-ajax-login

Traditional methods work too.

Example

Code sample (ES6+, production usage requires you to use a Webpack or Rollup and Babel or Bublé):

<form action="/wp-login.php">
  <!-- The input names are critical! -->
  <input type="text" name="log">
  <input type="password" name="pwd">
  <input type="checkbox" name="rememberme" value="forever">

  <!-- If you'd rather do it with an input. I'd recommend using the headers. -->
  <input type="hidden" name="RESPONSE_TYPE" value="json">
  <!-- Also note that this will kill the nojs-fallback. -->

  <input type="submit">
</form>
// ajax-login.js

import 'whatwg-fetch';

export default function(){
  const ajaxLogin = e => {
    const form = e.target;
    const data = new FormData(form);
    const headers = new Headers({
      'Response-Type': 'json'
    });

    fetch(form.action, {
      method: 'POST',
      body: data,
      headers: headers,
      credentials: 'include'
    })
    .then(response => response.json())
    .then(response => { 
      if(response.type === 'success'){
        console.log(response.message);
      } else {
        console.error(response.message);
      }
    });

    e.preventDefault();
  };

  Array.from(document.querySelectorAll('[action="/wp-login.php"]')).forEach(form => {
    form.addEventListener('submit', ajaxLogin);
  });
}
// main.js
import ajaxLogin from './ajax-login.js';
ajaxLogin();

This allows you to AJAXify any standard WP login form. If the user has JavaScript disabled, it will gracefully fallback to the vanilla WordPress way.

Logout

You can also log the current user out by sending a request to admin_ajax.php?action=wp_ajax_logout.

The response will be similar, with either success or error in the response.type.

统计信息

  • 总下载量: 143
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: gpl-2.0
  • 更新时间: 2016-10-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固