我需要更改输出篡改模板。例如:
现在我在数据库中存储了这个模板
<div id="foogallery-gallery-67" class="foogallery-container foogallery-default foogallery-link-image foogallery-lightbox-foobox-free spacing-width-10 hover-effect-zoom3 border-style-square-white alignment-center hover-caption-simple foogallery-default-loading">
<a href="http://wordpress.local/wp-content/uploads/2017/08/222-1.jpg" data-caption-title="Title" data-caption-desc="description text" data-attachment-id="128" class="">
<img src="http://wordpress.local/wp-content/uploads/cache/2017/08/222-1/705461751.jpg" width="150" height="150" />
</a>
</div>我需要添加一个data-*属性(data-custom)
<div id="foogallery-gallery-67" class="foogallery-container foogallery-default foogallery-link-image foogallery-lightbox-foobox-free spacing-width-10 hover-effect-zoom3 border-style-square-white alignment-center hover-caption-simple foogallery-default-loading">
<a href="http://wordpress.local/wp-content/uploads/2017/08/222-1.jpg" data-caption-title="Title" data-caption-desc="description text" data-attachment-id="128" data-custom="" class="">
<img src="http://wordpress.local/wp-content/uploads/cache/2017/08/222-1/705461751.jpg" width="150" height="150" />
</a>
</div>我知道我可以直接添加到数据库中,我感兴趣的是如何重新定义输出和输入函数,以便将来不会出现问题。
发布于 2017-08-25 17:40:07
我再一次回答我自己的问题
例如,我们有这样一个插件的结构:
class Plugin()
{
public function __construct()
{
}
}
$startPlugin = new Plugin();并且我们需要更改输出FooGallary模板。FooGallary有这个过滤器,谁可以改变输出的篡改foogallery_attachment_html_link_attributes。现在改变我们的类,帮助这个过滤器。
class Plugin()
{
public function __construct()
{
add_filter('foogallery_attachment_html_link_attributes', array($this, 'addFoogalleryCategory'), 10, 3);
}
public function addFoogalleryCategory($attr, $args, $attachment)
{
$attr['data-category'] = 'category';
return $attr;
}
}
$startPlugin = new Plugin();这很简单,但我没有立即找到解决方案。也许我帮了什么人。
https://stackoverflow.com/questions/45751761
复制相似问题