flexpress / component-shortcode
此包的最新版本(v1.0.0)没有可用的许可信息。
WordPress 短码助手
v1.0.0
2014-08-13 14:50 UTC
This package is not auto-updated.
Last update: 2024-09-24 03:13:59 UTC
README
使用 Pimple 安装
短码组件使用两个类
- AbstractShortcode,您可以通过扩展它来创建短码。
- ShortcodeHelper,它为您钩入所有内容并注册短码。
让我们为这两个创建一个 pimple 配置
$pimple["documentLinkShortcode"] = function () {
return new DocumentLink();
};
$pimple['ShortcodeHelper'] = function ($c) {
return new ShortcodeHelper($c['objectStorage'], array(
$c["documentLinkShortcode"]
));
};
- 注意依赖项 $c['objectStorage'] 是一个 SPLObjectStorage
创建一个具体的短码类
创建一个具体的类,该类实现 AbstractShortcode 类并实现 getName() 和 getCallback() 方法。
class DocumentLink extends AbstractShortcode {
public function getName()
{
return "document_link";
}
public function getCallback()
{
$link = func_get_arg(0);
return '<a href="' . $link . '">Download document</a>';
}
}
公共方法
- getName() - 返回在编辑器中将使用的短码名称。
- getCallback() - 返回短码的标记。
ShortcodeHelper 使用
一旦您设置好了 pimple 配置,您就可以像这样使用 ShortcodeHelper
$helper = $pimple['ShortcodeHelper'];
$helper->registerShortcodes();
这就完成了,助手将添加所有必要的钩子和注册您提供的所有短码。
公共方法
- registerShortcodes() - 注册提供的短码。