dsunj08246 2016-10-20 03:42
浏览 39

如何在Wordpress中覆盖插件类的功能?

I want to override function get_post() in class EM_Tickets of plugin Event Manager

class EM_Tickets extends EM_Object implements Iterator{
/**
 * Retrieve multiple ticket info via POST
 * @return boolean
 */
function get_post(){
    // something here

    return apply_filters('em_tickets_get_post', count($this->errors) == 0, $this);
    }
}

so I create my own plugin and put below codes but no luck, don't know why it's not working although I read and follow some manuals likes Is it possible to replace a function within a PHP class?

class EM_Tickets_Child extends EM_Tickets implements Iterator{

    public function get_post(){
        file_put_contents('log.txt', 'in child class', FILE_APPEND | LOCK_EX);
        //something here
    }           
}
  • 写回答

1条回答 默认 最新

  • duanleiliu7373 2016-10-20 07:13
    关注

    You have a filter (apply_filters) on the original code. You just need to hook and create a function to override the returns value, no needs to extends the plugin class, but it's another way to do.

    add_action('em_ticket_get_posts', array('Em_tickets', 'my_new_get_post), 10, 2);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c