generoi / wp-paywall
付费墙插件
dev-master
2024-09-20 17:01 UTC
Requires
- php: >=8.0.0
- firebase/php-jwt: ^6.10
- symfony/http-foundation: ^7.1
Requires (Dev)
- laravel/pint: ^1.17
- phpunit/phpunit: ^9.0
- wp-phpunit/wp-phpunit: ^6.6
- yoast/phpunit-polyfills: ^2.0
This package is auto-updated.
Last update: 2024-09-20 17:01:26 UTC
README
付费墙插件
默认情况下,文章内容位于付费墙之后,但可以在每个帖子设置中手动进行退订。页面是公开的,但像文章一样,也可以手动进行订阅。
如果页面/帖子已手动配置设置,它将优先于所有其他设置,但类别也可以为所有带有该类别的所有内容设置默认状态。此规则是继承的,因此如果您标记了一个子项,它将遍历祖先直到找到偏好设置。如果没有找到任何内容,则默认为帖子类型规则,其中post
是付费墙,而page
不是。
默认情况下,付费墙内容将显示登录表单,但您可以在主题中覆盖此模板。
此外,还有一个付费墙内容块,可以用于手动调整页面上的哪些部分位于付费墙之后,而其外部内容将是公开的。请注意,使用此块不会将页面标记为付费墙,它只会调整内容,如果它是付费的。
它与Yoast集成,根据谷歌的规范输出丰富的数据。还有一个发送的X-Robots-Tag: noarchive
HTTP头。
为了允许反向代理区分付费内容,响应中添加了Vary: X-Paywall-Accepted
头和X-Paywall-Access: 0|1
。目前,这也是bot白名单发生的地方。
环境变量
PAYWALL_JWT_PRIVATE_KEY
应设置为用于签名JWT有效负载的私钥的绝对路径。
常量
WP_PAYWALL_JWT_ENABLED
可以设置为false
来禁用添加JWT认证cookie,例如,如果您需要在插件启用或禁用时都使用它。默认值为启用true
如果设置了PAYWALL_JWT_PRIVATE_KEY
环境变量。
钩子
/** * Hook in early to return a header passed on from a reverse proxy. */ add_filter('wp-paywall/has-access', function (?bool $hasAccess, ?int $postId) { $proxyAuth = $_SERVER['X-Proxy-Valid-Auth'] ?? null; return $proxyAuth === '1'; }, 10, 2); /** * Remove default access rules and set your own. */ add_filter('wp-paywall/access-rules', function (array $rules, ?int $postId) { $rules = []; $rules[] = CustomAccess::class; return $rules; }, 10, 2); /** * Hook in early to return if paywall is applied or not. */ add_filter('wp-paywall/is-applied', function (?bool $isApplied = null, ?int $postId) { if ($postId === 1234) { return true; } return $isApplied; }, 10, 2);
开发
安装依赖项
composer install
npm install
运行测试
npm run lint
composer lint
# Setup WP-ENV
npm -g i @wordpress/env
wp-env start
# Run unit tests
wp-env run tests-cli --env-cwd=wp-content/plugins/wp-paywall ./vendor/bin/phpunit
# With Xdebug
wp-env stop
wp-env start --xdebug
wp-env run tests-cli --env-cwd=wp-content/plugins/wp-paywall ./vendor/bin/phpunit
构建资产
# Minified assets which are to be committed to git
npm run build:production
# Watch for changes and re-compile while developing the plugin
npm run start
翻译
wp i18n make-pot . languages/wp-paywall.pot
wp i18n make-mo languages/