[英]Pass the callback function as a parameter to wp_insert_post_data from inside a class
我有这样的课:
class A
{
function __construct() {
add_filter('wp_insert_post_data', [$this, 'my_func'], 99, 2);
}
//...
function my_func($data, $postarr)
{
//I want to change some contents before save post, then i do:
$data['post_content'] .= 'Add something';
return $data;
}
}
看起来好像没有传递参数,因此没有调用该函数。 我还在课外测试了我的代码,并且效果很好。
我如何在课堂上使用它?
您快到了-使用array()
代替[]
add_filter('wp_insert_post_data', array($this, 'my_func'), 99, 2);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.