【问题标题】:How To Override WordPress Plugin Displays如何覆盖 WordPress 插件显示
【发布时间】:2012-04-09 19:07:06
【问题描述】:
这似乎是一个简单的问题,但事实证明很难找到相关信息。
我正在使用一些输出很糟糕的 WordPress 插件 - 特别是 The Events Calendar 1.6.5。此插件具有用于输出事件内容的 PHP 文件,例如 gridview.php、list.php、single.php 和 table .php。我熟悉挂钩这些文件调用的函数以覆盖插件的工作方式,但我需要更改整个显示格式以适应我的主题。
有没有办法覆盖这些显示文件,或者我只是制作自己的主题文件并调用插件文件使用的相同函数?
【问题讨论】:
标签:
plugins
calendar
overriding
wordpress-theming
【解决方案1】:
我正在寻找类似的答案。我不确定事件日历是如何实现的,但是从使用 Business Directly 插件完成类似操作的经验来看,您可以通过从主题的 functions.php 文件中将其挂钩到您自己的方法来覆盖挂钩。
这是一个例外,我写的是覆盖钩子“wpbdm_show-add-listing-form”:
/*
* Fix the horrible output of wpbusdirman_displaypostform() from wpbusdirman.php
*
* This is done by overriding the wpbdm_show-add-listing-form hook with my own function
*/
add_filter('wpbdm_show-add-listing-form', 'alternative_wpbusdirman_displaypostform', 10, 4);
// Ensure that the method signature is the same (same order of vars, same
function alternative_wpbusdirman_displaypostform($makeactive = 1, $wpbusdirmanerrors = '', $neworedit = 'new', $wpbdmlistingid = '')
{
// This assumes that the Business Directory Plugin is installed
if (!function_exists("wpbusdirman_displaypostform"))
{
// If the funct doesn't exist then it probably isn't installed
return '';
}
// Call the method and regex parse out the bits we don't want
$original_output = wpbusdirman_displaypostform($makeactive, $wpbusdirmanerrors, $neworedit, $wpbdmlistingid);
// Do some fixing of the output. In this example we do nothing and just return what we received.
return $original_output . " WE EDITED IT!";
}