livy / plumbing-normalize-links
在 ACF 中规范化 WordPress 的原生 "链接" 输出。
1.6.1-alpha
2020-11-10 20:35 UTC
Requires
- php: ~7.3
Requires (Dev)
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-09-21 21:14:36 UTC
README
这个小包的目的是摄入由 ACF 的 "链接" 字段类型 生成的链接数组,对它们进行一些逻辑处理,并提供一个优雅的接口来交互这些数据。它也可以接受纯字符串形式的 URL。
使用方法
ACF 字段$Link = new Normalized(get_field('some_link')); $Link->valid(); //whether or not this is a "valid" link $Link->url(); // the URL of the link $Link->label(); // the "title" set for this link $Link->newTab(); // whether this link should be opened in a new tab $Link->probablyExternal() // if the link is (probably) external or not简单字符串
$Link = new Normalized('https://www.alwaysblank.org');
设置
支持一些设置,可以在实例化时传递。
$Link = new Normalized(get_field('some_link'), [ 'label' => "Learn More", // Used as a fallback if there is no `title.` 'external_in_new_tab' => true, // Always open external links in new tab 'validate' => [ 'url' => false, 'label' => false, ], // Validate url and/or label ]);
label 默认为 "了解更多",external_in_new_tab 默认为 true。 validate 默认不验证输入。您可以指定要验证的项目(url 或 label),或将 validate 设置为 true 以验证所有项目。