generoi/wp-paywall

付费墙插件

安装: 73

依赖: 0

建议: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:wordpress-plugin

dev-master 2024-09-20 17:01 UTC

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/