sillynet/adretto-consent-tools
使用 Adretto 的 WordPress consent-tools 库的后端。
0.1.1
2022-11-22 00:01 UTC
Requires
- php: >=7.4
- htmlburger/carbon-fields: ^3.3
- psr/container: ^1.1
- sillynet/adretto: ^0.2
Requires (Dev)
- phpstan/phpstan: ^1.4
- szepeviktor/phpstan-wordpress: ^1.0
README
使用 Adretto 的 WordPress consent-tools 库的后端。
安装
通过 composer
> composer require sillynet/adretto-consent-tools
这个库是 Adretto WordPress ADR 框架的扩展,所以您需要安装并设置 Adretto。
请确保您有 Composer 自动加载或替代类加载器。
Carbon Fields
此包使用 CarbonFields 来生成设置页面。不幸的是,当在主题根目录外使用时,CarbonFields 的设置可能有些棘手。如果您的主题文件位于 public/wp-content/themes/<yourtheme>/
,并且您的 composer.json 和 vendor/
目录在那里,那么您就没有问题。
然而,如果您在主题目录外维护 Composer 依赖项,或者使用某些符号链接设置,您可能会遇到麻烦。最简单的解决方案是在设置和构建过程中添加一个步骤,使 CF 的 JS 和 CSS 资产在已知路径下公开可用。
- 作为您构建流程的一部分,将整个
vendor/htmlburger/carbon-fields
目录复制到public/wp-content
(或者您也可以只复制*.js
和*.css
文件,但您必须保留目录结构)。一个简单的解决方案是实际使用您的主题目录,所以让我们以public/wp-content/themes/<mytheme>/vendor/cf
作为例子。 - 通过设置一个常量,在 CF “启动”之前告诉 CarbonFields 它可以找到其资产的位置,在大多数情况下,在您的
functions.php
顶部附近设置即可。define('Carbon_Fields\DIR', get_theme_file_path('vendor/cf'));
使用
在您的 Adretto 配置文件中加载扩展
# .config.yaml extensions: - Sillynet\\ConsentTools\\ConsentToolsExtension
您将在 WordPress 一般设置标签页下找到一个设置页面,您可以在其中配置 @gebruederheitz/consent-tools
的同意管理服务。
在设置 consent-tools 时,您可以通过 /wp-json/sillynet/v1/consent-management/config?lang=en
获取配置,它将返回以下形状的对象
type ServiceConfig = { // regular fields prettyName?: string; // The pretty name for the service as it // should be shown to user, in placeholder // templates or settings modals cmpServiceId?: string; // The ID of this service as defined by // by the CMP used. If you're running // consent-tools in standalone mode, // this can simply be ignored. privacyPolicySection?: string; // An anchor for linking to this specific // service's section on the privacy policy // page. // translated fields, these will differ based on the requested language // ("en" in this example) titleText?: string; // override for default titleText below buttonText?: string; // override for default buttonText below description?: string; // override for default description below } type ConsentToolsConfig = { default: { titleText: string; // Default text to be displayed in the // placeholder element's heading if not // overridden by the service's config. description: string; // Default text to be displayed in the // placeholder element's body. May contain // %templateTags%. buttonText: string; // Default text to be displayed in the // placeholder element's "consent" button. }, types: { [serviceId: string]: ServiceConfig } }
开发
依赖关系
- PHP >= 7.4
- Composer 2.x
- NVM 和 nodeJS LTS(v16.x)
- 可选:GNU Make(或替代品)
Makefile
Makefile 覆盖了大多数日常开发任务。