跳至内容
WordPress.org

China 简体中文

  • 主题
  • 插件
  • 新闻
    • 文档
    • 论坛
  • 关于
  • 获取 WordPress
获取 WordPress
WordPress.org

Plugin Directory

Headless Login Guard

  • 提交插件
  • 我的收藏
  • 登录
  • 提交插件
  • 我的收藏
  • 登录

Headless Login Guard

作者:Andrew Wilkinson
下载
  • 详情
  • 评价
  • 安装
  • 开发进展
支持

描述

A lightweight plugin that forces login for backend access in a headless WordPress setup. Keeps your WordPress dashboard private while allowing your front end (e.g. Astro, Next.js) to pull content via GraphQL/REST.

What it does

  • Requires authentication for /wp-admin/ and other backend pages
  • Always allows the login page to avoid redirect loops
  • Leaves key endpoints open for headless use:
    • /wp-json/ (REST API)
    • /graphql (WPGraphQL)
    • /wp-admin/admin-ajax.php (AJAX)
    • /wp-cron.php (cron)
    • /robots.txt
    • /sitemap*.xml (sitemaps and indexes)
    • /wp-content/uploads/* (media)
    • /favicon.ico
    • /newrelic (New Relic monitoring)
  • Logged-in users visiting the backend root get redirected to the dashboard
  • Works with Bedrock layouts (handles root path vs /wp/)

Use case

  • WordPress is the content backend
  • Public site is built with Astro/Next.js/etc
  • Editors log in to WordPress. Visitors never see the backend
  • Front end builds and live pages can still query GraphQL/REST without authentication

Customization

Developers can customize allowed endpoints using the force_login_allowed_patterns filter:

add_filter('force_login_allowed_patterns', function($patterns) {
    $patterns[] = '#^/healthz$#';           // custom health check
    $patterns[] = '#^/status$#';            // uptime checks
    $patterns[] = '#^/wp-json/acf/v3/.*#';  // specific REST namespace
    return $patterns;
});

安装

  1. Upload the plugin files to the /wp-content/plugins/force-login directory, or install the plugin through the WordPress plugins screen directly.
  2. Activate the plugin through the ‘Plugins’ screen in WordPress.
  3. The plugin will automatically start protecting your backend – no configuration needed!

常见问题

I’m locked out! How do I access my site?

Visit /wp-login.php directly to sign in. The plugin always allows access to the login page.

My front-end requests are failing. What should I do?

Verify the endpoint is on the allow list. Check the plugin description for the default allowed patterns, or use the force_login_allowed_patterns filter to add custom endpoints.

Does this work with Bedrock?

Yes! The plugin correctly handles both standard WordPress installs and Bedrock layouts where the site URL and home URL may differ.

Can I add custom endpoints?

Yes, use the force_login_allowed_patterns filter to add your own regex patterns for additional endpoints that should remain public.

评价

此插件暂无评价。

贡献者及开发者

「Headless Login Guard」是开源软件。 以下人员对此插件做出了贡献。

贡献者
  • Andrew Wilkinson

帮助将「Headless Login Guard」翻译成简体中文。

对开发感兴趣吗?

您可以浏览代码,查看SVN仓库,或通过RSS订阅开发日志。

更新日志

1.0.1

  • Added: New Relic monitoring endpoint allowlist pattern (/newrelic) to support APM monitoring
  • Added: WordPress.org plugin directory compatibility
  • Added: Proper plugin structure with activation/deactivation hooks
  • Added: Filter hook for customizing allowed patterns
  • Improved: Code organization and documentation

1.0.0

  • Initial release
  • Restricts backend (/wp-admin/) to authenticated users
  • Allows GraphQL and REST API endpoints for headless front-ends
  • Basic whitelist of essential endpoints (cron, ajax, robots.txt, sitemaps, uploads)

额外信息

  • 版本 1.0.1
  • 最后更新:1 周前
  • 活跃安装数量 不到10
  • WordPress 版本 6.0 或更高版本
  • 已测试的最高版本为 6.9.4
  • PHP 版本 8.1 或更高版本
  • 语言
    English (US)
  • 标签
    GraphQLheadlessloginrest-apisecurity
  • 高级视图

评级

尚未提交反馈。

Your review

查看全部评论

贡献者

  • Andrew Wilkinson

支持

有话要说吗?是否需要帮助?

查看支持论坛

  • 关于
  • 新闻
  • 主机
  • 隐私
  • 陈列窗
  • 主题
  • 插件
  • 区块样板
  • 学习
  • 支持
  • 开发者
  • WordPress.tv ↗︎
  • 参与
  • 活动
  • 捐赠 ↗
  • 未来五分计划
  • WordPress.com ↗
  • Matt ↗
  • bbPress ↗
  • BuddyPress ↗
WordPress.org
WordPress.org

China 简体中文

  • 关注我们的 X(原 Twitter)账号
  • 访问我们的 Bluesky 账号
  • 关注我们的 Mastodon 账号
  • 访问我们的 Threads 账号
  • 访问我们的 Facebook 公共主页
  • 关注我们的 Instagram 账号
  • 关注我们的 LinkedIn 主页
  • 访问我们的 TikTok 账号
  • 访问我们的 YouTube 频道
  • 访问我们的 Tumblr 账号
代码如诗
The WordPress® trademark is the intellectual property of the WordPress Foundation.