generoi/wp-paywall 问题修复 & 功能扩展

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

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

generoi/wp-paywall

Composer 安装命令:

composer require generoi/wp-paywall

包简介

A paywall plugin

关键字:

README 文档

README

A paywall plugin

By default article content is behind the paywall but can be manually opted-out on a per-post setting. Pages are public but like article they can be opted-in manually.

If a page/post has manually configured a setting it will take precedence over everything else but categories can also set a default state for all content tagged with the category. This rule is inherited so if you tag a child-term it traverse ancestors until a preference is found. If nothing is found it defaults to the post-type rules where post is paywalled and page is not.

Out of the box paywalled content will show the login form but you can override this template in your theme.

Additionally there is a Paywalled content block which can be used to manually tailor which section of a page is behind the paywall while everything outside of it will be public. Note that using this block does NOT mark a page as paywalled, it only adjusts the content IF paywalled.

There's a integration with Yoast to output rich schema data according to Google's specifications. There's also a X-Robots-Tag: noarchive HTTP header sent.

To allow reverse proxies to differentiate paywelled content there's a Vary: X-Paywall-Accepted header and a X-Paywall-Access: 0|1 added to the response. For now this is also where bot whitelisting would happen for now.

Environment variables

  • PAYWALL_JWT_PRIVATE_KEY should be set to the absolute of path of a private key used to sign JWT payloads.

Constants

  • WP_PAYWALL_JWT_ENABLED can be set to false to disable adding the JWT auth cookie, for example if you need it regardless if the plugin is enabled or not. Defaults to enabled true if there is a PAYWALL_JWT_PRIVATE_KEY environment variable set.

Hooks

/**
 * 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);

Development

Install dependencies

composer install
npm install

Run the tests

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

Build assets

# 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

Translations

wp i18n make-pot . languages/wp-paywall.pot
wp i18n make-mo languages/

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固