deliciousbrains/wp-auto-login
Composer 安装命令:
composer require deliciousbrains/wp-auto-login
包简介
WordPress library for generating automatic login URLs for users
README 文档
README
WordPress library for generating automatic login URLs for users
Requirements
This package is designed to be used on a WordPress site project, not for a plugin or theme.
It needs to be running PHP 5.3 or higher.
It requires the deliciousbrains/wp-migration package and so the site will need to be set up to run wp dbi migrate as a last stage build step in your deployment process.
You should also run wp dbi migrate after updating the package to make sure you have up to date database tables.
It automatically purges expired keys from the database daily, and there are WP-CLI commands to:
- Manually purge expired keys
- Manually generate an auto-login URL
Installation
composer require deliciousbrains/wp-auto-login- Bootstrap the package by adding
\DeliciousBrains\WPAutoLogin\AutoLogin::instance();to an mu-plugin.
There are two parameters you can pass when bootstrapping the package:
- A custom WP-CLI parent command name (default:
'dbi') - A global default expiry time in seconds (default:
10368000- 120 days)
These options are explained below.
Use
To generate a URL that will automatically login a user and land them at a specific URL use this function:
dbi_get_auto_login_url( $destination_url, $user_id, [$query_params], [$expiry], [$one_time] );
The URL will expire in 120 days. However, you can pass the number of seconds the URL will be valid for as the fourth argument, e.g valid for 1 day:
dbi_get_auto_login_url( $destination_url, $user_id, $query_params, 86400 );
You can also specify your own global default for expiry when bootstrapping the package as explained in the "Installation" section above. Use:
\DeliciousBrains\WPAutoLogin\AutoLogin::instance( 'dbi', <expiry_in_seconds> );
There is also an option to generate links that can only be used once:
dbi_get_auto_login_url( $destination_url, $user_id, $query_params, null, true );
WP-CLI
There are two WP-CLI commands.
The commands are added as sub-commands of a parent command. By default the parent command is dbi (for example: wp dbi purge_autologin_keys). But this can be changed when you bootstrap the package.
For example, doing:
\DeliciousBrains\WPAutoLogin\AutoLogin::instance( 'autologin', <expiry_in_seconds> );
will make the commands to be like:
wp autologin purge_autologin_keys
purge_autologin_keys
This command purges any expired keys from the WordPress database. On most sites this happens daily, automatically, with a WP-Cron task. But if you have disabled WP-Cron or want to do this manually for whatever reason then this WP-CLI command lets you do it:
wp dbi purge_autologin_keys
auto_login_url
This command manually generates an auto-login URL that logs a specified user in and sends them to a specified URL.
wp dbi auto_login_url <user_id> <url> [--expiry=<seconds>]
The default expiry is used, but you can override it for each link that you create with this command by specifying your own expiry in seconds.
Example:
wp dbi auto_login_url 12345 https://example.com/dashboard --expiry=21600
Will generate a link that logs in the user with ID 12345 and takes them to https://example.com/dashboard. The link will be valid for 6 hours.
You can add --one-time to generate a single-use link:
wp dbi auto_login_url 12345 https://example.com/dashboard --one-time
deliciousbrains/wp-auto-login 适用场景与选型建议
deliciousbrains/wp-auto-login 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.98k 次下载、GitHub Stars 达 16, 最近一次更新时间为 2019 年 08 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 deliciousbrains/wp-auto-login 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 deliciousbrains/wp-auto-login 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4.98k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2019-08-06